Blink uses 97% of program storage space

Development environment specific, Arduino, Eclipse, VS2013, Em::Blocks etc
Post Reply
calebjnz
Posts: 5
Joined: Sat May 20, 2023 1:34 am

Blink uses 97% of program storage space

Post by calebjnz »

Hi there,

I have been successfully uploading code to a Nucleo-32 board until a little while ago. Now sometimes when I compile the code I get this error saying the flash has been exceeded. I compiled Blink and it worked, but it said it used 97% of the program storage space. It seems like every time I compile a new sketch, the program storage of the previous sketches gets added to the compiler's calculations.

Here is what I'm using:
Nucleo-32 STM32L031K6
Arduino IDE 2.1.0
Windows 11
Arduino_Core_STM32 v2.5.0

Here is the part of the compiler output for blink

Code: Select all

Using library SrcWrapper at version 1.0.1 in folder: C:\Users\64204\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.5.0\libraries\SrcWrapper 
"C:\\Users\\64204\\AppData\\Local\\Arduino15\\packages\\STMicroelectronics\\tools\\xpack-arm-none-eabi-gcc\\12.2.1-1.2/bin/arm-none-eabi-size" -A "C:\\Users\\64204\\AppData\\Local\\Temp\\arduino\\sketches\\43FC912ACB8ECD750B945ECE697AA47A/Blink.ino.elf"
Sketch uses 31876 bytes (97%) of program storage space. Maximum is 32768 bytes.
Global variables use 1412 bytes (17%) of dynamic memory, leaving 6780 bytes for local variables. Maximum is 8192 bytes.
1 File(s) copied
Upload complete on NODE_L031K6 (F:)
Here is the error message for compiling the default basic example "Fade"

Code: Select all

c:/users/64204/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\64204\AppData\Local\Temp\arduino\sketches\2835662659F8FBB1FB8069AC10B587E7/Fade.ino.elf section `.text' will not fit in region `FLASH'
c:/users/64204/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld.exe: region `FLASH' overflowed by 6540 bytes
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1
I have been previously uploading sketches that use the default Arduino SD library as I'm working on a data logging project. These sketches had been working. I'm not sure if this has any relevance.

Any help would be greatly appreciated:).
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Blink uses 97% of program storage space

Post by ag123 »

well for an easier life use a nucleo-f401re instead
https://www.st.com/en/evaluation-tools/ ... 401re.html

STM32L031K6
has a mere 32k flash 8 k sram
https://www.st.com/en/microcontrollers- ... 031k6.html
and you are trying to do SD card apps, requires a lot of flash and most importantly needs more (lots of) sram.

a bigger chip like say with stm32f401re (on the nucleo board) has plenty of sram
https://www.st.com/en/microcontrollers- ... 401re.html
and you would face much less challenges trying to squeeze an elephant into a mouse hole.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Blink uses 97% of program storage space

Post by fpiSTM »

You can do some optimization to reduces spaces depending of your needs: https://github.com/stm32duino/Arduino_C ... tes-of-ram

In your case you should not disable SPI and optimizes SPI pinmap array:
https://github.com/stm32duino/Arduino_C ... nmap-array
calebjnz
Posts: 5
Joined: Sat May 20, 2023 1:34 am

Re: Blink uses 97% of program storage space

Post by calebjnz »

Hmm, I might need to upgrade to a better board. I chose this board because it is low power - the data logger is battery-powered.

The problem is not with the sketch size, because the memory is exceeded just when compiling Fade, which looks like this:

Code: Select all

/*
  Fade

  This example shows how to fade an LED on pin 9 using the analogWrite()
  function.

  The analogWrite() function uses PWM, so if you want to change the pin you're
  using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
  are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
*/

int led = 9;         // the PWM pin the LED is attached to
int brightness = 0;  // how bright the LED is
int fadeAmount = 5;  // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

Previously, the IDE was compiling much larger sketches. But now it can't even compile Fade and barely has the room to compile Blink. I think there might be an error in the compiler. It looks like the calculated sketch size is the accumulation of the previously compiled sketches.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Blink uses 97% of program storage space

Post by fpiSTM »

You probably used STM32 core version 1.x before. Now 2.x provides access to all peripherals for all pins which increase the size in flash.
Anyway as stated before you can reduce this size using some customization.
calebjnz
Posts: 5
Joined: Sat May 20, 2023 1:34 am

Re: Blink uses 97% of program storage space

Post by calebjnz »

It got fixed somehow.

I compiled the code for a different board and then compiled it again for the board I had and it worked. I am not 100% sure if this solved the problem, or if it was something else I did. I could have upgraded the version, but I am unsure. I might have downloaded the wrong version via a link in an old tutorial when setting up stm32duino. I really don't know.

Thanks for the suggestions.
calebjnz
Posts: 5
Joined: Sat May 20, 2023 1:34 am

Re: Blink uses 97% of program storage space

Post by calebjnz »

Yup, compiling it for a random generic stm32 MCU and recompiling it solves the issue. The issue only pops up every 10 or so compiles. It might be a problem for only my computer. I'm happy to just live with it.
Post Reply

Return to “IDE's”