cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Monitor on STM32CubeIDE

CAben.1
Associate II

Dear ST Community,

I am new to STM32Cube IDE (previously used Arduino IDE only) and I have been trying to use Printf() for output on the serial monitor to no avail. After a few google searches and trials, i unfortunately didnt succeed to get it running.

My question: What is the simplest way to get basic print out on the Serial monitor within the STM32Cude IDE. Thank you.

#STM32CubeIDE​  #stdio #printf

1 REPLY 1
KnarfB
Principal III

Depends on the board/debug adapter you are using. Nucleo, Discovery and more boards have a virtual COM port (VCP) integrated in the USB Debug connection and routed to some UART pins of the MCU. If you generate your code with STM32Cube, the generation option "Initialize all peripherals..." will activate that UART. Otherwise, you have to find out the correct UART by reading the board schematics etc... Also, check the config for the correct UART settings: 115200 8N1.

Next, you have to route printf and friends to that UART. This can be done easily by writing a global function in a user code section (adapt UART number):

int __io_putchar(int ch)
{
	HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, HAL_MAX_DELAY);
	return ch;
}

In fact, this overwrites a default "do nothing" implementation of __io_putchar.

There are alternatives like semi-hosting or SWO tracing. For more info see AN4989 Application note "STM32 microcontroller debug toolbox".

hth

KnarfB