cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault when accessing dwt control register

bojan2
Associate
Posted on April 04, 2014 at 00:54

Hello!

I would like to add watchpoints from application to DWT periphery on stm32f100, which would then trigger DebugMon_Handler to perform some diagnostic task.

I have already written a simple driver which does that. The driver works when using GNU toolchain. Unfortunately, when trying to import the same code to Keil (uVision 4) HardFault occurs. The fault occurs when CoreDebug->DEMCR is accessed.

Does anyone have any clues what might be wrong?

Thanks.

Bojan

#dwt-keil-stm32f100-watchpoint
3 REPLIES 3
os_kopernika
Associate II
Posted on April 05, 2014 at 14:39

And what was the cause of HF?

Perhaps you were accessing DEMCR in a wrong mode? Or you have made something with undefined behavior?

Posted on April 05, 2014 at 15:13

I've used other code in Keil that touches DEMCR, and not observed issues. What address does it end up accessing? And can you share enough code for others to replicate your condition?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bojan2
Associate
Posted on April 07, 2014 at 21:33

The dwt driver is attached.

Example:

...

#include ''dwt.h''

uint32_t my_var;

/* Watchpoint callback*/

void do_diagnostics(int32_t wp_n)

{

/* Do some diagnostics */

...

}

int main(void)

{

dwt_Comp_Num_t wp_n;

my_var = 0;

/* init */

dwt_comp_init();

/* Setup Write access watchpoint on my_var. */

wp_n = dwt_watchp_set((void *) &my_var) ;

/* Add callback to watch point. */

dwt_watchp_attach_callback(wp_n, do_diagnostics);

my_var = 10; /* this should trigger a debug handler and callback */

...

}

This code compiled with gcc works on stm32f1-discovery (stm32f100) board, but fails under Keil uVision4.

Maybe I missed something ...

Any suggestion would be really helpful.

Thanks

Bojan

________________

Attachments :

dwt.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1C5&d=%2Fa%2F0X0000000bjd%2Fe73lIo86tenOrYS5wrnhYIWHZfbXfSBvWq49ZZLrn.E&asPdf=false

dwt.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1C0&d=%2Fa%2F0X0000000bje%2Fo1UwTaP4mt4nNgnxUwWTIc2xKE8xlUy9PR22R2.MGoM&asPdf=false

dwt_conf.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Bv&d=%2Fa%2F0X0000000bjf%2FVKIGRajQbr8JQra4cVqdjsHCkuHmf2xUA9qKmkGJ1dU&asPdf=false