From 58e50e7fd9062e45ec23d575a16cd411522c37cb Mon Sep 17 00:00:00 2001 From: Roger Clark Date: Sun, 3 Sep 2017 10:51:08 +1000 Subject: [PATCH] Add partial support for a DFU bootloader for the F4 --- STM32F4/boards.txt | 26 ++++++++++++++++++- STM32F4/cores/maple/libmaple/libmaple.h | 2 ++ STM32F4/platform.txt | 10 +++---- .../generic_f407v/ld/bootloader_8004000.ld | 21 +++++++++++++++ 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 STM32F4/variants/generic_f407v/ld/bootloader_8004000.ld diff --git a/STM32F4/boards.txt b/STM32F4/boards.txt index abc40f0..907e6f7 100644 --- a/STM32F4/boards.txt +++ b/STM32F4/boards.txt @@ -2,6 +2,7 @@ menu.usb_cfg=USB configuration menu.opt=Optimize +menu.upload_method=Upload method ############################################################## discovery_f407.name=STM32 Discovery F407 @@ -30,6 +31,7 @@ discovery_f407.build.density=STM32_HIGH_DENSITY discovery_f407.build.error_led_port=GPIOD discovery_f407.build.error_led_pin=14 discovery_f407.build.board=STM32DiscoveryF407 +discovery_f407.build.vect_flags=-DVECT_TAB_FLASH -DUSER_ADDR_ROM=(uint32)0x08000000 discovery_f407.menu.usb_cfg.usb_nc=USB inactive discovery_f407.menu.usb_cfg.usb_nc.build.cpu_flags=-DUSB_NC @@ -92,16 +94,37 @@ generic_f407v.build.density=STM32_HIGH_DENSITY generic_f407v.build.error_led_port=GPIOA generic_f407v.build.error_led_pin=7 generic_f407v.build.board=STM32GenericF407VET6 +generic_f407v.build.vect_flags=-DVECT_TAB_FLASH -DUSER_ADDR_ROM=(uint32)0x08000000 generic_f407v.menu.usb_cfg.usb_nc=USB inactive generic_f407v.menu.usb_cfg.usb_nc.build.cpu_flags=-DUSB_NC generic_f407v.menu.usb_cfg.usb_serial=USB serial (CDC) generic_f407v.menu.usb_cfg.usb_serial.build.cpu_flags=-DSERIAL_USB - generic_f407v.menu.usb_cfg.usb_msc=USB Mass Storage (MSC) generic_f407v.menu.usb_cfg.usb_msc.build.cpu_flags=-DUSB_MSC +#note STLink is the default from the main block of config above, so does not need settings for everything +generic_f407v.menu.upload_method.STLinkMethod=STLink +generic_f407v.menu.upload_method.STLinkMethod.upload.protocol=STLink +generic_f407v.menu.upload_method.STLinkMethod.upload.tool=stlink_upload +generic_f407v.menu.upload_method.STLinkMethod.upload.dfuse_addr=0x08004000 +generic_f407v.menu.upload_method.STLinkMethod.build.vect_flags=-DVECT_TAB_FLASH -DUSER_ADDR_ROM=(uint32)0x08000000 + + +generic_f407v.menu.upload_method.DFUUploadMethod=STM32duino bootloader +generic_f407v.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu +generic_f407v.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload +generic_f407v.menu.upload_method.DFUUploadMethod.build.vect_flags=-DVECT_TAB_FLASH -DUSER_ADDR_ROM=(uint32)0x08004000 +generic_f407v.menu.upload_method.DFUUploadMethod.build.ldscript=ld/bootloader_8004000.ld +generic_f407v.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 +generic_f407v.menu.upload_method.DFUUploadMethod.upload.altID=2 + + + + + + #-- Optimizations generic_f407v.menu.opt.osstd=Smallest (default) generic_f407v.menu.opt.osstd.build.flags.optimize=-Os @@ -158,6 +181,7 @@ stm32f4stamp.build.density=STM32_HIGH_DENSITY stm32f4stamp.build.error_led_port=GPIOD stm32f4stamp.build.error_led_pin=14 stm32f4stamp.build.board=STM32F4StampF405 +stm32f4stamp.build.vect_flags=-DVECT_TAB_FLASH -DUSER_ADDR_ROM=(uint32)0x08000000 stm32f4stamp.menu.usb_cfg.usb_nc=USB inactive stm32f4stamp.menu.usb_cfg.usb_nc.build.cpu_flags=-DUSB_NC diff --git a/STM32F4/cores/maple/libmaple/libmaple.h b/STM32F4/cores/maple/libmaple/libmaple.h index 8360ba3..2ec0b28 100644 --- a/STM32F4/cores/maple/libmaple/libmaple.h +++ b/STM32F4/cores/maple/libmaple/libmaple.h @@ -47,7 +47,9 @@ #define STACK_TOP 0x20000800 #elif defined(BOARD_freeflight) */ +#ifndef USER_ADDR_ROM #define USER_ADDR_ROM 0x08000000 +#endif #define USER_ADDR_RAM 0x20000C00 #define STACK_TOP 0x20000800 /* diff --git a/STM32F4/platform.txt b/STM32F4/platform.txt index 92dc1ea..d115210 100755 --- a/STM32F4/platform.txt +++ b/STM32F4/platform.txt @@ -10,13 +10,13 @@ version=0.1.0 # ---------------------- compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ compiler.c.cmd=arm-none-eabi-gcc -compiler.c.flags=-c -g {build.flags.optimize} -Wall -MMD -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin} +compiler.c.flags=-c -g {build.flags.optimize} -Wall -MMD -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DBOARD_{build.variant} {build.vect_flags} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin} compiler.c.elf.cmd=arm-none-eabi-g++ compiler.c.elf.flags={build.flags.optimize} -Wl,--gc-sections {build.flags.ldspecs} compiler.S.cmd=arm-none-eabi-gcc compiler.S.flags=-c -g -x assembler-with-cpp -MMD compiler.cpp.cmd=arm-none-eabi-g++ -compiler.cpp.flags=-c -g {build.flags.optimize} -Wall -MMD -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin} +compiler.cpp.flags=-c -g {build.flags.optimize} -Wall -MMD -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_{build.variant} {build.vect_flags} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin} compiler.ar.cmd=arm-none-eabi-ar compiler.ar.flags=rcs compiler.objcopy.cmd=arm-none-eabi-objcopy @@ -64,13 +64,13 @@ compiler.libs.c.flags="-I{build.system.path}/libmaple" "-I{build.core.path}/libm # --------------------- ## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.cpu_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.cpu_flags} {build.vect_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" ## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.cpu_flags} {build.hs_flag} {build.common_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.cpu_flags} {build.vect_flags} {build.hs_flag} {build.common_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" ## Compile S files -recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.cpu_flags} {build.hs_flag} {build.common_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" +recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.cpu_flags} {build.vect_flags} {build.hs_flag} {build.common_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" ## Create archives recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" diff --git a/STM32F4/variants/generic_f407v/ld/bootloader_8004000.ld b/STM32F4/variants/generic_f407v/ld/bootloader_8004000.ld new file mode 100644 index 0000000..677683e --- /dev/null +++ b/STM32F4/variants/generic_f407v/ld/bootloader_8004000.ld @@ -0,0 +1,21 @@ +/* + * STM32F4xx high density linker script for + * JTAG (bare metal, no bootloader) builds. + */ + +MEMORY +{ + ccmram (rw): ORIGIN = 0x10000000, LENGTH = 64K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K + rom (rx) : ORIGIN = 0x08004000, LENGTH = 496K +} + +/* GROUP(libcs3_stm32_high_density.a) */ + +REGION_ALIAS("REGION_TEXT", rom); +REGION_ALIAS("REGION_DATA", ram); +REGION_ALIAS("REGION_BSS", ram); +REGION_ALIAS("REGION_RODATA", rom); + +_FLASH_BUILD = 1; +INCLUDE common.inc