Skip to content

Commit 7fbc951

Browse files
committed
samx5x: support external clock sources
Adds two board config define's, which can be added in a board's mpconfigboard.h: BOARD_XOSC_FREQ_HZ, and BOARD_XOSC_IS_CRYSTAL, which are passed to clock_init(). External clock sources are currently only implemented for SAM_D5X_E5X series chips, so defining BOARD_XOSC_FREQ_HZ for a SAMD21 board will emit an error. Signed-off-by: Qyriad <[email protected]>
1 parent 8de9d5a commit 7fbc951

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

ports/atmel-samd/mpconfigport.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,30 @@
173173
#define BOARD_HAS_CRYSTAL (0)
174174
#endif
175175

176+
#ifndef BOARD_XOSC_FREQ_HZ
177+
// 0 Indicates XOSC is not used.
178+
#define BOARD_XOSC_FREQ_HZ (0)
179+
#else
180+
// For now, only allow external clock sources that divide cleanly into
181+
// the system clock frequency of 120 MHz.
182+
#if (120000000 % BOARD_XOSC_FREQ_HZ) != 0
183+
#error "BOARD_XOSC_FREQ_HZ must be an integer factor of 120 MHz"
184+
#endif
185+
#endif
186+
187+
#if BOARD_XOSC_FREQ_HZ != 0
188+
// External clock sources are currently not implemented for SAMD21 chips.
189+
#ifdef SAMD21
190+
#error "BOARD_XOSC_FREQ_HZ is non-zero but external clock sources are not yet supported for SAMD21 chips"
191+
#endif
192+
#ifndef BOARD_XOSC_IS_CRYSTAL
193+
#error "BOARD_XOSC_IS_CRYSTAL must be defined to 0 or 1 if BOARD_XOSC_FREQ_HZ is not 0"
194+
#endif
195+
#else
196+
// It doesn't matter what the value is in this case.
197+
#define BOARD_XOSC_IS_CRYSTAL (0)
198+
#endif
199+
176200
// if CALIBRATE_CRYSTALLESS is requested, make room for storing
177201
// calibration data generated from external USB.
178202
#ifndef CIRCUITPY_INTERNAL_CONFIG_SIZE

ports/atmel-samd/supervisor/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ safe_mode_t port_init(void) {
356356
clock_init(BOARD_HAS_CRYSTAL, fine);
357357
#else
358358
// Use a default fine value
359-
clock_init(BOARD_HAS_CRYSTAL, DEFAULT_DFLL48M_FINE_CALIBRATION);
359+
clock_init(BOARD_HAS_CRYSTAL, BOARD_XOSC_FREQ_HZ, BOARD_XOSC_IS_CRYSTAL, DEFAULT_DFLL48M_FINE_CALIBRATION);
360360
#endif
361361

362362
rtc_init();

0 commit comments

Comments
 (0)