Skip to content

Commit

Permalink
itm: configure: unlock and disable ITM before modifying, then lock
Browse files Browse the repository at this point in the history
  • Loading branch information
tmplt committed Jan 13, 2022
1 parent f9e81a5 commit 4e9bcf5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/peripheral/itm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,25 @@ impl ITM {
pub fn configure(&mut self, settings: ITMSettings) -> Result<(), ITMConfigurationError> {
use ITMConfigurationError as Error;

// The ITM must be unlocked before we apply any changes.
if self.has_software_lock() && self.locked() {
self.unlock();
while self.locked() {}
}

// The ITM must then be disabled before altering certain fields
// in order to avoid trace stream corruption.
//
// NOTE: this is only required before modifying the TraceBusID
// field, but better be on the safe side for now.
unsafe {
self.tcr.modify(|mut r| {
r.set_itmena(false);
r
});
while self.busy() {}
}

unsafe {
self.tcr.modify(|mut r| {
r.set_gtsfreq(match settings.global_timestamps {
Expand Down Expand Up @@ -327,6 +346,10 @@ impl ITM {
});
}

if self.has_software_lock() {
self.lock();
}

Ok(())
}
}

0 comments on commit 4e9bcf5

Please sign in to comment.