Using printf in STM32 ARM Cortex-M3/M4/M7 microcontrollers requires setting up a few things before you can start printing out messages. Firstly, you need to configure the ITM (Instrumentaton Trace Macrocell) unit to send its FIFO buffer content through the SWO (Serial Wire Output) pin of the SWD (Serial Wire Debug) Interface. This can be done by the follwoing code:
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
(void)file;
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
//__io_putchar(*ptr++);
ITM_SendChar(*ptr++);
}
return len;
}
In the STM32cubeide the SWV(Serial Wire Viewer) will then receive the printf statements and
display it in the console. In the SWV ITM Data Console, set the ITM Stimulus Port to '0',
and before running the application press on 'start trace'. As can be seen on the following
picture.

No comments:
Post a Comment