2019-08-12 01:48 AM
Used cube to generate a project with default settings for STM32F429I disco board plus CMSIS V2 RTOS and USART 2 half duplex transmit only . Generated the code for System Workbench.
I retargeted _write() and provided __io_putchar(). I added -u _printf_float to the linker flags.
In the StartDefaultTask I added
float fVal = 345.678;
printf("Hello World\r\n");
printf("fVal %f\r\n",fVal);
Output
Hello World
fVal . !
Issues
With -specs = nosys.specs -specs= nano.specs -u _printf_float - printf causes a hard fault.
With specs = nosys.specs -specs -u _printf_float - 1st printf OK 2nd printf produces incorrect output
2019-08-13 11:43 AM
See: http://www.nadler.com/embedded/newlibAndFreeRTOS.html
If you're using an RTOS, probably your printf with %f is failing because printf internally tries to malloc a buffer and fails.
Let us know if that's the issue please!
2019-08-13 01:01 PM
When I had issues with snprintf() under FreeRTOS, I increased heap and stack allocation as well as task stack size (by a factor of 10x from the original size), and the issue was resolved.
2019-08-14 07:11 AM
@davidregan9 - Was this any help? Did you get your issue fixed? Please let us know,
Thanks, Best Regards, Dave
2019-08-14 07:18 AM
Hi Dave
I am still having issues.
I tested the return values of the printf which was a positive value (albeit wrong).
No errno was set.
I have been trying to isolate the issue. Without RTOS it works
2019-08-14 07:18 AM
BTW Increasing heap/stack made no difference.
2019-08-14 07:59 AM
@davidregan9 - Can you confirm you are using:
If yes to both, your problem will definitely be solved using code here: http://www.nadler.com/embedded/newlibAndFreeRTOS.html
Please let us know, Thanks, Best Regards, Dave
2019-08-14 08:04 AM
@Dave Nadler I am using FreeRTOS 10.2.1; GCC ARM Embedded Toolchain 8 2019-q3-update and newlib (I assume since I removed -specs=nano.specs)
2019-08-14 08:07 AM
@davidregan9 You are using newlib (or newlib-nano).
Use the code/instructions on my web page and it will solve your problem.
If the page isn't clear PLEASE let me know how to improve it.
Thanks, Best Regards, Dave
2019-08-14 08:09 AM
@Dave Nadler I will try it out and let you know. Thank you