2

Can anyone advise why my actions described below do not work?:

I have been trying to run the code snippet from the post Can Cortex M4 data watchpoint trigger an interrupt without a debugger? on(STM32F407VG board emulated with QEMU on eclipse.), but the DebugMon_Handler is not triggered even after enabling it by adding the extra two lines mentioned as a solution in that post.

I have also tried on Keil uMicrovision IDE and it throws the below error after running "DWT->COMP1 = &test_variable;" this line.

***** error 65: access violation at 0xE0001020 : no 'write' permission**

You can read more about my issue in the below link.

https://stackoverflow.com/questions/72122224/data-watchpoints-dwt-on-cortex-m4-to-detect-memory-corruption

My CODE:

#include <stdio.h>
#include <stdlib.h>
#include "diag/Trace.h"
//#include "core_cm3.h"
#include "stm32f4xx.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;
trace_printf("enable watch points.... \n");
DWT->COMP1 = &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*/;
trace_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)
{

    trace_printf("Debug handler in action...\n");
}

#pragma GCC diagnostic pop
Russell McMahon
  • 147,325
  • 18
  • 210
  • 386
  • K Sai, please note that this is not a forum, so when you post a question you are not addressing a specific user. With that in mind, write questions in such a way that anyone could answer and do not request direct communications/responses. In this way, both the question and answer have value for future visitors and others having the same or similar problem. – JYelton May 12 '22 at 15:38
  • Hi JYelton, I completely understand what you are saying, sorry for the inconvenience .This Question was created as i did not have enough reputations to comment under a question posted by a user named filo. I wanted him to answer the question as I was running his code. Find filo's post below https://electronics.stackexchange.com/questions/325560/can-cortex-m4-data-watchpoint-trigger-an-interrupt-without-a-debugger – K. Sai Bharadwaj May 13 '22 at 06:02
  • Unfortunately there's (intentionally) no mechanism to ask specific users new questions. You can use comments to clarify things, to add context, point out problems, etc. Any new question should be posted as a new question and not as a comment (just as you've done). The new question though needs to be addressed to no one in particular. You may or may not get the same user's attention. – JYelton May 13 '22 at 16:16
  • I placed a request for Filo to look at this question on his original answer – Russell McMahon May 17 '22 at 12:45
  • How does it behave on real hardware? I would ask a Qemu question if DWT is implemented at all for the virtual STM32. – filo May 17 '22 at 12:52
  • I don't have hardware board to test the code. As filo pointed looks like QEMU doesn't emulate the DWT unit. Any way I tried to run the code in arm development studio(arm-ds5) in a simulation mode and to my surprise it worked perfectly fine. – K. Sai Bharadwaj May 18 '22 at 09:39
  • Hi, I am trying to test the above functionality on hardware now. I want to set a WatchPoint at an address on the stack, say at (0x878FFF9A) and check for write access at this address instead of declaring a variable and setting the variables address to the COMP1.I am doing (DWT->COMP1 = (uint_32)0x2003FF00);.When I try to do this my PUTTY terminal just stops.(my pc is connected to board through UART cable). – K. Sai Bharadwaj May 31 '22 at 10:18

0 Answers0