From 2d65b214b1bde98722053d60392e179286d939ec Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 14 Jul 2026 17:46:21 -0500 Subject: [PATCH 1/2] fix pio_encode_mov in release mode --- .../include/hardware/pio_instructions.h | 5 ++- test/CMakeLists.txt | 1 + test/pico_sync_test/pico_sync_test.c | 7 +--- test/pio_encoding_test/BUILD.bazel | 7 ++++ test/pio_encoding_test/CMakeLists.txt | 5 +++ test/pio_encoding_test/encodings.pio | 12 ++++++ test/pio_encoding_test/pio_encoding_test.c | 41 +++++++++++++++++++ 7 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 test/pio_encoding_test/BUILD.bazel create mode 100644 test/pio_encoding_test/CMakeLists.txt create mode 100644 test/pio_encoding_test/encodings.pio create mode 100644 test/pio_encoding_test/pio_encoding_test.c 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 902e60604..348daa59a 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h @@ -54,6 +54,7 @@ enum pio_instr_bits { #define _PIO_INVALID_MOV_SRC 0u #define _PIO_INVALID_MOV_DEST 0u #endif +#define _PIO_AMBIGUOUS_SRC_DEST 0x100u /*! \brief Enumeration of values to pass for source/destination args for instruction encoding functions * \ingroup pio_instructions @@ -68,7 +69,7 @@ enum pio_src_dest { pio_null = 3u | _PIO_INVALID_SET_DEST | _PIO_INVALID_MOV_DEST, #if PICO_PIO_VERSION > 0 pio_pindirs_mov = 3u | _PIO_INVALID_IN_SRC | _PIO_INVALID_MOV_SRC, - pio_pindirs = 4u | _PIO_INVALID_IN_SRC | _PIO_INVALID_MOV_SRC, + pio_pindirs = 4u | _PIO_INVALID_IN_SRC | _PIO_INVALID_MOV_SRC | _PIO_AMBIGUOUS_SRC_DEST, #else pio_pindirs = 4u | _PIO_INVALID_IN_SRC | _PIO_INVALID_MOV_SRC | _PIO_INVALID_MOV_DEST, #endif @@ -79,7 +80,7 @@ enum pio_src_dest { pio_isr = 6u | _PIO_INVALID_SET_DEST, pio_osr = 7u | _PIO_INVALID_OUT_DEST | _PIO_INVALID_SET_DEST, pio_exec_out = 7u | _PIO_INVALID_IN_SRC | _PIO_INVALID_SET_DEST | _PIO_INVALID_MOV_SRC | _PIO_INVALID_MOV_DEST, - pio_exec = 7u | _PIO_INVALID_IN_SRC | _PIO_INVALID_SET_DEST | _PIO_INVALID_MOV_SRC, + pio_exec = 7u | _PIO_INVALID_IN_SRC | _PIO_INVALID_SET_DEST | _PIO_INVALID_MOV_SRC | _PIO_AMBIGUOUS_SRC_DEST, }; static inline uint _pio_major_instr_bits(uint instr) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e35796619..876eafc2b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,6 +22,7 @@ if (PICO_ON_DEVICE) add_subdirectory(pico_low_power_test) add_subdirectory(pico_async_context_test) add_subdirectory(pico_thread_local_test) + add_subdirectory(pio_encoding_test) endif() # PICO_TEST_FILE_GENERATOR: Path to the a CMake script to generate test files for ci diff --git a/test/pico_sync_test/pico_sync_test.c b/test/pico_sync_test/pico_sync_test.c index e9fd8f7c3..b2794eca4 100644 --- a/test/pico_sync_test/pico_sync_test.c +++ b/test/pico_sync_test/pico_sync_test.c @@ -6,12 +6,9 @@ #include -#include "../../src/common/pico_base_headers/include/pico/types.h" -#include "../../src/common/pico_time/include/pico/time.h" -#include "../../src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h" -#include "pico/lock_core.h" +#include "pico/stdlib.h" +#include "pico/sync.h" #include "pico/test.h" -#include "pico/stdio.h" PICOTEST_MODULE_NAME("SYNC", "sync test"); diff --git a/test/pio_encoding_test/BUILD.bazel b/test/pio_encoding_test/BUILD.bazel new file mode 100644 index 000000000..6dacc1e17 --- /dev/null +++ b/test/pio_encoding_test/BUILD.bazel @@ -0,0 +1,7 @@ +# TODO: Add these tests to the Bazel build. +filegroup( + name = "unsupported_tests", + srcs = [ + "pio_encoding_test.c", + ], +) diff --git a/test/pio_encoding_test/CMakeLists.txt b/test/pio_encoding_test/CMakeLists.txt new file mode 100644 index 000000000..3b95e652f --- /dev/null +++ b/test/pio_encoding_test/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(pio_encoding_test ${CMAKE_CURRENT_LIST_DIR}/pio_encoding_test.c) +target_link_libraries(pio_encoding_test PRIVATE pico_stdlib pico_test hardware_pio) +pico_add_extra_outputs(pio_encoding_test) + +pico_generate_pio_header(pio_encoding_test ${CMAKE_CURRENT_LIST_DIR}/encodings.pio) \ No newline at end of file diff --git a/test/pio_encoding_test/encodings.pio b/test/pio_encoding_test/encodings.pio new file mode 100644 index 000000000..2af1af5f2 --- /dev/null +++ b/test/pio_encoding_test/encodings.pio @@ -0,0 +1,12 @@ +.pio_version 1 + +.program encodings + +public mov_osr_x: + mov osr, x +public mov_pindirs_x: + mov pindirs, x +public mov_exec_x: + mov exec, x +public mov_y_x: + mov y, x diff --git a/test/pio_encoding_test/pio_encoding_test.c b/test/pio_encoding_test/pio_encoding_test.c new file mode 100644 index 000000000..11ae08f20 --- /dev/null +++ b/test/pio_encoding_test/pio_encoding_test.c @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2022 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include "pico/stdlib.h" +#include "pico/test.h" +#include "hardware/pio_instructions.h" +#include "encodings.pio.h" + +PICOTEST_MODULE_NAME("PIO_ENCODING", "pio encoding test"); + + +int main() { + stdio_init_all(); + + PICOTEST_START(); + + PICOTEST_START_SECTION("check pio_encodings"); + + PICOTEST_CHECK(0xa0e1 == encodings_program_instructions[encodings_offset_mov_osr_x], "mov osr, x"); + printf("0x%x\n", pio_encode_mov(pio_osr, pio_x)); + PICOTEST_CHECK(0xa0e1 == pio_encode_mov(pio_osr, pio_x), "pio_encode_mov(pio_osr, pio_x)"); + PICOTEST_CHECK(0xa061 == encodings_program_instructions[encodings_offset_mov_pindirs_x], "mov pindirs, x"); + PICOTEST_CHECK(0xa061 == pio_encode_mov(pio_pindirs, pio_x), "pio_encode_mov(pio_pindirs, pio_x)"); +#if PICO_PIO_VERSION > 1 + PICOTEST_CHECK(0xa061 == pio_encode_mov(pio_pindirs_mov, pio_x), "pio_encode_mov(pio_pindirs_mov, pio_x)"); +#endif + PICOTEST_CHECK(0xa081 == encodings_program_instructions[encodings_offset_mov_exec_x], "mov exec, x"); + PICOTEST_CHECK(0xa081 == pio_encode_mov(pio_exec, pio_x), "pio_encode_mov(pio_exec, pio_x)"); + PICOTEST_CHECK(0xa081 == pio_encode_mov(pio_exec_mov, pio_x), "pio_encode_mov(pio_exec_mov, pio_x)"); + PICOTEST_CHECK(0xa041 == encodings_program_instructions[encodings_offset_mov_y_x], "mov y, x"); + PICOTEST_CHECK(0xa041 == pio_encode_mov(pio_y, pio_x), "pio_encode_mov(pio_y, pio_x)"); + PICOTEST_END_SECTION(); + + PICOTEST_END_TEST(); +} + From 70849222b96db8a2baaed00567943f6b17c66868 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 14 Jul 2026 18:43:55 -0500 Subject: [PATCH 2/2] remove debugging printf --- test/pio_encoding_test/pio_encoding_test.c | 1 - 1 file changed, 1 deletion(-) diff --git a/test/pio_encoding_test/pio_encoding_test.c b/test/pio_encoding_test/pio_encoding_test.c index 11ae08f20..fc6e62577 100644 --- a/test/pio_encoding_test/pio_encoding_test.c +++ b/test/pio_encoding_test/pio_encoding_test.c @@ -22,7 +22,6 @@ int main() { PICOTEST_START_SECTION("check pio_encodings"); PICOTEST_CHECK(0xa0e1 == encodings_program_instructions[encodings_offset_mov_osr_x], "mov osr, x"); - printf("0x%x\n", pio_encode_mov(pio_osr, pio_x)); PICOTEST_CHECK(0xa0e1 == pio_encode_mov(pio_osr, pio_x), "pio_encode_mov(pio_osr, pio_x)"); PICOTEST_CHECK(0xa061 == encodings_program_instructions[encodings_offset_mov_pindirs_x], "mov pindirs, x"); PICOTEST_CHECK(0xa061 == pio_encode_mov(pio_pindirs, pio_x), "pio_encode_mov(pio_pindirs, pio_x)");