Hello @wangyang06014 ,
We tried to implement it, also for S32K148, and initially we had the same issue than you.
The problem is only in debug mode, as it seems the debugger controls the DebugMon_Handler interrupt in a particular way, because in debug mode there actually is a break when it goes in overflow (run is interrupted inside the "push" loop at loop 16) but the DebugMon_Handler code is not executed.
However in normal run without the debugger attached the code inside DebugMon_Handler is executed correctly : on the EVB with example code the LED lights up in RED as expected (and for our project we put some debug statement on uart and saw it printed as expected).
Once you have tested it, to actually implement it in your system, it seems you have to insert the actual address for your stack limit (if you leave the comparator setting as in the example, the error will be triggered after a few function calls:
Original:
DWT->NUMCOMP[0].COMP = (uint32_t)stackPointer - (16 * sizeof(uint32_t));
I set it using the actual address from the linker file:
extern uint32_t __StackLimit[];
#define DWT_OVERFLOW_DATA_ADDR ((uint32_t )(__StackLimit))
DWT->NUMCOMP[0].COMP = DWT_OVERFLOW_DATA_ADDR;
Can someone from NXP confirm that it is the correct way to implement it in a running system?
Best regards,