stm32f4: Add support for HID bootloader

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-04-25 14:20:25 -04:00 committed by KevinOConnor
parent 380ba2a618
commit ab87af90a3
3 changed files with 23 additions and 4 deletions

View File

@ -219,6 +219,8 @@ Failed to flash to %s: %s
If the device is already in bootloader mode it can be flashed with the If the device is already in bootloader mode it can be flashed with the
following command: following command:
make flash FLASH_DEVICE=0483:df11 make flash FLASH_DEVICE=0483:df11
OR
make flash FLASH_DEVICE=1209:beba
If attempting to flash via 3.3V serial, then use: If attempting to flash via 3.3V serial, then use:
make serialflash FLASH_DEVICE=%s make serialflash FLASH_DEVICE=%s
@ -228,6 +230,9 @@ If attempting to flash via 3.3V serial, then use:
def flash_stm32f4(options, binfile): def flash_stm32f4(options, binfile):
start = "0x%x:leave" % (options.start,) start = "0x%x:leave" % (options.start,)
try: try:
if options.start == 0x8004000:
flash_hidflash(options.device, binfile, options.sudo)
else:
flash_dfuutil(options.device, binfile, flash_dfuutil(options.device, binfile,
["-R", "-a", "0", "-s", start], options.sudo) ["-R", "-a", "0", "-s", start], options.sudo)
except error as e: except error as e:

View File

@ -93,11 +93,13 @@ config STACK_SIZE
default 512 default 512
choice 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 config STM32_FLASH_START_800
bool "2KiB bootloader (HID Bootloader)" if MACH_STM32F103 bool "2KiB bootloader (HID Bootloader)" if MACH_STM32F103
config STM32_FLASH_START_2000 config STM32_FLASH_START_2000
bool "8KiB bootloader (stm32duino)" if MACH_STM32F103 || MACH_STM32F070 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 config STM32_FLASH_START_7000
bool "28KiB bootloader" if MACH_STM32F103 bool "28KiB bootloader" if MACH_STM32F103
config STM32_FLASH_START_8000 config STM32_FLASH_START_8000
@ -111,6 +113,7 @@ config FLASH_START
hex hex
default 0x8000800 if STM32_FLASH_START_800 default 0x8000800 if STM32_FLASH_START_800
default 0x8002000 if STM32_FLASH_START_2000 default 0x8002000 if STM32_FLASH_START_2000
default 0x8004000 if STM32_FLASH_START_4000
default 0x8007000 if STM32_FLASH_START_7000 default 0x8007000 if STM32_FLASH_START_7000
default 0x8008000 if STM32_FLASH_START_8000 default 0x8008000 if STM32_FLASH_START_8000
default 0x8010000 if STM32_FLASH_START_10000 default 0x8010000 if STM32_FLASH_START_10000

View File

@ -98,7 +98,18 @@ void
usb_request_bootloader(void) usb_request_bootloader(void)
{ {
irq_disable(); irq_disable();
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; *(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG;
}
NVIC_SystemReset(); NVIC_SystemReset();
} }