STM32_Examples/Trace_debug.md
2021-07-01 14:12:44 +02:00

1.2 KiB

All you need to know

Debugger modification:

connect PA10 (pin 31) to one of the debugger pins for example to one of the 5V pins.

Software

printf adaptation:

For printf function to work we need _write method.

int _write(int file, char *ptr, int len){
    int DataIdx;
    for(DataIdx=0; DataIdx<len; DataIdx++){
        ITM_SendChar(*ptr++);
    }
    return len;
}

Cube IDE setup:

In .IOC perspective in system core tab select Trace Asynchronous Sw
Make sure you know core frequency.

Initial code:

#include stdio.h

#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))

Example code before while loop:

SystemClock_Config();

ITM_Port32(31) = 1;

MX_GPIO_Init();

printf("gpio init done \r\n");
ITM_Port32(31) = 2;

In debug configuration enable SWV and make sure Core clock matches clock of processor
For view the trace data go to Window>Show view>SWV

M0 and M0+ cortex MCUs are not supported
Make sure, that you have selected output port in "Configure trace"

For more info: https://www.youtube.com/watch?list=PLXnwAHPMBciEfY6C6rnz6rUehFxCQMwzY&v=4wT9NhlcWP4&feature=emb_title