Skip to content

Hid/DFU boot loader (superseded by #525) #415

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

Closed
wants to merge 4 commits into from
Closed
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
31 changes: 29 additions & 2 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,27 @@ 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 3.0 (0x0800)
GenF1.menu.upload_method.hidMethod.upload.protocol=hid3
GenF1.menu.upload_method.hidMethod.upload.tool=hid_upload
GenF1.menu.upload_method.hidMethod.upload.bl_size=0x800
GenF1.menu.upload_method.hidMethod.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} -DVECT_TAB_OFFSET=0x0800 -DHIDBL_F1

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
GenF1.menu.upload_method.dfu2Method.upload.bl_size=0x2000
GenF1.menu.upload_method.dfu2Method.upload.usbID=1EAF:0003
GenF1.menu.upload_method.dfu2Method.upload.altID=2
GenF1.menu.upload_method.dfu2Method.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} -DVECT_TAB_OFFSET=0x2000 -DUSB_DISC_PIN=PB9

GenF1.menu.upload_method.dfuoMethod=Maple DFU Bootloader original (0x5000)
GenF1.menu.upload_method.dfuoMethod.upload.protocol=maple
GenF1.menu.upload_method.dfuoMethod.upload.tool=maple_upload
GenF1.menu.upload_method.dfuoMethod.upload.bl_size=0x5000
GenF1.menu.upload_method.dfuoMethod.upload.usbID=1EAF:0003
GenF1.menu.upload_method.dfuoMethod.upload.altID=1
GenF1.menu.upload_method.dfuoMethod.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} -DVECT_TAB_OFFSET=0x5000 -DUSB_DISC_PIN=PB9
################################################################################
# Generic F4

Expand Down Expand Up @@ -734,6 +755,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 3.0 (0x4000)
GenF4.menu.upload_method.hidMethod.upload.protocol=hid3
GenF4.menu.upload_method.hidMethod.upload.tool=hid_upload
GenF4.menu.upload_method.hidMethod.upload.bl_size=0x4000
GenF4.menu.upload_method.hidMethod.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} -DVECT_TAB_OFFSET=0x4000 -DHIDBL_F4

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

Expand Down Expand Up @@ -761,7 +788,7 @@ Sparky.menu.upload_method.STLinkMethod=STLink
Sparky.menu.upload_method.STLinkMethod.upload.protocol=STLink
Sparky.menu.upload_method.STLinkMethod.upload.tool=stlink_upload

################################################################################
###############################
# RAK boards

RAK.name=RAKWireless
Expand Down Expand Up @@ -1349,4 +1376,4 @@ RAK.menu.rtlib.full.build.flags.ldspecs=
3dprinter.menu.rtlib.nanofps=Newlib Nano + Float Printf/Scanf
3dprinter.menu.rtlib.nanofps.build.flags.ldspecs=--specs=nano.specs -u _printf_float -u _scanf_float
3dprinter.menu.rtlib.full=Newlib Standard
3dprinter.menu.rtlib.full.build.flags.ldspecs=
3dprinter.menu.rtlib.full.build.flags.ldspecs=
36 changes: 35 additions & 1 deletion cores/arduino/stm32/usb/cdc/usbd_cdc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ __IO bool receivePended = true;
static uint32_t transmitStart = 0;


/* USER CODE BEGIN PRIVATE_VARIABLES */
uint8_t dtr_pin = 0; //DTR pin is disabled
/* USER CODE END PRIVATE_VARIABLES */

/** USBD_CDC Private Function Prototypes */

static int8_t USBD_CDC_Init(void);
Expand Down Expand Up @@ -182,6 +186,8 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
if (lineState) { // Reset the transmit timeout when the port is connected
transmitStart = 0;
}
dtr_pin++; //DTR pin is enabled

break;

case CDC_SEND_BREAK:
Expand Down Expand Up @@ -213,6 +219,35 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
*/
static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
/* Four byte is the magic pack "1EAF" that puts the MCU into bootloader. */
if (*Len >= 4) {
/**
* Check if the incoming contains the string "1EAF".
* If yes, check if the DTR has been set, to put the MCU into the bootloader mode.
*/
if (dtr_pin > 3) {
if ((Buf[0] == '1') && (Buf[1] == 'E') && (Buf[2] == 'A') && (Buf[3] == 'F')) {

#if defined (HIDBL_F1)
RTC_HandleTypeDef hrtc;
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_BKP_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR10, 0x424C); //Write the magic number 0x424C

#elif defined (HIDBL_F4)
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
__BKPSRAM_CLK_ENABLE();
*(__IO uint32_t *)(BKPSRAM_BASE) = 0x424C; //Write the magic number 0x424C at Backup SRAM address 0x40024000

#endif
HAL_NVIC_SystemReset();
}
dtr_pin = 0;
}
} /* USER CODE END */
UNUSED(Buf);
/* It always contains required amount of free space for writing */
CDC_ReceiveQueue_CommitBlock(&ReceiveQueue, (uint16_t)(*Len));
Expand All @@ -224,7 +259,6 @@ static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
return USBD_OK;
}


