diff --git a/ports/stm32/boards/OPENMV2/board_init.c b/ports/stm32/boards/OPENMV2/board_init.c new file mode 100644 index 000000000000..2bc1d187c062 --- /dev/null +++ b/ports/stm32/boards/OPENMV2/board_init.c @@ -0,0 +1,8 @@ +#include "py/mphal.h" +#define OMV_BOOTLOADER_MAGIC_ADDR (0x1000FFFCU) +#define OMV_BOOTLOADER_MAGIC_VALUE (0xB00710ADU) + +void board_enter_bootloader(void) { + *((uint32_t *) OMV_BOOTLOADER_MAGIC_ADDR) = OMV_BOOTLOADER_MAGIC_VALUE; + NVIC_SystemReset(); +} diff --git a/ports/stm32/boards/OPENMV2/mpconfigboard.h b/ports/stm32/boards/OPENMV2/mpconfigboard.h index 5d0b8f616dec..37d0708f413e 100644 --- a/ports/stm32/boards/OPENMV2/mpconfigboard.h +++ b/ports/stm32/boards/OPENMV2/mpconfigboard.h @@ -26,9 +26,10 @@ typedef unsigned int mp_uint_t; // must be pointer size #define MICROPY_HW_ENABLE_USB (1) #define MICROPY_HW_ENABLE_SDCARD (1) #define MICROPY_HW_TIM_IS_RESERVED(id) (id == 1 || id == 6) - #define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (0) -#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) NVIC_SystemReset() + +extern void board_enter_bootloader(void); +#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) board_enter_bootloader() #define MICROPY_HW_CLK_PLLM (6) #define MICROPY_HW_CLK_PLLN (360) diff --git a/ports/stm32/boards/OPENMV3/board_init.c b/ports/stm32/boards/OPENMV3/board_init.c new file mode 100644 index 000000000000..cc699644b5cc --- /dev/null +++ b/ports/stm32/boards/OPENMV3/board_init.c @@ -0,0 +1,8 @@ +#include "py/mphal.h" +#define OMV_BOOTLOADER_MAGIC_ADDR (0x2001FFFCU) +#define OMV_BOOTLOADER_MAGIC_VALUE (0xB00710ADU) + +void board_enter_bootloader(void) { + *((uint32_t *) OMV_BOOTLOADER_MAGIC_ADDR) = OMV_BOOTLOADER_MAGIC_VALUE; + NVIC_SystemReset(); +} diff --git a/ports/stm32/boards/OPENMV3/mpconfigboard.h b/ports/stm32/boards/OPENMV3/mpconfigboard.h index 6adc57a3be63..389d8ec6a8e9 100644 --- a/ports/stm32/boards/OPENMV3/mpconfigboard.h +++ b/ports/stm32/boards/OPENMV3/mpconfigboard.h @@ -27,9 +27,10 @@ typedef unsigned int mp_uint_t; // must be pointer size #define MICROPY_HW_ENABLE_USB (1) #define MICROPY_HW_ENABLE_SDCARD (1) #define MICROPY_HW_TIM_IS_RESERVED(id) (id == 1 || id == 6) - #define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (0) -#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) NVIC_SystemReset() + +extern void board_enter_bootloader(void); +#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) board_enter_bootloader() #define MICROPY_HW_CLK_PLLM (12) #define MICROPY_HW_CLK_PLLN (432) diff --git a/ports/stm32/boards/OPENMV4/board_init.c b/ports/stm32/boards/OPENMV4/board_init.c new file mode 100644 index 000000000000..cc699644b5cc --- /dev/null +++ b/ports/stm32/boards/OPENMV4/board_init.c @@ -0,0 +1,8 @@ +#include "py/mphal.h" +#define OMV_BOOTLOADER_MAGIC_ADDR (0x2001FFFCU) +#define OMV_BOOTLOADER_MAGIC_VALUE (0xB00710ADU) + +void board_enter_bootloader(void) { + *((uint32_t *) OMV_BOOTLOADER_MAGIC_ADDR) = OMV_BOOTLOADER_MAGIC_VALUE; + NVIC_SystemReset(); +} diff --git a/ports/stm32/boards/OPENMV4/mpconfigboard.h b/ports/stm32/boards/OPENMV4/mpconfigboard.h index 6fdfb9fcc6eb..464f65034f01 100644 --- a/ports/stm32/boards/OPENMV4/mpconfigboard.h +++ b/ports/stm32/boards/OPENMV4/mpconfigboard.h @@ -21,9 +21,10 @@ typedef unsigned int mp_uint_t; // must be pointer size #define MICROPY_HW_ENABLE_USB (1) #define MICROPY_HW_ENABLE_SDCARD (1) #define MICROPY_HW_TIM_IS_RESERVED(id) (id == 1 || id == 6) - #define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (0) -#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) NVIC_SystemReset() + +extern void board_enter_bootloader(void); +#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) board_enter_bootloader() // Note these are not used in top system.c. #define MICROPY_HW_CLK_PLLM (3) diff --git a/ports/stm32/boards/OPENMV4P/board_init.c b/ports/stm32/boards/OPENMV4P/board_init.c index 7c599b4b2094..c0c5e9b68639 100644 --- a/ports/stm32/boards/OPENMV4P/board_init.c +++ b/ports/stm32/boards/OPENMV4P/board_init.c @@ -2,8 +2,10 @@ #include "storage.h" #include "sdram.h" -void board_low_power(int mode) -{ +#define OMV_BOOTLOADER_MAGIC_ADDR (0x2001FFFCU) +#define OMV_BOOTLOADER_MAGIC_VALUE (0xB00710ADU) + +void board_low_power(int mode) { switch (mode) { case 0: // Leave stop mode. sdram_leave_low_power(); @@ -18,3 +20,8 @@ void board_low_power(int mode) // Enable QSPI deepsleep for modes 1 and 2 mp_spiflash_deepsleep(&spi_bdev.spiflash, (mode != 0)); } + +void board_enter_bootloader(void) { + *((uint32_t *) OMV_BOOTLOADER_MAGIC_ADDR) = OMV_BOOTLOADER_MAGIC_VALUE; + NVIC_SystemReset(); +} diff --git a/ports/stm32/boards/OPENMV4P/mpconfigboard.h b/ports/stm32/boards/OPENMV4P/mpconfigboard.h index c893840c9384..38c7d20624ec 100644 --- a/ports/stm32/boards/OPENMV4P/mpconfigboard.h +++ b/ports/stm32/boards/OPENMV4P/mpconfigboard.h @@ -21,9 +21,10 @@ typedef unsigned int mp_uint_t; // must be pointer size #define MICROPY_HW_HAS_FLASH (1) #define MICROPY_HW_ENABLE_SDCARD (1) #define MICROPY_HW_TIM_IS_RESERVED(id) (id == 1 || id == 6) - #define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (0) -#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) NVIC_SystemReset() + +extern void board_enter_bootloader(void); +#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) board_enter_bootloader() // Note these are not used in top system.c. #define MICROPY_HW_CLK_PLLM (3) diff --git a/ports/stm32/boards/OPENMVPT/board_init.c b/ports/stm32/boards/OPENMVPT/board_init.c index 7c599b4b2094..c0c5e9b68639 100644 --- a/ports/stm32/boards/OPENMVPT/board_init.c +++ b/ports/stm32/boards/OPENMVPT/board_init.c @@ -2,8 +2,10 @@ #include "storage.h" #include "sdram.h" -void board_low_power(int mode) -{ +#define OMV_BOOTLOADER_MAGIC_ADDR (0x2001FFFCU) +#define OMV_BOOTLOADER_MAGIC_VALUE (0xB00710ADU) + +void board_low_power(int mode) { switch (mode) { case 0: // Leave stop mode. sdram_leave_low_power(); @@ -18,3 +20,8 @@ void board_low_power(int mode) // Enable QSPI deepsleep for modes 1 and 2 mp_spiflash_deepsleep(&spi_bdev.spiflash, (mode != 0)); } + +void board_enter_bootloader(void) { + *((uint32_t *) OMV_BOOTLOADER_MAGIC_ADDR) = OMV_BOOTLOADER_MAGIC_VALUE; + NVIC_SystemReset(); +} diff --git a/ports/stm32/boards/OPENMVPT/mpconfigboard.h b/ports/stm32/boards/OPENMVPT/mpconfigboard.h index 8a868dfc1c11..797e92338780 100644 --- a/ports/stm32/boards/OPENMVPT/mpconfigboard.h +++ b/ports/stm32/boards/OPENMVPT/mpconfigboard.h @@ -21,9 +21,10 @@ typedef unsigned int mp_uint_t; // must be pointer size #define MICROPY_HW_ENABLE_USB (1) #define MICROPY_HW_ENABLE_SDCARD (1) #define MICROPY_HW_TIM_IS_RESERVED(id) (id == 1 || id == 6) - #define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (0) -#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) NVIC_SystemReset() + +extern void board_enter_bootloader(void); +#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) board_enter_bootloader() // Note these are not used in top system.c. #define MICROPY_HW_CLK_PLLM (3)