When building a program for the ESP32 which utilises the ULP assembly files, changes made to the .S sources should be rebuilt and merged into the final .bin file.
Current Behavior
Looks like under platform.io, the build process does not correctly rebuild the .S source files.
The test program has the ULP add a number to a variable in the RTC slow mem every second. The main core prints out the value of said vaiable 4 times a second.
When changing the amount that is added to the variable, the old version of the ULP program seems to be still used even though the source file has different contents
This same example and steps work as expected under pure ESP-IDF
flash and open monitor, observe the counter value increasing by 5 every 4 readings.
change the ulp/main.S source file line 18 from: add r1, r1, 5 -> to: add r1, r1, 10
flash and observe as before, You may need to do change code again and flash to see the fail condition, otherwise: the sequence should be incremented by 10 every 4 readings, but it looks like the ULP is running old code.
As stated in step 4, you may need to change code and flash twice before the code stops updating in the ULP
You can keep changing the numbers but no change will occur until the build folder is deleted.
The C macro apporach works flawlessly, only real assembly files are cached weirdly like this
Context (Environment)
Main test environment:
System: Windows 11
IDE: VS Code
Alternative test environment:
System: Debian 12
IDE: none / ESP-IDF command line tools
ESP-IDF version: v5.1.2
Processing esp32dev (platform: espressif32; board: esp32dev; framework: espidf)
---------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.5.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-espidf @ 3.50102.240122 (5.1.2)
- tool-cmake @ 3.16.4
- tool-esptoolpy @ 1.40501.0 (4.5.1)
- tool-idf @ 1.0.1
- tool-mconf @ 1.4060000.20190628 (406.0.0)
- tool-mkfatfs @ 2.0.1
- tool-mklittlefs @ 1.203.210628 (2.3)
- tool-mkspiffs @ 2.230.0 (2.30)
- tool-ninja @ 1.9.0
- tool-riscv32-esp-elf-gdb @ 11.2.0+20220823
- tool-xtensa-esp-elf-gdb @ 11.2.0+20230208
- toolchain-esp32ulp @ 1.23500.220830 (2.35.0)
- toolchain-xtensa-esp32 @ 12.2.0+20230208
Reading CMake configuration...
Warning! Flash memory size mismatch detected. Expected 4MB, found 2MB!
Please select a proper value in your `sdkconfig.defaults` or via the `menuconfig` target!
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Generating ULP configuration
-- git rev-parse returned 'fatal: not a git repository (or any of the parent directories): .git'
fatal: not a git repository (or any of the parent directories): .git
-- Building ULP app ulp_main
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/purewack/Desktop/ULP/ulp_test/.pio/build/esp32dev/esp-idf/src/ulp_main
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: [ ] 3.2% (used 10604 bytes from 327680 bytes)
Flash: [== ] 16.6% (used 173881 bytes from 1048576 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: COM26
Uploading .pio\build\esp32dev\firmware.bin
esptool.py v4.5.1
Serial port COM26
Connecting......
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 0c:b8:15:f6:c7:04
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00007fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x00010000 to 0x0003afff...
Compressed 24848 bytes to 15730...
Writing at 0x00001000... (100 %)
Wrote 24848 bytes (15730 compressed) at 0x00001000 in 0.9 seconds (effective 225.6 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 307.7 kbit/s)...
Hash of data verified.
Compressed 174240 bytes to 96970...
Writing at 0x00010000... (16 %)
Writing at 0x0001bed3... (33 %)
Writing at 0x00021881... (50 %)
Writing at 0x00027dad... (66 %)
Writing at 0x0002faba... (83 %)
Writing at 0x000350a4... (100 %)
Wrote 174240 bytes (96970 compressed) at 0x00010000 in 2.7 seconds (effective 521.8 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
=================== [SUCCESS] Took 15.97 seconds ===================
* Terminal will be reused by tasks, press any key to close it.
Project Structure
(showing important files only)
Expected Behavior
When building a program for the ESP32 which utilises the ULP assembly files, changes made to the .S sources should be rebuilt and merged into the final .bin file.
Current Behavior
Looks like under platform.io, the build process does not correctly rebuild the .S source files. The test program has the ULP add a number to a variable in the RTC slow mem every second. The main core prints out the value of said vaiable 4 times a second.
When changing the amount that is added to the variable, the old version of the ULP program seems to be still used even though the source file has different contents
This same example and steps work as expected under pure ESP-IDF
Example source files:
ulp_test.zip
Steps to Reproduce
add r1, r1, 5
-> to:add r1, r1, 10
As stated in step 4, you may need to change code and flash twice before the code stops updating in the ULP
You can keep changing the numbers but no change will occur until the build folder is deleted.
The C macro apporach works flawlessly, only real assembly files are cached weirdly like this
Context (Environment)
Main test environment: System: Windows 11 IDE: VS Code
Alternative test environment: System: Debian 12 IDE: none / ESP-IDF command line tools ESP-IDF version: v5.1.2
Tested Boards:
src/main.c
contents:ulp/main.S
contents:Output log when glitch occurs: