cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS sprintf %f not working.

Jame DEV
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

> multiple definition of `_sbrk'

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

-- pa

View solution in original post

2 REPLIES 2
Pavel A.
Evangelist III

> multiple definition of `_sbrk'

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

-- pa

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