mirror of https://github.com/Desuuuu/klipper.git
stm32f1: Add support for HID Bootloader
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
4b9b705b99
commit
05efccc874
|
@ -113,6 +113,25 @@ def flash_dfuutil(device, binfile, extra_flags=[], sudo=True):
|
||||||
pathname = wait_path(devpath)
|
pathname = wait_path(devpath)
|
||||||
call_dfuutil(["-p", buspath] + extra_flags, binfile, sudo)
|
call_dfuutil(["-p", buspath] + extra_flags, binfile, sudo)
|
||||||
|
|
||||||
|
def call_hidflash(binfile, sudo):
|
||||||
|
args = ["lib/hidflash/hid-flash", binfile]
|
||||||
|
if sudo:
|
||||||
|
args.insert(0, "sudo")
|
||||||
|
sys.stderr.write(" ".join(args) + '\n\n')
|
||||||
|
res = subprocess.call(args)
|
||||||
|
if res != 0:
|
||||||
|
raise error("Error running hid-flash")
|
||||||
|
|
||||||
|
# Flash via call to hid-flash
|
||||||
|
def flash_hidflash(device, binfile, sudo=True):
|
||||||
|
hexfmt_r = re.compile(r"^[a-fA-F0-9]{4}:[a-fA-F0-9]{4}$")
|
||||||
|
if hexfmt_r.match(device.strip()):
|
||||||
|
call_hidflash(binfile, sudo)
|
||||||
|
return
|
||||||
|
buspath, devpath = translate_serial_to_usb_path(device)
|
||||||
|
enter_bootloader(device)
|
||||||
|
pathname = wait_path(devpath)
|
||||||
|
call_hidflash(binfile, sudo)
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# Device specific helpers
|
# Device specific helpers
|
||||||
|
@ -174,6 +193,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=1eaf:0003
|
make flash FLASH_DEVICE=1eaf:0003
|
||||||
|
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
|
||||||
|
@ -182,7 +203,11 @@ If attempting to flash via 3.3V serial, then use:
|
||||||
|
|
||||||
def flash_stm32f1(options, binfile):
|
def flash_stm32f1(options, binfile):
|
||||||
try:
|
try:
|
||||||
flash_dfuutil(options.device, binfile, ["-R", "-a", "2"], options.sudo)
|
if options.start == 0x8000800:
|
||||||
|
flash_hidflash(options.device, binfile, options.sudo)
|
||||||
|
else:
|
||||||
|
flash_dfuutil(options.device, binfile, ["-R", "-a", "2"],
|
||||||
|
options.sudo)
|
||||||
except error as e:
|
except error as e:
|
||||||
sys.stderr.write(STM32F1_HELP % (
|
sys.stderr.write(STM32F1_HELP % (
|
||||||
options.device, str(e), options.device))
|
options.device, str(e), options.device))
|
||||||
|
|
|
@ -94,6 +94,8 @@ config STACK_SIZE
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "Bootloader offset" if MACH_STM32F407 || MACH_STM32F103 || MACH_STM32F070
|
prompt "Bootloader offset" if MACH_STM32F407 || MACH_STM32F103 || MACH_STM32F070
|
||||||
|
config STM32_FLASH_START_800
|
||||||
|
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_7000
|
config STM32_FLASH_START_7000
|
||||||
|
@ -107,6 +109,7 @@ choice
|
||||||
endchoice
|
endchoice
|
||||||
config FLASH_START
|
config FLASH_START
|
||||||
hex
|
hex
|
||||||
|
default 0x8000800 if STM32_FLASH_START_800
|
||||||
default 0x8002000 if STM32_FLASH_START_2000
|
default 0x8002000 if STM32_FLASH_START_2000
|
||||||
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
|
||||||
|
|
|
@ -52,7 +52,11 @@ $(OUT)klipper.bin: $(OUT)klipper.elf
|
||||||
$(Q)$(OBJCOPY) -O binary $< $@
|
$(Q)$(OBJCOPY) -O binary $< $@
|
||||||
|
|
||||||
# Flash rules
|
# Flash rules
|
||||||
flash: $(OUT)klipper.bin
|
lib/hidflash/hid-flash:
|
||||||
|
@echo " Building hid-flash"
|
||||||
|
$(Q)make -C lib/hidflash
|
||||||
|
|
||||||
|
flash: $(OUT)klipper.bin lib/hidflash/hid-flash
|
||||||
@echo " Flashing $< to $(FLASH_DEVICE)"
|
@echo " Flashing $< to $(FLASH_DEVICE)"
|
||||||
$(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" -s "$(CONFIG_FLASH_START)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin
|
$(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" -s "$(CONFIG_FLASH_START)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin
|
||||||
|
|
||||||
|
|
|
@ -112,13 +112,18 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup)
|
||||||
void
|
void
|
||||||
usb_request_bootloader(void)
|
usb_request_bootloader(void)
|
||||||
{
|
{
|
||||||
if (!CONFIG_STM32_FLASH_START_2000)
|
if (!(CONFIG_STM32_FLASH_START_2000 || CONFIG_STM32_FLASH_START_800))
|
||||||
return;
|
return;
|
||||||
// Enter "stm32duino" bootloader
|
// Enter "stm32duino" or HID bootloader
|
||||||
irq_disable();
|
irq_disable();
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
|
RCC->APB1ENR |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
|
||||||
PWR->CR |= PWR_CR_DBP;
|
PWR->CR |= PWR_CR_DBP;
|
||||||
BKP->DR10 = 0x01;
|
if (CONFIG_STM32_FLASH_START_800)
|
||||||
|
// HID Bootloader magic key
|
||||||
|
BKP->DR4 = 0x424C;
|
||||||
|
else
|
||||||
|
// stm32duino bootloader magic key
|
||||||
|
BKP->DR10 = 0x01;
|
||||||
PWR->CR &=~ PWR_CR_DBP;
|
PWR->CR &=~ PWR_CR_DBP;
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue