“Machine learning, and TinyML in particular, has the potential to revolutionize the way embedded systems are designed and built. Traditionally, these systems used programming algorithms based on the developer’s experience with the system. Machine learning brings a different approach where system algorithms are based on observations and data from the real world. If the environmental data changes, the machine learning model can quickly use the data to relearn. Human-coded solutions need to be rewritten.
Author: Jacob Beningo
Machine learning, and TinyML in particular, has the potential to revolutionize the way embedded systems are designed and built. Traditionally, these systems used programming algorithms based on the developer’s experience with the system. Machine learning brings a different approach where system algorithms are based on observations and data from the real world. If the environmental data changes, the machine learning model can quickly use the data to relearn. Human-coded solutions need to be rewritten.
This article will explore machine learning platforms and tools for embedded systems powered by STMicroelectronics’ STM32 microcontroller family.
Machine learning support for the STM32 microcontroller family
Machine learning can be a powerful tool for embedded system developers. However, developers often believe that machine learning algorithms require too much processing power, or that the algorithms are too large to fit into a typical microcontroller. In reality, the microcontroller chosen will depend more on what one wants to do with machine learning than how a particular microcontroller supports machine learning.
For example, Figure 1 shows a family of STM32 microcontrollers that support machine learning. These microcontrollers range from the STM32F0, which runs at 48 MHz with up to 256 KB of flash and 32 KB of RAM, to the STM32F7, which runs at 216 MHz with up to 2 MB of flash and 512 KB of RAM.
Figure 1: Machine learning enabled by STM32 microcontrollers using STM32Cube.AI and NanoEdge development tools. (Image credit: STMicroelectronics)
As we know, there are quite a few microcontrollers that can support machine learning. The real problem is that a machine learning platform must smoothly support a wide range of developers. For example, it is not common for embedded software teams to have a machine learning expert. Instead, embedded software developers are forced to master machine learning in addition to their traditional skills. Therefore, a platform is needed to support teams with or without machine learning experts. The toolchain of the STM32 machine learning ecosystem helps to solve this problem.
Helping embedded teams without machine learning experts
To be sure, designing and training machine learning algorithms can seem like a daunting task. Developers need to be able to acquire data, design models, train models, and then make sure the models are good enough for optimization and deploy them into embedded systems.
Traditionally, machine learning models are created with TensorFlow Lite, PyTorch, Matlab, or other tools. These tools are often far beyond the comfort zone or experience of embedded software developers. Mastering these tools and getting accurate results is time-consuming and expensive.
The STM32 machine learning ecosystem includes a tool called NanoEdge (Figure 2) that helps developers without machine learning expertise or experience to train and deploy machine learning applications on their devices.
For example, developers can easily create machine learning libraries for applications such as anomaly detection, outlier detection, classification, and regression. These libraries can then be deployed on STM32 microcontrollers.
Figure 2: NanoEdge guides developers through the entire machine learning development process. (Image credit: STMicroelectronics)
What about embedded teams with machine learning experts?
When a development team can turn to a machine learning expert, they get more tools to develop machine learning models for STM32 microcontrollers. For example, when the expertise is available, the development team can use TensorFlow Lite, PyTorch, Matlab, or some other tool to model. A frequent problem is that these tools produce unoptimized libraries. Such libraries do not run efficiently on microcontrollers.
In the STM32 series, developers can use the STM32Cube.AI plugin to import machine learning models and optimize them to run efficiently on STM32 microcontrollers. The tool allows developers to run and tune their machine learning models on target microcontrollers. First, developers can import their models into the toolchain, as shown in Figure 3. They can then transform the model, analyze the network, and then validate it. Once this is done, developers can generate code within STM32CubeIDE to create a machine learning framework around the model to simplify embedded software development.
Figure 3: The sine wave generator machine learning model is imported into STM32CubeIDE.AI. (Image credit: Beningo Embedded Group)
Embedded software developers must provide appropriate input to the machine learning model, as well as check the resulting code. The results can be manipulated, averaged, or manipulated in any way that makes sense for the application. Figure 4 shows a simple apply loop for running and checking model results.
Figure 4: The main loop revolves around the machine learning model. (Image credit: Beningo Embedded Group)
Driven by TinyML, machine learning is being incorporated into embedded applications in a proper way. To be successful, developers need to leverage a platform. While it appears that platform options are popping up almost every day, the STM32 ecosystem provides developers with an easy and scalable solution path.
In this ecosystem, developers with machine learning experience can leverage their traditional tools and use the STM32CubeIDE.AI plugin to optimize and tune solutions. For teams without machine learning expertise, NanoEdge can simplify the development of machine learning libraries and get solutions up and running quickly and cost-effectively.