From 11367953d2de3568c25875040f58fcc0cc182131 Mon Sep 17 00:00:00 2001 From: 1ridic Date: Wed, 27 Sep 2023 12:01:55 +0800 Subject: [PATCH] [bsp][pico] Add msh cmd to reset pico to BOOTSEL mode --- bsp/raspberry-pico/board/board.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/bsp/raspberry-pico/board/board.c b/bsp/raspberry-pico/board/board.c index 7cfbfc64cb..11dd09d3f7 100644 --- a/bsp/raspberry-pico/board/board.c +++ b/bsp/raspberry-pico/board/board.c @@ -16,6 +16,7 @@ #include "board.h" #include "hardware/structs/systick.h" +#include "pico/bootrom.h" #define PLL_SYS_KHZ (133 * 1000) @@ -36,16 +37,16 @@ void isr_systick(void) uint32_t systick_config(uint32_t ticks) { - if ((ticks - 1UL) > M0PLUS_SYST_RVR_RELOAD_BITS) - { - return (1UL); /* Reload value impossible */ - } + if ((ticks - 1UL) > M0PLUS_SYST_RVR_RELOAD_BITS) + { + return (1UL); /* Reload value impossible */ + } - mpu_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */ - mpu_hw->csr = M0PLUS_SYST_CSR_CLKSOURCE_BITS | + mpu_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */ + mpu_hw->csr = M0PLUS_SYST_CSR_CLKSOURCE_BITS | M0PLUS_SYST_CSR_TICKINT_BITS | M0PLUS_SYST_CSR_ENABLE_BITS; /* Enable SysTick IRQ and SysTick Timer */ - return (0UL); /* Function successful */ + return (0UL); /* Function successful */ } void rt_hw_board_init() @@ -71,12 +72,13 @@ void rt_hw_board_init() // Call each function in the list. // We have to take the address of the symbols, as __init_array_start *is* // the first function pointer, not the address of it. - for (void (**p)() = &__init_array_start; p < &__init_array_end; ++p) { + for (void (**p)() = &__init_array_start; p < &__init_array_end; ++p) + { (*p)(); } /* Configure the SysTick */ - systick_config(clock_get_hz(clk_sys)/RT_TICK_PER_SECOND); + systick_config(clock_get_hz(clk_sys) / RT_TICK_PER_SECOND); #ifdef RT_USING_COMPONENTS_INIT rt_components_board_init(); @@ -88,6 +90,15 @@ void rt_hw_board_init() #endif #ifdef RT_USING_CONSOLE - rt_console_set_device(RT_CONSOLE_DEVICE_NAME); + rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif } + +#ifdef RT_USING_MSH +static int pico_reboot(int argc, char *argv[]) +{ + reset_usb_boot(0, 0); + return 0; +} +MSH_CMD_EXPORT_ALIAS(pico_reboot, reboot, reset Pico to BOOTSEL mode); +#endif