Skip to content

Commit

Permalink
stm32f4: Add support for USB on stm32f103
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Aug 5, 2019
1 parent 7efc53f commit ec3d865
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scripts/flash_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,21 @@ def flash_stm32f1(options, binfile):
options.device, str(e), options.device))
sys.exit(-1)

STM32F4_HELP = """
USB flash is not supported on the STM32F4!
If attempting to flash via 3.3V serial, then use:
make serialflash FLASH_DEVICE=%s
"""

def flash_stm32f4(options, binfile):
sys.stderr.write(STM32F4_HELP % (options.device,))
sys.exit(-1)

MCUTYPES = {
'atsam3': flash_atsam3, 'atsam4': flash_atsam4, 'atsamd': flash_atsamd,
'lpc176x': flash_lpc176x, 'stm32f1': flash_stm32f1
'lpc176x': flash_lpc176x, 'stm32f1': flash_stm32f1, 'stm32f4': flash_stm32f4
}


Expand Down
23 changes: 23 additions & 0 deletions src/stm32f4/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ choice
config MACH_STM32F103
bool "STM32F103"
select MACH_STM32F1xx
select HAVE_STM32_USBFS
config MACH_STM32F405
bool "STM32F405"
select MACH_STM32F4xx
Expand All @@ -34,6 +35,8 @@ config MACH_STM32F1xx
bool
config MACH_STM32F4xx
bool
config HAVE_STM32_USBFS
bool

config MCU
string
Expand Down Expand Up @@ -64,6 +67,21 @@ config STACK_SIZE
int
default 512

choice
prompt "Bootloader offset" if MACH_STM32F103
config STM32_FLASH_START_2000
bool "8KiB bootloader (stm32duino)"
config STM32_FLASH_START_7000
bool "28KiB bootloader"
config STM32_FLASH_START_0000
bool "No bootloader"
endchoice
config FLASH_START
hex
default 0x2000 if STM32_FLASH_START_2000
default 0x7000 if STM32_FLASH_START_7000
default 0x0000

choice
prompt "Clock Reference" if LOW_LEVEL_OPTIONS
config STM32_CLOCK_REF_8M
Expand All @@ -76,7 +94,12 @@ config CLOCK_REF_8M
default n if STM32_CLOCK_REF_INTERNAL
default y

config USBSERIAL
bool "Use USB for communication (instead of serial)"
depends on HAVE_STM32_USBFS
default y
config SERIAL
depends on !USBSERIAL
bool
default y
choice
Expand Down
8 changes: 8 additions & 0 deletions src/stm32f4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ src-$(CONFIG_MACH_STM32F4xx) += ../lib/stm32f4/system_stm32f4xx.c
src-$(CONFIG_MACH_STM32F4xx) += stm32f4/clock.c
src-$(CONFIG_HAVE_GPIO_ADC) += stm32f4/adc.c
src-$(CONFIG_HAVE_GPIO_SPI) += stm32f4/spi.c
src-$(CONFIG_USBSERIAL) += stm32f4/usbfs.c generic/usb_cdc.c
src-$(CONFIG_SERIAL) += stm32f4/serial.c generic/serial_irq.c

# Add assembler build rules
Expand All @@ -50,6 +51,13 @@ $(OUT)klipper.bin: $(OUT)klipper.elf
@echo " Creating hex file $@"
$(Q)$(OBJCOPY) -O binary $< $@

FLASH_TYPE-$(CONFIG_MACH_STM32F1xx) := stm32f1
FLASH_TYPE-$(CONFIG_MACH_STM32F4xx) := stm32f4

flash: $(OUT)klipper.bin
@echo " Flashing $< to $(FLASH_DEVICE)"
$(Q)$(PYTHON) ./scripts/flash_usb.py -t $(FLASH_TYPE-y) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin

serialflash: $(OUT)klipper.bin
@echo " Flashing $< to $(FLASH_DEVICE) via stm32flash"
$(Q)stm32flash -w $< -v -g 0 $(FLASH_DEVICE)
2 changes: 2 additions & 0 deletions src/stm32f4/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ DECL_COMMAND_FLAGS(command_reset, HF_IN_SHUTDOWN, "reset");
int
main(void)
{
SCB->VTOR += CONFIG_FLASH_START;

clock_setup();

sched_main();
Expand Down
Loading

0 comments on commit ec3d865

Please sign in to comment.