Tullio Facchinetti

Porting of a firmware from Arduino to STM32 architecture

by Francesco Carella

Categories: article thesis lang_en article_en


STM32 L152RE Nucleo board

The goal of this work was the porting of EasyScada firmware from the Arduino platform to the STM32 Nucleo board. This work was carried in collaboration with AGEvoluzione, an innovative small-medium company that deals with Internet of Things (IoT) devices.

IoT is a concept related to the fusion of the Internet with physical objects, so that they are able to communicate and exchange data over wireless networks. IoT sensors allow the collection of these data that will be analyzed and processed, in order to make the devices make decisions and perform operations. IoT is used in a wide range of applications such as medical field, home automation, logistics, etc.

Specifically for this work, the activity was done as a part of the development of NORBI, a pill dispenser that helps a patient or a caregiver to manage the scheduling of a prescribed pharmacological therapy. NORBI is composed by 28 cells containing pills, which are automatically dispensed at a predetermined time. It is controlled via a smartphone application and it gives vocal, visual and SMS alerts when the patient has to take the medicines.

The result of the assumption of the pills is notified via WiFi to the associated smartphone.

NORBI

The implementation of NORBI is based on the EasyScada libraries.

EasyScada is a generic automation software written in C++ with the Aduino’s IDE. The original version of the code runs on Arduino platform, but it was improved using an AGEduino board with ATWINC1500 WiFi board.

Afterwards, the code has been ported to the STM32 Nucleo board with the Inventek ISM WiFi board, using the STM32duino extensions, to keep the code compatible with Arduino’s IDE.

The Arduino environment

Arduino is an open-source platform born at Ivrea Interaction design Institute in 2005. It is used to develop a wide range of projects involving different branches of computer science.

It was born to simplify the creation of prototypes for the control of various type of sensors (temperature, brightness, humidity), motors and actuators, but also for the creation of IoT embedded devices.

Arduino board

The Arduino’s IDE contains a text editor to write the code, an area for warnings and error messages, a text console, a series of buttons that perform common functions (such as compiling the code and uploading it to the board) and several menus. There is also a button to be able to display the serial monitor, which is a window in which we can read read the output produced by the board.

High-level firmware description

Every EasyScada device can be seen as a sort of neural network. Every device has 10 channels with the following features:

The communication between channels is managed by the ChannelsHub, that features:

LivingStones Protocol

LivingStones Protocol (LSP) is the communication protocol of EasyScada devices. It is a P2P request/response communication protocol based on UDP. It is used for the communication between EasyScada devices. LSP uses UDP sockets and it is based on exchange of ASCII text messages. Every message is composed by the following elements:

There are four main types of messages:

When a message is correctly received, an appropriate response identifier is received as acknowledgment. The “K” message is a special message used for managing the automatic sending of notifications.

In addition to UDP communication, the LSP protocol added the support for MQTT. MQTT is a lightweight publish/subscribe message transport protocol. In LSP it is used to allow the communication of the channels’ values on the internet, with an only MQTT broker. MQTT is very similar to Observer/Notifier but it is not peer-to-peer (P2P), in fact each device communicates with a broker, not with another equal level device.

MQTT

Boards used during the activity

The project started from the AGEduino board. AGEduino represents an upgrade to the original Arduino platform. It features the ATMEL ATmega1284P processor at 16MHz. It is compatible with Arduino libraries and IDE using the Sanguino extensions. It feature a better memory capability with respect to Arduino: 128KB Flash, 16 KB RAM, 4 KB EEPROM.

Ageduino

Ageduino

Ageduino A model

Ageduino B model

The WiFi board used with AGEduino is the ATWINC 1500-MR210PB, that is a low power consumption 802.11 b/g/n IoT module, specifically optimized for low-power IoT applications. This module provides SPI ports to interface with a host controller.

ATWINC 1500-MR210PB

Then the code has been moved to STM32 L152RE Nucleo board. The STM32 Nucleo board supports Arduino connectivity and it’s a flexible and expandable environment. The processor is the ARM Cortex-M3 32-bit at 32 MHz. It is a better hardware with respect to AGEduino, in particular it features: 512 KB Flash memory and 80 KB RAM.

