Skip to content

Commit 42b760b

Browse files
authored
Disable SAMD21 SysTick interrupt during sleep
Disabling the systick timer interrupt during sleep has previously been discussed on the Microchip/Atmel community forum: https://community.atmel.com/comment/2625116#comment-2625116. In summary, due to a hardware bug on the SAMD21, the SysTick interrupts become active before the flash has powered up from sleep, causing a hard fault after a random time. To prevent this the SysTick interrupts are disabled before entering sleep mode and enabled oncemore after the processor has woken up: SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; // Disable SysTick interrupts __DSB(); // Data sync to ensure outgoing memory accesses complete __WFI(); // Wait for interrupt (places device in sleep mode) SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; // Enable SysTick interrupts
1 parent d393a25 commit 42b760b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/RTCZero.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,15 @@ void RTCZero::detachInterrupt()
145145

146146
void RTCZero::standbyMode()
147147
{
148+
// Disable systick interrupt
149+
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
148150
// Entering standby mode when connected
149151
// via the native USB port causes issues.
150152
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
151153
__DSB();
152154
__WFI();
155+
// Enable systick interrupt
156+
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
153157
}
154158

155159
/*

0 commit comments

Comments
 (0)