Javascript required
Skip to content Skip to sidebar Skip to footer

Com Port Disconnected After Uploading Sketch to Stm32

How to configure STM32 "blue pill" development boards for programming with Arduino IDE. Instructions for Windows and Linux

The "blueish pill" is a STM32F103 based development board. Although it is less pop, the lath is cheaper than the Arduino Nano. More than that, STM32F103 is a device with Cortex-M3 ARM CPU that runs at 72 MHz, 20 kB of RAM and 64 or 128 kB of flash retentiveness. The microcontroller (MCU) has USB port, two serial ports, 16 fleck PWM pins and 12 bit ADC pins. It runs at 3.3V, simply some of its pins are 5V tolerant.

Programming the board can be simplified using the pop Arduino IDE. But earlier this, an Arduino-like bootloader must be flashed to the board. This can be done via series port or using the debug interface of the MCU with ST-Link tool. There are also some pocket-sized hardware bug with Chinese boards that need to be fixed. This post will bear witness a straightforward guide for setting up this board to work with Arduino IDE on Linux and Windows. The instructions below are based on STM32duino wiki [downwards?] documentation.

Of import! In that location is at present an officially developed Arduino STM32 boards package from STMicroelectronics. It is based on HAL and LL libraries. It is recommended to use that one instead. Delight follow instructions from Programme "blue pill" with STM32 Cores in Arduino IDE.

Set up STM32 "blue pill" for Arduino IDE

If you lot decide to utilize ST-Link programmer, there is no need for a bootloader. If you prefer a dissimilar IDE, see here how to develop for STM32 in PlatformIO. You have access to multiple frameworks if you go for PlatformIO.

Hardware issues

STM32duino wiki contributors take reported that some of the boards came with poor soldering of the micro-USB connector. Also some of them have USB D+ pulled up with 4.7 thou or ten g resistors which may cause the USB port non to work on some computers. My board had both these issues. I soldered the USB connector. Fifty-fifty though my computer recognized the USB device and so may yours, I highly recommend pulling upwards D+ with 1.5 1000 if y'all use USB port.

Expect on the dorsum of the board and locate R10. If it's 10 k (marked 103) you can add i.viii one thousand parallel resistor to obtain 1.5 k equivalent resistance. If it's 4.7 k (marked 472), a two.ii k resistor is suitable for parallel connection. Don't worry, you don't have to exercise SMD soldering as D+ is connected to PA12. Just solder the resistor between PA12 and 3.3V pinheader pads.

Another matter that is good to know, is what pin the LED connects to. Depending on this you will choose the correct bootloader.

STM32 Blue pill hardware check

Bluish pill hardware cheque

Go to STM32duino GitHub repo and look for the bootloader. Roger Clark offers many bootloaders for different boards. If your lath has the green LED connected at PC13, you need the bootloader congenital for this configuration: generic_boot20_pc13.bin. Download the bootloader for your board and keep reading.

Arduino IDE

The IDE doesn't come up with default support for STM32 boards. This step is common to all operating systems, so let's do it now. Launch Arduino IDE, become to File - Preferences, and add the following Boards Manager URL:

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

Click OK to close the dialog.

Arduino IDE - add Boards Manager URLs

Arduino IDE - add Boards Managing director URLs

Next, get to Tools - Boards - Boards Manager. In the dialog that appears, search for STM32 and choose STM32F1xx for "blue pill". If your lath uses a different chipset (i.due east. STM32F3) select that 1. Install it.

Arduino IDE, Boards Manager - install new board

Arduino IDE, Boards Managing director - install new lath

Before really uploading sketches to the board via USB port, it needs the STM32duino bootloader. I will be using a ST-Link v2 clone to fire the bootloader. The connection to the evolution lath is straightforward, using SWCLK, SWDIO, GND and three.3V pins. Connect them using the included jumper cables that came with the ST-Link. Do not ability the development board from other source or USB port! Information technology will become its power from the programmer. Correct at present, you can plug the programmer into an USB port and plan the board direct from Arduino IDE using STlink upload method.

If you don't want to use the programmer all the time and prefer to utilise the micro USB port to upload software to board, install the bootloader. I found this method non quite reliable, so I'm uploading sketches straight to flash with ST-Link developer. At the terminate of the post I share some data about information technology. Anyway, y'all may requite information technology a attempt. Move the jumper to set BOOT0 to i. Plug the ST-Link into an USB port. From now on, configuration process is unlike depending on operating organisation.

