Skip to content

Commit 4e9bcf5

Browse files
committed
itm: configure: unlock and disable ITM before modifying, then lock
1 parent f9e81a5 commit 4e9bcf5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/peripheral/itm.rs

+23
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,25 @@ impl ITM {
257257
pub fn configure(&mut self, settings: ITMSettings) -> Result<(), ITMConfigurationError> {
258258
use ITMConfigurationError as Error;
259259

260+
// The ITM must be unlocked before we apply any changes.
261+
if self.has_software_lock() && self.locked() {
262+
self.unlock();
263+
while self.locked() {}
264+
}
265+
266+
// The ITM must then be disabled before altering certain fields
267+
// in order to avoid trace stream corruption.
268+
//
269+
// NOTE: this is only required before modifying the TraceBusID
270+
// field, but better be on the safe side for now.
271+
unsafe {
272+
self.tcr.modify(|mut r| {
273+
r.set_itmena(false);
274+
r
275+
});
276+
while self.busy() {}
277+
}
278+
260279
unsafe {
261280
self.tcr.modify(|mut r| {
262281
r.set_gtsfreq(match settings.global_timestamps {
@@ -327,6 +346,10 @@ impl ITM {
327346
});
328347
}
329348

349+
if self.has_software_lock() {
350+
self.lock();
351+
}
352+
330353
Ok(())
331354
}
332355
}

0 commit comments

Comments
 (0)