RTCZero icon indicating copy to clipboard operation
RTCZero copied to clipboard

Disable SAMD21 SysTick interrupt during sleep

Open robdmob opened this issue 3 years ago • 3 comments
trafficstars

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.

robdmob avatar Feb 16 '22 23:02 robdmob

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Feb 16 '22 23:02 CLAassistant

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<br>flash,%,examples/Epoch<br>RAM for global variables,%,examples/SimpleRTC<br>flash,%,examples/SimpleRTC<br>RAM for global variables,%,examples/SimpleRTCAlarm<br>flash,%,examples/SimpleRTCAlarm<br>RAM for global variables,%,examples/SleepRTCAlarm<br>flash,%,examples/SleepRTCAlarm<br>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] avatar Feb 16 '22 23:02 github-actions[bot]

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<br>flash,%,examples/Epoch<br>RAM for global variables,%,examples/SimpleRTC<br>flash,%,examples/SimpleRTC<br>RAM for global variables,%,examples/SimpleRTCAlarm<br>flash,%,examples/SimpleRTCAlarm<br>RAM for global variables,%,examples/SleepRTCAlarm<br>flash,%,examples/SleepRTCAlarm<br>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] avatar Jul 02 '22 21:07 github-actions[bot]