Skip to content

HID Bootloader v2.2 support #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ GenF1.menu.upload_method.bmpMethod=BMP (Black Magic Probe)
GenF1.menu.upload_method.bmpMethod.upload.protocol=gdb_bmp
GenF1.menu.upload_method.bmpMethod.upload.tool=bmp_upload

GenF1.menu.upload_method.hidMethod=HID Bootloader 2.2
GenF1.menu.upload_method.hidMethod.upload.protocol=hid22
GenF1.menu.upload_method.hidMethod.upload.tool=hid_upload
GenF1.menu.upload_method.hidMethod.build.flash_offset=0x800
GenF1.menu.upload_method.hidMethod.build.bootloader_flags=-DBL_HID -DVECT_TAB_OFFSET={build.flash_offset}

GenF1.menu.upload_method.dfu2Method=Maple DFU Bootloader 2.0
GenF1.menu.upload_method.dfu2Method.upload.protocol=maple
GenF1.menu.upload_method.dfu2Method.upload.tool=maple_upload
Expand All @@ -704,7 +710,7 @@ GenF4.name=Generic STM32F4 series
GenF4.build.vid=0x0483
GenF4.build.core=arduino
GenF4.build.board=GenF4
GenF4.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial}
GenF4.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} {build.bootloader_flags}
GenF4.build.mcu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
GenF4.build.series=STM32F4xx
GenF4.build.cmsis_lib_gcc=arm_cortexM4l_math
Expand Down Expand Up @@ -785,6 +791,12 @@ GenF4.menu.upload_method.bmpMethod=BMP (Black Magic Probe)
GenF4.menu.upload_method.bmpMethod.upload.protocol=gdb_bmp
GenF4.menu.upload_method.bmpMethod.upload.tool=bmp_upload

GenF4.menu.upload_method.hidMethod=HID Bootloader 2.2
GenF4.menu.upload_method.hidMethod.upload.protocol=hid22
GenF4.menu.upload_method.hidMethod.upload.tool=hid_upload
GenF4.menu.upload_method.hidMethod.build.flash_offset=0x4000
GenF4.menu.upload_method.hidMethod.build.bootloader_flags=-DBL_HID -DVECT_TAB_OFFSET={build.flash_offset}

###############################
# Sparky Flight Controllers

Expand Down
11 changes: 11 additions & 0 deletions cores/arduino/stm32/backup.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ extern "C" {
#define RTC_BKP_VALUE 0x32F2
#endif

#if defined (BL_HID)
#if !defined(HID_MAGIC_NUMBER_BKP_INDEX)
#define HID_MAGIC_NUMBER_BKP_INDEX LL_RTC_BKP_DR4
#endif /* HID_MAGIC_NUMBER_BKP_INDEX */
#if !defined(HID_OLD_MAGIC_NUMBER_BKP_INDEX) && defined(LL_RTC_BKP_DR10)
#define HID_OLD_MAGIC_NUMBER_BKP_INDEX LL_RTC_BKP_DR10
#endif /* HID_OLD_MAGIC_NUMBER_BKP_INDEX */
#ifndef HID_MAGIC_NUMBER_BKP_VALUE
#define HID_MAGIC_NUMBER_BKP_VALUE 0x424C
#endif /* HID_MAGIC_NUMBER_BKP_VALUE */
#endif /* BL_HID */

/* Exported functions ------------------------------------------------------- */
static inline void resetBackupDomain(void)
Expand Down
22 changes: 22 additions & 0 deletions cores/arduino/stm32/bootloader.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "bootloader.h"

#include "stm32_def.h"
#include "backup.h"

#ifdef BL_LEGACY_LEAF
void dtr_togglingHook(uint8_t *buf, uint32_t *len)
Expand All @@ -15,3 +16,24 @@ void dtr_togglingHook(uint8_t *buf, uint32_t *len)
}
}
#endif /* BL_LEGACY_LEAF */

#ifdef BL_HID
void dtr_togglingHook(uint8_t *buf, uint32_t *len)
{
/**
* Four byte is the magic pack "1EAF" that puts the MCU into bootloader.
* Check if the incoming contains the string "1EAF".
* If yes, put the MCU into the bootloader mode.
*/
if ((*len >= 4) && (buf[0] == '1') && (buf[1] == 'E') && (buf[2] == 'A') && (buf[3] == 'F')) {
enableBackupDomain();
/* New HID Bootloader (ver 2.2+) */
setBackupRegister(HID_MAGIC_NUMBER_BKP_INDEX, HID_MAGIC_NUMBER_BKP_VALUE);
#ifdef HID_OLD_MAGIC_NUMBER_BKP_INDEX
/* Compatibility to the old HID Bootloader (ver <= 2.1) */
setBackupRegister(HID_OLD_MAGIC_NUMBER_BKP_INDEX, HID_MAGIC_NUMBER_BKP_VALUE);
#endif
NVIC_SystemReset();
}
}
#endif /* BL_HID */
4 changes: 2 additions & 2 deletions cores/arduino/stm32/bootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define _BOOTLOADER_H_

/* Ensure DTR_TOGGLING_SEQ enabled */
#ifdef BL_LEGACY_LEAF
#if defined(BL_LEGACY_LEAF) || defined(BL_HID)
#ifndef DTR_TOGGLING_SEQ
#define DTR_TOGGLING_SEQ
#endif /* DTR_TOGGLING_SEQ */
#endif /* DTR_TOGGLING_SEQ || BL_HID */
#endif /* BL_LEGACY_LEAF */

#ifdef __cplusplus
Expand Down
10 changes: 10 additions & 0 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ tools.bmp_upload.upload.params.verbose=-batch
tools.bmp_upload.upload.params.quiet=--batch-silent
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"

# HID flash 2.2 (HID bootloader v2.2 for STM32F1 and STM32F4 series)
tools.hid_upload.cmd=hid-flash
tools.hid_upload.cmd.windows=hid-flash.exe
tools.hid_upload.path={runtime.hardware.path}/tools/win
tools.hid_upload.path.macosx={runtime.hardware.path}/tools/macosx
tools.hid_upload.path.linux={runtime.hardware.path}/tools/linux
tools.hid_upload.upload.params.verbose=-d
tools.hid_upload.upload.params.quiet=n
tools.hid_upload.upload.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.bin" {serial.port.file}

# Upload using Maple bootloader over DFU
tools.maple_upload.cmd=maple_upload
tools.maple_upload.cmd.windows=maple_upload.bat
Expand Down
6 changes: 3 additions & 3 deletions variants/DIYMROE_F407VGT/ldscript.ld
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@
ENTRY(Reset_Handler)

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

/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
FLASH (rx) : ORIGIN = 0x8000000 + LD_FLASH_OFFSET, LENGTH = LD_MAX_SIZE - LD_FLASH_OFFSET
}

/* Define output sections */
Expand Down