How to get printf() float / double support working on F7
I've been fighting with this too long and can't figure it out. I've added uart communication for use with printf() by implementing the following in syscalls.c:
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
HAL_StatusTypeDef status = HAL_UART_Transmit(&huart1, (uint8_t *)ptr, len, 0xFFFF);
return (status == HAL_OK ? len : 0);
}That works fine with printf. But printing floats or doubles causes it to hang when it tries to output the number. I have enabled -u _printf_float in the MCU Settings of STM32CubeIDE (also tried adding it manually to the Linker flags).
double test = 1.2345;
printf("test: %f\r\n", test);arm-none-eabi-g++ -o "ProjectTest.elf" @"objects.list" -l:libtouchgfx-float-abi-hard.a -mcpu=cortex-m7 -T"B:\gitrepo\ProjectTest\STM32F746NGHX_FLASH.ld" --specs=nosys.specs -Wl,-Map="ProjectTest.map" -Wl,--gc-sections -static -L../Middlewares/ST/TouchGFX/touchgfx/lib/core/cortex_m7/gcc --specs=nano.specs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-groupI don't really know how to debug this further, and I've read many relevant posts but nothing I've tried has worked. I really need it to, as the debugger in STM32CubeIDE is a pile of junk and the watcher shows incorrect values for variables.
Also note I'm using FreeRTOS here, not sure if it's an issue with stack alignment or how to debug that.
Help a brutha out?
