maxgerhardt / pio-pico-core-earlephilhower-test

Test firmware that uses the earlephilhower Arduino core.
4 stars 2 forks source link

Consider adding default optimization switch -Os #2

Closed jhmaloney closed 2 years ago

jhmaloney commented 2 years ago

Your Platformio support for the Earle Philhower Arduinio framework for the RP2040 is working perfectly for me! Thank you!

However, I needed to add the -Os switch to my build_flags to get it generate code that was comparable in size and speed to the code generated by the official mbed-based Pico framework from Arduino. Once I added that switch, the resulting code used less Flash and RAM and was as fast or faster than the mbed-based framework.

Ivan says the default optimization level for Platformio is -Os (see here). I believe the Arduino IDE also defaults to that optimization level.

Is there a way you can set the default optimization level to -Os? If so, it would help people see immediately that the Earle Philhower framework uses less resources than the official Arduino framework.

maxgerhardt commented 2 years ago

Woops, I really left that out. Thought it would get included from somewhere else. Fixed in https://github.com/maxgerhardt/arduino-pico/commit/fbb765f526c85d20008f444317594b03a6664334.

Firmware size went from

RAM:   [==        ]  15.7% (used 41232 bytes from 262144 bytes)
Flash: [          ]   3.9% (used 40632 bytes from 1044480 bytes)

quite significantly to

RAM:   [          ]   2.7% (used 7180 bytes from 262144 bytes)
Flash: [=         ]   5.4% (used 56032 bytes from 1044480 bytes)

Please execute a pio platform update raspberrypi from the CLI to pull the update.

jhmaloney commented 2 years ago

I did a pio platform update raspberrypi. The second run says:

--------
Updating git+https://github.com/maxgerhardt/platform-raspberrypi.git 1.5.0+sha.9811f13                  [Up-to-date]
Updating platformio/toolchain-gccarmnoneeabi  1.90201.191206 @ ~1.90201.0        [Up-to-date]
Updating https://github.com/earlephilhower/pico-quick-toolchain/releases/download/1.3.1-a/x86_64-apple-darwin14.arm-none-eabi-7855b0c.210706.tar.gz 5.100300.210706 @ ~5.100300.0      [Up-to-date]
Updating platformio/framework-arduino-mbed    2.6.1 @ ~2.6.0                     [Up-to-date]
Updating platformio/tool-rp2040tools          1.0.2 @ ~1.0.2                     [Up-to-date]
Updating platformio/tool-openocd-raspberrypi  2.1100.0 @ ~2.1100.0               [Up-to-date]
Updating platformio/tool-mklittlefs           1.203.210628 @ ~1.203.0            [Up-to-date]

But it still doesn't appear to default to -Os for me.

jhmaloney commented 2 years ago

Further info...

The pio platform update raspberrypi did not pull the latest version. When I manually added -Os to platform-build.py, it does get the correct optiimization default.

I then did a git pull in my .platformio/packages/framework-arduinopico folder and it pulled your change (as well as number of other changes). So the pio platform update raspberrypi mechanism may not be working correctly.

Here's my .platformio environment entry:

[env:pico-philhower]
; switch to forked platform with new extensions :)
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
lib_ignore = WiFi
framework = arduino
board_build.core = earlephilhower
; configure filesystem size. Default 0 Mbyte.
board_build.filesystem_size = 0m
lib_ldf_mode = chain+
; inject core package.. not yet registered with PlatformIO
; registry, so pull working version directly from git / download page.
; note that download link for toolchain is specific for OS. see https://github.com/earlephilhower/pico-quick-toolchain/releases.
platform_packages =
    maxgerhardt/framework-arduinopico@https://github.com/maxgerhardt/arduino-pico.git
    maxgerhardt/toolchain-pico@https://github.com/earlephilhower/pico-quick-toolchain/releases/download/1.3.1-a/x86_64-apple-darwin14.arm-none-eabi-7855b0c.210706.tar.gz

Let me know if I got something wrong.

Just to be super clear, after doing git pull my builds are now defaulting to -Os as expected. Thanks for making that change!

maxgerhardt commented 2 years ago

Oh yes, this is currently a fault in my platform-raspberrypi fork, the arduino core package is declared with a stable version tag here, but that causes pio platform update raspberrypi then to not pull the latest version from the git repo. You were right to pull the changes manually (or deleting ~/.platformio/packages/framework-arduinopico would have triggered a redownload).

However, it will likely take some time before I'll publish the framework-arduinopico package to the registry, as there still things to iron out. For now, in the latest git version of the core, the issue is resolved.

jhmaloney commented 2 years ago

Quick update: Builds are now defaulting to -Os, which for my super simple interpreter loop test is fastest as well as the smallest code. However, I found that that optimization switch can't be overridden by build_flags in the platformio.ini file. In order to experiment with different optimization settings I ended up modifying platformio-build.py. Other PlatformIO Arduino frames default to -Os be allow it to be overridden. Not a big deal, just thought I'd mention it.

maxgerhardt commented 2 years ago

Alright that's weird, it should be overridable. Maybe it has to in the platform's main.py or something to be overridable (order of operations / executions of the platform and framework builder scripts). I'll look into it.