STM32F103C8 and Fast Bootloader

STM32duino bootloader aka Maple bootloader
GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

I built a board based on the STM32F103C8. It has the 1.5k ohm pullup on USB D+ and it also has a 8MHz crystal and 32.768kHz crystal. I was experimenting with the bootloaders and the first bootloader I programmed in was the generic_boot20_pc13.bin using a ST Link and SWD. After I did that I was able to see the Maple Serial COM port show up on my Win10 PC. I used the latest Arduino IDE and tried to flash a sketch. I saw the board switch to DFU mode and it looked like the sketch was loaded but the IDE listed some connection errors.

I tried a few different times and after flashing the board would stay in DFU mode. I decided I would try the generic_boot20_pc13_fastboot.bin bootloader and now after flashing that the board always shows up as the Maple serial port but known of the tools can communicate with the board, not over USB or using the ST Link SWD (using both ST Link uloader or STM32 Cube Programmer).

The board shouldn't be bricked since when I plug it in with USB it enumerates and creates the serial port but that's all I can get.

Does anyone have any ideas on how I can debug this and bring the board back to life? In my design both BOOT0 and BOOT1 are pulled low and I forgot to add a jumper or button to be able to change the boot up mode but I can add jumper wires if that's what I need to do.

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

Re: STM32F103C8 and Fast Bootloader

Post by ag123 »

place a led on pc13, it should blink for 6 secs after reset. you need to install your sketch over usb-dfu in that 6s
assuming if you have the 'standard' usb-serial with the maple magic command in the core, it is then possible to install a new sketch from the arduino ide.
it uses the DTR - L.E.A.F sequence to trigger a reset and dfu mode. if for any reason you disable that usb-serial with the magic sequence trigger in the sketch/core. you would need to press reset and flash in 6 sec.
roger made an enhancement to keep it in 'perpetual' dfu mode if you set boot1, this would help if you stumble over installing a sketch in that 1st 6 secs after reset when the led blinks
http://docs.leaflabs.com/static.leaflab ... oader-mode
https://github.com/rogerclarkmelbourne/ ... fig.h#L422

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

Sorry, but what do you mean by "standard' usb-serial with the maple magic command in the core"? The last operation that worked was loading generic_boot20_pc13_fastboot.bin over SWD using the ST Link.

When I had just boot20_pc13.bin flashed I could see the board switch from serial to DFU but now it's always showing up as the Maple Serial Port.

PC13 is actually unused on my board so I could solder in a LED but I think you're saying that I need to manually issue a reset on the board to put it into DFU mode? Just curious why that was automatic without fastboot and now it isn't.

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

Re: STM32F103C8 and Fast Bootloader

Post by ag123 »

if you are using libmaple core, (note the core, not the boot loader) there is a piece of code that looks for the sequence
DTR - L . E. A. F
https://github.com/rogerclarkmelbourne/ ... l.cpp#L285
when this sequence is received, it does a reset. so that the usb dfu boot loader runs in the next 6 seconds

there is a utility shipped with the core. arduino ide runs that if you select stm32duino boot loader as the upload method.
so that it resets without needing you to press reset.

alternatively you can try things like, press reset and run (in the 1st 6 secs)

Code: Select all

dfu-util -a 2 -RD sketch.bin
where sketch.bin is your compiled firmware bin
you'd find dfu-util in the tools folder if you have installed libmaple core
alternatively you can get an updated version from here
http://dfu-util.sourceforge.net/

accordingly the magic sequence is implemented in the official core as well. but i'm not too sure how that works

the led at PC13 helps as it blinks when the boot loader starts
i've not tried the fastboot version, the behavior may be different. perhaps you can try both the generic_boot20_pc13.bin and generic_boot20_pc13_fastboot.bin
https://github.com/rogerclarkmelbourne/ ... r/binaries
note that on blue pill, the led is active low, i.e. it sinks from 3v3 when the led is on

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

Re: STM32F103C8 and Fast Bootloader

Post by stevestrong »

The normal bootloader waits for 3 seconds in DFU mode to allow the application to be uploaded, and jumps to the application after that.

The fast bootloader does not wait, it checks whether there is valid code at 0x08002000 and jumps to that if so.
It also check whether the magic word is written (by the software which initiated the soft reset) in the backup registers and if so then waits for code upload over USB.
Alternatively, it also stays in DFU mode if BOOT1 is tied to high.

