stm32f103c8 on platformio with serial FTDI, simple blink test

This is about testing an stm32f103c8 on platformio with a blink program.

Connect the STM32F to theFTDI usb to serial interface

Connect the STM32F to the computer with an FTDI usb to serial interface.

 

STM32F ###### FTDI

PIN A09 (TX) – PIN RX

PIN A10 (RX)-PIN TX

PIN 5V -PIN VCC

PIN G -PIN GND

 

Create a new project in the platformio IDE

Go to the platformio main screen by clicking the home icon on bottom toolbar.

Click in the New Project button

In the popup dialog:

insert the the project name

Select the board, STM32F103C8 (type some letters to filter the available boards)

Select the framework, Arduino (some boards have more than one framework to select, the STM32F have a few)

It will create a folder, with required sub folders, and main files in the file system

Its done, lets code.

Software to blink internal LED on stm32f103c8

Enter the following code in the src/main.cpp file (available on project explorer)

main.cpp

#include 

#ifndef LED_BUILTIN
  #define LED_BUILTIN PC13
#endif

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);
  // wait for a second
  delay(1000);
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);
   // wait for a second
  delay(1000);
}

Platformio project configuration

The wizard create a config file, platformio.ini, with basic configuration for the selected board and framework.

We then need to configure the project to use the right programmer method.

To program using an FTDI usb to serial interface add the following line, in the platformio.ini

upload_protocol = serial

platformio.ini

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = serial

Compile and upload the project

Assure that the jumper in boot0, is in the position 1, and reboot the MCU.

In the bottom tool bar click in the right arrow.

->

Output sample:

Processing bluepill_f103c8 (platform: ststm32; board: bluepill_f103c8; framework: arduino)
—————————————————————————————————————————————————————————-
Verbose mode can be enabled via `-v, –verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/bluepill_f103c8.html
PLATFORM: ST STM32 (13.0.0) > BluePill F103C8
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash

(…)

Wrote address 0x08002600 (95.15%)
Wrote address 0x08002700 (97.65%)
Wrote address 0x080027f0 (100.00%) Done.

Starting execution at address 0x08000000… done.

======================================================================= [SUCCESS] Took 7.34 seconds =======================================================================

Terminal will be reused by tasks, press any key to close it.

As soon as you confirm that is working good, in order to use the microcontroller as usual, don’t forget to place the jumper in boot0 in the position 0.