2025-05-09 7:45 AM
Hi everyone,
I’m using a MacBook with an Apple M1 chip running macOS Sequoia 15.2. I recently updated STM32CubeIDE to version 1.18.1.
My target board is a Nucleo-32 STM32L031K6T6. Initially, I created a new project using STM32CubeIDE and, without modifying anything, successfully debugged the automatically generated code. I noticed that the .elf file was correctly generated in the Debug folder.
Then, I added a very simple code snippet to send a value over the serial port, just to test functionality. However, when I ran the code, I got the following error:
/Applications/STM32CubeIDE.app/.../ld: oc4.elf section `.text' will not fit in region `FLASH'
/Applications/STM32CubeIDE.app/.../ld: region `FLASH' overflowed by 6884 bytes
collect2: error: ld returned 1 exit status
make: *** [makefile:64: oc4.elf] Error 1
After this error, the .elf file disappeared from the Debug folder. It seems that STM32CubeIDE generates the .elf file initially but deletes it after.
Has anyone experienced this issue before? How can I solve this problem?
Thanks in advance!
Solved! Go to Solution.
2025-05-09 3:37 PM - edited 2025-05-09 3:38 PM
If your program is too large to fit into flash, compilation will not complete and the ELF will not be generated.
You will need to reduce the code size in order to compile the program. One way to do this is to switch to the Release configuration, although this makes the code harder to debug as things are optimized away.
The STM32L031K6T6 only has 32 kB of flash, which is rather restrictive. The HAL library wasn't really set up with this amount of limited resources in mind.
2025-05-09 3:37 PM - edited 2025-05-09 3:38 PM
If your program is too large to fit into flash, compilation will not complete and the ELF will not be generated.
You will need to reduce the code size in order to compile the program. One way to do this is to switch to the Release configuration, although this makes the code harder to debug as things are optimized away.
The STM32L031K6T6 only has 32 kB of flash, which is rather restrictive. The HAL library wasn't really set up with this amount of limited resources in mind.
2025-05-10 7:42 AM
To reduce the program size, try: set optimizer -O2 , then compile.
2025-05-10 8:36 AM
Sometimes, STM32CubeIDE defaults to incorrect settings. Check the following:
Open .ioc file
Go to Project Manager → Project Settings → MCU Settings
Make sure the selected device is: STM32L031K6Tx and the memory size is 32 KB Flash, 8 KB RAM
2025-05-12 9:09 AM
@AScha.3 wrote:To reduce the program size, try: set optimizer -O2 , then compile.
@Tunahan Before that, I'd try 'Optimise for Debug (-Og)'
This should give you the best compromise between optimisation & "debuggability"
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-Og
2025-05-12 9:12 AM - edited 2025-05-12 9:12 AM
@TDK wrote:If your program is too large to fit into flash, compilation will not complete and the ELF will not be generated.
^^ This! ^^
@TDK wrote:You will need to reduce the code size in order to compile the program. One way to do this is to switch to the Release configuration, although this makes the code harder to debug as things are optimized away.
@Tunahan Or set your Debug configuration to use -Og - see my earlier reply.