Skip to main content
darla14
Associate III
March 8, 2016
Question

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

  • March 8, 2016
  • 5 replies
  • 2849 views
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
    This topic has been closed for replies.

    5 replies

    Nesrine M_O
    Associate
    March 8, 2016
    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
    Senior III
    March 8, 2016
    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
    March 8, 2016
    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
    March 8, 2016
    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.

    Tesla DeLorean
    Guru
    March 8, 2016
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..