Available SRAM in ESP-WROOM32

Why is there only 320 KBytes of SRAM set in most default board files that target an ESP-WROOM32 device when ESP-WROOM32 device’s have 520 KBytes of internal SRAM?

A few references:

I can increase the RAM size by tweaking the *.json file associated with the target board (or create my own and use a custom board file). However, I notice that there is no check to see if the amount of RAM space allocated by the linker actually fits in the target device when loading the code into the target ESP32.

I apologize if this is available somewhere on the interwebs and possible even within these forums. The answer to this question has presented itself after a fair amount of digging through posts, guides, and running through files in the PlatformIO installation directory on my PC.

Also, the reason I’m digging into this at all is because I am looking at doing one or a few of the following:

  1. Free up RAM by disabling unused pieces of libraries/core code that may be getting built into the image even though they have no use.
  2. Free up RAM by optimizing buffers used throughout the program (non-app code, libraries and core code).
  3. Gain access to 520 MBytes, or at least more, RAM instead of the default 320 MBytes.

Something worth mentioning: the board cannot be altered which means external RAM cannot be added to the ESP32.

** kBytes

The ESP32 is a harvard-architecture type core, not a Von-Neumann. Data and instruction are seperate. Refer to the technical datasheet. There you’ll see

Make sure to read the comments in the datasheet, some memory regions are switchable (remappable), some of the RAM can be dedicated to a cache for external mem, and there’s RTC specific memory.

But the important info here is that there is IRAM (instruction RAM) and DRAM (data RAM). Also SRAM = SRAM0 + SRAM1 + SRAM2 = 192 kB + 128 kB + 200 kB = 520 kB. However only SRAM1 and SRAM2 and be used for DRAM.

So when you have a data buffer in the firmware of say 300 kB, that data buffer can only be allocated in the 320kB DRAM. You can only put functions / instruction code in IRAM via the IRAM_ATTR

https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/include/esp32/esp_attr.h#L26

Which is used on numerious functions and every interrupt service routine, those must be in IRAM.

I think PIO only tells you the more common DRAM usage (thus, 320kB is correct). The linker script should however trip an error if you go over the maximum DRAM or IRAM.

1 Like

Gah, thank you very much