Windows

Needed tools tin can be found at ST. Y'all need STSW-LINK009 (this is the Windows driver) and STSW-LINK004 (the programming utility). You demand to brand an business relationship to download them. Use the included dpinst tools or the bat script to install the driver. After the driver is installed and the ST-Link adapter is recognized by the computer, install and launch STM32 ST-LINK Utility.

ST-Link Utility

ST-Link Utility

Use the File carte du jour to open the bootloader bin file you downloaded earlier. Next, connect to programmer (use the plug icon on the primary toolbar, or Target - Connect) then cull Erase and Program choice from the same menu. The bootloader will be burned to MCU Flash memory.

Downloading bootloader

Downloading bootloader

While the bootloader is downloading to MCU, you lot will see the programmer LED flashing. When it is done, y'all can disconnect the lath from programmer, change back BOOT0 to 0 and connect it using board's USB. Of course, it needs Windows drivers which can be found in the Arduino_STM32 package prepared by Roger Clark. You don't need to download the entire repository merely for the drivers. About of the files independent in this repository were automatically downloaded by Arduino IDE when y'all added the lath support (but not the driver). Here is a commuter only archive. Excerpt it and run install_drivers script. When you reset the lath, for a curt moment of fourth dimension while bootloader is running, it appears as DFU device, then switches to serial port.

Linux

ST offers no GUI tools to program the lath from Linux. But, when you downloaded the board with Arduino IDE, you too downloaded the tools to program the board using ST-Link adapter. In your home folder, open hidden .arduino15 binder (nautilus ~/.arduino15). Browse to packages/stm32duino/tools/stm32tools. Here you will find a folder named similar the STM32 package version (i.eastward. 2017.11.14). Open it, then linux subfolder. There should be an install.sh script here. Run it from terminal with root permissions (sudo ./install.sh). You just installed udev rules for ST-Link and board. It is now recommended to log off then back in or restart computer.

Open up again ~/.arduino15/packages/stm32duino/tools/stm32tools/2017.11.14/linux, become to stlink folder. Make sure BOOT0 is set to 1 and run ./st-info --probe. You should see something similar this:

Found one stlink programmers  serial: 573f... openocd: "\x57\x3f\x..."   flash: 131072 (pagesize: 1024)    sram: 20480  chipid: 0x0410   descr: F1 Medium-density device

This is an indication that everything is OK and you can continue burning the bootloader with the post-obit command:

./st-flash --reset write ~/Desktop/generic_boot20_pc13.bin 0x8000000

Arrange the command with the correct path to bootloader file. Here is the output of this command:

2017-eleven-19T12:32:28 INFO src/common.c: Loading device parameters.... 2017-11-19T12:32:28 INFO src/common.c: Device connected is: F1 Medium-density device, id 0x20036410 2017-11-19T12:32:28 INFO src/common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes 2017-xi-19T12:32:28 INFO src/mutual.c: Attempting to write 21140 (0x5294) bytes to stm32 address: 134217728 (0x8000000) Wink page at addr: 0x08005000 erased 2017-eleven-19T12:32:29 INFO src/common.c: Finished erasing 21 pages of 1024 (0x400) bytes 2017-11-19T12:32:29 INFO src/common.c: Starting Wink write for VL/F0/F3 core id 2017-11-19T12:32:29 INFO src/common.c: Successfully loaded wink loader in sram  20/twenty pages written 2017-11-19T12:32:31 INFO src/common.c: Starting verification of write consummate 2017-xi-19T12:32:31 INFO src/mutual.c: Wink written and verified! jolly adept!

That's it. Disconnect the developer, move BOOT0 back to 0 and connect the board using its USB port.

Hither is what happens when you reset (plug in) the board. Outset the DFU device appears then the USB series port (/dev/ttyACM0).

