Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add PlatformIO support #250

Merged
merged 26 commits into from
Sep 14, 2021
Merged

Add PlatformIO support #250

merged 26 commits into from
Sep 14, 2021

Conversation

maxgerhardt
Copy link
Contributor

@maxgerhardt maxgerhardt commented Jul 17, 2021

The builder script is pretty much final.

The rest of the work is in the platform scripts / board definitions at https://github.com/maxgerhardt/platform-raspberrypi, where e.g. filesystem uploading etc. is handled.

Updates the package.json too with some more meta-information and corrects the version field (SemVer expression).

All Arduino IDE menu settings of this core can be replicated within the platformio.ini.

Selecting the new core

Prerequisite for using this core is to tell PlatformIO to switch to it. There will be board definition files where the Earle-Philhower core will be the default since it's a board that only exists in this core (and not the other https://github.com/arduino/ArduinoCore-mbed). To switch boards for which this is not the default core (e.g. the standard board = pico), the directive

board_build.core = earlephilhower

must be added to the platformio.ini. This controls the core switching logic.

Flash size

Controlled via specifying the size allocated for the filesystem. Available sketch size is calculated accordingly by using (as in makeboards.py) that number and the (constant) EEPROM size (4096 bytes) and the total flash size as known to PlatformIO via the board definition file. The expression on the right can involve "b","k","m" (bytes/kilobytes/megabytes) and floating point numbers. This makes it actually more flexible than in the Arduino IDE where there is a finite list of choices. Calculations happen in the platform.

; in reference to a board = pico config (2MB flash)
; Flash Size: 2MB (Sketch: 1MB, FS:1MB)
board_build.filesystem_size = 1m
; Flash Size: 2MB (No FS)
board_build.filesystem_size = 0m
; Flash Size: 2MB (Sketch: 0.5MB, FS:1.5MB)
board_build.filesystem_size = 1.5m

CPU Speed

As for all other PlatformIO platforms, the f_cpu macro value (which is passed to the core) can be changed as documented

; 133MHz
board_build.f_cpu = 133000000L

Debug Port

Via build_flags as done for many other cores (example).

; Debug Port: Serial
build_flags = -DDEBUG_RP2040_PORT=Serial
; Debug Port: Serial 1
build_flags = -DDEBUG_RP2040_PORT=Serial1
; Debug Port: Serial 2
build_flags = -DDEBUG_RP2040_PORT=Serial2

Debug Level

Done again by directly adding the needed build flags. When wanting to define multiple buid flags, they must be accumulated in either a sing line or a newline-separated expression.

; Debug level: Core
build_flags = -DDEBUG_RP2040_CORE
; Debug level: SPI
build_flags = -DDEBUG_RP2040_SPI
; Debug level: Wire
build_flags = -DDEBUG_RP2040_WIRE
; Debug level: All
build_flags = -DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI -DDEBUG_RP2040_CORE
; Debug level: NDEBUG
build_flags = -DNDEBUG

; example: Debug port on serial 2 and all debug output
build_flags = -DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI -DDEBUG_RP2040_CORE -DDEBUG_RP2040_PORT=Serial2
; equivalent to above
build_flags = 
   -DDEBUG_RP2040_WIRE
   -DDEBUG_RP2040_SPI
   -DDEBUG_RP2040_CORE
   -DDEBUG_RP2040_PORT=Serial2

USB Stack

Not specifying any special build flags regarding this gives one the default Pico SDK USB stack. To change it, add

; Adafruit TinyUSB
build_flags = -DUSE_TINYUSB
; No USB stack
build_flags = -DPIO_FRAMEWORK_ARDUINO_NO_USB

Note that the special "No USB" setting is also supported, through the shortcut-define PIO_FRAMEWORK_ARDUINO_NO_USB.

arduino-pico/boards.txt

Lines 337 to 338 in 05356da

rpipicopicodebug.menu.usbstack.nousb=No USB
rpipicopicodebug.menu.usbstack.nousb.build.usbstack_flags="-DNO_USB -DDISABLE_USB_SERIAL -I{runtime.platform.path}/tools/libpico"

Selecting a different core version

If you wish to use a different version of the core, e.g., the latest git master version, you can use a platform_packages directive to do so. Simply specify that the framework package (framework-arduinopico) comes from a different source.

platform_packages =
   framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#master

Whereas the #master can also be replaced by a #branchname or a #commithash.

Note that this can only be done for versions that have the PlatformIO builder script it in, so versions before 1.9.2 are not supported.

Examples

The following example platformio.ini can be used for a Raspberry Pi Pico and 0.5MByte filesystem.

