In SSP 1.0, ThreadX introduced the use of the HW stack monitor (enabled by default), so each time a thread is run, the HW stack monitor is programmed with the limits of the stack for that task. If the stack pointer goes outside the region that is set in the HW stack monitor, an NMI will occur (R_ICU- NMISR_b.SPEST). I like to register a user NMI hw stack monitor callback :- void R_BSP_WarmStart (bsp_warm_start_event_t event) { if (BSP_WARM_START_PRE_C == event) { /* C runtime environment has not been setup so you cannot use globals. System clocks and pins are not setup. */ } else if (BSP_WARM_START_POST_C == event) { /* C runtime environment, system clocks, and pins are all setup. */ /* Register a user callback for HW stack monitor NMI interrupt */ R_BSP_GroupIrqWrite(BSP_GRP_IRQ_MPU_STACK, usr_nmi_hw_stack_callback); } else { /* Unhandled case. */ } } Then in the NMI hw stack monitor callback, by default I use the code :- #include "bsp_api.h" void usr_nmi_hw_stack_callback(bsp_grp_irq_t irq) { __asm("BKPT #0\n") ; // Break into the debugger } to force a breakpoint to occur if a NMI occurs due to the HW stack monitor, so I don't have to remember to set a breakpoint (or use up breakpoint resources). By default, a thread is created with a stack size of 1024 bytes, depending on the code in the thread, this thread stack size might need to be increased.
↧