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

43 lines
1.2 KiB
Markdown

# 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.<br/>
```c
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<br/>
Make sure you know core frequency.<br/>
<br/>
Initial code:<br/>
```c
#include stdio.h
#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
```
Example code before while loop:<br/>
```c
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<br/>
For view the trace data go to Window>Show view>SWV<br/>
<br/>
M0 and M0+ cortex MCUs are not supported<br/>
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