From 42b760b83394dba79ee89d5e82fe476aa857ad85 Mon Sep 17 00:00:00 2001 From: Rob <31293055+robdmob@users.noreply.github.com> Date: Tue, 15 Feb 2022 23:11:02 +0000 Subject: [PATCH] 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 --- src/RTCZero.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/RTCZero.cpp b/src/RTCZero.cpp index 593a8bb..e322d0f 100644 --- a/src/RTCZero.cpp +++ b/src/RTCZero.cpp @@ -145,11 +145,15 @@ void RTCZero::detachInterrupt() void RTCZero::standbyMode() { + // Disable systick interrupt + SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; // Entering standby mode when connected // via the native USB port causes issues. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; __DSB(); __WFI(); + // Enable systick interrupt + SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; } /*