Maker.io main logo

PlatformIO Advanced Features for Code Debugging and Version Control

2022-09-21 | By Maker.io Staff

Another recent article explored how hobbyists and more advanced software developers can quickly get started using PlatformIO, a VS Code-based IDE, with their favorite embedded development board. However, that article only summarized a few of the more advanced features the plugin offers. Therefore, this article investigates some of those features in more detail. Further, it also explains how beginners and more experienced users can benefit from using them in their everyday embedded projects.

Advanced Debugging Features

Debugging is widely implemented in most major integrated development environments (IDEs). However, some programs, such as the Arduino IDE, omit debugging support to make the program more accessible to new users. Unfortunately, the missing debugger often frustrates more experienced users, who need to look for alternative methods to work around this limitation.

PlatformIO natively supports debugging many development boards (around 300 models across multiple chip manufacturers, platforms, architectures, and languages) without requiring users to write a single line of configuration or debugging code. In addition, the debugger supports features such as conditional breakpoints, viewing register and memory values, multi-thread support, and a variable explorer for local, global, and static variables. Only a few official Arduino boards (such as the Nano 33 IoT, the Nano 33 BLE, Nano 33 BLE Sense, and the MKR range of devices) expose the necessary debug headers. Further, the process still requires using a compatible JTAG debug probe.

Unit Testing Arduino Programs for Greater Reliability

Unit-testing is another method commonly used when developing more extensive programs, and it is one of three primary testing techniques that help engineers boost the reliability of their programs. Using this technique, developers test modules of their program in isolation to determine whether the software correctly returns the expected results when given a set of predetermined input values. How developers split their programs into modules sometimes depends on the context. However, categorizing each class as a module is often a good approach.

PlatformIO Advanced Features for Code Debugging and Version Control PlatformIO uses a convenient test framework to run unit test cases. This image shows the result of executing such a test.

Regardless of the exact module size, PlatformIO allows developers to add test cases to their Arduino programs without modifying the embedded application itself. For that purpose, PlatformIO uses a unit testing framework called Unity, which includes all the features developers would expect from similar frameworks, such as JUnit. PlatformIO allows developers to run tests locally on their PCs, directly on the target hardware, or remotely.

Detect Potential Problems Early On With Static Code Analysis

Static Code Analysis may sound complicated initially, but it's a great tool that helps developers detect and iron out common errors in their programs that may later lead to severe problems. As its name implies, the static analysis doesn't require any code execution. Instead, developers configure their IDEs to look for potential problems, such as possible array out-of-bounds errors and styling issues, for example, overly long variable and method names.

Besides finding potential problems and code quality issues, the static code analysis within PlatformIO can also summarize how much memory the program will use, and which variables significantly impact the application's memory footprint.

PlatformIO Advanced Features for Code Debugging and Version Control This image shows how the variables in the program impact the application’s memory footprint.

Version Control and Continuous Integration

Developers can also benefit from tracking their projects using a version control system like git. Doing so allows them to create backups of their programs, track changes in their code, revert recent changes should they become a problem, and release program snapshots. All these aspects become especially important when working with other developers in a team.

Finally, a continuous integration (CI) solution helps software engineers automate all the tasks discussed in this article. These systems perform various tasks automatically whenever certain conditions are met, for example, daily at a specified time or whenever a developer changes a file tracked in the version control system. By automating these tasks, developers are free to concentrate on programming rather than worry about running tests, static code analysis, and other duties, such as fixing code formatting issues. For that purpose, PlatformIO supports various CI/CD solutions, such as CircleCI, Drone, GitLab, GitHub Actions, Jenkins, and TravisCI.

Summary

While PlatformIO makes it easier than ever before for beginners to get started with embedded development, the multi-platform Visual Studio Code extension also offers a few features that benefit more advanced users.

Advanced debugging features help engineers track down bugs in their embedded applications. PlatformIO supports over 300 boards across different manufacturers and platforms, and the IDE takes care of all underlying details and the configuration, turning embedded debugging into a plug-and-play experience.

Static code analysis and unit-testing capabilities help engineers significantly improve their programs' reliability and quality by pointing out errors and potential problems in their code before they make it into production.

Finally, version control support allows engineers to track changes in their embedded projects, which is not only helpful when working solo. Out-of-the-box CI/CD support ties all these advanced features together, automating the tedious tasks so that the system performs them whenever a particular condition is met, for example, once every day at midnight.

制造商零件编号 ABX00027
ARDUINO NANO 33 IOT
Arduino
制造商零件编号 ABX00032
ARDUINO NANO 33 IOT WITH HEADERS
Arduino
制造商零件编号 ABX00034
ARDUINO NANO 33 BLE WITH HEADERS
Arduino
制造商零件编号 ABX00031
ARDUINO NANO 33 BLE SENSE
Arduino
制造商零件编号 ABX00035
ARDUINO NANO 33 BLE SENSE W/ HDR
Arduino
制造商零件编号 ABX00012
ARDUINO MKR ZERO W/ HDR ATSAMD21
Arduino
制造商零件编号 ABX00045
PORTENTA H7 LITE
Arduino
制造商零件编号 ABX00042
PORTENTA H7
Arduino
制造商零件编号 ABX00019
ARDUINO MKR NB 1500
Arduino
制造商零件编号 ABX00023
ARDUINO MKR WIFI 1010
Arduino
制造商零件编号 ABX00029
MKR WAN 1310 W/O ANTENNA
Arduino
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum