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
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))

View File

@ -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

View File

@ -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();
}