I'm using STM32F7xx for my project where I use VS Code text editor in combination with CMake project build. I also use CubeMX for code generation. For a record I have already examined all the answers in this question but none seems to work.
When I generate code using STM32CubeIDE template, the syscalls.c
file is generated. It provides the following declaration:
extern int __io_putchar(int ch) __attribute__((weak));
If I provide __io_putchar()
definition in my main.cpp
file nothing happens after using printf()
. However, if I provide __io_putchar()
function definition inside of syscalls.c
then printf()
operates as should and I get output stream printed out on terminal.
extern int __io_putchar(int ch) __attribute__((weak));
int __io_putchar(int ch)
{
HAL_UART_Transmit(UART_GetHuart3(), (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
I have tried several other methods of printf()
retarget, like retargeting _write
or fputc
, however nothing really works besides providing function definition inside of syscalls.c
. And the problem of providing __io_putchar()
function definition inside of syscalls.c
is that after re-generating code from CubeMX, this definition will be removed. Therefore I need more "clean" solution for this.