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:
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.
- Initialize the DFLL 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.
- Write the new configuration to the DFLL module.
Use Case
Code
Copy-paste the following code to your user application:
#if(SAMR30E)
{
}
}
#else
{
}
}
#endif
#if (!SAMC21)
}
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.
- 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.division_factor = 1;