Skip to content

Commit 7159658

Browse files
author
Amanda Butler
authored
Merge pull request #413 from marcuschangarm/patch-1
Create itm.md
2 parents 3bd067a + 9f098e2 commit 7159658

File tree

1 file changed

+50
-0
lines changed
  • docs/reference/contributing/target

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
### Instrumented Trace Macrocell
2+
3+
For targets with Arm CoreSight (for example, Cortex-M3 and Cortex-M4), the Instrumented Trace Macrocell provides a lightweight, nonintrusive way to collect debug trace output.
4+
5+
#### Assumptions
6+
7+
##### Defined behavior
8+
9+
When the ITM has been initialized (by the SerialWireOutput class or other application), writing data to the ITM stimulus registers results in the ITM transmitting the data over the SWO line.
10+
11+
##### Undefined behavior
12+
13+
- The debug clock frequency is left undefined because the most optimal frequency varies by target. It is up to each target's owner to choose a frequency that doesn't interfere with normal operation and that the owner's preferred debug monitor supports.
14+
- If another peripheral tries to take control of the SWO pin, it is undefined whether that operation succeeds.
15+
16+
##### Note
17+
18+
Some SWO viewers do not allow an arbitrary frequency to be set. Make sure that the development tools you expect your users to use support the chosen frequency.
19+
20+
#### Dependencies
21+
22+
- The target supports Arm CoreSight.
23+
- The target has SWO connected either to a compatible interface chip or exposed as a debug pin.
24+
25+
#### Implementing the ITM API
26+
27+
[![View code](https://www.mbed.com/embed/?type=library)](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/group__itm__hal.html)
28+
29+
- You must implement the function `itm_init`. When the function is called:
30+
- The function must initialize the debug clock for the ITM.
31+
- The function must configure the SWO pin for debug output.
32+
- You must add `ITM` to the `device_has` section in `target.json`.
33+
34+
It is not necessary to modify any of the ITM registers in `itm_init`, except for the one related to the clock prescaling, `TPI->ACPR`. The helper function `mbed_itm_init` is responsible for calling `itm_init` and initializing the generic ITM registers. `mbed_itm_init` only calls the function `itm_init` once, making it unnecessary to protect `itm_init` against multiple initializations.
35+
36+
#### Testing
37+
38+
You can use the `SerialWireOutput` to send `stdout` to the SWO stimulus port on the ITM by including this override function:
39+
40+
```
41+
#include "SerialWireOutput.h"
42+
43+
FileHandle* mbed::mbed_override_console(int fd)
44+
{
45+
static SerialWireOutput swo;
46+
return &swo;
47+
}
48+
```
49+
50+
You can place the function in any C++ compilation unit, including `main.cpp`.

0 commit comments

Comments
 (0)