Migration from Keil to AC6
Hi Bernard,
I need your help once again!
Now my problem regards the redirection of printf to UART2.
My MCU is a STM32F103VDT and I use UART2 to print debug on serial console.
On Keil I used this code to redirect the printf trough UART2:
int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
if ((char)ch == ‘\n’) /* Add a LF before \n — LF -> CR LF */
{
HAL_UART_Transmit(&huart2,(uint8_t*)”\r”,1,1);
}
HAL_UART_Transmit(&huart2,(uint8_t*)&ch,1,1); // 1 tick waiting (1ms) enough for 87us/byte at 115200
return ch;
}
But now this code not works when I compile with System WorkBench AC6.
Exploring the forum I found a hint regarding the redirection of UART.
It’s suggest to use this code to redirect the printf (I add my code into the function):
void __io_putchar(uint8_t ch)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
if ((char)ch == ‘\n’) /* Add a LF before \n — LF -> CR LF */
{
HAL_UART_Transmit(&huart2,(uint8_t*)”\r”,1,1);
}
HAL_UART_Transmit(&huart2,(uint8_t*)&ch,1,1); // 1 tick waiting (1ms) enough for 87us/byte at 115200
//return ch;
}
But this code not works.
Any suggestion?
Thanks