Arduino Due and sysTickHook, why does it return?

Hi,

Looking at the SysTick_Handler() CMSIS handler I noticed that the isr might return after a calling to the user's sysTickHook() function, what this behaviour is good for?

void SysTick_Handler(void)
{
	if (sysTickHook())
		return;

	tickReset();

	// Increment tick count each ms
	TimeTick_Increment();
}

Despite the fact that the user can override sysTickHook() I can't see any reason why the remainder code should not be executed. If I override sysTickHook() to blink a LED and then I decide to return 0, then I'll lose the calls to tickReset() and TimeTick_Increment() breaking the system, due to there are some functions that relied upon it ( TimeTick_Increment() just increments the global variable _dwTickCount):

extern void Wait( volatile uint32_t dwMs )
{
    uint32_t dwStart ;
    uint32_t dwCurrent ;

    dwStart = _dwTickCount ;
    do
    {
        dwCurrent = _dwTickCount ;
    } while ( dwCurrent - dwStart < dwMs ) ;
}

/**
 *  \brief Sync Sleep for several ms
 */
extern void Sleep( volatile uint32_t dwMs )
{
    uint32_t dwStart ;
    uint32_t dwCurrent ;

    dwStart = _dwTickCount ;

    do
    {
        dwCurrent = _dwTickCount ;

        if ( dwCurrent - dwStart > dwMs )
        {
            break ;
        }

        __WFI() ;
    } while( 1 ) ;
}

Besides that, in the main() function someone tried to override the ISR handler, but then he/her regrets:

/*
 * Cortex-M3 Systick IT handler
 */
/*
extern void SysTick_Handler( void )
{
  // Increment tick count each ms
  TimeTick_Increment() ;
}
*/

And, why tickReset() would reset the tick counter in every tick? Although such function is declared, it's not defined (I didn't find the definition), so what is this good for?

Any hints? Thank you!

I think it's a way for the user hook routine sysTickHook() to signal back (by a true return),
that the standard behavior should not be invoked.

1 Like

tickReset is poorly named. It's defined in Reset.cpp, and has something to do with uploading new sketches via self-erasing (?) the flash or invoking the ROM-based bootloader.