Small USB HID bootloader for BluePill and other STM32F10X devices

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
Post Reply
User avatar
bootsector
Posts: 38
Joined: Sun Apr 15, 2018 10:27 am

Small USB HID bootloader for BluePill and other STM32F10X devices

Post by bootsector » Sun Apr 15, 2018 11:34 am

Hi there!

Maybe this could be moved to the relevant section in the forum!

I've just got to know the BluePill and I'm now migrating all my personal projects (AVR 8-bit based) to ARM!

One of my first needs was a very small bootloader that I can use in my projects. Tried stm32duino bootloader (Thanks, Roger, for the great work on it!), but I needed something simpler, smaller, driverless and compatible with latest GCC toolchains.

So I came up with this small bootloader:

https://github.com/bootsector/stm32-hid-bootloader

Maybe that could be useful for some of you guys!

Cheers,

bootsector

User avatar
RogerClark
Posts: 8416
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by RogerClark » Sun Apr 15, 2018 12:08 pm

Interesting

Can you link to the program used to upload to this bootloader e.g. what is hid-Flash

PS. I have seen similar bootloaders that enumerate as USB mass storage, but also need a special uploader.
However they were much bigger than 1k in size.


Also on an unrelated note, I have noticed a trend for companies now to use raw HID for their products, because Windows doesnt need a special driver.

Well, the dfu bootloader does not really need a driver dll to be installed, all the installer does is associate the dfu driver that comes with Windows to be associated with the USB VID PID of the bootloader

But Microsoft’s approach has just moved the perceived problem of not allowing unknown devices to connect, and now all devices masquerade as HID or mass storage even if they are a completely different type of device

User avatar
bootsector
Posts: 38
Joined: Sun Apr 15, 2018 10:27 am

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by bootsector » Sun Apr 15, 2018 12:15 pm

hid-flash sources is also included in the repo: https://github.com/bootsector/stm32-hid ... master/cli

Trigger condition for the USB HID bootloader is pulling A8 LOW during startup.

Cheers,

bootsector

User avatar
Slammer
Posts: 350
Joined: Tue Mar 01, 2016 10:35 pm
Location: Athens, Greece

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by Slammer » Sun Apr 15, 2018 2:46 pm

And the vector table is redirected to 0x8001000, as I can see...
Image

User avatar
bootsector
Posts: 38
Joined: Sun Apr 15, 2018 10:27 am

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by bootsector » Sun Apr 15, 2018 3:13 pm

Slammer wrote:
Sun Apr 15, 2018 2:46 pm
And the vector table is redirected to 0x8001000, as I can see...
Correct! That's where user program should go, so make sure to adjust your vector table when using this bootloader.

The bootloader takes the first three 1K flash pages. Another 1K flash page is reserved for user configuration data, if desired.

User avatar
RogerClark
Posts: 8416
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by RogerClark » Sun Apr 15, 2018 9:24 pm

So total size is 4K ?

But it should be possible to change that to jump to the existnug Address used by LibMaple as it’s start address

Does it check if a sketch already exists and flash the led etc and then jump to the sketch after a few seconds ?

Does it support locking in hid bootloader mode using the battery backed ram registers ?


It’s just a shame on Windows that the serial driver still needs to be installed :-(

User avatar
bootsector
Posts: 38
Joined: Sun Apr 15, 2018 10:27 am

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by bootsector » Sun Apr 15, 2018 9:51 pm

RogerClark wrote:
Sun Apr 15, 2018 9:24 pm
So total size is 4K ?
That's correct, I'm reserving the first 4K for the bootloader itself plus some space for optional user program configuration data
But it should be possible to change that to jump to the existnug Address used by LibMaple as it’s start address
Right, bootloader can be configured to jump to any flash address you want!
Does it check if a sketch already exists and flash the led etc and then jump to the sketch after a few seconds ?
It just jumps to the defined user program address without checking anything if A8 is not LOW when bootloader runs.
Does it support locking in hid bootloader mode using the battery backed ram registers ?
If bootloader is activated by driving A8 LOW while it starts, firmware will be in HID USB mode until manually restarted or disconnected.
It’s just a shame on Windows that the serial driver still needs to be installed :-(
I'm not sure what you mean here. No drivers should be needed to be installed even on windows.

Just for clarity, this is a very simple and straightforward bootloader. It fits my use cases just fine, but it might be useless for other use cases though.

User avatar
madias
Posts: 1198
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by madias » Sun Apr 15, 2018 10:09 pm

RogerClark wrote:
Sun Apr 15, 2018 9:24 pm
It’s just a shame on Windows that the serial driver still needs to be installed :-(
I think Roger means the general USB serial functionality. For code upload only, this bootloader should work without drivers. I think nobody in this forum will use/program/debug without serial, but building things for third persons this bootloader would be from interest.

User avatar
bootsector
Posts: 38
Joined: Sun Apr 15, 2018 10:27 am

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by bootsector » Sun Apr 15, 2018 10:13 pm

madias wrote:
Sun Apr 15, 2018 10:09 pm
RogerClark wrote:
Sun Apr 15, 2018 9:24 pm
It’s just a shame on Windows that the serial driver still needs to be installed :-(
I think Roger means the general USB serial functionality. For code upload only, this bootloader should work without drivers. I think nobody in this forum will use/program/debug without serial, but building things for third persons this bootloader would be from interest.
Gotcha! Yeah, serial functionality should be inside the user program and that would require a windows driver, for sure!

User avatar
RogerClark
Posts: 8416
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Small USB HID bootloader for BluePill and other STM32F10X devices

Post by RogerClark » Sun Apr 15, 2018 10:14 pm

I really like the idea of the driverless installation of the bootloader, and that it’s only 4K.

Using a special program to upload is also Ok, as we currently have to use DFU-Util and that needs versions for every platform.


I think it should be easy to take the code from the Stm32dunno bootloader which checks if the program start address ram vector contains real data, and then jump after a predefined delay

And flash the LED while waiting , and also do the USB bus reset..

And still be under 4K


Also..
Do you think it would be possible to compile this for the F4 series

As we desperately need a bootloader or the F4

Post Reply