PlatformIO Core 6.1 ๐Ÿš€

A professional collaborative platform for declarative and test-driven embedded development

Ivan Kravets
Ivan Kravets
Ph.D., Founder & CEO at PlatformIO Labs
Share:

We are happy to announce the next release of PlatformIO Core with refactored Device Monitor, Pre & Post Actions for library authors, Stringification helpers, and an improved PlatformIO Unit Testing solution for test-driven embedded development.

PlatformIO Core 6.1 ๐Ÿš€

Table of Contents

What is new

In this section, we are going to highlight the most important changes and features introduced in PlatformIO Core 6.1. Please visit PlatformIO Core 6.1 Release Notes for more detailed information.

Device Monitor

Today, it is difficult to imagine modern embedded development without a proper serial port monitor. PlatformIO Core comes with an advanced Device Monitor packed with rich features and supports multiple data sources, including the RFC 2217 remote serial ports and raw sockets.

It is noteworthy that as distinct from the classic serial port monitors, PlatformIOโ€™s Device Monitor allows developers to apply custom filters to the INPUT/OUTPUT streams. The most popular use cases using Device Monitorโ€™s filters are logging data to the physical file, adding timestamps with milliseconds for each new line, showing data in the hexadecimal representation, and decoding crash exceptions. See the list with built-in filters.

Automatic reconnection

Automatic device reconnection was the most requested feature by the PlatformIO Community. PlatformIO Core 6.1 comes with automatic reconnection of the Device Monitor if a connection fails. This feature can be disabled with the pio device monitor --no-reconnect option.

The screencast below demonstrates the usage of the time filter and automatic reconnection:

ANSI escape codes

Another addition to the Device Monitor is the ability to disable encodings and transformations of device output using the --raw option. In this mode, the Device Monitor does not apply any filters and outputs data in the raw format.

A good use case for the raw option is controlling a terminal (cursor location, color, font styling, etc.) using ANSI escape sequences. The example below uses the raw mode and the robtillaart/ANSI library to send ANSI escape sequences from the embedded device.

Build System

Pre & Post Actions

PlatformIO Core 6.1 received significantly improved support for Pre & Post Actions. They can now be used in PRE-type scripts for the targets even if they are not available at the declaration time.

Library authors also can benefit from this new feature. The Pre & Post Actions are now allowed in the extraScript when using the library.json manifest.

library.json:

{
    "name": "Foo",
    "version": "1.0.0",
    "build": {
        "extraScript": "sign-firmware.py"
    }
}

sign-firmware.py:

def post_program_action(source, target, env):
    print("Firmware has been built!")
    program_path = target[0].get_abspath()
    print("Program path", program_path)
    # Use case: sign a firmware, do any manipulations with ELF, etc.
    env.Execute(f"sign --elf {program_path}")

global_env = DefaultEnvironment()
global_env.AddPostAction("$PROGPATH", post_program_action)

Stringification

Passing a macro flag (-D) with a string value to the compiler command has always been a pain. This process requires special escaping of the shell symbols and macro-expansion to the valid C String constant (Stringification) in the source code.

PlatformIO Core 6.1 extends the Build System API with a new env.StringifyMacro(value) helper function that automatically escapes macro arguments. It is very useful for passing dynamic data such as program version, Wi-Fi credentials, or user data (Asking for input (prompts)).

The example below demonstrates how to read a username and pass it as a string using the USER_NAME macro:

platformio.ini:

[env:my_env]
platform = ...
extra_scripts = pre:prompt-user-data.py

prompt-user-data.py:

Import("env")

# Ask user name
print("Enter your name:")
user_name = input()
env.Append(
    CPPDEFINES=[("USER_NAME", env.StringifyMacro(user_name))],
)

Upgrade

  • PlatformIO IDE: Left Sidebar > PlatformIO (icon) > Quick Access > Upgrade PlatformIO Core
  • Terminal: Please run pio upgrade command in terminal.

Stay in touch with us

Stay tuned to this blog or follow us on LinkedIn and Twitter @PlatformIO_Org to keep up to date with the latest news, articles and tips!

Ivan Kravets
Ivan Kravets
Share:

Have questions?

Join the discussion on our forum