DEV Community

Cover image for Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program
Shilleh
Shilleh

Posted on • Edited on

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill using the Arduino IDE and a DSD TECH SH-U09C5 USB to TTL converter. The STM32 Blue Pill is a powerful yet affordable microcontroller board based on the STM32F103C8T6 ARM Cortex-M3 processor. Known for its robustness and versatility, the Blue Pill is an excellent choice for hobbyists, makers, and professionals alike who are looking to harness the power of 32-bit ARM architecture in their projects.

Why the STM32 Blue Pill?

The STM32 Blue Pill offers an impressive set of features at a fraction of the cost of similar microcontrollers. With a 72 MHz clock speed, 20 KB of RAM, and 64 KB of flash memory, it outperforms many 8-bit microcontrollers, making it suitable for more demanding applications such as real-time data processing, motor control, and advanced sensor integration. Its wide range of peripherals, including SPI, I2C, USART, and ADC, allows for seamless interfacing with various components, sensors, and modules.

Additionally, the STM32 Blue Pill is well-supported by the open-source community, with a variety of development environments available, including the Arduino IDE. This makes it accessible even to those who are familiar with Arduino but want to step up to more advanced hardware.

Why Use a USB to TTL Converter?

Unlike many Arduino boards, the STM32 Blue Pill does not come with a built-in USB-to-serial converter, which is typically used for uploading code and debugging. Instead, the board is equipped with UART (Universal Asynchronous Receiver-Transmitter) pins that require an external converter to communicate with your computer. The DSD TECH SH-U09C5 USB to TTL converter acts as a bridge between your computer’s USB port and the UART pins on the Blue Pill, allowing you to upload code, monitor serial output, and debug your programs. This converter is an essential tool in working with the STM32 Blue Pill, enabling seamless communication between the board and your development environment.

Image description

Get Started with a Pre-Soldered Board

For those looking to dive straight into development without the hassle of soldering, you can purchase pre-soldered STM32 Blue Pill boards at Shillehtek. These boards come ready to use, so you can focus on building your projects right away.

— — -

Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:

  • Subscribe to our YouTube Channel: Stay updated with our latest tutorials and project insights by subscribing to our channel at YouTube — Shilleh.
  • Support Us: Your support is invaluable. Consider buying me a coffee at Buy Me A Coffee to help us continue creating quality content.
  • Hire Expert IoT Services: For personalized assistance with your IoT projects, hire me on UpWork.

ShillehTek Website (Exclusive Discounts):

https://shillehtek.com/collections/all

ShillehTekAmazon Store:

ShillehTek Amazon Store — US

ShillehTek Amazon Store — Canada

ShillehTek Amazon Store — Japan

Step 1: Connect the STM32 Blue Pill to the USB to TTL Converter

To start, you’ll need to connect your STM32 Blue Pill to your computer using the DSD TECH SH-U09C5 USB to TTL converter. This converter will allow your computer to communicate with the STM32 Blue Pill via its UART interface.

Image description

Wiring Setup:

  • RXD (SH-U09C5) -> PA9 (RX on Blue Pill)
  • TXD (SH-U09C5) -> PA10 (TX on Blue Pill)
  • GND (SH-U09C5) -> GND (Blue Pill)
  • VCC (SH-U09C5) -> 3.3V (Blue Pill)

Set the BOOT0 Jumper:
Set the BOOT0 jumper on the Blue Pill to the 1 position (this puts the Blue Pill into UART bootloader mode). See diagram below for bootloader mode.

Image description

Make sure to plug the TTL converter into power, you can simply plug it into your computer if it has a USB port!

Step 2: Install STM32 Support in Arduino IDE

Before you can program the STM32 Blue Pill in the Arduino IDE, you need to install support for STM32 boards.

Step 1: Open Arduino IDE Preferences

  • Open the Arduino IDE.
  • Go to File > Preferences.

Step 2: Add STM32 Board Manager URL
In the “Additional Boards Manager URLs” field, add the following URL:

https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json

Click OK.

Image description