[env:pico]
platform = raspberrypi
board = pico
framework = arduino
build_board.core = earlephilhower
board_build.filesystem_size = 0.5m

The initial project structure should be generated just creating a new project for the Pico and the Arduino framework, after which the auto-generated platformio.ini can be adapter per above.


The project has been tested with https://github.com/maxgerhardt/pio-pico-core-earlephilhower-test on a Pi Pico and a Sparkfun RP2040 Thing Plus and wit works just fine.

Following the merge of this PR, there's still some packaging and publishing work to do (toolchain-pico, tool-pioasm, this repo as framework-arduinopico), along with porting all board definitions into the platform to fully support the core. Oh, and of course a PR to https://github.com/platformio/platformio-docs/ for the documentation of core settings.

@earlephilhower
Copy link
Owner

@maxgerhardt Thanks! I'll try and get to the toolchain issues very soon.

How about adding your notes in this issue to a new doc/platformio.rst file? It's almost a cut-n-paste and would preserve the documentation you've done (since closed bugs don't get many eyeballs).

@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented Jul 17, 2021

I've added a doc/platformio.rst (and tested that it rendered fine in VSCode with some reStructured Text extension), and slightly expanded it with the most recent commit above.

package.json Outdated
"version": "0.9.2"
}
"name": "framework-arduinopico",
"version": "1.10902.0",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version is auto-generated by the package script. It's a minor change I can do to change the #, but what's wrong with the existing #.#.# format? I always update it (during package/release, but not in git) for releases, so it will be unique no matter what...

Copy link
Contributor Author

@maxgerhardt maxgerhardt Jul 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format I used is used by pretty much PlatformIO packages, decodable per this, aka <major package version>.<semver encoding of exact version>.<datecode>, so this is just for the sake of being in-sync with PlatformIO (see e.g. toolchain-gccarmnoneeabi). PlatformIO has no problems also decoding 0.9.2 if it detects that it's not in PlatformIO's preferred format. Although even PlatformIO has inconsistencies.. (see framework-arduino-mbed).

Note that if changed, also the platform.json must be adapted (no big deal since no package version has been released anyway). I'm fine with either :)

@earlephilhower
Copy link
Owner