[ 1146.407442] usb 7-1: USB disconnect, device number two [ 1172.671329] usb vii-1: new total-speed USB device number 3 using uhci_hcd [ 1173.058344] usb 7-1: New USB device institute, idVendor=1eaf, idProduct=0003 [ 1173.058347] usb 7-ane: New USB device strings: Mfr=one, Product=ii, SerialNumber=3 [ 1173.058349] usb vii-1: Product: Maple 003 [ 1173.058351] usb vii-1: Manufacturer: LeafLabs [ 1173.058352] usb 7-1: SerialNumber: LLM 003 [ 1173.687380] usb vii-1: USB disconnect, device number 3 [ 1174.407316] usb 7-1: new total-speed USB device number four using uhci_hcd [ 1174.587353] usb seven-i: New USB device found, idVendor=1eaf, idProduct=0004 [ 1174.587357] usb vii-1: New USB device strings: Mfr=1, Product=two, SerialNumber=0 [ 1174.587359] usb 7-i: Product: Maple [ 1174.587361] usb vii-1: Manufacturer: LeafLabs [ 1174.628070] cdc_acm seven-1:1.0: ttyACM0: USB ACM device [ 1174.629510] usbcore: registered new interface commuter cdc_acm [ 1174.629513] cdc_acm: USB Abstract Control Model commuter for USB modems and ISDN adapters

Sketches are uploaded while in DFU fashion (device 1eaf:0003).

Uploading a sketch

Launch the IDE and choose the lath. For a generic "blueish pill", here is the default configuration:

STM32 Generic board in Arduino IDE

STM32 Generic board in Arduino IDE

On Windows, only the port is different (COMx). Open up a sample sketch and compile information technology. From my feel, on Windows you can just press Upload push button to reset the board and burn the sketch binary. But, on Linux I had no luck with automatic reset. I make sure the sketch is compiled then I reset the lath by pushing the button and I click quickly on Upload button in Arduino IDE. Otherwise, uploading fails.

This is the output in Arduino IDE:

Sketch uses 13028 bytes (ix%) of program storage space. Maximum is 131072 bytes. Global variables use 2824 bytes (xiii%) of dynamic retentiveness, leaving 17656 bytes for local variables. Maximum is 20480 bytes. No valid DFU suffix signature Alarm: File has no DFU suffix dfu-util 0.7  Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc. Copyright 2010-2012 Tormod Volden and Stefan Schmidt This program is Gratuitous Software and has ABSOLUTELY NO WARRANTY Please report bugs to dfu-util@lists.gnumonks.org  Filter on vendor = 0x1eaf product = 0x0003 Opening DFU capable USB device... ID 1eaf:0003 Run-fourth dimension device DFU version 0110 Found DFU: [1eaf:0003] devnum=0, cfg=1, intf=0, alt=ii, proper noun="STM32duino bootloader v1.0  Upload to Flash 0x8002000" Claiming USB DFU Interface... Setting Alternate Setting #two ... Determining device status: country = dfuIDLE, condition = 0 dfuIDLE, continuing DFU way device DFU version 0110 Device returned transfer size 1024 bytes_per_hash=260 Copying data from PC to DFU device Starting download: [##################################################] finished! state(eight) = dfuMANIFEST-WAIT-RESET, status(0) = No mistake status is nowadays Done! Resetting USB to switch dorsum to runtime way Waiting for /dev/ttyACM0 series...Washed

If dfu-util reports no DFU devices, you didn't reset the board at the right time. This ways sketch was non uploaded to board. The Linux issues seems to be related to commuter implementation because shortly afterward a failed upload (without reset), dmesg reports a failure to set dtr/rts on ttyACM0.

Without bootloader

If this method of uploading a sketch (using the bootloader) is a pain, there are alternatives. I regularly use the ST-Link programmer to upload Arduino sketches to bluish pill. No need to manually reset the lath, no need to movement jumpers. Uploading is faster on Linux than on Windows (I don't know why).

On very rare occasions uploading fails. In this state of affairs I have to motion BOOT0 jumper to 1 and upload the sketch. Binaries practise non run when BOOT0 is fix to 1 therefore I move information technology back. There are besides very rare occasions when blue pill does not reset afterwards upload. I accept to push the reset push button.

Configure blue pill in Arduino for ST-Link

Configure blueish pill in Arduino IDE for ST-Link

Programming port of the blueish pill has only 3.3V supply. This can be regarded every bit a adept thing, because 5V won't be bachelor on 5V pin so you tin be sure you won't supply 5V to a not tolerant pin. But, if you fit the bluish pill on the breadboard it's easy to become a 5V supply line from ST-Link using a jumper wire (if yous actually need it).

Using Arduino IDE with STM32duino bootloader to program the "blueish pill" development board isn't the nearly constructive way to develop STM32 based systems, only information technology's easier than with other development kits. It's recommended to read the API differences and accept a look at examples if you will utilise this method.

croftsthearced70.blogspot.com

Source: https://www.onetransistor.eu/2017/11/stm32-bluepill-arduino-ide.html