Skip to content

Commit e7b4a45

Browse files
committed
itm: configure: unlock and disable ITM before modifying, then lock
1 parent 61ee6ed commit e7b4a45

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
@@ -260,6 +260,25 @@ impl ITM {
260260
pub fn configure(&mut self, settings: ITMSettings) -> Result<(), ITMConfigurationError> {
261261
use ITMConfigurationError as Error;
262262

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

352+
if self.has_software_lock() {
353+
self.lock();
354+
}
355+
333356
Ok(())
334357
}
335358
}

0 commit comments

Comments
 (0)