This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2642R: Restart on exceptions

Part Number: CC2642R


Hi,

I have a project using CC2642R based on Simple Peripheral. In release build I want it to restart whenever any kind of exception or abort() happens. I have looked over the .cfg file but I'm not sure which of the hooks below I need to implement or if there is a standard policy to handle this. I have noticed that some of them default to a spin which I really don't want.

Error.policyFxn
Error.raiseHook

m3Hwi.enableException
m3Hwi.excHandlerFunc

System.abortFxn
System.exitFxn

SysCallback.abortFxn
SysCallback.exitFxn

  • Hi Martin,

    What about implementing a watchdog?

    You can find documentation and an example project in the SimpleLink CC13x2/CC26x2 SDK.

     

  • Yes I have a watchdog already, I forgot about that. In release build do all the handlers just implement a while(1) loop?

  • Hi Martin,

    Yes, in release build you will have the most aggressive approach for code footprint saving, which will trap exceptions and errors with while(1). If you have a look in your simple_peripheral_app.cfg, this will be because both "m3Hwi.excHandlerFunc" and "Error.raiseHook" are set to null. 

    If you want to decode exceptions and handle errors in any other manner, you could change either or both of these to:

    m3Hwi.enableException = true;     // Decode and print exceptions, raise errors
    //m3Hwi.enableException = false;  // Do not decode or print, but still raise errors
    //m3Hwi.excHandlerFunc = null;    // Trap in while(1)
    
    //Error.raiseHook = Error.print;
    //Error.raiseHook = null;                  // Trap in while(1)
    Error.raiseHook = "&myErrorFxn";  // Handle error in custom function

    Best regards,

    Vetle

  • great thank you! 

  • actually, I went back and looked at the case that made me ask this question and it looks like the watchdog won't fix it.

    I was calling Semaphore_post on an uninitialized semaphore, i.e.

    static Semaphore_Struct sem;

    Semaphore_post(Semaphore_handle(&sem));

    The watchdog wasn't firing, stepping through Semaphore_post() I thought the problem was that Hwi_disable() was called so I added a handler:

    m3Hwi.excHookFunc = "&execHandlerHook";

    void execHandlerHook(void *ctx)
    {

    Hwi_restore(0);

    while (1);

    }

    but this didn't work either, I guess because execHandlerHook is called in the context a HWI (?)  so the watchdog is blocked. I am now using:

    void execHandlerHook(void *ctx) {  SysCtrlSystemReset();  }

    so I guess this opens up the original question, will this handle all cases?

      

  • Hi Martin,

    For your case, in the Simple Peripheral project, the watchdog is implemented as a clock object and not by using the watchdog driver. This can be part of the problem, as you are correct in your 'execHandlerHook' function being called in Hwi context. 

    If you want the the application to restart on exception, your suggestion will handle your exception cases:

    void execHandlerHook(void *ctx)
    {
        SysCtrlSystemReset();
    }
    

    This is also the simplest solution, as you with a watchdog would have to wait for the timer to run out, and the overhead/delay would depend on when the exception is triggered. In this case, you will reset your application at the same time you know an exception has occurred.

    Best regards,

    Vetle

  • I am using the watchdog driver but it still isn't getting called when the processor is in this state. I will use the code above to force a restart.

    thanks!