cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to print(printf) float values in STM32L4/F4

darla14
Senior
Posted on March 08, 2016 at 09:27

I am using STM32L476RG/F401RE nucleo board and trying to view the output of printf of float value on the terminal I/O.I am using IAR.

But what  I am getting is this : 

value = %f

for the below code : 

float value = 168/21617.0

printf(''value = %f '' ,value) ;

I am already using the semihosting option ticked.Is there any specific setting/condition?

It doesn't happens with STM32F29I Disco.

Br.

Rp

#!stm32 #rtfm
5 REPLIES 5
Nesrine M_O
Lead II
Posted on March 08, 2016 at 12:18

Hi Rp,

Be sure that you use the right settings: Project>Options>General Options>Print formatter: try to select

Large without multibytes

option The code:

float
value=168/2160;
printf( 
''%f
''
,value) ;

The Output of the terminal I/O: 0.007772 -Syrine-
AvaTar
Lead
Posted on March 08, 2016 at 13:41

>Be sure that you use the right settings: ...

 

To be more precise, in ''project options''->''General Options''->''Library options'', ''Printf formatter'', you need to specify ''Large'' of ''Full''. Otherwise, you get no floating point support for the printf() function family.

connectjagadeep
Associate II
Posted on March 08, 2016 at 18:26

Could you please let me know the similar settings for AC6 Studio ? I too have difficulty with float value to convert in snprintf function. 

I use STM32F7Disco. 

Regards,

Jagadeep.

cbenson
Associate
Posted on March 08, 2016 at 18:45

Also, make sure that your stack pointer is initialized to an address which is a multiple of 8, otherwise a floating point value will not be passed to printf correctly.

Posted on March 08, 2016 at 19:34

Also, make sure that your stack pointer is initialized to an address which is a multiple of 8, otherwise a floating point value will not be passed to printf correctly.

 

Yeah, I'm pretty sure that's not a hard rule for most Cortex-Mx parts, where 4-byte alignment is workable for LDRD. The Cortex-M0 is the most problematic, where everything needs alignment. The current F7 also doesn't support doubles in hardware.

A lot of GNU/GCC platforms have this kind of idiocy in the linker scripts, which is like a goddamn cancer spread all over the place.

_estack = 0x2002FFFF;    /* end of RAM */

http://www.openstm32.org/Using+CCM+Memory?structure=Documentation

The top of memory would be 0x20030000, the stack pre-decrements.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..