diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 73686e1445..6fb969e47b 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -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 diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index baca4c0843..82e514b6e0 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit baca4c084334aa8625f525a4032d66a397199ea6 +Subproject commit 82e514b6e0d1a2b09dc73be9973663b6b837a817 diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 8cba5c61e0..8ae2d3740e 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -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();