cortex-m icon indicating copy to clipboard operation
cortex-m copied to clipboard

ITM: exhaustively check feature support during `configure`; improve standard correctness, documentation

Open tmplt opened this issue 4 years ago • 16 comments

As discussed in #382, this PR checks that the requested features are ensured before continuing in ITM::configure. Because some register fields in ITM_TCR are RAZ/WI and RAZ or RAO (and no dedicated RO flags exists that we can otherwise check) there are cases when we end up with partially applied configurations. These cases are documented on the relevant errors.

No ITM::configure_unchecked in this PR because of the code duplication it would require. But I do not see a common use-case for configuring the ITM outside of an init function which (in my current case at least) allows for a few more registers reads.

This PR also ensures that the ITM is unlocked (if a software lock is implemented) and disabled before modifying any registers. When the configuration has been correctly applied, the ITM is re-locked, as per CoreSight recommendation. The ITM is not re-locked if the configuration fails to apply.

tmplt avatar Jan 04 '22 12:01 tmplt

r? @thalesfragoso

(rust-highfive has picked a reviewer for you, use r? to override)

rust-highfive avatar Jan 04 '22 12:01 rust-highfive

dc4642512761f2b6d9fe65d7878cd12a2131aeb8 can be fixup'd into 622a9b7297f47a1d6a0d40894e2d2994ad46db27.

tmplt avatar Jan 04 '22 21:01 tmplt

Wait with eventual merge for me to test these checks. It should be done by next week.

tmplt avatar Jan 05 '22 19:01 tmplt

https://github.com/rust-embedded/cortex-m/issues/392 must be handled in this PR.

tmplt avatar Jan 13 '22 16:01 tmplt

Only TraceBusID remains.

tmplt avatar Jan 14 '22 13:01 tmplt

ARM DDI 0403E.d, p. C1-716:

If multi-source trace is in use, the debugger must write a non-zero value to this field.

C-718:

If a system supports multiple trace streams, the debugger must write a nonzero value to the ITM_TCR.TraceBusID field. For information about permitted values for this field in a CoreSight-compliant implementation, see the ARM IHI 0029E [...] An example of a system with multiple trace streams is an ARMv7-M core with ETM. In this case, the debugger must program the ETM TraceBusID register with a different nonzero identifier for the ETM trace stream.

ARM IHI 0029E does not contain the term "TraceBusID".


It is not very clear whether non-zero should be written if multi-source trace is wanted, or if the target implements it. If the latter, we'll need to write non-zero even if we only want a single trace source.

tmplt avatar Jan 14 '22 13:01 tmplt

This refactored implementation of ITM::configure works as expected on the atsame51n. I've sent an email to ARM in hopes of some clarification on TraceBusID; eventual fixes for which can be postponed to another PR.

I consider this PR ready for review.

tmplt avatar Jan 14 '22 14:01 tmplt

lock and unlock has been streamlined a bit and in the process has_software_lock and locked have been hidden. lock and unlock could potentially be hidden later when #393 and similar close so that configure is exhaustive.

tmplt avatar Jan 15 '22 21:01 tmplt

Latest changes work as expected on hardware. Also tested on the atsame51n.

tmplt avatar Jan 19 '22 17:01 tmplt

On TraceBusID: after a brief back-and-forth with ARM it seems to be valid to write non-zero. If only ITM is supported on the system, TraceBusID is potentially RAZ (in ARMv8-M, at least). Some rules do apply when multi-source trace is in use, but that's for another day.

tmplt avatar Jan 24 '22 10:01 tmplt

This PR is ready for final review, @thalesfragoso.

tmplt avatar Mar 09 '22 19:03 tmplt

The re-locking sequence currently incorrectly always assumes that a software lock is implemented. Amendmend will follow.

tmplt avatar May 18 '22 14:05 tmplt

Hi all,

What happened with this PR? Looking over it, it seems ready to go.

Ping @rust-embedded/cortex-m

korken89 avatar Apr 22 '24 06:04 korken89

IIRC

The re-locking sequence currently incorrectly always assumes that a software lock is implemented

is still relevant, and should be fixed before merge.

I do not have access to relevant hardware, and my knowledge of the area has faded somewhat. Is anyone else interested in taking up the torch?

tmplt avatar Apr 22 '24 19:04 tmplt

@tmplt I could probably give it a look. What HW is needed? I can get some ordered for testing.

korken89 avatar Apr 28 '24 07:04 korken89

I've tested the code on SAME51 and SAMV71 boards. IIRC one of these lack the software lock, resulting in a busy wait that never exits. I don't think the ITM coverage is exhaustively detailed in the data sheets, and so must be detected at run-time.

tmplt avatar Apr 28 '24 09:04 tmplt