lpcware

SysTick just stops for no apparent reason

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by sdt99 on Thu Sep 25 08:08:02 MST 2014
LPC1857 on Keil demo board with IAR, using 1ms SysTick as the primary clock source.  I have one variable updated by Systick and used by the main code so I wanted to suspend SysTick interrupts when the variable is accessed by the main code.  Here is SysTick initialization (works fine):(CoreClock=180MHz, so the countdown value is within range :  I checked)

#define TICKRATE_HZ1 (1000)/* 1000 ticks per second */
SysTick_Config(SystemCoreClock / TICKRATE_HZ1);


Here are functions I created to disable and re-enable SysTick, checking for a missed tick.  The intent was to disable the tick, access the variable (memcpy) and reenable the tick.

void DisableSysTick(void){
    SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; // disable Systick interupt
}

void EnableSysTick(void){
    // Check if an interrupt was missed
    if(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk){
        SysTick_Handler();
    }
    SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; // Enable Systick interupt
}


If I call these functions then SysTick seems to randomly stop ticking.  When I dump memory from xe000e000 to xe000f000 to look for any register changes that might explain the stop I see no changes (other than the downcounter value, of course).

If I comment out these functions then SysTick continues to work.

I can't see why this code would cause a problem from either NXP or ARM documentation, but I am pretty new to NXP ARM CPUs.

Would be grateful if anyone can point out any obvious errors.   I could restructure my code to avoid masking systick, but I am bothered by the fact that I don't understand why the tick stops.

Thanks

Outcomes