20.7.1.1.2 Code
Copy-paste the following setup code to your user application:
staticvoidperformance_level_switch_test(void){structsystem_gclk_gen_config gclk_conf;/* Switch to PL2 */system_switch_performance_level(SYSTEM_PERFORMANCE_LEVEL_2);system_flash_set_waitstates(2);/* Switch GCLK0 to 48MHz */system_gclk_gen_get_config_defaults(&gclk_conf);gclk_conf.source_clock = SYSTEM_CLOCK_SOURCE_DFLL;gclk_conf.division_factor = 1;gclk_conf.run_in_standby =false;gclk_conf.output_enable =true;system_gclk_gen_set_config(GCLK_GENERATOR_0, &gclk_conf);}staticvoidconfig_clock_output_and_extwake_pin(void){structsystem_pinmux_config pin_conf;system_pinmux_get_config_defaults(&pin_conf);pin_conf.mux_position = CONF_GCLK0_OUTPUT_PINMUX;pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;system_pinmux_pin_set_config(CONF_GCLK0_OUTPUT_PIN, &pin_conf);pin_conf.mux_position = CONF_GCLK1_OUTPUT_PINMUX;system_pinmux_pin_set_config(CONF_GCLK1_OUTPUT_PIN, &pin_conf);#if SAML21pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_UP;pin_conf.mux_position = CONF_EXT_WAKEUP_PINMUX;system_pinmux_pin_set_config(CONF_EXT_WAKEUP_PIN, &pin_conf);#endif}staticvoidconfigure_extint_channel(void){structextint_chan_conf config_extint_chan;extint_chan_get_config_defaults(&config_extint_chan);config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;config_extint_chan.gpio_pin_pull = EXTINT_PULL_UP;config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);extint_chan_enable_callback(BUTTON_0_EIC_LINE,EXTINT_CALLBACK_TYPE_DETECT);system_interrupt_enable_global();while(extint_chan_is_detected(BUTTON_0_EIC_LINE)) {extint_chan_clear_detected(BUTTON_0_EIC_LINE);}}staticvoidled_toggle_indication(uint32_t count){for(uint32_t i = 0; i < count; i++) {port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);delay_ms(200);port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);delay_ms(200);}}
