In this case we apply the following configuration:
- RC8MHz (internal 8MHz RC oscillator)
- Divide by four, giving a frequency of 2MHz
- DFLL (Digital frequency locked loop)
- Open loop mode
- 48MHz frequency
- CPU clock
- Use two wait states when reading from flash memory
- Use the DFLL, configured to 48MHz
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Copy-paste the following setup code to your application:
void configure_osc32k(void)
{
}
Workflow
- Create a EXTOSC32K module configuration struct, which can be filled out to adjust the configuration of the external 32KHz oscillator channel.
- Initialize the oscillator configuration struct with the module's default values.
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Alter the EXTOSC32K module configuration struct to require a start-up time of 4096 clock cycles.
- Write the new configuration to the EXTOSC32K module.
- Create a DFLL module configuration struct, which can be filled out to adjust the configuration of the external 32KHz oscillator channel.
struct system_clock_source_dfll_config config_dfll;
- Initialize the DFLL oscillator configuration struct with the module's default values.
system_clock_source_dfll_get_config_defaults(&config_dfll);
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Write the new configuration to the DFLL module.
system_clock_source_dfll_set_config(&config_dfll);
Use Case
Code
Copy-paste the following code to your user application:
#if(SAMR30E)
{
configure_osc32k();
}
}
#else
{
configure_extosc32k();
}
}
#endif
#if (!SAMC21)
configure_dfll_open_loop();
}
config_gclock_gen.source_clock = SYSTEM_CLOCK_SOURCE_DFLL;
config_gclock_gen.division_factor = 1;
#endif
Workflow
- Configure the external 32KHz oscillator source using the previously defined setup function.
- Enable the configured external 32KHz oscillator source.
- Configure the DFLL oscillator source using the previously defined setup function.
configure_dfll_open_loop();
- Enable the configured DFLL oscillator source.
- Configure the flash wait states to have two wait states per read, as the high speed DFLL will be used as the system clock. If insufficient wait states are used, the device may crash randomly due to misread instructions.
- Switch the system clock source to the DFLL, by reconfiguring the main clock generator.
config_gclock_gen.source_clock = SYSTEM_CLOCK_SOURCE_DFLL;
config_gclock_gen.division_factor = 1;