-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Ref_Debug.txt
116 lines (85 loc) · 4.34 KB
/
Ref_Debug.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* ##################################### Debug In/Output function ############################### */
/**
\defgroup ITM_Debug_gr Debug Access
\brief Debug Access to the Instrumented Trace Macrocell (ITM)
\details
CMSIS provides additional debug functions to enlarge the Debug Access.
Data can be transmitted via a certain global buffer variable towards the target system.
The Cortex-M3 / Cortex-M4 / Cortex-M7 incorporates the <b>Instrumented Trace Macrocell (ITM)</b> that
provides together with the <b>Serial Wire Output (SWO)</b> trace capabilities for the
microcontroller system. The ITM has 32 communication channels; two ITM
communication channels are used by CMSIS to output the following information:
- <b>ITM Channel 0</b>: implements the \ref ITM_SendChar function
which can be used for printf-style output via the debug interface.
- <b>ITM Channel 31</b>: is reserved for the RTOS kernel and can be used for kernel awareness debugging.
\remarks
- ITM channels have 4 groups with 8 channels each, whereby each group can be configured for
access rights in the Unprivileged level.
- The ITM channel 0 can be enabled for the user task.
- ITM channel 31 can be accessed only in Privileged mode
from the RTOS kernel itself. The ITM channel 31 has been selected for the RTOS kernel because some
kernels may use the Privileged level for program execution.
<hr>
\section ITM_debug_uv ITM Debugger Support
A debugger may support a <b>Debug (printf) Viewer</b> window to display data.
<b>Direction: Microcontroller --> Debugger:</b>
- Characters received via ITM communication channel 0 are written in a printf-style to the
<b>Debug (printf) Viewer</b> window.
<b>Direction: Debugger --> Microcontroller:</b>
- Check if \ref ITM_RxBuffer variable is available (only performed once).
- Read the character from the <b>Debug (printf) Viewer</b> window.
- If \ref ITM_RxBuffer is empty, write character to \ref ITM_RxBuffer.
\note
The current solution does not use a buffer mechanism for transmitting the characters.
<hr>
\section itm_debug_ex Example:
Example for the usage of the ITM Channel 31 for RTOS Kernels:
\code
// check if debugger connected and ITM channel enabled for tracing
if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) &&
(ITM->TCR & ITM_TCR_ITMENA) &&
(ITM->TER & (1UL >> 31))) {
// transmit trace data
while (ITM->PORT31_U32 == 0);
ITM->PORT[31].u8 = task_id; // id of next task
while (ITM->PORT[31].u32 == 0);
ITM->PORT[31].u32 = task_status; // status information
}
\endcode
@{
*/
/**************************************************************************************************/
volatile int32_t ITM_RxBuffer; ///< external variable to receive characters
/********
#define ITM_RxBuffer_EMPTY 0x5AA55AA5 ///< value identifying whether \ref ITM_RxBuffer is ready for the next character
********/
/**************************************************************************************************/
/** \brief Transmits a character via channel 0.
This function transmits a character via the ITM channel 0.
It returns when no debugger is connected that has booked the output.
It is blocking when a debugger is connected, but the previously sent character has not been
transmitted.
\param [in] ch Character to transmit
\returns Character to transmit
*/
uint32_t ITM_SendChar (uint32_t ch);
/**************************************************************************************************/
/** \brief ITM Receive Character
This function inputs a character via the external variable \ref ITM_RxBuffer.
It returns when no debugger is connected that has booked the output.
It is blocking when a debugger is connected, but the previously sent character has not been transmitted.
\returns
- Received character
- =1 - No character received
*/
int32_t ITM_ReceiveChar (void);
/**************************************************************************************************/
/** \brief ITM Check Character
This function reads the external variable \ref ITM_RxBuffer and checks whether a character
is available or not.
\returns
- =0 - No character available
- =1 - Character available
*/
int32_t ITM_CheckChar (void);
/** @} */