Redirecting printf() does not work
I have enabled USART1 and I’m able to send data using HAL_UART_Transmit() function. I want printf() to put its data on this port using following code :
#include stdio.h #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */
And at the bottom of the code I have defined PUTCHAR_PROTOTYPE like this:
PUTCHAR_PROTOTYPE { HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); return ch; }
But after initializing the USART1 in the main function I don’t see any data coming from something simple like printf(“Hello!\n”)
What wonders me is that I did all this in Keil and it worked like a charm!
I suspect there is a compile option or something like that in GCC. I’m not sure. Could you guys help me?
(By the way I don’t know why all # marks have been changed into line numbers in above code)