File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
libs/trace/include/orbcode/trace Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,21 @@ extern "C"
197
197
void DWTSetup (const DWTOptions * options )
198
198
{
199
199
CoreDebug -> DEMCR |= CoreDebug_DEMCR_TRCENA_Msk ; // Enable ITM and DWT
200
- DWT -> LAR = 0xC5ACCE55 ; // Unlock DWT access via magic number
200
+
201
+ // Some CPU do not have DWT lock registers
202
+ // All CoreSight compoents that might have lock, will have
203
+ // lock status register at offset 0xFB4
204
+ // lock access register at offset 0xFB0
205
+ // If locking is not implemented, lock status register will read as zero
206
+ // See: ARMv7-M Architecture Reference Manual, section D.1.1, table D1-2
207
+ volatile uint32_t * lockStatus = ((volatile uint32_t * )DWT ) + (0xFB4 / 4 );
208
+ volatile uint32_t * lockAccess = ((volatile uint32_t * )DWT ) + (0xFB0 / 4 );
209
+
210
+ if (* lockStatus != 0 )
211
+ {
212
+ // lock status is not zero, meaning that unlock is necessary
213
+ * lockAccess = 0xC5ACCE55 ; // Unlock DWT access via magic number
214
+ }
201
215
202
216
uint32_t ctrl = 0 ;
203
217
ctrl |= (options -> FoldedInstructionCounterEvent ? 1 : 0 ) << DWT_CTRL_FOLDEVTENA_Pos ;
You can’t perform that action at this time.
0 commit comments