Retargeting printf
I’m trying to retarget the printf function in order to print formatted output to USART3 on my STM32 NUCLEO F746ZG.
This is the code in the uart.h file I created:
1 #ifdef GNUC
2 /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to ‘Yes’) calls __io_putchar() */
3 #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
4 #else
5 #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
6 #endif /* GNUC */
(Please note that the lines 1 and 6 have a couple of underscores before and after the GNUC keyword, but I didn’t succeed in innserting it in the post...)
This is the code in the corresponding uart.c file:
1 PUTCHAR_PROTOTYPE {
2 HAL_UART_Transmit (&huart3, (uint8_t *)&ch, 1, 0xFFFF);
3 return ch;
4 }
Nothing happens if I run the application........
In particular:
If I directly call the HAL_UART_Transmit function, I can send characters.
If I call the printf function, the PUTCHAR_PROTOTYPE function is not executed.
I guess the printf is calling something else than the PUTCHAR_PROTOTYPE function.
By the way, I didn’t see the “small printf” option in the System Workbench linker options.
What’s wrong with this code?
Thanks in advance