rrivirr / rriv

GNU General Public License v3.0
1 stars 9 forks source link

Custom bootloader to program board over USB #103

Open ZavenArra opened 1 year ago

ZavenArra commented 1 year ago

We want to be able to plug the board in using USB, and program the MCU directly from platformio, without using an STLINK programmer.

The default bootloader on our MCU, the STM32F103RB, allows for programming over STLINK and serial. We would like to be able to program the MCU directly over the USB connection instead, using the on-chip USB controller.

The USB controller is not enabled by default in the bootloader, so it is necessary to write a custom bootloader. Searching online reveals that customer bootloaders haven been written for STM31F103RB, but documentation is scarce.

One approach is to use the USB HID mode to accomplish this: https://github.com/Serasidis/STM32_HID_Bootloader

A bootloader has also been written for STMduino boards, which use the same processor as WaterBear but are not the same PCB. This may also be a good starting point: https://github.com/rogerclarkmelbourne/STM32duino-bootloader

Also see https://rrivirr.github.io/rriv-documentation/hardware/datasheets/ for datasheets for the F103RB and other components.

matthewdburton commented 1 year ago

Some notes: Didn't find many other options besides Zaven's recommendations. Found a walk through here

From the AN2606 app note we see the description of the system bootloader

Screen Shot 2022-11-29 at 12 38 34 PM

I'm leaning STM32duino approach, next step is to move forward and try it. Let me know if there are any other considerations here, mostly not familiar with our current flash & SRAM usage/use cases.

ZavenArra commented 1 year ago

In terms of SRAM and flash, we don't need to be very concerned about space because the target platform (since PCB with MCU embedded, rather than the shield we are using now) will have a much higher capacity version of the F103. We have been waiting for availability due to supply chain issues, but have now secured 100 STM32F013RE chips, which are 512K flash and 64K SRAM (https://www.st.com/en/microcontrollers-microprocessors/stm32f103.html).

I saw in the post that HID doesn't require drivers while the other approach does, so I lean towards not requiring drivers as it might make things easier for various users with different levels of experience. I imagine that other details might also complicate one approach or the other as we get this working, so the approach to use is whatever gets us to being able to program the device over USB the easiest without additional hardware or less well known software needing to be involved (currently we built and program directly via platformio, so retaining that workflow is also a goal)