21.8.2.1.2 Code
Copy-paste the following setup code to your user application:
Add to user application initialization (typically the start of main()):voidconfigure_gclock_generator(void){structsystem_gclk_gen_config gclock_gen_conf;system_gclk_gen_get_config_defaults(&gclock_gen_conf);#if (SAML21) || (SAML22)gclock_gen_conf.source_clock = SYSTEM_CLOCK_SOURCE_OSC16M;gclock_gen_conf.division_factor = 128;#elif (SAMC21)gclock_gen_conf.source_clock = SYSTEM_CLOCK_SOURCE_OSC48M;gclock_gen_conf.division_factor = 128;#elsegclock_gen_conf.source_clock = SYSTEM_CLOCK_SOURCE_OSC8M;gclock_gen_conf.division_factor = 128;#endifsystem_gclk_gen_set_config(GCLK_GENERATOR_1, &gclock_gen_conf);system_gclk_gen_enable(GCLK_GENERATOR_1);}voidconfigure_gclock_channel(void){structsystem_gclk_chan_config gclk_chan_conf;system_gclk_chan_get_config_defaults(&gclk_chan_conf);gclk_chan_conf.source_generator = GCLK_GENERATOR_1;#if (SAMD10) || (SAMD11)system_gclk_chan_set_config(TC1_GCLK_ID, &gclk_chan_conf);system_gclk_chan_enable(TC1_GCLK_ID);#elsesystem_gclk_chan_set_config(TC3_GCLK_ID, &gclk_chan_conf);system_gclk_chan_enable(TC3_GCLK_ID);#endif}
configure_gclock_generator();configure_gclock_channel();
