float in sprintf

Sysprogs forums Forums VisualGDB float in sprintf

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #722
    alireza.r
    Participant

    hello every one i tried to use sprintf and change a float variable to chars in visual stdio via VisualGDB
    like:

    float a;
    char b[5];

    sprinf(b,”%f”,a);

    but it make hard fault in micro(stm407), how i can active float variable in sprintf or printf ?

    #2897
    ket
    Participant

    Hi,

    Please read our STM32F4 tutorial on the topic for hints:
    http://visualgdb.com/tutorials/arm/stm32/fpu/

    #2896
    alireza.r
    Participant

    thanks for your replay
    but my problem is with hardware floating point. if i use software floating point the program run correctly
    but when chose hardware floating point the hard fault occur.

    Note that -mfloat-abi=hard has been added to GCC flags correctly

    i use sprintf(..) and in Disassembly it is vcvt.f64.f32
    how can i solved this problem.

    #2894
    support
    Keymaster

    Hi,

    This problem means that the standard C library has been compiled in a way that treats the ‘%f’ format in a way that uses the double type. We would recommend simply using an alternative implementation of sprintf() from some open-source library and tweaking it so that it only uses the float type.

    #2895
    alireza.r
    Participant

    thanks for your replay bazis

    but i have this problem with float variable too.
    i readied this link before
    http://visualgdb.com/tutorials/arm/stm32/fpu/

    and i understood that this problem occre with double type but i just use float not double
    and i have this problem.

    #2893
    support
    Keymaster

    Hi,

    The problem is that printf() inside itself uses ‘double’. Although you pass a float there, it reads ‘%f’ in your string and somehow converts it to double. You cannot change this behavior by modifying your program as it is located inside the printf() that is a part of the standard library. You could either modify the standard library used by GCC (which is somewhat cumbersome), or simply use another open-source implementation of printf() (there should be plenty of those available online).

    #31375
    Reza1757
    Participant

    Hi

    I’m using vidualGDB for programming on STM32 microcontroller with visual studio 2019.

    When I want to convert float into string with sprintf() function then it seems doesn’t work.

    I want puts a buffer array on LCD but when I puts it float variable doesn’t visible…

    I saw just characters and no number.

    #31376
    Reza1757
    Participant

    Hi

    I had this problem and this link was useful.

    https://visualgdb.com/tutorials/arm/stm32/fpu/

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.