I found several posts like this one, using syscalls.c, but I don't have this file in my project... I generate the code with CubeMX v4.18.0.
To get printf working, you have to do the following.
In the main.c, add this code in the relevant sections:
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* USER CODE END PFP */
/* USER CODE BEGIN 4 */
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
/* 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(&UartHandle, (uint8_t *)&ch, 1, 0xFFFF);
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
/* USER CODE END 4 */
In combination with the syscall.c, you should get your printf getting out on the UART.
Addapt the code to the uart handler you are using :-)
With cube, I generate mine with UART2. So in the code huart2 has been used.
You can refer to some projects examples in the firmware library directory.
Under the family you are using, you will find them.
Retrieving data ...