Step 3: Install STM32 Boards

  • Go to Tools > Board > Boards Manager.
  • Search for STM32 and click Install next to the “STM32 MCU based boards” package.

Step 3: Select the STM32 Blue Pill Board in Arduino IDE

After installing STM32 support, you’ll need to configure the Arduino IDE to use the correct settings for your STM32 Blue Pill.

Step 1: Select the Board

  • Go to Tools > Board > STM32 Boards and select Generic STM32F1 series.

Step 2: Configure Board Settings

  • Under Tools > Board Part Number, select BluePill F103C8 (or BluePill F103CB if you have the 128KB flash version).
  • Set the Upload Method to STM32CubeProgrammer (Serial).
  • Set the Port to the port associated with the device.

Step 4: Install STM32CubeProgrammer

STM32CubeProgrammer is required for uploading code to the STM32 Blue Pill via the serial interface.

Step 1: Download and Install STM32CubeProgrammer

  • Download STM32CubeProgrammer from STMicroelectronics.
  • Make sure you create a free account if you have not.
  • Install it on your system following the on-screen instructions. It has downloads for different operating systems.

Step 2: Set the Environment Variable

Open a terminal and add the STM32CubeProgrammer path to the STM32_PRG_PATH environment variable.

For macOS, add the following line to your ~/.zshrc or ~/.bash_profile file:

export STM32_PRG_PATH=/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin

Apply the changes by running:

source ~/.zshrc

or

source ~/.bash_profile

For Windows:

  • Open the Start Menu and search for “Environment Variables.”
  • Select “Edit the system environment variables” from the search results.
  • In the System Properties window, click on the “Environment Variables” button.
  • Under “System variables” (or “User variables” if you prefer), click on “New.”

Variable Name: STM32_PRG_PATH
Variable Value: The path to the STM32CubeProgrammer bin directory, such as:
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin

Click “OK” to save the new environment variable.

Close the Environment Variables and System Properties windows.

Step 5: Upload Your First Program

Now that everything is set up, you’re ready to upload your first program to the STM32 Blue Pill.

Step 1: Write the Code

Open a new sketch in Arduino IDE and write a simple program. Here’s an example that prints a message to the Serial Monitor:

void setup() {
  // Start the Serial communication at 9600 baud
  Serial.begin(9600);

  // Wait for the serial port to connect (necessary for some boards)
  while (!Serial) {
    ; // Wait
  }
}

void loop() {
  // Print a message to the Serial Monitor
  Serial.println("Hello, Blue Pill!");

  // Wait for 1 second
  delay(1000);
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Reset the Blue Pill

Before clicking the upload button in Arduino IDE, press the Reset button on the Blue Pill board. This ensures that the board is ready to receive the program.

Step 3: Upload the Code

  • Click the Upload button in Arduino IDE.
  • After the upload completes you will see the onboard LED blink on intervals. If you want to upload another script you can hit the reset button and modify the script and upload again!

Troubleshooting

  • If you encounter issues with uploading:
  • Ensure the correct port is selected.
  • Check your wiring and jumper settings.
  • Verify that the STM32_PRG_PATH environment variable is correctly set.
  • Ensure your board is authentic, like the board from STM32 ShillehTek Amazon Store. The board comes pre-soldered as well.

Conclusion

Congratulations! You’ve successfully set up and programmed your STM32 Blue Pill using the Arduino IDE and the DSD TECH SH-U09C5 USB to TTL converter. This powerful microcontroller opens up a world of possibilities for your projects, offering the performance of a 32-bit ARM Cortex-M3 processor at an affordable price. Whether you’re a beginner or an experienced developer, the STM32 Blue Pill is a versatile tool that can help you bring your ideas to life.

If you found this tutorial helpful, be sure to check out more content on my YouTube channel, where I regularly share tips, tutorials, and project ideas to help you get the most out of your development boards and microcontrollers. Don’t forget to subscribe at MM Shilleh on YouTube to stay updated with the latest videos. Good luck with your projects!

Top comments (0)