diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py index 7a02da45..550051f3 100755 --- a/scripts/flash_usb.py +++ b/scripts/flash_usb.py @@ -219,6 +219,8 @@ Failed to flash to %s: %s If the device is already in bootloader mode it can be flashed with the following command: make flash FLASH_DEVICE=0483:df11 + OR + make flash FLASH_DEVICE=1209:beba If attempting to flash via 3.3V serial, then use: make serialflash FLASH_DEVICE=%s @@ -228,8 +230,11 @@ If attempting to flash via 3.3V serial, then use: def flash_stm32f4(options, binfile): start = "0x%x:leave" % (options.start,) try: - flash_dfuutil(options.device, binfile, - ["-R", "-a", "0", "-s", start], options.sudo) + if options.start == 0x8004000: + flash_hidflash(options.device, binfile, options.sudo) + else: + flash_dfuutil(options.device, binfile, + ["-R", "-a", "0", "-s", start], options.sudo) except error as e: sys.stderr.write(STM32F4_HELP % ( options.device, str(e), options.device)) diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index 3651aa2f..53853ace 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -93,11 +93,13 @@ config STACK_SIZE default 512 choice - prompt "Bootloader offset" if MACH_STM32F407 || MACH_STM32F103 || MACH_STM32F070 + prompt "Bootloader offset" if MACH_STM32F407 || MACH_STM32F405 || MACH_STM32F103 || MACH_STM32F070 config STM32_FLASH_START_800 bool "2KiB bootloader (HID Bootloader)" if MACH_STM32F103 config STM32_FLASH_START_2000 bool "8KiB bootloader (stm32duino)" if MACH_STM32F103 || MACH_STM32F070 + config STM32_FLASH_START_4000 + bool "16KiB bootloader (HID Bootloader)" if MACH_STM32F405 || MACH_STM32F407 config STM32_FLASH_START_7000 bool "28KiB bootloader" if MACH_STM32F103 config STM32_FLASH_START_8000 @@ -111,6 +113,7 @@ config FLASH_START hex default 0x8000800 if STM32_FLASH_START_800 default 0x8002000 if STM32_FLASH_START_2000 + default 0x8004000 if STM32_FLASH_START_4000 default 0x8007000 if STM32_FLASH_START_7000 default 0x8008000 if STM32_FLASH_START_8000 default 0x8010000 if STM32_FLASH_START_10000 diff --git a/src/stm32/stm32f4.c b/src/stm32/stm32f4.c index f8b5ab2d..9b5433af 100644 --- a/src/stm32/stm32f4.c +++ b/src/stm32/stm32f4.c @@ -98,7 +98,18 @@ void usb_request_bootloader(void) { irq_disable(); - *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; + if (CONFIG_STM32_FLASH_START_4000) { + // HID Bootloader + RCC->APB1ENR |= RCC_APB1ENR_PWREN; + RCC->APB1ENR; + PWR->CR |= PWR_CR_DBP; + // HID Bootloader magic key + RTC->BKP4R = 0x424C; + PWR->CR &= ~PWR_CR_DBP; + } else { + // System DFU Bootloader + *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG; + } NVIC_SystemReset(); }