How do you use DWT mechanism to trigger interrupt on memory writes?

Hello all,

i want to use DWT functionality to check for memory access and trigger DebugMon_Handler interrupt on memory write at particular address.I am able to configure DWT units but the interrupt is not triggerd on write to particular address.please check my code below and please correct me where i am doing wrong.

i also tried runnig the exact code form the below blog

https://m0agx.eu/2018/08/25/cortex-m-debugging-runtime-memory-corruption/

CODE:

#include "stm32f4xx.h" // Device header
//#include "core_cm3.h"
#include <stdio.h>
#include <stdint.h>

void watchpoint_enable(void);
void watchpoint_enable(){
CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk /*enable tracing*/ |
CoreDebug_DEMCR_MON_EN_Msk /*enable debug interrupt*/;
// __enable_irq();
// __set_PRIMASK(1);
// prim = __get_PRIMASK();
// trace_printf("check for primask....%d\n",prim);

printf("enable watch points.... \n");
uint32_t test_variable;
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


}

void DebugMon_Handler( void )
{

printf("Debug handler in action\n");
}

int main(){


printf("in the main\n");

watchpoint_enable();
printf("End of the main\n");

return 0;

}


#include "stm32f4xx.h" // Device header
//#include "core_cm3.h"
#include <stdio.h>
#include <stdint.h>


void watchpoint_enable(void);
void watchpoint_enable(){
CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk /*enable tracing*/ |
CoreDebug_DEMCR_MON_EN_Msk /*enable debug interrupt*/;

printf("enable watch points.... \n");


uint32_t test_variable;


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 and trigger an interrupt


}

void DebugMon_Handler( void )
{

printf("Debug handler in action\n");
}

int main(){


printf("in the main\n");

watchpoint_enable();
printf("End of the main\n");

return 0;

}

Thank you!