Programming STM32F103C8 Board using USB Port (2023)

TheSTM32Development Board housing theSTM32F103C8Microcontroller is getting increasingly popular thanks to its ARM Cortex M3 architecture, it has high operational speed and more peripheral options. Also since, this board can be easilyprogrammedusing theArduinoIDE it has become a preferable choice for many hobbyists and engineers for quick prototyping.

In our previous tutorial we learnt thebasics of theSTM32Development Boardand alsoprogrammedit to blink an LED. But there was one huge drawback with it. In order to program the Board weutilisedaFTDIprogrammer module and also had to toggle the boot 0 jumper between and 1 position while uploading and testing a code, which is surely a daunting task. Also the mini-USB port on the Development board was left totally unused. The reason for doing that is, when theSTM32development board is purchasedit does not come with anArduinoready boot loaderand hence the board will not be discovered by your computer when connected through the USB.

Hopefully though, there exists an experimental boot loader developed byLeafLabsfor Maple mini boards. This boot loader can be flashed into theSTM32once and thereafter we can directly use the USB port of theSTM32board to upload programs just like any otherArduinoboards. However this boot loader is still in developmental stage at the time of documenting this tutorial and is not advisable for critical applications. Before proceedings with this tutorial make sure you have read theprevious tutorialto understand the basics of this board including details about the specifications and pin-outs.

Materials Required

  • STM32– (BluePill) Development Board (STM32F103C8)
  • FTDIProgrammer
  • Breadboard
  • Connecting wires
  • Laptop with Internet

Circuit Diagram

To program theSTM32Blue Pill board directly through USB portwe need to first flash the Maple boot loader into theMCU. To do this we need to use a SerialFTDIboard. This board is connected to the Rx and Tx pin of theSTM32as shown below.

Programming STM32F103C8 Board using USB Port (1)

TheVccpin of theFTDIboard is connected to theSTM325V pin of power the board. The ground is connected to the Ground ofSTM32. The Rx and Tx pin of theFTDIboard is connected to the A9 andA10pin of theSTM32respectively. Where the A9 is the Tx pin ofSTM32MCUand theA10is Rx pin.

Programming STM32F103C8 Board using USB Port (2)

Make sure the boot 0 jumper pin on the board is set to 1 (programming mode) while uploading the boot loader. Once the boot loader is flashed this pin can be changed back to initial position (operating mode).

Programming STM32F103C8 Board using USB Port (3)

Uploading the Maple Boot loader toSTM32Development board

Once we have made the above connection connect theFTDIboard to your computer and follow the steps to flash the boot loader into theSTM32.

Step 1:We have to download the boot loader program file binaries (bin file) form the github page. There are many versions of bin file, for the Blue Pill board use thisgithub linkand click on the download button to download the bin file.

(Video) STM32 Bootloader | Programming STM32F103C via USB Port

Step 2:Next we have to download and install theSTMFlash loader software to flash the downloaded bin file intoSTM32. Click onthis linkto get into the ST website and scroll to the bottom and click on get software

Programming STM32F103C8 Board using USB Port (4)

Step 3: To download the software you have to enter your E-mail address and the download link will be sent to your E-mail. Then follow the link back to the website and click on get software again and you download will begin. Yes it’s a bit frustrating but this is how it should be done. Don’t forget to check your spam folder for the E-mail, sometimes it takes a couple of minutes for the E-mail to arrive.

Step 4: Once downloaded install the software, make sure yourSTM32board is connect to your computer thoughFTDIboard and then launch the software. The software will automatically detect the COM port if not use the Device manager and make sure you select the correct COM port number. In my case it isCOM4. Leave the rest of the setting as it is as shown below.

Programming STM32F103C8 Board using USB Port (5)

Step 5:Click on the Next button twice and the software will again automatically detect the board details and display as shown below. The board we are using isSTM32F1with128Kflash memory.

Programming STM32F103C8 Board using USB Port (6)

Step 6:In the next step, select Download to device and browse to the location where we downloaded our bin file in step 1 and select it. Click on next.

Programming STM32F103C8 Board using USB Port (7)

Step 7:The software will download some required files as shown below and will then begin the process of flashing.

Programming STM32F103C8 Board using USB Port (8)

(Video) STM32 Bootloader, STM32F103C Programming using USB Port, STM32 LED Blinking, STM32 for beginners

Step 8:Once the flashing is completes successfully, we will get the below screen. Click on close and exit the application. We have flashed theSTM32board withArduinoboot loader successfully. Now we have to prepare theArduinoIDE and install the drivers before we can program theSTM32board.

Programming STM32F103C8 Board using USB Port (9)

Preparing theArduinoIDE and Installing the Drivers

Follow the below steps to download and prepare theArduinoIDE to be used with theSTM32 Development board.

Step 1:- If you have not yet installed theArduinoIDE, download and install it fromthis link. Make sure you select your correct operating system.

