From d17bafd1fab186019054c53a62b667fe159734c2 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 12 Nov 2024 10:48:11 +0100 Subject: [PATCH] ports/rp2: Fix firmware. Signed-off-by: iabdalkader --- src/omv/ports/rp2/main.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/omv/ports/rp2/main.c b/src/omv/ports/rp2/main.c index fe531f332..10d75fa8d 100644 --- a/src/omv/ports/rp2/main.c +++ b/src/omv/ports/rp2/main.c @@ -45,6 +45,7 @@ #include "mpbthciport.h" #include "mpnetworkport.h" #include "genhdr/mpversion.h" + #include "pico/stdlib.h" #include "pico/binary_info.h" #include "pico/unique_id.h" @@ -53,6 +54,8 @@ #include "hardware/regs/intctrl.h" #include "hardware/structs/rosc.h" #include "pico/bootrom.h" +#include "pico/aon_timer.h" +#include "shared/timeutils/timeutils.h" #include "omv_boardconfig.h" #include "framebuffer.h" @@ -107,6 +110,19 @@ void pico_reset_to_bootloader(size_t n_args, const void *args_in) { int main(int argc, char **argv) { bool first_soft_reset = true; + // This is a tickless port, interrupts should always trigger SEV. + #if PICO_ARM + SCB->SCR |= SCB_SCR_SEVONPEND_Msk; + #endif + + soft_timer_init(); + + // Set the MCU frequency and as a side effect the peripheral clock to 48 MHz. + set_sys_clock_khz(SYS_CLK_KHZ, false); + + // Hook for setting up anything that needs to be super early in the bootup process. + MICROPY_BOARD_STARTUP(); + #if MICROPY_HW_ENABLE_UART_REPL bi_decl(bi_program_feature("UART REPL")) setup_default_uart(); @@ -127,17 +143,9 @@ int main(int argc, char **argv) { #endif // Start and initialise the RTC - datetime_t t = { - .year = 2021, - .month = 1, - .day = 1, - .dotw = 4, // 0 is Monday, so 4 is Friday - .hour = 0, - .min = 0, - .sec = 0, - }; - rtc_init(); - rtc_set_datetime(&t); + struct timespec ts = { 0, 0 }; + ts.tv_sec = timeutils_seconds_since_epoch(2021, 1, 1, 0, 0, 0); + aon_timer_start(&ts); mp_hal_time_ns_set_from_rtc(); // Set board unique ID from flash for USB debugging.