ESP32 Project-> code behaves different depending on the packages version

Hello,

I’m developing a project where the ESP32 uses an encoder to trigger 2 GPIOs depending on the encoder value. The code works perfectly when compiled in one computer, but behaves slightly different when compiled and uploaded from my laptop.
After some investigation, I found some differences in the upload log output. The package’s versions are different, so the output binaries have different size and simply, does not do the same job.

I had to specify the working versions in my platform.ini file, but I believe it’s weird that old versions of the packages produce a faster and better code than the newer ones.

As an example, this is the memory usage with old libraries (code that works):
RAM: [== ] 20.1% (used 65700 bytes from 327680 bytes)
Flash: [======= ] 65.6% (used 860110 bytes from 1310720 bytes)

And this is the memory usage when using the latest and greatest packages, with a compact code that is not working as expected:
RAM: [== ] 21.0% (used 68808 bytes from 327680 bytes)
Flash: [====== ] 61.5% (used 806085 bytes from 1310720 bytes)

The difference is not big, but there’s something in that compilation that produces a smaller code that works slower!

Best regards,
Paco

When you compile your code with the latest Arduino-ESP32 core (2.0.4) in the Arduino IDE, does it also behave slower than when you install e.g. 1.0.6 in the board manager? If yes → issue to Issues · espressif/arduino-esp32 · GitHub

Here you have more detailed information, the versions I have installed are 1.0.6 and 2.0.1. I will try the latest version too and check how it behaves.

This is the output of the working/fast version:

PLATFORM: Espressif 32 (3.5.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.10006.210326 (1.0.6)
 - tool-esptoolpy @ 1.30100.210531 (3.1.0)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-xtensa32 @ 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- lvgl @ 8.3.1
|   |-- ESP32 BLE Arduino @ 1.0.1
|-- LovyanGFX @ 0.4.18
|   |-- SPI @ 1.0
|   |-- Wire @ 1.0.1
|-- ESP32Encoder @ 0.9.2
|-- Utilities @ 0.4.6
|-- Preferences @ 1.0
Building in release mode
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  20.1% (used 65700 bytes from 327680 bytes)
Flash: [=======   ]  65.6% (used 860222 bytes from 1310720 bytes)

And this the ouput of the slow/non working version:

PLATFORM: Espressif 32 (4.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20001.0 (2.0.1)
 - tool-esptoolpy @ 1.30100.210531 (3.1.0)
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 36 compatible libraries
Scanning dependencies...
Dependency Graph
|-- lvgl @ 8.3.1      
|-- LovyanGFX @ 0.4.18
|   |-- SPI @ 2.0.0   
|   |-- Wire @ 2.0.0  
|-- ESP32Encoder @ 0.9.2
|-- Utilities @ 0.4.6
|-- Preferences @ 2.0.0
Building in release mode
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  21.0% (used 68808 bytes from 327680 bytes)
Flash: [======    ]  61.5% (used 806085 bytes from 1310720 bytes)

Regards!

Tested with the latest & greatest. Does not wrk as expected. Is missing encoder pulses and missing triggers.
The code is more compact, but somehow, is slower than the one that produces old versions.

PLATFORM: Espressif 32 (5.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20004.0 (2.0.4)
 - tool-esptoolpy @ 1.30300.0 (3.3.0)
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
 - toolchain-xtensa32 @ 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 37 compatible libraries
Scanning dependencies...
Dependency Graph
|-- lvgl @ 8.3.1
								 
|-- LovyanGFX @ 0.4.18
|   |-- SPI @ 2.0.0
|   |-- Wire @ 2.0.0
|-- ESP32Encoder @ 0.9.2
|-- Utilities @ 0.4.6
|-- Preferences @ 2.0.0
Building in release mode
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  20.9% (used 68592 bytes from 327680 bytes)
Flash: [======    ]  62.6% (used 820481 bytes from 1310720 bytes)