STM32F767ZI nucleo board printf to console
Hello. I have got my nucleo stm32 board and created a brand new project. I have used a default configuration so all the peripherals are already configured for me.
All I want to do is to print some debug messages as following:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(1000);
printf(“UART Printf Example: retarget the C library printf function to the UART \n\r”);
printf(“** Test finished successfully. ** \n\r”);
}
/* USER CODE END 3 */
}
After looking up at the internet I have found many solutions for this problem. I have tried to add some additional code to my main.c as suggested:
- ifdef GNUC
/* 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)
- else
- define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
- endif /* GNUC */
and then furhter down the main.c I have declared the prototype;
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
In my syscalls I have put a breakpoint in _write function and I can see that it is being called, but no messsage appears on the console. Can someone help me understand how printf works and how to get it to print to console?