List of supported boards:
- SAM L21 Xplained Pro
- SAM L22 Xplained Pro
- SAM L22 Xplained Pro B
This example demonstrates how to use the power driver. BUTTON0 is used to wake up the system from the standby sleep mode and as an external wakeup pin to wake up the system from the backup sleep mode. The wakeup pin level is low. The I/O pins PB22/PB23 are used as GCLK0/GCLK1 outputs so that an oscilloscope can be used to monitor the clock frequencies.
After power-on-reset (POR), GCLK0 and GCLK1 runs at 4MHz and LED0 is turned on. After one second, LED0 is turned off and the system enters standby sleep mode. BUTTON0 can then be used to wake up the system. After the system wakeup, LED0 is turned on, the performance level is switched to PL2, and the GCLK0 is increased to 48MHz. Further LED0 toggles two times and is turned off before the system enters BACKUP.
When BUTTON0 pushes, it connects to low level, system wakes up from the backup sleep mode, LED0 toggles four times. GCLK0/GCLK1 are running at 4MHz.
Quick Start
Prerequisites
There are no prerequisites for this use case.
Code
Copy-paste the following setup code to your user application:
{
gclk_conf.division_factor = 1;
gclk_conf.run_in_standby = false;
gclk_conf.output_enable = true;
}
{
pin_conf.mux_position = CONF_GCLK0_OUTPUT_PINMUX;
pin_conf.mux_position = CONF_GCLK1_OUTPUT_PINMUX;
#if SAML21 || SAMR30
pin_conf.mux_position = CONF_EXT_WAKEUP_PINMUX;
#endif
}
{
config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;
config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;
}
}
{
for (uint32_t i = 0; i <
count; i++) {
}
}
Workflow
- Switch performance level to PL2.
{
gclk_conf.division_factor = 1;
gclk_conf.run_in_standby = false;
gclk_conf.output_enable = true;
}
- Configure GCLK0/GCLK1 output pin and extwakeup pin.
{
pin_conf.mux_position = CONF_GCLK0_OUTPUT_PINMUX;
pin_conf.mux_position = CONF_GCLK1_OUTPUT_PINMUX;
#if SAML21 || SAMR30
pin_conf.mux_position = CONF_EXT_WAKEUP_PINMUX;
#endif
}
- Config external interrupt.
{
config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;
config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;
}
}
Use Case
Code
Copy-paste the following code to your user application:
#if SAML21 || SAMR30
&& (system_get_pin_wakeup_cause() & (1 << CONF_EXT_WAKEUP_PIN))
) {
while(1);
}
#endif
#if SAML21 || SAMR30
system_set_pin_wakeup_polarity_low(1<<CONF_EXT_WAKEUP_PIN);
system_enable_pin_wakeup(1<<CONF_EXT_WAKEUP_PIN);
system_set_pin_wakeup_debounce_counter(SYSTEM_WAKEUP_DEBOUNCE_2CK32);
#endif
Workflow
- Check if the RESET is caused by external wakeup pin.
#if SAML21 || SAMR30
&& (system_get_pin_wakeup_cause() & (1 << CONF_EXT_WAKEUP_PIN))
) {
while(1);
}
#endif
- Check the standby mode and the backup sleep mode.
#if SAML21 || SAMR30
system_set_pin_wakeup_polarity_low(1<<CONF_EXT_WAKEUP_PIN);
system_enable_pin_wakeup(1<<CONF_EXT_WAKEUP_PIN);
system_set_pin_wakeup_debounce_counter(SYSTEM_WAKEUP_DEBOUNCE_2CK32);
#endif