From 856d48f7d4c4f59cb6d9fef75e5ee992a03e35c8 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 20 Feb 2024 21:46:57 +0100 Subject: [PATCH] rp2/main.c: Set the default clock frequency at boot and soft reset. As a side effect, the peripheral clock will be set to 48Mhz and both UART and I2C will not be affected by CPu speed changed using machine.freq(). With the change the UART baud rate range is 50 to 3_000_000. Signed-off-by: robert-hh --- ports/rp2/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ports/rp2/main.c b/ports/rp2/main.c index 70a67066fc..f3d56cff42 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -76,6 +76,10 @@ int main(int argc, char **argv) { // This is a tickless port, interrupts should always trigger SEV. SCB->SCR |= SCB_SCR_SEVONPEND_Msk; + // set the MCU frequency and as a side effect the peripheral clock + // to 48 MHz. + set_sys_clock_khz(125000, false); + #if MICROPY_HW_ENABLE_UART_REPL bi_decl(bi_program_feature("UART REPL")) setup_default_uart(); @@ -223,6 +227,12 @@ int main(int argc, char **argv) { soft_timer_deinit(); gc_sweep_all(); mp_deinit(); + // Reset the MCU frequency + set_sys_clock_khz(125000, false); + #if MICROPY_HW_ENABLE_UART_REPL + setup_default_uart(); + mp_uart_init(); + #endif } return 0;