Setting the SAMD21’s SLEEPDEEP bit in the ARM Core’s System Control Register (SCR), indicates that when the low power mode is activated, the processor should go into low power STANDBY mode, (rather than IDLE mode):
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Set up the CPU to enter low power STANDBY mode, (rather than IDLE mode)
The __WFI() (Wait for Interrupt) function is the command that actually puts the processor into deep sleep:
__WFI(); // Put the SAMD21 into deep sleep Zzzzzzzzzz
In this instance the processor can be woken by an interrupt, by simply using the attachInterrupt() function.
The SAMD21 also allows its various on-chip oscillators and off-chip crystals to remain active during sleep, in order for selected peripherals to remain active. This is usually done by setting the oscillator’s and peripheral’s RUNSTDBY (Run Standby) bit. For example this can be used allow the SAMD21’s Real Time Clock (RTC) to run off a slow clock, such as the 32.768kHz crystal, while CPU is asleep.
There’s also an ONDEMAND bit that allows the clocks to become active only when required by the peripheral. In this case a request is sent by the peripheral back via the generic clock system to start and stop the oscillator.