Oh, and FYI I updated a minor typo in the doc and added your file to the table of contents (otherwise it's invisible to most people!).

@maxgerhardt
Copy link
Contributor Author

I just had to correct another typo, too.

@earlephilhower
Copy link
Owner

I was occupied with other things this weekend so unable to start on the PIO support work, sorry!

I'll see what I can get going this week. Or, if you think it's safe to merge this w/o the add'l things in pico-quick-toolchain let me know and I can merge here and work on PIO-proper stuff later.

@maxgerhardt
Copy link
Contributor Author

I'll add some more documentation (small introduction to PlatformIO in the docs, not jumping straight into platformio.ini options..), revert the version format change (but still change 0.9.2 to 1.9.2.. somehow the script messes up theree), update the libstdc++.a path so that it is in sync with current master. Other things can just be ammended in future PRs (e.g. C++ exception handling), before an actual PlatformIO package release for the core is done.

Regarding the toolchain: The compiler package toolchain-pico can already be pio package publish-ed for all OSes. After publishing, they'll be in the queue for manual inspection by PlatformIO anyways, so it's better to publish them now.

@earlephilhower
Copy link
Owner

I've not forgotten about this! Just been very busy these past couple weeks, but it's still on the radar.

@maxgerhardt
Copy link
Contributor Author

Same same, but I'll aim to push the things I talked about above today.

@derekmulcahy
Copy link

I know this is a work in progress but is it possible for me to use/test it?

@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented Aug 8, 2021

@derekmulcahy In the PR description I've mentioned my test project

The project has been tested with https://github.com/maxgerhardt/pio-pico-core-earlephilhower-test on a Pi Pico and a Sparkfun RP2040 Thing Plus and wit works just fine.

@earlephilhower I've further updated the docs regarding a general PlatformIO section. I also retested the building & uploading with this latest version. This is good to merge for now in my eyes.

Notice that I do change the package.json, fixing the version from 0.9.3 to 1.9.3 as it appears in the release page. If that previous package.json was auto-generated, there's a bug in that script somewhere.

@maxgerhardt
Copy link
Contributor Author

I've re-based onto master.

@Jason2866
Copy link

@maxgerhardt toolchain for Windows is missing.

Processing tasmota-pico (board: pico; platform: raspberrypi; framework: arduino)
------------------------------------------------------------------------------------Tool Manager: Installing maxgerhardt/toolchain-pico @ ~5.100300.0
Error: Could not find the package with 'maxgerhardt/toolchain-pico @ ~5.100300.0' requirements for your system 'windows_amd64'
Der Terminalprozess "C:\Python37\Scripts\platformio.exe 'run', '--target', 'clean'" wurde mit folgendem Exitcode beendet: 1.

@maxgerhardt
Copy link
Contributor Author

Correct, that's why one needs to do a platform_packages instruction as referenced in the docs + referenced example to get it working.

https://github.com/maxgerhardt/pio-pico-core-earlephilhower-test/blob/ad342fd984696139a931f73be991e85e9855040e/platformio.ini#L28-L33

earlephilhower/pico-quick-toolchain#5

@Jason2866
Copy link

Thx, good so far. Now i get this

Processing tasmota-pico (board: pico; platform: 
https://github.com/maxgerhardt/platform-raspberrypi.git#develop; framework: arduino)------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/pico.html
PLATFORM: Raspberry Pi RP2040 (1.2.0+sha.673d327) > Raspberry Pi Pico
HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, picoprobe, raspberrypi-swd)  
PACKAGES:
 - framework-arduinopico 1.10903.0+sha.e33a2e0
 - tool-rp2040tools 1.0.2
 - toolchain-pico 5.100300.210706 (10.3.0)
Converting tasmota.ino
Der Befehl "arm-none-eabi-g++" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
*** Error 1
AssertionError: :
  File "C:\python37\lib\site-packages\platformio\builder\main.py", line 178:        
    env.SConscript("$BUILD_SCRIPT")
  File "C:\Users\Hans\.platformio\packages\tool-scons\scons-local-4.2.0\SCons\Script\SConscript.py", line 597:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\Hans\.platformio\packages\tool-scons\scons-local-4.2.0\SCons\Script\SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "C:\Users\Hans\.platformio\platforms\raspberrypi\builder\main.py", line 221: 
    target_elf = env.BuildProgram()
  File "C:\Users\Hans\.platformio\packages\tool-scons\scons-local-4.2.0\SCons\Util.py", line 748:
    return self.method(*nargs, **kwargs)
  File "C:\python37\lib\site-packages\platformio\builder\tools\platformio.py", line 
61:
    env.ProcessProgramDeps()
  File "C:\Users\Hans\.platformio\packages\tool-scons\scons-local-4.2.0\SCons\Util.py", line 748:
    return self.method(*nargs, **kwargs)
  File "C:\python37\lib\site-packages\platformio\builder\tools\platformio.py", line 
128:
    env.BuildFrameworks(env.get("PIOFRAMEWORK"))
  File "C:\Users\Hans\.platformio\packages\tool-scons\scons-local-4.2.0\SCons\Util.py", line 748:
    return self.method(*nargs, **kwargs)
  File "C:\python37\lib\site-packages\platformio\builder\tools\platformio.py", line 
340:
    env.ConvertInoToCpp()
  File "C:\Users\Hans\.platformio\packages\tool-scons\scons-local-4.2.0\SCons\Util.py", line 748:
    return self.method(*nargs, **kwargs)
  File "C:\python37\lib\site-packages\platformio\builder\tools\piomisc.py", line 240:
    out_file = c.convert(ino_nodes)
  File "C:\python37\lib\site-packages\platformio\builder\tools\piomisc.py", line 92:    return self.process(contents)
  File "C:\python37\lib\site-packages\platformio\builder\tools\piomisc.py", line 113:
    assert self._gcc_preprocess(contents, out_file)
============================ [FAILED] Took 2.13 seconds ============================
Environment    Status    Duration
-------------  --------  ------------
tasmota-pico   FAILED    00:00:02.130

Any hints?

@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented Sep 9, 2021

Something is still wrong with the toolchain or path. Possibly wrong downloadlink for wrong architecture. Can you open an issue in the Tasmota repo with this repo so that we can discuss it here instead of in the PR? This should be a project-specific issue. (Or an issue in my platform-raspberrypi)

@Jason2866
Copy link

Arrgh, sorry! All good. Silly Copy&Paste error!.
Thx. for your great work!

@maxgerhardt
Copy link
Contributor Author

Can we get this merged @earlephilhower? Otherwise let me know if there are open points for this script as of now.

Copy link
Owner

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay! It's been one heck of a busy late summer.

The script (and docs!) LGTM, so thanks again for doing the integration work!

@earlephilhower
Copy link
Owner

I'll address the update of the package.JSON numbering in a later PR, but for now this can go in as-is!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants