Skip to content

Commit 607fcb4

Browse files
BennehBoyfpistm
authored andcommitted
STM32 HID bootloader 2.1 support
https://github.com/Serasidis/STM32_HID_Bootloader Signed-off-by: BennehBoy <[email protected]>
1 parent 0410805 commit 607fcb4

File tree

7 files changed

+50
-16
lines changed

7 files changed

+50
-16
lines changed

boards.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,12 @@ GenF1.menu.upload_method.bmpMethod=BMP (Black Magic Probe)
669669
GenF1.menu.upload_method.bmpMethod.upload.protocol=gdb_bmp
670670
GenF1.menu.upload_method.bmpMethod.upload.tool=bmp_upload
671671

672+
GenF1.menu.upload_method.hidMethod=HID Bootloader 2.1 (0x0800)
673+
GenF1.menu.upload_method.hidMethod.upload.protocol=hid21
674+
GenF1.menu.upload_method.hidMethod.upload.tool=hid_upload
675+
GenF1.menu.upload_method.hidMethod.upload.bl_size=0x800
676+
GenF1.menu.upload_method.hidMethod.build.bootloader_flags=-DBOOTLOADER_DTR_TOGGLING -DHIDBL_F1 -DVECT_TAB_OFFSET={upload.bl_size}
677+
672678
GenF1.menu.upload_method.dfu2Method=Maple DFU Bootloader 2.0 (0x2000)
673679
GenF1.menu.upload_method.dfu2Method.upload.protocol=maple
674680
GenF1.menu.upload_method.dfu2Method.upload.tool=maple_upload
@@ -693,7 +699,7 @@ GenF4.name=Generic STM32F4 series
693699
GenF4.build.vid=0x0483
694700
GenF4.build.core=arduino
695701
GenF4.build.board=GenF4
696-
GenF4.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial}
702+
GenF4.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} {build.bootloader_flags}
697703
GenF4.build.mcu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
698704
GenF4.build.series=STM32F4xx
699705
GenF4.build.cmsis_lib_gcc=arm_cortexM4l_math
@@ -774,6 +780,12 @@ GenF4.menu.upload_method.bmpMethod=BMP (Black Magic Probe)
774780
GenF4.menu.upload_method.bmpMethod.upload.protocol=gdb_bmp
775781
GenF4.menu.upload_method.bmpMethod.upload.tool=bmp_upload
776782

783+
GenF4.menu.upload_method.hidMethod=HID Bootloader 2.1 (0x4000)
784+
GenF4.menu.upload_method.hidMethod.upload.protocol=hid21
785+
GenF4.menu.upload_method.hidMethod.upload.tool=hid_upload
786+
GenF4.menu.upload_method.hidMethod.upload.bl_size=0x4000
787+
GenF4.menu.upload_method.hidMethod.build.bootloader_flags=-DBOOTLOADER_DTR_TOGGLING -DHIDBL_F4 -DVECT_TAB_OFFSET={upload.bl_size}
788+
777789
###############################
778790
# Sparky Flight Controllers
779791

cores/arduino/stm32/usb/cdc/usbd_cdc_if.c

+14
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
229229
*/
230230
if (dtr_toggling > 3) {
231231
if ((Buf[0] == '1') && (Buf[1] == 'E') && (Buf[2] == 'A') && (Buf[3] == 'F')) {
232+
#if defined (HIDBL_F1)
233+
RTC_HandleTypeDef hrtc;
234+
__HAL_RCC_PWR_CLK_ENABLE();
235+
__HAL_RCC_BKP_CLK_ENABLE();
236+
HAL_PWR_EnableBkUpAccess();
237+
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR10, 0x424C); //Write the magic number 0x424C
238+
239+
#elif defined (HIDBL_F4)
240+
__HAL_RCC_PWR_CLK_ENABLE();
241+
HAL_PWR_EnableBkUpAccess();
242+
__BKPSRAM_CLK_ENABLE();
243+
*(__IO uint32_t *)(BKPSRAM_BASE) = 0x424C; //Write the magic number 0x424C at Backup SRAM address 0x40024000
244+
245+
#endif
232246
HAL_NVIC_SystemReset();
233247
}
234248
dtr_toggling = 0;

platform.txt

