2016-06-15 6:41 AM
Hi there,
I'm working on custom board based on STM32F103 and the IDE is Keil. I will use UART2 to print some debug logs. To do this I add the fputc function to my code in order to redirect printf to UART2.int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
HAL_UART_Transmit(&uart_debug_handler,(uint8_t*)&ch,1,1);
return ch;
}
Everything work but the output on serial port seems to haven't the Carrige Return (CR). There is only the Line Feed (LF).
This is an extract of serial output:
I'm Alive: 2269
I'm Alive: 2270
I'm Alive: 2271
I'm Alive: 2272
Any suggestions?
Thanks a lot!
Federico
2016-06-16 1:45 AM
Do you send /r ?
Can we see the printf line ?2016-06-16 2:21 AM
If your terminal needs to receive '' '' when you send ' ', then you are going to have to add that functionality to your fputc() function, or change your terminal settings.
int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
if ((char)ch == '
') // LF -> CR LF
HAL_UART_Transmit(&uart_debug_handler,(uint8_t*)''
'',1,1);
HAL_UART_Transmit(&uart_debug_handler,(uint8_t*)&ch,1,1);
return ch;
}
2016-06-16 9:18 AM
Thanks clive1!!!
You solved my bug in printf!Thanks!