2019-12-04 04:58 AM
Hi,
I'm using STM32CubeIDE and I'm trying to retarget printf to the USART1 of the STM32F746G.
USART1 of the MCU is connected to the ST-Link Virtual com. I have tested the connection the USART1 directly using the function "HAL_UART_Transmit(&huart1, "A", 1, 0xFFFF)" this does work meaning that the hardware is correctly setup. So far I have implemented __io_putchar() function in my main.cpp like the following :
int __io_putchar(int ch)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
I took the code from the one of the example in the STM32Cube_FW_F7_V1.15.0 but for an other board since there is no UART_printf example for the STM32F746G.
Any of what could be wrong with my implementation ?
2019-12-04 05:06 AM
Hi @Renaud Dk
Does your project embed syscall.c ?
Else customized _write function has to be defined also.
Please refer to "AN4989 STM32 microcontroller debug toolbox" Chapter 7.
Olivier
2019-12-04 05:29 AM
Hi @Community member
Yes I have syscall.c integrated in my project (under [PROJECT_ROOT]/Core/Src). I read the app note and this why I chose to implement the __io_putchar() instead of _write(). One word about my project configuration, my main.cpp is in C++ because I'm using touchgfx framework with CMSIS-Freertos.
Renaud
2019-12-04 04:26 PM
> Any of what could be wrong with my implementation ?
Try two small changes before digging deeper:
1: in your __io_putchar:
extern "C"
int __io_putchar(int ch)
{
if (ch == '\n')
HAL_UART_Transmit(&huart1, (uint8_t *)"\r", 1, 0xFFFF);
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
2: in UART1 advanced settings (in CubeMX) - make sure to disable overrun detection.
-- pa