diff options
author | BIGTREETECH <38851044+bigtreetech@users.noreply.github.com> | 2022-07-01 01:58:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-30 13:58:00 -0400 |
commit | 1636a9759bc2d5f162312ac8bf5823e95e0ad053 (patch) | |
tree | 5612ea4cfd8e61bf02ae817941c4c05b868e6c5e /src/stm32/stm32h7.c | |
parent | 167736ad1c127735806ba06858bc74c8ce6d49df (diff) | |
download | kutter-1636a9759bc2d5f162312ac8bf5823e95e0ad053.tar.gz kutter-1636a9759bc2d5f162312ac8bf5823e95e0ad053.tar.xz kutter-1636a9759bc2d5f162312ac8bf5823e95e0ad053.zip |
stm32: stm32g0/h7 usb_dfu_bootloader support (#5596)
Signed-off-by: Alan.Ma from BigTreeTech <tech@biqu3d.com>
Diffstat (limited to 'src/stm32/stm32h7.c')
-rw-r--r-- | src/stm32/stm32h7.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/stm32/stm32h7.c b/src/stm32/stm32h7.c index d6a32d96..bb0fe454 100644 --- a/src/stm32/stm32h7.c +++ b/src/stm32/stm32h7.c @@ -6,6 +6,7 @@ #include "autoconf.h" // CONFIG_CLOCK_REF_FREQ #include "board/armcm_boot.h" // VectorTable +#include "board/irq.h" // irq_disable #include "board/armcm_reset.h" // try_request_canboot #include "command.h" // DECL_CONSTANT_STR #include "internal.h" // get_pclock_frequency @@ -187,11 +188,36 @@ clock_setup(void) * USB bootloader ****************************************************************/ +#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 1024) +#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" + +// Flag that bootloader is desired and reboot +static void +usb_reboot_for_dfu_bootloader(void) +{ + irq_disable(); + *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; + NVIC_SystemReset(); +} + +// Check if rebooting into system DFU Bootloader +static void +check_usb_dfu_bootloader(void) +{ + if (!CONFIG_USBSERIAL || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG) + return; + *(uint64_t*)USB_BOOT_FLAG_ADDR = 0; + uint32_t *sysbase = (uint32_t*)0x1FF09800; + asm volatile("mov sp, %0\n bx %1" + : : "r"(sysbase[0]), "r"(sysbase[1])); +} + // Handle USB reboot requests void usb_request_bootloader(void) { try_request_canboot(); + usb_reboot_for_dfu_bootloader(); } @@ -205,8 +231,14 @@ armcm_main(void) { // Run SystemInit() and then restore VTOR SystemInit(); + RCC->D1CCIPR = 0x00000000; + RCC->D2CCIP1R = 0x00000000; + RCC->D2CCIP2R = 0x00000000; + RCC->D3CCIPR = 0x00000000; SCB->VTOR = (uint32_t)VectorTable; + check_usb_dfu_bootloader(); + clock_setup(); sched_main(); |