Platformio and HID bootloader (or any bootloader)

LibMaple (The core that Roger's repo uses)
Post Reply
robca
Posts: 8
Joined: Sat Feb 29, 2020 10:59 pm

Platformio and HID bootloader (or any bootloader)

Post by robca »

I have an old Blue Pill device, genuine STM32 chip. I used it many times in the past with Arduino and the Libmaple core. So I know that the board is not the problem

I'm now trying to use Platformio with the Libmaple core. I loaded the STM32duino core and the Libmaple one, I manually updated the Libmaple core because I read that some libraries were not updated (I confirmed it was the case using the F1 USB Composite library https://github.com/arpruss/USBComposite_stm32f1).

I first tried Blinky, but if I uploaded it with the SWD protocol (using ST Link), nothing worked: the project gets flashed but doesn't run, and the USB device is not recognized. I suspected a bootloader problem. I flashed the Maple DFU bootloader, but using that protocol I get a Java crash, not sure why

Lastly I decided to try USB HID (https://github.com/Serasidis/STM32_HID_Bootloader). If I use the ST core, everything works with the following settings in Platformio.ini

[env:genericSTM32F103CB]
platform = ststm32
board = genericSTM32F103CB
framework = arduino

upload_protocol = hid
upload_port = COM3
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D USB_VID=0x0483
-D USB_MANUFACTURER="Unknown"
-D USB_PRODUCT="\"genericSTM32F103CB\""
-D HAL_PCD_MODULE_ENABLED

Code flashes, then reboots and I can see Blinky working as expected. If I reflash, everything works (i.e. HID bootloader is maintained)

But if I add the "use Maple core configuration" as follows

[env:genericSTM32F103CB]
platform = ststm32
board = genericSTM32F103CB
framework = arduino
board_build.core = maple ; Use Maple core

upload_protocol = hid
upload_port = COM3
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D USB_VID=0x0483
-D USB_MANUFACTURER="Unknown"
-D USB_PRODUCT="\"genericSTM32F103CB\""
-D HAL_PCD_MODULE_ENABLED

The code builds and flashes, but then the BluePill is not recognized as a USB device and Blinky doesn't blink. Just like when using SWD to flash

What is the trick to use a BluePill with Platformio and the Maple/Rogers core?

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

Re: Platformio and HID bootloader (or any bootloader)

Post by mrburnette »

... then the BluePill is not recognized as a USB device ...
What is the trick to use a BluePill with Platformio and the Maple/Rogers core?
Roger's bootloader is an enhancement on the original LeafLab's bootloader which enumerated the USB hardware. So, without a bootloader the user's sketch code must provide the enumeration. Thus, if you are using the built-in serial loader or the SWD, there is no bootloader because you overwrote the flash space and the uC starts with the user code after Reset.

Roger's enhancements to Libmaple deals with this by appending automatically the binary for USB when used on the Blue Pill. With Maple Mini, a bootloader is always assumed.

https://stm32duinoforum.com/forum/viewt ... rt_20.html

Bottom line: Pick a core and stay with it. When you start to compare Official Core with Roger's core and throw in the Platformio product, there are just going to be issues and these MUST be accepted. Only the Official Core from STM is supported. Roger's core is in long-term (limited changes) mode.

Ray
Last edited by mrburnette on Mon Sep 14, 2020 4:09 pm, edited 1 time in total.

robca
Posts: 8
Joined: Sat Feb 29, 2020 10:59 pm

Re: Platformio and HID bootloader (or any bootloader)

Post by robca »

Thanks for the reply. And just to leave more info for anyone else facing the same problem in the future

i had loaded both STM32 cores in Platformio, which creates an unpleasant side effect: when creating a new project, Platformio uses the content of boards.txt from both cores. So if you select the option for Blue Pill, it comes from the official core. If you then select to use the old Rogers core, things can get bad.

But you can have both cores coexist, as long as you select the boards.txt option from the core you compile with. In my case I needed to use the Generic STM32F103C8 (20k, 128k) board and then select SWD load. Everything then compiles and uploads fine (since I use SWD, no need to have a bootloader... easier to debug, too)

Unfortunately the official core only supports mouse, keyboard and serial for USB, and the great https://github.com/arpruss/USBComposite_stm32f1 library is not supported. I got it working as I wanted in minutes with Rogers core, so for now I'll stay with that. I also have an H7 board, and for that only the official core works

Post Reply

Return to “LibMaple”