stm32: Add support for flashing over usb on stm32f042

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-10-26 17:11:04 -04:00
parent 2ecc8d8f62
commit 5131ec5eb0
3 changed files with 18 additions and 1 deletions

View File

@ -211,7 +211,8 @@ def flash_stm32f4(options, binfile):
MCUTYPES = { MCUTYPES = {
'atsam3': flash_atsam3, 'atsam4': flash_atsam4, 'atsamd': flash_atsamd, 'atsam3': flash_atsam3, 'atsam4': flash_atsam4, 'atsamd': flash_atsamd,
'lpc176x': flash_lpc176x, 'stm32f1': flash_stm32f1, 'stm32f4': flash_stm32f4 'lpc176x': flash_lpc176x, 'stm32f1': flash_stm32f1,
'stm32f4': flash_stm32f4, 'stm32f0': flash_stm32f4,
} }

View File

@ -49,6 +49,7 @@ $(OUT)klipper.bin: $(OUT)klipper.elf
$(Q)$(OBJCOPY) -O binary $< $@ $(Q)$(OBJCOPY) -O binary $< $@
# Flash rules # Flash rules
FLASH_TYPE-$(CONFIG_MACH_STM32F0) := stm32f0
FLASH_TYPE-$(CONFIG_MACH_STM32F1) := stm32f1 FLASH_TYPE-$(CONFIG_MACH_STM32F1) := stm32f1
FLASH_TYPE-$(CONFIG_MACH_STM32F4) := stm32f4 FLASH_TYPE-$(CONFIG_MACH_STM32F4) := stm32f4

View File

@ -6,6 +6,7 @@
#include "autoconf.h" // CONFIG_CLOCK_REF_8M #include "autoconf.h" // CONFIG_CLOCK_REF_8M
#include "board/armcm_boot.h" // armcm_main #include "board/armcm_boot.h" // armcm_main
#include "board/irq.h" // irq_disable
#include "command.h" // DECL_CONSTANT_STR #include "command.h" // DECL_CONSTANT_STR
#include "internal.h" // enable_pclock #include "internal.h" // enable_pclock
#include "sched.h" // sched_main #include "sched.h" // sched_main
@ -86,10 +87,16 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup)
regs->OSPEEDR = (regs->OSPEEDR & ~m_msk) | (0x02 << m_shift); regs->OSPEEDR = (regs->OSPEEDR & ~m_msk) | (0x02 << m_shift);
} }
#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 1024)
#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT"
// Handle USB reboot requests // Handle USB reboot requests
void void
usb_request_bootloader(void) usb_request_bootloader(void)
{ {
irq_disable();
*(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG;
NVIC_SystemReset();
} }
#if CONFIG_CLOCK_REF_8M #if CONFIG_CLOCK_REF_8M
@ -153,6 +160,14 @@ hsi48_setup(void)
void void
armcm_main(void) armcm_main(void)
{ {
if (CONFIG_USBSERIAL && CONFIG_MACH_STM32F042
&& *(uint64_t*)USB_BOOT_FLAG_ADDR == USB_BOOT_FLAG) {
*(uint64_t*)USB_BOOT_FLAG_ADDR = 0;
uint32_t *sysbase = (uint32_t*)0x1fffc400;
asm volatile("mov sp, %0\n bx %1"
: : "r"(sysbase[0]), "r"(sysbase[1]));
}
SystemInit(); SystemInit();
// Set flash latency // Set flash latency