Trouble with printf and sprintf with float in STM32Cube + VS Code (CMake)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-06-21 6:38 AM
Hi everyone,
I'm working on an STM32 (Nucleo-F446RE to be spesific) project using the STM32Cube extension for VS Code, not CubeIDE. I'm using CMake for building the project.
I encountered a few issues:
printf doesn't print anything to the serial monitor, so I switched to using HAL_UART_Transmit.
When I try to print a float using sprintf(msg, "value: %f\n", var);, it doesn’t work. The output just skips the float value (e.g., "value: \n").
After some research, I found out I need to add "-u _printf_float" to the linker flags to enable float formatting support with printf and sprintf.
However, I'm new to CMake and I couldn’t figure out which CMake file I need to modify in the project folder to add this flag.
I'd really appreciate it if someone could guide me:
Where exactly should I add the "-u _printf_float" flag?
Is there anything else I should do to make printf work properly over UART?
Thanks in advance for your help.
- Labels:
-
VSCode for STM32
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-06-25 5:13 AM
@umut373 wrote:
printf doesn't print anything to the serial monitor
Have you followed the instructions:
A complex system designed from scratch never works and cannot be patched up to make it work.
