Skip to main content
Graduate II
October 31, 2024
Solved

One-time HID bootloader? ("destroying" the STM32F103's ability to load bootloader again) ?

  • October 31, 2024
  • 4 replies
  • 2140 views

In order to make it easier for others to upload software, I decided to add the HID Bootloader:

https://github.com/Serasidis/STM32_HID_Bootloader

 

it is small and effiecient

 

uploaded this to Bluepill (both jumpers in "0" position)

 

$ ./STM32_Programmer.sh -c port=SWD -w ~/Downloads/stm32_HID\ bootloader2.2/F103/low_and_medium_density/hid_generic_pc13.bin 0x08000000
 -------------------------------------------------------------------
 STM32CubeProgrammer v2.5.0 
 -------------------------------------------------------------------

ST-LINK SN : 7287090032124647524B4E00
ST-LINK FW : V2J29S7
Board : --
Voltage : 3.18V
SWD freq : 4000 KHz
Connect mode: Normal
Reset mode : Software reset
Device ID : 0x410
Revision ID : Rev X
Device name : STM32F101/F102/F103 Medium-density
Flash size : 64 KBytes
Device type : MCU
Device CPU : Cortex-M3



Memory Programming ...
Opening and parsing file: hid_generic_pc13.bin
 File : hid_generic_pc13.bin
 Size : 1976 Bytes
 Address : 0x08000000 


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 1]
Download in Progress:
[==================================================] 100% 

File download complete
Time elapsed during download operation: 00:00:00.181

 

 

 

In order to test it, I uploaded "blink" using Arduino method "HID bootloader 2.2"

it worked, the device started blinking - tried again, but was unable, no matter what I did the HID device 1209:BEBA does not appear anymore. 
Re-uploaded the bootloader using SWD - but this time it does not work at all.

I repeated this two times, this process does somehow mess up the device.

 

 

    This topic has been closed for replies.
    Best answer by pilot

    oh, I see, the main program gets executed first, unless I move the jumper!

     

    Are there other small bootloaders ?

    4 replies

    pilotAuthorAnswer
    Graduate II
    October 31, 2024

    oh, I see, the main program gets executed first, unless I move the jumper!

     

    Are there other small bootloaders ?

    Visitor II
    January 8, 2025

    Have you tried flashing a bin file or uploading an app to HID Bootloader without using arduino IDE? If yes, how you've been able to do it without overwriting the bootloader?

     

    pilotAuthor
    Graduate II
    January 8, 2025

    yes, the solution was to build outside Arduino, I guess that Arduino produces code that overwrites the bootloader. Using PlatformIO solved the issue.

    Visitor II
    January 9, 2025

    Thank you for the reply. I am currently trying to make the HID bootloader work for my stm32f103c8t6 custom dev board. What have you done to produce bin file which wont overwrite the bootloader?

    I tried editing the linker file of the app I'm making so many times and set the address of the application to where it will not mess up the allocated memory for bootloader but somehow it does not work.

     

     

    MEMORY
    
    {
    
    RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
    
    FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 60K
    
    
    
    }

     

    I also modified this system_stm32f1xx.c in STM32CUBEIDE

     

    #if defined(USER_VECT_TAB_ADDRESS)
    /*!< Uncomment the following line if you need to relocate your vector Table
     in Sram else user remap will be done in Flash. */
    /* #define VECT_TAB_SRAM */
    #if defined(VECT_TAB_SRAM)
    #define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
     This value must be a multiple of 0x200. */
    #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
     This value must be a multiple of 0x200. */
    #else
    #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
     This value must be a multiple of 0x200. */
    #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
     This value must be a multiple of 0x200. */
    #endif /* VECT_TAB_SRAM */
    #endif /* USER_VECT_TAB_ADDRESS */

     

    What do you think the right approach to create binary file which is compatible to HID Bootloader?


     

    pilotAuthor
    Graduate II
    January 9, 2025

    I have only used the PlatformIO in VSCode on Linux -method, which "just works"  when compiling for the upload protocol of "hid"  - I do not know exactly what is done.

    If I compile the upload protocol "stlink"  - and then upload that binary using HID, it will mess up he bootloader.

    Somehow - something is different between those two binary files.