Skip to content

Instantly share code, notes, and snippets.

@hexeguitar
Created November 23, 2022 19:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexeguitar/f4533bc697c956ac1245b6843e2ef438 to your computer and use it in GitHub Desktop.
Save hexeguitar/f4533bc697c956ac1245b6843e2ef438 to your computer and use it in GitHub Desktop.

Using pioasm in platformio projects

Here is somethig you might find useful: automatic pio assembly -> h file generation for platformio.
I have tested it on Linux only.

This is the state as of Nov 2022. The arduino core for RP2040 will most likely change in the future and make this method obsolete.

Step 1:

Contrary to the docs, stating the pioasm is installed together with the dev platform:
https://registry.platformio.org/tools/earlephilhower/tool-pioasm-rp2040-earlephilhower/installation
the json file
https://github.com/maxgerhardt/platform-raspberrypi/blob/develop/platform.json
does not include the picoasm tool, i had to install it manually using the terminal command:

pio pkg install -g --tool "earlephilhower/tool-pioasm-rp2040-earlephilhower@^5.100300.220714"

Maybe it's correct for the arduino environment only.

Step 2:

add the package in the platformio.ini file:

platform_packages = earlephilhower/tool-pioasm-rp2040-earlephilhower

Step3:

We are going to create a python script searching for any .pio files in the project src directory and converting them to compiled header files.
Add the following to the platformio.ini file:

extra_scripts = pre:scripts/pioasm.py

This tells the platformio to execute that script before building the firmware.

Step 4:

Create a new dir called "scripts" in your project's root dir and copy the following pioasm.py file into it:

"""
Custom pioasm compiler script for platformio.
(c) 2022 by P.Z.

"""
from os.path import join
import glob
import sys
Import("env")

platform = env.PioPlatform()
PROJ_SRC = env["PROJECT_SRC_DIR"]
PIO_FILES = glob.glob(join(PROJ_SRC, '*.pio'), recursive=True)

if PIO_FILES:
    print("==============================================")
    print('PIO ASSEMBLY COMPILER')
    try:
        PIOASM_DIR = platform.get_package_dir("tool-pioasm-rp2040-earlephilhower")
    except:
        print("tool-pioasm-rp2040-earlephilhower not found!")
        print("please install it using the following command:")
        print("pio pkg install -g --tool \"earlephilhower/tool-pioasm-rp2040-earlephilhower@^5.100300.220714\"")
        sys.exit()

    PIOASM_EXE = join(PIOASM_DIR, "pioasm")
    print("pio files found:")
    for filename in PIO_FILES:
        env.Execute(PIOASM_EXE + f' -o c-sdk {filename} {filename}.h')
    print("==============================================")

The project folder structure after succesful build looks like this (using the apa102.pio driver as example):

├── include
│   └── README
├── lib
│   └── README
├── platformio.ini
├── scripts
│   └── pioasm.py
├── src
│   ├── apa102.pio
│   ├── apa102.pio.h
│   └── main.cpp
└── test
    └── README

My full platformio.ini file looks like this :

[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
build_flags = -DUSE_TINYUSB
monitor_speed = 115200
extra_scripts = pre:scripts/pioasm.py
platform_packages = earlephilhower/tool-pioasm-rp2040-earlephilhower

Building a project automatically converts the .pio files into compiled .pio.h ones, which can be included in the rest of the firmware.

Processing pico (platform: https://github.com/maxgerhardt/platform-raspberrypi.git; board: pico; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
==============================================
PIO ASSEMBLY COMPILER
pio files found:
/home/user/.platformio/packages/tool-pioasm-rp2040-earlephilhower/pioasm -o c-sdk /home/user/Projects/Software/arm/RPi_Pico/MIDI2EXP/src/apa102.pio /home/user/Projects/Software/arm/RPi_Pico/MIDI2EXP/src/apa102.pio.h
==============================================
CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/pico.html
PLATFORM: Raspberry Pi RP2040 (1.7.0+sha.bd485fe) > Raspberry Pi Pico
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment