Retargeting printf on STM32F746G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-04 4: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 ?
- Labels:
-
STM32CubeIDE
-
STM32F7 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-04 5: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
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-04 5: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-04 4: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
