Skip to main content
CBarb.1
Associate II
February 26, 2023
Question

I Cannot seem to find a way to do a serial print of a floating number with NUCLEO-C031C6?

  • February 26, 2023
  • 4 replies
  • 1683 views

I am using the NUCLEO-C031C6 dev board and I seem to be having many difficulties. I am trying to do a printf() or use a sprintf() method to print a float number to the serial port. I noticed that this controller device(STM32C031C6T6) does not have an FPU and when I try to enable the linker flag -u_printf_float I automatically get a compilation error: "Nucleo_C031_FirstTest.elf section `.text' will not fit in region `FLASH'

\tools\arm-none-eabi\bin\ld.exe: region `FLASH' overflowed by 8676 bytes

collect2.exe: error: ld returned 1 exit status" I am not sure how to circumvent this? Is there a way to increase the allocation for FLASH? I tried changing the HEAP and STACK sizes but that has no effect. I am sure this device should be able to handle the extra code to do a printf of a float value? Once again any help or suggestions are greatly appreciated. I have attached my project file here

This topic has been closed for replies.

4 replies

Tesla DeLorean
Guru
February 26, 2023

It should have 32KB of FLASH, and that should be described in the Linker Script

Floating Point libraries take up space, but I have them in some 16KB parts.

Perhaps it's your other code that is the issue?

Perhaps try the Keil compiler. It has a free license for STM32 CM0(+) parts

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
AScha.3
Super User
February 26, 2023

and set optimizer to -Os or -O2 .

If you feel a post has answered your question, please click on " Best Answer ".
AScha.3
Super User
February 26, 2023

i just tried on F030 : opt. -Os :

(old) prog 7.2kB ;

with float + printf(..float) 11kB overflow.

with float (but no printf float lib) 11.4 kB ;

so you can use float , but for print must put the float in some int by subtract+multiply and put the print chars for float together yourself.

If you feel a post has answered your question, please click on " Best Answer ".
S.Ma
Principal
February 27, 2023

There are alternative to float for saving code size and core bandwidth.

Here are some example for STM32C03 on STM32C0316-DK just using for example int32_t Temperature_degC_x10 with corresponding custom printf to show like "27.5". There is a printf for the 16x2 LCD and the reporting on Bluetooth Electronics Android app using USART to SPP HC-06 dongle.

Otherwise there is the Q31 fractional bit representation in 32 bit variables elements that was used in the past in mobile phone drivers.