Hi Colin,
Sorry for the late reply (was away on holiday).
I have an external 32kHz crystal that I use to clock the external interrupt peripheral so that it is active even when the other clocks are stopped during STANDBY sleep mode. If you also use ASF, you must modify “conf_clocks.h” to enable the oscillator and keep it running in STANDBY mode:
/* SYSTEM_CLOCK_SOURCE_XOSC32K configuration - External 32KHz crystal/clock oscillator */
define CONF_CLOCK_XOSC32K_ENABLE true
define CONF_CLOCK_XOSC32K_EXTERNAL_CRYSTAL SYSTEM_CLOCK_EXTERNAL_CRYSTAL
define CONF_CLOCK_XOSC32K_STARTUP_TIME SYSTEM_XOSC32K_STARTUP_16384
define CONF_CLOCK_XOSC32K_AUTO_AMPLITUDE_CONTROL false
define CONF_CLOCK_XOSC32K_ENABLE_1KHZ_OUPUT false
define CONF_CLOCK_XOSC32K_ENABLE_32KHZ_OUTPUT true
define CONF_CLOCK_XOSC32K_ON_DEMAND false
define CONF_CLOCK_XOSC32K_RUN_IN_STANDBY true
You then need to enable a separate GCLK generator in “conf_clocks.h” and keep it running in STANDBY mode:
/* Configure GCLK generator 1 */
define CONF_CLOCK_GCLK_1_ENABLE true
define CONF_CLOCK_GCLK_1_RUN_IN_STANDBY true
define CONF_CLOCK_GCLK_1_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_XOSC32K
define CONF_CLOCK_GCLK_1_PRESCALER 1
define CONF_CLOCK_GCLK_1_OUTPUT_ENABLE false
In “conf_extint.h” you need to tell the peripheral to use GCLK1:
define EXTINT_CLOCK_SOURCE GCLK_GENERATOR_1
To put the CPU into STANDBY sleep mode, you can call the following function:
sleepmgr_sleep(SLEEPMGR_STANDBY);
I use an external edge interrupt to wake up the CPU, but I also tried an external level interrupt and got the same result: the CPU locked up and would not wake up. It could be worth your while to also read this thread:
http://community.atmel.com/comment/1953 … nt-1953791
In the end I decided to enable the watchdog (16 seconds reset) with the watchdog early warning interrupt (8 second interrupt) to wake up the CPU from STANDBY sleep mode and keep the watchdog happy. If the CPU does not wake up, then it will be reset 8 seconds later. This works well and the CPU is able to recover from the “deadlock”.
FYI, I found during my testing that the CPU locks up just by using the 8s watchdog early warning interrupt to wake it up (no external interrupt required). I used 4 test units: the first unit locked up within 1 day,… until all 4 units locked up after 4 days. So if you perform the test with 1 unit, it should lock up within 4 days.
NB! I have been unable to produce the problem on SAMD21 Xplained Pro boards (using SAMD21J18A), only on our boards using ATSAMD21E15B. The “B” device has a NVM area that can be used for non-volatile storage (instead of EEPROM). A fellow contractor has informed me that the NVM started to behave strangely after he enabled the early watchdog early warning interrupt, so he enables it only when going into STANDBY sleep mode (when he does not need to access the NVM area). I suspect that there is a link…
Anyway, good lock! If you find anything concrete, please post so that we can get to the bottom of it.
Best regards,
Pieter