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 <qyriad@qyriad.me>
This commit is contained in:
Qyriad 2023-07-18 16:47:37 -06:00
parent 8de9d5a522
commit 3f3ec1c835
3 changed files with 27 additions and 3 deletions

View File

@ -173,6 +173,30 @@
#define BOARD_HAS_CRYSTAL (0)
#endif
#ifndef BOARD_XOSC_FREQ_HZ
// 0 Indicates XOSC is not used.
#define BOARD_XOSC_FREQ_HZ (0)
#else
// For now, only allow external clock sources that divide cleanly into
// the system clock frequency of 120 MHz.
#if (120000000 % BOARD_XOSC_FREQ_HZ) != 0
#error "BOARD_XOSC_FREQ_HZ must be an integer factor of 120 MHz"
#endif
#endif
#if BOARD_XOSC_FREQ_HZ != 0
// External clock sources are currently not implemented for SAMD21 chips.
#ifdef SAMD21
#error "BOARD_XOSC_FREQ_HZ is non-zero but external clock sources are not yet supported for SAMD21 chips"
#endif
#ifndef BOARD_XOSC_IS_CRYSTAL
#error "BOARD_XOSC_IS_CRYSTAL must be defined to 0 or 1 if BOARD_XOSC_FREQ_HZ is not 0"
#endif
#else
// It doesn't matter what the value is in this case.
#define BOARD_XOSC_IS_CRYSTAL (0)
#endif
// if CALIBRATE_CRYSTALLESS is requested, make room for storing
// calibration data generated from external USB.
#ifndef CIRCUITPY_INTERNAL_CONFIG_SIZE

@ -1 +1 @@
Subproject commit baca4c084334aa8625f525a4032d66a397199ea6
Subproject commit 82e514b6e0d1a2b09dc73be9973663b6b837a817

View File

@ -353,10 +353,10 @@ safe_mode_t port_init(void) {
if (strcmp((char *)CIRCUITPY_INTERNAL_CONFIG_START_ADDR, "CIRCUITPYTHON1") == 0) {
fine = ((uint16_t *)CIRCUITPY_INTERNAL_CONFIG_START_ADDR)[8];
}
clock_init(BOARD_HAS_CRYSTAL, fine);
clock_init(BOARD_HAS_CRYSTAL, BOARD_XOSC_FREQ_HZ, BOARD_XOSC_IS_CRYSTAL, fine);
#else
// Use a default fine value
clock_init(BOARD_HAS_CRYSTAL, DEFAULT_DFLL48M_FINE_CALIBRATION);
clock_init(BOARD_HAS_CRYSTAL, BOARD_XOSC_FREQ_HZ, BOARD_XOSC_IS_CRYSTAL, DEFAULT_DFLL48M_FINE_CALIBRATION);
#endif
rtc_init();