diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-03-08 21:29:51 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-03-08 22:22:41 -0500 |
commit | 9466c2d66cce7290bb73edcd7123d0b3a04a9021 (patch) | |
tree | c708c1d382b438d9e6d43528b01da8598adc6578 | |
parent | 6a16e1f4c5f7c4ea4307cdca9e500d21fa842e99 (diff) | |
download | kutter-9466c2d66cce7290bb73edcd7123d0b3a04a9021.tar.gz kutter-9466c2d66cce7290bb73edcd7123d0b3a04a9021.tar.xz kutter-9466c2d66cce7290bb73edcd7123d0b3a04a9021.zip |
stm32f1: Add support for entering the bootloader via USB
Add support for entering the "stm32duino" bootloader via the arduino
1200 baud USB request. Add supprot for flashing over USB via the
"make flash" command.
Rename the existing "make flash" command to "make serialflash".
Default to using a bootloader in Kconfig.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | src/stm32f1/Kconfig | 4 | ||||
-rw-r--r-- | src/stm32f1/Makefile | 4 | ||||
-rw-r--r-- | src/stm32f1/usbserial.c | 11 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/stm32f1/Kconfig b/src/stm32f1/Kconfig index 78fb1bfd..49cd6919 100644 --- a/src/stm32f1/Kconfig +++ b/src/stm32f1/Kconfig @@ -20,10 +20,10 @@ config CLOCK_FREQ choice prompt "Bootloader offset" - config STM_FLASH_START_0000 - bool "No bootloader" config STM_FLASH_START_2000 bool "8KiB bootloader (stm32duino)" + config STM_FLASH_START_0000 + bool "No bootloader" endchoice config FLASH_START diff --git a/src/stm32f1/Makefile b/src/stm32f1/Makefile index 8d813d4d..28662a01 100644 --- a/src/stm32f1/Makefile +++ b/src/stm32f1/Makefile @@ -47,5 +47,9 @@ $(OUT)klipper.bin: $(OUT)klipper.elf $(Q)$(OBJCOPY) -O binary $< $@ flash: $(OUT)klipper.bin + @echo " Flashing $< to $(FLASH_DEVICE)" + $(Q)$(PYTHON) ./scripts/flash_usb.py -t stm32f1 -d "$(FLASH_DEVICE)" $(OUT)klipper.bin + +serialflash: $(OUT)klipper.bin @echo " Flashing $< to $(FLASH_DEVICE) via stm32flash" $(Q)stm32flash -w $< -v -g 0 $(FLASH_DEVICE) diff --git a/src/stm32f1/usbserial.c b/src/stm32f1/usbserial.c index 641aacc0..7eeb3421 100644 --- a/src/stm32f1/usbserial.c +++ b/src/stm32f1/usbserial.c @@ -5,8 +5,10 @@ // This file may be distributed under the terms of the GNU GPLv3 license. #include <string.h> // NULL +#include "autoconf.h" // CONFIG_STM_FLASH_START_2000 #include "board/gpio.h" // gpio_out_setup #include "board/io.h" // writeb +#include "board/irq.h" // irq_disable #include "board/usb_cdc.h" // usb_notify_ep0 #include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN #include "internal.h" // GPIO @@ -214,6 +216,15 @@ usb_set_configure(void) void usb_request_bootloader(void) { + if (!CONFIG_STM_FLASH_START_2000) + return; + // Enter "stm32duino" bootloader + irq_disable(); + RCC->APB1ENR |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN; + PWR->CR |= PWR_CR_DBP; + BKP->DR10 = 0x01; + PWR->CR &=~ PWR_CR_DBP; + NVIC_SystemReset(); } |