To connect over SWD you need to press reset and then try to connect. The timing here is critical so you have to try several combinations.

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

OK, well it seems that I have some research to do. I don't believe that I'm running the libmaple core because I don't have the stm32duino boot loader option in the Arduino IDE, I have "Maple DFU Bootloader 2.0" and "Maple DFU Bootloader Original" along with the standard STM32 upload options.

Right now none of the tools can connect to the board to allow me to flash anything. This happened after I flashed generic_boot20_pc13_fastboot.bin .

The STM32F103C8 is running something since when I plug it into the PC I do get the Maple Serial Com port to show up.

So this morning I'll solder in an LED to PC13 as well as adding a button so I can pull BOOT0 high and reset the board while it is plugged in using USB and not SWD. If I can get it inot DFU mode resetting the board within 3 seconds of power up I can at least flash the generic_boot20_pc13.bin bootloader back in and see if I can communicate with the board again. If that works that will get me back to being able to flash using SWD and I can go back to trying to figure out why the board would get stuck in DFU mode if the Arduino IDE does the programming.

BOOT1 is pulled low on my board but it actually is used to drive to MOSFET and there's a 10k series resistor and then a 10k pull down before the connection to the gate of the MOSFET.

@stevestrong Once I'm able to connect over SWD what should I flash if my ultimate goal is to flash firmware over USB instead of SWD?

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

Re: STM32F103C8 and Fast Bootloader

Post by stevestrong »

Flashing over USB is possible using a bootloader, wherein there are several botloaders available.
You have tried the normal and fast DFU bootloaders, both should work but need a special USB driver.
When you already have the fastbootloader, you should be able to upload new code, but you have to specify in Arduino IDE the USB serial COM port, because the uploader utility will use this port to send a magic sequence which resets the CPU and forces it to wait for upload.

Alternatives for a driverless bootloader are the HID and the CDC bootloder.

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

I do have the driver installed and when I was using the generic_boot20_pc13.bin I did see the board go from a COM port to a DFU. But now with the generic_boot20_pc13_fastboot.bin installed I'm only getting the COM port when I am trying to use the Arduino IDE to flash a sketch. If there a different driver that I need now that I have the fast DFU bootloader installed? Perhaps there's something else I need to install in the Arduino IDE?

Sorry for the questions but I wasn't expecting to get stuck like I am now and before the fast DFU was installed I always had access over SWD but that does not work now as it can't see the target.

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

Re: STM32F103C8 and Fast Bootloader

Post by ag123 »

i think the 'fast' boot works by having some codes in the *core* (not bootloader) by saving some values in the backup registers.
so those persist across reset. that saves the initial 'irritation' of the initial delay with the 'conventional' boot loader.
i'd suggest you could work with the 'conventional' one first hand to get sketches working, the 3 secs delay (i probably mis-intepreted to be longer) at boot.
that helps in that it is 'easier' if you have 3 secs 'delay' to install a new sketch.
in fact, more often i did not use the ide to do my installs, more often, i've the command line ready (roger's bootloader, 'conventional' not 'fast')
note i'm working in linux

Code: Select all

dfu-util -a 2 -RD sketch.bin
and hit enter on pressing reset and i flashed the sketch. the bin file is normally found in the Arduino IDE temporary build folders.
in the end i made do with the 3 secs delay and literally keep binaries as i got lazy to having to rebuilt each time i wanted it.

as for the 'fast' boot, you'd need to dig in to the codes in the (libmaple) core, figure out the define or selection that'd set the backup register, so that the codes that is part of the core/sketch would set that backup register and reset so that it'd fall directly into the boot loader.
it saves you 3s each time upon board reset if you regularly use the same board for the same app

GeorgeIoak
Posts: 39
Joined: Sun Jun 07, 2020 2:01 am

Re: STM32F103C8 and Fast Bootloader

Post by GeorgeIoak »

I have a SWD breakout board so I used that to access nRST. I plugged the USB cable in and jumpered nRST momentarily to 3.3V immediately after power up but I still only see the Maple COM port in the Device Manager. I tried this several times but I don't see the COM port drop out or the DFU appear.

I assume that if I don't see DFU device in Device Manager then any DFU utility isn't going to be able to access the device, right?

So how can I get this board into DFU mode knowing that I've flashed the fastboot bootloader and I'm only seeing the COM port device?

Post Reply

Return to “USB bootloader”