For the last couple of days I have been trying to get printf to work to print a debug message to a STM32CubeIDE console. However, with no luck. I have gone through numerous forum threads and discussions and none of them appear to have fully solved this weird issue that is well known.
I have just generated a brand new project with STM32CubeMX and used a default configuration for the Nucleo board. I am just using USB cable with build in ST-link to program the device.
What I have been suggested to do so far is to add a few lines of code that apparently should have fixed the issue but it didint:
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
I have also included :
#include "stdio.h"
The actual code:
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t uart3_data[20] = "hello from uart3";
uint8_t uart1_data[20] = "hello from uart1";
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART3_UART_Init();
MX_USART1_UART_Init();
MX_TIM10_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim10);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//Toggle_leds(GPIOB,GPIO_PIN_0,100);
HAL_Delay(1000);
printf("UART Printf Example: retarget the C library printf function to the UART \n\r");
printf("** Test finished successfully. ** \n\r");
HAL_UART_Transmit(&huart3,uart3_data, sizeof(uart3_data), 50); // just to see what happens
//HAL_UART_Transmit(&huart1,uart1_data, sizeof(uart1_data), 50); // just to see what happens
}
/* USER CODE END 3 */
}
When I open up a terminal and connect to the device , I can see the messages coming as expected: enter image description here
However, I cannot understand why I am not able to see messages dispalyed on the stm32cubeIDE console. Am I missing some additional configuration?