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>
This commit is contained in:
Kevin O'Connor 2019-03-08 21:29:51 -05:00
parent 6a16e1f4c5
commit 9466c2d66c
3 changed files with 17 additions and 2 deletions

View File

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

View File

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

View File

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