Skip to content

Commit

Permalink
soc: sam0: samd5x: xosc32 configurable startup time
Browse files Browse the repository at this point in the history
Adds Kconfig option to configure the startup time of the external
32KHz crystal oscillator.

Signed-off-by: Thomas Schranz <[email protected]>
(cherry picked from commit cd20154)
  • Loading branch information
Thomas Schranz authored and dkalowsk committed Jan 16, 2025
1 parent c861286 commit 72a1c80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 8 additions & 0 deletions soc/atmel/sam0/common/Kconfig.samd5x
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ config SOC_ATMEL_SAMD5X_XOSC32K
startup. This can then be selected as the main clock source
for the SOC.

config SOC_ATMEL_SAMD5X_XOSC32K_STARTUP
depends on SOC_ATMEL_SAMD5X_XOSC32K
hex "Startup time external 32 kHz crystal oscillator"
range 0x0 0x6
default 0x1
help
Selects the startup time for the external 32 kHz crystal oscillator.

choice
prompt "Main clock source"
default SOC_ATMEL_SAMD5X_DEFAULT_AS_MAIN
Expand Down
11 changes: 8 additions & 3 deletions soc/atmel/sam0/common/soc_samd5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
#define SAM0_DFLL_FREQ_HZ (48000000U)
#define SAM0_DPLL_FREQ_MIN_HZ (96000000U)
#define SAM0_DPLL_FREQ_MAX_HZ (200000000U)
#define SAM0_XOSC32K_STARTUP_TIME CONFIG_SOC_ATMEL_SAMD5X_XOSC32K_STARTUP

#if CONFIG_SOC_ATMEL_SAMD5X_XOSC32K_AS_MAIN
static void osc32k_init(void)
{
OSC32KCTRL->XOSC32K.reg = OSC32KCTRL_XOSC32K_ENABLE | OSC32KCTRL_XOSC32K_XTALEN
| OSC32KCTRL_XOSC32K_EN32K | OSC32KCTRL_XOSC32K_RUNSTDBY
| OSC32KCTRL_XOSC32K_STARTUP(0) | OSC32KCTRL_XOSC32K_CGM_XT;
OSC32KCTRL->XOSC32K.reg = OSC32KCTRL_XOSC32K_ENABLE
| OSC32KCTRL_XOSC32K_XTALEN
| OSC32KCTRL_XOSC32K_CGM_XT
| OSC32KCTRL_XOSC32K_EN32K
| OSC32KCTRL_XOSC32K_RUNSTDBY
| OSC32KCTRL_XOSC32K_STARTUP(SAM0_XOSC32K_STARTUP_TIME)
;

while (!OSC32KCTRL->STATUS.bit.XOSC32KRDY) {
}
Expand Down

0 comments on commit 72a1c80

Please sign in to comment.