As some friends have said, Arduino is more like a framework. Various development boards and IDEs are trying to be compatible with Arduino’s syntax. For example, in the previous article “How to Use Visual Studio Code to Develop Arduino”, it is quite suitable for professional programmers who are already accustomed to Visual Studio and VS Code to get started with Arduino. Moreover, this compatibility between different platform products is also beneficial for those who start exploring the electronic world with Arduino to enter more professional fields.A friend commented asking us to introduce how to develop STM32 series development boards using Arduino. I believe many people will be interested, so let’s arrange an introduction.What are the differences between Arduino and STM32?To be precise, what we usually refer to as Arduino includes Arduino development boards, Arduino IDE (Integrated Development Environment), and Arduino syntax.STM32 refers to the microcontrollers/development boards based on the ARM Cortex-M series from STMicroelectronics. There are many types of STM32 series chips, and the performance of STM32 chips at the same price point can generally outperform the ATMEL ATMEGA chips used by Arduino, as most of them are still 8-bit microcontrollers while STM32 is 32-bit.
There are many types of IDEs for STM32, with professional ones like IAR and ARM Keil being much more complex than Arduino IDE. The syntax used for developing STM32 is relatively pure C/C++. STM32 is aimed at more professional electronic engineers and stable product-level development, and the entry barrier for developers is higher than that of Arduino.
The above factors often also start the disdain chain, some playing STM32 think Arduino is too toy-like, with poor performance, and most Arduino users are non-electronic major “amateurs”. In fact, the positioning of the two is completely different, and there is no absolute better or worse. For example, although Arduino’s performance is not high, it encapsulates and simplifies many low-level hardware drivers, allowing non-professionals to implement an electronic prototype with just some logical judgments and data processing. While STM32 is more professional, it is also more complex. For example, often to light up an LED, various initialization and clock configuration operations are required.So can we use Arduino IDE to develop STM32 boards? This way we can take advantage of the simplicity and convenience of Arduino syntax and libraries while utilizing the performance of the STM32 platform? The answer is of course yes.Leaflabs and MapleDon’t rush, let’s talk about some history. In the history of connecting Arduino and STM32 platforms, we must mention Leaflabs and Maple (Maple board). Leaflabs (https://www.leaflabs.com) is a company founded by some MIT students, and they were the first to attempt to combine Arduino and STM32. Maple (Maple board) was the first minimal system based on STM32 compatible with Arduino they launched in 2009.
Leaflabs borrowed Arduino’s syntax and libraries, but replaced the underlying compiler from AVR-GCC to ARM-GCC, and encapsulated a libmaple library to translate Arduino interfaces and STM32’s low-level interfaces.In 2015, after launching the Maple Mini board, Leaflabs unfortunately announced that it would no longer maintain the libmaple library, leaving it to the open-source community to continue its legacy.
https://github.com/leaflabs/libmaple
Arduino_STM32The legacy of libmaple has not ended. Developer Roger Clark and contributors from the open-source community launched the Arduino_STM32 project. Arduino_STM32 continues to expand support for STM32 series chips based on libmaple and maintains compatibility with the latest Arduino IDE boards, with a very active community.
After searching around, I found that most tutorials on using Arduino with STM32 in China are basically based on Arduino_STM32. So next, I will take everyone through the practice of how to use Arduino_STM32.Practice SectionBefore the practice, we need a STM32 development board or a minimal system. Here I recommend the BluePill based on the STM32F103C8T6 chip, which costs about 10 yuan on Taobao.
First, we need to understand several important positions on the STM32 minimal system board.
Choosing the startup mode, the BluePill board has two yellow jump caps representing BOOT0 and BOOT1. Each cap can choose 0 (LOW) or 1 (HIGH), and the high and low of these two pins are used to configure where the development board starts after power on.
For normal startup, we generally choose BOOT0 as 0, BOOT1 can be arbitrary. When we need to burn the program via serial, we need to set BOOT0 to 1 and BOOT1 to 0, then press the reset key, so that we can start the BootLoader from the system memory.Another thing to note is that the USB port on the BluePill cannot be used directly for serial programming. According to the diagram, you need an additional serial TTL downloader, with the RX connected to the PA9 pin of the BluePill and the TX connected to the PA10 pin. Then connect the downloader’s USB to the computer.
Installing Arduino_STM32
Download Arduino_STM32-master.zip from the Arduino_STM32 GitHub homepage, unzip and rename it, copy it to C:\Users\Username\Documents\Arduino\hardware folder. If there is no hardware folder, create one, as shown in the figure below.
Open the Arduino IDE, click Tools->Board->Board Manager->Search for SAM. Install the configuration files corresponding to the development board. The BluePill is STM32F103, so we choose to install Cortex-M3.
After installing the corresponding files, you can see many STM32 development boards in Tools->Board . We choose Generic STM32F103C series.
We choose the Blink LED example.
Select the upload method as Serial, then select the correct COM port, press the Reset button on the BluePill board, and then click upload.
If the upload is successful, the PC13 LED on the BluePill board will start blinking.
At this point, you can start developing STM32 boards just like you would with Arduino boards. Although Arduino_STM32 still has many unsupported libraries and bugs, it is compatible with most Arduino libraries and the STM32 platform.
Due to space limitations, we have divided “How to Use Arduino IDE to Develop STM32” into two parts. In the next part, we will introduce another project jointly produced by the stm32duino community and STM official that allows Arduino to develop STM32 – Arduino_Core_STM32, while practically comparing it with Arduino_STM32. Thank you for reading, and if you like my article, feel free to follow us and share. See you in the next part!
Arduino Electronics Books and Video Tutorials Acquisition Method
Do you also want a copy of our kit’s attached Arduino Electronics Books and various Video Tutorials?
Scan the QR code below to follow, reply “Benefits“
Click to read the original text, buy the Arduino Beginner’s Learning Kit