esp32zephyr-rtosnrf52840

Out of Memory on ESP32 with Zephyr 4.1


I have a Zephyr 4.1 application that is reading values from an MPU6050 and calculating Roll and Pitch.

I have been developing on a nRF52840DK and it builds correctly, as such I thought I would try moving it over to an ESP32, as I had one on my desk. I could not get a successful build due to out of iram0 memory until I disabled logging on the ESP32 or set it to CONFIG_LOG_DEFAULT_LEVEL=1

When I look at the two build messages I see widely different values for size of the compiled code.

I was suprised to see that the ESP32 only has 64kb available (the datasheet says 520kb) and that most of it was used by the same code that only uses 11kb on the nrf52840.

Are there specific optimisations needed in the ESP32 build process to reduce memory usage?

Below is the prj.conf

Executing task: west build -b nrf52840dk/nrf52840 c:\Coding\zephyrproject\flight_controller -p --build-dir c:\Coding\zephyrproject\flight_controller\build\nrf52840dk\nrf52840  -- -DBOARD_ROOT='c:\Coding\zephyrproject'   -DEXTRA_DTC_OVERLAY_FILE='c:\Coding\zephyrproject\boards\nrf52840dk_nrf52840\nrf52840dk_nrf52840.overlay;'  
[209/210] Linking C executable zephyr\zephyr.elf
Memory region         Used Size  Region Size  %age Used

           FLASH:       70900 B         1 MB      6.76%
             RAM:       11424 B       256 KB      4.36%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from C:/Coding/zephyrproject/flight_controller/build/nrf52840dk/nrf52840/zephyr/zephyr.elf for board: nrf52840dk


Executing task: west build -b esp32_devkitc_wroom/esp32/appcpu c:\Coding\zephyrproject\flight_controller -p --build-dir c:\Coding\zephyrproject\flight_controller\build\esp32_devkitc_wroom\esp32\appcpu  -- -DBOARD_ROOT='c:\Coding\zephyrproject\external\zephyr'   -DEXTRA_DTC_OVERLAY_FILE='c:\Coding\zephyrproject\boards\esp32_devkitc_wroom\esp32_devkitc_wroom.overlay;'  

-- Zephyr version: 4.1.0 (C:/Coding/zephyrproject/external/zephyr), build: v4.1.0
[249/249] Linking C executable zephyr\zephyr.elf
Memory region         Used Size  Region Size  %age Used
     mcuboot_hdr:          32 B         32 B    100.00%
        metadata:          32 B         32 B    100.00%
           FLASH:       63076 B    4194240 B      1.50%
     iram0_1_seg:       52852 B        64 KB     80.65%
     dram0_1_seg:       21704 B        64 KB     33.12%
        IDT_LIST:          0 GB         8 KB      0.00%
Generating files from C:/Coding/zephyrproject/flight_controller/build/esp32_devkitc_wroom/esp32/appcpu/zephyr/zephyr.elf for board: esp32_devkitc_wroom

https://www.espressif.com/sites/default/files/documentation/esp32-wroom-32_datasheet_en.pdf

3.1 CPUandInternal Memory ESP32-D0WDQ6 contains two low-power Xtensa® 32-bit LX6 microprocessors. The internal memory includes: • 448 KB of ROM for booting and core functions. • 520 KB of on-chip SRAM for data and instructions. • 8KB of SRAMinRTC, which is called RTC FAST Memory and can be used for data storage; it is accessed by the main CPU during RTC Boot from the Deep-sleep mode. • 8KB of SRAMin RTC, which is called RTC SLOW Memory and can be accessed by the co-processor during the Deep-sleep mode. • 1 Kbit of eFuse: 256 bits are used for the system (MAC address and chip configuration) and the remaining 768 bits are reserved for customer applications, including flash-encryption and chip-ID.

CONFIG_I2C=y
CONFIG_I2C_INIT_PRIORITY=60

CONFIG_SENSOR=y
CONFIG_SENSOR_ASYNC_API=y

CONFIG_MPU6050=y
CONFIG_MPU6050_TRIGGER_NONE=y

# CONFIG_BME280=y
CONFIG_BMP180=y

CONFIG_GPIO=y

# CONFIG_CBPRINTF_FP_SUPPORT=y

# CONFIG_STDOUT_CONSOLE=y
# CONFIG_PRINTK=y

CONFIG_LOG=y
CONFIG_LOG_MODE_DEFERRED=n
CONFIG_LOG_DEFAULT_LEVEL=1


CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
# CONFIG_SETTINGS_NVS=y
CONFIG_FLASH=y
CONFIG_NVS=y
# CONFIG_MAIN_STACK_SIZE=2048

Solution

  • The answer was provided by the Zephyr Espressif Discord group.

    In my build command I was targeting the APPCPU

    build\esp32_devkitc_wroom\esp32\appcpu
    

    I should have targeted the PROCPU which is the main boot core.

    Once changed the build was successful and showed the correct RAM value