From c6d4338c87ce703fc958e4cf31a320686e867ef7 Mon Sep 17 00:00:00 2001 From: Steven Slupsky Date: Wed, 8 May 2019 15:18:02 -0600 Subject: [PATCH 1/2] fix SysTick timer lockup when waking from sleep --- src/samd/ArduinoLowPower.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/samd/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp index d756ed6..43506b2 100644 --- a/src/samd/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -23,10 +23,13 @@ void ArduinoLowPowerClass::sleep() { USBDevice.detach(); restoreUSBDevice = true; } + // Disable systick interrupt: See https://www.avrfreaks.net/forum/samd21-samd21e16b-sporadically-locks-and-does-not-wake-standby-sleep-mode + SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; __DSB(); __WFI(); - if (restoreUSBDevice) { + // Enable systick interrupt + SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; if (restoreUSBDevice) { USBDevice.attach(); } } From 9d898e998fa7426dbc5254c3262080c9f9b5066d Mon Sep 17 00:00:00 2001 From: Steven Slupsky Date: Wed, 8 May 2019 16:09:28 -0600 Subject: [PATCH 2/2] fix formatting --- src/samd/ArduinoLowPower.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/samd/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp index 43506b2..faee7e8 100644 --- a/src/samd/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -29,7 +29,8 @@ void ArduinoLowPowerClass::sleep() { __DSB(); __WFI(); // Enable systick interrupt - SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; if (restoreUSBDevice) { + SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; + if (restoreUSBDevice) { USBDevice.attach(); } }