Cross-board and cross-vendor embedded development with PlatformIO

Atmel

The original version of my article “Cross-board and cross-vendor embedded development with PlatformIO” which has been published by Atmel Staff in their blog.

We live in time when a wall between hobbyist and micro controller world has been completely broken. Just a few years ago nobody has imagined that MCUs could have become popular with people who are not familiar with electronics. Nowadays, you don’t need to have deep knowledge in PCB design, assembly language or become buried under MCU application notes to get your first experience with embedded world.

Moreover, vendors have realized that there is a need to decrease entrance threshold and to propose alternatives to existing professional development kits. It was the point where popular prototype boards (such as Arduino) were born. Comfortable board form-factor, rich peripheral and huge community of enthusiasts gave rise to a new trend, which can be called “Embedded board for everybody”.

Still, there is a problem related to programming instruments. It’s excellent that MCU vendors have spent a lot of efforts to create rich HDKs/SDKs and comfortable IDEs which allow to perform hardware debugging/tracing. However, all of these features are of interest mostly for people who have already decided which specific MCU they will use for the project. So, at this point the market has generated another demand: to make cross-MCU development easy. On this way, Arduino and Arduino community have played an important part: cross platform Processing-based Arduino IDE, simple and easy to use Wiring-based Framework with high level API, incredible count of shields (sensors, actuators etc.), and a lot of different libraries which cover significant part of hobbyist tasks, have made embedded development much easier. However, while Arduino allows development for different MCUs, it is a commercial product, so it is inherently restricted to Arduino boards.

Saving time for the task in hand

Today, it doesn’t come as a big surprise, when an interesting embedded project is invented by people who had not have professional experience with MCUs earlier. I feel that this phenomenon can be explained with my motto: “Creativity comes from talent and never from knowledge”. Talented people, people with ideas are interested in quick prototype instruments which don’t require big efforts to use them. Many of these people prefer to concentrate on the task in hand, and don’t want to install too much of additional software, play with confused manual or get used to new additional IDE… So far so good, as many of vendor IDEs do address these issues.

However, what if, for your next project, you need some board or MCU which aren’t supported by your favorite vendor? With devices becoming smaller, wireless, and battery-powered, this happens more and more frequently. Then, all of a sudden, you have a problem: development platforms from the different vendors tend to recommend their own IDEs and approaches. As a result, you’re likely to have several IDEs installed, each with its own requirements (to make things worse, these requirements sometimes conflict with each other), and with an ongoing switching back and forth. Ouch. All of this quickly becomes a major headache, and ironically, headache is exactly what these development platforms aim to avoid.

Developer, meet PlatformIO. PlatformIO, meet developer

Here is where PlatformIO comes in – an open source cross platform code builder and library manager (available on GitHub at https://github.com/ivankravets/platformio). After many months of development, we have finally released PlatformIO 1.0 which has been recommended for production using.

I admit that, as one of the authors behind PlatformIO, I cannot be 100% objective when speaking about it, but I’ll try.

PlatformIO allows to:

  • Decide which operation system you want to run development process on (you can even use one OS at home, and another one at work)
  • Choose which editor to use for writing the code (it can be pretty simple editor or powerful favourite IDE)
  • Focus on the code development, significantly simplifying support for the different development platforms, boards and MCUs.

Cross platform code builder

PlatformIO: Cross platform code builder

PlatformIO is independent from the platform where it is running (the only requirement is Python, which exists pretty much everywhere). It means that PlatformIO projects can be easily moved from one computer to another. It also means that PlatformIO allows easy sharing of the projects between team members, regardless of operating system they prefer to work with. In addition, PlatformIO can be run not only on commonly used desktops/laptops but also on the servers without X Window System. While PlatformIO itself is a console application, it can be used together with one’s favourite IDE or text editor such as, for instance, Arduino IDE, Eclipse, Visual Studio, Vim, Sublime Text.
Ok, so PlatformIO can run on different operating systems. But probably more important from development perspective is a list of supported boards and MCUs. To keep things short:

PlatformIO supports over 100 embedded boards
(including all boards which are supported by Arduino IDE)
It also supports all major development platforms
(including Atmel AVR, Atmel SAM, TI MSP430, STM32, and many others).

How it works

Without going too deep into PlatformIO implementation details, work cycle of the project developed using PlatformIO looks as follows:

  • choose board(s) you’re interested in project configuration file – “platformio.ini”
  • based on this list of boards, PlatformIO downloads required toolchains and installs them automagically
  • you develop your code and PlatformIO makes sure that it is compiled for, prepared for, and uploaded to all the boards you’re interested in.

Cross-board Code and Continuous Integration

As it has already been mentioned above, PlatformIO supports cross-board code development: multiple boards can be selected in a single project, and PlatformIO will apply all respective environments and will compile the code against each of boards within the project. And as an icing on the cake, this feature can be easy integrated with Continuous Integration System (such Jenkins, Travis CI, Circle CI ). It should help to ensure that at any point in time, your code at least compiles on all target boards, eliminating costly, time-consuming, and error-prone process of fixing these cross-platform issues at later stages (read: “right before release”), when your team members have already forgotten what this code was about.

The Missing Library Manager

PlatformIO: The Missing Library Manager

With an overall trend towards open source, embedded development is not an exception. There are lots of embedded libraries available out there – such as high level communication with sensors, actuators, or even full-fledged IoT implementations. However, every time you need something like it, there is a Big Question – where to finding this specific library, and how to make it work with your environment.

To address this problem, PlatformIO Library Manager provides an eco-system for library writers and library users. Using library manifest file (“library.json”), writers have an ability to describe library. This manifest is not only about such things as authors, description, keywords, and version, but first and foremost about technical information, such as location of source code and examples, CVS repository, dependencies, and include/ignore code rules. This manifest file is generic enough to be used by other library managers (if somebody want to write them).

For the library users (a.k.a. developers), PlatformIO provides 2 ways for looking for libraries. The first way is via Command Line Interface, the second one is Web 2.0 Library Search (http://platformio.org/#lib) with functionality such as library categories, different framework and platform filters, advanced search syntax with boolean operations.

PlatformIO Library Manager can be integrated into the most popular IDEs and extend their functionality, including all-important automated updates of installed libraries. For example, for Arduino IDE benefits of using PlatformIO Library Manager are summarized in the following table:

Manager / Operation Install Uninstall Search Update Own libraries
per project
PlatfomIO Yes Yes Yes (CLI + WEB) Yes Yes
Arduino IDE Yes** you should have already downloaded library archive No** only manual deletion of the library folder) No No No

Conclusion

As noted above, as an author, I cannot be objective when speaking about PlatformIO. However, I am sure that for any kind of cross-board and cross-MCU development PlatformIO provides substantial benefits. PlatformIO takes the hassle of installing all the tool chains you need, and allows to build your code for many boards with a single command. PlatformIO Library Manager not only helps you to find and install libraries, but also has an option to keep them up to date.

And as PlatformIO is an open-source project, you shouldn’t care about price or vendor lock-in. So, what are you waiting for? Give it a try (and if you don’t like it, you’ll get back that zero bucks you’ve paid for it, some restrictions apply, batteries not included).