diff options
author | BIGTREETECH <38851044+bigtreetech@users.noreply.github.com> | 2022-06-30 20:58:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-30 20:58:00 +0300 |
commit | 1636a9759bc2d5f162312ac8bf5823e95e0ad053 (patch) | |
tree | 5612ea4cfd8e61bf02ae817941c4c05b868e6c5e | |
parent | 167736ad1c127735806ba06858bc74c8ce6d49df (diff) |
stm32: stm32g0/h7 usb_dfu_bootloader support (#5596)
Signed-off-by: Alan.Ma from BigTreeTech <tech@biqu3d.com>
-rwxr-xr-x | scripts/flash_usb.py | 3 | ||||
-rw-r--r-- | src/stm32/stm32g0.c | 3 | ||||
-rw-r--r-- | src/stm32/stm32h7.c | 32 |
3 files changed, 36 insertions, 2 deletions
diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py index 4004ad556..3d62a643e 100755 --- a/scripts/flash_usb.py +++ b/scripts/flash_usb.py @@ -339,7 +339,8 @@ MCUTYPES = { 'sam3': flash_atsam3, 'sam4': flash_atsam4, 'samd': flash_atsamd, 'same70': flash_atsam4, 'lpc176': flash_lpc176x, 'stm32f103': flash_stm32f1, 'stm32f4': flash_stm32f4, 'stm32f042': flash_stm32f4, - 'stm32f072': flash_stm32f4, 'rp2040': flash_rp2040 + 'stm32f072': flash_stm32f4, 'stm32g0b1': flash_stm32f4, + 'stm32h7': flash_stm32f4, 'rp2040': flash_rp2040 } diff --git a/src/stm32/stm32g0.c b/src/stm32/stm32g0.c index f38fc9c57..36520dfbf 100644 --- a/src/stm32/stm32g0.c +++ b/src/stm32/stm32g0.c @@ -147,7 +147,6 @@ usb_request_bootloader(void) void armcm_main(void) { - check_usb_dfu_bootloader(); SCB->VTOR = (uint32_t)VectorTable; // Reset clock registers (in case bootloader has changed them) @@ -164,6 +163,8 @@ armcm_main(void) RCC->APBENR1 = 0x00000000; RCC->APBENR2 = 0x00000000; + check_usb_dfu_bootloader(); + // Set flash latency FLASH->ACR = (2<<FLASH_ACR_LATENCY_Pos) | FLASH_ACR_ICEN | FLASH_ACR_PRFTEN; diff --git a/src/stm32/stm32h7.c b/src/stm32/stm32h7.c index d6a32d96d..bb0fe4543 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(); |