cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L031 region `FLASH' overflowed by 5416 bytes when adding -u printf_float flag

LPetr.1
Senior

Hello. In my project, I would like to printf float type variables such as:

 

 

			 float t_degC = -45 + 175 * t_ticks/65535;
			 float rh_pRH = -6 + 125 * rh_ticks/65535;

			 printf("t_degC = %.2f \n",t_degC);
			 printf("rh_pRH = %.2f \n",rh_pRH);

 

Initially, I had the following error:

LPetr1_1-1695030115374.png

So I have enabled the flag as suggested by the warning:

 

LPetr1_0-1695030075938.png
After adding this flag, I can no longer compile my project as I am getting the following errors:

 

c:\st\stm32cubeide_1.10.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: SHT40_test.elf section `.text' will not fit in region `FLASH'
c:\st\stm32cubeide_1.10.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: region `FLASH' overflowed by 5416 bytes

 

This is quite strange since my project is pretty much blank. I only have a couple lines of code and it says that it cannot fit in the FLASH section? What is up with the linker flag that I have added to allow printf float variables?

 

Is it normal that a almost blank project for STM32L031 already uses more than 60% of total flash memory?

LPetr1_0-1695030587141.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Printing floats is quite complicated and consumes lots of resources, both FLASH and RAM. Choose an STM32 with larger FLASH or don't use/print floats.

One way to avoid floats is to use fixed decimal point - simply scale all your variables by 100.

JW

 

View solution in original post

4 REPLIES 4

Printing floats is quite complicated and consumes lots of resources, both FLASH and RAM. Choose an STM32 with larger FLASH or don't use/print floats.

One way to avoid floats is to use fixed decimal point - simply scale all your variables by 100.

JW

 

TDK
Guru

You can also use more aggressive optimization which will reduce code size. In general, STM32CubeIDE isn't created with small executables in mind, but it can work.

I created a nearly-blank project in STM32CubeIDE for that chip and the Debug file size is under 5 kB. You must be adding something else to increase the size.

TDK_0-1695040192871.png

Edit: nope, apparently using printf with floats just adds like 20kB to flash size. Crazy.

If you feel a post has answered your question, please click "Accept as Solution".
GLASS
Senior

Use nanolib and not full libc.

Try to use fixed point arithmetic as sayed by Jan.

If you really can't avoid float, you must  be sure that const are float and not double. To do that you MUST add after each const float value a 'f' letter.

For example :

float t_degC = -45.0f + 175.0f* (float)t_ticks/65535.0f;

But for sure you can use integer only...

 

 

Thanks for all the responses. I would have never thought that using printf floats are so complex and requires 10's of KB's of FLASH memory.

 

For now, I just use integer like below:

 

			 float t_degC = -45.0f + 175.0f * ((float)(t_ticks/65535.0f));
			 float rh_pRH =  -6.0f + 125.0f * ((float)(rh_ticks/65535.0f));
			 uint32_t t_degC_to_int = (uint32_t)(t_degC * 100.0f);
			 uint32_t rh_pRH_to_int = (uint32_t)(rh_pRH * 100.0f);