to investigate a race condition I would need to "turn on" the DWT.
To validate the code I'm going to have to use, I wrote a piece of simplified code, but even that doesn't work. Of course, I test it using the debugger (Segger J-Link).
volatile static uint8_t dummy; volatile uint8_t *pdummy; uint32_t dhcsr_DEBUGEN = (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) >> CoreDebug_DHCSR_C_DEBUGEN_Pos; assert(1 == dhcsr_DEBUGEN); CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; /* this should enable also DWT */ __DSB(); __ISB(); uint32_t demcr_TRCENA = (CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) >> CoreDebug_DEMCR_TRCENA_Pos; assert(1 == demcr_TRCENA); // CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->LAR = 0xC5ACCE55; /* Is this really necessary? */ pdummy = &dummy; DWT->COMP1 = (uint32_t)pdummy; DWT->MASK1 = 1; /* 1 byte */ DWT->FUNCTION1 = 6; /* Write */ __DSB(); __ISB(); *pdummy = 5 * ac; /* ac is a function parameter */ __DSB(); __ISB(); uint32_t function_MATCHED = (DWT->FUNCTION1 & DWT_FUNCTION_MATCHED_Msk) >> DWT_FUNCTION_MATCHED_Pos; assert(1 == function_MATCHED);
The first assert confirms that halting debugging is enabled, while the second assert confirms that DWT should be enabled (as a consequence of the TRCENA bit)
Then I program comparator, mask and function of set 1 (I also tried 0). Finally I try to write the variable that should be monitored, but the debugger does not stop, and the core does not enter debug mode.The last assert confirms that the event was not detected.
Can you help me understand where I am going wrong?
best regards
Max