2021-01-13 02:26 AM
I have a ST32F769I-DISCO board and an example project that uses the onboard ST LINK/v2
as a VCP (Virtual Com Port) that allows me to use printf to send data to a terminal on the PC.
This example project is not a CubeIDE project and all hardware settings are manually written in the code. I would like to implement the same capability in my own project that is based on CubbeIde. I configured UART1 so the generated code is exactly the same as in the example, and also copied (see below) some additional code that might be relevant from the example to my own project . BUT nothing is coming out using printf.
What am I missing ?
The example code I am using is from the en.x-cube-aws_v1-4-1.zip.
Here is the additional code I took from the example:
#if (defined(__GNUC__) && !defined(__CC_ARM))
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define GETCHAR_PROTOTYPE int __io_getchar(void)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#define GETCHAR_PROTOTYPE int fgetc(FILE *f)
#endif /* __GNUC__ */
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART2 and Loop until the end of transmission */
while (HAL_OK != HAL_UART_Transmit(&console_uart, (uint8_t *) &ch, 1, 30000))
{
;
}
return ch;
}
/**
* @brief Retargets the C library scanf function to the USART.
* @param None
* @retval None
*/
GETCHAR_PROTOTYPE
{
/* Place your implementation of fgetc here */
/* e.g. read a character on USART and loop until the end of read */
uint8_t ch = 0;
while (HAL_OK != HAL_UART_Receive(&console_uart, (uint8_t *)&ch, 1, 30000))
{
;
}
return ch;
}
and
#if (defined(__GNUC__) && !defined(__CC_ARM))
/* Do not buffer stdout, so that single chars are output without any delay to the console. */
setvbuf(stdout, NULL, _IONBF, 0);
#endif