diff --git a/pio-scripts/lto.py b/pio-scripts/lto.py new file mode 100644 index 0000000000..f6e7cab5dd --- /dev/null +++ b/pio-scripts/lto.py @@ -0,0 +1,24 @@ +Import('env') + +env.Replace(AR=env['AR'].replace('elf-ar', 'elf-gcc-ar')) +env.Replace(RANLIB=env['RANLIB'].replace('elf-ranlib', 'elf-gcc-ranlib')) + +# Something later clobbers AR & RANLIB, so until https://github.com/platformio/platform-espressif32/pull/1329 +# is available, wrap the replace function to protect them + +# Save a reference to the original env.Replace() +original_replace = env.Replace + +def create_replace_wrapper(env): + def replace_wrapper(**kw): + if 'AR' in kw: + kw.pop("AR") + if 'RANLIB' in kw: + kw.pop("RANLIB") + + original_replace(**kw) + + return replace_wrapper + +# Replace the env.Replace with the wrapper +env.Replace = create_replace_wrapper(env) diff --git a/platformio.ini b/platformio.ini index 6306595a29..3a1eb4c9ea 100644 --- a/platformio.ini +++ b/platformio.ini @@ -59,6 +59,7 @@ platform_packages = platformio/framework-arduinoespressif8266 # esp8266 : see https://docs.platformio.org/en/latest/platforms/espressif8266.html#debug-level # esp32 : see https://docs.platformio.org/en/latest/platforms/espressif32.html#debug-level # ------------------------------------------------------------------------------ +# Enabling debug? You might want to disable LTO to avoid call stacks being squashed through inlining debug_flags = -D DEBUG=1 -D WLED_DEBUG -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM ;; for esp8266 # if needed (for memleaks etc) also add; -DDEBUG_ESP_OOM -include "umm_malloc/umm_malloc_cfg.h" @@ -103,11 +104,16 @@ build_flags = -D DECODE_LG=true -DWLED_USE_MY_CONFIG +lto_flags = + -flto + build_unflags = + -fno-lto +# No LTO for ESP8266 as we overflow IRAM build_flags_esp8266 = ${common.build_flags} ${esp8266.build_flags} -build_flags_esp32 = ${common.build_flags} ${esp32.build_flags} -build_flags_esp32_V4= ${common.build_flags} ${esp32_idf_V4.build_flags} +build_flags_esp32 = ${common.build_flags} ${esp32.build_flags} ${common.lto_flags} +build_flags_esp32_V4= ${common.build_flags} ${esp32_idf_V4.build_flags} ${common.lto_flags} ldscript_1m128k = eagle.flash.1m128.ld ldscript_2m512k = eagle.flash.2m512.ld @@ -121,6 +127,7 @@ extra_scripts = post:pio-scripts/strip-floats.py pre:pio-scripts/user_config_copy.py pre:pio-scripts/build_ui.py + pre:pio-scripts/lto.py # ------------------------------------------------------------------------------ # COMMON SETTINGS: @@ -198,6 +205,7 @@ build_flags = ; decrease code cache size and increase IRAM to fit all pixel functions -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48 ;; in case of linker errors like "section `.text1' will not fit in region `iram1_0_seg'" ; -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED ;; (experimental) adds some extra heap, but may cause slowdown + lib_deps = #https://github.com/lorol/LITTLEFS.git diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 866543ab93..50e6561429 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -12,10 +12,12 @@ */ #include "wled.h" +void setup() __attribute__((used)); void setup() { WLED::instance().setup(); } +void loop() __attribute__((used)); void loop() { WLED::instance().loop(); }