Hey. I have recently started learning stm32. The first thing I need to setup before I do any is to get printf print out a message to a console so it is easier for me to debug.
I have found a numerous forum threads regarding this issue but none of them are fully solved. From what I understood, there are few minor changes that needs to be implemented to get printf to work to print a message to a console:
First, defining sine functions:
and then further down the code:
Now my actual code:
Keep in mind that I have used CubeMX program to generate all the required peripherals so I can be certain that I did not make any mistake initializing something myself.
I am able to sucessfully upload the program to the device and I can see that printf fuction invokes the _write and HAL_UART_Transmit functions by using a breakpoints but the message does not show up in the console

I have tried to open a terminal program and it works with the terminal, I can see the messages appear as programmed every 1 second:

But how do I get it working in the cubeIDE console instead?
Any tips appreciated...
I have found a numerous forum threads regarding this issue but none of them are fully solved. From what I understood, there are few minor changes that needs to be implemented to get printf to work to print a message to a console:
First, defining sine functions:
Code:
#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__ */
Code:
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;
}
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();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
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");
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 */
}
I am able to sucessfully upload the program to the device and I can see that printf fuction invokes the _write and HAL_UART_Transmit functions by using a breakpoints but the message does not show up in the console

I have tried to open a terminal program and it works with the terminal, I can see the messages appear as programmed every 1 second:

But how do I get it working in the cubeIDE console instead?
Any tips appreciated...