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
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
I used it for the exact same reason also… very useful.
RichardS
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.
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
Thank You for your time and knowledge.
Don
I had the same issue. I removed: –cref -Wl,-EL -Wl,
then it works
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
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
Things have changed a bit since I wrote this….
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
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.
Win10
IDE 1.8.13
I don’t find platforms.txt Is there a new file name perhaps?
Thanks
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?
They keep changing things in the IDE so it make it hard to keep up 🙂