STM32 with USB boot loader

Hello and welcome to our post today.

 

The STM32 module is well known to many. Equipped with a 32-bit arm cortex, it plays in a different league than, for example, the Nano V3.

However, I myself have to admit that I usually use the Nano V3 when I start a project, and only switch to the STM32 when I find that the nano is no longer sufficient. The main reason is that I always have to connect an FTDI adapter for the STM32, while I can connect a Nano V3 simply via USB.

The STM32 also has a USB port, but this is only used to power the module.

One of the reasons is that the STM32 does not ship with a USB boot loader. This boot loader occupies about 20k of disk space. However, since I have never intentionally reached the 64k limit, today we try to flash the USB boot loader.

To do this, we need:

1x STM32 Microcontroller + MicroUSB Cable
1x USB FTDI Adapter + MiniUSB Cable
Jumper cable
Patience and strong nerves

In the first step, we make sure that the jumper of the FTDI adapter is set to 3.3V and connect the components as follows:

STM32 FTDI Adapter
G Gnd
A10 Tx
A9 Rx

 

If you are sure that your FTDI adapter to VCC outputs a clean 3.3V (preferably measure first) you can power your STM32 above it. However, I have had bad experiences with this in the past, and prefer to supply my STM32 with power via USB. We connect the FTDI adapter to the PC and select the correct module in the Arduino IDE:

 

If there is no STM32 in the board manager, the appropriate drivers still need to be installed.

To do this, the first thing you need to do is toArduino SAM" support via the board manager. This is necessary to install the arm-none-eabi-g++ toolchain.

 

Next, we need the files for the STM32 that we can download from GitHub: https://github.com/rogerclarkmelbourne/Arduino_STM32/archive/master.zip 

We unpack them from the Arduino directory C:-Users-<Users>-Documents-Arduino-hardware-Arduino_STM32.

If the folder "hardware" does not yet exist, we can simply create it.

Now we need to install the serial upload drivers by running the file "install_drivers.bat" as administrator in the Arduino_STM32 folder under "drivers" -> "win".

If at some point in the future (typically after an automatic Windows update) the STM32 can no longer be programmed, it usually helps to perform the above driver installation again.

Now, after restarting the Arduino IDE, the board should be available for selection.

Via "File" -> "Examples" -> "A_STM32_Examples" -> "Digital" -> "Blink" we now open the Blink sample sketch and change the pin in 3 places of PB1 also PC13.

Finally, we set the BOOT0 jumper on the STM32 to 1, and upload the blink program.

 

If you have any problems at this point, please check the wiring and make sure the settings match your STM32 board.

 

Next we need the program "STM32 Flash loader demonstrator (UM0462)" which we can Manufacturer's pagecan download. After registering on the manufacturer's page, we can download and install the program.

Finally, we need the binaries with the USB boot loader. These can also be found on GitHub at https://github.com/rogerclarkmelbourne/STM32duino-bootloader/tree/master/binaries.

We need the file "generic_boot20_pc13.bin" for our module. 

We launch the Flash Loader Demonstrator, select the port that is right for us, and click "Next".

If the program freezes at this point, it may take a few minutes for an error message to appear. In this case simply make sure that the jumper BOOT0 is set to 1, and restart the STM32 with the reset button, then it should go.

The next two windows show us information about flash size. We can skip these by means of "Next".

In the last window, we need to select "Download to device" and select the .bin file. 

If you don't see the .bin file, please change the extension from "s19 Files (*.s10)" to "Bin Files (*.bin)".

Now we load the firmware on our STM32. After a few seconds, the following message should appear:

Before we do anything, we should set the BOOT0 jumper from 1 to 0, otherwise the bootloader will be gone after a restart. We can now disconnect the FTDI adapter and connect our STM directly via USB.

In the device manager (press Win+R and enter devmgmt.msc) a new entry should now appear under "Connections (COM & LPT)":

 

 

To test if it works now, we try to upload our Blink Sketch again. For this purpose, we change the upload method to "STM32duino bootloader" in the board settings.

 

The upload should be completed after a few seconds, and our onboard LED will start flashing again. We can ignore the error message about the usb_reset.

Managed! From now on, laziness no longer counts as an excuse to leave the STM32 in the drawer.

I hope you enjoyed our contribution today and will help you take the step into the world of 32-bit microcontrollers.

 

I wish everyone a nice weekend and a lot of fun while tinkering.

Yours Markus Neumann

 

 

Projects for beginners

6 comments

Ricardo

Ricardo

Ich habe bei Amazon AZDelivery 3 x STM32 STM32F103C8T6 gekauft.
Es ist für mich unmöglich, dass Windows 10 64 das Gerät über USB erkennt.
Ich habe Ihr Tutorium und andere im Internet verfolgt.
Irgendeine Lösung?
Danke

Gholiamirza

Gholiamirza

Es geht viel einfacher mit dem STM32F103C.
Schaut am besten hier https://youtu.be/MLEQk73zJoU

Matthias 2

Matthias 2

Scheint kein Einzelfall zu sein. Auch bei mir funktioniert der Anschluß über USB nicht (Win10Pro). Bis dahin lief alles nach Anleitung genauso ab wie beschrieben. Jumper umgesteckt. Stecke ich nun USB an, dann bekomme ich die Meldung “USB-Gerät unbekannt” – mit den entsprechenden Folgen.
Irgendwie passen Bootloader und Treiber nicht zusammen.

Peter Mauß

Peter Mauß

Hallo Markus,
auch bei mir wars wie bei Johannes, Windows 10 erkennt den STM32, trotz installierter Treiber nicht
und zeigt einfach keinen Comport und keine Maple-Devices an.

Johannes

Johannes

Hallo Markus,

leider funktioniert das nicht bei mir. Ich habe alles nach Deiner Anleitung gemacht, alle Treiber installiert und konnte den Bootloader problemlos auf den STM32 laden. Den Jumper habe ich auch entsprechen Deiner Anweisung zurueckgesetzt. Auch habe ich den R10 auf dem Blue Pill Board auf 1,5kOhm geaendert. Leider wird dann nur im Devicemanager nichts angezeigt. Woran kann das liegen? Wuerde mich ueber eine Antwort & Tips freuen.

Viele Gruesse
Johannes

Matthias

Matthias

Wow, hab ich lange versucht aber nie hinbekommen, vielen Dank :-)

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN