Good day. I have an espressif clone that uses NodeMCU-32s board and the arduino framework. When I try to upload my code to the board I am met with the following error:
Linking .pio/build/nodemcu-32s/firmware.elf
/Users/kstanl27/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/firmware.elf section `.dram0.bss' will not fit in region `dram0_0_seg'
/Users/kstanl27/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld: DRAM segment data does not fit.
/Users/kstanl27/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld: region `dram0_0_seg' overflowed by 156768 bytes
After searching through other topics on this forum, and other places across the search engines, I’ve seen where it’s an issue with the number of uninitialized static variables exceeding the size limit of the .bss memory space and to look in the corresponding .map file to see which variables are the offenders.
The problem I’m running into, and have had no luck finding how to solve, is that there does not seem to be a .map file generated by platformio, or if it is, it’s being auto-removed before I can look at it.
I am using CLion 2020.3 and the PlatformIO plugin 203.5981.106 from Jetbrains. This is my first C++ project, and my first time using PlatformIO; in other words, my apologies if I missed something otherwise simple or obvious. And if you need any other information from me, please let me know.
Thank you in advance for any assistance. I’m banging my head on the keyboard over here.
But there’s still some tricks to be used. We can ‘simply’ change the linker file and expand the size of the region dram0_0_seg so that it forcefully builds, and then take a look at what’s hogging up memory so badly.
After doing a verbose build, we see the final linker command (is huge)…
But we know it’s linked against esp32_out.ld. That is in the framework. So we open up the file C:\Users\<user>\.platformio\packages\framework-arduinoespressif32\tools\sdk\ld\esp32_out.ld and see…
that is ~124K available. See comment above on why that is so low.
Anyways, we change the len of that to something we know that fits (old size plus overflowed-by plus a little extra)
to the absolute path where my xtensa-esp32-elf-nm is (C:\Users\Max\.platformio\packages\toolchain-xtensa32\bin\xtensa-esp32-elf-nm). The thing was originally written for ARM. So I’ll just let it run on the .elf file…
C:\Users\Max\mbed-os-linker-report>elfsize.py -i C:\Users\Max\Documents\PlatformIO\Projects\dbuddy\.pio\build\nodemcu-32s\firmware.elf -b
C:\Users\Max\.platformio\packages\toolchain-xtensa32\bin\xtensa-esp32-elf-nm -l -S -C -f sysv C:\Users\Max\Documents\PlatformIO\Projects\dbuddy\.pio\build\nodemcu-32s\firmware.elf
[INFO] data written to C:\Users\Max\mbed-os-linker-report\html\data-flare.js
[INFO] opening in browser file://C:\Users\Max\mbed-os-linker-report\index.html
and we get nice graphs that show how memory is being used in flash (code, constant variables, …) and ram (bss, global initialized but modifyable variables, etc.)
and that thing is 256 kilobytes in its current config!! Much too large than what fits in the bss section for the ESP32 when using the Arduino-ESP32 linker script (and they probably put a lot of thought into that).
Now let’s modify what you have written in your config file…
to set that to (64*1024) and also revert the linker file hacks in esp32_out.ld and build again…
and it builds. Can LVGL work with that buffer space? No idea. But now you know why it doesn’t build.
Hint: The comment in the linker file section talks about how more memory may be available in the heap. So if static allocation in RAM doesn’t work, try LV_MEM_CUSTOM and do a heap alloc.
Even better, on a board with PSRAM, you can have a large buffer size allocated in PSRAM, if memory really is not enough in either stack or heap in the internal memory.
Wow. That was so much more than I could have ever expected. Thank you! There is so much to unpack from this that I will do my best to absorb as much from this as I can.
On another note, the LVGL project does have a nice PlatformIO demo project with a config file. And in there.
They do 32K. Even less than my 64K guess.
That project also takes advantage of PlatformIO’s native platform so it can build a desktop application (linked against SDL2), alongside the ESP32 and STM32F429ZI discovery board firmware.