cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeiDE + RTOS float problem

stm32f4
Associate II

Hi all.

i have problem using float and double in mytest application.

I hjave an aplication generated using stm32cubeide Version: 1.0.2

Build: 3566_20190716-0927 (UTC), CUBEMX ver 4.21.0.

Application use FreeRTOS Kernel V10.0.1 and task.

in a task i read temperature valu from a sensor and try to set the value in a variable.

Variable contain garbage but with debug i can see rigth value returned from sensor.

i cannot get hint from google search.

Someone ha the same problem? may you suggest same?

Regards,

Carmelo GAllucci

13 REPLIES 13
stm32f4
Associate II

i can add also that prinf of float give me hard fault.

kurta999
Senior

For printf, try this include: https://github.com/mpaland/printf

I cannot help you more without additional information

stm32f4
Associate II

thanks i will try to avoid hardfault with printf.

Some other info:

i have this code:

float currtempvalue = MPC9808_getTemperature();

 float  currtempres= MPC9808_getResolution();

   printf("MPC9808: temperature %f - resolution %f \r\n",currtempvalue ,currtempres);

whit debug i can see that MPC9808_getTemperature() return, correctly 28.5 but currtempvalue is assigned with garbage.

I try also to modify ftos aligment (from 8 to 4) as MCU. nothing changed.

Regards,

carmelo

The reason for your hard-fault in printf is explained here:

http://www.nadler.com/embedded/newlibAndFreeRTOS.html

@Markus GIRDLAND​ (ST Employee) - Yet another example of your customers getting tripped up by STM's incorrect newlib integration...

@stm32f4​ - Carmelo, did this fix your problem??

http://www.nadler.com/embedded/newlibAndFreeRTOS.html

Please let us know!

stm32f4
Associate II

hello Dave. Sorr for delay.

Yes i do.Thanks so much for you hint. I did exacle what you suggest with link.

I fix also the garbage behavior. It was my mistake. i did not include the correct .h in mai main. Compiler not complain at all only a warning. afte that all work correctly.

Thank a lot.

Carmelo

mal h
Associate II

do you already use this ?

The float formatting support is not enabled, check your MCU Settings from "Project Properties > C/C++ Build > Settings > Tool Settings", or add manually "-u _printf_float" in linker flags.

@mal h​ - If you read Carmelo's reply above, he has everything working now.

So yes, he is using the correct linker flags, in addition to the heap_useNewlib I provided...

@Dave Nadler​ 

Thanks for your solution. It helps.