hardware: Enable DEMCR TRCENA on boot for cycle counter

Previously, the cycle counter would only work correctly when
running in the debugger (which would also enable tracing).

GitHub: Fixes #299.
This commit is contained in:
David Nadlinger 2021-03-05 17:58:41 +00:00
parent 65e9131bfb
commit 148a3c8281
1 changed files with 9 additions and 1 deletions

View File

@ -825,6 +825,14 @@ pub fn setup(
None None
}; };
let cycle_counter = {
// Set TRCENA bit, which is required for DWT counter to tick. (This is also
// set automatically when running in the debugger, and only cleared on power
// reset, not on soft reset.)
core.DCB.enable_trace();
CycleCounter::new(core.DWT, ccdr.clocks.c_ck())
};
let stabilizer = StabilizerDevices { let stabilizer = StabilizerDevices {
afes, afes,
adcs, adcs,
@ -833,7 +841,7 @@ pub fn setup(
net: network_devices, net: network_devices,
adc_dac_timer: sampling_timer, adc_dac_timer: sampling_timer,
timestamp_timer, timestamp_timer,
cycle_counter: CycleCounter::new(core.DWT, ccdr.clocks.c_ck()), cycle_counter,
}; };
// info!("Version {} {}", build_info::PKG_VERSION, build_info::GIT_VERSION.unwrap()); // info!("Version {} {}", build_info::PKG_VERSION, build_info::GIT_VERSION.unwrap());