PlatformIO — Every Embedded Developer Should Use It

Barak Menachem
Embedded IoT
Published in
6 min readApr 13, 2021

Feel free to contact me on any subject: BarakMenachem@gmail.com
Download This Article as PDF >>>

It all started with the same story, you are an embedded developer, you have to manage your project with many different aspects:

  • Find a compatible IDE.
  • Choose a great debugger tool for your MCU.
  • Create a new project with your favorite framework.
  • Make sure that each of the solutions you found is a Cross-Platform solution (for thus teams that use Linux and Windows).
  • more…

Any embedded developer can agree with the fact that in any new project, with some new requirements he does all of this process repeatedly…

The Perfect Framework for Embedded Developers

What is PlatformIO? Who Use it?

(1) PlatformIO is a professional collaborative platform for embedded development.

Let’s start with some numbers that will make you understand that you must have to continue reading this article:

  • More than 1,572,314 installs of the PlatformIO framework.
  • Supported by worldwide embedded companies&projects, such as:
    ARMmbed, Atmel, ST, SiliconLabs, Intel, WesternDigital, Microchip, and more.
  • Supports 24 Platforms include: ZephyrProject, Mbed, CubeMX, FreeRTOS, more.
  • 5K start on git — for compression ZephyrProject has 4.4K start, MbedOS has 3.7K start.
PlatformIO Professional development environment for various companies

As you can see, PlatformIO is highly used by the top embedded engineers in the world. To help you decide better if you should give it a try, let's find out what is the main features of it:

Top 5 PlatformIO Features That Makes Your Life Much Easier

/* cant wait to see how to work with these features? go to our full PlatformIO tutorial. */

  1. Creating full template projects from various embedded frameworks like Zephyr, Mbed, etc…, with only a few mouse clicks on VSCode! (yes, it supports VSCode >>>).
  2. Such a great debugger with the following main features:
    Local, Global, and Static Variable Explorer
    - Conditional Breakpoints
    - Expressions and Watchpoints
    - Generic Registers
    - Peripheral Registers
    - Memory Viewer
    - Disassembly
    - Multi-thread support
    - A hot restart of an active debugging session
  3. PlatformIO understands C++ even better than you! It adds two important features to VSCode:
    - C/C++ Intelligent Code Completion
    - C/C++ Smart Code Linter for rapid professional development
  4. 100 percent of RAM usage? but how? — Extensive User Interface that allows you to get full memory project inspection with separation of RAM, Flash, and Defects. each of these has an internal separation of sections, symbols, and more.

Things to Worry About

  1. I tried to use the “lvgl/lvgl@8.0.0” which should help you to build UI on embedded screens. After installation using the following environment:
    - Board: NUCLEO_H743ZI
    - IDE: VSCode + PlatformIO Extention
    - Framework: ZephyrRTOS
    - Desktop OS: Windows10
    It failed to compile this library, according to some issues, it may cause because I'm using windows instead of Linux.
  2. PlatformIO currently didn't support the following:
    - Flex Gecko, not supported at all(but other Gecko versions are supported like Leopard Gecko, Wonder Gecko, etc.).
    Note: you can always submit an issue with a request to add a board that you want, it looks like the PlatformIO team answer pretty fast.
  3. Cloning of libraries — I tried to use NanoPB, it works fine, but the generator script was a miss in the folder so I had to download it separately by myself in order to generate the .pb.h/.c files.
  4. There are still some bugs when creating a new project/adding new libraries.

Simple PlatformIO Tutorial

Step 1 — Install PlatformIO

Step 1 — Install PlatformIO

Online installation:
Go to your VSCode extension page, and search for “PlatformIO” — install it.

Offline installation:
PlatformIO is an OpenSource project, so you can easily install it on your private network and use it:

  1. Follow some instructions from the PlatformIO community:
    https://community.platformio.org/t/platformio-cli-and-ide-bundle-for-offline-installation/308/6
  2. Or you can try other solutions from this issue or try to use Portable VSC/Platformio/Python for Windows

Step 2— Create New Project

Step 2 — Create New Project
  1. Click on the PlatformIO extension.
  2. Choose “PIO Home > Open”.
  3. Choose “New Project”.

Step 3 — Config Your New Project

Step 3 — Config Your New Project

Here you can select your board and your framework. In our case, we will use “Nucleo H743ZI” and ZephyrOS as a Framework.
* Note: if you want to use a board that does not exist in the list, you will need to ask it from the PlatformIO team, or try to figure out how to do it by yourself.

Step 4— Add Library to Your Project

In PlatformIO it's very easy to handle the process of adding libraries to your project, all you have to do is to go to “PlatformIO Extention Icon > PIO Home > Libraries”.

On the Libraries Page, you can determine three main features that may help you in the future:

1 — Recently added libraries, which allows you to stay updated on what`s new in the IoT market:

Recently added libraries

2 — Quick search by tags, it can be very helpful in some cases that you want to look for an existing solution for some Sensors, for example, then all you have to do is to filter the libraries using the “Popular Tags” feature.

Quick search by tags

3 — Be the First to Know About New Trends, using the “Trending” section, you can know what is the most trending libraries that people use around the world. You can see the most trending libraries of the Day, Week, and Month.

Be the First to Know About New Trends

Now, lest looking for the NanoPB library, and adding it to our project.
for this purpose search for the following “framework:zephyr nanopb”, click on the library and click on “Add to Project”

Any library that added to your project will be available under
“your-project/.pio/libdeps/nucleo_h743zi/Nanopb”.

Step 5— Generate file.pb.h & file.pb.c

One of the problems in embedded projects is to add new libraries, every time you want to add a library you need to start dealing with CMakes, Kconfigs and etc.
In PlatformIO you only need to add your library under the “your-project/lib” folder! Thus, we will create a folder that will contain all of our auto-generated code:

Note: to generate .pb.h pb.c files run the command, after installing protobuf from git:
“protoc nanopb_out=./lib/autogen/ src/simple.proto proto_path=./lib/autogen/”

[code snippet created using “carbon”]

Now, without any hard work, we can easily start using it in our code!

Now you can start creating your IoT solutions much faster and easier without wasting time on the configuration and compilation process.

Step 6— Code & Memory Inspection

You can use PlatformIO to sort and find the part of the code that needs the most memory in Flash or RAM.

I'm inviting you to send us articles about embedded and IoT and we will make sure everyone will read them! Thanks!
Send us your articles or any other ideas to: BarakMenachem@gmail.com

--

--