I am using the following code to configure the DWT(Data Watchpoint and Trace) and test it in Arm Development Studio. When using a Cortex-M4 or Cortex-M3, it triggers the DebugMon_Handler, but when using a Cortex-M33, it doesn’t. Does anyone know the reason for this?
#include "RTE_Components.h" /* This mechanism is the standard way to include */
#include CMSIS_device_header /* the device header file, in this case ARMCM33.h */
#include <stdio.h>
#include <stdlib.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wreturn-type"
void watchpoint_enable()
{
CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk /*enable tracing*/ |
CoreDebug_DEMCR_MON_EN_Msk /*enable debug interrupt*/;
uint32_t test_variable;
printf("enable watch points.... n");
DWT->COMP1 = (uint32_t)&test_variable;
DWT->MASK1 = 0; // match all comparator bits, don't ignore any
DWT->FUNCTION1 = (1 << 11) /*DATAVSIZE 1 - match whole word*/
| (1 << 1) | (1 << 2) /*generate a watchpoint event on write*/;
printf("watch points enabled....n");
test_variable = 5; // <<----- CPU stops after this line
}
int main(int argc, char *argv[])
{
watchpoint_enable();
}
void DebugMon_Handler(void)
{
printf("Debug handler in action...n");
}
#pragma GCC diagnostic pop
Besides: I found out that cortex-M33 doesn’t have DWT->MASKx registers, while cortex-M3 and cortex-M4 do.