From 5e4d134f2b1013517e115214436cbab53bee41ec Mon Sep 17 00:00:00 2001 From: uzleo Date: Thu, 4 Dec 2025 12:51:32 +0100 Subject: [PATCH 01/14] Fix pioasm build with GCC 15 by forcing pthread init --- tools/pioasm/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/pioasm/CMakeLists.txt b/tools/pioasm/CMakeLists.txt index dcca23860..36bd5d04b 100644 --- a/tools/pioasm/CMakeLists.txt +++ b/tools/pioasm/CMakeLists.txt @@ -23,6 +23,7 @@ add_executable(pioasm gen/lexer.cpp gen/parser.cpp ) +target_compile_definitions(pioasm PRIVATE _GTHREAD_USE_COND_INIT_FUNC) target_sources(pioasm PRIVATE c_sdk_output.cpp) target_sources(pioasm PRIVATE python_output.cpp) From 85fa4954b40a3a129c0fb32ff8e394dde83d2dc6 Mon Sep 17 00:00:00 2001 From: uzleo Date: Sun, 14 Dec 2025 18:24:32 +0000 Subject: [PATCH 02/14] chore: setup docker-compose file --- docker-compose.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..517cd760a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: "3.9" + +services: + pico2: + image: pico2:25.10 + user: "${UID:-1000}:${GID:-1000}" + working_dir: /stuff/work/pico-sdk + environment: + USER: uzleo + HOME: /home/uzleo + entrypoint: ["/usr/bin/env", "fish"] + volumes: + - /stuff/work:/stuff/work + - /stuff/tools:/stuff/tools + - /home/uzleo:/home/uzleo + - /etc/passwd:/etc/passwd:ro + - /etc/group:/etc/group:ro + stdin_open: true + tty: true From 7a1764c44ed8dbc31aec2b0de1e02e4b9d7acba1 Mon Sep 17 00:00:00 2001 From: uzleo Date: Sun, 14 Dec 2025 18:24:40 +0000 Subject: [PATCH 03/14] feat: add a led-blink program --- examples/CMakeLists.txt | 17 +++++++++++++++ examples/led_blink.cpp | 14 +++++++++++++ examples/led_blink_raw.cpp | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 examples/CMakeLists.txt create mode 100644 examples/led_blink.cpp create mode 100644 examples/led_blink_raw.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000..de51a1ac4 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.13) + +include(../pico_sdk_init.cmake) + +project(examples C CXX ASM) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +pico_sdk_init() + +add_executable(led_blink_raw + led_blink_raw.cpp +) + +target_link_libraries(led_blink_raw pico_runtime) + +pico_add_extra_outputs(led_blink_raw) diff --git a/examples/led_blink.cpp b/examples/led_blink.cpp new file mode 100644 index 000000000..49f428949 --- /dev/null +++ b/examples/led_blink.cpp @@ -0,0 +1,14 @@ +#include "pico/stdlib.h" + +int main() { + const uint led_pin = PICO_DEFAULT_LED_PIN; + gpio_init(led_pin); + gpio_set_dir(led_pin, GPIO_OUT); + + while (true) { + gpio_put(led_pin, true); + sleep_ms(500); + gpio_put(led_pin, false); + sleep_ms(500); + } +} diff --git a/examples/led_blink_raw.cpp b/examples/led_blink_raw.cpp new file mode 100644 index 000000000..40ccce1b0 --- /dev/null +++ b/examples/led_blink_raw.cpp @@ -0,0 +1,42 @@ + + +#include "hardware/structs/io_bank0.h" +#include "hardware/structs/padsbank0.h" +#include "hardware/structs/sio.h" +#include "pico/platform.h" + +namespace { + +constexpr uint LED_PIN = 25; +constexpr uint32_t LED_MASK = 1u << LED_PIN; + +void init_led_pin() { + // Configure the pad for push-pull output: 4 mA drive, Schmitt enabled, no + // pulls. + padsbank0_hw->io[LED_PIN] = + (PADS_BANK0_GPIO25_DRIVE_VALUE_4MA << PADS_BANK0_GPIO25_DRIVE_LSB) | + PADS_BANK0_GPIO25_SCHMITT_BITS; + + // Route the pin to the SIO peripheral so we can drive it directly. + io_bank0_hw->io[LED_PIN].ctrl = GPIO_FUNC_SIO; + + // Enable output on the pin via SIO. + sio_hw->gpio_oe_set = LED_MASK; +} + +void busy_delay(uint32_t cycles) { + for (volatile uint32_t i = 0; i < cycles; ++i) { + tight_loop_contents(); + } +} + +} // namespace + +auto main() -> int { + init_led_pin(); + + while (true) { + sio_hw->gpio_togl = LED_MASK; + busy_delay(12000000); + } +} From c1cbc5c291cc9e9be7bdc2db8b9f03b07cf04538 Mon Sep 17 00:00:00 2001 From: uzleo Date: Wed, 17 Dec 2025 19:55:26 +0000 Subject: [PATCH 04/14] fix: add `__printflike` attribute if toolchain does not provide it Some libc variants (e.g. picolibc/LLVM embedded toolchain) don't provide __printflike; fall back to the usual GCC-style format attribute. --- .../pico_platform_compiler/include/pico/platform/compiler.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h b/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h index 7f24008a2..44af9f326 100644 --- a/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h +++ b/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h @@ -27,6 +27,11 @@ #else #define PICO_C_COMPILER_IS_GNU 1 #endif +/* Some libc variants (e.g. picolibc/LLVM embedded toolchain) don't provide + * __printflike; fall back to the usual GCC-style format attribute. */ +#ifndef __printflike +#define __printflike(a, b) __attribute__((__format__(printf, a, b))) +#endif #elif defined __ICCARM__ #ifndef __aligned #define __aligned(x) __attribute__((__aligned__(x))) From fb2982ebf998ad5eb7f2cb434e72107904a70a6a Mon Sep 17 00:00:00 2001 From: uzleo Date: Wed, 17 Dec 2025 12:29:43 +0000 Subject: [PATCH 05/14] build: use clang to cross-compile --- examples/CMakeLists.txt | 26 +++++++++++++++++++++++--- examples/README.md | 18 ++++++++++++++++++ examples/led_blink_raw.cpp | 3 +++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 examples/README.md diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index de51a1ac4..c84b61880 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,16 +2,36 @@ cmake_minimum_required(VERSION 3.13) include(../pico_sdk_init.cmake) +set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP ON) +set(CMAKE_CXX_SCAN_FOR_MODULES ON) project(examples C CXX ASM) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) pico_sdk_init() -add_executable(led_blink_raw +if (NOT CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS) + find_program(CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS + NAMES clang-scan-deps clang-scan-deps-21 clang-scan-deps-20 + PATHS ${PICO_TOOLCHAIN_PATH}/bin /usr/bin) +endif() + +add_executable(led_blink led_blink_raw.cpp ) -target_link_libraries(led_blink_raw pico_runtime) +target_compile_features(led_blink PRIVATE cxx_std_20) +target_link_libraries(led_blink pico_runtime) +pico_set_printf_implementation(led_blink none) +if (PICO_CLIB STREQUAL "llvm_libc") + # libdummyhost provides stdio symbols for llvm-libc runtimes. + target_link_options(led_blink PRIVATE -ldummyhost) +endif() + +target_sources(led_blink PRIVATE + FILE_SET cxx_modules TYPE CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_LIST_DIR}/sdk + FILES sdk/hw/hw.cppm +) -pico_add_extra_outputs(led_blink_raw) +pico_add_extra_outputs(led_blink) diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..6f5063617 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,18 @@ +# Building without USB/stdio using LLVM Embedded Toolchain + +For bare-metal targets that don’t need USB stdio, configure with the LLVM Embedded Toolchain sysroot and skip picotool/UF2. Example (building `led_blink` on pico2): +``` +rm -rf build +cmake -G Ninja -S examples -B build -DPICO_BOARD=pico2 \ + -DPICO_COMPILER=pico_arm_cortex_m33_clang \ + -DPICO_TOOLCHAIN_PATH=/stuff/tools/llvm/ATfE-21.1.1 \ + -DPICO_COMPILER_SYSROOT=/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/armv8m.main_hard_fp_exn_rtti_unaligned_size \ + -DPICO_NO_PICOTOOL=1 \ + -DCMAKE_TRY_COMPILE_PLATFORM_VARIABLES="PICO_COMPILER_SYSROOT;PICO_CLANG_RUNTIMES;PICO_CLIB" \ + -DCMAKE_C_STANDARD_INCLUDE_DIRECTORIES=/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/include/ \ + -DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES="/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/include/c++/v1/;/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/include/" + +cmake --build build +``` + +Adjust paths for your toolchain install; some ATfE versions add a `_size` suffix to the runtime directory. Re-enable picotool/USB stdio if needed. diff --git a/examples/led_blink_raw.cpp b/examples/led_blink_raw.cpp index 40ccce1b0..dbabed6ff 100644 --- a/examples/led_blink_raw.cpp +++ b/examples/led_blink_raw.cpp @@ -32,6 +32,9 @@ void busy_delay(uint32_t cycles) { } // namespace +// Provide a dummy _fini so newlib's cleanup hook has a target. +extern "C" void _fini() {} + auto main() -> int { init_led_pin(); From a68d3116573a8b2d65001166e59a232eccc96b19 Mon Sep 17 00:00:00 2001 From: uzleo Date: Fri, 26 Dec 2025 17:52:39 +0100 Subject: [PATCH 06/14] chore: add project-specific clangd customization file for diagnostics --- .clangd-bin | 1 + 1 file changed, 1 insertion(+) create mode 100644 .clangd-bin diff --git a/.clangd-bin b/.clangd-bin new file mode 100644 index 000000000..bef1314fd --- /dev/null +++ b/.clangd-bin @@ -0,0 +1 @@ +/stuff/tools/llvm/ATfE-21.1.1/bin/clangd From 8908035a50169677348ffa7cb7f0875a793ec551 Mon Sep 17 00:00:00 2001 From: uzleo Date: Fri, 26 Dec 2025 17:53:16 +0100 Subject: [PATCH 07/14] feat: add hw module --- examples/led_blink_raw.cpp | 40 +++++-------------------------- examples/sdk/hw/hw.cppm | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 34 deletions(-) create mode 100644 examples/sdk/hw/hw.cppm diff --git a/examples/led_blink_raw.cpp b/examples/led_blink_raw.cpp index dbabed6ff..db1b1f08c 100644 --- a/examples/led_blink_raw.cpp +++ b/examples/led_blink_raw.cpp @@ -1,45 +1,17 @@ -#include "hardware/structs/io_bank0.h" -#include "hardware/structs/padsbank0.h" -#include "hardware/structs/sio.h" -#include "pico/platform.h" - -namespace { - -constexpr uint LED_PIN = 25; -constexpr uint32_t LED_MASK = 1u << LED_PIN; - -void init_led_pin() { - // Configure the pad for push-pull output: 4 mA drive, Schmitt enabled, no - // pulls. - padsbank0_hw->io[LED_PIN] = - (PADS_BANK0_GPIO25_DRIVE_VALUE_4MA << PADS_BANK0_GPIO25_DRIVE_LSB) | - PADS_BANK0_GPIO25_SCHMITT_BITS; - - // Route the pin to the SIO peripheral so we can drive it directly. - io_bank0_hw->io[LED_PIN].ctrl = GPIO_FUNC_SIO; - - // Enable output on the pin via SIO. - sio_hw->gpio_oe_set = LED_MASK; -} - -void busy_delay(uint32_t cycles) { - for (volatile uint32_t i = 0; i < cycles; ++i) { - tight_loop_contents(); - } -} - -} // namespace +import pico.hw; +// TODO(): is below even needed? // Provide a dummy _fini so newlib's cleanup hook has a target. extern "C" void _fini() {} auto main() -> int { - init_led_pin(); + + pico::hw::InitLedPin(); while (true) { - sio_hw->gpio_togl = LED_MASK; - busy_delay(12000000); + pico::hw::ToggleLed(); + pico::hw::BusyDelay(12000000); } } diff --git a/examples/sdk/hw/hw.cppm b/examples/sdk/hw/hw.cppm new file mode 100644 index 000000000..0a0f5199f --- /dev/null +++ b/examples/sdk/hw/hw.cppm @@ -0,0 +1,48 @@ + +module; + +#include "hardware/structs/io_bank0.h" +#include "hardware/structs/padsbank0.h" +#include "hardware/structs/sio.h" +#include "pico/platform.h" + +#include + +export module pico.hw; + +namespace pico::hw { + +export auto InitLedPin() -> void; +export auto BusyDelay(std::uint32_t cycles) -> void; +export auto ToggleLed() -> void; + +} // namespace pico::hw + +namespace { +constexpr uint LED_PIN = 25; +constexpr uint32_t LED_MASK = 1u << LED_PIN; +} // namespace + +namespace pico::hw { + +auto InitLedPin() -> void { + // Configure the pad for push-pull output: 4 mA drive, Schmitt enabled, no + // pulls. + padsbank0_hw->io[LED_PIN] = + (PADS_BANK0_GPIO25_DRIVE_VALUE_4MA << PADS_BANK0_GPIO25_DRIVE_LSB) | + PADS_BANK0_GPIO25_SCHMITT_BITS; + + // Route the pin to the SIO peripheral so we can drive it directly. + io_bank0_hw->io[LED_PIN].ctrl = GPIO_FUNC_SIO; + + // Enable output on the pin via SIO. + sio_hw->gpio_oe_set = LED_MASK; +} + +auto BusyDelay(std::uint32_t cycles) -> void { + busy_wait_at_least_cycles(cycles); +} + +auto ToggleLed() -> void { sio_hw->gpio_togl = LED_MASK; } + +} // namespace pico::hw From 151d2f2858f577b76381e75f2fea6c06649cbd30 Mon Sep 17 00:00:00 2001 From: uzleo Date: Fri, 26 Dec 2025 19:08:24 +0000 Subject: [PATCH 08/14] build: refine cmake script --- examples/CMakeLists.txt | 29 +++++++++++++++++++++++++---- examples/led_blink_raw.cpp | 2 +- examples/sdk/hw/hw.cppm | 8 ++++---- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c84b61880..b24253177 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,15 +1,22 @@ -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.30) include(../pico_sdk_init.cmake) -set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP ON) set(CMAKE_CXX_SCAN_FOR_MODULES ON) + project(examples C CXX ASM) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) pico_sdk_init() +if (DEFINED PICO_COMPILER_SYSROOT) + set(LIBCXX_STD_MODULE_DIR "${PICO_COMPILER_SYSROOT}/share/libc++/v1") + set(LIBCXX_STD_MODULE "${LIBCXX_STD_MODULE_DIR}/std.cppm") +else() + message(FATAL_ERROR "PICO_COMPILER_SYSROOT is not set; cannot locate libc++ std module") +endif() + if (NOT CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS) find_program(CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS NAMES clang-scan-deps clang-scan-deps-21 clang-scan-deps-20 @@ -19,10 +26,14 @@ endif() add_executable(led_blink led_blink_raw.cpp ) - -target_compile_features(led_blink PRIVATE cxx_std_20) +target_compile_features(led_blink PRIVATE cxx_std_26) +target_compile_options(led_blink PRIVATE + $<$:-Weverything -Wno-c++98-compat> + $<$:-Weverything -Wno-c++98-compat> +) target_link_libraries(led_blink pico_runtime) pico_set_printf_implementation(led_blink none) + if (PICO_CLIB STREQUAL "llvm_libc") # libdummyhost provides stdio symbols for llvm-libc runtimes. target_link_options(led_blink PRIVATE -ldummyhost) @@ -34,4 +45,14 @@ target_sources(led_blink PRIVATE FILES sdk/hw/hw.cppm ) +if (EXISTS "${LIBCXX_STD_MODULE}") + target_sources(led_blink PRIVATE + FILE_SET libcxx_modules TYPE CXX_MODULES + BASE_DIRS "${LIBCXX_STD_MODULE_DIR}" + FILES "${LIBCXX_STD_MODULE}" + ) +else() + message(FATAL_ERROR "libc++ std module not found at ${LIBCXX_STD_MODULE}; import std will fail") +endif() + pico_add_extra_outputs(led_blink) diff --git a/examples/led_blink_raw.cpp b/examples/led_blink_raw.cpp index db1b1f08c..a4dd6f0c8 100644 --- a/examples/led_blink_raw.cpp +++ b/examples/led_blink_raw.cpp @@ -8,7 +8,7 @@ extern "C" void _fini() {} auto main() -> int { - pico::hw::InitLedPin(); + pico::hw::InitializeLedPin(); while (true) { pico::hw::ToggleLed(); diff --git a/examples/sdk/hw/hw.cppm b/examples/sdk/hw/hw.cppm index 0a0f5199f..8ec5b3aa8 100644 --- a/examples/sdk/hw/hw.cppm +++ b/examples/sdk/hw/hw.cppm @@ -6,13 +6,13 @@ module; #include "hardware/structs/sio.h" #include "pico/platform.h" -#include - export module pico.hw; +import std; + namespace pico::hw { -export auto InitLedPin() -> void; +export auto InitializeLedPin() -> void; export auto BusyDelay(std::uint32_t cycles) -> void; export auto ToggleLed() -> void; @@ -25,7 +25,7 @@ constexpr uint32_t LED_MASK = 1u << LED_PIN; namespace pico::hw { -auto InitLedPin() -> void { +auto InitializeLedPin() -> void { // Configure the pad for push-pull output: 4 mA drive, Schmitt enabled, no // pulls. padsbank0_hw->io[LED_PIN] = From a32b555ab993c91224bafb8c6485937134f6c204 Mon Sep 17 00:00:00 2001 From: uzleo Date: Mon, 29 Dec 2025 12:07:35 +0000 Subject: [PATCH 09/14] feat: add _fini stub to pico-runtime this way apps do not need to worry about providing this symbol. --- examples/led_blink_raw.cpp | 4 ---- src/rp2_common/pico_clib_interface/CMakeLists.txt | 4 ++++ src/rp2_common/pico_clib_interface/fini_stub.c | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 src/rp2_common/pico_clib_interface/fini_stub.c diff --git a/examples/led_blink_raw.cpp b/examples/led_blink_raw.cpp index a4dd6f0c8..24b9552a4 100644 --- a/examples/led_blink_raw.cpp +++ b/examples/led_blink_raw.cpp @@ -2,10 +2,6 @@ import pico.hw; -// TODO(): is below even needed? -// Provide a dummy _fini so newlib's cleanup hook has a target. -extern "C" void _fini() {} - auto main() -> int { pico::hw::InitializeLedPin(); diff --git a/src/rp2_common/pico_clib_interface/CMakeLists.txt b/src/rp2_common/pico_clib_interface/CMakeLists.txt index 84d3faf62..741485ae1 100644 --- a/src/rp2_common/pico_clib_interface/CMakeLists.txt +++ b/src/rp2_common/pico_clib_interface/CMakeLists.txt @@ -1,6 +1,10 @@ if (NOT TARGET pico_clib_interface) pico_add_library(pico_clib_interface) + target_sources(pico_clib_interface INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/fini_stub.c + ) + # ---- newlib ---- pico_add_library(pico_newlib_interface) diff --git a/src/rp2_common/pico_clib_interface/fini_stub.c b/src/rp2_common/pico_clib_interface/fini_stub.c new file mode 100644 index 000000000..ad5299ae7 --- /dev/null +++ b/src/rp2_common/pico_clib_interface/fini_stub.c @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico.h" + +// Bare-metal stub so __libc_fini_array can resolve _fini without pulling in +// hosted runtime shutdown logic. +void __weak _fini(void) {} From 8bcff0b123c861a51761c3cc5b5aa87e4c237c71 Mon Sep 17 00:00:00 2001 From: uzleo Date: Mon, 29 Dec 2025 13:14:01 +0000 Subject: [PATCH 10/14] chore: add sw dev files --- .clang-format | 2 ++ .clang-tidy | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..4444fb591 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +AllowShortFunctionsOnASingleLine: None +BasedOnStyle: Google diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..85df8ff87 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,26 @@ +Checks: > + -*, + clang-analyzer-*, + bugprone-*, + performance-*, + portability-*, + misc-*, + readability-*, + modernize-*, + -clang-analyzer-alpha*, + -bugprone-easily-swappable-parameters, + -bugprone-exception-escape, + -bugprone-narrowing-conversions, + -bugprone-reserved-identifier, + -misc-include-cleaner, + -modernize-avoid-c-arrays, + -modernize-use-auto, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + -readability-function-cognitive-complexity, + -readability-identifier-length, + -readability-implicit-bool-conversion, + -readability-magic-numbers +WarningsAsErrors: '' +HeaderFilterRegex: '.*' +FormatStyle: file From 1c0a7813f2553718423b4eec3c88b3a86335ada2 Mon Sep 17 00:00:00 2001 From: uzleo Date: Mon, 29 Dec 2025 13:14:17 +0000 Subject: [PATCH 11/14] refactor: improve readability --- examples/led_blink_raw.cpp | 1 - examples/sdk/hw/hw.cppm | 34 +++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/examples/led_blink_raw.cpp b/examples/led_blink_raw.cpp index 24b9552a4..66a745f53 100644 --- a/examples/led_blink_raw.cpp +++ b/examples/led_blink_raw.cpp @@ -3,7 +3,6 @@ import pico.hw; auto main() -> int { - pico::hw::InitializeLedPin(); while (true) { diff --git a/examples/sdk/hw/hw.cppm b/examples/sdk/hw/hw.cppm index 8ec5b3aa8..952aa1058 100644 --- a/examples/sdk/hw/hw.cppm +++ b/examples/sdk/hw/hw.cppm @@ -16,33 +16,49 @@ export auto InitializeLedPin() -> void; export auto BusyDelay(std::uint32_t cycles) -> void; export auto ToggleLed() -> void; -} // namespace pico::hw +} // namespace pico::hw namespace { -constexpr uint LED_PIN = 25; -constexpr uint32_t LED_MASK = 1u << LED_PIN; -} // namespace + +std::uint8_t constexpr kLedPin{25}; + +template > + requires(std::unsigned_integral or std::same_as>) +consteval auto GetLedMask() -> T { + std::bitset<32> led_mask{}; + led_mask.set(kLedPin); + + if constexpr (std::is_same_v>) { + return led_mask; + } + + return static_cast(led_mask.to_ulong()); +} + +} // namespace namespace pico::hw { auto InitializeLedPin() -> void { // Configure the pad for push-pull output: 4 mA drive, Schmitt enabled, no // pulls. - padsbank0_hw->io[LED_PIN] = + padsbank0_hw->io[kLedPin] = (PADS_BANK0_GPIO25_DRIVE_VALUE_4MA << PADS_BANK0_GPIO25_DRIVE_LSB) | PADS_BANK0_GPIO25_SCHMITT_BITS; // Route the pin to the SIO peripheral so we can drive it directly. - io_bank0_hw->io[LED_PIN].ctrl = GPIO_FUNC_SIO; + io_bank0_hw->io[kLedPin].ctrl = GPIO_FUNC_SIO; // Enable output on the pin via SIO. - sio_hw->gpio_oe_set = LED_MASK; + sio_hw->gpio_oe_set = GetLedMask(); } auto BusyDelay(std::uint32_t cycles) -> void { busy_wait_at_least_cycles(cycles); } -auto ToggleLed() -> void { sio_hw->gpio_togl = LED_MASK; } +auto ToggleLed() -> void { + sio_hw->gpio_togl = GetLedMask(); +} -} // namespace pico::hw +} // namespace pico::hw From 22e0317afb1c2bd21489fe6f41242067810c86ba Mon Sep 17 00:00:00 2001 From: uzleo Date: Mon, 29 Dec 2025 15:41:49 +0000 Subject: [PATCH 12/14] chore: removed unused source code --- examples/led_blink.cpp | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 examples/led_blink.cpp diff --git a/examples/led_blink.cpp b/examples/led_blink.cpp deleted file mode 100644 index 49f428949..000000000 --- a/examples/led_blink.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "pico/stdlib.h" - -int main() { - const uint led_pin = PICO_DEFAULT_LED_PIN; - gpio_init(led_pin); - gpio_set_dir(led_pin, GPIO_OUT); - - while (true) { - gpio_put(led_pin, true); - sleep_ms(500); - gpio_put(led_pin, false); - sleep_ms(500); - } -} From c3b686679a6555f5bdda31e4c402b3d06ab85a13 Mon Sep 17 00:00:00 2001 From: uzleo Date: Wed, 31 Dec 2025 14:38:30 +0100 Subject: [PATCH 13/14] fix(rp2350): expose init arrays for llvm-picolibc llvm-picolibc expects init array symbols to be visible; without them the start/end pointers resolve to 0, so board init (including TinyUSB) never runs. Expose the symbols in the default memmap to ensure proper initialization. --- src/rp2_common/pico_crt0/rp2350/memmap_default.ld | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld b/src/rp2_common/pico_crt0/rp2350/memmap_default.ld index bce316d14..48a5478a5 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_default.ld @@ -77,24 +77,26 @@ SECTIONS . = ALIGN(4); /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); + PROVIDE (__bothinit_array_start = .); + PROVIDE (__preinit_array_start = .); KEEP(*(SORT(.preinit_array.*))) KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); + PROVIDE (__preinit_array_end = .); . = ALIGN(4); /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); + PROVIDE (__init_array_start = .); KEEP(*(SORT(.init_array.*))) KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); + PROVIDE (__init_array_end = .); + PROVIDE (__bothinit_array_end = .); . = ALIGN(4); /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); + PROVIDE (__fini_array_start = .); *(SORT(.fini_array.*)) *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); + PROVIDE (__fini_array_end = .); *(.eh_frame*) . = ALIGN(4); @@ -299,4 +301,3 @@ SECTIONS /* todo assert on extra code */ } - From d90fe5bfe60318a9ca2d0bdc0f659bb9372cf9f5 Mon Sep 17 00:00:00 2001 From: uzleo Date: Fri, 2 Jan 2026 13:44:46 +0000 Subject: [PATCH 14/14] feat: enable USB functionality to easily flash pico2 --- examples/CMakeLists.txt | 4 +++- examples/README.md | 2 +- examples/led_blink_raw.cpp | 4 ++-- examples/sdk/hw/hw.cppm | 6 ++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b24253177..5088d19bc 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -31,8 +31,10 @@ target_compile_options(led_blink PRIVATE $<$:-Weverything -Wno-c++98-compat> $<$:-Weverything -Wno-c++98-compat> ) -target_link_libraries(led_blink pico_runtime) +target_link_libraries(led_blink pico_stdlib) pico_set_printf_implementation(led_blink none) +pico_enable_stdio_usb(led_blink 1) +pico_enable_stdio_uart(led_blink 0) if (PICO_CLIB STREQUAL "llvm_libc") # libdummyhost provides stdio symbols for llvm-libc runtimes. diff --git a/examples/README.md b/examples/README.md index 6f5063617..464d7d248 100644 --- a/examples/README.md +++ b/examples/README.md @@ -9,7 +9,7 @@ cmake -G Ninja -S examples -B build -DPICO_BOARD=pico2 \ -DPICO_COMPILER_SYSROOT=/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/armv8m.main_hard_fp_exn_rtti_unaligned_size \ -DPICO_NO_PICOTOOL=1 \ -DCMAKE_TRY_COMPILE_PLATFORM_VARIABLES="PICO_COMPILER_SYSROOT;PICO_CLANG_RUNTIMES;PICO_CLIB" \ - -DCMAKE_C_STANDARD_INCLUDE_DIRECTORIES=/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/include/ \ + -DCMAKE_C_STANDARD_INCLUDE_DIRECTORIES="/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/include/" \ -DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES="/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/include/c++/v1/;/stuff/tools/llvm/ATfE-21.1.1/lib/clang-runtimes/arm-none-eabi/include/" cmake --build build diff --git a/examples/led_blink_raw.cpp b/examples/led_blink_raw.cpp index 66a745f53..1a27a87b5 100644 --- a/examples/led_blink_raw.cpp +++ b/examples/led_blink_raw.cpp @@ -1,10 +1,10 @@ - import pico.hw; auto main() -> int { - pico::hw::InitializeLedPin(); + pico::hw::InitializeBoard(); + pico::hw::InitializeLedPin(); while (true) { pico::hw::ToggleLed(); pico::hw::BusyDelay(12000000); diff --git a/examples/sdk/hw/hw.cppm b/examples/sdk/hw/hw.cppm index 952aa1058..e4ecf22ba 100644 --- a/examples/sdk/hw/hw.cppm +++ b/examples/sdk/hw/hw.cppm @@ -5,6 +5,7 @@ module; #include "hardware/structs/padsbank0.h" #include "hardware/structs/sio.h" #include "pico/platform.h" +#include "pico/stdio.h" export module pico.hw; @@ -12,6 +13,7 @@ import std; namespace pico::hw { +export auto InitializeBoard() -> void; export auto InitializeLedPin() -> void; export auto BusyDelay(std::uint32_t cycles) -> void; export auto ToggleLed() -> void; @@ -39,6 +41,10 @@ consteval auto GetLedMask() -> T { namespace pico::hw { +auto InitializeBoard() -> void { + stdio_init_all(); +} + auto InitializeLedPin() -> void { // Configure the pad for push-pull output: 4 mA drive, Schmitt enabled, no // pulls.