Skip to main content
Visitor II
November 29, 2019
Solved

FreeRTOS sprintf %f not working.

  • November 29, 2019
  • 1 reply
  • 1420 views

I'm working on STM32F746 Discovery try to use STemWin. I using cubeMX to gen code for cubeIDE. But i'm stuck, sprintf %f not working. It's return 0x00 and dot instead. For example

char str[32];

float a = 123.456;

sprintf(str, "%f", a);

the result

str[0] = 0x00

str[1] = 0x00

str[2] = 0x00

str[3] = 0x26 '.'

str[4] = 0x00

str[5] = 0x00

str[6] = 0x00

Then i try to test whats wrong. I tried to gen a project without freeRTOS and test sprintf %f. And it's work fine.

Then i found this http://www.nadler.com/embedded/newlibAndFreeRTOS.html

I try to follow this step.

·        Exclude from all builds any current FreeRTOS heap implementation, typically something like:

·        Middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c

·        Add the module 

·        heap_useNewlib.c

·         I've provided.

·        If your application needs a complete 

·        snprintf

·         

·         implementation, 

·        strtok

·         

·        , or other newlib functions requiring reentrancy support, or you're not really sure...

·        Configure FreeRTOS for newlib support. In 

·        FreeRTOSconfig.h

·        , add the line:

·        #define configUSE_NEWLIB_REENTRANT 1

but it error: heap_useNewlib.c:(.text._sbrk+0x0): multiple definition of `_sbrk'

How to fix sprintf %f problem?

    This topic has been closed for replies.
    Best answer by Pavel A.

    > multiple definition of `_sbrk'

    So you have another instance of _sbrk somewhere else, in sysmem.c or syscalls.c. Delete it.

    -- pa

    1 reply

    Pavel A.Answer
    Super User
    November 29, 2019

    > multiple definition of `_sbrk'

    So you have another instance of _sbrk somewhere else, in sysmem.c or syscalls.c. Delete it.

    -- pa

    Jame DEVAuthor
    Visitor II
    November 29, 2019

    Thank you. You are the best. It's work now.