STM32F1 USB CDC bootloader

developed for generic STM32F1 (bluepill) device by stevestrong
Post Reply
stevestrong
Posts: 268
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 5
Location: Munich, Germany
Contact:

STM32F1 USB CDC bootloader

Post by stevestrong »

Hi all,

I would like to introduce the USB CDC bootloader developed for generic STM32F1 (bluepill) device.
Source files are available as Eclipse for C++ (latest version) project: https://github.com/stevstrong/STM32F1-CDC-Bootloader

I just wondered since a long time ago why such a bootloader was not developed by anyone else?
So this is why I made it just for fun, so don't ask "why yet another bootloader?"...

The main source of inspiration was this german site, together with further links available on that site.
And, of course, special thanks go to Roger (the stm32duino bootloader) and Vassilis (the HID bootloader).

Features:
-- no special driver installation needed, the device with this bootloader will be enumerated as a usual serial COM port.
-- the source files are partially based on libmaple core files, also included in this repository. This was one of the important factors, the code had to be readable and easily understandable.
-- the binary size of the bootloader is 4092 bytes so that is fits in the lower 4 memory pages of EEPROM of the bluepill.
However, at the moment the user code start address is hard coded to 0x0802000 (reserved 8kB memory), I used this in conjunction with programs compiled for upload with STM32duino 2.0 bootloader for initial tests.
-- in order to upload a program with the bootloader, a special utility program is needed, see CDC flasher, only available for windows atm.
The flasher looks for a serial device having vid:pid of 1eaf:0004, and generates a reset (using the well known magic sequence), if the core files support this feature.
After reset a serial device having 1eaf:0002 is expected. If found, then the user program code will be uploaded and executed right after that.
Entering into bootloader mode is identical with the HID bl behavior: by magic sequence (if supported by the core), PB2 set or missing user code at 0x0802000.

Currently, the bootloader can be used with the flasher as external tool, called within a cmd window.
I have tried to include the flasher into the Arduino framework, but somehow Arduino cannot start it correctly, it just freezes, I don't know why :?
Maybe someone can help on this.

Todos:
- integrate it into Arduino framework:
- add an extra upload tool in the platform and board txt files, with the correct user program start address of 4kB
- make Arduino to correctly execute the flasher tool - help is needed here
- port it to other STM family MCUs (F3, F4)

This project was very instructive, I can now understand the USB better then an average skilled user.
I also realized now how easy is to implement other type of USB devices, HID, MSC and any combination of them.
Maybe, sometime in the future, I will eventually adapt the USB composite library to this simple USB core.

I have also integrated this simple USB core to my libmaple repository, which saved at least 3 kB of code any some good amount of RAM.
I will eventually make a PR for the Roger's libample core, if Roger considers that it would make sense.

PS. Admin, do we need another group in the Bootloaders section for this?

mrburnette
Posts: 187
Joined: Thu Dec 19, 2019 1:23 am

Re: STM32F1 USB CDC bootloader

Post by mrburnette »

++1

User avatar
fpiSTM
Posts: 663
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 25
Location: Le Mans
Contact:

Re: STM32F1 USB CDC bootloader

Post by fpiSTM »

@stevestrong
if you want a new section, no problem.
Let me know which name you want.

Note that I'm the only Admin/moderator...

stevestrong
Posts: 268
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 5
Location: Munich, Germany
Contact:

Re: STM32F1 USB CDC bootloader

Post by stevestrong »

I was thinking on "STM32 USB CDC bootloader", if you agree.

ag123
Posts: 467
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: STM32F1 USB CDC bootloader

Post by ag123 »

++1 !

User avatar
fpiSTM
Posts: 663
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 25
Location: Le Mans
Contact:

Re: STM32F1 USB CDC bootloader

Post by fpiSTM »

stevestrong wrote:
Tue Apr 28, 2020 9:34 am
I was thinking on "STM32 USB CDC bootloader", if you agree.
Done. Let me know if you want to change the description.
And also if you want clean messages about formum management.

User avatar
Vassilis
Posts: 8
Joined: Wed Dec 18, 2019 3:04 pm
Location: Thessaloniki, Greece
Contact:

Re: STM32F1 USB CDC bootloader

Post by Vassilis »

+1 :)
Well done Steve
Vassilis Serasidis

Post Reply

Return to “STM32 USB CDC bootloader”