ESP32 Memory usage?

Hi All,

When I program a PIC controller, MPLAB IDE has a memory usage gauge, to indicate how much memory my code is using up. Is there anything like this for ESP32 ?

Thank you,

Trevor

I’ve tried Serial.println(ESP.getFreeHeap()); and got this serial monitor output.

Using ESP32-WROOM-32U WROVER Module

What does this mean ?

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4
342620

the ESP32 has an internal SRAM of about 512KB, but only around 320KB is usable for the heap

exactly your number is 334kB based on how optimal is arduino config…

Thanks for the reply,
I’m trying to gauge the size of my code and thus, whether I’ll run into memory limits, as I develop further.
So free heap = 342620 / 1024 = 334kB.
Does this mean I’ve used 512 - 334 kB = 178kB for my code ?
Trevor

Did a bit of Googling and found a post detailing the POI built in Program Memory Usage calculator, which looks ideal.
Looked in Platformio/Project tasks/nodemcu-32s/Platform and clicked PROGRAM SIZE.
However, I got the following results …

PLATFORM: Espressif 32 (6.12.0) > NodeMCU-32S
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash

Calculating size .pio\build\nodemcu-32s\firmware.elf
   text    data     bss    dec         hex filename
 292757  115956    5953  414666   653ca .pio\build\nodemcu-32s\firmware.elf

I’m now even more confused.
If my program uses 414666 bytes (404.94 kB), how does it fit into 320kB of RAM ?

There is RAM and FLASH memory. Which one are you talking about and what are your concerns?

HI Boris,
Hope you are well ?
I’m sure it’s far more complicated than my current understanding of this subject.
I’m just trying to work out how much memory space is available, for the rest of my project development, which might double the size of my code.
I read a post the other day about someone running out of memory on an ESP32 project and I suddenly thought “oooops, I haven’t considered that !”
So, I now have those numbers, but don’t understand what they mean.
I can’t find a clear explanation of those numbers.

After uploading my code to the ESP32, I read the following at the bottom of the terminal window …
Wrote 407152 bytes (239574 compressed) at 0x00010000 in 6.0 seconds (effective 540.7 kbit/s)...
Does this mean “233.95KB of 520KB used” ?
i.e. 286KB still available ?

Even it is for Arudino and not special for ESP32 but the basics are the same: Please take a look at Arduino Memory Guide | Arduino Documentation to get the basics.

No, because this is about how much of the FLASH is used. The available FLASH memory on an ESP32 depends on how much memory the physical FLASH chip provides and the used partition layout.

Basically: The code you write goes into FLASH memory. Every variable your sketch is using goes into RAM.

Ooooh very interesting reading, a lot clearer than other things I’ve found, thanks Boris. Think I understand a bit better now.
Interesting to read the “String Wrapper” section about using the F() string wrapper in “Serial.print” or “Serial.println” instructions, to free up SRAM space. But, why have I not seen this in any tutorials or code examples ?

Aha, I see now, thank you.

That’s where differences between ESP32 based and AVR based arduino projects kicks in.

On an ESP32 you don’t need the F() macro or PROGMEM.

Every day is a school day.
Thanks for your help Boris, much appreciated.

I have found some information, to answer my own question, people might find useful.

  1. During project build, the terminal window does give memory usage information, if you scroll
    back through it.
    My current project gives this …
Retrieving maximum program size .pio\build\nodemcu-32s\firmware.elf
Checking size .pio\build\nodemcu-32s\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:    [=       ]   7.6% (used  25040 bytes from  327680 bytes)
Flash:  [===     ]  32.0% (used 419781 bytes from 1310720 bytes)
  1. I’ve also discovered in Platformio “HOME”, the “Inspect” function gives the same information.

Trevor