Arduino and STM32 Discovery: Xu FENG, Minyi GU, Tianming GUO
Arduino and STM32 Discovery: Xu FENG, Minyi GU, Tianming GUO
and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
Arduino and STM32Discovery
Xu FENG, Minyi GU, Tianming GUO
RICM 4, March April, 2013
1/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
Outline
1 Context
1.1 Arduino
1.2 The Maple project
1.3 STM32 microcontrollers
1.4 Objective of the project
1.5 Tools
1.5.1 STM32F0Discovery board
1.5.2 Arduino UNO board
1.5.3 OpenOCD
1.5.4 ARMNONEEABI
2 Evaluation of the Libmaple
3 Evaluation of the Arduino lib
4 Compilation template
5 Adaption of Arduino IDE for STM32
6 Conclusion
Bibliography
Appendix A
2/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
1 Context
1.1 Arduino
Arduino is an opensource electronics prototyping platform based on flexible, easytouse
hardware and software. Arduino boards are equipped with 2 types of microcontrollers: AVR and
SAM. These microcontrollers are produced by Atmel. Compared to the AVR microcontrollers, SAM
is an ARMbased solution, for example, the microcontroller on the latest Arduino DUE. The Arduino
IDE is an envrionment to program the Arduino boards. Its 1.5.x+ versions which support the Arduino
DUE broad are compatible with CortexM.
1.2 The Maple project
The Maple project, which was launched by MIT, is based on CortexM3 microcontrollers
which have a more powerful computing capability than the older Arduino ones. Maple is offered in an
Arduinocompatible format, complete with Arduino pin layouts and programming environment. Maple
IDE is based on an earlier version of the Arduino IDE. Maple is a great way to get started with an
advanced 32 bitprocessor that, until now, has principally lived in the commercial domain.
1.3 STM32 microcontrollers
STM32 is a family of integrated circuit microcontrollers made by ST Microelectronics, which is
based on the 32bit ARM CortexM4F, CortexM3 and CortexM0 cores.
STM32 Series CPU Core
F3, F4 ARM CortexM4F
F1, F2 ARM CortexM3
F0 ARM CortexM0
Fig 1.1 Correspondence between STM32 and CPU Core
3/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
1.4 Objective of the project
The objective of this project is to simplify the use of STM32 boards by integrating them into the
Arduino IDE. To do this, serveral steps are indispensable.
● Getting familiar with different boards, especially Arduino and STM32.
● Analysis and evaluation of the libmaple library.
● Analysis and evaluation of the Arduino library.
● Development of a compilation template for the STM32 boards.
● Adaption of Arduino IDE for STM32.
1.5 Tools
Serveral tools are avaible and necessary for this project.
1.5.1 STM32F0Discovery board
The STM32F0 serie is the first group of ARM CortexM0 chips in the STM32 family. The
STM32F0Discovery owns two microcontrollers. The bigger one is STM32F051 which is not
connected to the USB port. The smaller one is STM32F103 which owns the USB port, but none of its
IO pins is available. It is basically a builtin programming circuit for the former.
1.5.2 Arduino UNO board
The Arduino UNO board is equipped with an ATmega328 microcontroller. This
microcontroller comes preburned with a bootloader that allows to upload new code to it without the use
of an external hardware programmer.
1.5.3 OpenOCD
1.5.4 ARMNONEEABI (Sourcery CodeBench Lite Edition for ARM processors)
4/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
2 Evaluation of the Libmaple
Libmaple is the library of the Maple project, developed for the STM32 line of ARM
CortexM3 microcontrollers. Libmaple is split into two layers, the lowerlevel layer written in pure C,
called “proper” Libmaple (in the libmaple/ directory of the source repository); the higherlevel layer
written in C++, and the Wiringstyle C++ application programming interfaces written on top of the
former, called Wirish (in wirish/), the interfaces of which are largely compatible with the AVR libraries
written for the Arduino and Wiring development boards.
However, the Libmaple bootloader is designed for the singlechip boards, which is not the case
for the STM32F0Discovery board. The bigger processor STM32F051 which does not have any
bootloader at all on the STM32F0Discovery board is not directly connected to the USB port. It needs
to be reprogrammed externally. The small processor STM32F103 does not really have a bootloader
either. Its own code never changes and it just uploads programs to the bigger one.
A Libmaple branch which was created by Anton has improved the peripheric drivers and the
files in the folder Wirish, and has resolved the problem so that the modified version of Libmaple can
work with STM32VLDiscovery which is a board owning two chips. Unfortunately, Anton has not
changed the fact that Libmaple only supports CortexM3 and does not work with STM32F0. Hence,
the libmaple of Anton can not be adapted directly.
3 Evaluation of the Arduino lib
5/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
The Arduino lib has two important parts, AVR and SAM. AVR is the library for AVR
microcontrollers and SAM for ARMbased microcontrollers. A majority of Arduino boards use AVR
microcontrollers. However the latest products like the Arduino DUE board use ARM CortexM3
microcontrollers. Thus, there is a subfolder CMSIS (Cortex Microcontroller Software Interface
Standard) in the Arduino SAM library folder, which contains supports for the CortexM CPU cores.
CMSIS provides a single standard across all CortexMx processor series vendors, and it enables code
reuse and code sharing across software projects.
The folder CMSIS is the same as the one in the STM32F0 template library. But the device
peripheric drivers of Arduino lib are for the Arduino boards, which are not totally compatible with the
STM32F0Discovery board.
Fig 3.1 below shows a comparison between the peripherics of Arduino, Maple and
STM32F0Discovery boards. The signification of the abbreviations are detailed in Annexe A.
Fig 3.1 Comparison between the peripherics of Arduino, Maple and ST boards
4 Compilation template
6/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
Fig 4.1 General structure of a STM32 compilation template
Device initialization files are usually written in assembler language, libraries and peripheric
drivers in C or C++. In this project, the core libraries are from CMSIS, and the drivers are for the
peripherics of the STM32 boards.
5 Adaption of Arduino IDE for STM32
Fig 5.1 Main interface of Arduino IDE
7/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
Arduino IDE, the IDE for the Arduino boards, is written in Java, using Ant to compile and to
run it. Once a new library folder is added under the hardware folder of Arduino IDE, new items which
shows the boards’ information described in the specification files are immediately added in the menus.
Fig 5.2 below shows the change of the menu after adding the STM32F0Discovery board in the
hardware folder (Fig 5.3).
Fig 5.2 The STM32F0Discovery board is added in Arduino IDE
Fig 5.3 A new folder “st” is added under hardware
8/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
6 Conclusion
The Libmaple works with STM32F1 and STM32F2 series which are ARM CortexM3
microcontrollers. The SAM part of Arduino library is compatible with all ARM CortexM
microcontrollers but the perioheric drivers work only with the Arduino SAM boards. The Arduino IDE
has a builtin editor to edit the program code, but it does not support the ST boards.
To propose a solution, an IDE for the STM32 boards can be an adaption of the Arduino IDE
by adding a modified version of Libmaple to support STM32F1 and STM32F2, OpenOCD to be able
to debug and upload programs to STM32 boards and the peripheric drivers for STM32F0.
9/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
Bibliography
1. Arduino
http://www.arduino.cc/
2. STM32
http://www.st.com/web/en/catalog/mmc/FM141/SC1169
3. A discussion on STM32VLDiscovery in Leaflabs Forum
http://forums.leaflabs.com/topic.php?id=630
4. Sourcery CodeBench
http://www.mentor.com/solutions/arm
5. LeafLabs Documentation
http://leaflabs.com/docs/
6. Libmaple branch created by Anton
https://github.com/anton19286/libmaple
7. Libmaplemaster
https://github.com/leaflabs/libmaple
8. OpenOCD
http://openocd.sourceforge.net/
10/11
Arduino and STM32Discovery Xu FENG, Minyi GU, Tianming GUO
Appendix A
Signification of the peripheric abbreviations :
adc := Analog to Digital Convertor
cec := Consumer Electronics Control
comp := comparators
crc := CRC computation unit peripheral
dac := Digital to Analog Convertor
dbgmcu := Debug MCU peripheral
dma := Direct Memory Access controller
exti := External Interruption
flash := Flash management
gpio := General Purpose Input Output
i2c := InterIntegrated circuit
iwdg := Independent watchdog
misc := addon to CMSIS functions
pwr := Power Controller
rcc := Reset and clock control
rtc := RealTime Clock
spi := Serial peripheral interface
usart := Universal synchronous asynchronous receiver transmitter
wwdg := Window watchdog
11/11