I had created a very large project that was starting to consume too much RAM and needed to see where it was all going, and how to better optimise the use of the RAM…. I quickley learned no map file was being created in the Arduino IDE environment, so I search out the solution.

Below you will find the solution:

First locate the directory Arduino\hardware\espressif\esp32, this will be in different locations machine to machine, but start looking in your c:\Program Files or c:\Program Files (x86)

Next open the file called platforms.txt in Arduino\hardware\espressif\esp32

Next look for the line that reads ## Combine gc-sections, archives, and objects and change the line below it to:

recipe.c.combine.pattern=”{compiler.path}{compiler.c.elf.cmd}” {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -Wl,–start-group {object_files} “{build.path}/arduino.ar” {compiler.c.elf.libs} -Wl,-Map=arduino.map -Wl,–cref -Wl,-EL -Wl,–end-group -o “{build.path}/{build.project_name}.elf”

Save it and recompile your code with the “Verify” button in the IDE….

A file called arduino.map will appear in Users\Richard\AppData\Local\VirtualStore\Program Files (x86)\Arduino, replace “Richard” with your Windows Username…..

This came in very handy as I soon found RAM segments that I could have easily turned into constants with the const declaration, and then FLASH would have been used to store the variable and not RAM, example:

int variableOne; // this is in RAM

const int variableTwo; // this is in FLASH

When searching for RAM usage in the map file, look for the .dram0.data section and this is where all the RAM variables are held. You will see sections that look like:

.data.lastConnected
0x3ffc10c4 0x4 C:\Users\Richard\AppData\Local\Temp\arduino_build_730303\sketch\cdstick_2.ino.cpp.o
0x3ffc10c4 lastConnected

This is showing you a variable called lastConnected at memory location 0x3ffc10c4 taking 4 bytes and the variable resides in the file C:\Users\Richard\AppData\Local\Temp\arduino_build_730303\sketch\cdstick_2.ino.cpp.

This is a great tool to also see all the “behind the scenes” functions and variables that are hidden in the build…..

Hope this helps!

Any comments or questions?? Please leave them below….

RichardS

14 thoughts on “ESP32 Arduino: Creating a Memory Map file”

  1. I just needed this last week! Thanks! I was having issues with some variables getting over written unexpectedly, and when I look in the memory map I see that a buffer is right next to these variables that are getting over written, so its a buffer overflow. In a large project you would never know what buffer is overflowing without this.

    Good work!

    Tim

  2. This did not work for me.
    Any idea what this means:
    Using library SPI at version 1.0 in folder: C:\Users\Donald\Documents\Arduino\hardware\espressif\esp32\libraries\SPI
    Using library ESP32-TFT-Library-ILI9486 at version 0.0.0 in folder: C:\Users\Donald\Documents\Arduino\libraries\ESP32-TFT-Library-ILI9486
    Using library FS at version 1.0 in folder: C:\Users\Donald\Documents\Arduino\hardware\espressif\esp32\libraries\FS
    Using library SD at version 1.0.5 in folder: C:\Users\Donald\Documents\Arduino\hardware\espressif\esp32\libraries\SD
    exec: “\x94C:\\Users\\Donald\\Documents\\Arduino\\hardware\\espressif\\esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc\x94”: file does not exist
    Error compiling for board SparkFun ESP32 Thing.

    1. Weird almost looks like the \x94 at the start of the string before the c:\\ is not meant to be there….

      I think a \x94 is an escape character… check it out….

      RichardS

  3. i have a problem, when i compile it shown
    exec: “\x94C:\\Users\\Widya\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-gcc\x94”: file does not exist

    how to fix it? i compiled in arduino IDE windows 7

    Thanks,
    widya

  4. AppData\Local\Temp\arduino_build_251116/arduino.ar: No such file or directory

    Also arduino.map is not reflecting in – > virtual store\\Program Files (x86)\Arduino. Arduino folder is created in virtual store

    1. You now need to find:

      platforms.txt Next look for the line that reads ## Combine gc-sections, archives, and objects

      then add

      -Wl,-Map=arduino.map after start-group

      RichardS

  5. How to get memory layout of esp32 for arduino platform.?
    I’m not getting the above mentioned path in my system.

    Please help me with the solution.

    1. Found the file. Did the edit and the added bit above.

      recipe.c.combine.pattern=”{compiler.path}{compiler.c.elf.cmd}” {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -Wl,–start-group -Wl,-Map=arduino.map {object_files} “{build.path}/arduino.ar” {compiler.c.elf.libs} -Wl,-Map=arduino.map -Wl,–cref -Wl,-EL -Wl,–end-group -o “{build.path}/{build.project_name}.elf”

      Is this correct?

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha loading...