STM32 Board – How to Begin and Blink a LED

In this tutorial, I am going to show you how to begin with STM32 microcontroller. It is starting to be a common board in the market as a competitor with Arduino boards, ESP8266, and ESP32. Like so, this tutorial can be a good kickstart for future developments with this board. For now, it would be very simple, but this hardware integrate great capabilities in comparison with his competitors, and it will bring more tutorial in the future.

Parts Required

STM32 Board Overview

Like other boards such as Esp8266, Esp32, and Arduinos, this is not very different from them at all. Then, you may ask why this is different or special in the first place? To show the differences and the capabilities we can start by highlighting the processor.

The STM32 family of microcontrollers is based on the ARM Cortex-M 32-bit processor core. They also have an excellent support base from multiple microcontroller development forums.

The STM32 line is quite expansive with numerous combinations of performance, peripherals, power, memory, and packages available. The datasheet is quite long with way too much information to ever cover in a single post. Don’t worry, we will keep it simple. Instead, we are going to look only at highlights and the microcontroller’s key features. In order to follow along, I suggest downloading the STM32F030 datasheet. Looking to the first page it can be observed the most important specs.

Figure 1

It offers a large number of serial and parallel communication peripherals which can be interfaced with all kinds of electronic components including sensors, displays, cameras, motors, etc. All STM32 variants come with internal Flash memory and RAM. The board also holds two crystal oscillators, one is an 8MHz crystal, and the other is a 32 kHz crystal, which can be used to drive the internal RTC (Real Time Clock). This enables the MCU to operate in deep sleep modes it ideal for battery saver applications. There is also one onboard LED for power and the other is connected to GPIO pin PC13.

Arduino IDE configuration

Thankfully, this board can be programmed using our beloved Arduino IDE. Otherwise, you would need to use an STM IDE tool. There are several ones follow below:

  • STM32CubeMX, a tool to set and graphically program all STM32 boards and products
  • STM32CubeIDE, the free IDE to develop the STM32 software
  • STM32CubeProg, a tool to load/spy software in the STM32 memory
  • STM32CubeL4, an STM32L4 MCU software package with embedded examples

But we will not enter in detail on those, since this is a solution to be used when you don’t have Arduino IDE or other user-friendly developing IDE. This is an out of factory solution. If you want to find more try on STM website. Go go to the simple part.

So, to get started it is needed to add STM32 board library to Arduino IDE so that we can program STM32 using Arduino IDE. So follow the next steps:

Step 1:

In Arduino IDE go to File – Preference and add the link: http://dan.drown.org/stm32duino/package_STM32duino_index.json

Figure 2

Step 2:

Go to Tools – Boards – Board Manager and then type STM32F1 and then install the boards that you get on board manager.

Figure 3

Step 3:

After installation is completed, make the following changes on Board:

Figure 4

Circuit

There are several methods by which you can program STM32 Microcontroller. The most used are:
1. STM32duino Bootloader Method
2. Serial Method
3. By using ST-Link Debugger
But here we will be using the most popular method, the Serial Method also due to its popularity and the no need to acquire an ST-Link Debugger. For this, you need a USB to TTL Converter. The connection diagram between them is given below.

Figure 5

To be able to program this board, we require an FTDI board as indicated previously. So, follow the figure above and connect as such. Have in mind that the TX and RX from the FTDI board pin must be respected. Also, the FTDI board will power STM32 Board with 5V. Attention, VCC and GND must be the 5V ones because the STM32 Microcontroller only works with 3.3V then the voltage must pass through the rectifier.

On STM32 Board you have 2 possible jumper connections bottom one is BOOT 1 & the top one is BOOT 0. For programming, you need to shift the BOOT 0 jumper to make High as shown in the photo below. Do this before any firmware upload.

Figure 6

Code

Now connect USB to TTL converter to your PC. Make sure that the FTDI driver is installed on your PC else, Arduino IDE won’t show the port.

Now you can copy the blink sketch form below and upload it to STM32 Board. This can be done by simply compiling and then uploading. Same as always.

#define LED_BOARD PC13
void setup() {
  // initialize digital pin 13 as LED_BOARD as output.
  pinMode(LED_BOARD, OUTPUT);
}
 
void loop() {
  digitalWrite(LED_BOARD, HIGH);   // Output HIGH 
  delay(1000);                       // wait for a second
  digitalWrite(LED_BOARD, LOW);    // Output LOW
  delay(1000);                       // wait for a second
}

After the upload is completed don’t forget to switch the jumper BOOT 1 to 0 to leave the programming mode and use the firmware in flash memory.

References

https://www.st.com/content/st_com/en/support/learning/stm32-education/stm32-step-by-step.html

https://predictabledesigns.com/introduction-to-programming-stm32-arm-cortex-m-32-bit-microcontrollers/

http://www.emcu.eu/how-to-program-the-stm32/

https://www.digikey.com/en/maker/projects/getting-started-with-stm32-introduction-to-stm32cubeide/6a6c60a670c447abb90fd0fd78008697

https://www.filipeflop.com/blog/como-programar-stm32-em-c/

https://deepbluembedded.com/stm32-arm-programming-tutorials/

https://deepbluembedded.com/stm32-arm-programming-tutorials/

https://www.sgbotic.com/index.php?dispatch=pages.view&page_id=48

https://circuitdigest.com/microcontroller-projects/getting-started-with-stm32-blue-pill-development-board-stm32f103c8-using-arduino-ide

https://predictabledesigns.com/stm32-microcontroller-datasheet-review/

https://alselectro.wordpress.com/tag/stm32-bluepill/

Leave a Reply

Your email address will not be published. Required fields are marked *