Skip to main content
stm32f4
Associate III
September 4, 2019
Question

STM32CubeiDE + RTOS float problem

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

This topic has been closed for replies.

13 replies

stm32f4
stm32f4Author
Associate III
September 4, 2019

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

kurta999
Senior
September 4, 2019

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

I cannot help you more without additional information

stm32f4
stm32f4Author
Associate III
September 4, 2019

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

Dave Nadler
Senior III
September 4, 2019

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...

Ethan HUANG
ST Employee
September 9, 2019

@Dave Nadler​ 

Thanks for your solution. It helps.

Dave Nadler
Senior III
September 6, 2019

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

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

Please let us know!

stm32f4
stm32f4Author
Associate III
September 8, 2019

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
September 8, 2019

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.

Dave Nadler
Senior III
September 8, 2019

@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
Senior III
September 23, 2019

I've provided an updated version of the web page and code here:

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

@Markus GIRDLAND​ - Any status update?

Please let your architecture group know they're free to contact me for any clarifications or suggestions,

Thanks,

Best Regards, Dave