+10
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ tools.bmp_upload.upload.params.verbose=-batch
169169
tools.bmp_upload.upload.params.quiet=--batch-silent
170170
tools.bmp_upload.upload.pattern="{path}{cmd}" -nx -b {upload.speed} {upload.verbose} -ex "set confirm off" -ex "target extended-remote {serial.port}" -ex "monitor swdp_scan" -ex "attach 1" -ex "load" -ex "compare-sections" -ex "kill" "{build.path}/{build.project_name}.elf"
171171

172+
# HID flash 2.1 (HID bootloader v2.1 for STM32F1 and STM32F4 series)
173+
tools.hid_upload.cmd=hid-flash
174+
tools.hid_upload.cmd.windows=hid-flash.exe
175+
tools.hid_upload.path={runtime.hardware.path}/tools/win
176+
tools.hid_upload.path.macosx={runtime.hardware.path}/tools/macosx
177+
tools.hid_upload.path.linux={runtime.hardware.path}/tools/linux
178+
tools.hid_upload.upload.params.verbose=-d
179+
tools.hid_upload.upload.params.quiet=n
180+
tools.hid_upload.upload.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.bin" {serial.port.file}
181+
172182
# Upload using Maple bootloader over DFU
173183
tools.maple_upload.cmd=maple_upload
174184
tools.maple_upload.cmd.windows=maple_upload.bat

variants/BLACK_F407XX/ldscript.ld

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
ENTRY(Reset_Handler)
5353

5454
/* Highest address of the user mode stack */
55-
_estack = 0x20020000; /* end of RAM */
55+
_estack = 0x20000000 + LD_MAX_DATA_SIZE; /* end of RAM */
5656
/* Generate a link error if heap and stack don't fit into RAM */
5757
_Min_Heap_Size = 0x200; /* required amount of heap */
5858
_Min_Stack_Size = 0x400; /* required amount of stack */
5959

6060
/* Specify the memory areas */
6161
MEMORY
6262
{
63-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
63+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
6464
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
65-
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = LD_MAX_SIZE
65+
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
6666
}
6767

6868
/* Define output sections */

variants/BLUE_F407VE_Mini/ldscript.ld

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
ENTRY(Reset_Handler)
5353

5454
/* Highest address of the user mode stack */
55-
_estack = 0x20020000; /* end of RAM */
55+
_estack = 0x20000000 + LD_MAX_DATA_SIZE; /* end of RAM */
5656
/* Generate a link error if heap and stack don't fit into RAM */
5757
_Min_Heap_Size = 0x200; /* required amount of heap */
5858
_Min_Stack_Size = 0x400; /* required amount of stack */
5959

6060
/* Specify the memory areas */
6161
MEMORY
6262
{
63-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
63+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
6464
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
65-
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
65+
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
6666
}
6767

6868
/* Define output sections */

variants/DIYMROE_F407VGT/ldscript.ld

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
ENTRY(Reset_Handler)
5353

5454
/* Highest address of the user mode stack */
55-
_estack = 0x20020000; /* end of RAM */
55+
_estack = 0x20000000 + LD_MAX_DATA_SIZE; /* end of RAM */
5656
/* Generate a link error if heap and stack don't fit into RAM */
5757
_Min_Heap_Size = 0x200; /* required amount of heap */
5858
_Min_Stack_Size = 0x400; /* required amount of stack */
5959

6060
/* Specify the memory areas */
6161
MEMORY
6262
{
63-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
63+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
6464
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
65-
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
65+
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
6666
}
6767

6868
/* Define output sections */

variants/FK407M1/ldscript.ld

+4-6
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
ENTRY(Reset_Handler)
5353

5454
/* Highest address of the user mode stack */
55-
_estack = 0x20020000; /* end of RAM */
55+
_estack = 0x20000000 + LD_MAX_DATA_SIZE; /* end of RAM */
5656
/* Generate a link error if heap and stack don't fit into RAM */
5757
_Min_Heap_Size = 0x200; /* required amount of heap */
5858
_Min_Stack_Size = 0x400; /* required amount of stack */
5959

6060
/* Specify the memory areas */
6161
MEMORY
6262
{
63-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
63+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
6464
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
65-
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
65+
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
6666
}
6767

6868
/* Define output sections */
@@ -203,6 +203,4 @@ SECTIONS
203203
}
204204

205205
.ARM.attributes 0 : { *(.ARM.attributes) }
206-
}
207-
208-
206+
}

0 commit comments

Comments
 (0)