STM32 L152RE Nucleo pinout
STM32 L152RE Nucleo pinout

The associated WiFi board is the Inventek ISM43362-M3G-L44 board. It is a member of eS-WiFi family of embedded wireless internet connectivity devices. It supports a Cortex-M3 microcomputer. The peculiarity of this board is that it only requires AT commands to establish connectivity with the main device.

ISM43362-M3G-L44 board

Organization of the codebase

The code is organized in two main directories called “AGE_SCADA” and “libraries”. Every operation of the firmware is represented by a Finite State Machine (FSM), and the directory “AGE_SCADA” contains all the files regarding the automata performing the operations. Also it contains the main sketch of the program, into which all the FSMs are enabled.

AGE_SCADA
AGE_SCADA

Instead, the libraries directory contains all the files related to the libraries used in the project, into which the operation performed by the FSMs are defined. The most important libraries are the ones related to the transmission/reception of the messages sent by the EasyScada device’s channels and the managing of the channels functioning and parameters.

libraries

The libraries directory contains also the WiFi drivers, related to the Inventek ISM WiFi board. These drivers have been added to the code instead of the old WiFi drivers related to the ATWINC 1500 WiFi board, used with the AGEduino. In these files, the function related to the WiFi connection and Client/server and UDP functions are defined. To do so, AT commands have been used, as a difference with respect to the old WiFi board.

“STM32Duino_ISM43362-MLG-L44”

Results

As results, some statistics of the git repository into which the project was uploaded were collected using GitStats tool, to see how the porting activity went over time.

The period of time taken into consideration to extrapolate this results goes from the time of creation of the git repository to the end of the porting work, which means from 2017-10-16 to 2021-04-07, but the porting was all carried out in 2021.

Other metrics were collected using the Metrix++ tool, which analyzes different regions in the code and derives several type of data.

These metrics are the Cyclomatic Complexity, the number of lines dedicated to preprocessor, the total number of comments lines, the maximum level of indentation and the total number of magic numbers.

Metrics
Code metrics collected using Metrix++.

Finally, the messages of LSP protocol have been tested using the tool Node-RED. It is a flow-based programming tool that simplifies the creation of applications, making available a list of “nodes” (represented by blocks) that can be dragged and dropped into a web browser grid and connected between them.

The functionalities of the blocks can be tested using a dashboard, into which insert the commands and see the behavior of the blocks.

Node-RED blocks
Node-RED blocks related to the LSP protocol of EasyScada devices.

Node-RED dashboard
Node-RED dashboard into which the commands. are inserted.

Conclusions

The goal of this work was the porting of the EasyScada firmware from AGEduino to STM32 nucleo board, in order to move to a better hardware and to abandon the Arduino environment.

This was just an intermediate step, but it was useful to have a working version of the firmware that could be tested on the final hardware.

A future work will be the migration to STM32CubeIDE, the development tool of STM32, with the code written in pure C++, in order to work with an environment compatible with the ARM processor of the STM32 Nucleo board.


Highlights

  • Publications
  • Students and theses
  • Thesis topics
  • Curated awesome list of CLI apps
  • Last updates (English)

  • Students and theses ()
  • Students and theses - English ()
  • Speed up the compilation of LaTex Beamer presentations ()
  • Learn enough C to survive ()
  • Workflow for writing theses collaboratively ()
  • Guidelines for theses and presentations ()
  • Projects ()
  • Last updates (Italian)

  • Studenti e tesi ()
  • Risultati FdI 27 Settembre 2024 ()
  • Risultati FdI 02 Settembre 2024 ()
  • Risultati FdI 25 Luglio 2024 ()
  • Risultati FdI 26 June 2024 ()
  • Risultati FdI 8 e 11 aprile 2024 ()
  • Risultati FdI 20 Febbraio 2024 ()
  • List of categories

    Article Article_en Article_it C Courses Fdi Lang_en Lang_it Latex Programming Project Research Results Robotics Software Teaching Thesis Tips