arduino-libraries / RTCZero

RTC Library for SAMD21 based boards
http://arduino.cc/en/Reference/RTC
GNU Lesser General Public License v2.1
76 stars 79 forks source link

Disable SAMD21 SysTick interrupt during sleep #84

Open robdmob opened 2 years ago

robdmob commented 2 years ago

This addresses a problem I experienced using an Adafruit Feather M0 where the board would suddenly refuse to wake up after a random time (4 - 12 hours). I found the solution in a discussion on the Atmel community forum: https://community.atmel.com/comment/2625116#comment-2625116.

In summary, due to a hardware bug on the SAMD21 platform it is possible for the SysTick interrupt to fire during wakeup before the RAM has had time to reinitialise which results in a hard fault. This can be prevented by disabling the SysTick interrupt before sleep and then reenabling it immediately after wakeup.

SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;  // Disable SysTick interrupt
__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 interrupt

After making this change the board has now been running for over two weeks with no problems.

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

github-actions[bot] commented 2 years ago

Memory usage change @ 42b760b83394dba79ee89d5e82fe476aa857ad85

Board flash % RAM for global variables %
arduino:samd:arduino_zero_edbg :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrfox1200 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrgsm1400 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrnb1500 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrvidor4000 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1300 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1310 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrzero :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
Click for full report table Board|examples/Epoch
flash|%|examples/Epoch
RAM for global variables|%|examples/SimpleRTC
flash|%|examples/SimpleRTC
RAM for global variables|%|examples/SimpleRTCAlarm
flash|%|examples/SimpleRTCAlarm
RAM for global variables|%|examples/SleepRTCAlarm
flash|%|examples/SleepRTCAlarm
RAM for global variables|% -|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|- arduino:samd:arduino_zero_edbg|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkr1000|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrfox1200|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrgsm1400|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrnb1500|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrvidor4000|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrwan1300|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrwan1310|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrwifi1010|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrzero|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:nano_33_iot|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0
Click for full report CSV ``` Board,examples/Epoch
flash,%,examples/Epoch
RAM for global variables,%,examples/SimpleRTC
flash,%,examples/SimpleRTC
RAM for global variables,%,examples/SimpleRTCAlarm
flash,%,examples/SimpleRTCAlarm
RAM for global variables,%,examples/SleepRTCAlarm
flash,%,examples/SleepRTCAlarm
RAM for global variables,% arduino:samd:arduino_zero_edbg,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkr1000,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrfox1200,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrgsm1400,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrnb1500,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrvidor4000,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrwan1300,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrwan1310,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrwifi1010,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrzero,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:nano_33_iot,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 ```
github-actions[bot] commented 1 year ago

Memory usage change @ 89695db5c3bae8c9184607514e5a2297092cc2e2

Board flash % RAM for global variables %
arduino:samd:arduino_zero_edbg :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrfox1200 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrgsm1400 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrnb1500 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrvidor4000 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1300 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1310 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrzero :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot :small_red_triangle: 0 - +20 0.0 - +0.01 0 - 0 0.0 - 0.0
Click for full report table Board|examples/Epoch
flash|%|examples/Epoch
RAM for global variables|%|examples/SimpleRTC
flash|%|examples/SimpleRTC
RAM for global variables|%|examples/SimpleRTCAlarm
flash|%|examples/SimpleRTCAlarm
RAM for global variables|%|examples/SleepRTCAlarm
flash|%|examples/SleepRTCAlarm
RAM for global variables|% -|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|- arduino:samd:arduino_zero_edbg|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkr1000|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrfox1200|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrgsm1400|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrnb1500|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrvidor4000|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrwan1300|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrwan1310|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrwifi1010|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:mkrzero|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0 arduino:samd:nano_33_iot|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|20|0.01|0|0.0
Click for full report CSV ``` Board,examples/Epoch
flash,%,examples/Epoch
RAM for global variables,%,examples/SimpleRTC
flash,%,examples/SimpleRTC
RAM for global variables,%,examples/SimpleRTCAlarm
flash,%,examples/SimpleRTCAlarm
RAM for global variables,%,examples/SleepRTCAlarm
flash,%,examples/SleepRTCAlarm
RAM for global variables,% arduino:samd:arduino_zero_edbg,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkr1000,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrfox1200,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrgsm1400,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrnb1500,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrvidor4000,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrwan1300,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrwan1310,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrwifi1010,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:mkrzero,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 arduino:samd:nano_33_iot,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,20,0.01,0,0.0 ```