Page 1 of 1

STM32L011D4 / Arduino_Core_STM32 / platformIO : region `RAM' overflowed

Posted: Fri Sep 05, 2025 6:46 pm
by Lupin
When I try to build the firmware for an L011D4 (16kB flash/2kB RAM) I get a "section '._user_heap_stack' will not fit in region 'RAM'" and "region `RAM' overflowed" error even on an empty project (empty Arduino setup() and loop() functions).

What do I need to do to get around this? I can't believe an empty project already fills up 2kB of RAM just for the Arduino core. If there really IS something demanding that much RAM, how could I find out what it is? I know there's also the ldscript.ld file, but I don't dare yet to change anything there, because I don't know what I'm doing ;) .

In the end the MCU should just react to two buttons, control two LEDs, read two ADC channels and control a PWM output based on that. I also need a calibration value, which is why I chose the L011D4 in the first place (it's one of the few with an EEPROM). The L011D4 should be plenty for that.


My project is configured as follows. I am using Visual Studio Code with platformIO for all my MCU (STM32, AVR, ESP32) programming, usually always with the Arduino framework. platformIO does not have a board definition for a generic L011D4, so I created a custom one based the "nucleo_l031k6" board. I just changed the lines

Code: Select all

"extra_flags": "-DSTM32L0 -DSTM32L031xx",
"mcu": "stm32l031k6t6",
"product_line": "STM32L031xx",
"variant": "STM32L0xx/L031K(4-6)T_L041K6T"
to

Code: Select all

"extra_flags": "-DSTM32L0 -DSTM32L011xx",
"mcu": "stm32l011d4p6",
"product_line": "STM32L0x1",
"variant": "STM32L0xx/L011D(3-4)P_L021D4P"
I also created the respective board variant folder to define custom clock settings. For that I copied the "variants/STM32L0xx/L011D(3-4)P_L021D4P" of Arduino_Core_STM32 and made changes to "WEAK void SystemClock_Config(void)" (code created with CubeMX) and then pointed platformIO to that directory (essentially overriding the variant-line in the board definition file). I know this procedure works, because I've done the same with a F103CB to create a board variant that uses the internal oscillator.

Re: STM32L011D4 / Arduino_Core_STM32 / platformIO : region `RAM' overflowed

Posted: Sat Sep 06, 2025 3:16 am
by ag123
well, use a 'bigger' chip e.g.
https://www.st.com/en/microcontrollers- ... 030f6.html
actually, even this is pretty 'squeezy'.
a recommended chip / board is
https://github.com/WeActStudio/WeActStu ... iSTM32F4x1
this has well enough resources sram, flash to run comfortably and is fast due to the 'Art accelerator' on chip cache and FPU.

A thing is the core package a lot of functionalities ADC, gpio, uart etc and has codes for cross series compability.
Inevitably, it needs space (sram, flash) to run.

running on very small 'squeezy' chips may too easily hit the limited resources sram, flash.
And you may need to compile manually trimmed custom core for it.

Re: STM32L011D4 / Arduino_Core_STM32 / platformIO : region `RAM' overflowed

Posted: Sat Sep 06, 2025 10:13 pm
by GonzoG
With all options enabled stm32duino will need quite a lot of flash and RAM.
It's because it's made to be easy to use and not resource efficient.
You can disable unused peripherals and this will save some flash and ram:
https://github.com/stm32duino/Arduino_C ... figuration