Reputation: 87
I have read a few older threads on this issue, and quite frankly the discussion flew over my head a bit. So I'm hoping for some help that I will hopefully be able to follow.
I am programming an STM32 with RTOS (two threads needed). It's a sensor application with some fairly intensive computation on the data gathered (hence the H7). Computation feedback is sent through CDC in the form of a char array, size 12. Nothing difficult. The computation feedback is a float. And this where I am having problems.
Prior to sending the data I need to convert the float to a char[].
my function looks like this:
void ASCII_transmitFloat(float value) {
uint8_t buffer[DEF_ASCII_TX_BUF];
snprintf((char *)buffer, sizeof(buffer), "%11.9f\n", value);
CDC_Transmit_FS(buffer, sizeof(buffer));
}
I am not getting an error, just a crash on the snprintf.
anyhow thanks for any help you can provide
cheers
edit:
Editing in response to the first response. I had the "use float with printf" option selected in the project properties (MCU settings) - see the screenshot below (not sure if this check box does the same as adding the flag manually) I tried adding the line -u _printf_float in the linked as suggested in your link, but I have the same results. Crashes when executing the snprintf.
Upvotes: 1
Views: 2786
Reputation: 1
This problem happened to me too. I'm not sure yours is same with mine but maybe it can help yoou. I just fixed it and the only thing i did is, i included "stdio.h". Then my warning gone.
Upvotes: 0
Reputation: 87
Here is how I fixed the problem. The problem is known, and ST hasn't fixed the issue since it was first brought up here a year ago, see: https://community.st.com/s/question/0D50X0000BB1eL7SQJ/bug-cubemx-freertos-projects-corrupt-memory and here's the recommended fix: http://www.nadler.com/embedded/newlibAndFreeRTOS.html
A bit over my head so I chose to go the route of using a lighter version of the printf function: https://github.com/mpaland/printf
I hope it helps someone else with the issue.
Cheers
Upvotes: 2
Reputation: 179
Probably because float support is not included by default using newlib. See printf floats with newlib on STM32
Upvotes: 1