STM32L011D4 / Arduino_Core_STM32 / platformIO : region `RAM' overflowed

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
Lupin
Posts: 2
Joined: Fri Sep 05, 2025 11:22 am

STM32L011D4 / Arduino_Core_STM32 / platformIO : region `RAM' overflowed

Post 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.
ag123
Posts: 1935
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

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

Post 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.
GonzoG
Posts: 507
Joined: Wed Jan 15, 2020 11:30 am
Answers: 36
Location: Prudnik, Poland

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

Post 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
Lupin
Posts: 2
Joined: Fri Sep 05, 2025 11:22 am

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

Post by Lupin »

I was just really astonished, because the functionality would easily fit in an ATmega328, the typical "Arduino-chip". I just wanted the higher resolution, higher speed ADC and higher clock speed without external crystal of the STM32. The chip should go into a cheap, small series (first batch <1000 pieces) product, where MCU cost makes at least some difference, which is why I started from the low end.

I have disabled a few of the modules (e. g. I2C, SPI, DMA) already, but that didn't make much of a difference, especially when it comes to the RAM usage. Seems like there isn't much that enabled, but unused features add to the bulk.

I had hoped that most of the cross compatibility code is guarded behind the MCU model #defines and wouldn't make it into the compiled binary.

Is there a way to know what module wants all the RAM? I mean there's pretty much only the ADC and timer functionality I'm using left, neither of which should need anywhere close to 2kB of RAM.
ag123
Posts: 1935
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

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

Post by ag123 »

Among the things, try building with CMake
viewtopic.php?t=2563

And working on a custom trimmed copy of the core. It is possibly easier doing that with CMake

A thing is, stm32duino STM core worked a challenge to have it running on a large practically nearly full portfolio of STM32 MCUs many series
f0, f1, f2, f3, f4, f7, h7, g0, g4, h5, l0, l4 etc and actually more e,.g. wb55 (bluetooth LE) a very large portfolio, probably 100s of individual part numbers
this in itself is no easy feat, it took many years to reach this maturity.
https://github.com/stm32duino/Arduino_Core_STM32
it'd be difficult to have the codes trimmed as in built for a specific MCU.
The other thing is a good part of the Arduino API is supported out of the box including analog (Read ADC (and Write DAC) ), just the ADC alone which actually have a large portfolio of settings, features and differences across the different series

Hence, to 'shrink' it significantly, you may need to resort to working a custom core / build.
And I think it could be simpler going the CMake route.

platformio would probably do quite similar too, but the idea is to work a custom core with that.

to stay on small mcus, it may help to select a somewhat bigger part number with more flash and ram , and it may help to fit the binary with much less rework, to possibly simply rebuilding with some options may fit things in with adequate flash and sram.
fpiSTM
Posts: 1969
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

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

Post by fpiSTM »

Will check tomorrow if possible to reduce RAM
fpiSTM
Posts: 1969
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

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

Post by fpiSTM »

fpiSTM wrote: Sun Sep 14, 2025 3:05 pm Will check tomorrow if possible to reduce RAM
Unfortunately, hard to use all features you want.
As stated by @ag123 and @GonzoG the core have to support several series and so this requires some extra code.
I would recommend a bare metal code using only LL or registers access like this you should be able to achieve all what you want.
Post Reply

Return to “General discussion”