From 14896b64196a11de67b344b222bee92117e954a5 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 8 Jul 2025 19:12:59 -0500 Subject: [PATCH 1/2] add pioasm --version, and print version number in generated files --- .../include/hardware/pio_instructions.h | 4 ++++ test/kitchen_sink/CMakeLists.txt | 4 ++++ test/kitchen_sink/trivial.pio | 3 +++ tools/Findpioasm.cmake | 1 + tools/pioasm/CMakeLists.txt | 8 ++++++- tools/pioasm/ada_output.cpp | 6 +++++- tools/pioasm/c_sdk_output.cpp | 6 +++++- tools/pioasm/go_output.cpp | 8 +++++-- tools/pioasm/main.cpp | 5 +++++ tools/pioasm/python_output.cpp | 6 ++++-- tools/pioasm/test/amethyst.pio | 21 ++++++++++++++++++- tools/pioasm/version.h.in | 16 ++++++++++++++ 12 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 test/kitchen_sink/trivial.pio create mode 100644 tools/pioasm/version.h.in diff --git a/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h b/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h index 671145606..2b5ff238a 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h @@ -18,6 +18,10 @@ * parameters. * * For fuller descriptions of the instructions in question see the "RP2040 Datasheet" + * + * NOTE: These are helper functions for the raw instruction encoding, and thus + * only provide support for pins numbered 0-31. You should adjust your encoding + * according to your expected GPIO_BASE (see \ref pio_set_gpio_base) */ // PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_PIO_INSTRUCTIONS, Enable/disable assertions in the PIO instructions, type=bool, default=0, group=pio_instructions diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index afc77e553..60d97fd06 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -105,6 +105,10 @@ pico_set_program_name(kitchen_sink "Wombat tentacles") pico_add_extra_outputs(kitchen_sink) target_compile_definitions(kitchen_sink PRIVATE KITCHEN_SINK_ID="regular binary") +if (TARGET hardware_pio) + pico_generate_pio_header(kitchen_sink ${CMAKE_CURRENT_LIST_DIR}/trivial.pio) +endif() + add_executable(kitchen_sink_extra_stdio ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) if (COMMAND suppress_tinyusb_warnings) # Explicitly suppress warnings in TinyUSB files which have them (this has to be done diff --git a/test/kitchen_sink/trivial.pio b/test/kitchen_sink/trivial.pio new file mode 100644 index 000000000..933f28ae4 --- /dev/null +++ b/test/kitchen_sink/trivial.pio @@ -0,0 +1,3 @@ +.program trivial + +out pins, 1 \ No newline at end of file diff --git a/tools/Findpioasm.cmake b/tools/Findpioasm.cmake index a5a547671..11cf44fcf 100644 --- a/tools/Findpioasm.cmake +++ b/tools/Findpioasm.cmake @@ -34,6 +34,7 @@ if (NOT TARGET pioasm) "-DCMAKE_RULE_MESSAGES=OFF" # quieten the build "-DCMAKE_INSTALL_MESSAGE=NEVER" # quieten the install CMAKE_CACHE_ARGS "-DPIOASM_EXTRA_SOURCE_FILES:STRING=${PIOASM_EXTRA_SOURCE_FILES}" + "-DPIOASM_VERSION_STRING:STRING=${PICO_SDK_VERSION_STRING}" BUILD_ALWAYS 1 # force dependency checking EXCLUDE_FROM_ALL TRUE ) diff --git a/tools/pioasm/CMakeLists.txt b/tools/pioasm/CMakeLists.txt index a7698cd81..dcca23860 100644 --- a/tools/pioasm/CMakeLists.txt +++ b/tools/pioasm/CMakeLists.txt @@ -41,7 +41,13 @@ if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND target_compile_options(pioasm PRIVATE -Wno-psabi) endif() -target_include_directories(pioasm PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/gen) +if (NOT PIOASM_VERSION_STRING) + message(FATAL_ERROR "PIOASM_VERSION_STRING must be provided when building pioasm") +endif() + +configure_file( ${CMAKE_CURRENT_LIST_DIR}/version.h.in ${CMAKE_BINARY_DIR}/version.h) + +target_include_directories(pioasm PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/gen ${CMAKE_BINARY_DIR}) if (MSVC OR (WIN32 AND NOT MINGW AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))) diff --git a/tools/pioasm/ada_output.cpp b/tools/pioasm/ada_output.cpp index c0f59a151..94197e676 100644 --- a/tools/pioasm/ada_output.cpp +++ b/tools/pioasm/ada_output.cpp @@ -13,8 +13,10 @@ #include #include +#include #include "output_format.h" #include "pio_disassembler.h" +#include "version.h" struct ada_output : public output_format { struct factory { @@ -97,7 +99,9 @@ struct ada_output : public output_format { FILE *out = open_single_output(destination); if (!out) return 1; - header(out, "This file is autogenerated by pioasm; do not edit!", 0); + std::stringstream header_string; + header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!"; + header(out, header_string.str(), 0); fprintf(out, "pragma Style_Checks (Off);\n\n"); fprintf(out, "with RP.PIO;\n\n"); diff --git a/tools/pioasm/c_sdk_output.cpp b/tools/pioasm/c_sdk_output.cpp index d62d47c35..156d3e71c 100644 --- a/tools/pioasm/c_sdk_output.cpp +++ b/tools/pioasm/c_sdk_output.cpp @@ -6,8 +6,10 @@ #include #include +#include #include "output_format.h" #include "pio_disassembler.h" +#include "version.h" struct c_sdk_output : public output_format { struct factory { @@ -66,7 +68,9 @@ struct c_sdk_output : public output_format { FILE *out = open_single_output(destination); if (!out) return 1; - header(out, "This file is autogenerated by pioasm; do not edit!"); + std::stringstream header_string; + header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!"; + header(out, header_string.str()); fprintf(out, "#pragma once\n"); fprintf(out, "\n"); diff --git a/tools/pioasm/go_output.cpp b/tools/pioasm/go_output.cpp index b1748d77a..10f4c5af9 100644 --- a/tools/pioasm/go_output.cpp +++ b/tools/pioasm/go_output.cpp @@ -14,8 +14,10 @@ #include #include +#include #include "output_format.h" #include "pio_disassembler.h" +#include "version.h" struct go_output : public output_format { struct factory { @@ -63,8 +65,10 @@ struct go_output : public output_format { FILE *out = open_single_output(destination); if (!out) return 1; - header(out, "Code generated by pioasm; DO NOT EDIT."); - + std::stringstream header_string; + header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!"; + header(out, header_string.str()); + // First we give priority to user's code blocks since // 1. In Go our imports always precede our code. // 2. We give users the freedom to use their own PIO implementation. diff --git a/tools/pioasm/main.cpp b/tools/pioasm/main.cpp index f5d678535..04e6f9987 100644 --- a/tools/pioasm/main.cpp +++ b/tools/pioasm/main.cpp @@ -6,6 +6,7 @@ #include #include "pio_assembler.h" +#include "version.h" #define DEFAULT_OUTPUT_FORMAT "c-sdk" @@ -24,6 +25,7 @@ void usage() { } std::cerr << " -p add a parameter to be passed to the output format generator" << std::endl; std::cerr << " -v specify the default PIO version (0 or 1)" << std::endl; + std::cerr << " --version print pioasm version information" << std::endl; std::cerr << " -?, --help print this help and exit\n"; } @@ -66,6 +68,9 @@ int main(int argc, char *argv[]) { } else if (argv[i] == std::string("-?") || argv[i] == std::string("--help")) { usage(); return 1; + } else if (argv[i] == std::string("--version")) { + std::cout << "pioasm version: " << PIOASM_VERSION_STRING << std::endl; + return 0; } else { std::cerr << "error: unknown option " << argv[i] << std::endl; res = 1; diff --git a/tools/pioasm/python_output.cpp b/tools/pioasm/python_output.cpp index f4cf326bd..080b90442 100644 --- a/tools/pioasm/python_output.cpp +++ b/tools/pioasm/python_output.cpp @@ -8,9 +8,9 @@ #include #include #include -#include #include "output_format.h" #include "pio_disassembler.h" +#include "version.h" struct python_output : public output_format { struct factory { @@ -61,7 +61,9 @@ struct python_output : public output_format { FILE *out = open_single_output(destination); if (!out) return 1; - header(out, "This file is autogenerated by pioasm; do not edit!"); + std::stringstream header_string; + header_string << "This file is autogenerated by pioasm version " << PIOASM_VERSION_STRING << "; do not edit!"; + header(out, header_string.str()); fprintf(out, "import rp2\n"); fprintf(out, "from machine import Pin"); diff --git a/tools/pioasm/test/amethyst.pio b/tools/pioasm/test/amethyst.pio index 6b8160460..d64f3f9f9 100644 --- a/tools/pioasm/test/amethyst.pio +++ b/tools/pioasm/test/amethyst.pio @@ -50,4 +50,23 @@ wait gpio 40 wait 0 jmppin wait 0 jmppin + 3 mov x, !x -.word 0x1234 \ No newline at end of file +.word 0x1234 + + +.program prev_next +.pio_version 1 +wait 0 irq prev 0 ; Wait for IRQ0 +irq prev clear 0 ; Clear IRQ0 +irq clear 0 ; Clear IRQ0 +wait 0 irq next 0 ; Wait for IRQ0 +irq next clear 0 ; Clear IRQ0 + +.program wee +.pio_version 1 +wait 0 gpio 15 +wait 0 gpio 31 + +.program wee2 +.pio_version 1 +wait 0 gpio 31 +wait 0 gpio 47 diff --git a/tools/pioasm/version.h.in b/tools/pioasm/version.h.in new file mode 100644 index 000000000..32a6d134a --- /dev/null +++ b/tools/pioasm/version.h.in @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// --------------------------------------- +// THIS FILE IS AUTOGENERATED; DO NOT EDIT +// --------------------------------------- + +#ifndef _PIOASM_VERSION_H +#define _PIOASM_VERSION_H + +#define PIOASM_VERSION_STRING "${PIOASM_VERSION_STRING}" + +#endif \ No newline at end of file From 485b34ac8d2042ec9f9e0410e0905473dfc087a7 Mon Sep 17 00:00:00 2001 From: Armando Montanez Date: Mon, 14 Jul 2025 10:30:37 -0700 Subject: [PATCH 2/2] Hook up pio version string in Bazel build --- test/kitchen_sink/BUILD.bazel | 7 ++++++- tools/pioasm/BUILD.bazel | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/kitchen_sink/BUILD.bazel b/test/kitchen_sink/BUILD.bazel index d703ff320..3dbb8492f 100644 --- a/test/kitchen_sink/BUILD.bazel +++ b/test/kitchen_sink/BUILD.bazel @@ -1,4 +1,4 @@ -load("//bazel:defs.bzl", "compatible_with_rp2") +load("//bazel:defs.bzl", "compatible_with_rp2", "pico_generate_pio_header") load("//bazel/util:transition.bzl", "kitchen_sink_test_binary") package(default_visibility = ["//visibility:public"]) @@ -21,6 +21,11 @@ cc_library( includes = ["."], ) +pico_generate_pio_header( + name = "trivial_pio_test", + srcs = ["trivial.pio"], +) + cc_library( name = "kitchen_sink_common", testonly = True, diff --git a/tools/pioasm/BUILD.bazel b/tools/pioasm/BUILD.bazel index 266bce68a..732d5e42c 100644 --- a/tools/pioasm/BUILD.bazel +++ b/tools/pioasm/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//rules:expand_template.bzl", "expand_template") + package(default_visibility = ["//visibility:public"]) # TODO: No support for building the parser. @@ -19,6 +21,7 @@ cc_library( "pio_disassembler.h", "pio_enums.h", "pio_types.h", + ":version", ], copts = select({ "@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"], @@ -63,6 +66,15 @@ cc_library( alwayslink = True, ) +expand_template( + name = "version", + template = "version.h.in", + substitutions = { + "${PIOASM_VERSION_STRING}": module_version() if module_version() != None else "0.0.1-WORKSPACE", + }, + out = "gen/version.h", +) + cc_binary( name = "pioasm", deps = [