USB to Serial Adapter
Let's learn how to use the Blackpill board as an USB to Serial adapter.
USB to Serial Adapter
When you want to communicate with a microcontroller via USB, you can use an USB to Serial adapter. Since the Blackpill board has an USB port and multiple UART channels, you can use it as an USB to Serial adapter.
Prerequisites
In this tutorial, the following hardware is used:
Blackpill STM32 board
MCU: STM32F411CEU6
Board: WeAct Black Pill V2.0
Schematic
You can purchase a cheap clone Blackpill STM32 board under $4. You can use other STM32 boards, but you need to modify platformio.ini file and the LED pin number.
ST-LINK V2 Programmer
You need this to upload the firmware to the board and debug the code. You can purchase a cheap clone ST-LINK V2 under $5.
Installation
VScode with PlatformIO
You can install PlatformIO from the VSCode extension marketplace.
STM32CubeProgrammer
You need this to flash the firmware to the board.
Clone the repository
git clone https://github.com/yuichiroaoki/stm32-usb-to-serial-adapter.git
cd stm32-usb-to-serial-adapter
Quickstart
-
Connect the Blackpill STM32 board to the ST-LINK V2 programmer.
Connect the ST-LINK V2 programmer to the Blackpill STM32 board as shown in the image above. -
Connect the ST-LINK V2 programmer to your computer.
-
Open the project folder in VSCode.
-
Click on the PlatformIO tab on the left sidebar and click on the
Upload
button to upload the firmware to the board. -
Power off the Blackpill board and connect
PA2
to the target device'sRX
pin andPA3
to the target device'sTX
pin.noteYou need to connnect TX to RX and RX to TX.
-
Connect the Blackpill board to your computer using a USB cable.
That's it! Now you can communicate with the target device using the Blackpill board as an USB to Serial adapter.