Disable SAMD21 SysTick interrupt during sleep and correct SAMD20/21 defines #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses two separate issues.
The first is in response to the issue: "strange reset on Feather M0 after random minutes", raised here: #9.
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:
The second issue, is that to the best of my knowledge the SAMD20 and SAMD21 definitions do not exist, either in the included "sam.h" file or anywhere else. I've tested the definitions with a small sketch and SAMD21 remains undefined. This means that the line that prevents the RAM from powering down during sleep never gets called:
The "sam.h" file does however provide a SAMD21_SERIES define and earlier versions also include SAMD20_SERIES, these encompass all the SAMD20/SAMD21 variants:
I've tested the code on a SAMD21, however I'm unable to test on a SAMD20. I've assumed that the SAMD20 also being an ARM Cortex M0+ exhibits the same behaviour as the SAMD21. The SAMD51 code remains unaffected by these changes.