cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot use printf with floats on a Cube generated System Workbench project for STM32F429i discovery board.

davidregan9
Associate III

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

14 REPLIES 14

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!

Michael98006
Associate III

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.

@davidregan9​ - Was this any help? Did you get your issue fixed? Please let us know,

Thanks, Best Regards, Dave

davidregan9
Associate III

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

davidregan9
Associate III

BTW Increasing heap/stack made no difference.

@davidregan9​ - Can you confirm you are using:

  • FreeRTOS?
  • newlib and gcc?

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

davidregan9
Associate III

@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)

@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

davidregan9
Associate III

@Dave Nadler​ I will try it out and let you know. Thank you