Step 2:- After Installing theArduinoIDE open and download the required packages for theSTM32board. This can be done by selectingFile -> Preferences.

Step 3:- Clicking on Preferences will open the below shown dialog box. In the additional Boards Manager URL text box paste the below link

http://dan.drown.org/stm32duino/package_STM32duino_index.json

and press OK.

Step 4:- Now go toTool -> Boards -> Board Manager. This will open the Boards manager dialog box, search for “STM32F1” and install the package that appears.

Step 5:After the package is installed, navigate to C:\Program Files (x86)\Arduino\hardware\Arduino_STM32-master\drivers\win where you will findinstall_drivers.batandinstall_STM_COM_drivers.bat.

(Video) Programming STM32 directly though USB port using Arduino

Step 6:Click on both the bat files and install the drivers. You will get a DOS screen as shown below.

Programming STM32F103C8 Board using USB Port (11)

Programming STM32F103C8 Board using USB Port (12)

Now theArduinoIDE is prepared for programmingSTM32(Blue Pill) Development Board and the drivers are also installed.

ProgrammingSTM32(Blue Pill) Directly Through USB Port

Remove theFTDIboard and all the existing connections from youSTM32. Just use the micro-USB port on theSTM32board to connect it to the computer as shown below. Make sure thejumper 0 pin is positioned back at 0(Operating mode). Hereafter we need not toggle the jumper anymore to upload and run the programs.

Programming STM32F103C8 Board using USB Port (13)

You computer should be able to discover the Board now. Wait for a while if you see any additional drivers getting installed. Then get intoDevice managerand check if yourSTM32board is discovered under the COM and port section as shown below. Mine is connected toCOM8with the name Maple Mini.

Programming STM32F103C8 Board using USB Port (14)

Go toToolsand scroll down to find the GenericSTM32F103Cseries as shown below. Then make sure the variant is64kFlash type, CPU speed is72MHzand change the upload method toSTM32duinoBootloader. Also select the correct COM port according to the one on your device manager.

Programming STM32F103C8 Board using USB Port (15)

After all the changes are made, check the bottom right corner of theArduinoIDE and you should notice the following setting being set. MySTM32board is connected toCOM8but yours might differ

(Video) Custom USB HID Interface using STM32 (stm32f103c8)

Programming STM32F103C8 Board using USB Port (16)

Now theArduinoIDE is ready to program theSTM32 Blue Pill Development Boards. Let us upload the Sample Blink Program from theArduinoIDE to theSTM32Blue Pill board to make sure everything is working properly. The example program can be found at

Programming STM32F103C8 Board using USB Port (17)

In the example program that opens,we have to make a small change. By default the program will be written forPB1but on our board the on-board LED is connected toPC13so replace allPB1withPC13and we are good to proceed. Thecomplete example programwhich is modified can also be found at the bottom of this page.

The code inside theloopfunction alone is shown below, where we can notice that thePC13pin is kept HIGH (on) for 1000 millisecond and then turned LOW (off) for another 1000 millisecond and this is done for infinite times since it is inloopfunction. Thus the LED appears to be blinking with an interval of 1000 millisecond.

digitalWrite(PC13, HIGH); // turn the LED on (HIGH is the voltage level)delay(1000); // wait for a seconddigitalWrite(PC13, LOW); // turn the LED off by making the voltage lowdelay(1000); // wait for a second

Press the upload button on theArduinoIDE and your program should get compiled and uploaded. If everything has worked as expected then you should see the following on yourArduinoIDE console.

Programming STM32F103C8 Board using USB Port (18)

If the Program has been uploaded successfully then you should see the Green LED blinking at a 1 second interval as shown in thevideobelow. You can also fiddle around with the program to increase or decrease the delay. Now you can start using theSTM32(Blue Pill) Development board like any otherArduinoboards, that is you no longer need not change the position of jumpers or use external hardware to upload and test programs.

Programming STM32F103C8 Board using USB Port (19)

Hope you understood the tutorial and found it useful toget started withSTM32Board. If you have any problem leave them in the comment section, also tell me what projects we should try with thisSTM32board in future.

Videos

1. Programming STM32 Board Blue Pill using native USB Port
(IOTES)
2. STM32 Send and Receive Data to PC without UART || USB COM PORT || Bluepill
(Controllers Tech)
3. STM32 USB CDC HOST and DEVICE || Communicate using USB || HAL
(Controllers Tech)
4. STM32 Bootloader | Programming STM32 using usb cable | Flashing bootloader in STM32 | Arduino IDE
(electronic GURU)
5. STM32 USB CDC (Virtual Com Port) with CubeMX HAL in 6 minutes
(chiptron)
6. 64. STM32F103C8T6 USB to MySQL database through Node JS ( Virtual Com Port )
(MicroPeta by Nizar Mohideen)
Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated: 12/12/2022

Views: 5931

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.