static int8_t USBD_CDC_Transferred(void)
{
transmitStart = 0;
Expand Down
26 changes: 25 additions & 1 deletion platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ build.usb_speed=
build.startup_file=
build.flags.optimize=-Os
build.flags.ldspecs=--specs=nano.specs
upload.bl_size=0

# Pre and post build hooks
build.opt.name=build_opt.h
Expand All @@ -97,7 +98,7 @@ recipe.hooks.prebuild.1.pattern.macosx=bash -c "[ -f {build.opt.sourcepath} ] ||
# preprocess linker file
preprocld.name=preproc.ld
preprocld.filepath={build.path}/{preprocld.name}
preprocld.flags=-DLD_MAX_SIZE={upload.maximum_size} -DLD_MAX_DATA_SIZE={upload.maximum_data_size}
preprocld.flags=-DLD_MAX_SIZE={upload.maximum_size} -DLD_MAX_DATA_SIZE={upload.maximum_data_size} -DBL_SIZE={upload.bl_size}
recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -x c -E -P {preprocld.flags} {compiler.c.flags} {build.info.flags} {compiler.c.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "{build.variant.path}/{build.ldscript}" -o "{preprocld.filepath}"

# compile patterns
Expand Down Expand Up @@ -186,3 +187,26 @@ tools.bmp_upload.upload.speed=230400
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 upload 2.0 (HID bootloader 2.0 This bootloader will cover the STM32F1 and STM32F4 MCUs)
tools.hid_upload.cmd=hid_upload
tools.hid_upload.cmd.windows=hid-flash.exe
tools.hid_upload.cmd.macosx=hid_flash
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.path.linux64={runtime.hardware.path}/tools/linux64
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
tools.maple_upload.path={runtime.hardware.path}/tools/win
tools.maple_upload.path.macosx={runtime.hardware.path}/tools/macosx
tools.maple_upload.path.linux={runtime.hardware.path}/tools/linux
tools.maple_upload.path.linux64={runtime.hardware.path}/tools/linux64
tools.maple_upload.upload.params.verbose=-d
tools.maple_upload.upload.params.quiet=n
tools.maple_upload.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin"
6 changes: 3 additions & 3 deletions variants/BLACK_F407XX/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 = LD_MAX_SIZE
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
}

/* Define output sections */
Expand Down
2 changes: 1 addition & 1 deletion variants/BLUEPILL_F103XX/ldscript.ld
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = LD_MAX_SIZE
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
}

/* Define output sections */
Expand Down
6 changes: 3 additions & 3 deletions variants/BLUE_F407VE_Mini/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 = 512K
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
}

/* Define output sections */
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 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
}

/* Define output sections */
Expand Down
43 changes: 11 additions & 32 deletions variants/FK407M1/ldscript.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

** File : LinkerScript.ld
**
** Abstract : Linker script for STM32F407VETx Device with
** 512KByte FLASH, 128KByte RAM
** Abstract : Linker script for STM32F103CBTx Device with
** 128KByte FLASH, 20KByte RAM
**
** Set heap size, stack size and stack location according
** to application requirements.
Expand Down 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 = 512K
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
}

/* Define output sections */
Expand All @@ -77,7 +77,7 @@ SECTIONS
} >FLASH

/* The program code and other data goes into FLASH */
.text ALIGN(8):
.text ALIGN(4):
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
Expand All @@ -94,7 +94,7 @@ SECTIONS
} >FLASH

/* Constant data goes into FLASH */
.rodata ALIGN(4):
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
Expand Down Expand Up @@ -134,7 +134,7 @@ SECTIONS
_sidata = LOADADDR(.data);

/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
Expand All @@ -145,26 +145,7 @@ SECTIONS
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH

_siccmram = LOADADDR(.ccmram);

/* CCM-RAM section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.ccmram :
{
. = ALIGN(4);
_sccmram = .; /* create a global symbol at ccmram start */
*(.ccmram)
*(.ccmram*)

. = ALIGN(4);
_eccmram = .; /* create a global symbol at ccmram end */
} >CCMRAM AT> FLASH



/* Uninitialized data section */
. = ALIGN(4);
.bss :
Expand Down Expand Up @@ -192,7 +173,7 @@ SECTIONS
. = ALIGN(8);
} >RAM



/* Remove information from the standard libraries */
/DISCARD/ :
Expand All @@ -203,6 +184,4 @@ SECTIONS
}

.ARM.attributes 0 : { *(.ARM.attributes) }
}


}
6 changes: 3 additions & 3 deletions variants/MAPLEMINI_F103CB/ldscript.ld
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20005000; /* 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 = 20K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
FLASH (rx) : ORIGIN = 0x8000000 + BL_SIZE, LENGTH = LD_MAX_SIZE - BL_SIZE
}

/* Define output sections */
Expand Down