This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NMI - SPEST problem

Hi 

I'm having a problem with a NMI triggering  in the NMISR : Non-Maskable Interrupt Status Register CPU Stack Pointer Monitor Interrupt Status Flag (SPEST) any ideas how to trace this error ?

thanks A

  • One of the Stack pointers (MSP or PSP) is going outside the configured stack area, so it is triggering HW Stack pointer monitor (i.e. the stack has overflowed).

    The PSP is used in threads/tasks, and the MSP is used in interrupt handlers in an RTOS based project.

    You can register a user callback for the stack monitor NMI interrupt in R_BSP_WarmStart, for the event BSP_WARM_START_POST_C :-

            R_BSP_GroupIrqWrite(BSP_GRP_IRQ_MPU_STACK, usr_nmi_hw_stack_callback);

    and then in the user callback, work out which stack has overflowed, if it is the PSP that has overflowed, work out which task/thread is the currently executing one when the NMI was triggered.



    #define MSP_STACK    0
    #define PSP_STACK    1

    void usr_nmi_hw_stack_callback(bsp_grp_irq_t irq)
    {
        FSP_PARAMETER_NOT_USED(irq);

        uint32_t psp;
        uint32_t msp;

        msp = __get_MSP();
        psp = __get_PSP();


        if ((  R_MPU_SPMON->SP[MSP_STACK].SA > msp) || (  R_MPU_SPMON->SP[MSP_STACK].EA < msp))
        {
            __BKPT(0); // MSP stack outside range. Interrupt/kernel stack overflow.
        }
        else if ((R_MPU_SPMON->SP[PSP_STACK].SA > psp) || (R_MPU_SPMON->SP[PSP_STACK].EA < psp))
        {

          //work out which Thread is currently running.
            __BKPT(0); // PSP stack outside range. Thread stack overflow.
        }
        else
        {
        }
    }

  • Thanks Jeremy,  I will try later today, the main problem of the stack overflow  is caused by faulty/badly configured  hardware device on the PCB which is basically putting a 100k 'clock' on the pin configured for an external IRQ.

    Thanks A

  • Hi Double A, 

    Did Jeremy's suggestion solved your issue?? 

    Herald
    RenesasRulz Forum Moderator

    https://renesasrulz.com/
    https://academy.renesas.com/
    en-us.knowledgebase.renesas.com/

  • Yes thank you. I was more of an external hardware issue 

    thanks AA