From 6a2e51585d6be277e243265016eb499ed3354dfe Mon Sep 17 00:00:00 2001 From: rogerclarkmelbourne Date: Fri, 22 May 2015 21:07:57 +1000 Subject: [PATCH] Added DFU upload options for all generic boards. Note, Its not possible to set the correct memort size in the linker file for DFU uploads, so its always set as having the max ram and rom for the series in question. So beware using this if you are maxing out the RAM or Flash (which seems highly unlikely!) --- STM32F1/boards.txt | 119 +++++++++++------- .../generic_stm32f103c/ld/bootloader_20.ld | 30 +++++ .../wirish/boards_setup.cpp | 9 +- .../ld/stm32f103re-bootloader.ld | 4 +- .../wirish/boards_setup.cpp | 10 +- .../wirish/boards_setup.cpp | 12 +- .../generic_stm32f103z/ld/stm32f103z_dfu.ld | 29 +++++ .../wirish/boards_setup.cpp | 11 +- 8 files changed, 146 insertions(+), 78 deletions(-) create mode 100644 STM32F1/variants/generic_stm32f103c/ld/bootloader_20.ld create mode 100644 STM32F1/variants/generic_stm32f103z/ld/stm32f103z_dfu.ld diff --git a/STM32F1/boards.txt b/STM32F1/boards.txt index 43e4519..cc8ab2e 100644 --- a/STM32F1/boards.txt +++ b/STM32F1/boards.txt @@ -217,6 +217,17 @@ genericSTM32F103C.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp genericSTM32F103C.menu.upload_method.BMPMethod.upload.tool=bmp_upload genericSTM32F103C.menu.upload_method.BMPMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG +genericSTM32F103C.menu.upload_method.DFUUploadMethod=Maple DFU +genericSTM32F103C.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu +genericSTM32F103C.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload +genericSTM32F103C.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB +genericSTM32F103C.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000 +genericSTM32F103C.menu.upload_method.DFUUploadMethod.build.ldscript=ld/bootloader_20.ld +genericSTM32F103C.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 +genericSTM32F103C.menu.upload_method.DFUUploadMethod.upload.altID=2 + + + ########################### Generic STM32F103R ########################### genericSTM32F103R.name= Generic STM32F103R series @@ -247,51 +258,14 @@ genericSTM32F103R.menu.upload_method.STLinkMethod.upload.protocol=STLink genericSTM32F103R.menu.upload_method.STLinkMethod.upload.tool=stlink_upload genericSTM32F103R.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 - -########################### Generic STM32F103Z ########################### - - -genericSTM32F103Z.name=Generic STM32F103Z series -genericSTM32F103Z.build.variant=generic_stm32f103z -genericSTM32F103Z.build.vect=VECT_TAB_ADDR=0x8000000 -genericSTM32F103Z.build.core=maple -genericSTM32F103Z.build.board=GENERIC_STM32F103Z -genericSTM32F103Z.upload.use_1200bps_touch=false -genericSTM32F103Z.upload.file_type=bin -genericSTM32F103Z.upload.auto_reset=true - -genericSTM32F103Z.menu.device_variant.STM32F103ZC=STM32F103ZC -genericSTM32F103Z.menu.device_variant.STM32F103ZC.build.cpu_flags=-DMCU_STM32F103ZC -genericSTM32F103Z.menu.device_variant.STM32F103ZC.upload.maximum_size=262144 -genericSTM32F103Z.menu.device_variant.STM32F103ZC.upload.ram.maximum_size=492152 -genericSTM32F103Z.menu.device_variant.STM32F103ZC.upload.flash.maximum_size=262144 -genericSTM32F103Z.menu.device_variant.STM32F103ZC.build.ldscript=ld/stm32f103zc.ld - -genericSTM32F103Z.menu.device_variant.STM32F103ZD=STM32F103ZD -genericSTM32F103Z.menu.device_variant.STM32F103ZD.build.cpu_flags=-DMCU_STM32F103ZD -genericSTM32F103Z.menu.device_variant.STM32F103ZD.upload.maximum_size=393216 -genericSTM32F103Z.menu.device_variant.STM32F103ZD.upload.ram.maximum_size=65536 -genericSTM32F103Z.menu.device_variant.STM32F103ZD.upload.flash.maximum_size=393216 -genericSTM32F103Z.menu.device_variant.STM32F103ZD.build.ldscript=ld/stm32f103zd.ld - -genericSTM32F103Z.menu.device_variant.STM32F103ZE=STM32F103ZE -genericSTM32F103Z.menu.device_variant.STM32F103ZE.build.cpu_flags=-DMCU_STM32F103ZE -genericSTM32F103Z.menu.device_variant.STM32F103ZE.upload.maximum_size=524288 -genericSTM32F103Z.menu.device_variant.STM32F103ZE.upload.ram.maximum_size=65536 -genericSTM32F103Z.menu.device_variant.STM32F103ZE.upload.flash.maximum_size=524288 -genericSTM32F103Z.menu.device_variant.STM32F103ZE.build.ldscript=ld/stm32f103ze.ld - -#---------------------------- UPLOAD METHODS --------------------------- -genericSTM32F103Z.menu.upload_method.serialMethod=Serial -genericSTM32F103Z.menu.upload_method.serialMethod.upload.protocol=maple_serial -genericSTM32F103Z.menu.upload_method.serialMethod.upload.tool=serial_upload - -genericSTM32F103Z.menu.upload_method.STLinkMethod=STLink -genericSTM32F103Z.menu.upload_method.STLinkMethod.upload.protocol=STLink -genericSTM32F103Z.menu.upload_method.STLinkMethod.upload.tool=stlink_upload -genericSTM32F103Z.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB - - +genericSTM32F103R.menu.upload_method.DFUUploadMethod=Maple DFU +genericSTM32F103R.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu +genericSTM32F103R.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload +genericSTM32F103R.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB +genericSTM32F103R.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000 +genericSTM32F103R.menu.upload_method.DFUUploadMethod.build.ldscript=ld/stm32f103re-bootloader.ld +genericSTM32F103R.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 +genericSTM32F103R.menu.upload_method.DFUUploadMethod.upload.altID=2 ########################### Generic STM32F103V ########################### @@ -352,3 +326,58 @@ genericSTM32F103V.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x genericSTM32F103V.menu.upload_method.DFUUploadMethod.build.ldscript=ld/stm32f103veDFU.ld genericSTM32F103V.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 genericSTM32F103V.menu.upload_method.DFUUploadMethod.upload.altID=2 + + + +########################### Generic STM32F103Z ########################### + + +genericSTM32F103Z.name=Generic STM32F103Z series +genericSTM32F103Z.build.variant=generic_stm32f103z +genericSTM32F103Z.build.vect=VECT_TAB_ADDR=0x8000000 +genericSTM32F103Z.build.core=maple +genericSTM32F103Z.build.board=GENERIC_STM32F103Z +genericSTM32F103Z.upload.use_1200bps_touch=false +genericSTM32F103Z.upload.file_type=bin +genericSTM32F103Z.upload.auto_reset=true + +genericSTM32F103Z.menu.device_variant.STM32F103ZC=STM32F103ZC +genericSTM32F103Z.menu.device_variant.STM32F103ZC.build.cpu_flags=-DMCU_STM32F103ZC +genericSTM32F103Z.menu.device_variant.STM32F103ZC.upload.maximum_size=262144 +genericSTM32F103Z.menu.device_variant.STM32F103ZC.upload.ram.maximum_size=492152 +genericSTM32F103Z.menu.device_variant.STM32F103ZC.upload.flash.maximum_size=262144 +genericSTM32F103Z.menu.device_variant.STM32F103ZC.build.ldscript=ld/stm32f103zc.ld + +genericSTM32F103Z.menu.device_variant.STM32F103ZD=STM32F103ZD +genericSTM32F103Z.menu.device_variant.STM32F103ZD.build.cpu_flags=-DMCU_STM32F103ZD +genericSTM32F103Z.menu.device_variant.STM32F103ZD.upload.maximum_size=393216 +genericSTM32F103Z.menu.device_variant.STM32F103ZD.upload.ram.maximum_size=65536 +genericSTM32F103Z.menu.device_variant.STM32F103ZD.upload.flash.maximum_size=393216 +genericSTM32F103Z.menu.device_variant.STM32F103ZD.build.ldscript=ld/stm32f103zd.ld + +genericSTM32F103Z.menu.device_variant.STM32F103ZE=STM32F103ZE +genericSTM32F103Z.menu.device_variant.STM32F103ZE.build.cpu_flags=-DMCU_STM32F103ZE +genericSTM32F103Z.menu.device_variant.STM32F103ZE.upload.maximum_size=524288 +genericSTM32F103Z.menu.device_variant.STM32F103ZE.upload.ram.maximum_size=65536 +genericSTM32F103Z.menu.device_variant.STM32F103ZE.upload.flash.maximum_size=524288 +genericSTM32F103Z.menu.device_variant.STM32F103ZE.build.ldscript=ld/stm32f103ze.ld + +#---------------------------- UPLOAD METHODS --------------------------- +genericSTM32F103Z.menu.upload_method.serialMethod=Serial +genericSTM32F103Z.menu.upload_method.serialMethod.upload.protocol=maple_serial +genericSTM32F103Z.menu.upload_method.serialMethod.upload.tool=serial_upload + +genericSTM32F103Z.menu.upload_method.STLinkMethod=STLink +genericSTM32F103Z.menu.upload_method.STLinkMethod.upload.protocol=STLink +genericSTM32F103Z.menu.upload_method.STLinkMethod.upload.tool=stlink_upload +genericSTM32F103Z.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB + +genericSTM32F103Z.menu.upload_method.DFUUploadMethod=Maple DFU +genericSTM32F103Z.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu +genericSTM32F103Z.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload +genericSTM32F103Z.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB +genericSTM32F103Z.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000 +genericSTM32F103Z.menu.upload_method.DFUUploadMethod.build.ldscript=ld/stm32f103z_dfu.ld +genericSTM32F103Z.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003 +genericSTM32F103Z.menu.upload_method.DFUUploadMethod.upload.altID=2 + diff --git a/STM32F1/variants/generic_stm32f103c/ld/bootloader_20.ld b/STM32F1/variants/generic_stm32f103c/ld/bootloader_20.ld new file mode 100644 index 0000000..4de3a08 --- /dev/null +++ b/STM32F1/variants/generic_stm32f103c/ld/bootloader_20.ld @@ -0,0 +1,30 @@ +/* + * libmaple linker script for "Flash" builds. + * + * A Flash build puts .text (and .rodata) in Flash, and + * .data/.bss/heap (of course) in SRAM, but offsets the sections by + * enough space to store the Maple bootloader, which lives in low + * Flash and uses low memory. + */ + +/* + * This pulls in the appropriate MEMORY declaration from the right + * subdirectory of stm32/mem/ (the environment must call ld with the + * right include directory flags to make this happen). Boards can also + * use this file to use any of libmaple's memory-related hooks (like + * where the heap should live). + */ +MEMORY +{ + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K + rom (rx) : ORIGIN = 0x08002000, LENGTH = 120K +} + +/* Provide memory region aliases for common.inc */ +REGION_ALIAS("REGION_TEXT", rom); +REGION_ALIAS("REGION_DATA", ram); +REGION_ALIAS("REGION_BSS", ram); +REGION_ALIAS("REGION_RODATA", rom); + +/* Let common.inc handle the real work. */ +INCLUDE common.inc diff --git a/STM32F1/variants/generic_stm32f103c/wirish/boards_setup.cpp b/STM32F1/variants/generic_stm32f103c/wirish/boards_setup.cpp index aeb4df4..73c4692 100644 --- a/STM32F1/variants/generic_stm32f103c/wirish/boards_setup.cpp +++ b/STM32F1/variants/generic_stm32f103c/wirish/boards_setup.cpp @@ -75,17 +75,14 @@ namespace wirish { __weak void board_setup_usb(void) { #ifdef SERIAL_USB - //Attempt to reset the USB interface - developed by Victor PV + //Reset the USB interface on generic boards - developed by Victor PV gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_OUTPUT_PP); gpio_write_bit(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit,0); - - for(volatile unsigned int i=0;i<5000000;i++) - { - asm("nop"); - } + for(volatile unsigned int i=0;i<256;i++);// Only small delay seems to be needed, and USB pins will get configured in Serial.begin gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_INPUT_FLOATING); + Serial.begin();// Roger Clark. Changed SerialUSB to Serial for Arduino sketch compatibility #endif } diff --git a/STM32F1/variants/generic_stm32f103r/ld/stm32f103re-bootloader.ld b/STM32F1/variants/generic_stm32f103r/ld/stm32f103re-bootloader.ld index fb1af71..5a58c24 100644 --- a/STM32F1/variants/generic_stm32f103r/ld/stm32f103re-bootloader.ld +++ b/STM32F1/variants/generic_stm32f103r/ld/stm32f103re-bootloader.ld @@ -21,8 +21,8 @@ */ MEMORY { -ram (rwx) : ORIGIN = 0x20000C00, LENGTH = 61K -rom (rx) : ORIGIN = 0x08005000, LENGTH = 492K +ram (rwx) : ORIGIN = 0x20000000, LENGTH = 61K +rom (rx) : ORIGIN = 0x08002000, LENGTH = 504K } diff --git a/STM32F1/variants/generic_stm32f103r/wirish/boards_setup.cpp b/STM32F1/variants/generic_stm32f103r/wirish/boards_setup.cpp index c7322b9..4e58258 100644 --- a/STM32F1/variants/generic_stm32f103r/wirish/boards_setup.cpp +++ b/STM32F1/variants/generic_stm32f103r/wirish/boards_setup.cpp @@ -75,17 +75,13 @@ namespace wirish { __weak void board_setup_usb(void) { #ifdef SERIAL_USB - //Attempt to reset the USB interface - developed by Victor PV + //Reset the USB interface on generic boards - developed by Victor PV gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_OUTPUT_PP); gpio_write_bit(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit,0); - - - for(volatile unsigned int i=0;i<5000000;i++) - { - asm("nop"); - } + for(volatile unsigned int i=0;i<256;i++);// Only small delay seems to be needed, and USB pins will get configured in Serial.begin gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_INPUT_FLOATING); + Serial.begin();// Roger Clark. Changed SerialUSB to Serial for Arduino sketch compatibility #endif } diff --git a/STM32F1/variants/generic_stm32f103v/wirish/boards_setup.cpp b/STM32F1/variants/generic_stm32f103v/wirish/boards_setup.cpp index 6765e4d..43009c5 100644 --- a/STM32F1/variants/generic_stm32f103v/wirish/boards_setup.cpp +++ b/STM32F1/variants/generic_stm32f103v/wirish/boards_setup.cpp @@ -77,19 +77,11 @@ namespace wirish { #ifdef SERIAL_USB - //Attempt to reset the USB interface - developed by Victor PV - + //Reset the USB interface on generic boards - developed by Victor PV gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_OUTPUT_PP); gpio_write_bit(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit,0); - - - for(volatile unsigned int i=0;i<5000000;i++) - { - asm("nop"); - } + for(volatile unsigned int i=0;i<256;i++);// Only small delay seems to be needed, and USB pins will get configured in Serial.begin gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_INPUT_FLOATING); - - Serial.begin();// Roger Clark. Changed SerialUSB to Serial for Arduino sketch compatibility #endif diff --git a/STM32F1/variants/generic_stm32f103z/ld/stm32f103z_dfu.ld b/STM32F1/variants/generic_stm32f103z/ld/stm32f103z_dfu.ld new file mode 100644 index 0000000..5cdf24e --- /dev/null +++ b/STM32F1/variants/generic_stm32f103z/ld/stm32f103z_dfu.ld @@ -0,0 +1,29 @@ +/* + * libmaple linker script + * + * This build puts .text (and .rodata) in Flash, and + * .data/.bss/heap (of course) in SRAM, but links starting at the + * Flash and SRAM starting addresses (0x08000000 and 0x20000000 + * respectively). This will wipe out a Maple bootloader if there's one + * on the board, so only use this if you know what you're doing. + * + * This build is perfectly usable for upload over SWD, + * the system memory bootloader, etc. The name is just a historical + * artifact. + */ + + +MEMORY +{ + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K + rom (rx) : ORIGIN = 0x08002000, LENGTH = 504K +} + +/* Provide memory region aliases for common.inc */ +REGION_ALIAS("REGION_TEXT", rom); +REGION_ALIAS("REGION_DATA", ram); +REGION_ALIAS("REGION_BSS", ram); +REGION_ALIAS("REGION_RODATA", rom); + +/* Let common.inc handle the real work. */ +INCLUDE common.inc diff --git a/STM32F1/variants/generic_stm32f103z/wirish/boards_setup.cpp b/STM32F1/variants/generic_stm32f103z/wirish/boards_setup.cpp index 1552f1b..6d546cf 100644 --- a/STM32F1/variants/generic_stm32f103z/wirish/boards_setup.cpp +++ b/STM32F1/variants/generic_stm32f103z/wirish/boards_setup.cpp @@ -78,17 +78,12 @@ namespace wirish { #ifdef SERIAL_USB - //Attempt to reset the USB interface - developed by Victor PV - + //Reset the USB interface on generic boards - developed by Victor PV gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_OUTPUT_PP); gpio_write_bit(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit,0); - - - for(volatile unsigned int i=0;i<5000000;i++) - { - asm("nop"); - } + for(volatile unsigned int i=0;i<256;i++);// Only small delay seems to be needed, and USB pins will get configured in Serial.begin gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_INPUT_FLOATING); + Serial.begin();// Roger Clark. Changed SerialUSB to Serial for Arduino sketch compatibility #endif }