21.8.1.2.1 Code
Copy-paste the following code to your user application:
/* Configure the external 32KHz oscillator */configure_extosc32k();/* Enable the external 32KHz oscillator */enumstatus_code osc32k_status =system_clock_source_enable(SYSTEM_CLOCK_SOURCE_XOSC32K);if(osc32k_status != STATUS_OK) {/* Error enabling the clock source */}#if (!SAMC21)/* Configure the DFLL in open loop mode using default values */configure_dfll_open_loop();/* Enable the DFLL oscillator */enumstatus_code dfll_status =system_clock_source_enable(SYSTEM_CLOCK_SOURCE_DFLL);if(dfll_status != STATUS_OK) {/* Error enabling the clock source */}/* Configure flash wait states before switching to high frequency clock */system_flash_set_waitstates(2);/* Change system clock to DFLL */structsystem_gclk_gen_config config_gclock_gen;system_gclk_gen_get_config_defaults(&config_gclock_gen);config_gclock_gen.source_clock = SYSTEM_CLOCK_SOURCE_DFLL;config_gclock_gen.division_factor = 1;system_gclk_gen_set_config(GCLK_GENERATOR_0, &config_gclock_gen);#endif
