Skip to content

samx5x: support external clock sources #8183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions ports/atmel-samd/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/peripherals
4 changes: 2 additions & 2 deletions ports/atmel-samd/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down