From bb916f470447a213d22488e806a2a4ed3558343f Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 25 Nov 2024 00:44:24 -0600 Subject: [PATCH 001/224] start 2.1.1-develop --- MODULE.bazel | 2 +- pico_sdk_version.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 9cdcce3b2..ec37d1b40 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "pico-sdk", - version = "2.1.0", + version = "2.1.1-develop", ) bazel_dep(name = "platforms", version = "0.0.9") diff --git a/pico_sdk_version.cmake b/pico_sdk_version.cmake index 27a215389..dea7dabb5 100644 --- a/pico_sdk_version.cmake +++ b/pico_sdk_version.cmake @@ -6,10 +6,10 @@ set(PICO_SDK_VERSION_MAJOR 2) set(PICO_SDK_VERSION_MINOR 1) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base -set(PICO_SDK_VERSION_REVISION 0) +set(PICO_SDK_VERSION_REVISION 1) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base -#set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) +set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base From f0a1ff3c0322ec831da2bf2f0a7ef0bf62013e57 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 25 Nov 2024 12:30:55 -0600 Subject: [PATCH 002/224] Fixes for/found by documentation generation (#2099) * fix errors breaking extra_[cmake_]configs.py * remove trailing whitespace which is confusing asciidoctor * fix rp2xxx-specific -> rp2xxx_specific * add missing xip_cache funcs to the combined docs * Revert "fix errors breaking extra_[cmake_]configs.py" * Fix typo in #define name * Allow optional whitespace at the start of "commented out" config lines Co-authored-by: Andrew Scheller --- .../hardware_gpio/include/hardware/gpio.h | 4 ++-- src/rp2_common/hardware_pio/include/hardware/pio.h | 2 +- .../include/hardware/xip_cache.h | 14 +++++++------- src/rp2_common/pico_bootrom/include/pico/bootrom.h | 2 +- src/rp2_common/pico_double/include/pico/double.h | 2 +- .../pico_stdio_usb/include/pico/stdio_usb.h | 4 ++-- tools/extract_build_defines.py | 2 +- tools/extract_cmake_configs.py | 2 +- tools/extract_configs.py | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/rp2_common/hardware_gpio/include/hardware/gpio.h b/src/rp2_common/hardware_gpio/include/hardware/gpio.h index 5ce0eef09..bd1f4b687 100644 --- a/src/rp2_common/hardware_gpio/include/hardware/gpio.h +++ b/src/rp2_common/hardware_gpio/include/hardware/gpio.h @@ -42,12 +42,12 @@ extern "C" { * * RP-series microcontrollers have two banks of General Purpose Input / Output (GPIO) pins, which are assigned as follows: * - * \if rp2040-specific + * \if rp2040_specific * RP2040 has 30 user GPIO pins in bank 0, and 6 QSPI pins in the QSPI bank 1 (QSPI_SS, QSPI_SCLK and QSPI_SD0 to QSPI_SD3). The QSPI * pins are used to execute code from an external flash device, leaving the User bank (GPIO0 to GPIO29) for the programmer to use. * \endif * - * \if rp2350-specific + * \if rp2350_specific * The number of GPIO pins available depends on the package. There are 30 user GPIOs in bank 0 in the QFN-60 package (RP2350A), or 48 user GPIOs * in the QFN-80 package. Bank 1 contains the 6 QSPI pins and the USB DP/DM pins. * \endif diff --git a/src/rp2_common/hardware_pio/include/hardware/pio.h b/src/rp2_common/hardware_pio/include/hardware/pio.h index 7ca20d64c..9d1f5ce09 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio.h @@ -919,7 +919,7 @@ int pio_set_gpio_base(PIO pio, uint gpio_base); * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 * \param program the program definition * \return true if the program can be loaded; - * false if not, e.g. if there is not suitable space in the instruction memory + * false if not, e.g. if there is not suitable space in the instruction memory */ bool pio_can_add_program(PIO pio, const pio_program_t *program); diff --git a/src/rp2_common/hardware_xip_cache/include/hardware/xip_cache.h b/src/rp2_common/hardware_xip_cache/include/hardware/xip_cache.h index 286db8bdc..ff915eb0c 100644 --- a/src/rp2_common/hardware_xip_cache/include/hardware/xip_cache.h +++ b/src/rp2_common/hardware_xip_cache/include/hardware/xip_cache.h @@ -20,14 +20,14 @@ * of flash), so pointers should have XIP_BASE subtracted before passing into one of these * functions. * - * \if rp2040-specific + * \if rp2040_specific * The only valid cache maintenance operation on RP2040 is "invalidate", which tells the cache to * forget everything it knows about some address. This is necessary after a programming operation, * because the cache does not automatically know about any serial programming operations performed * on the external flash device, and could return stale data. * \endif * - * \if rp2350-specific + * \if rp2350_specific * On RP2350, the three types of operation are: * * * Invalidate: tell the cache to forget everything it knows about some address. The next access to @@ -124,7 +124,7 @@ void xip_cache_invalidate_all(void); */ void xip_cache_invalidate_range(uintptr_t start_offset, uintptr_t size_bytes); -#if !XIP_CACHE_IS_READ_ONLY +#if !XIP_CACHE_IS_READ_ONLY || PICO_COMBINED_DOCS /*! \brief Clean the cache for the entire XIP address space * \ingroup hardware_xip_cache @@ -136,12 +136,12 @@ void xip_cache_invalidate_range(uintptr_t start_offset, uintptr_t size_bytes); * This function is faster than calling xip_cache_clean_range() for the entire address space, * because it iterates over cachelines instead of addresses. * - * \if rp2040-specific + * \if rp2040_specific * On RP2040 this is a no-op, as the XIP cache is read-only. This is indicated by the * XIP_CACHE_IS_READ_ONLY macro. * \endif * - * \if rp2350-specific + * \if rp2350_specific * On RP2350, due to the workaround applied for RP2350-E11, this function also effectively * invalidates all cache lines after cleaning them. The next access to each line will miss. Avoid * this by calling xip_cache_clean_range() which does not suffer this issue. @@ -155,7 +155,7 @@ void xip_cache_clean_all(void); * * This causes the cache to write out pending write data at these offsets to the downstream memory. * - * \if rp2040-specific + * \if rp2040_specific * On RP2040 this is a no-op, as the XIP cache is read-only. This is indicated by the * XIP_CACHE_IS_READ_ONLY macro. * \endif @@ -177,7 +177,7 @@ static inline void xip_cache_clean_range(uintptr_t start_offset, uintptr_t size_ } #endif -#if !PICO_RP2040 +#if !PICO_RP2040 || PICO_COMBINED_DOCS /*! \brief Pin a range of offsets within the XIP address space * \ingroup hardware_xip_cache diff --git a/src/rp2_common/pico_bootrom/include/pico/bootrom.h b/src/rp2_common/pico_bootrom/include/pico/bootrom.h index 498d4f724..c815f9bf0 100644 --- a/src/rp2_common/pico_bootrom/include/pico/bootrom.h +++ b/src/rp2_common/pico_bootrom/include/pico/bootrom.h @@ -403,7 +403,7 @@ static inline void rom_flash_enter_cmd_xip(void) { func(); } -#if !PICO_RP2040 +#if !PICO_RP2040 || PICO_COMBINED_DOCS #ifdef __riscv /*! * \brief Give the bootrom a new stack diff --git a/src/rp2_common/pico_double/include/pico/double.h b/src/rp2_common/pico_double/include/pico/double.h index f8c2b4dd5..5af8c9e4e 100644 --- a/src/rp2_common/pico_double/include/pico/double.h +++ b/src/rp2_common/pico_double/include/pico/double.h @@ -65,7 +65,7 @@ double exp10(double x); void sincos(double x, double *sinx, double *cosx); double powint(double x, int y); -#if !PICO_RP2040 +#if !PICO_RP2040 || PICO_COMBINED_DOCS double ddiv_fast(double n, double d); double sqrt_fast(double d); double mla(double x, double y, double z); // note this is not fused diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index b572998d8..b1cb0354c 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -74,8 +74,8 @@ // PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=47 on RP2350B, 29 otherwise, group=pico_stdio_usb // PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW, Whether pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE) is active low, type=bool, default=0, group=pico_stdio_usb -#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW -#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW 0 +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW +#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW 0 #endif // PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_stdio_usb diff --git a/tools/extract_build_defines.py b/tools/extract_build_defines.py index bbcad15af..179f084ec 100755 --- a/tools/extract_build_defines.py +++ b/tools/extract_build_defines.py @@ -139,7 +139,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): elif BASE_BUILD_DEFINE_RE.search(line): m = BUILD_DEFINE_RE.match(line) if not m: - if line.startswith("## "): + if re.match(r"^\s*#\s*# ", line): logger.info("Possible misformatted {} at {}:{} ({})".format(BASE_BUILD_DEFINE_NAME, file_path, linenum, line)) else: raise Exception("Found misformatted {} at {}:{} ({})".format(BASE_BUILD_DEFINE_NAME, file_path, linenum, line)) diff --git a/tools/extract_cmake_configs.py b/tools/extract_cmake_configs.py index 8fdb4504e..18884330f 100755 --- a/tools/extract_cmake_configs.py +++ b/tools/extract_cmake_configs.py @@ -139,7 +139,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): elif BASE_CMAKE_CONFIG_RE.search(line): m = CMAKE_CONFIG_RE.match(line) if not m: - if line.startswith("## "): + if re.match("^\s*#\s*# ", line): logger.info("Possible misformatted {} at {}:{} ({})".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line)) else: raise Exception("Found misformatted {} at {}:{} ({})".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line)) diff --git a/tools/extract_configs.py b/tools/extract_configs.py index 034866987..30705d5cb 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -158,7 +158,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): elif BASE_CONFIG_RE.search(line): m = CONFIG_RE.match(line) if not m: - if line.startswith("//// "): + if re.match(r"^\s*//\s*// ", line): logger.info("Possible misformatted {} at {}:{} ({})".format(BASE_CONFIG_NAME, file_path, linenum, line)) else: raise Exception("Found misformatted {} at {}:{} ({})".format(BASE_CONFIG_NAME, file_path, linenum, line)) From fe81780508bd31b678716830199228b404b26f9b Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:17:13 +0000 Subject: [PATCH 003/224] Update btstack license. (#2115) --- src/rp2_common/pico_btstack/LICENSE.RP | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_btstack/LICENSE.RP b/src/rp2_common/pico_btstack/LICENSE.RP index 79e0080db..124c61ca8 100644 --- a/src/rp2_common/pico_btstack/LICENSE.RP +++ b/src/rp2_common/pico_btstack/LICENSE.RP @@ -1,6 +1,6 @@ “BlueKitchen” shall refer to BlueKitchen GmbH. “Raspberry Pi” shall refer to Raspberry Pi Ltd. -“Product” shall refer to Raspberry Pi hardware products Raspberry Pi Pico W or Raspberry Pi Pico WH. +“Product” shall refer to Raspberry Pi hardware products Pico W, Pico WH, Pico 2 W, Pico 2 WH, and RM2. “Customer” means any purchaser of a Product. “Customer Products” means products manufactured or distributed by Customers which use or are derived from Products. From 54784f884b76a63d52d67029ae60c6efca609923 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:19:55 +0000 Subject: [PATCH 004/224] Add rom_data_lookup_inline function (#2116) * Move rom_data_lookup code into rom_data_lookup_inline Allows ROM data lookup from FLASH/RAM sensitive code * Use rom_data_lookup_inline in flash_devinfo_ptr Fixes bug introduced by #2082 where flash_devinfo_get_cs_size would use rom_data_lookup from flash during a __no_inline_not_in_flash_func --- src/rp2_common/hardware_flash/flash.c | 2 +- src/rp2_common/pico_bootrom/bootrom.c | 18 +------------ .../pico_bootrom/include/pico/bootrom.h | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/rp2_common/hardware_flash/flash.c b/src/rp2_common/hardware_flash/flash.c index 902d0daf7..26d47a68b 100644 --- a/src/rp2_common/hardware_flash/flash.c +++ b/src/rp2_common/hardware_flash/flash.c @@ -290,7 +290,7 @@ void flash_get_unique_id(uint8_t *id_out) { // device, so fields must have getters/setters. static io_rw_16 * flash_devinfo_ptr(void) { // Note the lookup returns a pointer to a 32-bit pointer literal in the ROM - io_rw_16 **p = (io_rw_16 **) rom_data_lookup(ROM_DATA_FLASH_DEVINFO16_PTR); + io_rw_16 **p = (io_rw_16 **) rom_data_lookup_inline(ROM_DATA_FLASH_DEVINFO16_PTR); assert(p); return *p; } diff --git a/src/rp2_common/pico_bootrom/bootrom.c b/src/rp2_common/pico_bootrom/bootrom.c index 344e3724c..1120f006a 100644 --- a/src/rp2_common/pico_bootrom/bootrom.c +++ b/src/rp2_common/pico_bootrom/bootrom.c @@ -14,25 +14,9 @@ void *rom_func_lookup(uint32_t code) { return rom_func_lookup_inline(code); } -#pragma GCC diagnostic push -// diagnostic: GCC thinks near-zero value is a null pointer member access, but it's not -#pragma GCC diagnostic ignored "-Warray-bounds" void *rom_data_lookup(uint32_t code) { -#if PICO_RP2040 - rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(BOOTROM_TABLE_LOOKUP_OFFSET); - uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(BOOTROM_DATA_TABLE_OFFSET); - return rom_table_lookup(data_table, code); -#else -#ifdef __riscv - uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0; - rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET + rom_offset_adjust); -#else - rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET); -#endif - return rom_table_lookup(code, RT_FLAG_DATA); -#endif + return rom_data_lookup_inline(code); } -#pragma GCC diagnostic pop /// \end::table_lookup[] bool rom_funcs_lookup(uint32_t *table, unsigned int count) { diff --git a/src/rp2_common/pico_bootrom/include/pico/bootrom.h b/src/rp2_common/pico_bootrom/include/pico/bootrom.h index c815f9bf0..bb5b8ba2f 100644 --- a/src/rp2_common/pico_bootrom/include/pico/bootrom.h +++ b/src/rp2_common/pico_bootrom/include/pico/bootrom.h @@ -215,6 +215,32 @@ static __force_inline void *rom_func_lookup_inline(uint32_t code) { } #pragma GCC diagnostic pop +/*! + * \brief Lookup a bootrom data address by its code. This method is forcibly inlined into the caller for FLASH/RAM sensitive code usage + * \ingroup pico_bootrom + * \param code the code + * \return a pointer to the data, or NULL if the code does not match any bootrom data + */ +#pragma GCC diagnostic push +// diagnostic: GCC thinks near-zero value is a null pointer member access, but it's not +#pragma GCC diagnostic ignored "-Warray-bounds" +static __force_inline void *rom_data_lookup_inline(uint32_t code) { +#if PICO_RP2040 + rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(BOOTROM_TABLE_LOOKUP_OFFSET); + uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(BOOTROM_DATA_TABLE_OFFSET); + return rom_table_lookup(data_table, code); +#else +#ifdef __riscv + uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0; + rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET + rom_offset_adjust); +#else + rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET); +#endif + return rom_table_lookup(code, RT_FLAG_DATA); +#endif +} +#pragma GCC diagnostic pop + /*! * \brief Reboot the device into BOOTSEL mode * \ingroup pico_bootrom From ba7aa3f075f3cf2d2b5e7f7c4bb4bc7511ab06dd Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 4 Dec 2024 20:51:48 +0000 Subject: [PATCH 005/224] Fix mis-matched backticks in doxygen (#2104) --- src/common/README.md | 2 +- src/rp2_common/pico_standard_binary_info/doc.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/README.md b/src/common/README.md index 0f30a4211..5397946c4 100644 --- a/src/common/README.md +++ b/src/common/README.md @@ -1,3 +1,3 @@ This directory code that is common to all builds regardless of `PICO_PLATFORM`. It is a mix of common header files, or high level functionality built entirely using `hardware_` or `pico_` libraries provided -by the actual target `PICO_PLATFORM`` \ No newline at end of file +by the actual target `PICO_PLATFORM` diff --git a/src/rp2_common/pico_standard_binary_info/doc.h b/src/rp2_common/pico_standard_binary_info/doc.h index e24741ec1..3245681f6 100644 --- a/src/rp2_common/pico_standard_binary_info/doc.h +++ b/src/rp2_common/pico_standard_binary_info/doc.h @@ -9,11 +9,11 @@ * * The program name if defined (unless `PICO_NO_BINARY_SIZE=1`). The value is `PICO_PROGRAM_NAME` or `PICO_TARGET_NAME` if the former isn't defined * * The value of PICO_BOARD (unless `PICO_NO_BI_PICO_BOARD=1`) * * The SDK version (unless `PICO_NO_BI_SDK_VERSION=1`) - * * The program version string if defined (unless `PICO_NO_BI_PROGRAM_VERSION_STRING=1`). The value is `PICO_PROGRAM_VERSION_STRING`` + * * The program version string if defined (unless `PICO_NO_BI_PROGRAM_VERSION_STRING=1`). The value is `PICO_PROGRAM_VERSION_STRING` * * The program description if defined (unless `PICO_NO_BI_PROGRAM_DESCRIPTION=1`). The value is `PICO_PROGRAM_DESCRIPTION` * * The program url if defined (unless `PICO_NO_BI_PROGRAM_URL=1`). The value is `PICO_PROGRAM_URL` * * The boot stage 2 used if any (unless `PICO_NO_BI_BOOT_STAGE2_NAME=1`). The value is `PICO_BOOT_STAGE2_NAME` - * * The program build date (unless `PICO_NO_BI_PROGRAM_BUILD_DATE=1). The value defaults to the C preprocessor value `__DATE__`, but can be overridden with `PICO_PROGRAM_BUILD_DATE`. Note you should do a clean build if you want to be sure this value is up to date. + * * The program build date (unless `PICO_NO_BI_PROGRAM_BUILD_DATE=1`). The value defaults to the C preprocessor value `__DATE__`, but can be overridden with `PICO_PROGRAM_BUILD_DATE`. Note you should do a clean build if you want to be sure this value is up to date. * * The program build type (unless `PICO_NO_BI_BUILD_TYPE=1`). The value is `PICO_CMAKE_BUILD_TYPE` which comes from the CMake build - e.g. Release, Debug, RelMinSize * * The binary size (unless `PICO_NO_BI_BINARY_SIZE=1`) */ From 969f5895aa6790a9c1af8ed31ccd06cc81fe36cf Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:39:04 +0000 Subject: [PATCH 006/224] ta_set_timeout can fail to set an alarm (#2127) * ta_set_timeout can fail to set an alarm If alarm_pool_irq_handler takes <1us between handling an alarm and calling ta_set_timeout then no alarms will be set as it will appear as if an earlier alarm is already armedi before the target time. Make sure ta_set_timeout always leaves with an alarm set by checking the armed status. Fixes #2118 * ta_disable_irq_handler should unarm its timer --- .../include/pico/time_adapter.h | 4 +- test/pico_time_test/pico_time_test.c | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h b/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h index 59308b4b9..bc9caf1ad 100644 --- a/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h +++ b/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h @@ -48,7 +48,8 @@ static inline void ta_set_timeout(alarm_pool_timer_t *timer, uint alarm_num, int // 2. If we just passed the target time, then time_til_target will be high, meaning we will // likely not do the update, but this is OK since the caller who has the full 64 bits // must check if the target time has passed when we return anyway to avoid races. - if (time_til_target < time_til_alarm) { + // 3. We should never leave here without an alarm being armed + if (time_til_target < time_til_alarm || (timer_hw_from_timer(timer)->armed & (1 << alarm_num)) == 0) { timer_hw_from_timer(timer)->alarm[alarm_num] = (uint32_t) target; } } @@ -75,6 +76,7 @@ static inline void ta_enable_irq_handler(alarm_pool_timer_t *timer, uint alarm_n static inline void ta_disable_irq_handler(alarm_pool_timer_t *timer, uint alarm_num, irq_handler_t irq_handler) { uint irq_num = timer_hardware_alarm_get_irq_num(timer, alarm_num); + timer_hw_from_timer(timer)->armed = 1u << alarm_num; // disarm the timer hw_clear_bits(&timer_hw_from_timer(timer)->inte, 1u << alarm_num); irq_set_enabled(irq_num, true); irq_remove_handler(irq_num, irq_handler); diff --git a/test/pico_time_test/pico_time_test.c b/test/pico_time_test/pico_time_test.c index 362187ddb..8092abbef 100644 --- a/test/pico_time_test/pico_time_test.c +++ b/test/pico_time_test/pico_time_test.c @@ -8,6 +8,7 @@ #include #include #include +#include "hardware/clocks.h" #include "pico/stdlib.h" #include "pico/test.h" // Include sys/types.h before inttypes.h to work around issue with @@ -74,6 +75,7 @@ static bool repeating_timer_callback(struct repeating_timer *t) { int issue_195_test(void); int issue_1812_test(void); int issue_1953_test(void); +int issue_2118_test(void); int main() { setup_default_uart(); @@ -246,6 +248,8 @@ int main() { issue_1953_test(); + issue_2118_test(); + PICOTEST_END_TEST(); } @@ -325,3 +329,38 @@ int issue_1953_test(void) { PICOTEST_END_SECTION(); return 0; } + +static int counter_2118; +static bool timer_callback_issue_2118(repeating_timer_t *rt) { + counter_2118++; + return true; +} + +int issue_2118_test(void) { + PICOTEST_START_SECTION("Issue #2118 defect - failure to set an alarm"); + + // this problem only happens when running the clock fast as it requires the time between + // alarm_pool_irq_handler handling an alarm and setting the next alarm to be <1us + set_sys_clock_hz(200 * MHZ, true); + setup_default_uart(); + + alarm_pool_t *pool = alarm_pool_create(2, 1); + repeating_timer_t timer; + alarm_pool_add_repeating_timer_ms(pool, -20, timer_callback_issue_2118, NULL, &timer); + + int iterations = 0; + while(iterations < 100) { + iterations++; + sleep_ms(20); + } + PICOTEST_CHECK(counter_2118 >= 100, "Repeating timer failure"); + + alarm_pool_destroy(pool); + hard_assert(timer_hw->armed == 0); // check destroying the pool unarms its timer + + set_sys_clock_hz(SYS_CLK_HZ, true); + setup_default_uart(); + + PICOTEST_END_SECTION(); + return 0; +} From e7a0e61165e52da35d70e028c2c0543afaed0127 Mon Sep 17 00:00:00 2001 From: Jean Jonethal Date: Tue, 7 Jan 2025 18:05:13 +0100 Subject: [PATCH 007/224] convert windows path delimiter to posix (#2149) (#2150) * convert windows path delimiter to posix (#2149) * add explicite variable assignment for intermediate resource name conversion result (#2149) --- src/rp2_common/pico_lwip/tools/makefsdata.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/pico_lwip/tools/makefsdata.py b/src/rp2_common/pico_lwip/tools/makefsdata.py index 88fca43a6..61312b5b8 100755 --- a/src/rp2_common/pico_lwip/tools/makefsdata.py +++ b/src/rp2_common/pico_lwip/tools/makefsdata.py @@ -23,9 +23,10 @@ def process_file(input_dir, file): if content_type is None: content_type = "application/octet-stream" - # file name - data = f"/{file.relative_to(input_dir)}\x00" - comment = f"\"/{file.relative_to(input_dir)}\" ({len(data)} chars)" + # file name with posix directory separators + file_path_posix = file.relative_to(input_dir).as_posix() + data = f"/{file_path_posix}\x00" + comment = f"\"/{file_path_posix}\" ({len(data)} chars)" while(len(data) % PAYLOAD_ALIGNMENT != 0): data += "\x00" results.append({'data': bytes(data, "utf-8"), 'comment': comment}); From 7bd430d7d6cdd7b7a61383c5aca60b9a257b08dc Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Sat, 11 Jan 2025 19:53:45 +0000 Subject: [PATCH 008/224] Fix RP02040 typos (#2168) --- src/rp2_common/hardware_adc/include/hardware/adc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/hardware_adc/include/hardware/adc.h b/src/rp2_common/hardware_adc/include/hardware/adc.h index 40bdb3260..c5d3fced7 100644 --- a/src/rp2_common/hardware_adc/include/hardware/adc.h +++ b/src/rp2_common/hardware_adc/include/hardware/adc.h @@ -106,7 +106,7 @@ static inline void adc_gpio_init(uint gpio) { * * Select an ADC input * \if rp2040_specific - * On RP02040 0...3 are GPIOs 26...29 respectively. Input 4 is the onboard temperature sensor. + * On RP2040 0...3 are GPIOs 26...29 respectively. Input 4 is the onboard temperature sensor. * \endif * \if rp2350_specific * On RP2350A 0...3 are GPIOs 26...29 respectively. Input 4 is the onboard temperature sensor. @@ -126,7 +126,7 @@ static inline void adc_select_input(uint input) { * \return The currently selected input channel. * * \if rp2040_specific - * On RP02040 0...3 are GPIOs 26...29 respectively. Input 4 is the onboard temperature sensor. + * On RP2040 0...3 are GPIOs 26...29 respectively. Input 4 is the onboard temperature sensor. * \endif * * \if rp2350_specific From 1b80db289de42d914b7c3d86160ad0b79b4560bb Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Sat, 11 Jan 2025 20:02:40 +0000 Subject: [PATCH 009/224] Restore the "API Documentation" link in sidebar when building with Doxygen >= 1.9.8 (#2135) --- docs/CMakeLists.txt | 10 ++++++++++ docs/Doxyfile.in | 4 ++-- docs/{DoxygenLayout.xml => DoxygenLayout.xml.in} | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) rename docs/{DoxygenLayout.xml => DoxygenLayout.xml.in} (98%) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 3171c5d3b..5b40ed730 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -55,11 +55,21 @@ if(PICO_BUILD_DOCS) set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + if(DOXYGEN_VERSION VERSION_GREATER_EQUAL "1.9.8") + # see https://github.com/doxygen/doxygen/issues/10562 + set(DOXY_API_DOCS_TAB_TYPE "topics") + else() + set(DOXY_API_DOCS_TAB_TYPE "modules") + endif() + set(doxylayout_in ${CMAKE_CURRENT_SOURCE_DIR}/DoxygenLayout.xml.in) + set(doxylayout ${CMAKE_CURRENT_BINARY_DIR}/DoxygenLayout.xml) + if (PICO_PLATFORM STREQUAL "rp2040") set(PICO_DOXYGEN_TAG "(RP2040)") elseif (PICO_PLATFORM STREQUAL "rp2350-arm-s" OR PICO_PLATFORM STREQUAL "rp2350-riscv") set(PICO_DOXYGEN_TAG "(RP2350)") endif() + configure_file(${doxylayout_in} ${doxylayout} @ONLY) configure_file(${doxyfile_in} ${doxyfile} @ONLY) add_custom_target(docs diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index 916877b32..f1e62f1e7 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -17,7 +17,7 @@ FILE_PATTERNS = *.h \ *.md USE_MDFILE_AS_MAINPAGE = @PROJECT_SOURCE_DIR@/docs/mainpage.md -LAYOUT_FILE = @PROJECT_SOURCE_DIR@/docs/DoxygenLayout.xml +LAYOUT_FILE = @PROJECT_BINARY_DIR@/docs/DoxygenLayout.xml HTML_FOOTER = @PROJECT_SOURCE_DIR@/docs/footer.html HTML_HEADER = @PROJECT_SOURCE_DIR@/docs/header.html @@ -65,4 +65,4 @@ PREDEFINED = __not_in_flash_func(x)= \ DOXYGEN_GENERATION= \ @DOXY_PREDEFINED@ -ENABLED_SECTIONS = @DOXY_ENABLED_SECTIONS@ \ No newline at end of file +ENABLED_SECTIONS = @DOXY_ENABLED_SECTIONS@ diff --git a/docs/DoxygenLayout.xml b/docs/DoxygenLayout.xml.in similarity index 98% rename from docs/DoxygenLayout.xml rename to docs/DoxygenLayout.xml.in index 07c1c980c..34dd66fcd 100644 --- a/docs/DoxygenLayout.xml +++ b/docs/DoxygenLayout.xml.in @@ -3,7 +3,7 @@ - + From fc37bede320e095ff86fa53034b142d279afe4f3 Mon Sep 17 00:00:00 2001 From: Osman Karaketir Date: Sat, 11 Jan 2025 23:04:10 +0300 Subject: [PATCH 010/224] Fix Doxygen comment (#2175) remove incorrect pool parameter --- src/common/pico_time/include/pico/time.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/pico_time/include/pico/time.h b/src/common/pico_time/include/pico/time.h index 53a606bcb..771fe42d6 100644 --- a/src/common/pico_time/include/pico/time.h +++ b/src/common/pico_time/include/pico/time.h @@ -688,7 +688,6 @@ static inline bool cancel_alarm(alarm_id_t alarm_id) { * \brief Return the time remaining before the next trigger of an alarm * \ingroup alarm * - * @param pool the alarm_pool containing the alarm * @param alarm_id the alarm * * @return >=0 the number of microseconds before the next trigger From 5202c272cb1b4d42c024ac72540543dc49708721 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Sat, 11 Jan 2025 20:06:12 +0000 Subject: [PATCH 011/224] Initialise stack in async_context_execute_sync call (#2106) We need to do this to avoid work_pending being set twice. Fixes #2101 --- src/rp2_common/pico_async_context/async_context_freertos.c | 2 +- .../pico_async_context/async_context_threadsafe_background.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_async_context/async_context_freertos.c b/src/rp2_common/pico_async_context/async_context_freertos.c index 3cffcbb98..9ae72b3af 100644 --- a/src/rp2_common/pico_async_context/async_context_freertos.c +++ b/src/rp2_common/pico_async_context/async_context_freertos.c @@ -193,7 +193,7 @@ static void handle_sync_func_call(async_context_t *context, async_when_pending_w uint32_t async_context_freertos_execute_sync(async_context_t *self_base, uint32_t (*func)(void *param), void *param) { async_context_freertos_t *self = (async_context_freertos_t*)self_base; hard_assert(xSemaphoreGetMutexHolder(self->lock_mutex) != xTaskGetCurrentTaskHandle()); - sync_func_call_t call; + sync_func_call_t call = {0}; call.worker.do_work = handle_sync_func_call; call.func = func; call.param = param; diff --git a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c index 33f3d45c8..730d8a5a7 100644 --- a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c +++ b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c @@ -140,7 +140,7 @@ uint32_t async_context_threadsafe_background_execute_sync(async_context_t *self_ #if ASYNC_CONTEXT_THREADSAFE_BACKGROUND_MULTI_CORE if (self_base->core_num != get_core_num()) { hard_assert(!recursive_mutex_enter_count(&self->lock_mutex)); - sync_func_call_t call; + sync_func_call_t call = {0}; call.worker.do_work = handle_sync_func_call; call.func = func; call.param = param; From 306c461cd33faa27b38a0107350d92e76de9ea64 Mon Sep 17 00:00:00 2001 From: Lesords <98899771+Lesords@users.noreply.github.com> Date: Sun, 12 Jan 2025 04:07:59 +0800 Subject: [PATCH 012/224] Fix: solve the problem that micropython could not be used (#2098) --- src/boards/include/boards/seeed_xiao_rp2350.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boards/include/boards/seeed_xiao_rp2350.h b/src/boards/include/boards/seeed_xiao_rp2350.h index 3390dedcc..52e163654 100644 --- a/src/boards/include/boards/seeed_xiao_rp2350.h +++ b/src/boards/include/boards/seeed_xiao_rp2350.h @@ -134,7 +134,7 @@ #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 #ifndef PICO_FLASH_SPI_CLKDIV -#define PICO_FLASH_SPI_CLKDIV 2 +#define PICO_FLASH_SPI_CLKDIV 4 #endif // pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) From 4b6e647590213f253f2789ad9026df1d00f38c5d Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Mon, 13 Jan 2025 13:59:03 -0800 Subject: [PATCH 013/224] Update Clang toolchain used by Bazel (#2151) * Update Clang toolchain used by Bazel * include * Sort includes * Use libc timeval definition * Disable unwinder linking for now * Link libm --- MODULE.bazel | 16 ++++++++-------- bazel/toolchain/BUILD.bazel | 2 ++ .../include/llvm_libc/sys/time.h | 10 +--------- .../pico_clib_interface/llvm_libc_interface.c | 9 +++++++++ 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index ec37d1b40..15275876e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -54,34 +54,34 @@ http_archive( http_archive( name = "clang_linux-x86_64", build_file = "//bazel/toolchain:clang.BUILD", - sha256 = "6c599d1aba568236064c340d7813324849896d5a4e2f3fd8225a8c31bfcbf884", + sha256 = "dd4b3b0fc7186a4da2b52796b251e0757aefac4813f9f635982954fec3337d2e", type = "zip", - url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/linux-amd64/+/git_revision:2b0a708f41dd6291ee744704d43febc975e3d026", + url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/linux-amd64/+/git_revision:9d3f9f47e6e630b8308562297757e0911be03a18", ) http_archive( name = "clang_win-x86_64", build_file = "//bazel/toolchain:clang.BUILD", - sha256 = "f49ba4123ee3958f2b47289d017a5b3f1ca01f82dd7a2168c45412c18101fd13", + sha256 = "21092395df915ee5a899a832a592b137c9ea07fbc91e49ac6069ea0083d31899", type = "zip", # Windows doesn't like `:` in the produced filename, so replace it with `%3A`. - url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/windows-amd64/+/git_revision:2b0a708f41dd6291ee744704d43febc975e3d026".replace("git_revision:", "git_revision%3A"), + url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/windows-amd64/+/git_revision:9d3f9f47e6e630b8308562297757e0911be03a18".replace("git_revision:", "git_revision%3A"), ) http_archive( name = "clang_mac-x86_64", build_file = "//bazel/toolchain:clang.BUILD", - sha256 = "d3516f2eb4c12d17ae77ee84c9226fbea581d4fb806910ceac4717d5adfcf748", + sha256 = "bb397fdce21d068ea40fefa9618993baa4907a248f996f18316c8fa6ca24dee2", type = "zip", - url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/mac-amd64/+/git_revision:2b0a708f41dd6291ee744704d43febc975e3d026", + url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/mac-amd64/+/git_revision:9d3f9f47e6e630b8308562297757e0911be03a18", ) http_archive( name = "clang_mac-aarch64", build_file = "//bazel/toolchain:clang.BUILD", - sha256 = "68e551f41c7e9473063b09819f6ab8ec6e7e53677f4078189656cb14dc52984b", + sha256 = "dad5583f96eabc913c1930d923c53a105d6ed73f56ca32451ea79ad70e495b0f", type = "zip", - url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/mac-arm64/+/git_revision:2b0a708f41dd6291ee744704d43febc975e3d026", + url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/mac-arm64/+/git_revision:9d3f9f47e6e630b8308562297757e0911be03a18", ) new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") diff --git a/bazel/toolchain/BUILD.bazel b/bazel/toolchain/BUILD.bazel index bba5baafd..ba8d947ca 100644 --- a/bazel/toolchain/BUILD.bazel +++ b/bazel/toolchain/BUILD.bazel @@ -79,9 +79,11 @@ cc_args( name = "llvm-libc_args", actions = ["@rules_cc//cc/toolchains/actions:link_actions"], args = [ + "--unwindlib=none", "-nostdlib++", "-nostartfiles", "-Wl,-lc++", + "-Wl,-lm", ], visibility = ["//visibility:private"], ) diff --git a/src/rp2_common/pico_clib_interface/include/llvm_libc/sys/time.h b/src/rp2_common/pico_clib_interface/include/llvm_libc/sys/time.h index 3d37f1c25..c22552ac1 100644 --- a/src/rp2_common/pico_clib_interface/include/llvm_libc/sys/time.h +++ b/src/rp2_common/pico_clib_interface/include/llvm_libc/sys/time.h @@ -9,15 +9,7 @@ #include <__llvm-libc-common.h> -#include -#include - -typedef long suseconds_t; - -struct timeval { - time_t tv_sec; - suseconds_t tv_usec; -}; +#include struct timezone { int tz_minuteswest; diff --git a/src/rp2_common/pico_clib_interface/llvm_libc_interface.c b/src/rp2_common/pico_clib_interface/llvm_libc_interface.c index da4281335..dfcab015e 100644 --- a/src/rp2_common/pico_clib_interface/llvm_libc_interface.c +++ b/src/rp2_common/pico_clib_interface/llvm_libc_interface.c @@ -5,8 +5,10 @@ */ #include +#include #include #include +#include #include @@ -65,6 +67,13 @@ ssize_t __llvm_libc_stdio_write(__unused void *cookie, const char *buf, size_t s return size; } +bool __llvm_libc_timespec_get_utc(struct timespec *ts) { + int64_t absolute_time = (int64_t)get_absolute_time(); + ts->tv_sec = (time_t)(absolute_time / 1000000); + ts->tv_nsec = (long)(absolute_time % 1000000 * 1000); + return true; +} + void __cxa_finalize(__unused void *dso) {} void __attribute__((noreturn)) __llvm_libc_exit(__unused int status) { From 61e271205714815b146b0bba71da8e6642b3221b Mon Sep 17 00:00:00 2001 From: waveshare <36142105+waveshare@users.noreply.github.com> Date: Sun, 19 Jan 2025 03:48:26 +0800 Subject: [PATCH 014/224] Added some weveshare board support (#2145) Signed-off-by: eng33 Co-authored-by: eng33 --- .../include/boards/waveshare_pico_cam_a.h | 83 +++++++++++++ .../include/boards/waveshare_rp2040_ble.h | 83 +++++++++++++ .../include/boards/waveshare_rp2040_eth.h | 83 +++++++++++++ .../include/boards/waveshare_rp2040_geek.h | 103 ++++++++++++++++ .../boards/waveshare_rp2040_lcd_0.96.h | 28 ++--- .../boards/waveshare_rp2040_lcd_1.28.h | 32 ++--- .../include/boards/waveshare_rp2040_matrix.h | 84 +++++++++++++ .../include/boards/waveshare_rp2040_pizero.h | 80 +++++++++++++ .../waveshare_rp2040_power_management_hat_b.h | 80 +++++++++++++ .../include/boards/waveshare_rp2040_tiny.h | 83 +++++++++++++ .../boards/waveshare_rp2040_touch_lcd_1.28.h | 105 ++++++++++++++++ .../include/boards/waveshare_rp2350_eth.h | 87 ++++++++++++++ .../include/boards/waveshare_rp2350_geek.h | 107 +++++++++++++++++ .../boards/waveshare_rp2350_lcd_0.96.h | 107 +++++++++++++++++ .../boards/waveshare_rp2350_lcd_1.28.h | 112 ++++++++++++++++++ .../include/boards/waveshare_rp2350_one.h | 87 ++++++++++++++ .../boards/waveshare_rp2350_plus_16mb.h | 89 ++++++++++++++ .../boards/waveshare_rp2350_plus_4mb.h | 89 ++++++++++++++ .../include/boards/waveshare_rp2350_tiny.h | 87 ++++++++++++++ .../boards/waveshare_rp2350_touch_lcd_1.28.h | 112 ++++++++++++++++++ .../include/boards/waveshare_rp2350_zero.h | 87 ++++++++++++++ 21 files changed, 1778 insertions(+), 30 deletions(-) create mode 100755 src/boards/include/boards/waveshare_pico_cam_a.h create mode 100755 src/boards/include/boards/waveshare_rp2040_ble.h create mode 100755 src/boards/include/boards/waveshare_rp2040_eth.h create mode 100755 src/boards/include/boards/waveshare_rp2040_geek.h create mode 100755 src/boards/include/boards/waveshare_rp2040_matrix.h create mode 100755 src/boards/include/boards/waveshare_rp2040_pizero.h create mode 100755 src/boards/include/boards/waveshare_rp2040_power_management_hat_b.h create mode 100755 src/boards/include/boards/waveshare_rp2040_tiny.h create mode 100755 src/boards/include/boards/waveshare_rp2040_touch_lcd_1.28.h create mode 100755 src/boards/include/boards/waveshare_rp2350_eth.h create mode 100755 src/boards/include/boards/waveshare_rp2350_geek.h create mode 100755 src/boards/include/boards/waveshare_rp2350_lcd_0.96.h create mode 100755 src/boards/include/boards/waveshare_rp2350_lcd_1.28.h create mode 100755 src/boards/include/boards/waveshare_rp2350_one.h create mode 100755 src/boards/include/boards/waveshare_rp2350_plus_16mb.h create mode 100755 src/boards/include/boards/waveshare_rp2350_plus_4mb.h create mode 100755 src/boards/include/boards/waveshare_rp2350_tiny.h create mode 100755 src/boards/include/boards/waveshare_rp2350_touch_lcd_1.28.h create mode 100755 src/boards/include/boards/waveshare_rp2350_zero.h diff --git a/src/boards/include/boards/waveshare_pico_cam_a.h b/src/boards/include/boards/waveshare_pico_cam_a.h new file mode 100755 index 000000000..a8b3b40e8 --- /dev/null +++ b/src/boards/include/boards/waveshare_pico_cam_a.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_PICO_CAM_A_H +#define _BOARDS_WAVESHARE_PICO_CAM_A_H + +// For board detection +#define WAVESHARE_PICO_CAM_A + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 2 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 3 +#endif + +// --- LCD --- +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 +#endif +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 9 +#endif +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 13 +#endif +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 +#endif +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 +#endif +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 7 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2040_ble.h b/src/boards/include/boards/waveshare_rp2040_ble.h new file mode 100755 index 000000000..8a56e9c58 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2040_ble.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_RP2040_BLE_H +#define _BOARDS_WAVESHARE_RP2040_BLE_H + +// For board detection +#define WAVESHARE_RP2040_BLE + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 2 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 3 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 4 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 5 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2040_eth.h b/src/boards/include/boards/waveshare_rp2040_eth.h new file mode 100755 index 000000000..8d3912e60 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2040_eth.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_RP2040_ETH_H +#define _BOARDS_WAVESHARE_RP2040_ETH_H + +// For board detection +#define WAVESHARE_RP2040_ETH + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 25 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 2 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 3 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 4 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 5 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2040_geek.h b/src/boards/include/boards/waveshare_rp2040_geek.h new file mode 100755 index 000000000..cba41cf7f --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2040_geek.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_RP2040_GEEK_H +#define _BOARDS_WAVESHARE_RP2040_GEEK_H + +// For board detection +#define WAVESHARE_RP2040_GEEK + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 1 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 4 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 5 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 2 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 3 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 20 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- LCD --- +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 +#endif +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 8 +#endif +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 9 +#endif +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 +#endif +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 +#endif +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 12 +#endif +#ifndef WAVESHARE_LCD_BL_PIN +#define WAVESHARE_LCD_BL_PIN 25 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2040_lcd_0.96.h b/src/boards/include/boards/waveshare_rp2040_lcd_0.96.h index 079187059..267dc1753 100644 --- a/src/boards/include/boards/waveshare_rp2040_lcd_0.96.h +++ b/src/boards/include/boards/waveshare_rp2040_lcd_0.96.h @@ -59,26 +59,26 @@ #endif // --- LCD --- -#ifndef WAVESHARE_RP2040_LCD_SPI -#define WAVESHARE_RP2040_LCD_SPI 1 +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 #endif -#ifndef WAVESHARE_RP2040_LCD_DC_PIN -#define WAVESHARE_RP2040_LCD_DC_PIN 8 +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 8 #endif -#ifndef WAVESHARE_RP2040_LCD_CS_PIN -#define WAVESHARE_RP2040_LCD_CS_PIN 9 +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 9 #endif -#ifndef WAVESHARE_RP2040_LCD_SCLK_PIN -#define WAVESHARE_RP2040_LCD_SCLK_PIN 10 +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 #endif -#ifndef WAVESHARE_RP2040_LCD_TX_PIN -#define WAVESHARE_RP2040_LCD_TX_PIN 11 +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 #endif -#ifndef WAVESHARE_RP2040_LCD_RST_PIN -#define WAVESHARE_RP2040_LCD_RST_PIN 12 +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 12 #endif -#ifndef WAVESHARE_RP2040_LCD_BL_PIN -#define WAVESHARE_RP2040_LCD_BL_PIN 25 +#ifndef WAVESHARE_LCD_BL_PIN +#define WAVESHARE_LCD_BL_PIN 25 #endif // --- FLASH --- diff --git a/src/boards/include/boards/waveshare_rp2040_lcd_1.28.h b/src/boards/include/boards/waveshare_rp2040_lcd_1.28.h index 816aec2e1..f88b9ed3d 100644 --- a/src/boards/include/boards/waveshare_rp2040_lcd_1.28.h +++ b/src/boards/include/boards/waveshare_rp2040_lcd_1.28.h @@ -59,30 +59,30 @@ #endif // --- LCD --- -#ifndef WAVESHARE_RP2040_LCD_SPI -#define WAVESHARE_RP2040_LCD_SPI 1 +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 #endif -#ifndef WAVESHARE_RP2040_LCD_DC_PIN -#define WAVESHARE_RP2040_LCD_DC_PIN 8 +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 8 #endif -#ifndef WAVESHARE_RP2040_LCD_CS_PIN -#define WAVESHARE_RP2040_LCD_CS_PIN 9 +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 9 #endif -#ifndef WAVESHARE_RP2040_LCD_SCLK_PIN -#define WAVESHARE_RP2040_LCD_SCLK_PIN 10 +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 #endif -#ifndef WAVESHARE_RP2040_LCD_TX_PIN -#define WAVESHARE_RP2040_LCD_TX_PIN 11 +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 #endif -#ifndef WAVESHARE_RP2040_LCD_RST_PIN -#define WAVESHARE_RP2040_LCD_RST_PIN 12 +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 12 #endif -#ifndef WAVESHARE_RP2040_LCD_BL_PIN -#define WAVESHARE_RP2040_LCD_BL_PIN 25 +#ifndef WAVESHARE_LCD_BL_PIN +#define WAVESHARE_LCD_BL_PIN 25 #endif // --- ADC --- -#ifndef WAVESHARE_RP2040_BAT_ADC_PIN -#define WAVESHARE_RP2040_BAT_ADC_PIN 29 +#ifndef WAVESHARE_BAT_ADC_PIN +#define WAVESHARE_BAT_ADC_PIN 29 #endif // --- FLASH --- diff --git a/src/boards/include/boards/waveshare_rp2040_matrix.h b/src/boards/include/boards/waveshare_rp2040_matrix.h new file mode 100755 index 000000000..9233a3639 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2040_matrix.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_RP2040_MATRIX_H +#define _BOARDS_WAVESHARE_RP2040_MATRIX_H + +// For board detection +#define WAVESHARE_RP2040_MATRIX + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2040_pizero.h b/src/boards/include/boards/waveshare_rp2040_pizero.h new file mode 100755 index 000000000..7c598fa59 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2040_pizero.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_RP2040_PIZERO_H +#define _BOARDS_WAVESHARE_RP2040_PIZERO_H + +// For board detection +#define WAVESHARE_RP2040_PIZERO + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2040_power_management_hat_b.h b/src/boards/include/boards/waveshare_rp2040_power_management_hat_b.h new file mode 100755 index 000000000..8290eb022 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2040_power_management_hat_b.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_RP2040_POWER_MANAGEMENT_HAT_B_H +#define _BOARDS_WAVESHARE_RP2040_POWER_MANAGEMENT_HAT_B_H + +// For board detection +#define WAVESHARE_RP2040_POWER_MANAGEMENT_HAT_B + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2040_tiny.h b/src/boards/include/boards/waveshare_rp2040_tiny.h new file mode 100755 index 000000000..84f646280 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2040_tiny.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_RP2040_TINY_H +#define _BOARDS_WAVESHARE_RP2040_TINY_H + +// For board detection +#define WAVESHARE_RP2040_TINY + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2040_touch_lcd_1.28.h b/src/boards/include/boards/waveshare_rp2040_touch_lcd_1.28.h new file mode 100755 index 000000000..35a340197 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2040_touch_lcd_1.28.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_WAVESHARE_RP2040_TOUCH_LCD_1_28_H +#define _BOARDS_WAVESHARE_RP2040_TOUCH_LCD_1_28_H + +// For board detection +#define WAVESHARE_RP2040_TOUCH_LCD_1_28 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- LCD --- +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 +#endif +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 8 +#endif +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 9 +#endif +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 +#endif +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 +#endif +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 12 +#endif +#ifndef WAVESHARE_LCD_BL_PIN +#define WAVESHARE_LCD_BL_PIN 25 +#endif + +// --- ADC --- +#ifndef WAVESHARE_BAT_ADC_PIN +#define WAVESHARE_BAT_ADC_PIN 29 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_eth.h b/src/boards/include/boards/waveshare_rp2350_eth.h new file mode 100755 index 000000000..f4aa7ee48 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_eth.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_ETH_H +#define _BOARDS_WAVESHARE_RP2350_ETH_H + +// For board detection +#define WAVESHARE_RP2350_ETH + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 25 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 2 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 3 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 4 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 5 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_geek.h b/src/boards/include/boards/waveshare_rp2350_geek.h new file mode 100755 index 000000000..ff065cbda --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_geek.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_GEEK_H +#define _BOARDS_WAVESHARE_RP2350_GEEK_H + +// For board detection +#define WAVESHARE_RP2350_GEEK + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 1 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 4 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 5 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 2 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 3 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 20 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- LCD --- +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 +#endif +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 8 +#endif +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 9 +#endif +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 +#endif +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 +#endif +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 12 +#endif +#ifndef WAVESHARE_LCD_BL_PIN +#define WAVESHARE_LCD_BL_PIN 25 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_lcd_0.96.h b/src/boards/include/boards/waveshare_rp2350_lcd_0.96.h new file mode 100755 index 000000000..fd6c9f778 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_lcd_0.96.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_LCD_0_96_H +#define _BOARDS_WAVESHARE_RP2350_LCD_0_96_H + +// For board detection +#define WAVESHARE_RP2350_LCD_0_96 + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- LCD --- +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 +#endif +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 8 +#endif +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 9 +#endif +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 +#endif +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 +#endif +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 12 +#endif +#ifndef WAVESHARE_LCD_BL_PIN +#define WAVESHARE_LCD_BL_PIN 25 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 3 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_lcd_1.28.h b/src/boards/include/boards/waveshare_rp2350_lcd_1.28.h new file mode 100755 index 000000000..4d4e0e022 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_lcd_1.28.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_LCD_1_28_H +#define _BOARDS_WAVESHARE_RP2350_LCD_1_28_H + +// For board detection +#define WAVESHARE_RP2350_LCD_1_28 + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- LCD --- +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 +#endif +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 8 +#endif +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 9 +#endif +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 +#endif +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 +#endif +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 12 +#endif +#ifndef WAVESHARE_LCD_BL_PIN +#define WAVESHARE_LCD_BL_PIN 25 +#endif + +// --- ADC --- +#ifndef WAVESHARE_BAT_ADC_PIN +#define WAVESHARE_BAT_ADC_PIN 29 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 3 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_one.h b/src/boards/include/boards/waveshare_rp2350_one.h new file mode 100755 index 000000000..937e1b682 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_one.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_ONE_H +#define _BOARDS_WAVESHARE_RP2350_ONE_H + +// For board detection +#define WAVESHARE_RP2350_ONE + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_plus_16mb.h b/src/boards/include/boards/waveshare_rp2350_plus_16mb.h new file mode 100755 index 000000000..8de280b1c --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_plus_16mb.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_PLUS_16MB_H +#define _BOARDS_WAVESHARE_RP2350_PLUS_16MB_H + +// For board detection +#define WAVESHARE_RP2350_PLUS_16MB + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- ADC --- +#ifndef WAVESHARE_BAT_ADC_PIN +#define WAVESHARE_BAT_ADC_PIN 29 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_plus_4mb.h b/src/boards/include/boards/waveshare_rp2350_plus_4mb.h new file mode 100755 index 000000000..3c8b98617 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_plus_4mb.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_PLUS_4MB_H +#define _BOARDS_WAVESHARE_RP2350_PLUS_4MB_H + +// For board detection +#define WAVESHARE_RP2350_PLUS_4MB + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- ADC --- +#ifndef WAVESHARE_BAT_ADC_PIN +#define WAVESHARE_BAT_ADC_PIN 29 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_tiny.h b/src/boards/include/boards/waveshare_rp2350_tiny.h new file mode 100755 index 000000000..23af13c0f --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_tiny.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_TINY_H +#define _BOARDS_WAVESHARE_RP2350_TINY_H + +// For board detection +#define WAVESHARE_RP2350_TINY + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 3 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/waveshare_rp2350_touch_lcd_1.28.h b/src/boards/include/boards/waveshare_rp2350_touch_lcd_1.28.h new file mode 100755 index 000000000..52eea9eb4 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_touch_lcd_1.28.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_TOUCH_LCD_1_28_H +#define _BOARDS_WAVESHARE_RP2350_TOUCH_LCD_1_28_H + +// For board detection +#define WAVESHARE_RP2350_TOUCH_LCD_1_28 + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- LCD --- +#ifndef WAVESHARE_LCD_SPI +#define WAVESHARE_LCD_SPI 1 +#endif +#ifndef WAVESHARE_LCD_DC_PIN +#define WAVESHARE_LCD_DC_PIN 8 +#endif +#ifndef WAVESHARE_LCD_CS_PIN +#define WAVESHARE_LCD_CS_PIN 9 +#endif +#ifndef WAVESHARE_LCD_SCLK_PIN +#define WAVESHARE_LCD_SCLK_PIN 10 +#endif +#ifndef WAVESHARE_LCD_TX_PIN +#define WAVESHARE_LCD_TX_PIN 11 +#endif +#ifndef WAVESHARE_LCD_RST_PIN +#define WAVESHARE_LCD_RST_PIN 12 +#endif +#ifndef WAVESHARE_LCD_BL_PIN +#define WAVESHARE_LCD_BL_PIN 25 +#endif + +// --- ADC --- +#ifndef WAVESHARE_BAT_ADC_PIN +#define WAVESHARE_BAT_ADC_PIN 29 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif + diff --git a/src/boards/include/boards/waveshare_rp2350_zero.h b/src/boards/include/boards/waveshare_rp2350_zero.h new file mode 100755 index 000000000..10b5d8b91 --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_zero.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_WAVESHARE_RP2350_ZERO_H +#define _BOARDS_WAVESHARE_RP2350_ZERO_H + +// For board detection +#define WAVESHARE_RP2350_ZERO + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 3 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif From b8dc8c488d8741eb9786b159fe3ff78324512c18 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:56:23 +0000 Subject: [PATCH 015/224] Fix ta_wakes_up_on_or_before (#2190) * Fix ta_wakes_up_on_or_before Handle target in the past and running for > 2^32 us. Fixes #2186 * Add test for ta_wakes_up_on_or_before fix --- .../include/pico/time_adapter.h | 6 +++--- test/pico_time_test/pico_time_test.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h b/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h index bc9caf1ad..639e91498 100644 --- a/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h +++ b/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h @@ -55,9 +55,9 @@ static inline void ta_set_timeout(alarm_pool_timer_t *timer, uint alarm_num, int } static inline bool ta_wakes_up_on_or_before(alarm_pool_timer_t *timer, uint alarm_num, int64_t target) { - uint32_t current = timer_time_us_32(timer_hw_from_timer(timer)); - uint32_t time_til_target = (uint32_t) target - current; - uint32_t time_til_alarm = timer_hw_from_timer(timer)->alarm[alarm_num] - current; + int64_t current = (int64_t)timer_time_us_64(timer_hw_from_timer(timer)); + int64_t time_til_target = target - current; + uint32_t time_til_alarm = timer_hw_from_timer(timer)->alarm[alarm_num] - (uint32_t)current; return time_til_alarm <= time_til_target; } diff --git a/test/pico_time_test/pico_time_test.c b/test/pico_time_test/pico_time_test.c index 8092abbef..5ce013df5 100644 --- a/test/pico_time_test/pico_time_test.c +++ b/test/pico_time_test/pico_time_test.c @@ -76,6 +76,7 @@ int issue_195_test(void); int issue_1812_test(void); int issue_1953_test(void); int issue_2118_test(void); +int issue_2186_test(void); int main() { setup_default_uart(); @@ -250,6 +251,8 @@ int main() { issue_2118_test(); + issue_2186_test(); + PICOTEST_END_TEST(); } @@ -311,8 +314,8 @@ int issue_1953_test(void) { repeating_timer_t timer1; repeating_timer_t timer2; - assert(add_repeating_timer_us(10, timer_callback_issue_1953, NULL, &timer1)); - assert(add_repeating_timer_us(100, timer_callback_issue_1953, NULL, &timer2)); + hard_assert(add_repeating_timer_us(10, timer_callback_issue_1953, NULL, &timer1)); + hard_assert(add_repeating_timer_us(100, timer_callback_issue_1953, NULL, &timer2)); int iterations = 0; while(iterations < 100) { @@ -364,3 +367,13 @@ int issue_2118_test(void) { PICOTEST_END_SECTION(); return 0; } + +int issue_2186_test(void) { + PICOTEST_START_SECTION("Issue #2186 defect - ta_wakes_up_on_or_before"); + + hard_assert(best_effort_wfe_or_timeout(get_absolute_time() - 1)); + hard_assert(best_effort_wfe_or_timeout(get_absolute_time() - 1)); // this will lockup without the fix - wfe which never happens + + PICOTEST_END_SECTION(); + return 0; +} From 5022582ec70538ac2c2f4c7b0fe32b579c5c38f0 Mon Sep 17 00:00:00 2001 From: Arkin Solomon Date: Mon, 20 Jan 2025 11:56:58 -0500 Subject: [PATCH 016/224] Fix brief #2196 (#2197) --- src/rp2_common/pico_aon_timer/include/pico/aon_timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_aon_timer/include/pico/aon_timer.h b/src/rp2_common/pico_aon_timer/include/pico/aon_timer.h index 768c79827..b3095d8e0 100644 --- a/src/rp2_common/pico_aon_timer/include/pico/aon_timer.h +++ b/src/rp2_common/pico_aon_timer/include/pico/aon_timer.h @@ -239,7 +239,7 @@ aon_timer_alarm_handler_t aon_timer_enable_alarm_calendar(const struct tm *tm, a void aon_timer_disable_alarm(void); /** - * \brief Disable the currently enabled AON timer alarm if any + * \brief Check if the AON timer is running * \ingroup pico_aon_timer * \return true if the AON timer is running */ From 863f5446e10d879758d2fbfaa756d3769bf33e15 Mon Sep 17 00:00:00 2001 From: Gregory Neverov <42853258+gneverov@users.noreply.github.com> Date: Mon, 20 Jan 2025 09:01:03 -0800 Subject: [PATCH 017/224] Follow-up to #1795 (#2177) Address the review comment to fix conditional compilation syntax: https://github.com/raspberrypi/pico-sdk/pull/1795#pullrequestreview-2444179188 --- src/rp2_common/pico_clib_interface/picolibc_interface.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_clib_interface/picolibc_interface.c b/src/rp2_common/pico_clib_interface/picolibc_interface.c index 8f7770ab8..728e93a56 100644 --- a/src/rp2_common/pico_clib_interface/picolibc_interface.c +++ b/src/rp2_common/pico_clib_interface/picolibc_interface.c @@ -39,8 +39,9 @@ static int picolibc_putc(char c, __unused FILE *file) { static int picolibc_getc(__unused FILE *file) { #if LIB_PICO_STDIO return stdio_getchar(); -#endif +#else return -1; +#endif } static int picolibc_flush(__unused FILE *file) { From 09482ed7a0cc25b0bb0be710bee3d98f85033961 Mon Sep 17 00:00:00 2001 From: gazzyt Date: Mon, 20 Jan 2025 20:42:46 +0100 Subject: [PATCH 018/224] Disable irq before removing handler in cyw43_irq_deinit (#2185) --- src/rp2_common/pico_cyw43_driver/cyw43_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c index 11d2652e0..308d649d9 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c @@ -63,8 +63,8 @@ uint32_t cyw43_irq_deinit(__unused void *param) { #ifndef NDEBUG assert(get_core_num() == async_context_core_num(cyw43_async_context)); #endif - gpio_remove_raw_irq_handler(CYW43_PIN_WL_HOST_WAKE, cyw43_gpio_irq_handler); cyw43_set_irq_enabled(false); + gpio_remove_raw_irq_handler(CYW43_PIN_WL_HOST_WAKE, cyw43_gpio_irq_handler); return 0; } From 73d007f1a4af6a6928fc07b885660f3aeeb7317e Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:45:06 +0000 Subject: [PATCH 019/224] Update cyw43 driver. (#2199) * Update cyw43 driver. Fixes #2153 * Update cyw43 in bazel --- MODULE.bazel | 2 +- lib/cyw43-driver | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 15275876e..f3b1bbe2e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -106,7 +106,7 @@ new_git_repository( new_git_repository( name = "cyw43-driver", build_file = "//src/rp2_common/pico_cyw43_driver:cyw43-driver.BUILD", - commit = "cf924bb04c8984675ca0fc2178f082e404e048c3", # keep-in-sync-with-submodule: lib/cyw43-driver + commit = "c1075d4bc440422cf2b2fd12c64a1f53f77660ee", # keep-in-sync-with-submodule: lib/cyw43-driver remote = "https://github.com/georgerobotics/cyw43-driver.git", ) diff --git a/lib/cyw43-driver b/lib/cyw43-driver index cf924bb04..c1075d4bc 160000 --- a/lib/cyw43-driver +++ b/lib/cyw43-driver @@ -1 +1 @@ -Subproject commit cf924bb04c8984675ca0fc2178f082e404e048c3 +Subproject commit c1075d4bc440422cf2b2fd12c64a1f53f77660ee From c54475da6ffb2394f4dc8af0ae74447ff72d09ee Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:45:51 +0000 Subject: [PATCH 020/224] Remove deprecated uses of FetchContent_Populate (#2169) * Remove deprecated uses of FetchContent_Populate Cannot use MakeAvailable as the files shouldn't be added to the build, so instead uses the full signature for FetchContent_Populate Fixes #2124 * Fix GIT_SUBMODULES_RECURSE for older CMake versions --- external/pico_sdk_import.cmake | 47 ++++++++++++++++++++++------------ tools/Findpicotool.cmake | 27 +++++++++---------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/external/pico_sdk_import.cmake b/external/pico_sdk_import.cmake index a0721d0d1..d625cdff3 100644 --- a/external/pico_sdk_import.cmake +++ b/external/pico_sdk_import.cmake @@ -40,25 +40,40 @@ if (NOT PICO_SDK_PATH) if (PICO_SDK_FETCH_FROM_GIT_PATH) get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") endif () - # GIT_SUBMODULES_RECURSE was added in 3.17 - if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") - FetchContent_Declare( - pico_sdk - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} - GIT_SUBMODULES_RECURSE FALSE - ) - else () - FetchContent_Declare( - pico_sdk - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} - ) - endif () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + ) if (NOT pico_sdk) message("Downloading Raspberry Pi Pico SDK") - FetchContent_Populate(pico_sdk) + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Populate( + pico_sdk + QUIET + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + GIT_SUBMODULES_RECURSE FALSE + + SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src + BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build + SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild + ) + else () + FetchContent_Populate( + pico_sdk + QUIET + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + + SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src + BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build + SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild + ) + endif () + set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) endif () set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) diff --git a/tools/Findpicotool.cmake b/tools/Findpicotool.cmake index e7ecbcea9..e5bfaeaac 100644 --- a/tools/Findpicotool.cmake +++ b/tools/Findpicotool.cmake @@ -15,10 +15,12 @@ if (NOT TARGET picotool) endif () include(FetchContent) - set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) if (PICOTOOL_FETCH_FROM_GIT_PATH) - get_filename_component(FETCHCONTENT_BASE_DIR "${PICOTOOL_FETCH_FROM_GIT_PATH}" ABSOLUTE) + get_filename_component(picotool_INSTALL_DIR "${PICOTOOL_FETCH_FROM_GIT_PATH}" ABSOLUTE) + else () + get_filename_component(picotool_INSTALL_DIR "${FETCHCONTENT_BASE_DIR}" ABSOLUTE) endif () + set(picotool_INSTALL_DIR ${picotool_INSTALL_DIR} CACHE PATH "Directory where picotool has been installed" FORCE) set(picotool_BUILD_TARGET picotoolBuild) set(picotool_TARGET picotool) @@ -32,20 +34,15 @@ if (NOT TARGET picotool) ) endif() - FetchContent_Declare( - picotool - GIT_REPOSITORY https://github.com/raspberrypi/picotool.git - GIT_TAG develop - GIT_PROGRESS true - ) + message("Downloading Picotool") + FetchContent_Populate(picotool QUIET + GIT_REPOSITORY https://github.com/raspberrypi/picotool.git + GIT_TAG develop - FetchContent_GetProperties(picotool) - set(picotool_INSTALL_DIR ${FETCHCONTENT_BASE_DIR} CACHE PATH "Directory where picotool has been installed" FORCE) - if (NOT picotool_POPULATED) - message("Downloading Picotool") - FetchContent_Populate(picotool) - endif () - set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + SOURCE_DIR ${picotool_INSTALL_DIR}/picotool-src + BINARY_DIR ${picotool_INSTALL_DIR}/picotool-build + SUBBUILD_DIR ${picotool_INSTALL_DIR}/picotool-subbuild + ) add_custom_target(picotoolForceReconfigure ${CMAKE_COMMAND} -E touch_nocreate "${CMAKE_SOURCE_DIR}/CMakeLists.txt" From a62d17cb42fa3d9785589284c198469a877ce44e Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Sun, 26 Jan 2025 13:30:56 -0600 Subject: [PATCH 021/224] Add PASSED/FAILED output to cmsis_test.c --- test/cmsis_test/cmsis_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cmsis_test/cmsis_test.c b/test/cmsis_test/cmsis_test.c index 6e9fdf62c..7c8f9baa4 100644 --- a/test/cmsis_test/cmsis_test.c +++ b/test/cmsis_test/cmsis_test.c @@ -35,5 +35,7 @@ int main(void) { irq_set_enabled(DMA_IRQ_0_IRQn, true); irq_set_pending(DMA_IRQ_0_IRQn); puts(irq_handler_called ? "SUCCESS" : "FAILURE"); - return !(pendsv_called && irq_handler_called); + bool ok = pendsv_called && irq_handler_called; + puts(ok ? "PASSED" : "FAILED"); + return !ok; } From f20663cb7feeaec6fed529cf30ba470572d95e56 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Sun, 26 Jan 2025 13:31:51 -0600 Subject: [PATCH 022/224] Fix pico_divider_nesting_test.c on RP2350 - was broken due to running faster and hence further on RP2350, breaking a check which was wrong for larger inputs --- test/pico_divider_test/pico_divider_nesting_test.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/pico_divider_test/pico_divider_nesting_test.c b/test/pico_divider_test/pico_divider_nesting_test.c index dfcdafc42..4e1915df8 100644 --- a/test/pico_divider_test/pico_divider_nesting_test.c +++ b/test/pico_divider_test/pico_divider_nesting_test.c @@ -47,7 +47,15 @@ bool timer_callback(repeating_timer_t *t) { // if (fabs(fz - (fa * 11.0f + fb)) > 1e-9f) { // FAILED(); // } - if (fabsf(fz - fa * 11.0f) > 1e-3f) { + union { + float f; + uint32_t i; + } fi, fi2; + fi.f = fabsf(fz - fa * 11.0f); + // make a float which is close to 1ulp + fi2.i = fi.i & 0x7f800000u; + fi2.i++; + if (fi.f > fi2.f) { FAILED(); } double dz = z; @@ -258,4 +266,3 @@ int main() { printf("PASSED\n"); return 0; } - From 9f95a46e3107612065503d48022f0f5fb062f8cd Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 29 Jan 2025 09:13:51 -0600 Subject: [PATCH 023/224] fix pico_time_test.c compile on native (#2207) --- test/pico_time_test/pico_time_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/pico_time_test/pico_time_test.c b/test/pico_time_test/pico_time_test.c index 5ce013df5..82c3d825f 100644 --- a/test/pico_time_test/pico_time_test.c +++ b/test/pico_time_test/pico_time_test.c @@ -8,7 +8,9 @@ #include #include #include +#if PICO_ON_DEVICE #include "hardware/clocks.h" +#endif #include "pico/stdlib.h" #include "pico/test.h" // Include sys/types.h before inttypes.h to work around issue with @@ -342,10 +344,12 @@ static bool timer_callback_issue_2118(repeating_timer_t *rt) { int issue_2118_test(void) { PICOTEST_START_SECTION("Issue #2118 defect - failure to set an alarm"); +#if PICO_ON_DEVICE // this problem only happens when running the clock fast as it requires the time between // alarm_pool_irq_handler handling an alarm and setting the next alarm to be <1us set_sys_clock_hz(200 * MHZ, true); setup_default_uart(); +#endif alarm_pool_t *pool = alarm_pool_create(2, 1); repeating_timer_t timer; @@ -359,10 +363,11 @@ int issue_2118_test(void) { PICOTEST_CHECK(counter_2118 >= 100, "Repeating timer failure"); alarm_pool_destroy(pool); +#if PICO_ON_DEVICE hard_assert(timer_hw->armed == 0); // check destroying the pool unarms its timer - set_sys_clock_hz(SYS_CLK_HZ, true); setup_default_uart(); +#endif PICOTEST_END_SECTION(); return 0; From 3ba9534c0314879a5ea26df6fa1f89dd35b0d556 Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Wed, 29 Jan 2025 16:15:36 +0100 Subject: [PATCH 024/224] update tinyusb to 0.18 (#2215) * update tinyusb to 0.18 * update tinyusb also for bazel --- MODULE.bazel | 2 +- lib/tinyusb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index f3b1bbe2e..79419199a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -90,7 +90,7 @@ new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl" new_git_repository( name = "tinyusb", build_file = "//src/rp2_common/tinyusb:tinyusb.BUILD", - commit = "5217cee5de4cd555018da90f9f1bcc87fb1c1d3a", # keep-in-sync-with-submodule: lib/tinyusb + commit = "86ad6e56c1700e85f1c5678607a762cfe3aa2f47", # keep-in-sync-with-submodule: lib/tinyusb remote = "https://github.com/hathach/tinyusb.git", ) diff --git a/lib/tinyusb b/lib/tinyusb index 5217cee5d..86ad6e56c 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 5217cee5de4cd555018da90f9f1bcc87fb1c1d3a +Subproject commit 86ad6e56c1700e85f1c5678607a762cfe3aa2f47 From 524716f1b9221c867dde553deea381051049632c Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:17:50 +0000 Subject: [PATCH 025/224] Fix unreliable writes to cyw43. (#2209) We use a pio and dma to write to the cyw43 chip using spi. Normally you write an address and then read the data from that address, so the pio program does does a write then read. If you just want to write data in the case of uploading firmware we use the fdebug_tx_stall flag to work out if the pio has stalled waiting to write more data. The theory is that this flag will also get set if the bus is busy. So we mistakenly think a write to cyw43 has completed. Wait for the dma write to complete before waiting for the pio to stall. Fixes #2206 --- src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c b/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c index bcc7284f1..787eeff5d 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c @@ -308,11 +308,13 @@ int cyw43_spi_transfer(cyw43_int_t *self, const uint8_t *tx, size_t tx_length, u dma_channel_configure(bus_data->dma_out, &out_config, &bus_data->pio->txf[bus_data->pio_sm], tx, tx_length / 4, true); + pio_sm_set_enabled(bus_data->pio, bus_data->pio_sm, true); + dma_channel_wait_for_finish_blocking(bus_data->dma_out); + uint32_t fdebug_tx_stall = 1u << (PIO_FDEBUG_TXSTALL_LSB + bus_data->pio_sm); bus_data->pio->fdebug = fdebug_tx_stall; - pio_sm_set_enabled(bus_data->pio, bus_data->pio_sm, true); while (!(bus_data->pio->fdebug & fdebug_tx_stall)) { - tight_loop_contents(); // todo timeout + tight_loop_contents(); } __compiler_memory_barrier(); pio_sm_set_enabled(bus_data->pio, bus_data->pio_sm, false); From 700f861eac4952c0e95071b7d2ff1b0bf5fc7482 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:20:42 +0000 Subject: [PATCH 026/224] Update btstack 1.6.2 (#2202) * Update btstack v1.6.2 plus one commit * Update bazel for btstack * Build changes for btstack v1.6.2 --- MODULE.bazel | 2 +- lib/btstack | 2 +- src/rp2_common/pico_btstack/CMakeLists.txt | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 79419199a..9e2bb30f7 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -98,7 +98,7 @@ new_git_repository( new_git_repository( name = "btstack", build_file = "//src/rp2_common/pico_btstack:btstack.BUILD", - commit = "2b49e57bd1fae85ac32ac1f41cdb7c794de335f6", # keep-in-sync-with-submodule: lib/btstack + commit = "501e6d2b86e6c92bfb9c390bcf55709938e25ac1", # keep-in-sync-with-submodule: lib/btstack remote = "https://github.com/bluekitchen/btstack.git", ) diff --git a/lib/btstack b/lib/btstack index 2b49e57bd..501e6d2b8 160000 --- a/lib/btstack +++ b/lib/btstack @@ -1 +1 @@ -Subproject commit 2b49e57bd1fae85ac32ac1f41cdb7c794de335f6 +Subproject commit 501e6d2b86e6c92bfb9c390bcf55709938e25ac1 diff --git a/src/rp2_common/pico_btstack/CMakeLists.txt b/src/rp2_common/pico_btstack/CMakeLists.txt index c622cacf5..010cc9e39 100644 --- a/src/rp2_common/pico_btstack/CMakeLists.txt +++ b/src/rp2_common/pico_btstack/CMakeLists.txt @@ -107,6 +107,13 @@ if (EXISTS ${PICO_BTSTACK_PATH}/${BTSTACK_TEST_PATH}) ENABLE_BLE=1 ) + # Added in v1.6.2 + if (EXISTS ${PICO_BTSTACK_PATH}/src/hci_event_builder.c) + target_sources(pico_btstack_ble INTERFACE + ${PICO_BTSTACK_PATH}/src/hci_event_builder.c + ) + endif() + pico_add_library(pico_btstack_classic) target_sources(pico_btstack_classic INTERFACE ${PICO_BTSTACK_PATH}/src/classic/a2dp.c @@ -161,6 +168,13 @@ if (EXISTS ${PICO_BTSTACK_PATH}/${BTSTACK_TEST_PATH}) ENABLE_CLASSIC=1 ) + # Added in v1.6.2 + if (EXISTS ${PICO_BTSTACK_PATH}/src/classic/obex_srm_client.c) + target_sources(pico_btstack_classic INTERFACE + ${PICO_BTSTACK_PATH}/src/classic/obex_srm_client.c + ) + endif() + pico_add_library(pico_btstack_mesh) target_sources(pico_btstack_mesh INTERFACE ${PICO_BTSTACK_PATH}/src/mesh/adv_bearer.c From d1a1c9f9fc0c759ff0cd23e97f3b065b18e14aa0 Mon Sep 17 00:00:00 2001 From: Wu Haotian Date: Wed, 29 Jan 2025 23:31:06 +0800 Subject: [PATCH 027/224] Support multiple .pio file in pico_generate_pio_header (#2188) --- tools/CMakeLists.txt | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index aa7dbcb00..6ebe44e5f 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -155,7 +155,7 @@ endfunction() # Generate pio header and include it in the build # PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build -function(pico_generate_pio_header TARGET PIO) +function(pico_generate_pio_header TARGET) pico_init_pioasm() cmake_parse_arguments(pico_generate_pio_header "" "OUTPUT_FORMAT;OUTPUT_DIR" "" ${ARGN} ) @@ -173,24 +173,31 @@ function(pico_generate_pio_header TARGET PIO) else() set(HEADER_DIR "${CMAKE_CURRENT_BINARY_DIR}") endif() - get_filename_component(PIO_NAME ${PIO} NAME) - set(HEADER "${HEADER_DIR}/${PIO_NAME}.h") - #message("Will generate ${HEADER}") - get_filename_component(HEADER_GEN_TARGET ${PIO} NAME_WE) - set(HEADER_GEN_TARGET "${TARGET}_${HEADER_GEN_TARGET}_pio_h") - add_custom_target(${HEADER_GEN_TARGET} DEPENDS ${HEADER}) + # Loop through each PIO file + foreach(PIO ${pico_generate_pio_header_UNPARSED_ARGUMENTS}) + get_filename_component(PIO_NAME ${PIO} NAME) + set(HEADER "${HEADER_DIR}/${PIO_NAME}.h") + #message("Will generate ${HEADER}") + get_filename_component(HEADER_GEN_TARGET ${PIO} NAME_WE) + set(HEADER_GEN_TARGET "${TARGET}_${HEADER_GEN_TARGET}_pio_h") + + add_custom_target(${HEADER_GEN_TARGET} DEPENDS ${HEADER}) + + if (PICO_PIO_VERSION) + set(VERSION_STRING "${PICO_PIO_VERSION}") + else() + set(VERSION_STRING "0") + endif() + + add_custom_command(OUTPUT ${HEADER} + DEPENDS ${PIO} + COMMAND pioasm -o ${OUTPUT_FORMAT} -v ${VERSION_STRING} ${PIO} ${HEADER} + VERBATIM) + + add_dependencies(${TARGET} ${HEADER_GEN_TARGET}) + endforeach() - if (PICO_PIO_VERSION) - set(VERSION_STRING "${PICO_PIO_VERSION}") - else() - set(VERSION_STRING "0") - endif() - add_custom_command(OUTPUT ${HEADER} - DEPENDS ${PIO} - COMMAND pioasm -o ${OUTPUT_FORMAT} -v ${VERSION_STRING} ${PIO} ${HEADER} - VERBATIM) - add_dependencies(${TARGET} ${HEADER_GEN_TARGET}) get_target_property(target_type ${TARGET} TYPE) if ("INTERFACE_LIBRARY" STREQUAL "${target_type}") target_include_directories(${TARGET} INTERFACE ${HEADER_DIR}) From 25069f54724722370904f332f55875875fccaad7 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 29 Jan 2025 16:35:20 +0100 Subject: [PATCH 028/224] btstack: configure incoming pre-buffer for cyw43 driver (#2165) --- .../btstack_hci_transport_cyw43.c | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/rp2_common/pico_cyw43_driver/btstack_hci_transport_cyw43.c b/src/rp2_common/pico_cyw43_driver/btstack_hci_transport_cyw43.c index ecfcf3dbe..b77ea0662 100644 --- a/src/rp2_common/pico_cyw43_driver/btstack_hci_transport_cyw43.c +++ b/src/rp2_common/pico_cyw43_driver/btstack_hci_transport_cyw43.c @@ -6,21 +6,35 @@ #include "pico.h" #include "cyw43.h" -#include "hci_transport.h" +#include "btstack_config.h" #include "hci.h" +#include "hci_transport.h" #include "pico/btstack_hci_transport_cyw43.h" #include "pico/btstack_chipset_cyw43.h" +// cyw43_bluetooth_hci_write and cyw43_bluetooth_hci_read require a custom 4-byte packet header in front of the actual HCI packet +// the HCI packet type is stored in the fourth byte of the packet header +#define CYW43_PACKET_HEADER_SIZE 4 + // assert outgoing pre-buffer for cyw43 header is available -#if !defined(HCI_OUTGOING_PRE_BUFFER_SIZE) || (HCI_OUTGOING_PRE_BUFFER_SIZE < 4) -#error HCI_OUTGOING_PRE_BUFFER_SIZE not defined or smaller than 4. Please update btstack_config.h +#if !defined(HCI_OUTGOING_PRE_BUFFER_SIZE) || (HCI_OUTGOING_PRE_BUFFER_SIZE < CYW43_PACKET_HEADER_SIZE) +#error HCI_OUTGOING_PRE_BUFFER_SIZE not defined or smaller than 4 (CYW43_PACKET_HEADER_SIZE) bytes. Please update btstack_config.h #endif // assert outgoing packet fragments are word aligned #if !defined(HCI_ACL_CHUNK_SIZE_ALIGNMENT) || ((HCI_ACL_CHUNK_SIZE_ALIGNMENT & 3) != 0) -#error HCI_ACL_CHUNK_SIZE_ALIGNMENT not defined or not a multiply of 4. Please update btstack_config.h +#error HCI_ACL_CHUNK_SIZE_ALIGNMENT not defined or not a multiple of 4. Please update btstack_config.h #endif +// ensure incoming pre-buffer for cyw43 header is available (defaults from btstack/src/hci.h) +#if HCI_INCOMING_PRE_BUFFER_SIZE < CYW43_PACKET_HEADER_SIZE +#undef HCI_INCOMING_PRE_BUFFER_SIZE +#define HCI_INCOMING_PRE_BUFFER_SIZE CYW43_PACKET_HEADER_SIZE +#endif + +// ensure buffer for cyw43_bluetooth_hci_read starts word aligned (word align pre buffer) +#define HCI_INCOMING_PRE_BUFFER_SIZE_ALIGNED ((HCI_INCOMING_PRE_BUFFER_SIZE + 3) & ~3) + #define BT_DEBUG_ENABLED 0 #if BT_DEBUG_ENABLED #define BT_DEBUG(...) CYW43_PRINTF(__VA_ARGS__) @@ -31,9 +45,12 @@ // Callback when we have data static void (*hci_transport_cyw43_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size) = NULL; -// Incoming packet buffer - cyw43 packet header (incl packet type) + incoming pre buffer + max(acl header + acl payload, event header + event data) +// The incoming packet buffer consist of a pre-buffer and the actual HCI packet +// For the call to cyw43_bluetooth_hci_read, the last 4 bytes (CY43_PACKET_HEADER_SIZE) of the pre-buffer is used for the CYW43 packet header +// After that, only the actual HCI packet is forwarded to BTstack, which expects HCI_INCOMING_PACKET_BUFFER_SIZE of pre-buffer bytes for its own use. __attribute__((aligned(4))) -static uint8_t hci_packet_with_pre_buffer[4 + HCI_INCOMING_PRE_BUFFER_SIZE + HCI_INCOMING_PACKET_BUFFER_SIZE ]; +static uint8_t hci_packet_with_pre_buffer[HCI_INCOMING_PRE_BUFFER_SIZE_ALIGNED + HCI_INCOMING_PACKET_BUFFER_SIZE ]; +static uint8_t * cyw43_receive_buffer = &hci_packet_with_pre_buffer[HCI_INCOMING_PRE_BUFFER_SIZE_ALIGNED - CYW43_PACKET_HEADER_SIZE]; static btstack_data_source_t transport_data_source; static bool hci_transport_ready; @@ -97,8 +114,8 @@ static int hci_transport_cyw43_can_send_now(uint8_t packet_type) { static int hci_transport_cyw43_send_packet(uint8_t packet_type, uint8_t *packet, int size) { // store packet type before actual data and increase size // This relies on HCI_OUTGOING_PRE_BUFFER_SIZE being set - uint8_t *buffer = &packet[-4]; - uint32_t buffer_size = size + 4; + uint8_t *buffer = &packet[-CYW43_PACKET_HEADER_SIZE]; + uint32_t buffer_size = size + CYW43_PACKET_HEADER_SIZE; buffer[3] = packet_type; CYW43_THREAD_ENTER @@ -143,10 +160,10 @@ static void hci_transport_cyw43_process(void) { uint32_t loop_count = 0; #endif do { - int err = cyw43_bluetooth_hci_read(hci_packet_with_pre_buffer, sizeof(hci_packet_with_pre_buffer), &len); + int err = cyw43_bluetooth_hci_read(cyw43_receive_buffer, CYW43_PACKET_HEADER_SIZE + HCI_INCOMING_PACKET_BUFFER_SIZE , &len); BT_DEBUG("bt in len=%lu err=%d\n", len, err); if (err == 0 && len > 0) { - hci_transport_cyw43_packet_handler(hci_packet_with_pre_buffer[3], hci_packet_with_pre_buffer + 4, len - 4); + hci_transport_cyw43_packet_handler(cyw43_receive_buffer[3], &cyw43_receive_buffer[CYW43_PACKET_HEADER_SIZE], len - CYW43_PACKET_HEADER_SIZE); has_work = true; } else { has_work = false; From 3d746b3fa7ea7aa5ed80f66e47d54850e96da1f5 Mon Sep 17 00:00:00 2001 From: Dryw Wade Date: Wed, 29 Jan 2025 08:35:47 -0700 Subject: [PATCH 029/224] Add SparkFun IoT Node LoRaWAN board (#2143) --- .../boards/sparkfun_iotnode_lorawan_rp2350.h | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/boards/include/boards/sparkfun_iotnode_lorawan_rp2350.h diff --git a/src/boards/include/boards/sparkfun_iotnode_lorawan_rp2350.h b/src/boards/include/boards/sparkfun_iotnode_lorawan_rp2350.h new file mode 100644 index 000000000..5bea33cc4 --- /dev/null +++ b/src/boards/include/boards/sparkfun_iotnode_lorawan_rp2350.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- +// Board definition for the SparkFun IoT Node LoRaWAN +// +// This header may be included by other board headers as "boards/sparkfun_iotnode_lorawan_rp2350.h" + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_SPARKFUN_IOTNODE_LORAWAN_RP2350_H +#define _BOARDS_SPARKFUN_IOTNODE_LORAWAN_RP2350_H + +// For board detection +#define SPARKFUN_IOTNODE_LORAWAN_RP2350 + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 18 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 19 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 25 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 20 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 21 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 14 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 15 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif From 6c06f90bfef588f371a5983ac3a788003c74b834 Mon Sep 17 00:00:00 2001 From: nilswiersma <7534520+nilswiersma@users.noreply.github.com> Date: Fri, 31 Jan 2025 18:41:07 +0100 Subject: [PATCH 030/224] Release the lock in mbedtls_sha256_free if it was not released already (#2105) * Release the lock in mbedtls_sha256_free if it was not released already. Requires making pico_sha256_unlock include-able. Fixes #2103. * addres lock release API comment * Fix description of pico_sha256_cleanup --------- Co-authored-by: nils Co-authored-by: Peter Harper --- src/rp2_common/pico_mbedtls/pico_mbedtls.c | 1 + src/rp2_common/pico_sha256/include/pico/sha256.h | 10 ++++++++++ src/rp2_common/pico_sha256/sha256.c | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/rp2_common/pico_mbedtls/pico_mbedtls.c b/src/rp2_common/pico_mbedtls/pico_mbedtls.c index 3279a42d1..853d97cdf 100644 --- a/src/rp2_common/pico_mbedtls/pico_mbedtls.c +++ b/src/rp2_common/pico_mbedtls/pico_mbedtls.c @@ -36,6 +36,7 @@ void mbedtls_sha256_init(__unused mbedtls_sha256_context *ctx) { } void mbedtls_sha256_free(__unused mbedtls_sha256_context *ctx) { + pico_sha256_cleanup(ctx); } int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224) { diff --git a/src/rp2_common/pico_sha256/include/pico/sha256.h b/src/rp2_common/pico_sha256/include/pico/sha256.h index 80aa5af37..ab0c81ad7 100644 --- a/src/rp2_common/pico_sha256/include/pico/sha256.h +++ b/src/rp2_common/pico_sha256/include/pico/sha256.h @@ -58,6 +58,16 @@ typedef struct pico_sha256_state { size_t total_data_size; } pico_sha256_state_t; +/*! \brief Release the internal lock on the SHA-256 hardware + * \ingroup pico_sha256 + * + * Release the internal lock on the SHA-256 hardware. + * Does nothing if the internal lock was not claimed. + * + * @param state A pointer to a pico_sha256_state_t instance + */ +void pico_sha256_cleanup(pico_sha256_state_t *state); + /*! \brief Start a SHA-256 calculation returning immediately with an error if the SHA-256 hardware is not available * \ingroup pico_sha256 * diff --git a/src/rp2_common/pico_sha256/sha256.c b/src/rp2_common/pico_sha256/sha256.c index e0cc73974..91009c804 100644 --- a/src/rp2_common/pico_sha256/sha256.c +++ b/src/rp2_common/pico_sha256/sha256.c @@ -30,6 +30,12 @@ void __weak pico_sha256_unlock(pico_sha256_state_t *state) { state->locked = false; } +void pico_sha256_cleanup(pico_sha256_state_t *state) { + if (state->locked) { + pico_sha256_unlock(state); + } +} + int pico_sha256_try_start(pico_sha256_state_t *state, enum sha256_endianness endianness, bool use_dma) { memset(state, 0, sizeof(*state)); if (!pico_sha256_lock(state)) return PICO_ERROR_RESOURCE_IN_USE; From d7f658245961bc9af7d9913b4d7fea437dab253a Mon Sep 17 00:00:00 2001 From: Richard Hulme Date: Sun, 2 Feb 2025 18:44:17 +0100 Subject: [PATCH 031/224] Declare platform.h functions with C linkage (#2218) The platform.h headers for both RP2040 and RP2350 need 'extern "C"' declarations when included from C++ code or 'rp2040_chip_version' and 'rp2350_chip_version' won't be found by the linker. --- src/rp2040/pico_platform/include/pico/platform.h | 8 ++++++++ src/rp2350/pico_platform/include/pico/platform.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/rp2040/pico_platform/include/pico/platform.h b/src/rp2040/pico_platform/include/pico/platform.h index 47aa119a7..5c157f532 100644 --- a/src/rp2040/pico_platform/include/pico/platform.h +++ b/src/rp2040/pico_platform/include/pico/platform.h @@ -77,6 +77,10 @@ #ifndef __ASSEMBLER__ +#ifdef __cplusplus +extern "C" { +#endif + /*! \brief No-op function for the body of tight loops * \ingroup pico_platform * @@ -210,6 +214,10 @@ return a; (__builtin_popcount(b) >= 2 ? __mul_instruction(a,b) : (a)*(b)), \ (a)*(b)) +#ifdef __cplusplus +} +#endif + #endif // __ASSEMBLER__ #endif diff --git a/src/rp2350/pico_platform/include/pico/platform.h b/src/rp2350/pico_platform/include/pico/platform.h index 24fec75bb..35a6a0bd6 100644 --- a/src/rp2350/pico_platform/include/pico/platform.h +++ b/src/rp2350/pico_platform/include/pico/platform.h @@ -70,6 +70,10 @@ #ifndef __ASSEMBLER__ +#ifdef __cplusplus +extern "C" { +#endif + /*! \brief No-op function for the body of tight loops * \ingroup pico_platform * @@ -281,6 +285,10 @@ __force_inline static int32_t __mul_instruction(int32_t a, int32_t b) { (__builtin_popcount(b) >= 2 ? __mul_instruction(a,b) : (a)*(b)), \ (a)*(b)) +#ifdef __cplusplus +} +#endif + #endif // __ASSEMBLER__ #endif From 0c2de5dc0c69e77fc34ac78994b0026c2284abc9 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 3 Feb 2025 11:23:56 -0600 Subject: [PATCH 032/224] Eat PATH argument to pico_generate_pio_header which was ignored before supporting multi-target on pico_generate_pio_header (#2221) --- tools/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 6ebe44e5f..371756664 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -157,7 +157,8 @@ endfunction() # PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build function(pico_generate_pio_header TARGET) pico_init_pioasm() - cmake_parse_arguments(pico_generate_pio_header "" "OUTPUT_FORMAT;OUTPUT_DIR" "" ${ARGN} ) + # Note that PATH is not a valid argument but was previously ignored (and happens to be passed by pico-extras) + cmake_parse_arguments(pico_generate_pio_header "" "OUTPUT_FORMAT;OUTPUT_DIR;PATH" "" ${ARGN} ) if (pico_generate_pio_header_OUTPUT_FORMAT) set(OUTPUT_FORMAT "${pico_generate_pio_header_OUTPUT_FORMAT}") From ccbd07c75857ce936f5d480c2d576428b832df81 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 3 Feb 2025 11:25:03 -0600 Subject: [PATCH 033/224] add extra assertions to pio.h (#2211) * add extra assertions to pio.h * add another assert * minor clarifications --- src/rp2_common/hardware_pio/include/hardware/pio.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_pio/include/hardware/pio.h b/src/rp2_common/hardware_pio/include/hardware/pio.h index 9d1f5ce09..b11733092 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio.h @@ -172,6 +172,9 @@ typedef pio_hw_t *PIO; */ #ifndef PIO_NUM static_assert(PIO1_BASE - PIO0_BASE == (1u << 20), "hardware layout mismatch"); +#if NUM_PIOS > 2 +static_assert(PIO2_BASE - PIO0_BASE == (2u << 20), "hardware layout mismatch"); +#endif #define PIO_NUM(pio) (((uintptr_t)(pio) - PIO0_BASE) >> 20) #endif @@ -185,6 +188,9 @@ static_assert(PIO1_BASE - PIO0_BASE == (1u << 20), "hardware layout mismatch"); */ #ifndef PIO_INSTANCE static_assert(PIO1_BASE - PIO0_BASE == (1u << 20), "hardware layout mismatch"); +#if NUM_PIOS > 2 +static_assert(PIO2_BASE - PIO0_BASE == (2u << 20), "hardware layout mismatch"); +#endif #define PIO_INSTANCE(instance) ((pio_hw_t *)(PIO0_BASE + (instance) * (1u << 20))) #endif @@ -214,8 +220,13 @@ static_assert(DREQ_PIO0_TX1 == DREQ_PIO0_TX0 + 1, ""); static_assert(DREQ_PIO0_TX2 == DREQ_PIO0_TX0 + 2, ""); static_assert(DREQ_PIO0_TX3 == DREQ_PIO0_TX0 + 3, ""); static_assert(DREQ_PIO0_RX0 == DREQ_PIO0_TX0 + NUM_PIO_STATE_MACHINES, ""); +static_assert(DREQ_PIO1_TX0 == DREQ_PIO0_RX0 + NUM_PIO_STATE_MACHINES, ""); static_assert(DREQ_PIO1_RX0 == DREQ_PIO1_TX0 + NUM_PIO_STATE_MACHINES, ""); -#define PIO_DREQ_NUM(pio, sm, is_tx) ((sm) + (((is_tx) ? 0 : NUM_PIO_STATE_MACHINES) + PIO_NUM(pio) * (DREQ_PIO1_TX0 - DREQ_PIO0_TX0))) +#if NUM_PIOS > 2 +static_assert(DREQ_PIO2_TX0 == DREQ_PIO1_RX0 + NUM_PIO_STATE_MACHINES, ""); +static_assert(DREQ_PIO2_RX0 == DREQ_PIO2_TX0 + NUM_PIO_STATE_MACHINES, ""); +#endif +#define PIO_DREQ_NUM(pio, sm, is_tx) (DREQ_PIO0_TX0 + (sm) + (((is_tx) ? 0 : NUM_PIO_STATE_MACHINES) + PIO_NUM(pio) * (DREQ_PIO1_TX0 - DREQ_PIO0_TX0))) #endif /** From 528858525708a7aeb3aaf16c03d7726ea85f254a Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 3 Feb 2025 12:21:09 -0600 Subject: [PATCH 034/224] add multicore_lockout_victim_deinit. clear lockedout_flag for core1 during core1 reset (#2223) --- .../pico_multicore/include/pico/multicore.h | 7 +++++ src/rp2_common/pico_multicore/multicore.c | 26 ++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/rp2_common/pico_multicore/include/pico/multicore.h b/src/rp2_common/pico_multicore/include/pico/multicore.h index c452b9822..5eb49ddce 100644 --- a/src/rp2_common/pico_multicore/include/pico/multicore.h +++ b/src/rp2_common/pico_multicore/include/pico/multicore.h @@ -449,6 +449,13 @@ static inline uint multicore_doorbell_irq_num(uint doorbell_num) { */ void multicore_lockout_victim_init(void); +/*! \brief Stop the current core being able to be a "victim" of lockout (i.e. forced to pause in a known state by the other core) + * \ingroup multicore_lockout + * + * This code unhooks the intercore FIFO IRQ, and the FIFO may be used for any other purpose after this. + */ +void multicore_lockout_victim_deinit(void); + /*! \brief Determine if \ref multicore_lockout_victim_init() has been called on the specified core. * \ingroup multicore_lockout * diff --git a/src/rp2_common/pico_multicore/multicore.c b/src/rp2_common/pico_multicore/multicore.c index c495b4ae3..f8f5660db 100644 --- a/src/rp2_common/pico_multicore/multicore.c +++ b/src/rp2_common/pico_multicore/multicore.c @@ -23,12 +23,11 @@ #endif #endif -// note that these are not reset by core reset, however for now, I think people resetting cores -// and then relying on multicore_lockout for that core without re-initializing, is probably -// something we can live with breaking. -// -// whilst we could clear this in core 1 reset path, that doesn't necessarily catch all, -// and means pulling in this array even if multicore_lockout is not used. +// Note that there is no automatic way for us to clear these flags when a particular core is reset, and yet +// we DO ideally want to clear them, as the `multicore_lockout_victim_init()` checks the flag for the current core +// and is a no-op if set. We DO have a new `multicore_lockout_victim_deinit()` method, which can be called in a pinch after +// the reset before calling `multicore_lockout_victim_init()` again, so that is good. We will reset the flag +// for core1 in `multicore_reset_core1()` though as a convenience since most people will use that to reset core 1. static bool lockout_victim_initialized[NUM_CORES]; void multicore_fifo_push_blocking(uint32_t data) { @@ -118,6 +117,9 @@ void multicore_reset_core1(void) { bool enabled = irq_is_enabled(irq_num); irq_set_enabled(irq_num, false); + // Core 1 will be in un-initialized state + lockout_victim_initialized[1] = false; + // Bring core 1 back out of reset. It will drain its own mailbox FIFO, then push // a 0 to our mailbox to tell us it has done this. *power_off_clr = PSM_FRCE_OFF_PROC1_BITS; @@ -243,6 +245,18 @@ void multicore_lockout_victim_init(void) { lockout_victim_initialized[core_num] = true; } +void multicore_lockout_victim_deinit(void) { + uint core_num = get_core_num(); + if (lockout_victim_initialized[core_num]) { + // On platforms other than RP2040, these are actually the same IRQ number + // (each core only sees its own IRQ, always at the same IRQ number). + uint fifo_irq_this_core = SIO_FIFO_IRQ_NUM(core_num); + irq_remove_handler(fifo_irq_this_core, multicore_lockout_handler); + irq_set_enabled(fifo_irq_this_core, false); + lockout_victim_initialized[core_num] = false; + } +} + static bool multicore_lockout_handshake(uint32_t magic, absolute_time_t until) { uint irq_num = SIO_FIFO_IRQ_NUM(get_core_num()); bool enabled = irq_is_enabled(irq_num); From 0d909920f13db7948088b6b04b63f4c4e300beb1 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 4 Feb 2025 11:17:07 -0600 Subject: [PATCH 035/224] clarify clock_configure and make it return the correct value achieved for bad clock inputs (#2225) --- src/rp2_common/hardware_clocks/clocks.c | 4 ++++ .../hardware_clocks/include/hardware/clocks.h | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/hardware_clocks/clocks.c b/src/rp2_common/hardware_clocks/clocks.c index cd76c1354..67db9b76b 100644 --- a/src/rp2_common/hardware_clocks/clocks.c +++ b/src/rp2_common/hardware_clocks/clocks.c @@ -102,6 +102,10 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32 return false; uint32_t div = (uint32_t)((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / freq); + // only clock divider of 1, or >= 2 are supported + if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) { + div = (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB); + } uint32_t actual_freq = (uint32_t) ((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div); clock_configure_internal(clock, src, auxsrc, actual_freq, div); diff --git a/src/rp2_common/hardware_clocks/include/hardware/clocks.h b/src/rp2_common/hardware_clocks/include/hardware/clocks.h index 8fd50a20e..400b6e431 100644 --- a/src/rp2_common/hardware_clocks/include/hardware/clocks.h +++ b/src/rp2_common/hardware_clocks/include/hardware/clocks.h @@ -262,11 +262,18 @@ extern "C" { typedef clock_num_t clock_handle_t; -/*! \brief Configure the specified clock +/*! \brief Configure the specified clock with automatic clock divisor setup * \ingroup hardware_clocks * + * This method allows both the src_frequency of the input clock source AND the desired + * frequency to be specified, and will set the clock divider to achieve the exact or higher frequency + * achievable, with the maximum being the src_freq. + * + * Note: That the clock hardware only support divisors of exactly 1 or 2.0->65535.0 + * * See the tables in the description for details on the possible values for clock sources. * + * * \param clock The clock to configure * \param src The main clock source, can be 0. * \param auxsrc The auxiliary clock source, which depends on which clock is being set. Can be 0 @@ -275,7 +282,7 @@ typedef clock_num_t clock_handle_t; */ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32_t src_freq, uint32_t freq); -/*! \brief Configure the specified clock to use the undividded input source +/*! \brief Configure the specified clock to use the undivided input source * \ingroup hardware_clocks * * See the tables in the description for details on the possible values for clock sources. @@ -287,7 +294,7 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32 */ void clock_configure_undivided(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32_t src_freq); -/*! \brief Configure the specified clock to use the undividded input source +/*! \brief Configure the specified clock to use the undivided input source * \ingroup hardware_clocks * * See the tables in the description for details on the possible values for clock sources. From b51fa1b747e0499da4f48a23c365dc8f5f27b8ad Mon Sep 17 00:00:00 2001 From: Luke Wren Date: Tue, 4 Feb 2025 22:06:56 +0000 Subject: [PATCH 036/224] Mark flash_devinfo_ptr() as RAM code to avoid flash call during flash_range_erase() (#2235) --- src/rp2_common/hardware_flash/flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_flash/flash.c b/src/rp2_common/hardware_flash/flash.c index 26d47a68b..adae07878 100644 --- a/src/rp2_common/hardware_flash/flash.c +++ b/src/rp2_common/hardware_flash/flash.c @@ -288,7 +288,7 @@ void flash_get_unique_id(uint8_t *id_out) { #if !PICO_RP2040 // This is a static symbol because the layout of FLASH_DEVINFO is liable to change from device to // device, so fields must have getters/setters. -static io_rw_16 * flash_devinfo_ptr(void) { +static io_rw_16 * __no_inline_not_in_flash_func(flash_devinfo_ptr)(void) { // Note the lookup returns a pointer to a 32-bit pointer literal in the ROM io_rw_16 **p = (io_rw_16 **) rom_data_lookup_inline(ROM_DATA_FLASH_DEVINFO16_PTR); assert(p); From 7d450bf097c2dd6dd9bcccc5762ab28ed75dbb90 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 4 Feb 2025 16:17:52 -0600 Subject: [PATCH 037/224] add a bunch of verbosity around shared vtables (#2230) --- .../hardware_irq/include/hardware/irq.h | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/rp2_common/hardware_irq/include/hardware/irq.h b/src/rp2_common/hardware_irq/include/hardware/irq.h index 78548ad9b..1ef382d5b 100644 --- a/src/rp2_common/hardware_irq/include/hardware/irq.h +++ b/src/rp2_common/hardware_irq/include/hardware/irq.h @@ -286,6 +286,33 @@ void irq_set_mask_n_enabled(uint n, uint32_t mask, bool enabled); * This method will assert if there is already any sort of interrupt handler installed * for the specified irq number. * + * NOTE: By default, the SDK uses a single shared vector table per core, and the current installed + * IRQ handlers are effectively a linked list starting a vector table entry for a particular IRQ number. + * Therefore, this method (when using the same vector table for both cores) sets the same interrupt handler + * for both cores. + * + * On RP2040 this was never really a cause of any confusion, because it rarely made sense to enable + * the same interrupt number in the NVIC on both cores (see \ref irq_set_enabled()), because the interrupt + * would then fire on both cores, and the interrupt handlers would race. + * + * The problem *does* exist however when dealing with interrupts which are independent on the two cores. + * + * This includes: + * + * * the core local "spare" IRQs + * * on RP2350 the SIO FIFO IRQ which is now the same irq number for both cores (vs RP2040 where it was two) + * + * In the cases where you want to enable the same IRQ on both cores, and both cores are sharing the same vector + * table, you should install the IRQ handler once - it will be used on both cores - and check the core + * number (via \ref get_core_num()) on each core. + * + * NOTE: It is not thread safe to add/remove/handle IRQs for the same irq number in the same vector table + * from both cores concurrently. + * + * NOTE: The SDK defines a PICO_VTABLE_PER_CORE variable indicating whether the two vector tables are separate, + * however as of version 2.1.1 the user cannot set this value, and expect the vector table duplication to be handled + * for them. This functionality will be added in a future SDK version + * * \param num Interrupt number \ref interrupt_nums * \param handler The handler to set. See \ref irq_handler_t * \see irq_add_shared_handler() @@ -316,6 +343,33 @@ irq_handler_t irq_get_exclusive_handler(uint num); * the (total across all IRQs on both cores) maximum (configurable via PICO_MAX_SHARED_IRQ_HANDLERS) number of shared handlers * would be exceeded. * + * NOTE: By default, the SDK uses a single shared vector table per core, and the current installed + * IRQ handlers are effectively a linked list starting a vector table entry for a particular IRQ number. + * Therefore, this method (when using the same vector table for both cores) add the same interrupt handler + * for both cores. + * + * On RP2040 this was never really a cause of any confusion, because it rarely made sense to enable + * the same interrupt number in the NVIC on both cores (see \ref irq_set_enabled()), because the interrupt + * would then fire on both cores, and the interrupt handlers would race. + * + * The problem *does* exist however when dealing with interrupts which are independent on the two cores. + * + * This includes: + * + * * the core local "spare" IRQs + * * on RP2350 the SIO FIFO IRQ which is now the same irq number for both cores (vs RP2040 where it was two) + * + * In the cases where you want to enable the same IRQ on both cores, and both cores are sharing the same vector + * table, you should install the IRQ handler once - it will be used on both cores - and check the core + * number (via \ref get_core_num()) on each core. + * + * NOTE: It is not thread safe to add/remove/handle IRQs for the same irq number in the same vector table + * from both cores concurrently. + * + * NOTE: The SDK defines a PICO_VTABLE_PER_CORE variable indicating whether the two vector tables are separate, + * however as of version 2.1.1 the user cannot set this value, and expect the vector table duplication to be handled + * for them. This functionality will be added in a future SDK version + * * \param num Interrupt number \ref interrupt_nums * \param handler The handler to set. See \ref irq_handler_t * \param order_priority The order priority controls the order that handlers for the same IRQ number on the core are called. From e85c3e5515fd86da7de11a1b2ea47c669c77ff3a Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 4 Feb 2025 16:19:17 -0600 Subject: [PATCH 038/224] rationalize pico_float/pico_double libraries (#2208) * on RP2350 _dcp variant now enables -msoft-float, since if you're using this at all it is likely because you don't want to use the VFP unit at all (to save stack space) * implement all float_ and double_ conversion functions in all pico_float_pico_ variants and pico_double_pico on RP2040 and RP2350 (many were missing in some combinations) * provide better granularity of what functions are wrapped in each case also marked custom_xxx_funcs_test.c as not in bazel build yet --- .../hardware_dma/include/hardware/dma.h | 2 +- src/rp2_common/pico_double/double_aeabi_dcp.S | 112 +++- .../pico_double/double_aeabi_rp2040.S | 89 +++ src/rp2_common/pico_double/double_conv_m33.S | 64 ++- src/rp2_common/pico_double/double_fma_dcp.S | 3 +- .../pico_double/include/pico/double.h | 176 +++++- src/rp2_common/pico_float/BUILD.bazel | 37 +- src/rp2_common/pico_float/CMakeLists.txt | 71 ++- src/rp2_common/pico_float/float_aeabi_dcp.S | 171 ++++-- .../pico_float/float_aeabi_rp2040.S | 29 +- .../{float_conv_m33.S => float_common_m33.S} | 49 +- src/rp2_common/pico_float/float_conv32_vfp.S | 106 ++++ .../pico_float/include/pico/float.h | 290 ++++++++-- test/pico_float_test/BUILD.bazel | 9 + test/pico_float_test/CMakeLists.txt | 27 + .../custom_double_funcs_test.c | 515 ++++++++++++++++++ .../pico_float_test/custom_float_funcs_test.c | 402 ++++++++++++++ 17 files changed, 2011 insertions(+), 141 deletions(-) rename src/rp2_common/pico_float/{float_conv_m33.S => float_common_m33.S} (85%) create mode 100644 src/rp2_common/pico_float/float_conv32_vfp.S create mode 100644 test/pico_float_test/custom_double_funcs_test.c create mode 100644 test/pico_float_test/custom_float_funcs_test.c diff --git a/src/rp2_common/hardware_dma/include/hardware/dma.h b/src/rp2_common/hardware_dma/include/hardware/dma.h index 8bb35ec1f..94b74cb7f 100644 --- a/src/rp2_common/hardware_dma/include/hardware/dma.h +++ b/src/rp2_common/hardware_dma/include/hardware/dma.h @@ -535,7 +535,7 @@ static inline void dma_channel_start(uint channel) { *\endcode * * \if rp2350_specific - * RP2350 only: Due to errata RP12350-E5 (see the RP2350 datasheet for further detail), it is necessary to clear the enable bit of + * RP2350 only: Due to errata RP2350-E5 (see the RP2350 datasheet for further detail), it is necessary to clear the enable bit of * the aborted channel and any chained channels prior to the abort to prevent re-triggering. * \endif * diff --git a/src/rp2_common/pico_double/double_aeabi_dcp.S b/src/rp2_common/pico_double/double_aeabi_dcp.S index 9579c70e4..8e055648d 100644 --- a/src/rp2_common/pico_double/double_aeabi_dcp.S +++ b/src/rp2_common/pico_double/double_aeabi_dcp.S @@ -7,7 +7,7 @@ #include "pico/asm_helper.S" #if !HAS_DOUBLE_COPROCESSOR -#error attempt to compile double_aeabi_rp2350 when there is no DCP +#error attempt to compile double_aeabi_dcp when there is no DCP #else #include "hardware/dcp_instr.inc.S" @@ -29,7 +29,7 @@ double_section WRAPPER_FUNC_NAME(\func) // ============== STATE SAVE AND RESTORE =============== -.macro saving_func type func +.macro saving_func type func, opt_label1='-', opt_label2='-' // Note we are usually 32-bit aligned already at this point, as most of the // function bodies contain exactly two 16-bit instructions: bmi and bx lr. // We want the PCMP word-aligned. @@ -41,6 +41,12 @@ double_section WRAPPER_FUNC_NAME(\func) push {lr} // 16-bit instruction bl generic_save_state // 32-bit instruction b 1f // 16-bit instruction +.ifnc \opt_label1,'-' +regular_func \opt_label1 +.endif +.ifnc \opt_label2,'-' +regular_func \opt_label2 +.endif // This is the actual entry point: \type\()_func \func PCMP apsr_nzcv @@ -128,53 +134,124 @@ saving_func wrapper sqrt dcp_dsqrt_m r0,r1,r0,r1,r0,r1,r2,r3,r12 saving_func_return -// todo not a real thing -double_wrapper_section __aeabi_dclassify -saving_func wrapper __aeabi_dclassify -@ with correct rounding +double_section dclassify +saving_func regular dclassify dcp_dclassify_m apsr_nzcv,r0,r1 saving_func_return // ============== CONVERSION FUNCTIONS =============== double_wrapper_section __aeabi_d2f -saving_func wrapper __aeabi_d2f +saving_func wrapper __aeabi_d2f double2float @ with rounding dcp_double2float_m r0,r0,r1 saving_func_return double_wrapper_section __aeabi_i2d -saving_func wrapper __aeabi_i2d +saving_func wrapper __aeabi_i2d int2double dcp_int2double_m r0,r1,r0 saving_func_return double_wrapper_section __aeabi_ui2d -saving_func wrapper __aeabi_ui2d +saving_func wrapper __aeabi_ui2d uint2double dcp_uint2double_m r0,r1,r0 saving_func_return +double_section double2fix_z +saving_func regular double2fix_z + ubfx r3, r1, #20, #11 + adds r3, r2 + beq 1f // very small; we don't care that we might make a denormal + asrs ip, r3, #11 + beq 1f + ite pl + movpl r3, #0x7ff + movsmi r3, #0 +1: + bfi r1, r3, #20, #11 + b double2int_z_entry + +double_section double2ufix +saving_func regular double2ufix_z double2ufix +double2ufix_z_entry: + ubfx r3, r1, #20, #11 + adds r3, r2 + beq 1f // very small; we don't care that we might make a denormal + asrs ip, r3, #11 + beq 1f + ite pl + lsrspl r3, r1, #20 // 0x7ff + movsmi r3, #0 +1: + bfi r1, r3, #20, #11 + b double2uint_z_entry + +double_section double2fix +saving_func regular double2fix + ubfx r3, r1, #20, #11 + cbz r3, 2f // 0 or denormal + adds r3, r2 + beq 1f // very small; we don't care that we might make a denormal + asrs ip, r3, #11 + beq 1f + ite pl + movpl r3, #0x7ff + movsmi r3, #0 +1: + bfi r1, r3, #20, #11 + b double2int_entry +2: + movs r0, #0 +saving_func_return + + +double_section double2int +saving_func regular double2int +double2int_entry: + lsls r2, r1, #1 + bcc double2int_z_entry // positive is ok for int64_z + lsrs r3, r2, #21 + beq double2int_z_entry // 0 or -0 or denormal is ok for int_z + + lsrs r2, #21 + adds r2, #1 + subs r2, r2, #0x400 + bcc 1f // <1 means subtract 1 + cmp r2, #31 + bge double2int_z_entry // must be an integer or maxed out + lsls r3, r1, #12 + adds r3, r3, r0, lsr #20 // r3 now has highest 32 mantissa bits + lsls r3, r2 + orrs r3, r3, r0, lsl #12 // these bits are all guaranteed to be in the fraction + beq double2int_z_entry // integer +1: + dcp_double2int_m r0,r0,r1 + subs r0, #1 +saving_func_return + double_wrapper_section __aeabi_d2iz -saving_func wrapper __aeabi_d2iz +saving_func wrapper __aeabi_d2iz double2int_z +double2int_z_entry: @ with truncation towards 0 dcp_double2int_m r0,r0,r1 + // note: this works with either saved or not saved call as it is just a `bx lr` saving_func_return double_wrapper_section __aeabi_d2uiz -saving_func wrapper __aeabi_d2uiz +saving_func wrapper __aeabi_d2uiz double2uint double2uint_z +double2uint_z_entry: @ with truncation towards 0 dcp_double2uint_m r0,r0,r1 saving_func_return -// todo not a real thing -double_wrapper_section __aeabi_d2i_r -saving_func wrapper __aeabi_d2i_r +double_section double2int_r +saving_func regular double2int_r @ with rounding dcp_double2int_r_m r0,r0,r1 saving_func_return -// todo not a real thing -double_wrapper_section __aeabi_d2ui_r -saving_func wrapper __aeabi_d2ui_r +double_section double2uint_r +saving_func regular double2uint_r @ with rounding dcp_double2uint_r_m r0,r0,r1 saving_func_return @@ -189,7 +266,6 @@ saving_func wrapper __aeabi_dcmpun saving_func_return double_wrapper_section __aeabi_dcmp - saving_func wrapper __aeabi_cdrcmple dcp_dcmp_m apsr_nzcv,r2,r3,r0,r1 // with arguments reversed bvs cmp_nan diff --git a/src/rp2_common/pico_double/double_aeabi_rp2040.S b/src/rp2_common/pico_double/double_aeabi_rp2040.S index 284846fd9..448b28355 100644 --- a/src/rp2_common/pico_double/double_aeabi_rp2040.S +++ b/src/rp2_common/pico_double/double_aeabi_rp2040.S @@ -425,6 +425,7 @@ double_wrapper_section __aeabi_ui2d double_wrapper_section __aeabi_i2d wrapper_func __aeabi_ui2d +regular_func uint2double movs r1, #0 cmp r0, #0 bne 2f @@ -432,6 +433,7 @@ wrapper_func __aeabi_ui2d bx lr // double FUNC_NAME(__aeabi_i2d)(int) integer to double (double precision) conversion wrapper_func __aeabi_i2d +regular_func int2double asrs r1, r0, #31 eors r0, r1 subs r0, r1 @@ -506,6 +508,7 @@ regular_func double2int // unsigned FUNC_NAME(__aeabi_d2uiz)(double) double (double precision) to unsigned C-style conversion [3] double_wrapper_section __aeabi_d2uiz wrapper_func __aeabi_d2uiz +regular_func double2uint_z regular_func double2uint shimmable_table_tail_call SF_TABLE_FLOAT2UINT double2uint_shim @@ -528,11 +531,13 @@ regular_func ufix642double // double FUNC_NAME(__aeabi_l2d)(long long) long long to double (double precision) conversion double_wrapper_section __aeabi_l2d wrapper_func __aeabi_l2d +regular_func int642double shimmable_table_tail_call SF_TABLE_INT642FLOAT int642double_shim // double FUNC_NAME(__aeabi_l2f)(long long) long long to double (double precision) conversion double_wrapper_section __aeabi_ul2d wrapper_func __aeabi_ul2d +regular_func uint642double shimmable_table_tail_call SF_TABLE_UINT642FLOAT uint642double_shim // long long FUNC_NAME(__aeabi_d2lz)(double) double (double precision) to long long C-style conversion [3] @@ -566,22 +571,106 @@ regular_func double2int64 // unsigned long long FUNC_NAME(__aeabi_d2ulz)(double) double to unsigned long long C-style conversion [3] double_wrapper_section __aeabi_d2ulz wrapper_func __aeabi_d2ulz +regular_func double2uint64 +regular_func double2uint64_z shimmable_table_tail_call SF_TABLE_FLOAT2UINT64 double2uint64_shim +double_section double2fix64_z +regular_func double2fix64_z + lsls r3, r1, #1 + bcc double2fix64 // input positive is ok for fix64 + mov ip, r2 + asrs r2, r3, #21 + beq 3f // input zero or denormal, so just return zero + adds r2, #1 + beq double2fix64 // input infinite/nan is ok for fix64 + + lsrs r3, #21 + add r3, ip + movs r2, #1 + negs r2, r2 + lsrs r2, #22 + subs r3, r2 // r3 = modified e - 0x3ff + + bcc 3f // modified input < 1.0 means result is zero + cmp r3, #52 + bge 2f // modified input must be an integer or infinite + + adds r3, #12 + mov r2, r1 + lsls r2, r2, r3 // r2 has remaining fractional mantissa bits of r1 + bne 1f // not integer as non zero fractional bits remain + subs r3, #32 + asrs r2, r3, #31 + bics r3, r3, r2 + movs r2, r0 + lsls r2, r2, r3 + bne 1f // remaining fractional bits are non-zero, so argument was not an integer +2: + // integer + mov r2, ip + b double2fix64 +3: // result is zero + movs r0, #0 + movs r1, #0 + bx lr +1: + push {lr} + mov r2, ip + bl double2fix64 + movs r2, #0 + adds r0, #1 + adcs r1, r2 + pop {pc} + double_section double2fix64 regular_func double2fix64 shimmable_table_tail_call SF_TABLE_FLOAT2FIX64 double2fix64_shim double_section double2ufix64 regular_func double2ufix64 +regular_func double2ufix64_z shimmable_table_tail_call SF_TABLE_FLOAT2UFIX64 double2ufix64_shim double_section double2fix regular_func double2fix shimmable_table_tail_call SF_TABLE_FLOAT2FIX double2fix_shim +double_section double2fix_z +regular_func double2fix_z + lsls r3, r1, #1 + asrs r3, #21 + beq 2f // input is zero or denormal + adds r3, #1 + beq 3f // input is infinite or nan + + // extract exponent again + lsls r3, r1, #1 + lsrs r3, #21 + // adjust + adds r3, r2 + ble 2f // adjusted input is zero or dedornmal or < 1 + lsrs r3, r3, #11 + bne 3f // adjusted input is > infinite + + lsls r2, r2, #20 // align exponent adjustment offset + adds r1, r1, r2 // we know adjustment is safe + b double2int_z +2: + // result is zero + movs r0, #0 + bx lr +3: + movs r0, #0 + subs r0, #1 + lsrs r0, #1 + asrs r1, #31 + eors r0, r1 + bx lr + double_section double2ufix regular_func double2ufix +regular_func double2ufix_z shimmable_table_tail_call SF_TABLE_FLOAT2UFIX double2ufix_shim double_wrapper_section __aeabi_d2f diff --git a/src/rp2_common/pico_double/double_conv_m33.S b/src/rp2_common/pico_double/double_conv_m33.S index 606cbfc30..d927d73ca 100644 --- a/src/rp2_common/pico_double/double_conv_m33.S +++ b/src/rp2_common/pico_double/double_conv_m33.S @@ -249,7 +249,69 @@ regular_func ufix2double movs r1,#0 bx r14 -double_wrapper_section conv_dtoi64 +double_section conv_dtoi64 +regular_func double2int64 + lsls r3, r1, #1 + bcc double2int64_z // input positive is ok for int64_z + cmp r3, #0xffe00000 + bcs double2int64_z // input is infinite + lsrs r3, #21 + beq 2f // input zero or denormal, means answer remains zero + sub r3, #0x3ff + cmp r3, #0 + blt 1f // input is less than 1.0 + cmp r3, #52 + bge double2int64_z // modified input must be an integer or infinite + adds r3, #12 + lsls r2, r1, r3 // r2 has remaining fractional mantissa bits of r1 + bne 1f // not integer as non zero fractional bits remain + subs r3, #32 + bics r3, r3, r3, asr #31 // map negative shift to zero + lsls r3, r0, r3 + beq double2int64_z // remaining fractional bits are 0, so argument was an integer +1: + push {lr} + bl double2int64_z + subs r0, #1 + sbcs r1, r1, #0 + pop {pc} +2: + movs r0, #0 + movs r1, #0 + bx lr + +double_section conv_dtofix64 +regular_func double2fix64 + lsls r3, r1, #1 + bcc double2fix64_z // input positive is ok for fix64_z + cmp r3, #0xffe00000 + bcs double2fix64_z // input is infinite + lsrs r3, #21 + beq 2f // input zero or denormal, means answer remains zero + sub r3, #0x3ff + adds r3, r2 + blt 1f // modified input zero or denormal, or less than 1.0 + cmp r3, #52 + bge double2fix64_z // modified input must be an integer or infinite + adds r3, #12 + lsls ip, r1, r3 // ip has remaining fractional mantissa bits of r1 + bne 1f // not integer as non zero fractional bits remain + subs r3, #32 + bics r3, r3, r3, asr #31 // map negative shift to zero + lsls r3, r0, r3 + beq double2fix64_z // remaining fractional bits are 0, so argument was an integer +1: + push {lr} + bl double2fix64_z + subs r0, #1 + sbcs r1, r1, #0 + pop {pc} +2: + movs r0, #0 + movs r1, #0 + bx lr + +double_wrapper_section conv_dtoi64_z @ convert double to signed int64, rounding towards 0, clamping wrapper_func __aeabi_d2lz diff --git a/src/rp2_common/pico_double/double_fma_dcp.S b/src/rp2_common/pico_double/double_fma_dcp.S index 30f669bd9..bb810d0fb 100644 --- a/src/rp2_common/pico_double/double_fma_dcp.S +++ b/src/rp2_common/pico_double/double_fma_dcp.S @@ -582,7 +582,7 @@ wrapper_func fma saving_func_return -double_wrapper_section __dmla +double_section fma_fast @ cf saving_func macro: but here we need to record the SP before the state save possibly changes it 1: push {lr} // 16-bit instruction @@ -592,6 +592,7 @@ double_wrapper_section __dmla @ r0:r1 m @ r2:r3 n @ [r13,#0] a +regular_func fma_fast regular_func mla mov r12,sp @ save the SP PCMP apsr_nzcv @ test the engaged flag diff --git a/src/rp2_common/pico_double/include/pico/double.h b/src/rp2_common/pico_double/include/pico/double.h index 5af8c9e4e..6805078fb 100644 --- a/src/rp2_common/pico_double/include/pico/double.h +++ b/src/rp2_common/pico_double/include/pico/double.h @@ -16,50 +16,153 @@ extern "C" { #endif /** \file double.h -* \defgroup pico_double pico_double +* \defgroup pico_double pico_double * * \brief Optimized double-precision floating point functions * -* (Replacement) optimized implementations are provided of the following compiler built-ins -* and math library functions: +* An application can take control of the floating point routines used in the application over and above what is provided by the compiler, +* by depending on the pico_double library. A user might want to do this: * -* - __aeabi_dadd, __aeabi_ddiv, __aeabi_dmul, __aeabi_drsub, __aeabi_dsub, __aeabi_cdcmpeq, __aeabi_cdrcmple, __aeabi_cdcmple, __aeabi_dcmpeq, __aeabi_dcmplt, __aeabi_dcmple, __aeabi_dcmpge, __aeabi_dcmpgt, __aeabi_dcmpun, __aeabi_i2d, __aeabi_l2d, __aeabi_ui2d, __aeabi_ul2d, __aeabi_d2iz, __aeabi_d2lz, __aeabi_d2uiz, __aeabi_d2ulz, __aeabi_d2f -* - sqrt, cos, sin, tan, atan2, exp, log, ldexp, copysign, trunc, floor, ceil, round, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, exp2, log2, exp10, log10, pow,, hypot, cbrt, fmod, drem, remainder, remquo, expm1, log1p, fma -* - powint, sincos (GNU extensions) +* 1. To use optimized software implementations provided by the RP2-series device's bootrom or the SDK +* 2. To use optimized combined software/hardware implementations utilizing custom RP2-series hardware for acceleration +* 3. To control the amount of C compiler/library code bloat +* 4. To make sure no floating point is called at all * -* The following additional optimized functions are also provided: +* The pico_double library comes in three main flavors: * -* - int2double, uint2double, int642double, uint642double, fix2double, ufix2double, fix642double, ufix642double -* - double2fix, double2ufix, double2fix64, double2ufix64, double2int, double2uint, double2int64, double2uint64, double2int_z, double2int64_z, -* - exp10, sincos, powint +* 1. `pico_double_none` - all floating point operations cause a \ref panic - no double-precision floating point code is included +* 2. `pico_double_compiler` - no custom functions are provided; all double-precision floating point is handled by the C compiler/library +* 3. `pico_double_pico` - the smallest and fastest available for the platform, along with additional functionality (e.g. fixed point conversions) which are detailed below * -* On RP2350 the following additional functions are available; the _fast methods are faster but do not round correctly" +* The user can control which version they want (e.g. **pico_double_xxx** by either setting the CMake global variable +* `PICO_DEFAULT_DOUBLE_IMPL=xxx`, or by using the CMake function `pico_set_double_implementation( xxx)`. Note that in the absence +* of either, pico_double_pico is used by default. * -* - ddiv_fast, sqrt_fast +* \if rp2040_specific +* On RP2040, `pico_double_pico` uses optimized hand coded implementations from the bootrom and the SDK for both +* basic double-precision floating point operations and floating point math library functions. These implementations +* are generally faster and smaller than those provided by the C compiler/library, though they don't support all the features of a fully compliant +* floating point implementation; they are however usually fine for the majority of cases +* \endif +* +* \if rp2350_specific +* On RP2350, `pico_double_pico` uses RP2350 DCP instructions (double co-processor) to implement fast version of the basic +* arithmetic functions, and provides optimized M33 implementations of trignometric and scientific functions. +* These implementations are generally faster and smaller than those provided by the C compiler/library, though they don't support all the features of a fully compliant +* floating point implementation; they are however usually fine for the majority of cases +* \endif +* +* On Arm, (replacement) optimized implementations are provided for the following compiler built-ins +* and math library functions when using `pico_double_pico`: +* +* - basic arithmetic: +* +* __aeabi_dadd, __aeabi_ddiv, __aeabi_dmul, __aeabi_drsub, __aeabi_dsub +* +* - comparison: +* +* __aeabi_cfcmpeq, __aeabi_cfrcmple, __aeabi_cfcmple, __aeabi_dcmpeq, __aeabi_dcmplt, __aeabi_dcmple, __aeabi_dcmpge, __aeabi_dcmpgt, __aeabi_dcmpun +* +* - (u)int32 <-> double: +* +* __aeabi_i2d, __aeabi_ui2d, __aeabi_d2iz, __aeabi_d2uiz +* +* - (u)int64 <-> double: +* +* __aeabi_l2d, __aeabi_ul2d, __aeabi_d2lz, __aeabi_d2ulz +* +* - double -> float: +* +* __aeabi_d2d +* +* - basic trigonometric: +* +* sqrt, cos, sin, tan, atan2, exp, log +* +* - trigonometric and scientific +* +* ldexp, copysign, trunc, floor, ceil, round, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, exp2, log2, exp10, log10, pow, hypot, cbrt, fmod, drem, remainder, remquo, expm1, log1p, fma +* +* - GNU exetnsions: +* +* powint, sincos +* +* On Arm, the following additional optimized functions are also provided when using `pico_double_pico`: +* +* - Conversions to/from integer types: +* +* - (u)int -> double (round to nearest): +* +* int2double, uint2double, int642double, uint642double +* +* - (u)double -> int (round towards zero): +* +* double2int_z, double2uint_z, double2int64_z, double2uint64_z +* +* - (u)double -> int (round towards -infinity): +* +* double2int, double2uint, double2int64, double2uint64 +* +* - Conversions to/from fixed point integers: +* +* - (u)fix -> double (round to nearest): +* +* fix2double, ufix2double, fix642double, ufix642double +* +* - double -> (u)fix (round towards zero): +* +* double2fix_z, double2ufix_z, double2fix64_z, double2ufix64_z +* +* - double -> (u)fix (round towards -infinity): +* +* double2fix, double2ufix, double2fix64, double2ufix64 +* +* - Even faster versions of divide and square-root functions that do not round correctly: +* +* ddiv_fast, sqrt_fast (these do not round correctly) +* +* - Faster unfused multiply and accumulate: +* +* mla (fast fma) +* +* \if rp2350_specific +* On RISC-V there is no custom double-precision floating point support, so `pico_double_pico` is equivalent to `pico_double_compiler` +* \endif */ +#if !defined(__riscv) || PICO_COMBINED_DOCS +#if PICO_COMBINED_DOCS || !LIB_PICO_DOUBLE_COMPILER double int2double(int32_t i); -double uint2double(uint32_t u); +double uint2double(uint32_t i); double int642double(int64_t i); -double uint642double(uint64_t u); +double uint642double(uint64_t i); double fix2double(int32_t m, int e); double ufix2double(uint32_t m, int e); double fix642double(int64_t m, int e); double ufix642double(uint64_t m, int e); -// These methods round towards -Infinity. -int32_t double2fix(double d, int e); -uint32_t double2ufix(double d, int e); -int64_t double2fix64(double d, int e); -uint64_t double2ufix64(double d, int e); -int32_t double2int(double d); -uint32_t double2uint(double d); -int64_t double2int64(double d); -uint64_t double2uint64(double d); +// These methods round towards 0, which IS the C way +int32_t double2int_z(double f); +int64_t double2int64_z(double f); +int32_t double2uint_z(double f); +int64_t double2uint64_z(double f); +int32_t double2fix_z(double f, int e); +uint32_t double2ufix_z(double f, int e); +int64_t double2fix64_z(double f, int e); +uint64_t double2ufix64_z(double f, int e); -// These methods round towards 0. -int32_t double2int_z(double d); -int64_t double2int64_z(double d); +// These methods round towards -Infinity - which IS NOT the C way for negative numbers; +// as such the naming is not ideal, however is kept for backwards compatibility +int32_t double2int(double f); +uint32_t double2uint(double f); +int64_t double2int64(double f); +uint64_t double2uint64(double f); +int32_t double2fix(double f, int e); +uint32_t double2ufix(double f, int e); +int64_t double2fix64(double f, int e); +uint64_t double2ufix64(double f, int e); + +#endif double exp10(double x); void sincos(double x, double *sinx, double *cosx); @@ -67,8 +170,24 @@ double powint(double x, int y); #if !PICO_RP2040 || PICO_COMBINED_DOCS double ddiv_fast(double n, double d); -double sqrt_fast(double d); -double mla(double x, double y, double z); // note this is not fused +double sqrt_fast(double f); +double fma_fast(double x, double y, double z); // this is not fused +double mla(double x, double y, double z); // another name for fma_fast +#endif + +#endif + +#if LIB_PICO_DOUBLE_COMPILER || defined(__riscv) +// when using the compiler; we provide as many functions as we trivially can, though in the double case they are not optimal +static inline double int2double(int32_t i) { return (double)i; } +static inline double uint2double(uint32_t i) { return (double)i; } +static inline double int642double(int64_t i) { return (double)i; } +static inline double uint642double(uint64_t i) { return (double)i; } + +static inline int32_t double2int_z(double d) { return (int32_t)d; } +static inline int64_t double2int64_z(double d) { return (int64_t)d; } +static inline int32_t double2uint_z(double d) { return (uint32_t)d; } +static inline int64_t double2uint64_z(double d) { return (uint64_t)d; } #endif #ifdef __cplusplus @@ -76,4 +195,3 @@ double mla(double x, double y, double z); // note this is not fused #endif #endif - diff --git a/src/rp2_common/pico_float/BUILD.bazel b/src/rp2_common/pico_float/BUILD.bazel index f6aadca2d..8d4ab363e 100644 --- a/src/rp2_common/pico_float/BUILD.bazel +++ b/src/rp2_common/pico_float/BUILD.bazel @@ -2,13 +2,16 @@ load("//bazel:defs.bzl", "compatible_with_rp2", "incompatible_with_config") package(default_visibility = ["//visibility:public"]) -_WRAP_FLOAT_AEABI_FLAGS = [ +_WRAP_FLOAT_AEABI_ARITHMETIC_FLAGS = [ "-Wl,--wrap=__aeabi_fadd", "-Wl,--wrap=__aeabi_fdiv", "-Wl,--wrap=__aeabi_fmul", "-Wl,--wrap=__aeabi_frsub", "-Wl,--wrap=__aeabi_fsub", "-Wl,--wrap=__aeabi_cfcmpeq", +] + +_WRAP_FLOAT_AEABI_CMP_FLAGS = [ "-Wl,--wrap=__aeabi_cfrcmple", "-Wl,--wrap=__aeabi_cfcmple", "-Wl,--wrap=__aeabi_fcmpeq", @@ -17,15 +20,27 @@ _WRAP_FLOAT_AEABI_FLAGS = [ "-Wl,--wrap=__aeabi_fcmpge", "-Wl,--wrap=__aeabi_fcmpgt", "-Wl,--wrap=__aeabi_fcmpun", +] + +_WRAP_FLOAT_AEABI_CONV_32_FLAGS = [ "-Wl,--wrap=__aeabi_i2f", "-Wl,--wrap=__aeabi_l2f", "-Wl,--wrap=__aeabi_ui2f", "-Wl,--wrap=__aeabi_ul2f", +] + +_WRAP_FLOAT_AEABI_CONV_64_FLAGS = [ "-Wl,--wrap=__aeabi_f2iz", "-Wl,--wrap=__aeabi_f2lz", "-Wl,--wrap=__aeabi_f2uiz", "-Wl,--wrap=__aeabi_f2ulz", +] + +_WRAP_FLOAT_AEABI_CONV_DOUBLE_FLAGS = [ "-Wl,--wrap=__aeabi_f2d", +] + +_WRAP_FLOAT_SQRTF_FLAGS = [ "-Wl,--wrap=sqrtf", ] @@ -36,13 +51,16 @@ _WRAP_FLOAT_SCI_FLAGS = [ "-Wl,--wrap=atan2f", "-Wl,--wrap=expf", "-Wl,--wrap=logf", + "-Wl,--wrap=sincosf", # gnu +] + +_WRAP_FLOAT_SCI_EXTRA_FLAGS = [ "-Wl,--wrap=ldexpf", "-Wl,--wrap=copysignf", "-Wl,--wrap=truncf", "-Wl,--wrap=floorf", "-Wl,--wrap=ceilf", "-Wl,--wrap=roundf", - "-Wl,--wrap=sincosf", # gnu "-Wl,--wrap=asinf", "-Wl,--wrap=acosf", "-Wl,--wrap=atanf", @@ -114,30 +132,31 @@ _PICO_FLOAT_IMPLS = [ ], "compatibility": incompatible_with_config("@platforms//cpu:riscv32") + ["//bazel/constraint:rp2040"], "extra_deps": [], - "linkopts": _WRAP_FLOAT_AEABI_FLAGS + _WRAP_FLOAT_SCI_FLAGS, + "linkopts": _WRAP_FLOAT_AEABI_ARITHMETIC_FLAGS + _WRAP_FLOAT_AEABI_CMP_FLAGS + _WRAP_FLOAT_AEABI_CONV_32_FLAGS + _WRAP_FLOAT_AEABI_CONV_64_FLAGS + _WRAP_FLOAT_AEABI_CONV_DOUBLE_FLAGS + _WRAP_FLOAT_SQRTF_FLAGS + _WRAP_FLOAT_SCI_FLAGS + _WRAP_FLOAT_SCI_EXTRA_FLAGS, }, { "name": "dcp", "srcs": [ "float_aeabi_dcp.S", - "float_conv_m33.S", + "float_common_m33.S", "float_math.c", "float_sci_m33.S", ], "compatibility": compatible_with_rp2() + incompatible_with_config("@platforms//cpu:riscv32") + incompatible_with_config("//bazel/constraint:rp2040"), "extra_deps": ["//src/rp2_common/hardware_dcp"], - "linkopts": _WRAP_FLOAT_SCI_FLAGS, + "linkopts": _WRAP_FLOAT_AEABI_ARITHMETIC_FLAGS + _WRAP_FLOAT_AEABI_CMP_FLAGS + _WRAP_FLOAT_AEABI_CONV_32_FLAGS + _WRAP_FLOAT_AEABI_CONV_64_FLAGS + _WRAP_FLOAT_AEABI_CONV_DOUBLE_FLAGS + _WRAP_FLOAT_SQRTF_FLAGS + _WRAP_FLOAT_SCI_FLAGS + _WRAP_FLOAT_SCI_EXTRA_FLAGS, }, { "name": "vfp", "srcs": [ + "float_conv32_vfp.S", "float_sci_m33_vfp.S", - "float_conv_m33.S", + "float_common_m33.S", "float_math.c", ], "compatibility": compatible_with_rp2() + incompatible_with_config("@platforms//cpu:riscv32") + incompatible_with_config("//bazel/constraint:rp2040"), "extra_deps": ["//src/rp2_common/hardware_dcp"], - "linkopts": _WRAP_FLOAT_SCI_FLAGS, + "linkopts": _WRAP_FLOAT_AEABI_CONV_64_FLAGS + _WRAP_FLOAT_SCI_FLAGS + _WRAP_FLOAT_SCI_EXTRA_FLAGS, }, { "name": "single_hazard3", @@ -146,7 +165,7 @@ _PICO_FLOAT_IMPLS = [ ], "compatibility": compatible_with_rp2() + ["@platforms//cpu:riscv32"], "extra_deps": ["//src/rp2_common/hardware_hazard3"], - "linkopts": _WRAP_FLOAT_SCI_FLAGS, + "linkopts": _WRAP_FLOAT_SCI_EXTRA_FLAGS, }, ] @@ -184,7 +203,7 @@ cc_library( hdrs = ["include/pico/float.h"], defines = ["LIB_PICO_FLOAT_PICO=0"], includes = ["include"], - linkopts = _WRAP_FLOAT_AEABI_FLAGS + _WRAP_FLOAT_SCI_FLAGS, + linkopts = _WRAP_FLOAT_AEABI_ARITHMETIC_FLAGS + _WRAP_FLOAT_AEABI_CMP_FLAGS + _WRAP_FLOAT_AEABI_CONV_32_FLAGS + _WRAP_FLOAT_AEABI_CONV_64_FLAGS + _WRAP_FLOAT_AEABI_CONV_DOUBLE_FLAGS + _WRAP_FLOAT_SQRTF_FLAGS + _WRAP_FLOAT_SCI_FLAGS + _WRAP_FLOAT_SCI_EXTRA_FLAGS, target_compatible_with = compatible_with_rp2(), visibility = ["//visibility:private"], deps = [ diff --git a/src/rp2_common/pico_float/CMakeLists.txt b/src/rp2_common/pico_float/CMakeLists.txt index 7d53274ff..f634f094d 100644 --- a/src/rp2_common/pico_float/CMakeLists.txt +++ b/src/rp2_common/pico_float/CMakeLists.txt @@ -18,13 +18,15 @@ $>,$,${PICO_DEFAULT_FLOAT_IMPL}>) function(wrap_float_functions TARGET) - cmake_parse_arguments(WRAP_FLOAT "NO_WRAP_AEABI;NO_WRAP_SCI" "" "" ${ARGN} ) - if (NOT WRAP_FLOAT_NO_WRAP_AEABI) + cmake_parse_arguments(WRAP_FLOAT "NO_AEABI_ARITHMETIC;NO_AEABI_CMP;NO_AEABI_CONV_32;NO_AEABI_CONV_64;NO_AEABI_CONV_DOUBLE;NO_SQRTF;NO_SCI;NO_SCI_EXTRA" "" "" ${ARGN} ) + if (NOT WRAP_FLOAT_NO_AEABI_ARITHMETIC) pico_wrap_function(${TARGET} __aeabi_fadd) pico_wrap_function(${TARGET} __aeabi_fdiv) pico_wrap_function(${TARGET} __aeabi_fmul) pico_wrap_function(${TARGET} __aeabi_frsub) pico_wrap_function(${TARGET} __aeabi_fsub) + endif() + if (NOT WRAP_FLOAT_NO_AEABI_CMP) pico_wrap_function(${TARGET} __aeabi_cfcmpeq) pico_wrap_function(${TARGET} __aeabi_cfrcmple) pico_wrap_function(${TARGET} __aeabi_cfcmple) @@ -34,32 +36,42 @@ pico_wrap_function(${TARGET} __aeabi_fcmpge) pico_wrap_function(${TARGET} __aeabi_fcmpgt) pico_wrap_function(${TARGET} __aeabi_fcmpun) + endif() + if (NOT WRAP_FLOAT_NO_AEABI_CONV_32) pico_wrap_function(${TARGET} __aeabi_i2f) - pico_wrap_function(${TARGET} __aeabi_l2f) pico_wrap_function(${TARGET} __aeabi_ui2f) - pico_wrap_function(${TARGET} __aeabi_ul2f) pico_wrap_function(${TARGET} __aeabi_f2iz) - pico_wrap_function(${TARGET} __aeabi_f2lz) pico_wrap_function(${TARGET} __aeabi_f2uiz) + endif() + if (NOT WRAP_FLOAT_NO_AEABI_CONV_64) + pico_wrap_function(${TARGET} __aeabi_l2f) + pico_wrap_function(${TARGET} __aeabi_ul2f) + pico_wrap_function(${TARGET} __aeabi_f2lz) pico_wrap_function(${TARGET} __aeabi_f2ulz) + endif() + if (NOT WRAP_FLOAT_NO_AEABI_CONV_DOUBLE) pico_wrap_function(${TARGET} __aeabi_f2d) + endif() + # separate as we have a direct DCP version + if (NOT WRAP_FLOAT_NO_SQRTF) pico_wrap_function(${TARGET} sqrtf) endif() - if (NOT WRAP_FLOAT_NO_WRAP_SCI) + if (NOT WRAP_FLOAT_NO_SCI) pico_wrap_function(${TARGET} cosf) pico_wrap_function(${TARGET} sinf) pico_wrap_function(${TARGET} tanf) pico_wrap_function(${TARGET} atan2f) pico_wrap_function(${TARGET} expf) pico_wrap_function(${TARGET} logf) - + pico_wrap_function(${TARGET} sincosf) # gnu + endif() + if (NOT WRAP_FLOAT_NO_SCI_EXTRA) pico_wrap_function(${TARGET} ldexpf) pico_wrap_function(${TARGET} copysignf) pico_wrap_function(${TARGET} truncf) pico_wrap_function(${TARGET} floorf) pico_wrap_function(${TARGET} ceilf) pico_wrap_function(${TARGET} roundf) - pico_wrap_function(${TARGET} sincosf) # gnu pico_wrap_function(${TARGET} asinf) pico_wrap_function(${TARGET} acosf) pico_wrap_function(${TARGET} atanf) @@ -93,7 +105,9 @@ ) target_link_libraries(pico_float_none INTERFACE pico_float_headers) - wrap_float_functions(pico_float_none) + wrap_float_functions(pico_float_none) # we wrap all functions + # be explicit that there should be no floating point instructions + target_compile_options(pico_float_none INTERFACE -msoft-float) pico_add_library(pico_float_pico) if (PICO_RP2040) @@ -107,21 +121,52 @@ target_link_libraries(pico_float_pico INTERFACE pico_bootrom pico_float_headers hardware_divider) elseif(NOT PICO_RISCV) pico_add_library(pico_float_pico_dcp) + # todo what functions from float_math belong in each case; should some be left to GCC on RP2350? target_sources(pico_float_pico_dcp INTERFACE ${CMAKE_CURRENT_LIST_DIR}/float_math.c ${CMAKE_CURRENT_LIST_DIR}/float_aeabi_dcp.S + ${CMAKE_CURRENT_LIST_DIR}/float_common_m33.S ${CMAKE_CURRENT_LIST_DIR}/float_sci_m33.S - ${CMAKE_CURRENT_LIST_DIR}/float_conv_m33.S ) - wrap_float_functions(pico_float_pico_dcp NO_WRAP_AEABI) + # NOTE the main reason for using pico_float_pico_dcp is presumably that you + # don't want to use VFP at all, so turn off compiler support, otherwise, it will inline usages + target_compile_options(pico_float_pico_dcp INTERFACE -msoft-float) + + wrap_float_functions(pico_float_pico_dcp + # we wrap all functions as we don't want to use VFP (or compiler versions) at all + #NO_AEABI_ARITHMETIC + #NO_AEABI_CMP + #NO_AEABI_CONV_32 + #NO_AEABI_CONV_64 + #NO_AEABI_CONV_DOUBLE + #NO_SQRTF + #NO_SCI + #NO_SCI_EXTRA + ) + pico_add_library(pico_float_pico_vfp) target_sources(pico_float_pico_vfp INTERFACE ${CMAKE_CURRENT_LIST_DIR}/float_math.c + ${CMAKE_CURRENT_LIST_DIR}/float_conv32_vfp.S + ${CMAKE_CURRENT_LIST_DIR}/float_common_m33.S ${CMAKE_CURRENT_LIST_DIR}/float_sci_m33_vfp.S - ${CMAKE_CURRENT_LIST_DIR}/float_conv_m33.S ) - wrap_float_functions(pico_float_pico_vfp NO_WRAP_AEABI) + wrap_float_functions(pico_float_pico_vfp + # for these 3, arguably compiler is probably inlining anyway, but use the cmopiler's + # version for explicit AEABI calls + NO_AEABI_ARITHMETIC + NO_AEABI_CMP + NO_AEABI_CONV_32 + #NO_AEABI_CONV_64 # we have optimized M33 versions + NO_AEABI_CONV_DOUBLE + # we don't have an optimized vfp or m33 sqrtf available + NO_SQRTF + #NO_SCI # we have optimized VFP versions + #NO_SCI_EXTRA # todo - are our versions better than what GCC proides? + ) + + target_link_libraries(pico_float_pico INTERFACE pico_float_pico_vfp) else() diff --git a/src/rp2_common/pico_float/float_aeabi_dcp.S b/src/rp2_common/pico_float/float_aeabi_dcp.S index 61c240919..de170d3ef 100644 --- a/src/rp2_common/pico_float/float_aeabi_dcp.S +++ b/src/rp2_common/pico_float/float_aeabi_dcp.S @@ -5,15 +5,17 @@ */ #include "pico/asm_helper.S" -#if HAS_DOUBLE_COPROCESSOR + +#if !HAS_DOUBLE_COPROCESSOR +#error attempt to compile float_aeabi_dcp when there is no DCP +#else + #include "hardware/dcp_instr.inc.S" #include "hardware/dcp_canned.inc.S" pico_default_asm_setup -// todo alignment -//__pre_init __aeabi_float_init, 00020 -// factor out save/restore (there is a copy in double code) +// todo factor out save/restore (there is a copy in double code) .macro float_section name #if PICO_FLOAT_IN_RAM @@ -29,7 +31,7 @@ float_section WRAPPER_FUNC_NAME(\func) // ============== STATE SAVE AND RESTORE =============== -.macro saving_func func +.macro saving_func type func, opt_label1='-', opt_label2='-' // Note we are usually 32-bit aligned already at this point, as most of the // function bodies contain exactly two 16-bit instructions: bmi and bx lr. // We want the PCMP word-aligned. @@ -41,8 +43,14 @@ float_section WRAPPER_FUNC_NAME(\func) push {lr} // 16-bit instruction bl generic_save_state // 32-bit instruction b 1f // 16-bit instruction +.ifnc \opt_label1,'-' +regular_func \opt_label1 +.endif +.ifnc \opt_label2,'-' +regular_func \opt_label2 +.endif // This is the actual entry point: -wrapper_func \func +\type\()_func \func PCMP apsr_nzcv bmi 1b 1: @@ -82,115 +90,208 @@ generic_restore_state: // ============== ARITHMETIC FUNCTIONS =============== float_wrapper_section __aeabi_fadd -saving_func __aeabi_fadd +saving_func wrapper __aeabi_fadd dcp_fadd_m r0,r0,r1 saving_func_return float_wrapper_section __aeabi_fsub -saving_func __aeabi_fsub +saving_func wrapper __aeabi_fsub dcp_fsub_m r0,r0,r1 saving_func_return float_wrapper_section __aeabi_frsub -saving_func __aeabi_frsub +saving_func wrapper __aeabi_frsub dcp_fsub_m r0,r1,r0 saving_func_return float_wrapper_section __aeabi_fmul -saving_func __aeabi_fmul +saving_func wrapper __aeabi_fmul dcp_fmul_m r0,r0,r1,r0,r1 saving_func_return float_section fdiv_fast -saving_func fdiv_fast +saving_func regular fdiv_fast dcp_fdiv_fast_m r0,r0,r1,r0,r1,r2 saving_func_return float_wrapper_section __aeabi_fdiv -saving_func __aeabi_fdiv +saving_func wrapper __aeabi_fdiv @ with correct rounding dcp_fdiv_m r0,r0,r1,r0,r1,r2,r3 saving_func_return float_section sqrtf_fast -saving_func sqrtf_fast +saving_func regular sqrtf_fast dcp_fsqrt_fast_m r0,r0,r0,r1,r2,r3 saving_func_return float_wrapper_section sqrtf -saving_func sqrtf +saving_func wrapper sqrtf @ with correct rounding dcp_fsqrt_m r0,r0,r0,r1,r2,r3 saving_func_return -// todo not a real thing -float_wrapper_section __aeabi_fclassify -saving_func __aeabi_fclassify +float_section fclassify +saving_func regular fclassify dcp_fclassify_m apsr_nzcv,r0 saving_func_return // ============== CONVERSION FUNCTIONS =============== float_wrapper_section __aeabi_f2d -saving_func __aeabi_f2d +saving_func wrapper __aeabi_f2d float2double dcp_float2double_m r0,r1,r0 saving_func_return float_wrapper_section __aeabi_i2f -saving_func __aeabi_i2f +saving_func wrapper __aeabi_i2f int2float @ with rounding dcp_int2float_m r0,r0 saving_func_return float_wrapper_section __aeabi_ui2f -saving_func __aeabi_ui2f +saving_func wrapper __aeabi_ui2f uint2float @ with rounding dcp_uint2float_m r0,r0 saving_func_return +float_section float2fix_z +regular_func float2fix_z + ubfx r2, r0, #23, #8 + cbz r2, 2f // input is zero or denormal + cmp r2, #0xff + beq 3f // input infinite or nan + adds r2, r1 + ble 2f // modified input is denormal so zero + cmp r2, #0xff + beq 3f // modified input is infinite +1: + bfi r0, r2, #23, #8 + b float2int_z_entry +2: + movs r0, #0 + bx lr +3: + mvn r1, #0x80000000 + add r0, r1, r0, lsr#31 @ so -Inf → 0x80000000, +Inf → 0x7fffffff + bx lr + float_wrapper_section __aeabi_f2iz -saving_func __aeabi_f2iz +saving_func wrapper __aeabi_f2iz float2int_z @ with truncation towards 0 +float2int_z_entry: dcp_float2int_m r0,r0 saving_func_return +float_section __aeabi_f2ufix +regular_func float2ufix +regular_func float2ufix_z + ubfx r2, r0, #23, #8 + cbz r2, 2f // input is zero or denormal + cmp r2, #0xff + beq 3f // input infinite or nan + adds r2, r1 + ble 2f // modified input is denormal so zero + cmp r2, #0xff + beq 3f // modified input is infinite +1: + bfi r0, r2, #23, #8 + b float2uint_z_entry +2: + movs r0, #0 + bx lr +3: + mvn r0, r0, asr #31 + bx lr + float_wrapper_section __aeabi_f2uiz -saving_func __aeabi_f2uiz +saving_func wrapper __aeabi_f2uiz float2uint_z float2uint @ with truncation towards 0 +float2uint_z_entry: dcp_float2uint_m r0,r0 saving_func_return -// todo not a real thing +float_section conv_f2fix +saving_func regular float2fix + ubfx r2, r0, #23, #8 + cbz r2, 2f // input is zero or denormal + cmp r2, #0xff + beq 3f // input infinite or nan + adds r2, r1 + ble 2f // modified input is denormal so zero + cmp r2, #0xff + beq 3f // modified input is infinite +1: + bfi r0, r2, #23, #8 + b float2int_entry +2: + movs r0, #0 + bx lr +3: + mvn r1, #0x80000000 + add r0, r1, r0, lsr#31 @ so -Inf → 0x80000000, +Inf → 0x7fffffff + bx lr + +float_section float2int +// (not a real thing - kept because we use wrapper in saving_func) +saving_func regular float2int +float2int_entry: + lsls r1, r0, #1 + // r0 = abs(zero) => r1 = 0x00000000 + // r0 = abs(denornaml) => r1 = 0x00xxxxxx + // r0 = abs(1.0f) => r1 = 0x7f000000 + // r0 = abs(inf/nan) => r1 = 0xffxxxxxx + bls float2int_z_entry // input positive or zero or -zero are ok for int64_z + lsrs r1, #24 + beq float2int_z_entry // input denormal is flushed to zero anyway + subs r1, #0x7f + bcc 1f // input < 1.0f means we need to subtract 1 after conversion + // mask off all but fractional bits + lsls r2, r0, r1 + lsls r2, #9 + beq float2int_z_entry // input is integer +1: + WXFC r0, r0 + ADD0 + ADD1 + NTDC + RDIC r0 + subs r0, #1 +saving_func_return + +#if 0 // not sure these are super useful; if they are we should give them names float_wrapper_section __aeabi_f2i_r -saving_func __aeabi_f2i_r +// (not a real thing - kept because we use wrapper in saving_func) +saving_func wrapper __aeabi_f2i_r @ with rounding dcp_float2int_r_m r0,r0 saving_func_return -// todo not a real thing float_wrapper_section __aeabi_f2ui_r -saving_func __aeabi_f2ui_r +// (not a real thing - kept because we use wrapper in saving_func) +saving_func wrapper __aeabi_f2ui_r @ with rounding dcp_float2uint_r_m r0,r0 saving_func_return +#endif // ============== COMPARISON FUNCTIONS =============== float_wrapper_section __aeabi_fcmpun -saving_func __aeabi_fcmpun +saving_func wrapper __aeabi_fcmpun dcp_fcmp_m r0,r0,r1 // extract unordered bit ubfx r0, r0, #28, #1 saving_func_return float_wrapper_section __aeabi_fcmp -saving_func __aeabi_cfrcmple +saving_func wrapper __aeabi_cfrcmple dcp_fcmp_m apsr_nzcv,r1,r0 // with arguments reversed bvs cmp_nan saving_func_return // these next two can be the same function in the absence of exceptions -saving_func __aeabi_cfcmple +saving_func wrapper __aeabi_cfcmple dcp_fcmp_m apsr_nzcv,r0,r1 bvs cmp_nan saving_func_return @@ -198,7 +299,7 @@ saving_func __aeabi_cfcmple // It is not clear from the ABI documentation whether cfcmpeq must set the C flag // in the same way as cfcmple. If not, we could save the "bvs" below; but we // err on the side of caution. -saving_func __aeabi_cfcmpeq +saving_func wrapper __aeabi_cfcmpeq dcp_fcmp_m apsr_nzcv,r0,r1 bvs cmp_nan saving_func_return @@ -212,14 +313,14 @@ cmp_nan: saving_func_return float_wrapper_section __aeabi_fcmpeq -saving_func __aeabi_fcmpeq +saving_func wrapper __aeabi_fcmpeq dcp_fcmp_m r0,r0,r1 // extract Z ubfx r0, r0, #30, #1 saving_func_return float_wrapper_section __aeabi_fcmplt -saving_func __aeabi_fcmplt +saving_func wrapper __aeabi_fcmplt dcp_fcmp_m apsr_nzcv,r1,r0 ite hi movhi r0,#1 @@ -227,7 +328,7 @@ saving_func __aeabi_fcmplt saving_func_return float_wrapper_section __aeabi_fcmple -saving_func __aeabi_fcmple +saving_func wrapper __aeabi_fcmple dcp_fcmp_m apsr_nzcv,r1,r0 ite hs movhs r0,#1 @@ -235,7 +336,7 @@ saving_func __aeabi_fcmple saving_func_return float_wrapper_section __aeabi_fcmpge -saving_func __aeabi_fcmpge +saving_func wrapper __aeabi_fcmpge dcp_fcmp_m apsr_nzcv,r0,r1 ite hs movhs r0,#1 @@ -243,7 +344,7 @@ saving_func __aeabi_fcmpge saving_func_return float_wrapper_section __aeabi_fcmpgt -saving_func __aeabi_fcmpgt +saving_func wrapper __aeabi_fcmpgt dcp_fcmp_m apsr_nzcv,r0,r1 ite hi movhi r0,#1 diff --git a/src/rp2_common/pico_float/float_aeabi_rp2040.S b/src/rp2_common/pico_float/float_aeabi_rp2040.S index 8eb83fc22..c34f68f67 100644 --- a/src/rp2_common/pico_float/float_aeabi_rp2040.S +++ b/src/rp2_common/pico_float/float_aeabi_rp2040.S @@ -471,17 +471,36 @@ float_section float2int regular_func float2int shimmable_table_tail_call SF_TABLE_FLOAT2INT float2int_shim +float_section float2fix_z +regular_func float2fix_z + cmn r0, r0 + bcc float2fix + push {lr} + lsls r0, #1 + lsrs r0, #1 + bl float2ufix_z + cmp r0, #0 + bmi 1f + negs r0, r0 + pop {pc} +1: + movs r0, #128 + lsls r0, #24 + pop {pc} + float_section float2fix regular_func float2fix shimmable_table_tail_call SF_TABLE_FLOAT2FIX float2fix_shim float_section float2ufix regular_func float2ufix +regular_func float2ufix_z table_tail_call SF_TABLE_FLOAT2UFIX // unsigned FUNC_NAME(__aeabi_f2uiz)(float) float (single precision) to unsigned C-style conversion [3] float_wrapper_section __aeabi_f2uiz wrapper_func __aeabi_f2uiz +regular_func float2uint regular_func float2uint_z table_tail_call SF_TABLE_FLOAT2UINT @@ -530,10 +549,11 @@ wrapper_func __aeabi_f2lz regular_func float2int64_z cmn r0, r0 bcc float2int64 + movs r1, #0 +float2fix64_z_neg: push {lr} lsls r0, #1 lsrs r0, #1 - movs r1, #0 bl float2ufix64 cmp r1, #0 bmi 1f @@ -553,17 +573,24 @@ regular_func float2int64 shimmable_table_tail_call SF_TABLE_FLOAT2INT64 float2int64_shim float_section float2fix64 +regular_func float2fix64_z + cmn r0, r0 + bcs float2fix64_z_neg + // fall thru + regular_func float2fix64 shimmable_table_tail_call SF_TABLE_FLOAT2FIX64 float2fix64_shim // unsigned long long FUNC_NAME(__aeabi_f2ulz)(float) float to unsigned long long C-style conversion [3] float_wrapper_section __aeabi_f2ulz wrapper_func __aeabi_f2ulz +regular_func float2uint64 regular_func float2uint64_z shimmable_table_tail_call SF_TABLE_FLOAT2UINT64 float2uint64_shim float_section float2ufix64 regular_func float2ufix64 +regular_func float2ufix64_z shimmable_table_tail_call SF_TABLE_FLOAT2UFIX64 float2ufix64_shim float_wrapper_section __aeabi_f2d diff --git a/src/rp2_common/pico_float/float_conv_m33.S b/src/rp2_common/pico_float/float_common_m33.S similarity index 85% rename from src/rp2_common/pico_float/float_conv_m33.S rename to src/rp2_common/pico_float/float_common_m33.S index dd47a939e..491d758fb 100644 --- a/src/rp2_common/pico_float/float_conv_m33.S +++ b/src/rp2_common/pico_float/float_common_m33.S @@ -241,7 +241,52 @@ regular_func ufix642float bxlo r14 b 3b -float_wrapper_section conv_ftoi64 +float_section conv_ftoi64 +regular_func float2int64 + lsls r1, r0, #1 + // r0 = abs(zero) => r1 = 0x00000000 + // r0 = abs(denornaml) => r1 = 0x00xxxxxx + // r0 = abs(1.0f) => r1 = 0x7f000000 + // r0 = abs(inf/nan) => r1 = 0xffxxxxxx + bls float2int64_z // positive or zero or -zero are ok for int64_z + lsrs r1, #24 + subs r1, #0x7f + bcc 1f // <1 means subtract 1 + // mask off all but fractional bits + lsls r2, r0, r1 + lsls r2, #9 + beq float2int64_z // integer +1: + push {lr} + bl float2int64_z + subs r0, #1 + sbcs r1, r1, #0 + pop {pc} + +float_section conv_ftof64 +regular_func float2fix64 + lsls r2, r0, #1 + // r0 = abs(zero) => r1 = 0x00000000 + // r0 = abs(denornaml) => r1 = 0x00xxxxxx + // r0 = abs(1.0f) => r1 = 0x7f000000 + // r0 = abs(inf/nan) => r1 = 0xffxxxxxx + bls float2fix64_z // positive or zero or -zero are ok for fix64_z + lsrs r2, #24 + rsbs r3, r1, #0x7f + subs r2, r3 + bcc 1f // <1 means subtract 1 + // mask off all but fractional bits + lsls r2, r0, r2 + lsls r2, #9 + beq float2fix64_z // integer +1: + push {lr} + bl float2fix64_z + subs r0, #1 + sbcs r1, r1, #0 + pop {pc} + +float_wrapper_section conv_ftoi64z @ convert float to signed int64, rounding towards 0, clamping wrapper_func __aeabi_f2lz @@ -318,7 +363,7 @@ regular_func float2uint64_z movs r1,#0 @ fall through @ convert float in r0 to unsigned fixed point in r0:r1, clamping regular_func float2ufix64 -//regular_func float2ufix64_z +regular_func float2ufix64_z subs r1,#0x96 @ remove exponent bias, compensate for mantissa length asrs r2,r0,#23 @ sign and exponent sub r3,r2,#1 diff --git a/src/rp2_common/pico_float/float_conv32_vfp.S b/src/rp2_common/pico_float/float_conv32_vfp.S new file mode 100644 index 000000000..80fb5ca25 --- /dev/null +++ b/src/rp2_common/pico_float/float_conv32_vfp.S @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#if !PICO_RP2040 +#include "pico/asm_helper.S" + +pico_default_asm_setup + +.macro float_section name +#if PICO_FLOAT_IN_RAM +.section RAM_SECTION_NAME(\name), "ax" +#else +.section SECTION_NAME(\name), "ax" +#endif +.endm + +float_section int2float +regular_func int2float + vmov s15, r0 + vcvt.f32.s32 s15, s15 + vmov r0, s15 + bx lr + +float_section uint2float +regular_func uint2float + vmov s15, r0 + vcvt.f32.u32 s15, s15 + vmov r0, s15 + bx lr + +float_section float2int +regular_func float2int + vmov s15, r0 + vcvtm.s32.f32 s15, s15 + vmov r0, s15 + bx lr + +float_section float2int_z +regular_func float2int_z + vmov s15, r0 + vcvt.s32.f32 s15, s15 + vmov r0, s15 + bx lr + +float_section float2uint +regular_func float2uint +regular_func float2uint_z + vmov s15, r0 + vcvt.u32.f32 s15, s15 + vmov r0, s15 + bx lr + +float_section float2fix_z +regular_func float2fix_z + ubfx r2, r0, #23, #8 + adds r2, r1 + asrs r3, r2, #8 + beq 1f + ite pl + movpl r2, #0xff + movmi r2, #0 +1: + bfi r0, r2, #23, #8 + b float2int_z + +float_section float2fix +regular_func float2fix + lsls r2, r0, #1 + // r0 = abs(zero) => r1 = 0x00000000 + // r0 = abs(denornaml) => r1 = 0x00xxxxxx + // r0 = abs(1.0f) => r1 = 0x7f000000 + // r0 = abs(inf/nan) => r1 = 0xffxxxxxx + bls float2fix_z // input positive or zero or -zero are ok for fix_z + lsrs r2, #24 + beq float2fix_z // input denormal will be flushed to zero + rsbs r3, r1, #0x7f + subs r2, r3 + bcc 1f // iunput <1.0f means we need to subtract 1 + // mask off all but fractional bits + lsls r2, r0, r2 + lsls r2, #9 + beq float2fix_z // input is integer +1: + push {lr} + bl float2fix_z + subs r0, #1 + sbcs r1, r1, #0 + pop {pc} + +float_section float2ufix +regular_func float2ufix +regular_func float2ufix_z + ubfx r2, r0, #23, #8 + adds r2, r1 + asrs r3, r2, #8 + beq 1f + ite pl + movpl r2, #0xff + movmi r2, #0 +1: + bfi r0, r2, #23, #8 + b float2uint_z +#endif diff --git a/src/rp2_common/pico_float/include/pico/float.h b/src/rp2_common/pico_float/include/pico/float.h index 6cafc83e4..ef95e1ecd 100644 --- a/src/rp2_common/pico_float/include/pico/float.h +++ b/src/rp2_common/pico_float/include/pico/float.h @@ -21,66 +21,294 @@ extern "C" { * * \brief Optimized single-precision floating point functions * -* (Replacement) optimized implementations are provided for the following compiler built-ins -* and math library functions on Arm: +* An application can take control of the floating point routines used in the application over and above what is provided by the compiler, +* by depending on the pico_float library. A user might want to do this * -* - __aeabi_fadd, __aeabi_fdiv, __aeabi_fmul, __aeabi_frsub, __aeabi_fsub, __aeabi_cfcmpeq, __aeabi_cfrcmple, __aeabi_cfcmple, __aeabi_fcmpeq, __aeabi_fcmplt, __aeabi_fcmple, __aeabi_fcmpge, __aeabi_fcmpgt, __aeabi_fcmpun, __aeabi_i2f, __aeabi_l2f, __aeabi_ui2f, __aeabi_ul2f, __aeabi_f2iz, __aeabi_f2lz, __aeabi_f2uiz, __aeabi_f2ulz, __aeabi_f2d, sqrtf, cosf, sinf, tanf, atan2f, expf, logf -* - ldexpf, copysignf, truncf, floorf, ceilf, roundf, asinf, acosf, atanf, sinhf, coshf, tanhf, asinhf, acoshf, atanhf, exp2f, log2f, exp10f, log10f, powf, hypotf, cbrtf, fmodf, dremf, remainderf, remquof, expm1f, log1pf, fmaf -* - powintf, sincosf (GNU extensions) +* 1. To use optimized software implementations provided by the RP2-series device's bootrom or the SDK +* 2. To use optimized combined software/hardware implementations utilizing custom RP2-series hardware for acceleration +* 3. To control the amount of C compiler/library code bloat +* 4. To make sure no floating point is called at all * -* The following additional optimized functions are also provided: +* The pico_float library comes in three main flavors: * -* - int2float, uint2float, int642float, uint642float, fix2float, ufix2float, fix642float, ufix642float -* - float2fix, float2ufix, float2fix64, float2ufix64, float2int, float2uint, float2int64, float2uint64, float2int_z, float2int64_z, float2uint_z, float2uint64_z -* - exp10f, sincosf, powintf +* 1. `pico_float_none` - all floating point operations cause a \ref panic - no single-precision floating point code is included +* 2. `pico_float_compiler` - no custom functions are provided; all single-precision floating point is handled by the C compiler/library +* 3. `pico_float_pico` - the smallest and fastest available for the platform, along with additional functionality (e.g. fixed point conversions) which are detailed below * -* On RP2350 (Arm) the following additional functions are available; the _fast methods are faster but do not round correctly +* The user can control which version they want (e.g. **pico_float_xxx** by either setting the CMake global variable +* `PICO_DEFAULT_FLOAT_IMPL=xxx`, or by using the CMake function `pico_set_float_implementation( xxx)`. Note that in the absence +* of either, pico_float_pico is used by default. * -* - float2fix64_z, fdiv_fast, fsqrt_fast, +* \if rp2040_specific +* On RP2040, `pico_float_pico` uses optimized hand coded implementations from the bootrom and the SDK for both +* basic single-precision floating point operations and floating point math library functions. These implementations +* are generally faster and smaller than those provided by the C compiler/library, though they don't support all the features of a fully compliant +* floating point implementation; they are however usually fine for the majority of cases +* \endif * -* On RP2350 RISC-V, only a small number of compiler runtime functions are overridden with faster implementations: +* \if rp2350_specific +* On Arm on RP2350, there are multiple options for `pico_float_pico`: * -* - __addsf3, __subsf3, __mulsf3 +* 1. `pico_float_pico_vfp` - this library leaves basic C single-precision floating point operations to the compiler +* which can use inlined VFP (Arm FPU) code. Custom optimized versions of trigonometric and scientific functions are provided. +* No DCP (RP2350 Double co-processor) instructions are used. +* 2. `pico_float_pico_dcp` - this library prevents the compiler injecting inlined VFP code, and also implements +* all single-precision floating point operations in optimized DCP or M33 code. This option is not quite as fast +* as pico_float_pico_vfp, however it allows floating point operations without enabling the floating point co-processor +* on the CPU; this can be beneficial in certain circumstances, e.g. where leaving stack in tasks or interrupts +* for the floating point state is undesirable. +* +* Note: `pico_float_pico` is equivalent to `pico_float_pico_vfp` on RP2350, as this is the most sensible default +* \endif +* +* On Arm, (replacement) optimized implementations are provided for the following compiler built-ins +* and math library functions when using `_pico` variants of `pico_float`: +* +* - basic arithmetic: (except `pico_float_pico_vfp`) +* +* __aeabi_fadd, __aeabi_fdiv, __aeabi_fmul, __aeabi_frsub, __aeabi_fsub +* +* - comparison: (except `pico_float_pico_vfp`) +* +* __aeabi_cfcmpeq, __aeabi_cfrcmple, __aeabi_cfcmple, __aeabi_fcmpeq, __aeabi_fcmplt, __aeabi_fcmple, __aeabi_fcmpge, __aeabi_fcmpgt, __aeabi_fcmpun +* +* - (u)int32 <-> float: (except `pico_float_pico_vfp`) +* +* __aeabi_i2f, __aeabi_ui2f, __aeabi_f2iz, __aeabi_f2uiz +* +* - (u)int64 <-> float: (except `pico_float_pico_vfp`) +* +* __aeabi_l2f, __aeabi_ul2f, __aeabi_f2lz, __aeabi_f2ulz +* +* - float -> double: (except `pico_float_pico_vfp`) +* +* __aeabi_f2d +* +* - basic trigonometric: +* +* sqrtf, cosf, sinf, tanf, atan2f, expf, logf +* +* - trigonometric and scientific +* +* ldexpf, copysignf, truncf, floorf, ceilf, roundf, asinf, acosf, atanf, sinhf, coshf, tanhf, asinhf, acoshf, atanhf, exp2f, log2f, exp10f, log10f, powf, hypotf, cbrtf, fmodf, dremf, remainderf, remquof, expm1f, log1pf, fmaf +* +* - GNU exetnsions: +* +* powintf, sincosf +* +* On Arm, the following additional optimized functions are also provided (when using `_pico` variants of `pico_float`): +* +* - Conversions to/from integer types: +* +* - (u)int -> float (round to nearest): +* +* int2float, uint2float, int642float, uint642float +* +* note: on `pico_float_pico_vfp` the 32-bit functions are also provided as C macros since they map to inline VFP code +* +* - (u)float -> int (round towards zero): +* +* float2int_z, float2uint_z, float2int64_z, float2uint64_z +* +* note: on `pico_float_pico_vfp` the 32-bit functions are also provided as C macros since they map to inline VFP code +* +* - (u)float -> int (round towards -infinity): +* +* float2int, float2uint, float2int64, float2uint64 +* +* - Conversions to/from fixed point integers: +* +* - (u)fix -> float (round to nearest): +* +* fix2float, ufix2float, fix642float, ufix642float +* +* - float -> (u)fix (round towards zero): +* +* float2fix_z, float2ufix_z, float2fix64_z, float2ufix64_z +* +* note: on `pico_float_pico_vfp` the 32-bit functions are also provided as C macros since they can map to inline VFP code +* when the number of fractional bits is a compile time constant between 1 and 32 +* +* - float -> (u)fix (round towards -infinity): +* +* float2fix, float2ufix, float2fix64, float2ufix64 +* +* note: on `pico_float_pico_vfp` the 32-bit functions are also provided as C macros since they can map to inline VFP code +* when the number of fractional bits is a compile time constant between 1 and 32 +* +* - Even faster versions of divide and square-root functions that do not round correctly: (`pico_float_pico_dcp` only) +* +* fdiv_fast, sqrtf_fast +* +* \if rp2350_specific +* On RISC-V, (replacement) optimized implementations are provided for the following compiler built-ins when using the `pico_float_pico` +* library (note that there are no variants of this library like there are on Arm): +* +* - basic arithmetic: +* +* __addsf3, __subsf3, __mulsf3 +* \endif */ - -// None of these functions are available on RISC-V: #if !defined(__riscv) || PICO_COMBINED_DOCS -float int2float(int32_t f); -float uint2float(uint32_t f); -float int642float(int64_t f); -float uint642float(uint64_t f); +#if PICO_COMBINED_DOCS || !LIB_PICO_FLOAT_COMPILER +float int2float(int32_t i); +float uint2float(uint32_t i); +float int642float(int64_t i); +float uint642float(uint64_t i); float fix2float(int32_t m, int e); float ufix2float(uint32_t m, int e); float fix642float(int64_t m, int e); float ufix642float(uint64_t m, int e); -// These methods round towards -Infinity. -int32_t float2fix(float f, int e); -uint32_t float2ufix(float f, int e); -int64_t float2fix64(float f, int e); -uint64_t float2ufix64(float f, int e); +// These methods round towards 0, which IS the C way +int32_t float2int_z(float f); +int64_t float2int64_z(float f); +int32_t float2uint_z(float f); +int64_t float2uint64_z(float f); +int32_t float2fix_z(float f, int e); +uint32_t float2ufix_z(float f, int e); +int64_t float2fix64_z(float f, int e); +uint64_t float2ufix64_z(float f, int e); + +// These methods round towards -Infinity - which IS NOT the C way for negative numbers; +// as such the naming is not ideal, however is kept for backwards compatibility int32_t float2int(float f); uint32_t float2uint(float f); int64_t float2int64(float f); uint64_t float2uint64(float f); +int32_t float2fix(float f, int e); +uint32_t float2ufix(float f, int e); +int64_t float2fix64(float f, int e); +uint64_t float2ufix64(float f, int e); -// These methods round towards 0. -int32_t float2int_z(float f); -int64_t float2int64_z(float f); -int32_t float2uint_z(float f); -int64_t float2uint64_z(float f); +#if LIB_PICO_FLOAT_PICO_VFP +// a bit of a hack to inline VFP fixed point conversion when exponent is constant and in range 1-32 +#define fix2float(m, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _fix2float_inline(m, e) : fix2 ## float(m, e), fix2 ## float(m, e)) +#define ufix2float(m, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _ufix2float_inline(m, e) : ufix2 ## float(m, e), ufix2 ## float(m, e)) +#define float2fix_z(f, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _float2fix_z_inline(f, e) : float2 ## fix_z(f, e), float2 ## fix_z(f, e)) +#define float2ufix_z(f, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _float2ufix_z_inline(f, e) : float2 ## ufix_z(f, e), float2 ## ufix_z(f, e)) +#define float2fix(f, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _float2fix_inline(f, e) : float2 ## fix(f, e), float2 ## fix(f, e)) +#define float2ufix(f, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _float2ufix_inline(f, e) : float2 ## ufix(f, e), float2 ## ufix(f, e)) + +#define _fix2float_inline(m, e) ({ \ + int32_t _m = m; \ + float f; \ + pico_default_asm( \ + "vmov %0, %1\n" \ + "vcvt.f32.s32 %0, %0, %2\n" \ + : "=t" (f) \ + : "r" (_m), "i" (e) \ + ); \ + f; \ +}) +#define _ufix2float_inline(m, e) ({ \ + uint32_t _m = m; \ + float f; \ + pico_default_asm( \ + "vmov %0, %1\n" \ + "vcvt.f32.u32 %0, %0, %2\n" \ + : "=t" (f) \ + : "r" (_m), "i" (e) \ + ); \ + f; \ +}) +#define _float2fix_z_inline(f, e) ({ \ + int32_t _m; \ + float _f = (f); \ + pico_default_asm( \ + "vcvt.s32.f32 %0, %0, %2\n" \ + "vmov %1, %0\n" \ + : "+t" (_f), "=r" (_m) \ + : "i" (e) \ + ); \ + _m; \ +}) +#define _float2ufix_z_inline(f, e) ({ \ + uint32_t _m; \ + float _f = (f); \ + pico_default_asm( \ + "vcvt.u32.f32 %0, %0, %2\n" \ + "vmov %1, %0\n" \ + : "+t" (_f), "=r" (_m) \ + : "i" (e) \ + ); \ + _m; \ +}) +#define _float2fix_z_inline(f, e) ({ \ + int32_t _m; \ + float _f = (f); \ + pico_default_asm( \ + "vcvt.s32.f32 %0, %0, %2\n" \ + "vmov %1, %0\n" \ + : "+t" (_f), "=r" (_m) \ + : "i" (e) \ + ); \ + _m; \ +}) +#define _float2fix_inline(f, e) ({ \ + union { float _f; int32_t _i; } _u; \ + _u._f = (f); \ + uint rc, tmp; \ + pico_default_asm( \ + "vcvt.s32.f32 %0, %0, %4\n" \ + "vmov %2, %0\n" \ + "lsls %1, #1\n" \ + "bls 2f\n" /* positive or zero or -zero are ok with the result we have */ \ + "lsrs %3, %1, #24\n" \ + "subs %3, #0x7f - %c4\n" \ + "bcc 1f\n" /* 0 < abs(f) < 1 ^ e, so need to round down */ \ + /* mask off all but fractional bits */ \ + "lsls %1, %3\n" \ + "lsls %1, #8\n" \ + "beq 2f\n" /* integers can round towards zero */ \ + "1:\n" \ + /* need to subtract 1 from the result to round towards -infinity... */ \ + /* this will never cause an overflow, because to get here we must have had a non integer/infinite value which */ \ + /* therefore cannot have been equal to INT64_MIN when rounded towards zero */ \ + "subs %2, #1\n" \ + "2:\n" \ + : "+t" (_u._f), "+r" (_u._i), "=r" (rc), "=r" (tmp) \ + : "i" (e) \ + ); \ + rc; \ +}) +#define _float2ufix_inline(f, e) _float2ufix_z_inline((f), (e)) +#endif + +#if LIB_PICO_FLOAT_PICO_VFP +// may as well provide inline macros for VFP +#define int2float(i) ((float)(int32_t)(i)) +#define uint2float(i) ((float)(uint32_t)(i)) +#define float2int_z(f) ((int32_t)(f)) +#define float2uint_z(f) ((uint32_t)(f)) +#endif + +#endif float exp10f(float x); void sincosf(float x, float *sinx, float *cosx); float powintf(float x, int y); #if !PICO_RP2040 || PICO_COMBINED_DOCS -int64_t float2fix64_z(float f, int e); float fdiv_fast(float n, float d); -float fsqrt_fast(float f); +float sqrtf_fast(float f); +#endif + #endif +#if defined(__riscv) || LIB_PICO_FLOAT_COMPILER +// when using the compiler or RISC-V, we provide as many functions as we trivially can - these will be efficient +// when using hard-float on Arm +static inline float int2float(int32_t i) { return (float)i; } +static inline float uint2float(uint32_t i) { return (float)i; } +static inline float int642float(int64_t i) { return (float)i; } +static inline float uint642float(uint64_t i) { return (float)i; } + +static inline int32_t float2int_z(float f) { return (int32_t)f; } +static inline int64_t float2int64_z(float f) { return (int64_t)f; } +static inline int32_t float2uint_z(float f) { return (uint32_t)f; } +static inline int64_t float2uint64_z(float f) { return (uint64_t)f; } #endif #ifdef __cplusplus diff --git a/test/pico_float_test/BUILD.bazel b/test/pico_float_test/BUILD.bazel index 1efdf724d..364053300 100644 --- a/test/pico_float_test/BUILD.bazel +++ b/test/pico_float_test/BUILD.bazel @@ -85,3 +85,12 @@ filegroup( name = "m33", srcs = ["m33.c"], ) + +# TODO: Add these tests to the Bazel build. +filegroup( + name = "unsupported_tests", + srcs = [ + "custom_double_funcs_test.c", + "custom_float_funcs_test.c", + ], +) \ No newline at end of file diff --git a/test/pico_float_test/CMakeLists.txt b/test/pico_float_test/CMakeLists.txt index 971c2a6d7..93845bb36 100644 --- a/test/pico_float_test/CMakeLists.txt +++ b/test/pico_float_test/CMakeLists.txt @@ -79,4 +79,31 @@ else () target_link_libraries(m33 pico_double pico_stdlib) pico_add_extra_outputs(m33) endif() + +endif() + +set(FLOAT_TYPES compiler) +set(DOUBLE_TYPES compiler) +list(APPEND FLOAT_TYPES pico) +list(APPEND DOUBLE_TYPES pico) +if (PICO_RP2350) + if (NOT PICO_RISCV) + list(APPEND FLOAT_TYPES pico_vfp pico_dcp) + endif() endif() + +foreach (FLOAT_TYPE IN LISTS FLOAT_TYPES) + add_executable(custom_float_funcs_test_${FLOAT_TYPE} custom_float_funcs_test.c) + pico_set_float_implementation(custom_float_funcs_test_${FLOAT_TYPE} ${FLOAT_TYPE}) + target_link_libraries(custom_float_funcs_test_${FLOAT_TYPE} PRIVATE pico_stdlib) + pico_add_extra_outputs(custom_float_funcs_test_${FLOAT_TYPE}) + pico_set_printf_implementation(custom_float_funcs_test_${FLOAT_TYPE} compiler) +endforeach () + +foreach (DOUBLE_TYPE IN LISTS DOUBLE_TYPES) + add_executable(custom_double_funcs_test_${DOUBLE_TYPE} custom_double_funcs_test.c) + pico_set_double_implementation(custom_double_funcs_test_${DOUBLE_TYPE} ${DOUBLE_TYPE}) + target_link_libraries(custom_double_funcs_test_${DOUBLE_TYPE} PRIVATE pico_stdlib) + pico_add_extra_outputs(custom_double_funcs_test_${DOUBLE_TYPE}) + pico_set_printf_implementation(custom_double_funcs_test_${DOUBLE_TYPE} compiler) +endforeach () \ No newline at end of file diff --git a/test/pico_float_test/custom_double_funcs_test.c b/test/pico_float_test/custom_double_funcs_test.c new file mode 100644 index 000000000..85624d4cb --- /dev/null +++ b/test/pico_float_test/custom_double_funcs_test.c @@ -0,0 +1,515 @@ +#include +#include "pico/stdlib.h" +#include "pico/double.h" +#include "math.h" + +#if 0 +#define printf(...) ((void)0) +#endif +#if 0 +#define stop() return -1 +#else +#define stop() rc=1 +#endif +#define test_assert(x) ({ if (!(x)) { printf("Assertion failed: ");puts(#x);printf(" at " __FILE__ ":%d\n", __LINE__); stop(); } }) +#define test_checkd(x, expected, msg) ({ if ((x) != (expected)) { printf(" %s: %f != %f\n", msg, x, expected); stop(); } }) +#define test_checki(x, expected, msg) ({ if ((x) != (expected)) { printf(" %s: %d != %d\n", msg, x, expected); stop(); } }) +#define test_checku(x, expected, msg) ({ if ((uint32_t)(x) != (uint32_t)(expected)) { printf(" %s: %u != %u\n", msg, x, expected); stop(); } }) +#define test_checki64(x, expected, msg) ({ if ((x) != (expected)) { printf(" %s: %lld != %lld\n", msg, (int64_t)(x), (int64_t)(expected)); stop(); } }) +#define test_checku64(x, expected, msg) ({ if ((uint64_t)(x) != (uint64_t)(expected)) { printf(" %s: %llu != %llu\n", msg, (uint64_t)(x), (uint64_t)(expected)); stop(); } }) + +#if !(LIB_PICO_DOUBLE_COMPILER || defined(__riscv)) +static inline double fix2double_8(int32_t m) { return fix2double(m, 8); } +static inline double fix2double_12(int32_t m) { return fix2double(m, 12); } +static inline double fix2double_16(int32_t m) { return fix2double(m, 16); } +static inline double fix2double_24(int32_t m) { return fix2double(m, 24); } +static inline double fix2double_28(int32_t m) { return fix2double(m, 28); } +static inline double fix2double_32(int32_t m) { return fix2double(m, 32); } + +static inline double ufix2double_12(int32_t m) { return ufix2double(m, 12); } + +static inline double double2fix_12(int32_t m) { return double2fix(m, 12); } + +static inline double double2ufix_12(int32_t m) { return double2ufix(m, 12); } +#endif + +#if 1 && (LIB_PICO_DOUBLE_COMPILER || defined(__riscv)) +#define double2int_z(f) ({ double _d = f; pico_default_asm_volatile("" : "+r" (_d)); double2 ## int_z(_d); }) +#define double2uint_z(f) ({ double _d = f; pico_default_asm_volatile("" : "+r" (_d)); double2 ## uint_z(_d); }) +#define double2int64_z(f) ({ double _d = f; pico_default_asm_volatile("" : "+r" (_d)); double2 ## int64_z(_d); }) +#define double2uint64_z(f) ({ double _d = f; pico_default_asm_volatile("" : "+r" (_d)); double2 ## uint64_z(_d); }) +#define int2double(i) ({ int32_t _i = i; pico_default_asm_volatile("" : "+r" (_i)); int2 ## double(_i); }) +#define uint2double(i) ({ uint32_t _i = i; pico_default_asm_volatile("" : "+r" (_i)); uint2 ## double(_i); }) +#define int642double(i) ({ int64_t _i = i; pico_default_asm_volatile("" : "+r" (_i)); int642 ## double(_i); }) +#define uint642double(i) ({ uint64_t _i = i; pico_default_asm_volatile("" : "+r" (_i)); uint642 ## double(_i); }) +#endif + +int test() { + int rc = 0; +#if LIB_PICO_DOUBLE_PICO + printf(">>> Using PICO\n"); +#endif + printf("int2double\n"); + test_checkd(int2double(0), 0.0, "int2double1"); + test_checkd(int2double(-1), -1.0, "int2double2"); + test_checkd(int2double(1), 1.0, "int2double3"); + test_checkd(int2double(INT32_MAX), 2147483647.0, "int2double4"); + test_checkd(int2double(INT32_MIN), -2147483648.0, "int2double5"); + // these have rounding behavior on float but not double + test_checkd(int2double(2147483391), 2147483391.0, "int2double6"); + test_checkd(int2double(2147483391), 2147483391.0, "int2double7"); + test_checkd(int2double(2147483457), 2147483457.0, "int2double8"); + test_checkd(int2double(2147483483), 2147483483.0, "int2double9"); + test_checkd(int2double(2147483584), 2147483584.0, "int2double10"); + + printf("uint2double\n"); + test_checkd(uint2double(0), 0.0, "uint2double1"); + test_checkd(uint2double(1), 1.0, "uint2double2"); + test_checkd(uint2double(INT32_MAX), 2147483647.0, "uint2double3"); + // todo test correct rounding around maximum precision + test_checkd(uint2double(UINT32_MAX), 4294967295.0, "uint2double4"); + + printf("int642double\n"); + test_checkd(int642double(0), 0.0, "int642double1"); + test_checkd(int642double(-1), -1.0, "int642double2"); + test_checkd(int642double(1), 1.0, "int642double3"); + test_checkd(int642double(INT32_MAX-1), 2147483646.0, "int642double4"); + test_checkd(int642double(INT32_MAX), 2147483647.0, "int642double5"); + test_checkd(int642double(INT32_MAX+1ll), 2147483648.0, "int642double6"); + test_checkd(int642double(INT32_MIN-1ll), -2147483649.0, "int642double7"); + test_checkd(int642double(INT32_MIN), -2147483648.0, "int642double8"); + test_checkd(int642double(INT32_MIN+1ll), -2147483647.0, "int642double9"); + // todo test correct rounding around maximum precision + test_checkd(int642double(INT64_MAX), 9223372036854775807.0, "int642double10"); + test_checkd(int642double(INT64_MIN), -9223372036854775808.0, "int642doubl11e"); + + printf("uint642double\n"); + test_checkd(uint642double(0), 0.0, "uint642double1"); + test_checkd(uint642double(1), 1.0, "uint642double2"); + test_checkd(uint642double(INT32_MAX-1), 2147483646.0, "uint642double3"); + test_checkd(uint642double(INT32_MAX), 2147483647.0, "uint642double4"); + test_checkd(uint642double(INT32_MAX+1ll), 2147483648.0, "uint642double5"); + test_checkd(uint642double(INT64_MAX), 9223372036854775807.0, "uint642double6"); + // todo test correct rounding around maximum precision + test_checkd(uint642double(UINT64_MAX), 18446744073709551615.0, "uint642double7"); + + union { + uint64_t u; + double d; + } u64d; + +#if !(LIB_PICO_DOUBLE_COMPILER || defined(__riscv)) + printf("fix2double\n"); + // todo test correct rounding around maximum precision + test_checkd(fix2double(-3, 1), -1.5, "fix2double1"); + test_checkd(fix2double(-3, 1), -1.5, "fix2double2"); + test_checkd(fix2double(-3, -4), -48.0, "fix2double3"); + + printf("ufix2double\n"); + // todo test correct rounding around maximum precision + test_checkd(ufix2double(0xa0000000, 30), 2.5, "ufix2double1"); + test_checkd(ufix2double(3, -4), 48.0, "ufix2double2"); + + printf("fix64double\n"); + // todo test correct rounding around maximum precision + test_checkd(fix642double(-0xa000000000ll, 38), -2.5, "fix642double1"); + test_checkd(fix642double(-3, -34), -51539607552.0, "fix642double2"); + + printf("ufix642double\n"); + // todo test correct rounding around maximum precision + test_checkd(ufix642double(0xa000000000ll, 38), 2.5, "ufix642double1"); + test_checkd(ufix642double(3, -34), 51539607552.0, "fix64double2"); + + test_checkd(fix2double_8(128), 0.5, "fix2double_8_1"); + test_checkd(fix2double_8(-128), -0.5, "fix2double_8_2"); + test_checkd(fix2double_16(8192), 0.125, "fix2double_8_3"); + test_checkd(fix2double_16(-8192), -0.125, "fix2double_8_4"); + test_checkd(fix2double_24(3<<23), 1.5, "fix2double_8_5"); + test_checkd(fix2double_24(-(3<<23)), -1.5, "fix2double_8_6"); + + printf("double2fix\n"); + test_checki(double2fix(-0.5, 8), -0x80, "double2fix0"); + test_checki(double2fix(3.5, 8), 0x380, "double2fix1"); + test_checki(double2fix(-3.5, 8), -0x380, "double2fix2"); + test_checki(double2fix(32768.0, 16), INT32_MAX, "double2fix3"); + test_checki(double2fix(65536.0, 16), INT32_MAX, "double2fix4"); + test_checki(double2fix(-65536.0, 16), INT32_MIN, "double2fix4b"); + test_checki(double2fix(INFINITY, 16), INT32_MAX, "double2fix5"); + test_checki(double2fix(-INFINITY, 16), INT32_MIN, "double2fix5b"); + test_checki(double2fix(INFINITY, -16), INT32_MAX, "double2fix5c"); + test_checki(double2fix(-INFINITY, -16), INT32_MIN, "double2fix5d"); + test_checki(double2fix(3.24999, 2), 12, "double2fix6"); + test_checki(double2fix(3.25, 2), 13, "double2fix7"); + test_checki(double2fix(-3.24999, 2), -13, "double2fix8"); + test_checki(double2fix(-3.25, 2), -13, "double2fix9"); + test_checki(double2fix(-0.75, 1), -2, "double2fix10"); + test_checki(double2fix(-3.0, -1), -2, "double2fix11"); // not very useful + test_checki(double2fix(0.0, 16), 0, "double2fix12"); + test_checki(double2fix(-0.0, 16), 0, "double2fix13"); + test_checki(double2fix(0.0, -16), 0, "double2fix14"); + test_checki(double2fix(-0.0, -16), 0, "double2fix15"); + + printf("double2ufix\n"); + test_checku(double2ufix(3.5, 8), 0x380, "double2ufix1"); + test_checku(double2ufix(-3.5, 8), 0, "double2ufix2"); + test_checku(double2ufix(32768.0, 16), 32768 << 16, "double2ufix3"); + test_checku(double2ufix(65536.0, 16), UINT32_MAX, "double2ufix4"); + test_checku(double2ufix(INFINITY, 16), UINT32_MAX, "double2ufix5"); + test_checku(double2ufix(-INFINITY, 16), 0, "double2ufix5b"); + test_checku(double2ufix(INFINITY, -16), UINT32_MAX, "double2ufix5c"); + test_checku(double2ufix(-INFINITY, -16), 0, "double2ufix5d"); + test_checku(double2ufix(3.24999, 2), 12, "double2ufix6"); + test_checku(double2ufix(3.25, 2), 13, "double2ufix7"); + test_checku(double2ufix(3.0, -1), 1, "double2ufix8"); // not very useful + test_checki(double2ufix(0.0, 16), 0, "double2ufix12"); + test_checki(double2ufix(-0.0, 16), 0, "double2fix13"); + test_checki(double2ufix(0.0, -16), 0, "double2ufix14"); + test_checki(double2ufix(-0.0, -16), 0, "double2fix15"); + + printf("double2fix64\n"); + test_checki64(double2fix64(3.5, 8), 0x380, "double2fix641"); + test_checki64(double2fix64(-3.5, 8), -0x380, "double2fix642"); + test_checki64(double2fix64(32768.0, 16), 32768ll << 16, "double2fix643"); + test_checki64(double2fix64(65536.0, 16), 65536ll << 16, "double2fix644"); + test_checki64(double2fix64(2147483648.0, 16), 2147483648ll << 16, "double2ufix644b"); + test_checki64(double2fix64(65536.0 * 65536.0 * 32768.0, 16), INT64_MAX, "double2fix644c"); + test_checki64(double2fix64(INFINITY, 16), INT64_MAX, "double2fix645"); + test_checki64(double2fix64(-INFINITY, 16), INT64_MIN, "double2fix645b"); + test_checki64(double2fix64(INFINITY, -16), INT64_MAX, "double2fix645c"); + test_checki64(double2fix64(-INFINITY, -16), INT64_MIN, "double2fix645d"); + test_checki64(double2fix64(3.24999, 2), 12, "double2fix646"); + test_checki64(double2fix64(3.25, 2), 13, "double2fix647"); + test_checki64(double2fix64(-3.24999, 2), -13, "double2fix648"); + test_checki64(double2fix64(-3.25, 2), -13, "double2fix649"); + test_checki64(double2fix64(-3.0, -1), -2, "double2fix6410"); // not very useful + test_checki64(double2fix64(2147483648.0 * 2147483648.0, 16), INT64_MAX, "double2ufix6411"); + test_checki64(double2fix64(0.0, 16), 0, "double2fix6412"); + test_checki64(double2fix64(-0.0, 16), 0, "double2fix6413"); + test_checki64(double2fix64(0.0, -16), 0, "double2fix6412b"); + test_checki64(double2fix64(-0.0, -16), 0, "double2fix6413b"); + test_checki64(double2fix64(-3.25, 40), -13ll * (1ll << 38), "double2fix6414"); + u64d.u = 0xc00a000000000001; + test_checki64(double2fix64(u64d.d, 40), -13ll * (1ll << 38) - 1ll, "double2fix6414b"); + + u64d.u = 0xc00a000080000001; + test_checki64(double2fix64(u64d.d, 20), -13ll * (1ll << 18) - 2ll, "double2fix6415c"); + u64d.u = 0xc00a000080000000; + test_checki64(double2fix64(u64d.d, 20), -13ll * (1ll << 18) - 1ll, "double2fix6415d"); + u64d.u = 0xc00a000000000001; + test_checki64(double2fix64(u64d.d, 20), -13ll * (1ll << 18) - 1ll, "double2fix6415e"); + u64d.u = 0xc00a000000000000; + test_checki64(double2fix64(u64d.d, 20), -13ll * (1ll << 18), "double2fix6415g"); + + u64d.u = 0xc00a000080000001; + test_checki64(double2fix64(u64d.d, 19), -13ll * (1ll << 17) - 1ll, "double2fix6415h"); + u64d.u = 0xc00a000080000000; + test_checki64(double2fix64(u64d.d, 19), -13ll * (1ll << 17) - 1ll, "double2fix6415i"); + u64d.u = 0xc00a000000000001; + test_checki64(double2fix64(u64d.d, 19), -13ll * (1ll << 17) - 1ll, "double2fix6415j"); + u64d.u = 0xc00a000000000000; + test_checki64(double2fix64(u64d.d, 19), -13ll * (1ll << 17), "double2fix6415k"); + + printf("double2ufix64\n"); + test_checku64(double2ufix64(3.5, 8), 0x380, "double2ufix641"); + test_checku64(double2ufix64(-3.5, 8), 0, "double2ufix642"); + test_checku64(double2ufix64(32768.0, 16), 32768ull << 16, "double2ufix643"); + test_checku64(double2ufix64(65536.0, 16), 65536ull << 16, "double2ufix644"); + test_checku64(double2ufix64(2147483648.0, 16), 2147483648ull << 16, "double2ufix644b"); + test_checku64(double2ufix64(INFINITY, 16), UINT64_MAX, "double2ufix645"); + test_checku64(double2ufix64(-INFINITY, 16), 0, "double2ufix645b"); + test_checku64(double2ufix64(INFINITY, -16), UINT64_MAX, "double2ufix645c"); + test_checku64(double2ufix64(-INFINITY, -16), 0, "double2ufix645d"); + test_checku64(double2ufix64(3.24999, 2), 12, "double2ufix646"); + test_checku64(double2ufix64(3.25, 2), 13, "double2ufix647"); + test_checku64(double2ufix64(3.0, -1), 1, "double2ufix648"); // not very useful + test_checki64(double2ufix64(0.0, 16), 0, "double2ufix649"); + test_checki64(double2ufix64(-0.0, 16), 0, "double2ufix6410"); + + printf("double2fix_z\n"); + test_checki(double2fix_z(3.5, 8), 0x380, "double2fix_z1"); + test_checki(double2fix_z(-3.5, 8), -0x380, "double2fix_z2"); + test_checki(double2fix_z(32768.0, 16), INT32_MAX, "double2fix_z3"); + test_checki(double2fix_z(65536.0, 16), INT32_MAX, "double2fix_z4"); + test_checki(double2fix_z(INFINITY, 16), INT32_MAX, "double2fix_z5"); + test_checki(double2fix_z(-INFINITY, 16), INT32_MIN, "double2fix_z5b"); + test_checki(double2fix_z(INFINITY, -50), INT32_MAX, "double2fix_z5c"); + test_checki(double2fix_z(-INFINITY, -50), INT32_MIN, "double2fix_z5d"); + test_checki(double2fix_z(3.24999, 2), 12, "double2fix_z6"); + test_checki(double2fix_z(3.25, 2), 13, "double2fix_z7"); + test_checki(double2fix_z(-3.24999, 2), -12, "double2fix_z8"); + test_checki(double2fix_z(-3.25, 2), -13, "double2fix_z9"); + test_checki(double2fix_z(-0.75, 1), -1, "double2fix_z10"); + test_checki(double2fix_z(-3.0, -1), -1, "double2fix_z11"); // not very useful + test_checki(double2fix_z(0.0, 16), 0, "double2fix_z12"); + test_checki(double2fix_z(-0.0, 16), 0, "double2fix_z13"); + test_checki(double2fix_z(0.0, -16), 0, "double2fix_z12b"); + test_checki(double2fix_z(-0.0, -16), 0, "double2fix_z13b"); + + printf("double2ufix_z\n"); + test_checku(double2ufix_z(3.5, 8), 0x380, "double2ufix_z1"); + test_checku(double2ufix_z(-3.5, 8), 0, "double2ufix_z2"); + test_checku(double2ufix_z(32768.0, 16), 32768 << 16, "double2ufix_z3"); + test_checku(double2ufix_z(65536.0, 16), UINT32_MAX, "double2ufix_z4"); + test_checku(double2ufix_z(INFINITY, 16), UINT32_MAX, "double2ufix_z5"); + test_checku(double2ufix_z(-INFINITY, 16), 0, "double2ufix_z5b"); + test_checku(double2ufix_z(INFINITY, 16), UINT32_MAX, "double2ufix_z5c"); + test_checku(double2ufix_z(-INFINITY, 16), 0, "double2ufix_z5d"); + test_checku(double2ufix_z(3.24999, 2), 12, "double2ufix_z6"); + test_checku(double2ufix_z(3.25, 2), 13, "double2ufix_z7"); + test_checku(double2ufix_z(3.0, -1), 1, "double2ufix_z8"); // not very useful + test_checki(double2ufix_z(0.0, 16), 0, "double2fix_z9"); + test_checki(double2ufix_z(-0.0, 16), 0, "double2fix_z10"); + test_checki(double2ufix_z(0.0, -16), 0, "double2fix_z11"); + test_checki(double2ufix_z(-0.0, -16), 0, "double2fix_z12"); + + printf("double2fix64_z\n"); + test_checki64(double2fix64_z(3.5, 8), 0x380, "double2fix64_z1"); + test_checki64(double2fix64_z(-3.5, 8), -0x380, "double2fix64_z2"); + test_checki64(double2fix64_z(32768.0, 16), 32768ll << 16, "double2fix64_z3"); + test_checki64(double2fix64_z(65536.0, 16), 65536ll << 16, "double2fix64_z4"); + test_checki64(double2fix64_z(65536.0 * 65536.0 * 32768.0, 16), INT64_MAX, "double2fix64_z4b"); + test_checki64(double2fix64_z(INFINITY, 16), INT64_MAX, "double2fix64_z5"); + test_checki64(double2fix64_z(-INFINITY, 16), INT64_MIN, "double2fix64_z5"); + test_checki64(double2fix64_z(INFINITY, 16), INT64_MAX, "double2fix64_z5"); + test_checki64(double2fix64_z(-INFINITY, 16), INT64_MIN, "double2fix64_z5"); + test_checki64(double2fix64_z(3.24999, 2), 12, "double2fix64_z6"); + test_checki64(double2fix64_z(3.25, 2), 13, "double2fix64_z7"); + test_checki64(double2fix64_z(-3.24999, 2), -12, "double2fix64_z8"); + test_checki64(double2fix64_z(-3.25, 2), -13, "double2fix64_z9"); + test_checki64(double2fix64_z(-3.0, -1), -1, "double2fix64_z10"); // not very useful + test_checki64(double2fix64_z(0.0, 16), 0, "double2fix64_z11"); + test_checki64(double2fix64_z(-0.0, 16), 0, "double2fix64_z12"); + test_checki64(double2fix64_z(0.0, -16), 0, "double2fix64_z13"); + test_checki64(double2fix64_z(-0.0, -16), 0, "double2fix64_z14"); + test_checki64(double2fix64_z(-3.25, 40), -13ll * (1ll << 38), "double2fix64_z15"); + u64d.u = 0xc00a000000000001; + test_checki64(double2fix64_z(u64d.d, 40), -13ll * (1ll << 38), "double2fix64_z15b"); + + u64d.u = 0xc00a000080000001; + test_checki64(double2fix64_z(u64d.d, 20), -13ll * (1ll << 18) - 1ll, "double2fix64_z15c"); + u64d.u = 0xc00a000080000000; + test_checki64(double2fix64_z(u64d.d, 20), -13ll * (1ll << 18) - 1ll, "double2fix64_z15d"); + u64d.u = 0xc00a000000000001; + test_checki64(double2fix64_z(u64d.d, 20), -13ll * (1ll << 18), "double2fix64_z15e"); + u64d.u = 0xc00a000000000000; + test_checki64(double2fix64_z(u64d.d, 20), -13ll * (1ll << 18), "double2fix64_z15g"); + + u64d.u = 0xc00a000080000001; + test_checki64(double2fix64_z(u64d.d, 19), -13ll * (1ll << 17), "double2fix64_z15h"); + u64d.u = 0xc00a000080000000; + test_checki64(double2fix64_z(u64d.d, 19), -13ll * (1ll << 17), "double2fix64_z15i"); + u64d.u = 0xc00a000000000001; + test_checki64(double2fix64_z(u64d.d, 19), -13ll * (1ll << 17), "double2fix64_z15j"); + u64d.u = 0xc00a000000000000; + test_checki64(double2fix64_z(u64d.d, 19), -13ll * (1ll << 17), "double2fix64_z15k"); + + printf("double2ufix64_z\n"); + test_checku64(double2ufix64_z(3.5, 8), 0x380, "double2ufix64_z1"); + test_checku64(double2ufix64_z(-3.5, 8), 0, "double2ufix64_z2"); + test_checku64(double2ufix64_z(32768.0, 16), 32768ll << 16, "double2ufix64_z3"); + test_checku64(double2ufix64_z(65536.0, 16), 65536ll << 16, "double2ufix64_z4"); + test_checki64(double2ufix64_z(65536.0 * 65536.0 * 65536.0, 16), UINT64_MAX, "double2fix64_z4b"); + test_checku64(double2ufix64_z(INFINITY, 16), UINT64_MAX, "double2ufix64_z5"); + test_checku64(double2ufix64_z(-INFINITY, 16), 0, "double2ufix64_z5b"); + test_checku64(double2ufix64_z(INFINITY, 16), UINT64_MAX, "double2ufix64_z5c"); + test_checku64(double2ufix64_z(-INFINITY, 16), 0, "double2ufix64_z5d"); + test_checku64(double2ufix64_z(3.24999, 2), 12, "double2ufix64_z6"); + test_checku64(double2ufix64_z(3.25, 2), 13, "double2ufix64_z7"); + test_checki64(double2ufix64_z(3.0, -1), 1, "double2fuix64_z8"); // not very useful + test_checki64(double2ufix64_z(0.0, 16), 0, "double2ufix64_z9"); + test_checki64(double2ufix64_z(-0.0, 16), 0, "double2ufix64_z10"); + test_checki64(double2ufix64_z(0.0, -16), 0, "double2ufix64_z11"); + test_checki64(double2ufix64_z(-0.0, -16), 0, "double2ufix64_z12"); + + printf("double2int\n"); + test_checki(double2int(0.0), 0, "double2int1"); + test_checki(double2int(0.25), 0, "double2int1b"); + test_checki(double2int(0.5), 0, "double2int2"); + test_checki(double2int(0.75), 0, "double2int2b"); + test_checki(double2int(1.0), 1, "double2int3"); + test_checki(double2int(-10.0), -10, "double2int3a"); + test_checki(double2int(-0.0), 0, "double2int3b"); + test_checki(double2int(-0.25), -1, "double2int4"); + test_checki(double2int(-0.5), -1, "double2int4b"); + test_checki(double2int(-0.75), -1, "double2int5"); + test_checki(double2int(-1.0), -1, "double2int5b"); + // todo test correct rounding around maximum precision + test_checki(double2int(2147483646.0), INT32_MAX-1, "double2int6"); + test_checki(double2int(2147483647.0), INT32_MAX, "double2int6b"); + test_checki(double2int(21474836470.0), INT32_MAX, "double2int7"); + test_checki(double2int(-2147483648.0), INT32_MIN, "double2int8"); + test_checki(double2int(-21474836480.0), INT32_MIN, "double2int9"); + test_checki(double2int(-2.5), -3, "double2int10"); + test_checki(double2int(-2.4), -3, "double2int11"); + u64d.u = 0xc000000000000000ull; + test_checki(double2int(u64d.d), -2, "double2int12"); + u64d.u = 0xc008000000000000ull; + test_checki(double2int(u64d.d), -3, "double2int12b"); + u64d.u = 0xc000000000000001ull; + test_checki(double2int(u64d.d), -3, "double2int12c"); + u64d.u = 0xc000000080000000ull; + test_checki(double2int(u64d.d), -3, "double2int12d"); + u64d.u = 0xc000000100000000ull; + test_checki(double2int(u64d.d), -3, "double2int12e"); + u64d.u = 0xc000000100000001ull; + test_checki(double2int(u64d.d), -3, "double2int12f"); + test_checki(double2int(-2147483647.0), INT32_MIN+1, "double2int13"); + test_checki(double2int(-2147483647.1), INT32_MIN, "double2int14"); + test_checki(double2int(-2147483647.9), INT32_MIN, "double2int15"); + test_checki(double2int(-2147483648.0), INT32_MIN, "double2int16"); + test_checki(double2int(-2147483648.1), INT32_MIN, "double2int17"); + test_checki(double2int(-21474836480.1), INT32_MIN, "double2int18"); + + printf("double2uint\n"); + test_checku(double2uint(0.0), 0, "double2uint1"); + test_checku(double2uint(0.25), 0, "double2uint2"); + test_checku(double2uint(0.5), 0, "double2uint3"); + test_checku(double2uint(0.75), 0, "double2uint4"); + test_checku(double2uint(1.0), 1, "double2uint5"); + test_checku(double2uint(2147483647.0), INT32_MAX, "double2uint6"); + test_checku(double2uint(2147483648.0), INT32_MAX+1u, "double2uint7"); + test_checku(double2uint(4294967294.5), UINT32_MAX-1, "double2uint8"); + test_checku(double2uint(4294967295.0), UINT32_MAX, "double2uint9"); + test_checku(double2uint(42949672950.0), UINT32_MAX, "double2uint10"); + + printf("double2int64\n"); + test_checki64(double2int64(0.0), 0, "double2int641"); + test_checki64(double2int64(0.25), 0, "double2int641b"); + test_checki64(double2int64(0.5), 0, "double2int642"); + test_checki64(double2int64(0.75), 0, "double2int642b"); + test_checki64(double2int64(1.0), 1, "double2int643"); + test_checki64(double2int64(-10.0), -10, "double2int643a"); + test_checki64(double2int64(-0.0), 0, "double2int643b"); + test_checki64(double2int64(-0.25), -1, "double2int644"); + test_checki64(double2int64(-0.5), -1, "double2int644b"); + test_checki64(double2int64(-0.75), -1, "double2int645"); + test_checki64(double2int64(-1.0), -1, "double2int645b"); + // todo test correct rounding around maximum precision + test_checki64(double2int64(2147483647.0), INT32_MAX, "double2int646"); + test_checki64(double2int64(21474836470.0), 21474836470ll, "double2int647"); + test_checki64(double2int64(-2147483648.0), INT32_MIN, "double2int648"); + test_checki64(double2int64(-21474836480.0), -21474836480ll, "double2int649"); + test_checki64(double2int64(-2.5), -3, "double2int6410"); + test_checki64(double2int64(-2.4), -3, "double2int6411"); + u64d.u = 0xc000000000000000ull; + test_checki64(double2int64(u64d.d), -2, "double2int6412"); + u64d.u = 0xc008000000000000ull; + test_checki64(double2int64(u64d.d), -3, "double2int6412b"); + u64d.u = 0xc000000000000001ull; + test_checki64(double2int64(u64d.d), -3, "double2int6412c"); + u64d.u = 0xc000000080000000ull; + test_checki64(double2int64(u64d.d), -3, "double2int6412d"); + u64d.u = 0xc000000100000000ull; + test_checki64(double2int64(u64d.d), -3, "double2int6412e"); + u64d.u = 0xc000000100000001ull; + test_checki64(double2int64(u64d.d), -3, "double2int6412f"); + + printf("double2uint64\n"); + test_checku64(double2uint64(0.0), 0, "double2uint641"); + test_checku64(double2uint64(0.25), 0, "double2uint642"); + test_checku64(double2uint64(0.5), 0, "double2uint643"); + test_checku64(double2uint64(0.75), 0, "double2uint644"); + test_checku64(double2uint64(1.0), 1, "double2uint645"); + test_checku64(double2uint64(2147483647.0), INT32_MAX, "double2uint646"); + test_checku64(double2uint64(2147483648.0), INT32_MAX+1u, "double2uint647"); + // todo test correct rounding around maximum precision + test_checku64(double2uint64(4294967294.5), 4294967294ull, "double2uint648"); + test_checku64(double2uint64(4294967295.0), 4294967295ull, "double2uint649"); + test_checku64(double2uint64(42949672950.0), 42949672950, "double2uint6410"); +#endif + + // // These methods round towards 0. + printf("double2int_z\n"); + test_checki(double2int_z(0.0), 0, "double2int_z1"); + test_checki(double2int_z(0.25), 0, "double2int_z1b"); + test_checki(double2int_z(0.5), 0, "double2int_z2"); + test_checki(double2int_z(0.75), 0, "double2int_z2b"); + test_checki(double2int_z(1.0), 1, "double2int_z3"); + test_checki(double2int_z(-10.0), -10, "double2int_z3a"); + test_checki(double2int_z(-0.0), 0, "double2int_z3b"); + test_checki(double2int_z(-0.25), 0, "double2int_z4"); + test_checki(double2int_z(-0.5), 0, "double2int_z4b"); + test_checki(double2int_z(-0.75), 0, "double2int_z5"); + test_checki(double2int_z(-1.0), -1, "double2int_z5b"); + // todo test correct rounding around maximum precision + test_checki(double2int_z(2147483647.0), INT32_MAX, "double2int_z6"); + test_checki(double2int_z(21474836470.0), INT32_MAX, "double2int_z7"); + test_checki(double2int_z(-2147483648.0), INT32_MIN, "double2int_z8"); + test_checki(double2int_z(-21474836480.0), INT32_MIN, "double2int_z9"); + test_checki(double2int_z(-2.5), -2, "double2int_z10"); + test_checki(double2int_z(-2.4), -2, "double2int_z11"); + u64d.u = 0xc000000000000000ull; + test_checki(double2int_z(u64d.d), -2, "double2int_z12"); + u64d.u = 0xc008000000000000ull; + test_checki(double2int_z(u64d.d), -3, "double2int_z12b"); + u64d.u = 0xc000000000000001ull; + test_checki(double2int_z(u64d.d), -2, "double2int_z12c"); + u64d.u = 0xc000000080000000ull; + test_checki(double2int_z(u64d.d), -2, "double2int_z12d"); + u64d.u = 0xc000000100000000ull; + test_checki(double2int_z(u64d.d), -2, "double2int_z12e"); + u64d.u = 0xc000000100000001ull; + test_checki(double2int_z(u64d.d), -2, "double2int_z12f"); + + printf("double2int64_z\n"); + test_checki64(double2int64_z(0.0), 0, "double2int64_z1"); + test_checki64(double2int64_z(0.25), 0, "double2int64_z1b"); + test_checki64(double2int64_z(0.5), 0, "double2int64_z2"); + test_checki64(double2int64_z(0.75), 0, "double2int64_z2b"); + test_checki64(double2int64_z(1.0), 1, "double2int64_z3"); + test_checki64(double2int64_z(-10.0), -10, "double2int64_z3a"); + test_checki64(double2int64_z(-0.0), 0, "double2int64_z3b"); + test_checki64(double2int64_z(-0.25), 0, "double2int64_z4"); + test_checki64(double2int64_z(-0.5), 0, "double2int64_z4b"); + test_checki64(double2int64_z(-0.75), 0, "double2int64_z5"); + test_checki64(double2int64_z(-1.0), -1, "double2int64_z5b"); + // todo test correct rounding around maximum precision + test_checki64(double2int64_z(2147483647.0), 2147483647ll, "double2int64_z6"); + test_checki64(double2int64_z(21474836470.0), 21474836470ll, "double2int64_z7"); + test_checki64(double2int64_z(-2147483648.0), INT32_MIN, "double2int64_z8"); + test_checki64(double2int64_z(-21474836480.0), -21474836480ll, "double2int64_z9"); + test_checki64(double2int64_z(-2.5), -2, "double2int64_z10"); + test_checki64(double2int64_z(-2.4), -2, "double2int64_z11"); + + printf("double2uint_z\n"); + test_checku(double2uint_z(0.0), 0, "double2uint_z1"); + test_checku(double2uint_z(0.25), 0, "double2uint_z2"); + test_checku(double2uint_z(0.5), 0, "double2uint_z3"); + test_checku(double2uint_z(0.75), 0, "double2uint_z4"); + test_checku(double2uint_z(1.0), 1, "double2uint_z5"); + test_checku(double2uint_z(2147483647.0), INT32_MAX, "double2uint_z6"); + test_checku(double2uint_z(2147483648.0), INT32_MAX+1u, "double2uint_z7"); + // todo test correct rounding around maximum precision + test_checku(double2uint_z(4294967294.5), UINT32_MAX-1u, "double2uint_z8"); + test_checku(double2uint_z(4294967295.0), UINT32_MAX, "double2uint_z9"); + test_checku(double2uint_z(42949672950.0), UINT32_MAX, "double2uint_z10"); + + printf("double2uint64_z\n"); + test_checku64(double2uint64_z(0.0), 0, "double2uint64_z1"); + test_checku64(double2uint64_z(0.25), 0, "double2uint64_z2"); + test_checku64(double2uint64_z(0.5), 0, "double2uint64_z3"); + test_checku64(double2uint64_z(0.75), 0, "double2uint64_z4"); + test_checku64(double2uint64_z(1.0), 1, "double2uint64_z5"); + test_checku64(double2uint64_z(2147483647.0), INT32_MAX, "double2uint64_z6"); + test_checku64(double2uint64_z(2147483648.0), INT32_MAX+1u, "double2uint64_z7"); + // todo test correct rounding around maximum precision + test_checku64(double2uint64_z(4294967294.5), 4294967294ull, "double2uint64_z8"); + test_checku64(double2uint64_z(4294967295.0), 4294967295ull, "double2uint64_z9"); + test_checku64(double2uint64_z(4294967296.0), 4294967296ull, "double2uint64_z9b"); + test_checku64(double2uint64_z(42949672950.0), 42949672950ull, "double2uint64_z10"); + + // double exp10(double x); + // void sincos(double x, double *sinx, double *cosx); + // double powint(double x, int y); + return rc; +} + +int main() { + stdio_init_all(); + int rc = test(); + if (rc) { + printf("FAILED\n"); + } else { + printf("PASSED\n"); + } +} diff --git a/test/pico_float_test/custom_float_funcs_test.c b/test/pico_float_test/custom_float_funcs_test.c new file mode 100644 index 000000000..d749f778a --- /dev/null +++ b/test/pico_float_test/custom_float_funcs_test.c @@ -0,0 +1,402 @@ +#include +#include "pico/stdlib.h" +#include "pico/float.h" +#include "math.h" + +#if 0 +#define printf(...) ((void)0) +#endif +#if 0 +#define stop() return -1 +#else +#define stop() rc=1 +#endif +#define test_assert(x) ({ if (!(x)) { printf("Assertion failed: ");puts(#x);printf(" at " __FILE__ ":%d\n", __LINE__); stop(); } }) +#define test_checkf(x, expected, msg) ({ if ((x) != (expected)) { printf(" %s: %f != %f\n", msg, x, expected); stop(); } }) +#define test_checki(x, expected, msg) ({ if ((x) != (expected)) { printf(" %s: %d != %d\n", msg, x, expected); stop(); } }) +#define test_checku(x, expected, msg) ({ if ((uint32_t)(x) != (uint32_t)(expected)) { printf(" %s: %u != %u\n", msg, x, expected); stop(); } }) +#define test_checki64(x, expected, msg) ({ if ((x) != (expected)) { printf(" %s: %lld != %lld\n", msg, (int64_t)(x), (int64_t)(expected)); stop(); } }) +#define test_checku64(x, expected, msg) ({ if ((uint64_t)(x) != (uint64_t)(expected)) { printf(" %s: %llu != %llu\n", msg, (uint64_t)(x), (uint64_t)(expected)); stop(); } }) + +#if !(LIB_PICO_FLOAT_COMPILER || defined(__riscv)) +static inline float fix2float_8(int32_t m) { return fix2float(m, 8); } +static inline float fix2float_12(int32_t m) { return fix2float(m, 12); } +static inline float fix2float_16(int32_t m) { return fix2float(m, 16); } +static inline float fix2float_24(int32_t m) { return fix2float(m, 24); } +static inline float fix2float_28(int32_t m) { return fix2float(m, 28); } +static inline float fix2float_32(int32_t m) { return fix2float(m, 32); } + +static inline float ufix2float_12(int32_t m) { return ufix2float(m, 12); } + +static inline float float2fix_12(int32_t m) { return float2fix(m, 12); } + +static inline float float2ufix_12(int32_t m) { return float2ufix(m, 12); } +#endif + +#if 1 && (LIB_PICO_FLOAT_COMPILER || defined(__riscv)) +#if __SOFTFP__ || defined(__riscv) +#define FREG "+r" +#else +#define FREG "+t" +#endif +// prevent the compiler from eliding the calculations +#define float2int_z(f) ({ float _f = f; pico_default_asm_volatile("" : FREG (_f)); float2 ## int_z(_f); }) +#define float2uint_z(f) ({ float _f = f; pico_default_asm_volatile("" : FREG (_f)); float2 ## uint_z(_f); }) +#define float2int64_z(f) ({ float _f = f; pico_default_asm_volatile("" : FREG (_f)); float2 ## int64_z(_f); }) +#define float2uint64_z(f) ({ float _f = f; pico_default_asm_volatile("" : FREG (_f)); float2 ## uint64_z(_f); }) +#define int2float(i) ({ int32_t _i = i; pico_default_asm_volatile("" : "+r" (_i)); int2 ## float(_i); }) +#define uint2float(i) ({ uint32_t _i = i; pico_default_asm_volatile("" : "+r" (_i)); uint2 ## float(_i); }) +#define int642float(i) ({ int64_t _i = i; pico_default_asm_volatile("" : "+r" (_i)); int642 ## float(_i); }) +#define uint642float(i) ({ uint64_t _i = i; pico_default_asm_volatile("" : "+r" (_i)); uint642 ## float(_i); }) +#endif + +#if 1 && LIB_PICO_FLOAT_VFP +// prevet the compiler from eliding the calculations +#undef float2int_z +#undef float2uint_z +#undef int2float +#undef uint2float +#endif + +int test() { + int rc = 0; +#if LIB_PICO_FLOAT_PICO_DCP + printf(">>> Using DCP\n"); +#endif +#if LIB_PICO_FLOAT_PICO_VFP + printf(">>> Using VFP\n"); +#endif + printf("int2float\n"); + test_checkf(int2float(0), 0.0f, "int2float1"); + test_checkf(int2float(-1), -1.0f, "int2float2"); + test_checkf(int2float(1), 1.0f, "int2float3"); + test_checkf(int2float(INT32_MAX), 2147483647.0f, "int2float4"); + test_checkf(int2float(INT32_MIN), -2147483648.0f, "int2float5"); + // check rounding + test_checkf(int2float(2147483391), 2147483392.0f, "int2float6"); + test_checkf(int2float(2147483456), 2147483392.0f, "int2float7"); + test_checkf(int2float(2147483457), 2147483520.0f, "int2float8"); + test_checkf(int2float(2147483483), 2147483520.0f, "int2float9"); + test_checkf(int2float(2147483584), 2147483648.0f, "int2float10"); + + printf("uint2float\n"); + test_checkf(uint2float(0), 0.0f, "uint2float1"); + test_checkf(uint2float(1), 1.0f, "uint2float2"); + test_checkf(uint2float(INT32_MAX), 2147483647.0f, "uint2float3"); + // todo test correct rounding around maximum precision + test_checkf(uint2float(UINT32_MAX), 4294967295.0f, "uint2float4"); + + printf("int642float\n"); + test_checkf(int642float(0), 0.0f, "int642float1"); + test_checkf(int642float(-1), -1.0f, "int642float2"); + test_checkf(int642float(1), 1.0f, "int642float3"); + test_checkf(int642float(INT32_MAX-1), 2147483646.0f, "int642float4"); // note equality is within 1ulp + test_checkf(int642float(INT32_MAX), 2147483647.0f, "int642float5"); // note equality is within 1ulp + test_checkf(int642float(INT32_MAX+1ll), 2147483648.0f, "int642float6"); + test_checkf(int642float(INT32_MIN-1ll), -2147483649.0f, "int642float7"); // note equality is within 1ulp + test_checkf(int642float(INT32_MIN), -2147483648.0f, "int642float8"); + test_checkf(int642float(INT32_MIN+1ll), -2147483647.0f, "int642float9"); // note equality is within 1ulp + // todo test correct rounding around maximum precision + test_checkf(int642float(INT64_MAX), 9223372036854775807.0f, "int642float10"); + test_checkf(int642float(INT64_MIN), -9223372036854775808.0f, "int642float11"); + + printf("uint642float\n"); + test_checkf(uint642float(0), 0.0f, "uint642float1"); + test_checkf(uint642float(1), 1.0f, "uint642float2"); + test_checkf(uint642float(INT32_MAX-1), 2147483646.0f, "uint642float3"); // note equality is within 1ulp + test_checkf(uint642float(INT32_MAX), 2147483647.0f, "uint642float4"); // note equality is within 1ulp + test_checkf(uint642float(INT32_MAX+1ll), 2147483648.0f, "uint642float5"); + test_checkf(uint642float(INT64_MAX), 9223372036854775807.0f, "uint642float6"); + // todo test correct rounding around maximum precision + test_checkf(uint642float(UINT64_MAX), 18446744073709551615.0f, "uint642float7"); + + union { + uint32_t u; + float f; + } u32f; + +#if !(LIB_PICO_FLOAT_COMPILER || defined(__riscv)) + printf("fix2float\n"); + // todo test correct rounding around maximum precision + test_checkf(fix2float(-3, 1), -1.5f, "fix2float1"); + test_checkf(fix2float(-3, 1), -1.5f, "fix2float2"); + test_checkf(fix2float(-3, -4), -48.0f, "fix2float3"); + + printf("ufix2float\n"); + // todo test correct rounding around maximum precision + test_checkf(ufix2float(0xa0000000, 30), 2.5f, "ufix2float1"); + test_checkf(ufix2float(3, -4), 48.0f, "ufix2float2"); + + printf("fix642float\n"); + // todo test correct rounding around maximum precision + test_checkf(fix642float(-0xa000000000ll, 38), -2.5f, "fix6422float1"); + test_checkf(fix642float(-3, -34), -51539607552.0f, "fix642float2"); + + printf("ufix642float\n"); + // todo test correct rounding around maximum precision + test_checkf(ufix642float(0xa000000000ll, 38), 2.5f, "ufix642float1"); + test_checkf(ufix642float(3, -34), 51539607552.0f, "fix64float2"); + + test_checkf(fix2float_8(128), 0.5f, "fix2float_8_1"); + test_checkf(fix2float_8(-128), -0.5f, "fix2float_8_2"); + test_checkf(fix2float_16(8192), 0.125f, "fix2float_8_3"); + test_checkf(fix2float_16(-8192), -0.125f, "fix2float_8_4"); + test_checkf(fix2float_24(3<<23), 1.5f, "fix2float_8_5"); + test_checkf(fix2float_24(-(3<<23)), -1.5f, "fix2float_8_6"); + + printf("float2fix\n"); + test_checki(float2fix(-0.5f, 8), -0x80, "float2fix0"); + test_checki(float2fix(3.5f, 8), 0x380, "float2fix1"); + test_checki(float2fix(-3.5f, 8), -0x380, "float2fix2"); + test_checki(float2fix(32768.0f, 16), INT32_MAX, "float2fix3"); + test_checki(float2fix(65536.0f, 16), INT32_MAX, "float2fix4"); + test_checki(float2fix(-65536.0f, 16), INT32_MIN, "float2fix4b"); + test_checki(float2fix(INFINITY, 16), INT32_MAX, "float2fix5"); + test_checki(float2fix(-INFINITY, 16), INT32_MIN, "float2fix5b"); + test_checki(float2fix(3.24999f, 2), 12, "float2fix6"); + test_checki(float2fix(3.25f, 2), 13, "float2fix7"); + test_checki(float2fix(-3.24999f, 2), -13, "float2fix8"); + test_checki(float2fix(-3.25f, 2), -13, "float2fix9"); + test_checki(float2fix(-0.75f, 1), -2, "float2fix10"); + test_checki(float2fix(-3.0f, -1), -2, "float2fix11"); // not very useful + u32f.u = 0x7f012345; + test_checki(float2fix(u32f.f, 1), INT32_MAX, "float2fix12"); + u32f.u = 0xff012345; + test_checki(float2fix(u32f.f, 1), INT32_MIN, "float2fix13"); + + printf("float2ufix\n"); + test_checku(float2ufix(3.5f, 8), 0x380, "float2ufix1"); + test_checku(float2ufix(-3.5f, 8), 0, "float2ufix2"); + test_checku(float2ufix(32768.0f, 16), 32768 << 16, "float2ufix3"); + test_checku(float2ufix(65536.0f, 16), UINT32_MAX, "float2ufix4"); + test_checku(float2ufix(INFINITY, 16), UINT32_MAX, "float2ufix5"); + test_checku(float2ufix(3.24999f, 2), 12, "float2ufix6"); + test_checku(float2ufix(3.25f, 2), 13, "float2ufix7"); + test_checku(float2ufix(3.0f, -1), 1, "float2ufix8"); // not very useful + + printf("float2fix64\n"); + test_checki64(float2fix64(3.5f, 8), 0x380, "float2fix641"); + test_checki64(float2fix64(-3.5f, 8), -0x380, "float2fix642"); + test_checki64(float2fix64(32768.0f, 16), 32768ll << 16, "float2fix643"); + test_checki64(float2fix64(65536.0f, 16), 65536ll << 16, "float2fix644"); + test_checki64(float2fix64(2147483648.0f, 16), 2147483648ll << 16, "float2ufix644b"); + test_checki64(float2fix64(65536.0f * 65536.0f * 32768.0f, 16), INT64_MAX, "float2fix644c"); + test_checki64(float2fix64(INFINITY, 16), INT64_MAX, "float2fix645"); + test_checki64(float2fix64(3.24999f, 2), 12, "float2fix646"); + test_checki64(float2fix64(3.25f, 2), 13, "float2fix647"); + test_checki64(float2fix64(-3.24999f, 2), -13, "float2fix648"); + test_checki64(float2fix64(-3.25f, 2), -13, "float2fix649"); + test_checki64(float2fix64(-3.0f, -1), -2, "float2fix6410"); // not very useful + + printf("float2ufix64\n"); + test_checku64(float2ufix64(3.5f, 8), 0x380, "float2ufix641"); + test_checku64(float2ufix64(-3.5f, 8), 0, "float2ufix642"); + test_checku64(float2ufix64(32768.0f, 16), 32768ull << 16, "float2ufix643"); + test_checku64(float2ufix64(65536.0f, 16), 65536ull << 16, "float2ufix644"); + test_checku64(float2ufix64(2147483648.0f, 16), 2147483648ull << 16, "float2ufix644b"); + test_checku64(float2ufix64(INFINITY, 16), UINT64_MAX, "float2ufix645"); + test_checku64(float2ufix64(3.24999f, 2), 12, "float2ufix646"); + test_checku64(float2ufix64(3.25f, 2), 13, "float2ufix647"); + test_checku64(float2ufix64(3.0f, -1), 1, "float2ufix648"); // not very useful + + printf("float2fix_z\n"); + test_checki(float2fix_z(3.5f, 8), 0x380, "float2fix_z1"); + test_checki(float2fix_z(-3.5f, 8), -0x380, "float2fix_z2"); + test_checki(float2fix_z(32768.0f, 16), INT32_MAX, "float2fix_z3"); + test_checki(float2fix_z(65536.0f, 16), INT32_MAX, "float2fix_z4"); + test_checki(float2fix_z(INFINITY, 16), INT32_MAX, "float2fix_z5"); + test_checki(float2fix_z(-INFINITY, 16), INT32_MIN, "float2fix_z5b"); + test_checki(float2fix_z(3.24999f, 2), 12, "float2fix_z6"); + test_checki(float2fix_z(3.25f, 2), 13, "float2fix_z7"); + test_checki(float2fix_z(-3.24999f, 2), -12, "float2fix_z8"); + test_checki(float2fix_z(-3.25f, 2), -13, "float2fix_z9"); + test_checki(float2fix_z(-0.75f, 1), -1, "float2fix_z10"); + test_checki(float2fix_z(-3.0f, -1), -1, "float2fix_z11"); // not very useful + u32f.u = 0x7f012345; + test_checki(float2fix_z(u32f.f, 1), INT32_MAX, "float2fix_z12"); + u32f.u = 0xff012345; + test_checki(float2fix_z(u32f.f, 1), INT32_MIN, "float2fix_z13"); + + printf("float2ufix_z\n"); + test_checku(float2ufix_z(3.5f, 8), 0x380, "float2ufix_z1"); + test_checku(float2ufix_z(-3.5f, 8), 0, "float2ufix_z2"); + test_checku(float2ufix_z(32768.0f, 16), 32768 << 16, "float2ufix_z3"); + test_checku(float2ufix_z(65536.0f, 16), UINT32_MAX, "float2ufix_z4"); + test_checku(float2ufix_z(INFINITY, 16), UINT32_MAX, "float2ufix_z5"); + test_checku(float2ufix_z(3.24999f, 2), 12, "float2ufix_z6"); + test_checku(float2ufix_z(3.25f, 2), 13, "float2ufix_z7"); + test_checku(float2ufix_z(3.0f, -1), 1, "float2ufix_z8"); // not very useful + u32f.u = 0x7f012345; + test_checku(float2ufix_z(u32f.f, 1), UINT32_MAX, "float2fix_z9"); + u32f.u = 0xff012345; + test_checku(float2ufix_z(u32f.f, 1), 0, "float2fix_z10"); + + printf("float2fix64_z\n"); + test_checki64(float2fix64_z(3.5f, 8), 0x380, "float2fix64_z1"); + test_checki64(float2fix64_z(-3.5f, 8), -0x380, "float2fix64_z2"); + test_checki64(float2fix64_z(32768.0f, 16), 32768ll << 16, "float2fix64_z3"); + test_checki64(float2fix64_z(65536.0f, 16), 65536ll << 16, "float2fix64_z4"); + test_checki64(float2fix64_z(65536.0f * 65536.0f * 32768.0f, 16), INT64_MAX, "float2fix64_z4b"); + test_checki64(float2fix64_z(INFINITY, 16), INT64_MAX, "float2fix64_z5"); + test_checki64(float2fix64_z(3.24999f, 2), 12, "float2fix64_z6"); + test_checki64(float2fix64_z(3.25f, 2), 13, "float2fix64_z7"); + test_checki64(float2fix64_z(-3.24999f, 2), -12, "float2fix64_z8"); + test_checki64(float2fix64_z(-3.25f, 2), -13, "float2fix64_z9"); + test_checki64(float2fix64_z(-3.0f, -1), -1, "float2fix64_z10"); // not very useful + + printf("float2ufix64_z\n"); + test_checku64(float2ufix64_z(3.5f, 8), 0x380, "float2ufix64_z1"); + test_checku64(float2ufix64_z(-3.5f, 8), 0, "float2ufix64_z2"); + test_checku64(float2ufix64_z(32768.0f, 16), 32768ll << 16, "float2ufix64_z3"); + test_checku64(float2ufix64_z(65536.0f, 16), 65536ll << 16, "float2ufix64_z4"); + test_checki64(float2ufix64_z(65536.0f * 65536.0f * 65536.0f, 16), UINT64_MAX, "float2fix64_z4b"); + test_checku64(float2ufix64_z(INFINITY, 16), UINT64_MAX, "float2ufix64_z5"); + test_checku64(float2ufix64_z(3.24999f, 2), 12, "float2ufix64_z6"); + test_checku64(float2ufix64_z(3.25f, 2), 13, "float2ufix64_z7"); + test_checki64(float2ufix64_z(3.0f, -1), 1, "float2fuix64_z8"); // not very useful + + printf("float2int\n"); + test_checki(float2int(0.0f), 0, "float2int1"); + test_checki(float2int(0.25f), 0, "float2int1b"); + test_checki(float2int(0.5f), 0, "float2int2"); + test_checki(float2int(0.75f), 0, "float2int2b"); + test_checki(float2int(1.0f), 1, "float2int3"); + test_checki(float2int(-10.0f), -10, "float2int3a"); + test_checki(float2int(-0.0f), 0, "float2int3b"); + test_checki(float2int(-0.25f), -1, "float2int4"); + test_checki(float2int(-0.5f), -1, "float2int4b"); + test_checki(float2int(-0.75f), -1, "float2int5"); + test_checki(float2int(-1.0f), -1, "float2int5b"); + // todo test correct rounding around maximum precision + test_checki(float2int(2147483647.0f), INT32_MAX, "float2int6"); + test_checki(float2int(21474836470.0f), INT32_MAX, "float2int7"); + test_checki(float2int(-2147483648.0f), INT32_MIN, "float2int8"); + test_checki(float2int(-21474836480.0f), INT32_MIN, "float2int9"); + test_checki(float2int(-2.5f), -3, "float2int10"); + test_checki(float2int(-2.4f), -3, "float2int11"); + + printf("float2uint\n"); + test_checku(float2uint(0.0f), 0, "float2uint1"); + test_checku(float2uint(0.25f), 0, "float2uint2"); + test_checku(float2uint(0.5f), 0, "float2uint3"); + test_checku(float2uint(0.75f), 0, "float2uint4"); + test_checku(float2uint(1.0f), 1, "float2uint5"); + test_checku(float2uint(2147483647.0f), INT32_MAX+1u, "float2uint6"); // note loss of precision + test_checku(float2uint(2147483648.0f), INT32_MAX+1u, "float2uint7"); + test_checku(float2uint(4294967294.5f), UINT32_MAX, "float2uint8"); // note loss of precision + test_checku(float2uint(4294967295.0f), UINT32_MAX, "float2uint9"); + test_checku(float2uint(42949672950.0f), UINT32_MAX, "float2uint10"); + + printf("float2int64\n"); + test_checki64(float2int64(0.0f), 0, "float2int641"); + test_checki64(float2int64(0.25f), 0, "float2int641b"); + test_checki64(float2int64(0.5f), 0, "float2int642"); + test_checki64(float2int64(0.75f), 0, "float2int642b"); + test_checki64(float2int64(1.0f), 1, "float2int643"); + test_checki64(float2int64(-10.0f), -10, "float2int643a"); + test_checki64(float2int64(-0.0f), 0, "float2int643b"); + test_checki64(float2int64(-0.25f), -1, "float2int644"); + test_checki64(float2int64(-0.5f), -1, "float2int644b"); + test_checki64(float2int64(-0.75f), -1, "float2int645"); + test_checki64(float2int64(-1.0f), -1, "float2int645b"); + // todo test correct rounding around maximum precision + test_checki64(float2int64(2147483647.0f), INT32_MAX+1ll, "float2int646"); + test_checki64(float2int64(21474836470.0f), 21474836480ll, "float2int647"); // note loss of precision + test_checki64(float2int64(-2147483648.0f), INT32_MIN, "float2int648"); + test_checki64(float2int64(-21474836480.0f), -21474836480ll, "float2int649"); + test_checki64(float2int64(-2.5f), -3, "float2int6410"); + test_checki64(float2int64(-2.4f), -3, "float2int6411"); + + printf("float2uint64\n"); + test_checku64(float2uint64(0.0f), 0, "float2uint641"); + test_checku64(float2uint64(0.25f), 0, "float2uint642"); + test_checku64(float2uint64(0.5f), 0, "float2uint643"); + test_checku64(float2uint64(0.75f), 0, "float2uint644"); + test_checku64(float2uint64(1.0f), 1, "float2uint645"); + test_checku64(float2uint64(2147483647.0f), INT32_MAX+1u, "float2uint646"); // note loss of precision + test_checku64(float2uint64(2147483648.0f), INT32_MAX+1u, "float2uint647"); + test_checku64(float2uint64(4294967294.5f), 4294967296ull, "float2uint648"); // note loss of precision + test_checku64(float2uint64(4294967295.0f), 4294967296ull, "float2uint649"); // note loss of precision + test_checku64(float2uint64(42949672950.0f), 42949672960ull, "float2uint6410"); // note loss of precision +#endif + + // // These methods round towards 0. + printf("float2int_z\n"); + test_checki(float2int_z(0.0f), 0, "float2int_z1"); + test_checki(float2int_z(0.25f), 0, "float2int_z1b"); + test_checki(float2int_z(0.5f), 0, "float2int_z2"); + test_checki(float2int_z(0.75f), 0, "float2int_z2b"); + test_checki(float2int_z(1.0f), 1, "float2int_z3"); + test_checki(float2int_z(-10.0f), -10, "float2int_z3a"); + test_checki(float2int_z(-0.0f), 0, "float2int_z3b"); + test_checki(float2int_z(-0.25f), 0, "float2int_z4"); + test_checki(float2int_z(-0.5f), 0, "float2int_z4b"); + test_checki(float2int_z(-0.75f), 0, "float2int_z5"); + test_checki(float2int_z(-1.0f), -1, "float2int_z5b"); + // todo test correct rounding around maximum precision + test_checki(float2int_z(2147483647.0f), INT32_MAX, "float2int_z6"); + test_checki(float2int_z(21474836470.0f), INT32_MAX, "float2int_z7"); + test_checki(float2int_z(-2147483648.0f), INT32_MIN, "float2int_z8"); + test_checki(float2int_z(-21474836480.0f), INT32_MIN, "float2int_z9"); + test_checki(float2int_z(-2.5f), -2, "float2int_z10"); + test_checki(float2int_z(-2.4f), -2, "float2int_z11"); + + printf("float2int64_z\n"); + test_checki64(float2int64_z(0.0f), 0, "float2int64_z1"); + test_checki64(float2int64_z(0.25f), 0, "float2int64_z1b"); + test_checki64(float2int64_z(0.5f), 0, "float2int64_z2"); + test_checki64(float2int64_z(0.75f), 0, "float2int64_z2b"); + test_checki64(float2int64_z(1.0f), 1, "float2int64_z3"); + test_checki64(float2int64_z(-10.0f), -10, "float2int64_z3a"); + test_checki64(float2int64_z(-0.0f), 0, "float2int64_z3b"); + test_checki64(float2int64_z(-0.25f), 0, "float2int64_z4"); + test_checki64(float2int64_z(-0.5f), 0, "float2int64_z4b"); + test_checki64(float2int64_z(-0.75f), 0, "float2int64_z5"); + test_checki64(float2int64_z(-1.0f), -1, "float2int64_z5b"); + test_checki64(float2int64_z(2147483647.0f), 2147483648ll, "float2int64_z6"); // note loss of precision + test_checki64(float2int64_z(21474836470.0f), 21474836480ll, "float2int64_z7"); // note loss of precision + test_checki64(float2int64_z(-2147483648.0f), INT32_MIN, "float2int64_z8"); + test_checki64(float2int64_z(-21474836480.0f), -21474836480ll, "float2int64_z9"); + test_checki64(float2int64_z(-2.5f), -2, "float2int64_z10"); + test_checki64(float2int64_z(-2.4f), -2, "float2int64_z11"); + + printf("float2uint_z\n"); + test_checku(float2uint_z(0.0f), 0, "float2uint_z1"); + test_checku(float2uint_z(0.25f), 0, "float2uint_z2"); + test_checku(float2uint_z(0.5f), 0, "float2uint_z3"); + test_checku(float2uint_z(0.75f), 0, "float2uint_z4"); + test_checku(float2uint_z(1.0f), 1, "float2uint_z5"); + test_checku(float2uint_z(2147483647.0f), INT32_MAX+1u, "float2uint_z6"); // note loss of precision + test_checku(float2uint_z(2147483648.0f), INT32_MAX+1u, "float2uint_z7"); + // todo test correct rounding around maximum precision + test_checku(float2uint_z(4294967294.5f), UINT32_MAX, "float2uint_z8"); // note loss of precision + test_checku(float2uint_z(4294967295.0f), UINT32_MAX, "float2uint_z9"); + test_checku(float2uint_z(42949672950.0f), UINT32_MAX, "float2uint_z10"); + + printf("float2uint64_z\n"); + test_checku64(float2uint64_z(0.0f), 0, "float2uint64_z1"); + test_checku64(float2uint64_z(0.25f), 0, "float2uint64_z2"); + test_checku64(float2uint64_z(0.5f), 0, "float2uint64_z3"); + test_checku64(float2uint64_z(0.75f), 0, "float2uint64_z4"); + test_checku64(float2uint64_z(1.0f), 1, "float2uint64_z5"); + test_checku64(float2uint64_z(2147483647.0f), INT32_MAX+1u, "float2uint64_z6"); // note loss of precision + test_checku64(float2uint64_z(2147483648.0f), INT32_MAX+1u, "float2uint64_z7"); + test_checku64(float2uint64_z(4294967294.5f), 4294967296ull, "float2uint64_z8"); // note loss of precision + test_checku64(float2uint64_z(4294967295.0f), 4294967296ull, "float2uint64_z9"); // note loss of precision + test_checku64(float2uint64_z(42949672950.0f), 42949672960ull, "float2uint64_z10"); // note loss of precision + + // float exp10f(float x); + // void sincosf(float x, float *sinx, float *cosx); + // float powintf(float x, int y); + return rc; +} + +int main() { + stdio_init_all(); + int rc = test(); + if (rc) { + printf("FAILED\n"); + } else { + printf("PASSED\n"); + } +} From eb5c2c3ff02118645f33fbee770d5d254407554f Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 5 Feb 2025 10:55:10 -0600 Subject: [PATCH 039/224] Clang related fixes (#2231) * workaround change in llvm picked up by llvm ETA 19 * fix clang compilation not including floating point instructions in build output --- cmake/preload/toolchains/pico_arm_clang_arm.cmake | 2 -- cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake | 2 +- src/cmake/on_device.cmake | 3 +-- src/rp2_common/pico_clib_interface/picolibc_interface.c | 2 ++ 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cmake/preload/toolchains/pico_arm_clang_arm.cmake b/cmake/preload/toolchains/pico_arm_clang_arm.cmake index bf06d3410..4c7816561 100644 --- a/cmake/preload/toolchains/pico_arm_clang_arm.cmake +++ b/cmake/preload/toolchains/pico_arm_clang_arm.cmake @@ -1,5 +1,3 @@ -# NOTE: THIS IS A WIP ONLY PICO_ARM_GCC IS CURRENTLY SUPPORTED -# todo there is probably a more "cmake" way of doing this going thru the standard path with our "PICO" platform # i.e. CMakeInformation and whatnot include(${CMAKE_CURRENT_LIST_DIR}/util/find_compiler.cmake) diff --git a/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake b/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake index d35bdbc19..c5199e55a 100644 --- a/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake +++ b/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake @@ -4,5 +4,5 @@ set(CMAKE_SYSTEM_PROCESSOR cortex-m33) set(PICO_CLANG_RUNTIMES armv8m.main_soft_nofp armv8m.main-unknown-none-eabi) set(PICO_COMMON_LANG_FLAGS "-mcpu=cortex-m33 --target=armv8m.main-none-eabi -mfloat-abi=softfp -march=armv8m.main+fp+dsp") - +set(PICO_DISASM_OBJDUMP_ARGS --mcpu=cortex-m33 --arch=armv8m.main+fp+dsp) include(${CMAKE_CURRENT_LIST_DIR}/util/pico_arm_clang_common.cmake) diff --git a/src/cmake/on_device.cmake b/src/cmake/on_device.cmake index 5cabf3cc9..00a5fffc6 100644 --- a/src/cmake/on_device.cmake +++ b/src/cmake/on_device.cmake @@ -37,10 +37,9 @@ function(pico_add_dis_output TARGET) set(EXTRA_COMMAND COMMAND picotool coprodis --quiet ${output_path}$>,$,$>.dis ${output_path}$>,$,$>.dis) endif() endif() - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJDUMP} -h $ > ${output_path}$>,$,$>.dis - COMMAND ${CMAKE_OBJDUMP} -d $ >> ${output_path}$>,$,$>.dis + COMMAND ${CMAKE_OBJDUMP} -d ${PICO_DISASM_OBJDUMP_ARGS} $ >> ${output_path}$>,$,$>.dis ${EXTRA_COMMAND} VERBATIM ) diff --git a/src/rp2_common/pico_clib_interface/picolibc_interface.c b/src/rp2_common/pico_clib_interface/picolibc_interface.c index 728e93a56..63d79135e 100644 --- a/src/rp2_common/pico_clib_interface/picolibc_interface.c +++ b/src/rp2_common/pico_clib_interface/picolibc_interface.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include From 111fa7de2d761975e19872cf46718b2399e6c33d Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 5 Feb 2025 10:55:24 -0600 Subject: [PATCH 040/224] small pioasm improvements (#2224) - fix disassembly of `wait jmppin` - fix incorrect error message - make python output emit `word(x)` for all unsupported instructions --- tools/pioasm/pio_assembler.cpp | 2 +- tools/pioasm/pio_disassembler.cpp | 11 ++++++--- tools/pioasm/python_output.cpp | 38 ++++++++++++++++++------------- tools/pioasm/test/amethyst.pio | 7 ++++++ 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/tools/pioasm/pio_assembler.cpp b/tools/pioasm/pio_assembler.cpp index a427c22e4..3a8a3009d 100644 --- a/tools/pioasm/pio_assembler.cpp +++ b/tools/pioasm/pio_assembler.cpp @@ -63,7 +63,7 @@ void program::set_pio_version(const yy::location &l, int version) { void program::set_clock_div(const yy::location &l, float clock_div) { if (clock_div < 1.0f || clock_div >= 65536.0f) { - throw syntax_error(l, "clock divider must be between 1 and 65546"); + throw syntax_error(l, "clock divider must be between 1 and 65535"); } clock_div_int = (uint16_t)clock_div; if (clock_div_int == 0) { diff --git a/tools/pioasm/pio_disassembler.cpp b/tools/pioasm/pio_disassembler.cpp index 2a34796d0..74d862bc6 100644 --- a/tools/pioasm/pio_disassembler.cpp +++ b/tools/pioasm/pio_disassembler.cpp @@ -56,7 +56,9 @@ std::string disassemble(uint inst, uint sideset_bits_including_opt, bool sideset if (arg2 & 0x1cu) { invalid = true; } else if (arg2) { - guts = "jmppin " + std::to_string(arg2 & 3u); + guts = "jmppin + " + std::to_string(arg2 & 3u); + } else { + guts = "jmppin"; } break; } @@ -131,7 +133,7 @@ std::string disassemble(uint inst, uint sideset_bits_including_opt, bool sideset op("mov"); std::string guts = dest + ", "; if (operation == 1) { - guts += "!"; + guts += "~"; } else if (operation == 2) { guts += "::"; } @@ -193,6 +195,9 @@ std::string disassemble(uint inst, uint sideset_bits_including_opt, bool sideset } delay &= ((1u << (5 - sideset_bits_including_opt)) - 1u); ss << std::left << std::setw(4) << (delay ? ("[" + std::to_string(delay) + "]") : ""); - return ss.str(); + // remove trailing spaces + auto str = ss.str(); + str.erase(str.find_last_not_of(' ')+1); + return str; } diff --git a/tools/pioasm/python_output.cpp b/tools/pioasm/python_output.cpp index bcaa8d610..f4cf326bd 100644 --- a/tools/pioasm/python_output.cpp +++ b/tools/pioasm/python_output.cpp @@ -204,6 +204,9 @@ struct python_output : public output_format { } } break; + default: + invalid = true; + break; } if (!invalid) { guts = ((arg1 & 4u) ? "1, " : "0, ") + guts; @@ -254,23 +257,24 @@ struct python_output : public output_format { uint operation = arg2 >> 3u; if (source.empty() || dest.empty() || operation == 3) { invalid = true; - } - if (dest == source && (arg1 == 1 || arg2 == 2) && operation == 0) { - op("nop"); - op_guts(""); } else { - op("mov"); - std::string guts = dest + ", "; - if (operation == 1) { - guts += "invert("; - } else if (operation == 2) { - guts += "reverse("; - } - guts += source; - if (operation == 1 || operation == 2) { - guts += ")"; + if (dest == source && (arg1 == 1 || arg2 == 2) && operation == 0) { + op("nop"); + op_guts(""); + } else { + op("mov"); + std::string guts = dest + ", "; + if (operation == 1) { + guts += "invert("; + } else if (operation == 2) { + guts += "reverse("; + } + guts += source; + if (operation == 1 || operation == 2) { + guts += ")"; + } + op_guts(guts); } - op_guts(guts); } break; } @@ -310,7 +314,9 @@ struct python_output : public output_format { if (invalid) { op("word"); ss << std::hex; - op_guts(std::to_string(inst)); + std::stringstream guts; + guts << std::hex << std::showbase << std::setfill('0') << std::setw(4) << inst; + op_guts(guts.str()); } uint delay = ((uint) inst >> 8u) & 0x1f; ss << std::left << std::setw(9); diff --git a/tools/pioasm/test/amethyst.pio b/tools/pioasm/test/amethyst.pio index 97422a22b..6b8160460 100644 --- a/tools/pioasm/test/amethyst.pio +++ b/tools/pioasm/test/amethyst.pio @@ -44,3 +44,10 @@ wait gpio 40 .pio_version 1 .mov_status txfifo < 12 .mov_status irq next set 3 + +.program python +.pio_version 1 +wait 0 jmppin +wait 0 jmppin + 3 +mov x, !x +.word 0x1234 \ No newline at end of file From 7dfbb3c95846db0ed7be876e17924383a415ce4a Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:24:30 +0000 Subject: [PATCH 041/224] Add a delay after rtc_set_datetime (#2156) If you call rtc_get_datetime immediately after rtc_set_datetime you get junk back. According to the datasheet "Writing to the RTC will take 2 clk_rtc clock periods to arrive". So add a delay after calling rtc_set_datetime in aon_timer_set_time_calendar. Fixes #2148 --- src/rp2_common/pico_aon_timer/BUILD.bazel | 4 ++ src/rp2_common/pico_aon_timer/CMakeLists.txt | 1 + src/rp2_common/pico_aon_timer/aon_timer.c | 6 ++ test/pico_time_test/BUILD.bazel | 1 + test/pico_time_test/CMakeLists.txt | 3 + test/pico_time_test/pico_time_test.c | 59 ++++++++++++++++---- 6 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/rp2_common/pico_aon_timer/BUILD.bazel b/src/rp2_common/pico_aon_timer/BUILD.bazel index 6ceaf2e52..45ef4f3cc 100644 --- a/src/rp2_common/pico_aon_timer/BUILD.bazel +++ b/src/rp2_common/pico_aon_timer/BUILD.bazel @@ -6,10 +6,14 @@ cc_library( name = "pico_aon_timer", srcs = ["aon_timer.c"], hdrs = ["include/pico/aon_timer.h"], + defines = [ + "LIB_PICO_AON_TIMER=1", + ], includes = ["include"], target_compatible_with = compatible_with_rp2(), deps = [ "//src/common/pico_util", + "//src/common/pico_time", "//src/rp2_common:hardware_regs", "//src/rp2_common:pico_platform", "//src/rp2_common/hardware_irq", diff --git a/src/rp2_common/pico_aon_timer/CMakeLists.txt b/src/rp2_common/pico_aon_timer/CMakeLists.txt index 0d2a2d657..c1abe98f3 100644 --- a/src/rp2_common/pico_aon_timer/CMakeLists.txt +++ b/src/rp2_common/pico_aon_timer/CMakeLists.txt @@ -12,6 +12,7 @@ pico_mirrored_target_link_libraries(pico_aon_timer INTERFACE pico_util) if (TARGET hardware_rtc) pico_mirrored_target_link_libraries(pico_aon_timer INTERFACE hardware_rtc) + target_link_libraries(pico_aon_timer_headers INTERFACE pico_time_headers) endif() if (TARGET hardware_powman) diff --git a/src/rp2_common/pico_aon_timer/aon_timer.c b/src/rp2_common/pico_aon_timer/aon_timer.c index a4d594f63..62ef6c27a 100644 --- a/src/rp2_common/pico_aon_timer/aon_timer.c +++ b/src/rp2_common/pico_aon_timer/aon_timer.c @@ -13,6 +13,8 @@ static aon_timer_alarm_handler_t aon_timer_alarm_handler; #if HAS_RP2040_RTC #include "hardware/rtc.h" #include "pico/util/datetime.h" +#include "pico/time.h" +#include "hardware/clocks.h" #elif HAS_POWMAN_TIMER #include "hardware/powman.h" @@ -56,6 +58,10 @@ bool aon_timer_set_time_calendar(const struct tm *tm) { datetime_t dt; tm_to_datetime(tm, &dt); rtc_set_datetime(&dt); + + // Writing to the RTC will take 2 clk_rtc clock periods to arrive + uint rtc_freq = clock_get_hz(clk_rtc); + busy_wait_us(((1000000 + rtc_freq - 1) / rtc_freq) * 2); return true; #elif HAS_POWMAN_TIMER struct timespec ts; diff --git a/test/pico_time_test/BUILD.bazel b/test/pico_time_test/BUILD.bazel index b7a437629..038738601 100644 --- a/test/pico_time_test/BUILD.bazel +++ b/test/pico_time_test/BUILD.bazel @@ -12,6 +12,7 @@ cc_binary( target_compatible_with = compatible_with_rp2(), deps = [ "//src/rp2_common/pico_stdlib", + "//src/rp2_common/pico_aon_timer", "//test/pico_test", ], ) diff --git a/test/pico_time_test/CMakeLists.txt b/test/pico_time_test/CMakeLists.txt index d36a3da07..20a5608bd 100644 --- a/test/pico_time_test/CMakeLists.txt +++ b/test/pico_time_test/CMakeLists.txt @@ -4,5 +4,8 @@ if (NOT PICO_TIME_NO_ALARM_SUPPORT) PICO_TIME_DEFAULT_ALARM_POOL_MAX_TIMERS=250 ) target_link_libraries(pico_time_test PRIVATE pico_test) + if (PICO_RP2040) + target_link_libraries(pico_time_test PRIVATE pico_aon_timer) + endif() pico_add_extra_outputs(pico_time_test) endif() \ No newline at end of file diff --git a/test/pico_time_test/pico_time_test.c b/test/pico_time_test/pico_time_test.c index 82c3d825f..b8f4cba3c 100644 --- a/test/pico_time_test/pico_time_test.c +++ b/test/pico_time_test/pico_time_test.c @@ -13,6 +13,11 @@ #endif #include "pico/stdlib.h" #include "pico/test.h" + +#if LIB_PICO_AON_TIMER +#include "pico/aon_timer.h" +#endif + // Include sys/types.h before inttypes.h to work around issue with // certain versions of GCC and newlib which causes omission of PRIi64 #include @@ -74,11 +79,12 @@ static bool repeating_timer_callback(struct repeating_timer *t) { #define RESOLUTION_ALLOWANCE PICO_HARDWARE_TIMER_RESOLUTION_US #endif -int issue_195_test(void); -int issue_1812_test(void); -int issue_1953_test(void); -int issue_2118_test(void); -int issue_2186_test(void); +static int issue_195_test(void); +static int issue_1812_test(void); +static int issue_1953_test(void); +static int issue_2118_test(void); +static int issue_2148_test(void); +static int issue_2186_test(void); int main() { setup_default_uart(); @@ -253,6 +259,8 @@ int main() { issue_2118_test(); + issue_2148_test(); + issue_2186_test(); PICOTEST_END_TEST(); @@ -265,7 +273,7 @@ int64_t issue_195_callback(alarm_id_t id, void *user_data) { return -ISSUE_195_TIMER_DELAY; } -int issue_195_test(void) { +static int issue_195_test(void) { PICOTEST_START_SECTION("Issue #195 race condition - without fix may hang on gcc 10.2.1 release builds"); absolute_time_t t1 = get_absolute_time(); int id = add_alarm_in_us(ISSUE_195_TIMER_DELAY, issue_195_callback, NULL, true); @@ -284,7 +292,7 @@ int issue_195_test(void) { } // Setting an alarm should not swallow a sev -int issue_1812_test(void) { +static int issue_1812_test(void) { PICOTEST_START_SECTION("Issue #1812 defect - Setting an alarm should not ignore a sev"); __sev(); // Make sure the call below does not ignore this @@ -308,7 +316,7 @@ static void alarm_pool_stuck_issue_1953(uint alarm) { hard_assert(false); } -int issue_1953_test(void) { +static int issue_1953_test(void) { PICOTEST_START_SECTION("Issue #1953 defect - Alarm can be set in the past"); int alarm = hardware_alarm_claim_unused(true); hardware_alarm_set_callback(alarm, alarm_pool_stuck_issue_1953); @@ -341,7 +349,7 @@ static bool timer_callback_issue_2118(repeating_timer_t *rt) { return true; } -int issue_2118_test(void) { +static int issue_2118_test(void) { PICOTEST_START_SECTION("Issue #2118 defect - failure to set an alarm"); #if PICO_ON_DEVICE @@ -373,7 +381,7 @@ int issue_2118_test(void) { return 0; } -int issue_2186_test(void) { +static int issue_2186_test(void) { PICOTEST_START_SECTION("Issue #2186 defect - ta_wakes_up_on_or_before"); hard_assert(best_effort_wfe_or_timeout(get_absolute_time() - 1)); @@ -382,3 +390,34 @@ int issue_2186_test(void) { PICOTEST_END_SECTION(); return 0; } + +static int issue_2148_test(void) { +#if HAS_RP2040_RTC + PICOTEST_START_SECTION("Issue #2148 defect - get time after rtc start"); + struct tm tm = { 0 }; + struct tm tm_check = { 0 }; + + tm.tm_sec = 55; + tm.tm_min = 36; + tm.tm_hour = 20; + tm.tm_mday = 21; + tm.tm_mon = 10; + tm.tm_year = 124; + tm.tm_wday = 4; + tm.tm_yday = 325; + tm.tm_isdst = 0; + hard_assert(aon_timer_start_calendar(&tm)); + hard_assert(aon_timer_get_time_calendar(&tm_check)); + + PICOTEST_CHECK(tm.tm_sec == tm_check.tm_sec || tm.tm_sec == tm_check.tm_sec - 1, "failed to get seconds"); + PICOTEST_CHECK(tm.tm_min == tm_check.tm_min, "failed to get minutes"); + PICOTEST_CHECK(tm.tm_hour == tm_check.tm_hour, "failed to get hour"); + PICOTEST_CHECK(tm.tm_mday == tm_check.tm_mday, "failed to get day"); + PICOTEST_CHECK(tm.tm_mon == tm_check.tm_mon, "failed to get month"); + PICOTEST_CHECK(tm.tm_year == tm_check.tm_year, "failed to get year"); + + aon_timer_stop(); + PICOTEST_END_SECTION(); +#endif + return 0; +} From 1ee91e103997a0c3b1e6d0a253816036c99f9d79 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 7 Feb 2025 12:07:46 -0600 Subject: [PATCH 042/224] Add license to pico_sdk_import.cmake (#2239) --- external/pico_sdk_import.cmake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/external/pico_sdk_import.cmake b/external/pico_sdk_import.cmake index d625cdff3..d493cc23a 100644 --- a/external/pico_sdk_import.cmake +++ b/external/pico_sdk_import.cmake @@ -3,6 +3,28 @@ # This can be dropped into an external project to help locate this SDK # It should be include()ed prior to project() +# Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +# following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") From 876c09cbfac68cf10b551a81dc3a0f132d46590b Mon Sep 17 00:00:00 2001 From: Steven Conaway Date: Fri, 7 Feb 2025 11:08:12 -0700 Subject: [PATCH 043/224] pico_flash: Support FreeRTOS Static Allocation (#2229) --- src/rp2_common/pico_flash/flash.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_flash/flash.c b/src/rp2_common/pico_flash/flash.c index 6a6294a78..1dc68c7b7 100644 --- a/src/rp2_common/pico_flash/flash.c +++ b/src/rp2_common/pico_flash/flash.c @@ -145,7 +145,16 @@ static int default_enter_safe_zone_timeout_ms(__unused uint32_t timeout_ms) { uint core_num = get_core_num(); // create at low priority on other core TaskHandle_t task_handle; + + // when FreeRTOS dynamic allocation is disabled (configSUPPORT_DYNAMIC_ALLOCATION == 0), the following fails +#if configSUPPORT_DYNAMIC_ALLOCATION if (pdPASS != xTaskCreateAffinitySet(flash_lockout_task, "flash lockout", configMINIMAL_STACK_SIZE, (void *)core_num, 0, 1u << (core_num ^ 1), &task_handle)) { +#else + static StackType_t flash_lockout_stack[configMINIMAL_STACK_SIZE]; + static StaticTask_t flash_lockout_task_tcb; + task_handle = xTaskCreateStaticAffinitySet(flash_lockout_task, "flash lockout", configMINIMAL_STACK_SIZE, (void *)core_num, 0, flash_lockout_stack, &flash_lockout_task_tcb, 1u << (core_num ^ 1)); + if (task_handle == NULL) { +#endif return PICO_ERROR_INSUFFICIENT_RESOURCES; } lockout_state[core_num] = FREERTOS_LOCKOUT_LOCKER_WAITING; @@ -216,4 +225,4 @@ static int default_exit_safe_zone_timeout_ms(__unused uint32_t timeout_ms) { #endif } return PICO_OK; -} \ No newline at end of file +} From 396aa06736d3fad5d31db2ae8761e28999761dab Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Fri, 7 Feb 2025 18:08:56 +0000 Subject: [PATCH 044/224] Fix Windows CI (#2241) Don't install CMake, as it comes pre-installed on GitHub runners This fixes the version incompatibilities that keep appearing with the Windows CI build --- .github/workflows/choco_packages.config | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/choco_packages.config b/.github/workflows/choco_packages.config index f7885c9fc..d443f751c 100644 --- a/.github/workflows/choco_packages.config +++ b/.github/workflows/choco_packages.config @@ -1,7 +1,6 @@ - From 05dbc11b4a68e4352c5972b48e91ff4ccc3e5087 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 7 Feb 2025 16:52:18 -0600 Subject: [PATCH 045/224] update stdio_usb CDC constants to the defaults used by TinyUSB, and allow the user to override them (#2246) --- .../pico_stdio_usb/include/tusb_config.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_stdio_usb/include/tusb_config.h b/src/rp2_common/pico_stdio_usb/include/tusb_config.h index 13e0c5eb5..0b9e4306b 100644 --- a/src/rp2_common/pico_stdio_usb/include/tusb_config.h +++ b/src/rp2_common/pico_stdio_usb/include/tusb_config.h @@ -33,8 +33,19 @@ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE) #define CFG_TUD_CDC (1) -#define CFG_TUD_CDC_RX_BUFSIZE (256) -#define CFG_TUD_CDC_TX_BUFSIZE (256) + +// CDC FIFO size of TX and RX +#ifndef CFG_TUD_CDC_RX_BUFSIZE +#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +#endif +#ifndef CFG_TUD_CDC_TX_BUFSIZE +#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +#endif + +// CDC Endpoint transfer buffer size, more is faster +#ifndef CFG_TUD_CDC_EP_BUFSIZE +#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +#endif // We use a vendor specific interface but with our own driver // Vendor driver only used for Microsoft OS 2.0 descriptor From f407f5b8e863e5a8e84269bad7bda7dce358d1ef Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 10 Feb 2025 11:18:33 -0500 Subject: [PATCH 046/224] boards/adafruit_feather_rp2350.h: add PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 (#2248) --- src/boards/include/boards/adafruit_feather_rp2350.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/boards/include/boards/adafruit_feather_rp2350.h b/src/boards/include/boards/adafruit_feather_rp2350.h index 20d77478d..75aaaf902 100644 --- a/src/boards/include/boards/adafruit_feather_rp2350.h +++ b/src/boards/include/boards/adafruit_feather_rp2350.h @@ -16,6 +16,11 @@ #ifndef _BOARDS_ADAFRUIT_FEATHER_RP2350_H #define _BOARDS_ADAFRUIT_FEATHER_RP2350_H +// On some samples, the xosc can take longer to stabilize than is usual +#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 +#endif + // For board detection #define ADAFRUIT_FEATHER_RP2350 From 24c4480b82c87ebc58536068dbe70ba0b8a1efd8 Mon Sep 17 00:00:00 2001 From: HugoTro <64845965+HugoTro@users.noreply.github.com> Date: Tue, 11 Feb 2025 23:39:14 +0100 Subject: [PATCH 047/224] Fix semicolon in makefsdata.py (#2238) Simple semicolon that breaks the file otherwise --- src/rp2_common/pico_lwip/tools/makefsdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_lwip/tools/makefsdata.py b/src/rp2_common/pico_lwip/tools/makefsdata.py index 61312b5b8..9ee0d88c1 100755 --- a/src/rp2_common/pico_lwip/tools/makefsdata.py +++ b/src/rp2_common/pico_lwip/tools/makefsdata.py @@ -95,7 +95,7 @@ def process_file_list(fd, input): fd.write(f"static const unsigned char {data_var}[] = {{\n") for entry in results: fd.write(f"\n /* {entry['comment']} */\n") - byte_count = 0; + byte_count = 0 for b in entry['data']: if byte_count % 16 == 0: fd.write(" ") From 564aa6490437d3dcc35237b0d842c5a330a8e8c5 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Wed, 12 Feb 2025 09:34:48 -0600 Subject: [PATCH 048/224] minor irq.h comment tweaks --- src/rp2_common/hardware_irq/include/hardware/irq.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/hardware_irq/include/hardware/irq.h b/src/rp2_common/hardware_irq/include/hardware/irq.h index 1ef382d5b..ae9ff954b 100644 --- a/src/rp2_common/hardware_irq/include/hardware/irq.h +++ b/src/rp2_common/hardware_irq/include/hardware/irq.h @@ -286,7 +286,7 @@ void irq_set_mask_n_enabled(uint n, uint32_t mask, bool enabled); * This method will assert if there is already any sort of interrupt handler installed * for the specified irq number. * - * NOTE: By default, the SDK uses a single shared vector table per core, and the current installed + * NOTE: By default, the SDK uses a single shared vector table for both cores, and the currently installed * IRQ handlers are effectively a linked list starting a vector table entry for a particular IRQ number. * Therefore, this method (when using the same vector table for both cores) sets the same interrupt handler * for both cores. @@ -309,7 +309,7 @@ void irq_set_mask_n_enabled(uint n, uint32_t mask, bool enabled); * NOTE: It is not thread safe to add/remove/handle IRQs for the same irq number in the same vector table * from both cores concurrently. * - * NOTE: The SDK defines a PICO_VTABLE_PER_CORE variable indicating whether the two vector tables are separate, + * NOTE: The SDK has a PICO_VTABLE_PER_CORE define indicating whether the two vector tables are separate, * however as of version 2.1.1 the user cannot set this value, and expect the vector table duplication to be handled * for them. This functionality will be added in a future SDK version * @@ -343,7 +343,7 @@ irq_handler_t irq_get_exclusive_handler(uint num); * the (total across all IRQs on both cores) maximum (configurable via PICO_MAX_SHARED_IRQ_HANDLERS) number of shared handlers * would be exceeded. * - * NOTE: By default, the SDK uses a single shared vector table per core, and the current installed + * NOTE: By default, the SDK uses a single shared vector table for both core, and the currently installed * IRQ handlers are effectively a linked list starting a vector table entry for a particular IRQ number. * Therefore, this method (when using the same vector table for both cores) add the same interrupt handler * for both cores. From de0416a0790e3f36c098daa70b35a3cc7b1060ef Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 12 Feb 2025 16:56:57 +0000 Subject: [PATCH 049/224] Minor irq.h comment typos (#2257) --- src/rp2_common/hardware_irq/include/hardware/irq.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/hardware_irq/include/hardware/irq.h b/src/rp2_common/hardware_irq/include/hardware/irq.h index ae9ff954b..065670b0c 100644 --- a/src/rp2_common/hardware_irq/include/hardware/irq.h +++ b/src/rp2_common/hardware_irq/include/hardware/irq.h @@ -46,7 +46,7 @@ * where there is one IO interrupt per bank, per core. These are completely independent, so, for example, processor 0 can be * interrupted by GPIO 0 in bank 0, and processor 1 by GPIO 1 in the same bank. * - * \note That all IRQ APIs affect the executing core only (i.e. the core calling the function). + * \note All IRQ APIs affect the executing core only (i.e. the core calling the function). * * \note You should not enable the same (shared) IRQ number on both cores, as this will lead to race conditions * or starvation of one of the cores. Additionally, don't forget that disabling interrupts on one core does not disable interrupts @@ -280,7 +280,7 @@ void irq_set_mask_n_enabled(uint n, uint32_t mask, bool enabled); * \ingroup hardware_irq * * Use this method to set a handler for single IRQ source interrupts, or when - * your code, use case or performance requirements dictate that there should + * your code, use case or performance requirements dictate that there should be * no other handlers for the interrupt. * * This method will assert if there is already any sort of interrupt handler installed @@ -343,7 +343,7 @@ irq_handler_t irq_get_exclusive_handler(uint num); * the (total across all IRQs on both cores) maximum (configurable via PICO_MAX_SHARED_IRQ_HANDLERS) number of shared handlers * would be exceeded. * - * NOTE: By default, the SDK uses a single shared vector table for both core, and the currently installed + * NOTE: By default, the SDK uses a single shared vector table for both cores, and the currently installed * IRQ handlers are effectively a linked list starting a vector table entry for a particular IRQ number. * Therefore, this method (when using the same vector table for both cores) add the same interrupt handler * for both cores. @@ -366,7 +366,7 @@ irq_handler_t irq_get_exclusive_handler(uint num); * NOTE: It is not thread safe to add/remove/handle IRQs for the same irq number in the same vector table * from both cores concurrently. * - * NOTE: The SDK defines a PICO_VTABLE_PER_CORE variable indicating whether the two vector tables are separate, + * NOTE: The SDK has a PICO_VTABLE_PER_CORE define indicating whether the two vector tables are separate, * however as of version 2.1.1 the user cannot set this value, and expect the vector table duplication to be handled * for them. This functionality will be added in a future SDK version * From 7c023fa320550ae3b3edf3b0bd0092f91aff2f8d Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 12 Feb 2025 11:40:56 -0600 Subject: [PATCH 050/224] Increase default PICO_XOSC_STARTUP_DELAY_MULTIPLIER to 6 (ms) (#2245) --- src/rp2_common/hardware_xosc/include/hardware/xosc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/hardware_xosc/include/hardware/xosc.h b/src/rp2_common/hardware_xosc/include/hardware/xosc.h index 1153b9362..fe4922785 100644 --- a/src/rp2_common/hardware_xosc/include/hardware/xosc.h +++ b/src/rp2_common/hardware_xosc/include/hardware/xosc.h @@ -13,9 +13,9 @@ // Allow lengthening startup delay to accommodate slow-starting oscillators -// PICO_CONFIG: PICO_XOSC_STARTUP_DELAY_MULTIPLIER, Multiplier to lengthen xosc startup delay to accommodate slow-starting oscillators, type=int, min=1, default=1, group=hardware_xosc +// PICO_CONFIG: PICO_XOSC_STARTUP_DELAY_MULTIPLIER, Multiplier (from 1ms) for xosc startup delay to accommodate slow-starting oscillators, type=int, min=1, default=6, group=hardware_xosc #ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER -#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 1 +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 6 #endif From 0ca463a29fdc94e3beafc3e70b030165bb682b9b Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 12 Feb 2025 12:46:32 -0600 Subject: [PATCH 051/224] Fix compilation of pico_double_test on llvm 15 - workaround compiler bug (#2258) --- test/pico_float_test/pico_double_test.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/pico_float_test/pico_double_test.c b/test/pico_float_test/pico_double_test.c index 3b7a8ec29..b844e15d4 100644 --- a/test/pico_float_test/pico_double_test.c +++ b/test/pico_float_test/pico_double_test.c @@ -365,7 +365,13 @@ int main() { printf("EXP %10.18g\n", check_close1(exp, x)); printf("LN %10.18g\n", check_close1(log, x)); printf("POW %10.18f\n", check_close2(pow, x, x)); +#if LIB_PICO_DOUBLE_PICO && __clang_major__ == 15 + // seem to be a compiler/linker bug here with calls to __real_trunc, so just call trunc rather than doing + // a closeness check - at least we will know that the call works + printf("TRUNC %10.18f\n", trunc(x)); +#else printf("TRUNC %10.18f\n", check_close1(trunc, x)); +#endif printf("LDEXP %10.18f\n", check_close2(ldexp, x, x)); // todo come pack // printf("FMOD %10.18f\n", check_close2(fmod, x, 3.0f)); From e7f8e48b98e56e3366c6f8b3de4c9bbab7df099b Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 13 Feb 2025 11:13:03 -0600 Subject: [PATCH 052/224] Add clang and host CI builds (#2259) * ci: remove cmake from Windows choco_packages.config as there is already a version in the windows image * multi-gcc: add GCC 14.2. On RP2040 build for Pico W * multi_gcc: add host * support cancellation --------- Co-authored-by: Liam Fraser --- .github/workflows/multi-gcc.yml | 422 ++++++++++++++---- .../scripts/generate_multi_gcc_workflow.py | 115 ++++- 2 files changed, 440 insertions(+), 97 deletions(-) diff --git a/.github/workflows/multi-gcc.yml b/.github/workflows/multi-gcc.yml index 886109d2e..f20062458 100644 --- a/.github/workflows/multi-gcc.yml +++ b/.github/workflows/multi-gcc.yml @@ -25,133 +25,399 @@ jobs: - name: Checkout submodules run: git submodule update --init - - name: GCC 6.2.1 Debug - if: always() + - name: Host Release + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: Host Debug + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 6.2.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-6_2-2016q4; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 6.2.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-6_2-2016q4; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 6.3.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-6-2017-q2-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 6.3.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-6-2017-q2-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 7.2.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-7-2017-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 7.2.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-7-2017-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 7.3.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-7-2018-q2-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 7.3.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-7-2018-q2-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 8.2.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-8-2018-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 8.2.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-8-2018-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 8.3.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-8-2019-q3-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 8.3.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-8-2019-q3-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 9.2.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2019-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 9.2.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2019-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 9.2.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2019-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 9.2.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2019-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 9.3.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2020-q2-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 9.3.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2020-q2-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 9.3.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2020-q2-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 9.3.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2020-q2-update; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 10.2.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10-2020-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 10.2.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10-2020-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 10.2.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10-2020-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 10.2.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10-2020-q4-major; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 10.3.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10.3-2021.10; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 10.3.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10.3-2021.10; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 10.3.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10.3-2021.10; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 10.3.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10.3-2021.10; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 11.2.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 11.2.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 11.2.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 11.2.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 11.3.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 11.3.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 11.3.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 11.3.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 12.2.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 12.2.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 12.2.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 12.2.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 12.3.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 12.3.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 12.3.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 12.3.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 13.2.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 13.2.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 13.2.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 13.2.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 13.3.1 Debug Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 13.3.1 Debug RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 13.3.1 Release Pico W + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: GCC 13.3.1 Release RP2350 + if: ${{ !cancelled() }} + shell: bash + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: LLVM 14.0.0 Debug Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-6_2-2016q4 -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-14.0.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 6.2.1 Release - if: always() + - name: LLVM 14.0.0 Debug RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-6_2-2016q4 -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-14.0.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 6.3.1 Debug - if: always() + - name: LLVM 14.0.0 Release Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-6-2017-q2-update -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-14.0.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 6.3.1 Release - if: always() + - name: LLVM 14.0.0 Release RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-6-2017-q2-update -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-14.0.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 7.2.1 Debug - if: always() + - name: RISCV GCC 14.1.0 Debug RP2350 RISCV + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-7-2017-q4-major -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350-riscv -DPICO_TOOLCHAIN_PATH=/opt/riscv/riscv32-unknown-elf-gcc-14.1.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 7.2.1 Release - if: always() + - name: RISCV GCC 14.1.0 Release RP2350 RISCV + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-7-2017-q4-major -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350-riscv -DPICO_TOOLCHAIN_PATH=/opt/riscv/riscv32-unknown-elf-gcc-14.1.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 7.3.1 Debug - if: always() + - name: GCC 14.2.1 Debug Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-7-2018-q2-update -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 7.3.1 Release - if: always() + - name: GCC 14.2.1 Debug RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-7-2018-q2-update -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 8.2.1 Debug - if: always() + - name: GCC 14.2.1 Release Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-8-2018-q4-major -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 8.2.1 Release - if: always() + - name: GCC 14.2.1 Release RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-8-2018-q4-major -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-eabi; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 8.3.1 Debug - if: always() + - name: LLVM 15.0.2 Debug Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-8-2019-q3-update -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-15.0.2; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 8.3.1 Release - if: always() + - name: LLVM 15.0.2 Debug RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-8-2019-q3-update -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-15.0.2; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 9.2.1 Debug - if: always() + - name: LLVM 15.0.2 Release Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2019-q4-major -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-15.0.2; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 9.2.1 Release - if: always() + - name: LLVM 15.0.2 Release RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2019-q4-major -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-15.0.2; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 9.3.1 Debug - if: always() + - name: LLVM 16.0.0 Debug Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2020-q2-update -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-16.0.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 9.3.1 Release - if: always() + - name: LLVM 16.0.0 Debug RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-9-2020-q2-update -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-16.0.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 10.2.1 Debug - if: always() + - name: LLVM 16.0.0 Release Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10-2020-q4-major -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-16.0.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 10.2.1 Release - if: always() + - name: LLVM 16.0.0 Release RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10-2020-q4-major -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-16.0.0; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 10.3.1 Debug - if: always() + - name: LLVM 17.0.1 Debug Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10.3-2021.10 -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-17.0.1; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 10.3.1 Release - if: always() + - name: LLVM 17.0.1 Debug RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-none-eabi-10.3-2021.10 -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-17.0.1; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 11.2.1 Debug - if: always() + - name: LLVM 17.0.1 Release Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-17.0.1; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 11.2.1 Release - if: always() + - name: LLVM 17.0.1 Release RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVMEmbeddedToolchainForArm-17.0.1; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 11.3.1 Debug - if: always() + - name: LLVM 18.1.3 Debug Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVM-ET-Arm-18.1.3-Linux-x86_64; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 11.3.1 Release - if: always() + - name: LLVM 18.1.3 Debug RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVM-ET-Arm-18.1.3-Linux-x86_64; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 12.2.1 Debug - if: always() + - name: LLVM 18.1.3 Release Pico W + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_BOARD=pico_w -DPICO_PLATFORM=rp2040 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVM-ET-Arm-18.1.3-Linux-x86_64; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) - - name: GCC 12.2.1 Release - if: always() + - name: LLVM 18.1.3 Release RP2350 + if: ${{ !cancelled() }} shell: bash - run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_TOOLCHAIN_PATH=/opt/arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=rp2350 -DPICO_COMPILER=pico_arm_clang -DPICO_TOOLCHAIN_PATH=/opt/arm/LLVM-ET-Arm-18.1.3-Linux-x86_64; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) diff --git a/.github/workflows/scripts/generate_multi_gcc_workflow.py b/.github/workflows/scripts/generate_multi_gcc_workflow.py index ac10b8b2c..7e36f63af 100755 --- a/.github/workflows/scripts/generate_multi_gcc_workflow.py +++ b/.github/workflows/scripts/generate_multi_gcc_workflow.py @@ -5,15 +5,52 @@ import subprocess import re -toolchain_dir = "/opt/arm" -toolchains = os.listdir(toolchain_dir) +toolchains = [os.path.join("/opt/arm", x) for x in os.listdir("/opt/arm")] +toolchains += [os.path.join("/opt/riscv", x) for x in os.listdir("/opt/riscv")] -gcc_versions = OrderedDict() +compilers = [] +class Compiler: + def __init__(self, version, path, type): + self.version = version + self.path = path + self.type = type + @property + def gcc(self): + return self.type == "GCC" + + @property + def llvm(self): + return self.type == "LLVM" + + @property + def riscv(self): + return "RISCV" in self.type + + def __repr__(self): + return self.version + +seen_versions = [] for toolchain in toolchains: - fullpath = os.path.join(toolchain_dir, toolchain) - gcc_path = os.path.join(fullpath, "bin/arm-none-eabi-gcc") - version = subprocess.run([gcc_path, "--version"], capture_output=True) + gcc_path = os.path.join(toolchain, "bin/arm-none-eabi-gcc") + llvm_path = os.path.join(toolchain, "bin/clang") + riscv_gcc_path = os.path.join(toolchain, "bin/riscv32-unknown-elf-gcc") + + type = None + path = None + if os.path.exists(gcc_path): + path = gcc_path + type = "GCC" + elif os.path.exists(llvm_path): + path = llvm_path + type = "LLVM" + elif os.path.exists(riscv_gcc_path): + path = riscv_gcc_path + type = "RISCV GCC" + else: + raise Exception("Unknown compiler type") + + version = subprocess.run([path, "--version"], capture_output=True) stdout = version.stdout.decode('utf-8') stderr = version.stderr.decode('utf-8') assert(len(stderr) == 0) @@ -23,14 +60,13 @@ assert(m is not None) version = m.group(1) - if version in gcc_versions: - raise Exception("Already have version {} in versions current path {}, this path {}".format(version, gcc_versions[version], fullpath)) - - gcc_versions[version] = fullpath + if version in seen_versions: + raise Exception("Already have version {} in versions current path {}, this path {}".format(version, gcc_versions[version], path)) -# Sort by major version -gcc_versions_sorted = OrderedDict(sorted(gcc_versions.items(), key=lambda item: int(item[0].replace(".", "")))) + compilers.append(Compiler(version, toolchain, type)) + seen_versions.append(version) +compilers_sorted = sorted(compilers, key=lambda x: int(x.version.replace(".", ""))) # Create output output = ''' @@ -59,14 +95,55 @@ - name: Checkout submodules run: git submodule update --init + + - name: Host Release + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) + + - name: Host Debug + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) ''' -for gcc_version, toolchain_path in gcc_versions_sorted.items(): - for build_type in ["Debug", "Release"]: - output += "\n" - output += " - name: GCC {} {}\n".format(gcc_version, build_type) - output += " if: always()\n" - output += " shell: bash\n" - output += " run: cd ${{{{github.workspace}}}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE={} -DPICO_TOOLCHAIN_PATH={} -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc)\n".format(build_type, toolchain_path) +platforms = [] +class Platform: + def __init__(self, name, platform, board, minimum_gcc_version=None): + self.name = name + self.board = board + self.platform = platform + self.riscv = "riscv" in platform + self.minimum_gcc_version = minimum_gcc_version + + def cmake_string(self, compiler): + opts = [] + # Temporary while private repo + opts.append("-DPICO_NO_PICOTOOL=1") + if self.board: opts.append(f"-DPICO_BOARD={self.board}") + opts.append(f"-DPICO_PLATFORM={self.platform}") + if compiler.llvm: opts.append("-DPICO_COMPILER=pico_arm_clang") + opts.append(f"-DPICO_TOOLCHAIN_PATH={compiler.path}") + return " ".join(opts) + + def compiler_valid(self, compiler): + if compiler.riscv != self.riscv: + return False + + if self.minimum_gcc_version and compiler.gcc: + if int(compiler.version.split(".")[0]) < self.minimum_gcc_version: + return False + return True + + +platforms.append(Platform("Pico W", "rp2040", "pico_w")) +platforms.append(Platform("RP2350", "rp2350", None, 9)) +platforms.append(Platform("RP2350 RISCV", "rp2350-riscv", None)) + +for compiler in compilers_sorted: + for build_type in ["Debug", "Release"]: + for p in platforms: + if not p.compiler_valid(compiler): continue + output += "\n" + output += " - name: {} {} {} {}\n".format(compiler.type, compiler.version, build_type, p.name) + output += " if: always()\n" + output += " shell: bash\n" + output += " run: cd ${{{{github.workspace}}}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE={} {}; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc)\n".format(build_type, p.cmake_string(compiler)) print(output) From 302fd9a811c289daf682edc03baa0cc31f1b0c82 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 14 Feb 2025 09:26:22 -0600 Subject: [PATCH 053/224] Fix `WAIT GPIO n` for n > 32 and when using gpio_base = 16 (#2265) - fix bug: pioasm was spilling bit 5 of arg2 into arg1 - make pio_add_program flip bit 5 of a WAIT GPIO instruction if gpio_base is 16 Note: pioasm will encode only the bits 4-0 of arg2 (the GPIO number), however it does indicate whether 0-15 means 0-15 or 32-47. This can only be fixed up when loading the program, and indeed once the GPIO base is known. pio_can_add_program and friends already detected the cases where this was impossible --- .../hardware_pio/include/hardware/pio_instructions.h | 4 ++++ src/rp2_common/hardware_pio/pio.c | 9 +++++++++ tools/pioasm/pio_assembler.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) 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 c27a4c178..671145606 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h @@ -79,6 +79,10 @@ static inline uint _pio_major_instr_bits(uint instr) { return instr & 0xe000u; } +static inline uint _pio_arg1(uint instr) { + return (instr >> 5) & 0x7u; +} + static inline uint _pio_encode_instr_and_args(enum pio_instr_bits instr_bits, uint arg1, uint arg2) { valid_params_if(PIO_INSTRUCTIONS, arg1 <= 0x7); #if PARAM_ASSERTIONS_ENABLED(PIO_INSTRUCTIONS) diff --git a/src/rp2_common/hardware_pio/pio.c b/src/rp2_common/hardware_pio/pio.c index ed34cd815..33b039457 100644 --- a/src/rp2_common/hardware_pio/pio.c +++ b/src/rp2_common/hardware_pio/pio.c @@ -162,6 +162,15 @@ static int add_program_at_offset(PIO pio, const pio_program_t *program, uint off if (rc != 0) return rc; for (uint i = 0; i < program->length; ++i) { uint16_t instr = program->instructions[i]; +#if PICO_PIO_USE_GPIO_BASE + if (pio_instr_bits_wait == _pio_major_instr_bits(instr) && !((_pio_arg1(instr) & 3u))) { + // wait GIO will include only the 5 lower bits of the GPIO number, so if the GPIO + // base is 16 we need to flip bit 4 (which is equivalent to subtracting 16 from + // the original number 16-47 stored as 16-31 and 0-15) + static_assert(PIO_GPIOBASE_BITS == 16, ""); // only works for gpio base being 0 or 16 + instr ^= pio_get_gpio_base(pio); + } +#endif pio->instr_mem[offset + i] = pio_instr_bits_jmp != _pio_major_instr_bits(instr) ? instr : instr + offset; } uint32_t program_mask = (1u << program->length) - 1; diff --git a/tools/pioasm/pio_assembler.cpp b/tools/pioasm/pio_assembler.cpp index 3a8a3009d..a36854b2c 100644 --- a/tools/pioasm/pio_assembler.cpp +++ b/tools/pioasm/pio_assembler.cpp @@ -292,7 +292,7 @@ uint instruction::encode(program &program) { } } // note we store the 6th bit of arg2 above the 16 bits of instruction - return (((uint) raw.type) << 13u) | (((uint) _delay | (uint) _sideset) << 8u) | (raw.arg1 << 5u) | raw.arg2 | ((raw.arg2 >> 5) << 16); + return (((uint) raw.type) << 13u) | (((uint) _delay | (uint) _sideset) << 8u) | (raw.arg1 << 5u) | (raw.arg2 & 0x1fu) | ((raw.arg2 >> 5) << 16); } raw_encoding instruction::raw_encode(program& program) { From 6989c893cc97db296dd06d0fb86eeefb2cc70bac Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Sat, 15 Feb 2025 10:59:16 -0800 Subject: [PATCH 054/224] Update Clang toolchain used by Bazel (#2269) * This includes an FMA issue fix that broke several math functions. --- MODULE.bazel | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 9e2bb30f7..99cd4c3d2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -54,34 +54,34 @@ http_archive( http_archive( name = "clang_linux-x86_64", build_file = "//bazel/toolchain:clang.BUILD", - sha256 = "dd4b3b0fc7186a4da2b52796b251e0757aefac4813f9f635982954fec3337d2e", + sha256 = "82302f8f0d9cb1062e60756147403c1525e965e1d7b777fab8076c74c7a5a19b", type = "zip", - url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/linux-amd64/+/git_revision:9d3f9f47e6e630b8308562297757e0911be03a18", + url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/linux-amd64/+/git_revision:910be4ff90d7d07bd4518ea03b85c0974672bf9c", ) http_archive( name = "clang_win-x86_64", build_file = "//bazel/toolchain:clang.BUILD", - sha256 = "21092395df915ee5a899a832a592b137c9ea07fbc91e49ac6069ea0083d31899", + sha256 = "2e9b8ac889838754e5305b6fd73c7bba7a6ec7364f1ce8ac60268b6d3bc61e6c", type = "zip", # Windows doesn't like `:` in the produced filename, so replace it with `%3A`. - url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/windows-amd64/+/git_revision:9d3f9f47e6e630b8308562297757e0911be03a18".replace("git_revision:", "git_revision%3A"), + url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/windows-amd64/+/git_revision:910be4ff90d7d07bd4518ea03b85c0974672bf9c".replace("git_revision:", "git_revision%3A"), ) http_archive( name = "clang_mac-x86_64", build_file = "//bazel/toolchain:clang.BUILD", - sha256 = "bb397fdce21d068ea40fefa9618993baa4907a248f996f18316c8fa6ca24dee2", + sha256 = "d3f2ef6f391ef66141092cfdf07facd18d2587a25616e1251e6e6b13b05ab3df", type = "zip", - url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/mac-amd64/+/git_revision:9d3f9f47e6e630b8308562297757e0911be03a18", + url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/mac-amd64/+/git_revision:910be4ff90d7d07bd4518ea03b85c0974672bf9c", ) http_archive( name = "clang_mac-aarch64", build_file = "//bazel/toolchain:clang.BUILD", - sha256 = "dad5583f96eabc913c1930d923c53a105d6ed73f56ca32451ea79ad70e495b0f", + sha256 = "61109b8464e9213ef8b9bfe55ce56298b94d4c66eaea308cf2b6556b0b85429e", type = "zip", - url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/mac-arm64/+/git_revision:9d3f9f47e6e630b8308562297757e0911be03a18", + url = "https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/clang/mac-arm64/+/git_revision:910be4ff90d7d07bd4518ea03b85c0974672bf9c", ) new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") From 1ca386847c8831902cc4dfb0f30d2b4e1460f2e2 Mon Sep 17 00:00:00 2001 From: David Dyck Date: Sun, 16 Feb 2025 08:13:30 -1000 Subject: [PATCH 055/224] Correct type in comment in CMakeLists.txt (#2274) correct outdated comment after 2 lines were deleted, but comment was not Fixes https://github.com/raspberrypi/pico-sdk/issues/2273 --- src/rp2_common/cmsis/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/cmsis/CMakeLists.txt b/src/rp2_common/cmsis/CMakeLists.txt index fb1fea229..d0582440e 100644 --- a/src/rp2_common/cmsis/CMakeLists.txt +++ b/src/rp2_common/cmsis/CMakeLists.txt @@ -44,7 +44,7 @@ # message(WARNING "Non-standard vendor ${PICO_CMSIS_VENDOR} amd device ${PICO_CMSIS_DEVICE} specified, but PICO_CMSIS_PATH was not set") #endif() -# ... using these 3 lines instead +# ... using this line instead set(PICO_CMSIS_CORE_PATH ${CMAKE_CURRENT_LIST_DIR}/stub) if (PICO_CMSIS_CORE_PATH AND PICO_CMSIS_DEVICE) From f9d65a06ca3ee101b651ba0593f5283dce79b987 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Sun, 16 Feb 2025 12:28:50 -0600 Subject: [PATCH 056/224] remove reference to hardware_busctrl doxygen group that doesn't exit (#2275) --- src/rp2040/hardware_structs/include/hardware/structs/busctrl.h | 1 - src/rp2350/hardware_structs/include/hardware/structs/busctrl.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/rp2040/hardware_structs/include/hardware/structs/busctrl.h b/src/rp2040/hardware_structs/include/hardware/structs/busctrl.h index 65893227d..2302025e7 100644 --- a/src/rp2040/hardware_structs/include/hardware/structs/busctrl.h +++ b/src/rp2040/hardware_structs/include/hardware/structs/busctrl.h @@ -24,7 +24,6 @@ // BITMASK [BITRANGE] FIELDNAME (RESETVALUE) DESCRIPTION /** \brief Bus fabric performance counters on RP2040 (used as typedef \ref bus_ctrl_perf_counter_t) - * \ingroup hardware_busctrl */ typedef enum bus_ctrl_perf_counter_rp2040 { arbiter_rom_perf_event_access = 19, diff --git a/src/rp2350/hardware_structs/include/hardware/structs/busctrl.h b/src/rp2350/hardware_structs/include/hardware/structs/busctrl.h index 2eb83a992..b38797b25 100644 --- a/src/rp2350/hardware_structs/include/hardware/structs/busctrl.h +++ b/src/rp2350/hardware_structs/include/hardware/structs/busctrl.h @@ -24,7 +24,6 @@ // BITMASK [BITRANGE] FIELDNAME (RESETVALUE) DESCRIPTION /** \brief Bus fabric performance counters on RP2350 (used as typedef \ref bus_ctrl_perf_counter_t) - * \ingroup hardware_busctrl */ typedef enum bus_ctrl_perf_counter_rp2350 { arbiter_rom_perf_event_access = 19, From 04525b802e45cd327bbfd9aad736cafba338d140 Mon Sep 17 00:00:00 2001 From: Enrico Zaghini Date: Sun, 16 Feb 2025 21:26:46 +0100 Subject: [PATCH 057/224] Fixed linker error for lwIP PPP support (#2272) (#2278) - Added `sys_jiffies` with weak linking for NO_SYS configuration --- src/rp2_common/pico_lwip/lwip_nosys.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rp2_common/pico_lwip/lwip_nosys.c b/src/rp2_common/pico_lwip/lwip_nosys.c index 856affa56..9a949f6ea 100644 --- a/src/rp2_common/pico_lwip/lwip_nosys.c +++ b/src/rp2_common/pico_lwip/lwip_nosys.c @@ -71,4 +71,8 @@ void sys_arch_unprotect(__unused sys_prot_t pval) { uint32_t sys_now(void) { return to_ms_since_boot(get_absolute_time()); } + +__weak uint32_t sys_jiffies(void) { + return time_us_32(); +} #endif \ No newline at end of file From c691da85e575843ce71abea103d825d4ae74a31e Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 17 Feb 2025 10:53:15 -0600 Subject: [PATCH 058/224] update previous fix as 1.0 < clkdiv < 2.0 IS supported on RP2350 (#2255) * update previous fix as 1.0 < clkdiv < 2.0 IS supported on RP2350 --- src/rp2_common/hardware_clocks/clocks.c | 20 ++++++++++++++----- .../hardware_clocks/include/hardware/clocks.h | 10 ++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/rp2_common/hardware_clocks/clocks.c b/src/rp2_common/hardware_clocks/clocks.c index 67db9b76b..c648a729f 100644 --- a/src/rp2_common/hardware_clocks/clocks.c +++ b/src/rp2_common/hardware_clocks/clocks.c @@ -101,12 +101,22 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32 if (freq > src_freq) return false; - uint32_t div = (uint32_t)((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / freq); - // only clock divider of 1, or >= 2 are supported - if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) { - div = (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB); + uint64_t div64 =((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / freq); + uint32_t div, actual_freq; + if (div64 >> 32) { + // set div to 0 for maximum clock divider + div = 0; + actual_freq = src_freq >> (32 - CLOCKS_CLK_GPOUT0_DIV_INT_LSB); + } else { + div = div64; +#if PICO_RP2040 + // on RP2040 only clock divider of 1, or >= 2 are supported + if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) { + div = (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB); + } +#endif + actual_freq = (uint32_t) ((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div); } - uint32_t actual_freq = (uint32_t) ((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div); clock_configure_internal(clock, src, auxsrc, actual_freq, div); // Store the configured frequency diff --git a/src/rp2_common/hardware_clocks/include/hardware/clocks.h b/src/rp2_common/hardware_clocks/include/hardware/clocks.h index 400b6e431..ec6eb0609 100644 --- a/src/rp2_common/hardware_clocks/include/hardware/clocks.h +++ b/src/rp2_common/hardware_clocks/include/hardware/clocks.h @@ -269,16 +269,22 @@ typedef clock_num_t clock_handle_t; * frequency to be specified, and will set the clock divider to achieve the exact or higher frequency * achievable, with the maximum being the src_freq. * - * Note: That the clock hardware only support divisors of exactly 1 or 2.0->65535.0 + * \if rp2350_specific + * Note: The RP2350 clock hardware supports divisors from 1.0->65536.0 in steps of 1/65536 * - * See the tables in the description for details on the possible values for clock sources. + * \endif + * \if rp2040_specific + * Note: The RP2040 clock hardware only supports divisors of exactly 1.0 or 2.0->16777216.0 in steps of 1/256 + * \endif * + * See the tables in the description for details on the possible values for clock sources. * * \param clock The clock to configure * \param src The main clock source, can be 0. * \param auxsrc The auxiliary clock source, which depends on which clock is being set. Can be 0 * \param src_freq Frequency of the input clock source * \param freq Requested frequency + * \return true if the clock is updated, false if freq > src_freq */ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32_t src_freq, uint32_t freq); From 7b96a34513617cf3a99cd77503557accba468b3a Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 17 Feb 2025 10:53:50 -0600 Subject: [PATCH 059/224] add missing extern C (#2284) --- .../hardware_boot_lock/include/hardware/boot_lock.h | 9 +++++++++ src/rp2_common/hardware_powman/include/hardware/powman.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/rp2_common/hardware_boot_lock/include/hardware/boot_lock.h b/src/rp2_common/hardware_boot_lock/include/hardware/boot_lock.h index dd63ef0e8..3244afb7a 100644 --- a/src/rp2_common/hardware_boot_lock/include/hardware/boot_lock.h +++ b/src/rp2_common/hardware_boot_lock/include/hardware/boot_lock.h @@ -9,6 +9,10 @@ #include "pico.h" +#ifdef __cplusplus +extern "C" { +#endif + // PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_BOOT_LOCK, Enable/disable assertions in the hardware_boot_lock module, type=bool, default=0, group=hardware_boot_lock #ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_BOOT_LOCK #define PARAM_ASSERTIONS_ENABLED_HARDWARE_BOOT_LOCK 0 @@ -141,4 +145,9 @@ boot_lock_t *boot_lock_init(uint lock_num); void boot_locks_reset(void); #endif + +#ifdef __cplusplus +} +#endif + #endif \ No newline at end of file diff --git a/src/rp2_common/hardware_powman/include/hardware/powman.h b/src/rp2_common/hardware_powman/include/hardware/powman.h index fce8c14cd..ea9e2758b 100644 --- a/src/rp2_common/hardware_powman/include/hardware/powman.h +++ b/src/rp2_common/hardware_powman/include/hardware/powman.h @@ -10,6 +10,10 @@ #include "pico.h" #include "hardware/structs/powman.h" +#ifdef __cplusplus +extern "C" { +#endif + /** \file hardware/powman.h * \defgroup hardware_powman hardware_powman * @@ -272,4 +276,8 @@ static inline void powman_set_debug_power_request_ignored(bool ignored) { powman_clear_bits(&powman_hw->dbg_pwrcfg, 0); } +#ifdef __cplusplus +} +#endif + #endif \ No newline at end of file From 59c92115897a4a20cdb482381777903e1c6dcc23 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 17 Feb 2025 11:23:29 -0600 Subject: [PATCH 060/224] Add enable_interrupts() and disable_interrupts() (#2276) --- .../hardware_sync/include/hardware/sync.h | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/rp2_common/hardware_sync/include/hardware/sync.h b/src/rp2_common/hardware_sync/include/hardware/sync.h index 474b27936..82b253786 100644 --- a/src/rp2_common/hardware_sync/include/hardware/sync.h +++ b/src/rp2_common/hardware_sync/include/hardware/sync.h @@ -198,10 +198,41 @@ __force_inline static void __mem_fence_release(void) { //#endif } -/*! \brief Save and disable interrupts +/*! \brief Explicitly disable interrupts on the calling core * \ingroup hardware_sync + */ +__force_inline static uint32_t disable_interrupts(void) { +#ifdef __riscv + __compiler_memory_barrier(); + riscv_clear_csr(mstatus, 8); + __compiler_memory_barrier(); +#else + pico_default_asm_volatile ( "cpsid i" : : : "memory"); +#endif +} + +/*! \brief Explicitly enable interrupts on the calling core + * \ingroup hardware_sync + */ +__force_inline static uint32_t enable_interrupts(void) { +#ifdef __riscv + __compiler_memory_barrier(); + riscv_set_csr(mstatus, 8); + __compiler_memory_barrier(); +#else + pico_default_asm_volatile ( "cpsie i" : : : "memory"); +#endif +} + +/*! \brief Disable interrupts on the calling core, returning the previous interrupt state + * \ingroup hardware_sync + * + * This method is commonly paired with \ref restore_interrupts_from_disabled() to temporarily + * disable interrupts around a piece of code, without needing to care whether interrupts + * were previously enabled * - * \return The prior interrupt enable status for restoration later via restore_interrupts() + * \return The prior interrupt enable status for restoration later via \ref restore_interrupts_from_disabled() + * or \ref restore_interrupts() */ __force_inline static uint32_t save_and_disable_interrupts(void) { uint32_t status; @@ -219,7 +250,7 @@ __force_inline static uint32_t save_and_disable_interrupts(void) { return status; } -/*! \brief Restore interrupts to a specified state +/*! \brief Restore interrupts to a specified state on the calling core * \ingroup hardware_sync * * \param status Previous interrupt status from save_and_disable_interrupts() @@ -238,10 +269,10 @@ __force_inline static void restore_interrupts(uint32_t status) { #endif } -/*! \brief Restore interrupts to a specified state with restricted transitions +/*! \brief Restore interrupts to a specified state on the calling core with restricted transitions * \ingroup hardware_sync * - * This method should only be used when the interrupt state is known to be disabled, + * This method should only be used when the current interrupt state is known to be disabled, * e.g. when paired with \ref save_and_disable_interrupts() * * \param status Previous interrupt status from save_and_disable_interrupts() From 0ed224cf591b35f542ddb6615bbce44ce5799ddd Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 17 Feb 2025 16:07:27 -0600 Subject: [PATCH 061/224] Add irq_has_handler() and use it to fix GPIO IRQ assert (#2277) --- src/rp2_common/hardware_gpio/gpio.c | 7 ++----- .../hardware_irq/include/hardware/irq.h | 16 +++++++++++++++- src/rp2_common/hardware_irq/irq.c | 8 +++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/rp2_common/hardware_gpio/gpio.c b/src/rp2_common/hardware_gpio/gpio.c index 44c39e9c4..2c4e91d40 100644 --- a/src/rp2_common/hardware_gpio/gpio.c +++ b/src/rp2_common/hardware_gpio/gpio.c @@ -184,12 +184,9 @@ static void _gpio_set_irq_enabled(uint gpio, uint32_t events, bool enabled, io_b } void gpio_set_irq_enabled(uint gpio, uint32_t events, bool enabled) { - // either this call disables the interrupt - // or callback should already be set (raw or using gpio_set_irq_callback) + // either this call disables the interrupt or callback should already be set. // this protects against enabling the interrupt without callback set - assert(!enabled - || (raw_irq_mask[get_core_num()] & (1ull< Date: Mon, 17 Feb 2025 12:12:07 -1000 Subject: [PATCH 062/224] Update README.md (#2289) Fix Issue #2288 Correct spelling of boardname --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69f6c4ef3..4d24d9fa2 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ instructions for other platforms, and just in general, we recommend you see [Ras When building for a board other than the Raspberry Pi Pico, you should pass `-DPICO_BOARD=board_name` to the `cmake` command above, e.g. `cmake -DPICO_BOARD=pico2 ..` or `cmake -DPICO_BOARD=pico_w ..` to configure the SDK and build options accordingly for that particular board. - Specifying `PICO_BOARD=` sets up various compiler defines (e.g. default pin numbers for UART and other hardware) and in certain + Specifying `PICO_BOARD=` sets up various compiler defines (e.g. default pin numbers for UART and other hardware) and in certain cases also enables the use of additional libraries (e.g. wireless support when building for `PICO_BOARD=pico_w`) which cannot be built without a board which provides the requisite hardware functionality. From 38776d876402b63fe8f2f73a4665c39b8c8b96e0 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 17 Feb 2025 21:49:47 -0600 Subject: [PATCH 063/224] add missing define --- src/common/boot_picobin_headers/include/boot/picobin.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/boot_picobin_headers/include/boot/picobin.h b/src/common/boot_picobin_headers/include/boot/picobin.h index 25308478b..0b65221e0 100644 --- a/src/common/boot_picobin_headers/include/boot/picobin.h +++ b/src/common/boot_picobin_headers/include/boot/picobin.h @@ -76,6 +76,9 @@ #define PICOBIN_IMAGE_TYPE_EXE_CPU_VARMULET _u(2) #define PICOBIN_IMAGE_TYPE_EXE_CPU_AS_BITS(x) _PICOBIN_INDEX_TO_BITS(PICOBIN_IMAGE_TYPE_EXE_CPU, _ ## x) +#define PICOBIN_IMAGE_TYPE_EXE_EXTRA_SECURITY_LSB _u(11) +#define PICOBIN_IMAGE_TYPE_EXE_EXTRA_SECURITY_BITS _u(0x0800) + #define PICOBIN_IMAGE_TYPE_EXE_CHIP_LSB _u(12) #define PICOBIN_IMAGE_TYPE_EXE_CHIP_BITS _u(0x7000) #define PICOBIN_IMAGE_TYPE_EXE_CHIP_RP2040 _u(0) From 7ce1ae8cdf273267b2d5bc555950bf451457193b Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 18 Feb 2025 15:50:44 +0000 Subject: [PATCH 064/224] Comment typo (#2293) --- src/rp2_common/hardware_pio/pio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_pio/pio.c b/src/rp2_common/hardware_pio/pio.c index 33b039457..9b59c4132 100644 --- a/src/rp2_common/hardware_pio/pio.c +++ b/src/rp2_common/hardware_pio/pio.c @@ -164,7 +164,7 @@ static int add_program_at_offset(PIO pio, const pio_program_t *program, uint off uint16_t instr = program->instructions[i]; #if PICO_PIO_USE_GPIO_BASE if (pio_instr_bits_wait == _pio_major_instr_bits(instr) && !((_pio_arg1(instr) & 3u))) { - // wait GIO will include only the 5 lower bits of the GPIO number, so if the GPIO + // wait GPIO will include only the 5 lower bits of the GPIO number, so if the GPIO // base is 16 we need to flip bit 4 (which is equivalent to subtracting 16 from // the original number 16-47 stored as 16-31 and 0-15) static_assert(PIO_GPIOBASE_BITS == 16, ""); // only works for gpio base being 0 or 16 From c757f36aacee8d664fecc59abc8c7e3c631baba5 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 18 Feb 2025 09:51:51 -0600 Subject: [PATCH 065/224] add PICO_USE_FASTEST_SUPPORTED_CLOCK, and support vreg setting and SYS_CLOCK_MHZ=200 for rp2040 (#2285) --- .../include/hardware/platform_defs.h | 9 ++++++ .../include/hardware/platform_defs.h | 5 ++++ src/rp2_common/BUILD.bazel | 1 + src/rp2_common/hardware_clocks/CMakeLists.txt | 6 +++- .../hardware_clocks/include/hardware/clocks.h | 30 +++++++++++++++++++ src/rp2_common/hardware_vreg/BUILD.bazel | 2 +- .../hardware_vreg/include/hardware/vreg.h | 7 +++++ src/rp2_common/hardware_vreg/vreg.c | 18 ++++++----- src/rp2_common/pico_runtime_init/BUILD.bazel | 2 ++ .../pico_runtime_init/CMakeLists.txt | 2 +- .../pico_runtime_init/runtime_init_clocks.c | 11 +++++++ 11 files changed, 82 insertions(+), 11 deletions(-) diff --git a/src/rp2040/hardware_regs/include/hardware/platform_defs.h b/src/rp2040/hardware_regs/include/hardware/platform_defs.h index 1d23b9d12..537988846 100644 --- a/src/rp2040/hardware_regs/include/hardware/platform_defs.h +++ b/src/rp2040/hardware_regs/include/hardware/platform_defs.h @@ -61,6 +61,11 @@ #endif #endif +// PICO_CONFIG: PICO_USE_FASTEST_SUPPORTED_CLOCK, Use the fastest officially supported clock by default, type=bool, default=0, group=hardware_base +#ifndef PICO_USE_FASTEST_SUPPORTED_CLOCK +#define PICO_USE_FASTEST_SUPPORTED_CLOCK 0 +#endif + // PICO_CONFIG: SYS_CLK_HZ, System operating frequency in Hz, type=int, default=125000000, advanced=true, group=hardware_base #ifndef SYS_CLK_HZ #ifdef SYS_CLK_KHZ @@ -68,9 +73,13 @@ #elif defined(SYS_CLK_MHZ) #define SYS_CLK_HZ ((SYS_CLK_MHZ) * _u(1000000)) #else +#if PICO_USE_FASTEST_SUPPORTED_CLOCK +#define SYS_CLK_HZ _u(200000000) +#else #define SYS_CLK_HZ _u(125000000) #endif #endif +#endif // PICO_CONFIG: USB_CLK_HZ, USB clock frequency. Must be 48MHz for the USB interface to operate correctly, type=int, default=48000000, advanced=true, group=hardware_base #ifndef USB_CLK_HZ diff --git a/src/rp2350/hardware_regs/include/hardware/platform_defs.h b/src/rp2350/hardware_regs/include/hardware/platform_defs.h index bd8b68a9f..25dc1d624 100644 --- a/src/rp2350/hardware_regs/include/hardware/platform_defs.h +++ b/src/rp2350/hardware_regs/include/hardware/platform_defs.h @@ -89,6 +89,11 @@ #endif #endif +// PICO_CONFIG: PICO_USE_FASTEST_SUPPORTED_CLOCK, Use the fastest officially supported clock by default, type=bool, default=0, group=hardware_base +#ifndef PICO_USE_FASTEST_SUPPORTED_CLOCK +#define PICO_USE_FASTEST_SUPPORTED_CLOCK 0 +#endif + // PICO_CONFIG: SYS_CLK_HZ, System operating frequency in Hz, type=int, default=150000000, advanced=true, group=hardware_base #ifndef SYS_CLK_HZ #ifdef SYS_CLK_KHZ diff --git a/src/rp2_common/BUILD.bazel b/src/rp2_common/BUILD.bazel index 6ad8f2241..fe1c0c3e3 100644 --- a/src/rp2_common/BUILD.bazel +++ b/src/rp2_common/BUILD.bazel @@ -71,6 +71,7 @@ alias( "//src/rp2_common/hardware_base:__pkg__", "//src/rp2_common/hardware_irq:__pkg__", "//src/rp2_common/hardware_pll:__pkg__", + "//src/rp2_common/hardware_vreg:__pkg__", "//src/rp2_common/hardware_watchdog:__pkg__", "//src/rp2_common/hardware_xosc:__pkg__", "//src/rp2_common/pico_bit_ops:__pkg__", diff --git a/src/rp2_common/hardware_clocks/CMakeLists.txt b/src/rp2_common/hardware_clocks/CMakeLists.txt index 87312781c..95b16c2f3 100644 --- a/src/rp2_common/hardware_clocks/CMakeLists.txt +++ b/src/rp2_common/hardware_clocks/CMakeLists.txt @@ -10,4 +10,8 @@ pico_mirrored_target_link_libraries(hardware_clocks INTERFACE hardware_vreg hardware_watchdog hardware_xosc -) \ No newline at end of file +) + +if (PICO_USE_FASTEST_SUPPORTED_CLOCK) + target_compile_definitions(hardware_clocks INTERFACE PICO_USE_FASTEST_SUPPORTED_CLOCK=1) +endif() \ No newline at end of file diff --git a/src/rp2_common/hardware_clocks/include/hardware/clocks.h b/src/rp2_common/hardware_clocks/include/hardware/clocks.h index ec6eb0609..8320cea27 100644 --- a/src/rp2_common/hardware_clocks/include/hardware/clocks.h +++ b/src/rp2_common/hardware_clocks/include/hardware/clocks.h @@ -206,6 +206,36 @@ extern "C" { #endif #endif // SYS_CLK_KHZ == 125000 && XOSC_KHZ == 12000 && PLL_COMMON_REFDIV == 1 +#if PICO_RP2040 && (SYS_CLK_HZ == 200 * MHZ) && (XOSC_HZ == 12 * MHZ) && (PLL_SYS_REFDIV == 1) +// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST, Should the regulator voltage be adjusted above SYS_CLK_VREG_VOLTAGE_MIN when initializing the clocks, type=bool, default=0, advanced=true, group=hardware_clocks +#ifndef SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST +#define SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST 1 +#endif +// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_MIN, minimum voltage (see VREG_VOLTAGE_x_xx) for the voltage regulator to be ensured during clock initialization if SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST is 1, type=int, advanced=true, group=hardware_clocks +#if SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST && !defined(SYS_CLK_VREG_VOLTAGE_MIN) +#define SYS_CLK_VREG_VOLTAGE_MIN VREG_VOLTAGE_1_15 +#endif +// PLL settings for fast 200 MHz system clock on RP2040 +#ifndef PLL_SYS_VCO_FREQ_HZ +#define PLL_SYS_VCO_FREQ_HZ (1200 * MHZ) +#endif +#ifndef PLL_SYS_POSTDIV1 +#define PLL_SYS_POSTDIV1 6 +#endif +#ifndef PLL_SYS_POSTDIV2 +#define PLL_SYS_POSTDIV2 1 +#endif +#else +#ifndef SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST +#define SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST 0 +#endif +#endif // PICO_RP2040 && SYS_CLK_KHZ == 200000 && XOSC_KHZ == 12000 && PLL_COMMON_REFDIV == 1 + +// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US, Number of microseconds to wait after updating regulator voltage due to SYS_CLK_VREG_VOLTAGE_MIN to allow voltage to settle, type=bool, default=1, advanced=true, group=hardware_clocks +#ifndef SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US +#define SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US 1000 +#endif + #if !defined(PLL_SYS_VCO_FREQ_HZ) || !defined(PLL_SYS_POSTDIV1) || !defined(PLL_SYS_POSTDIV2) #error PLL_SYS_VCO_FREQ_HZ, PLL_SYS_POSTDIV1 and PLL_SYS_POSTDIV2 must all be specified when using custom clock setup #endif diff --git a/src/rp2_common/hardware_vreg/BUILD.bazel b/src/rp2_common/hardware_vreg/BUILD.bazel index a1d381eef..d8f092be5 100644 --- a/src/rp2_common/hardware_vreg/BUILD.bazel +++ b/src/rp2_common/hardware_vreg/BUILD.bazel @@ -10,7 +10,7 @@ cc_library( target_compatible_with = compatible_with_rp2(), deps = [ "//src/rp2_common:hardware_structs", - "//src/rp2_common:pico_platform", + "//src/rp2_common:pico_platform_internal", "//src/rp2_common/hardware_base", ], ) diff --git a/src/rp2_common/hardware_vreg/include/hardware/vreg.h b/src/rp2_common/hardware_vreg/include/hardware/vreg.h index ce6ad0ca6..011ba7991 100644 --- a/src/rp2_common/hardware_vreg/include/hardware/vreg.h +++ b/src/rp2_common/hardware_vreg/include/hardware/vreg.h @@ -82,6 +82,13 @@ enum vreg_voltage { void vreg_set_voltage(enum vreg_voltage voltage); +/*! \brief Get voltage + * \ingroup hardware_vreg + * + * \return The current voltage (from enumeration \ref vreg_voltage) of the voltage regulator + **/ +enum vreg_voltage vreg_get_voltage(void); + /*! \brief Enable use of voltages beyond the safe range of operation * \ingroup hardware_vreg * diff --git a/src/rp2_common/hardware_vreg/vreg.c b/src/rp2_common/hardware_vreg/vreg.c index 61fd08042..b5a406c06 100644 --- a/src/rp2_common/hardware_vreg/vreg.c +++ b/src/rp2_common/hardware_vreg/vreg.c @@ -16,7 +16,7 @@ void vreg_set_voltage(enum vreg_voltage voltage) { VREG_AND_CHIP_RESET_VREG_VSEL_BITS ); -#elif PICO_RP2350 +#else hw_set_bits(&powman_hw->vreg_ctrl, POWMAN_PASSWORD_BITS | POWMAN_VREG_CTRL_UNLOCK_BITS); @@ -32,19 +32,21 @@ void vreg_set_voltage(enum vreg_voltage voltage) { while (powman_hw->vreg & POWMAN_VREG_UPDATE_IN_PROGRESS_BITS) tight_loop_contents(); +#endif +} + +enum vreg_voltage vreg_get_voltage(void) { +#if PICO_RP2040 + return (vreg_and_chip_reset_hw->vreg & VREG_AND_CHIP_RESET_VREG_VSEL_BITS) >> VREG_AND_CHIP_RESET_VREG_VSEL_LSB; #else - panic_unsupported(); + return (powman_hw->vreg & POWMAN_VREG_VSEL_BITS) >> POWMAN_VREG_VSEL_LSB; #endif } void vreg_disable_voltage_limit(void) { #if PICO_RP2040 - // The voltage limit can't be disabled on RP2040 (was implemented by - // hardwiring the LDO controls) - return; -#elif PICO_RP2350 - hw_set_bits(&powman_hw->vreg_ctrl, POWMAN_PASSWORD_BITS | POWMAN_VREG_CTRL_DISABLE_VOLTAGE_LIMIT_BITS); + // The voltage limit can't be disabled on RP2040 (was implemented by hard-wiring the LDO controls) #else - panic_unsupported(); + hw_set_bits(&powman_hw->vreg_ctrl, POWMAN_PASSWORD_BITS | POWMAN_VREG_CTRL_DISABLE_VOLTAGE_LIMIT_BITS); #endif } diff --git a/src/rp2_common/pico_runtime_init/BUILD.bazel b/src/rp2_common/pico_runtime_init/BUILD.bazel index ec5c40205..8956c4e18 100644 --- a/src/rp2_common/pico_runtime_init/BUILD.bazel +++ b/src/rp2_common/pico_runtime_init/BUILD.bazel @@ -34,6 +34,8 @@ cc_library( "//src/rp2_common/hardware_base", "//src/rp2_common/hardware_clocks", "//src/rp2_common/hardware_ticks", + "//src/rp2_common/hardware_timer", + "//src/rp2_common/hardware_vreg", "//src/rp2_common/pico_bootrom", "//src/rp2_common/pico_runtime", ], diff --git a/src/rp2_common/pico_runtime_init/CMakeLists.txt b/src/rp2_common/pico_runtime_init/CMakeLists.txt index 769e4aa11..81f6ab47f 100644 --- a/src/rp2_common/pico_runtime_init/CMakeLists.txt +++ b/src/rp2_common/pico_runtime_init/CMakeLists.txt @@ -13,7 +13,7 @@ pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE ) if (TARGET hardware_clocks) - pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_clocks) + pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_clocks hardware_timer hardware_vreg) endif() # pico/runtime_init.h includes pico/runtime.h diff --git a/src/rp2_common/pico_runtime_init/runtime_init_clocks.c b/src/rp2_common/pico_runtime_init/runtime_init_clocks.c index 435a80166..85d473b8e 100644 --- a/src/rp2_common/pico_runtime_init/runtime_init_clocks.c +++ b/src/rp2_common/pico_runtime_init/runtime_init_clocks.c @@ -10,6 +10,8 @@ #include "hardware/clocks.h" #include "hardware/pll.h" #include "hardware/ticks.h" +#include "hardware/timer.h" +#include "hardware/vreg.h" #include "hardware/xosc.h" #if PICO_RP2040 #include "hardware/regs/rtc.h" @@ -85,6 +87,15 @@ void __weak runtime_init_clocks(void) { 0, XOSC_HZ); + // This must be done after we've configured CLK_REF to XOSC due to the need to time a delay +#if SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST && defined(SYS_CLK_VREG_VOLTAGE_MIN) + if (vreg_get_voltage() < SYS_CLK_VREG_VOLTAGE_MIN) { + vreg_set_voltage(SYS_CLK_VREG_VOLTAGE_MIN); + // wait for voltage to settle; must use CPU cycles as TIMER is not yet clocked correctly + busy_wait_at_least_cycles((uint32_t)((SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US * (uint64_t)XOSC_HZ) / 1000000)); + } +#endif + /// \tag::configure_clk_sys[] // CLK SYS = PLL SYS (usually) 125MHz / 1 = 125MHz clock_configure_undivided(clk_sys, From a38da922e57f7a1c840349c9307941d207001902 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 18 Feb 2025 11:48:48 -0600 Subject: [PATCH 066/224] add cast (#2298) --- src/rp2_common/hardware_clocks/clocks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_clocks/clocks.c b/src/rp2_common/hardware_clocks/clocks.c index c648a729f..2d41c73d2 100644 --- a/src/rp2_common/hardware_clocks/clocks.c +++ b/src/rp2_common/hardware_clocks/clocks.c @@ -108,7 +108,7 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32 div = 0; actual_freq = src_freq >> (32 - CLOCKS_CLK_GPOUT0_DIV_INT_LSB); } else { - div = div64; + div = (uint32_t) div64; #if PICO_RP2040 // on RP2040 only clock divider of 1, or >= 2 are supported if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) { From 186e71546270036c6175567be296eb7aef3edf53 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 18 Feb 2025 12:17:34 -0600 Subject: [PATCH 067/224] fix up access type of CHAN_ABORT register in RP2040.svd and RP2350.svd (#2270) --- src/rp2040/hardware_regs/RP2040.svd | 3 ++- src/rp2350/hardware_regs/RP2350.svd | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rp2040/hardware_regs/RP2040.svd b/src/rp2040/hardware_regs/RP2040.svd index 7ffdf3868..2bac8265d 100644 --- a/src/rp2040/hardware_regs/RP2040.svd +++ b/src/rp2040/hardware_regs/RP2040.svd @@ -32214,7 +32214,8 @@ SPDX-License-Identifier: BSD-3-Clause After writing, this register must be polled until it returns all-zero. Until this point, it is unsafe to restart the channel. [15:0] - write-only + read-write + oneToClear diff --git a/src/rp2350/hardware_regs/RP2350.svd b/src/rp2350/hardware_regs/RP2350.svd index aa2c36213..fc6479ebb 100644 --- a/src/rp2350/hardware_regs/RP2350.svd +++ b/src/rp2350/hardware_regs/RP2350.svd @@ -62229,7 +62229,8 @@ SPDX-License-Identifier: BSD-3-Clause After writing, this register must be polled until it returns all-zero. Until this point, it is unsafe to restart the channel. [15:0] - write-only + read-write + oneToClear From 2dd58bff9e83549177c9b4c93b654ddadc7412f0 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 18 Feb 2025 12:18:25 -0600 Subject: [PATCH 068/224] fix emulated asynchronous divisions started via hw_divider_divmod_s32_start and hw_divider_divmod_u32_start (#2299) --- src/rp2_common/hardware_divider/include/hardware/divider.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/hardware_divider/include/hardware/divider.h b/src/rp2_common/hardware_divider/include/hardware/divider.h index de8772dfd..70746da58 100644 --- a/src/rp2_common/hardware_divider/include/hardware/divider.h +++ b/src/rp2_common/hardware_divider/include/hardware/divider.h @@ -110,7 +110,7 @@ static inline void hw_divider_divmod_s32_start(int32_t a, int32_t b) { sio_hw->div_sdividend = (uint32_t)a; sio_hw->div_sdivisor = (uint32_t)b; #else - hw_divider_divmod_s32(a, b); + hw_divider_results[get_core_num()] = hw_divider_divmod_s32(a, b); #endif } @@ -130,7 +130,7 @@ static inline void hw_divider_divmod_u32_start(uint32_t a, uint32_t b) { sio_hw->div_udividend = a; sio_hw->div_udivisor = b; #else - hw_divider_divmod_u32(a, b); + hw_divider_results[get_core_num()] = hw_divider_divmod_u32(a, b); #endif } From 6a7b4c71601013d673e79558efce1e21532d97a3 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 18 Feb 2025 16:56:03 -0600 Subject: [PATCH 069/224] fix warning --- src/rp2_common/hardware_pio/pio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_pio/pio.c b/src/rp2_common/hardware_pio/pio.c index 9b59c4132..7182cfff5 100644 --- a/src/rp2_common/hardware_pio/pio.c +++ b/src/rp2_common/hardware_pio/pio.c @@ -168,7 +168,7 @@ static int add_program_at_offset(PIO pio, const pio_program_t *program, uint off // base is 16 we need to flip bit 4 (which is equivalent to subtracting 16 from // the original number 16-47 stored as 16-31 and 0-15) static_assert(PIO_GPIOBASE_BITS == 16, ""); // only works for gpio base being 0 or 16 - instr ^= pio_get_gpio_base(pio); + instr ^= (uint16_t)pio_get_gpio_base(pio); } #endif pio->instr_mem[offset + i] = pio_instr_bits_jmp != _pio_major_instr_bits(instr) ? instr : instr + offset; From b5af60771cfbcf648a64e0f3c35e12462180b2b1 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 18 Feb 2025 13:47:05 -0600 Subject: [PATCH 070/224] bump SDK version to 2.1.1 and update picotool dependency since 2.1.1 is faster --- MODULE.bazel | 4 ++-- pico_sdk_version.cmake | 2 +- tools/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 99cd4c3d2..f80a08a99 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,12 +1,12 @@ module( name = "pico-sdk", - version = "2.1.1-develop", + version = "2.1.1", ) bazel_dep(name = "platforms", version = "0.0.9") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "rules_python", version = "0.36.0") -bazel_dep(name = "picotool", version = "2.1.0") +bazel_dep(name = "picotool", version = "2.1.1") bazel_dep(name = "rules_cc", version = "0.0.10") http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/pico_sdk_version.cmake b/pico_sdk_version.cmake index dea7dabb5..58d0b1483 100644 --- a/pico_sdk_version.cmake +++ b/pico_sdk_version.cmake @@ -9,7 +9,7 @@ set(PICO_SDK_VERSION_MINOR 1) set(PICO_SDK_VERSION_REVISION 1) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base -set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) +# set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 371756664..c2fbe3281 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -101,7 +101,7 @@ endfunction() # Check picotool is installed, or download and build it if not installed function(pico_init_picotool) - set(picotool_VERSION_REQUIRED 2.1.0) + set(picotool_VERSION_REQUIRED 2.1.1) if (NOT TARGET picotool AND NOT DEFINED picotool_FOUND) # Build path of local install dir if (DEFINED ENV{PICOTOOL_FETCH_FROM_GIT_PATH} AND (NOT PICOTOOL_FETCH_FROM_GIT_PATH)) From a994a8abce49afdb0f3423688d6d603aa5df8d71 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 18 Feb 2025 17:19:20 -0600 Subject: [PATCH 071/224] temporary disable bazel CI check against referened picotool --- .github/workflows/bazel_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bazel_build.yml b/.github/workflows/bazel_build.yml index 81b7ae583..1d98ef7ba 100644 --- a/.github/workflows/bazel_build.yml +++ b/.github/workflows/bazel_build.yml @@ -41,8 +41,8 @@ jobs: - name: Full Bazel build with develop Picotool run: python3 tools/run_all_bazel_checks.py --program=build --picotool-dir=lib/picotool # Checks that the current BCR-requested version of Picotool builds. - - name: Bazel Picotool backwards compatibility - run: bazel build @picotool//:picotool + # - name: Bazel Picotool backwards compatibility + # run: bazel build @picotool//:picotool other-bazel-checks: runs-on: ubuntu-latest steps: From bddd20f928ce76142793bef434d4f75f4af6e433 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 18 Feb 2025 17:55:07 -0600 Subject: [PATCH 072/224] SDK 2.1.1 Release --- .github/workflows/bazel_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bazel_build.yml b/.github/workflows/bazel_build.yml index 1d98ef7ba..81b7ae583 100644 --- a/.github/workflows/bazel_build.yml +++ b/.github/workflows/bazel_build.yml @@ -41,8 +41,8 @@ jobs: - name: Full Bazel build with develop Picotool run: python3 tools/run_all_bazel_checks.py --program=build --picotool-dir=lib/picotool # Checks that the current BCR-requested version of Picotool builds. - # - name: Bazel Picotool backwards compatibility - # run: bazel build @picotool//:picotool + - name: Bazel Picotool backwards compatibility + run: bazel build @picotool//:picotool other-bazel-checks: runs-on: ubuntu-latest steps: From c871e759c6c5a0bd4373629e96bd9fe48cb6d016 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 18 Feb 2025 19:46:23 -0600 Subject: [PATCH 073/224] start 2.1.2-develop --- MODULE.bazel | 2 +- pico_sdk_version.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index f80a08a99..d3afd78ff 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "pico-sdk", - version = "2.1.1", + version = "2.1.2-develop", ) bazel_dep(name = "platforms", version = "0.0.9") diff --git a/pico_sdk_version.cmake b/pico_sdk_version.cmake index 58d0b1483..772ab8237 100644 --- a/pico_sdk_version.cmake +++ b/pico_sdk_version.cmake @@ -6,10 +6,10 @@ set(PICO_SDK_VERSION_MAJOR 2) set(PICO_SDK_VERSION_MINOR 1) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base -set(PICO_SDK_VERSION_REVISION 1) +set(PICO_SDK_VERSION_REVISION 2) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base -# set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) +set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base From ee68c78d0afae2b69c03ae1a72bf5cc267a2d94c Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 18 Feb 2025 20:08:06 -0600 Subject: [PATCH 074/224] fix doc for SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US --- src/rp2_common/hardware_clocks/include/hardware/clocks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_clocks/include/hardware/clocks.h b/src/rp2_common/hardware_clocks/include/hardware/clocks.h index 8320cea27..68f4b1a50 100644 --- a/src/rp2_common/hardware_clocks/include/hardware/clocks.h +++ b/src/rp2_common/hardware_clocks/include/hardware/clocks.h @@ -231,7 +231,7 @@ extern "C" { #endif #endif // PICO_RP2040 && SYS_CLK_KHZ == 200000 && XOSC_KHZ == 12000 && PLL_COMMON_REFDIV == 1 -// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US, Number of microseconds to wait after updating regulator voltage due to SYS_CLK_VREG_VOLTAGE_MIN to allow voltage to settle, type=bool, default=1, advanced=true, group=hardware_clocks +// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US, Number of microseconds to wait after updating regulator voltage due to SYS_CLK_VREG_VOLTAGE_MIN to allow voltage to settle, type=bool, default=1000, advanced=true, group=hardware_clocks #ifndef SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US #define SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US 1000 #endif From 26ab4be83416bd99f6c7a2a254f92827415620a5 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Mon, 3 Mar 2025 17:21:16 +0000 Subject: [PATCH 075/224] Fix misleading error messages in spin_lock.h (#2326) (looks like this was a copy-paste mistake) --- .../hardware_sync_spin_lock/include/hardware/sync/spin_lock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h b/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h index 6885efd79..2be493d6f 100644 --- a/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h +++ b/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h @@ -149,7 +149,7 @@ typedef SW_SPIN_LOCK_TYPE spin_lock_t; __mem_fence_acquire(); \ }) #else -#error no SW_SPIN_TRY_LOCK available for PICO_USE_SW_SPIN_LOCK on this platform +#error no SW_SPIN_LOCK_LOCK available for PICO_USE_SW_SPIN_LOCK on this platform #endif #endif @@ -210,7 +210,7 @@ typedef SW_SPIN_LOCK_TYPE spin_lock_t; *(lock) = 0; /* write to spinlock register (release lock) */ \ }) #else -#error no SW_SPIN_TRY_LOCK available for PICO_USE_SW_SPIN_LOCK on this platform +#error no SW_SPIN_LOCK_UNLOCK available for PICO_USE_SW_SPIN_LOCK on this platform #endif #endif From dd1f48335b104c34d50d53292dab3eeddb9232f8 Mon Sep 17 00:00:00 2001 From: Alex Brudner <101155592+SFE-Brudnerd@users.noreply.github.com> Date: Wed, 5 Mar 2025 09:46:07 -0700 Subject: [PATCH 076/224] Add upcoming sparkfun board (#2329) --- .../boards/sparkfun_iotredboard_rp2350.h | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 src/boards/include/boards/sparkfun_iotredboard_rp2350.h diff --git a/src/boards/include/boards/sparkfun_iotredboard_rp2350.h b/src/boards/include/boards/sparkfun_iotredboard_rp2350.h new file mode 100644 index 000000000..ac0972eb2 --- /dev/null +++ b/src/boards/include/boards/sparkfun_iotredboard_rp2350.h @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- +// Board definition for the SparkFun IoT RedBoard - RP2350 +// +// This header may be included by other board headers as "boards/sparkfun_iotredboard_rp2350.h" + +// pico_cmake_set PICO_PLATFORM=rp2350 +// pico_cmake_set PICO_CYW43_SUPPORTED = 1 + +#ifndef _BOARDS_SPARKFUN_IOTREDBOARD_RP2350_H +#define _BOARDS_SPARKFUN_IOTREDBOARD_RP2350_H + +// For board detection +#define SPARKFUN_IOTREDBOARD_RP2350 + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 0 // 1 for RP2350A, 0 for RP2350B + +// --- BOARD SPECIFIC --- +#define SPARKFUN_IOTREDBOARD_RP2350_USER_SW_PIN 39 +#define SPARKFUN_IOTREDBOARD_RP2350_PSRAM_CS_PIN 47 + + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif + +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 3 +#endif + +// --- I2C --- Qwiic connector is on these pins +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 4 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 5 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 22 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 23 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 20 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 21 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +// The IoT RedBoard has an SD Card. +#ifndef PICO_SD_CLK_PIN +#define PICO_SD_CLK_PIN 10 +#endif +#ifndef PICO_SD_CMD_PIN +#define PICO_SD_CMD_PIN 11 +#endif +#ifndef PICO_SD_DAT0_PIN +#define PICO_SD_DAT0_PIN 8 +#endif +#ifndef PICO_SD_DAT3_PIN +#define PICO_SD_DAT3_PIN 9 // DAT3 of the SD card is the chip select pin +#endif +#ifndef PICO_SD_DAT_PIN_COUNT +#define PICO_SD_DAT_PIN_COUNT 1 +#endif + +// The GPIO Pin used to monitor VSYS. Typically you would use this with ADC. +// There is an example in adc/read_vsys in pico-examples. +#ifndef PICO_VSYS_PIN +#define PICO_VSYS_PIN 46 +#endif + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +// Bootloader activity LED in double reset mode. +#ifndef PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED +#define PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED PICO_DEFAULT_LED_PIN +#endif + +// Bootloader activity LED in USB reset mode. +#ifndef PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED +#define PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED PICO_DEFAULT_LED_PIN +#endif + +// --- CYW43 --- + +#ifndef CYW43_WL_GPIO_COUNT +#define CYW43_WL_GPIO_COUNT 3 +#endif + +#ifndef CYW43_WL_GPIO_LED_PIN +#define CYW43_WL_GPIO_LED_PIN 0 +#endif + +// If CYW43_WL_GPIO_VBUS_PIN is defined then a CYW43 GPIO has to be used to read VBUS. +// This can be passed to cyw43_arch_gpio_get to determine if the device is battery powered. +// PICO_VBUS_PIN and CYW43_WL_GPIO_VBUS_PIN should not both be defined. +#ifndef CYW43_WL_GPIO_VBUS_PIN +#define CYW43_WL_GPIO_VBUS_PIN 2 +#endif + +// cyw43 SPI pins can't be changed at runtime +#ifndef CYW43_PIN_WL_DYNAMIC +#define CYW43_PIN_WL_DYNAMIC 0 +#endif + +// gpio pin to power up the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_REG_ON +#define CYW43_DEFAULT_PIN_WL_REG_ON 24u +#endif + +// gpio pin for spi data out to the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_DATA_OUT +#define CYW43_DEFAULT_PIN_WL_DATA_OUT 38u +#endif + +// gpio pin for spi data in from the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_DATA_IN +#define CYW43_DEFAULT_PIN_WL_DATA_IN 38u +#endif + +// gpio (irq) pin for the irq line from the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_HOST_WAKE +#define CYW43_DEFAULT_PIN_WL_HOST_WAKE 38u +#endif + +// gpio pin for the spi clock line to the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_CLOCK +#define CYW43_DEFAULT_PIN_WL_CLOCK 37u +#endif + +// gpio pin for the spi chip select to the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_CS +#define CYW43_DEFAULT_PIN_WL_CS 36u +#endif + +#endif // _BOARDS_SPARKFUN_IOTREDBOARD_RP2350_H From b1676c18a3a9e3670d2a83a6d72b3a97e0ff31db Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Sun, 9 Mar 2025 14:39:21 -0500 Subject: [PATCH 077/224] fix return type of enable/disable interrupt methods... add host versions for completeness (#2310) --- src/host/hardware_sync/include/hardware/sync.h | 4 ++++ src/host/hardware_sync/sync_core0_only.c | 9 +++++++++ src/rp2_common/hardware_sync/include/hardware/sync.h | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/host/hardware_sync/include/hardware/sync.h b/src/host/hardware_sync/include/hardware/sync.h index ffbc08032..ae3865ae2 100644 --- a/src/host/hardware_sync/include/hardware/sync.h +++ b/src/host/hardware_sync/include/hardware/sync.h @@ -121,6 +121,10 @@ void restore_interrupts(uint32_t status); void restore_interrupts_from_disabled(uint32_t status); +void disable_interrupts(void); + +void enable_interrupts(void); + uint spin_lock_get_num(spin_lock_t *lock); spin_lock_t *spin_lock_instance(uint lock_num); diff --git a/src/host/hardware_sync/sync_core0_only.c b/src/host/hardware_sync/sync_core0_only.c index 47d0f2f5b..70964c4b0 100644 --- a/src/host/hardware_sync/sync_core0_only.c +++ b/src/host/hardware_sync/sync_core0_only.c @@ -31,6 +31,15 @@ PICO_WEAK_FUNCTION_DEF(restore_interrupts_from_disabled) void PICO_WEAK_FUNCTION_IMPL_NAME(restore_interrupts_from_disabled)(uint32_t status) { } +PICO_WEAK_FUNCTION_DEF(disable_interrupts) + +void PICO_WEAK_FUNCTION_IMPL_NAME(disable_interrupts)(void) { +} + +PICO_WEAK_FUNCTION_DEF(enable_interrupts) + +void PICO_WEAK_FUNCTION_IMPL_NAME(enable_interrupts)(void) { +} PICO_WEAK_FUNCTION_DEF(spin_lock_instance) diff --git a/src/rp2_common/hardware_sync/include/hardware/sync.h b/src/rp2_common/hardware_sync/include/hardware/sync.h index 82b253786..69b3e69a0 100644 --- a/src/rp2_common/hardware_sync/include/hardware/sync.h +++ b/src/rp2_common/hardware_sync/include/hardware/sync.h @@ -201,7 +201,7 @@ __force_inline static void __mem_fence_release(void) { /*! \brief Explicitly disable interrupts on the calling core * \ingroup hardware_sync */ -__force_inline static uint32_t disable_interrupts(void) { +__force_inline static void disable_interrupts(void) { #ifdef __riscv __compiler_memory_barrier(); riscv_clear_csr(mstatus, 8); @@ -214,7 +214,7 @@ __force_inline static uint32_t disable_interrupts(void) { /*! \brief Explicitly enable interrupts on the calling core * \ingroup hardware_sync */ -__force_inline static uint32_t enable_interrupts(void) { +__force_inline static void enable_interrupts(void) { #ifdef __riscv __compiler_memory_barrier(); riscv_set_csr(mstatus, 8); From ab12d556cdafdabe53950517b4a9f26209b12564 Mon Sep 17 00:00:00 2001 From: eightycc Date: Tue, 18 Mar 2025 08:08:11 -0700 Subject: [PATCH 078/224] Fix use of PICO_RP2040 macro. (#2356) --- src/rp2_common/pico_crt0/embedded_start_block.inc.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_crt0/embedded_start_block.inc.S b/src/rp2_common/pico_crt0/embedded_start_block.inc.S index 8f1b622d4..e4632255b 100644 --- a/src/rp2_common/pico_crt0/embedded_start_block.inc.S +++ b/src/rp2_common/pico_crt0/embedded_start_block.inc.S @@ -41,7 +41,7 @@ embedded_block: PICOBIN_IMAGE_TYPE_EXE_CPU_AS_BITS(RISCV) | \ PICOBIN_IMAGE_TYPE_EXE_CHIP_AS_BITS(RP2350) | \ CRT0_TBYB_FLAG -#elif defined(PICO_RP2040) +#elif PICO_RP2040 .hword PICOBIN_IMAGE_TYPE_IMAGE_TYPE_AS_BITS(EXE) | \ PICOBIN_IMAGE_TYPE_EXE_SECURITY_AS_BITS(NS) | \ PICOBIN_IMAGE_TYPE_EXE_CPU_AS_BITS(ARM) | \ @@ -84,7 +84,7 @@ embedded_block: .word SRAM_END // stack pointer #endif -#ifndef PICO_RP2040 +#if !PICO_RP2040 #if PICO_NO_FLASH // If no_flash bin, then include a vector table item .byte PICOBIN_BLOCK_ITEM_1BS_VECTOR_TABLE From 4f31ef17613adae101cb98912e623a6c92a3040b Mon Sep 17 00:00:00 2001 From: Dryw Wade Date: Tue, 18 Mar 2025 12:22:27 -0600 Subject: [PATCH 079/224] Add SparkFun XRP Controller header (#2347) --- .../include/boards/sparkfun_xrp_controller.h | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 src/boards/include/boards/sparkfun_xrp_controller.h diff --git a/src/boards/include/boards/sparkfun_xrp_controller.h b/src/boards/include/boards/sparkfun_xrp_controller.h new file mode 100644 index 000000000..70c2f13c7 --- /dev/null +++ b/src/boards/include/boards/sparkfun_xrp_controller.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- +// Board definition for the SparkFun XRP Controller +// +// This header may be included by other board headers as "boards/sparkfun_xrp_controller.h" + +// pico_cmake_set PICO_PLATFORM=rp2350 +// pico_cmake_set PICO_CYW43_SUPPORTED = 1 + +#ifndef _BOARDS_SPARKFUN_XRP_CONTROLLER_H +#define _BOARDS_SPARKFUN_XRP_CONTROLLER_H + +// For board detection +#define SPARKFUN_XRP_CONTROLLER + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 0 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 12 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 13 +#endif + +// --- LED --- +// no PICO_DEFAULT_LED_PIN - LED is on Wireless chip +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 37 +#endif + +// --- I2C --- Qwiic connector is on these pins +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 4 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 5 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +#ifndef CYW43_WL_GPIO_COUNT +#define CYW43_WL_GPIO_COUNT 3 +#endif + +#ifndef CYW43_WL_GPIO_LED_PIN +#define CYW43_WL_GPIO_LED_PIN 0 +#endif + +// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +// cyw43 SPI pins can't be changed at runtime +#ifndef CYW43_PIN_WL_DYNAMIC +#define CYW43_PIN_WL_DYNAMIC 0 +#endif + +// gpio pin to power up the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_REG_ON +#define CYW43_DEFAULT_PIN_WL_REG_ON 26u +#endif + +// gpio pin for spi data out to the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_DATA_OUT +#define CYW43_DEFAULT_PIN_WL_DATA_OUT 29u +#endif + +// gpio pin for spi data in from the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_DATA_IN +#define CYW43_DEFAULT_PIN_WL_DATA_IN 29u +#endif + +// gpio (irq) pin for the irq line from the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_HOST_WAKE +#define CYW43_DEFAULT_PIN_WL_HOST_WAKE 29u +#endif + +// gpio pin for the spi clock line to the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_CLOCK +#define CYW43_DEFAULT_PIN_WL_CLOCK 28u +#endif + +// gpio pin for the spi chip select to the cyw43 chip +#ifndef CYW43_DEFAULT_PIN_WL_CS +#define CYW43_DEFAULT_PIN_WL_CS 27u +#endif + +#endif From a45e1e46f55f97571249f956a9ed8e3a3e05a8d1 Mon Sep 17 00:00:00 2001 From: gsboylan Date: Tue, 18 Mar 2025 14:27:07 -0400 Subject: [PATCH 080/224] Add board file for Eelectronicparts Pico Mini in 2,4,8,16MB variants (#2346) Store page and pinout diagrams are here: https://www.eelectronicparts.com/products/rp2040-pro-mini-pico-development-board-for-raspberry-pi-dual-core-mciro-python --- .../boards/eelectronicparts_picomini_16mb.h | 86 +++++++++++++++++++ .../boards/eelectronicparts_picomini_2mb.h | 86 +++++++++++++++++++ .../boards/eelectronicparts_picomini_4mb.h | 86 +++++++++++++++++++ .../boards/eelectronicparts_picomini_8mb.h | 86 +++++++++++++++++++ 4 files changed, 344 insertions(+) create mode 100644 src/boards/include/boards/eelectronicparts_picomini_16mb.h create mode 100644 src/boards/include/boards/eelectronicparts_picomini_2mb.h create mode 100644 src/boards/include/boards/eelectronicparts_picomini_4mb.h create mode 100644 src/boards/include/boards/eelectronicparts_picomini_8mb.h diff --git a/src/boards/include/boards/eelectronicparts_picomini_16mb.h b/src/boards/include/boards/eelectronicparts_picomini_16mb.h new file mode 100644 index 000000000..52a530813 --- /dev/null +++ b/src/boards/include/boards/eelectronicparts_picomini_16mb.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- +// +//------------------------------------------------------------------------------------------ +// Board definition for the E Electronic Parts "Pico_Mini RP2040" +// +// This header may be included by other board headers as "boards/eelectronicparts_picomini_16mb.h" + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_EELECTRONICPARTS_PICOMINI_16MB_H +#define _BOARDS_EELECTRONICPARTS_PICOMINI_16MB_H + +// For board detection +#define EELECTRONICPARTS_PICOMINI_16MB + +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 16 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 17 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +// This board comes in 2MB, 4MB, 8MB, and 16MB variants +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif +// All boards have B1 RP2040 + +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/eelectronicparts_picomini_2mb.h b/src/boards/include/boards/eelectronicparts_picomini_2mb.h new file mode 100644 index 000000000..e0fcab1ff --- /dev/null +++ b/src/boards/include/boards/eelectronicparts_picomini_2mb.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- +// +//------------------------------------------------------------------------------------------ +// Board definition for the E Electronic Parts "Pico_Mini RP2040" +// +// This header may be included by other board headers as "boards/eelectronicparts_picomini_2mb.h" + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_EELECTRONICPARTS_PICOMINI_2MB_H +#define _BOARDS_EELECTRONICPARTS_PICOMINI_2MB_H + +// For board detection +#define EELECTRONICPARTS_PICOMINI_2MB + +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 16 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 17 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +// This board comes in 2MB, 4MB, 8MB, and 16MB variants +#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) +#endif +// All boards have B1 RP2040 + +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/eelectronicparts_picomini_4mb.h b/src/boards/include/boards/eelectronicparts_picomini_4mb.h new file mode 100644 index 000000000..132dc0c90 --- /dev/null +++ b/src/boards/include/boards/eelectronicparts_picomini_4mb.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- +// +//------------------------------------------------------------------------------------------ +// Board definition for the E Electronic Parts "Pico_Mini RP2040" +// +// This header may be included by other board headers as "boards/eelectronicparts_picomini_4mb.h" + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_EELECTRONICPARTS_PICOMINI_4MB_H +#define _BOARDS_EELECTRONICPARTS_PICOMINI_4MB_H + +// For board detection +#define EELECTRONICPARTS_PICOMINI_4MB + +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 16 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 17 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +// This board comes in 2MB, 4MB, 8MB, and 16MB variants +#define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) +#endif +// All boards have B1 RP2040 + +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif diff --git a/src/boards/include/boards/eelectronicparts_picomini_8mb.h b/src/boards/include/boards/eelectronicparts_picomini_8mb.h new file mode 100644 index 000000000..479e11050 --- /dev/null +++ b/src/boards/include/boards/eelectronicparts_picomini_8mb.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- +// +//------------------------------------------------------------------------------------------ +// Board definition for the E Electronic Parts "Pico_Mini RP2040" +// +// This header may be included by other board headers as "boards/eelectronicparts_picomini_8mb.h" + +// pico_cmake_set PICO_PLATFORM=rp2040 + +#ifndef _BOARDS_EELECTRONICPARTS_PICOMINI_8MB_H +#define _BOARDS_EELECTRONICPARTS_PICOMINI_8MB_H + +// For board detection +#define EELECTRONICPARTS_PICOMINI_8MB + +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 16 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 17 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 10 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 11 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 12 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 13 +#endif + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +// This board comes in 2MB, 4MB, 8MB, and 16MB variants +#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) +#endif +// All boards have B1 RP2040 + +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif From cc1ac399ed811c2895ba23447fa112707071f280 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 19 Mar 2025 05:28:15 +1100 Subject: [PATCH 081/224] Remove assignment of cyw43 last_size/header/backplane_window variables (#2306) They are never used by the cyw43-driver code, because `F1_OVERFLOW_CHANGE` is disabled. Signed-off-by: Damien George --- src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c b/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c index 787eeff5d..30b184736 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c @@ -451,13 +451,6 @@ static inline int _cyw43_write_reg(cyw43_int_t *self, uint32_t fn, uint32_t reg, uint32_t buf[2]; buf[0] = make_cmd(true, true, fn, reg, size); buf[1] = val; - if (fn == BACKPLANE_FUNCTION) { - // In case of f1 overflow - self->last_size = 8; - self->last_header[0] = buf[0]; - self->last_header[1] = buf[1]; - self->last_backplane_window = self->cur_backplane_window; - } if (fn == BACKPLANE_FUNCTION) { logic_debug_set(pin_BACKPLANE_WRITE, 1); From 3751bc5f98209ac4520e23f8f2df976b5a0f7545 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 18 Mar 2025 18:31:21 +0000 Subject: [PATCH 082/224] Check for the misuse of '#define PICO_RP2350B' in board headers (#2290) --- tools/check_board_header.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/check_board_header.py b/tools/check_board_header.py index c259c8131..4efeef4c7 100755 --- a/tools/check_board_header.py +++ b/tools/check_board_header.py @@ -391,6 +391,8 @@ def read_defines_from(header_file, defines_dict): chip = 'RP2350A' else: chip = 'RP2350B' + if 'PICO_RP2350B' in defines: + raise Exception("{} sets #define {} {} (should probably be #define {} {})".format(board_header, 'PICO_RP2350B', defines['PICO_RP2350B'].resolved_value, 'PICO_RP2350A', 1 - defines['PICO_RP2350B'].resolved_value)) if not board_header.endswith("amethyst_fpga.h"): if 'PICO_RP2350_A2_SUPPORTED' not in cmake_default_settings: raise Exception("{} uses chip {} but is missing a pico_cmake_set_default {} comment".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) From 6a564808797a4546001c4d8eb9f4b11d96073c2f Mon Sep 17 00:00:00 2001 From: David Dyck Date: Tue, 18 Mar 2025 08:39:10 -1000 Subject: [PATCH 083/224] Remove FIXME delete comment (#2341) Fixes #2337 per @kilograham --- src/boards/include/boards/amethyst_fpga.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/boards/include/boards/amethyst_fpga.h b/src/boards/include/boards/amethyst_fpga.h index ea6b9a2d4..190a07675 100644 --- a/src/boards/include/boards/amethyst_fpga.h +++ b/src/boards/include/boards/amethyst_fpga.h @@ -9,8 +9,6 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// FIXME delete this file before release (board file for Amethyst FPGA platform) - // pico_cmake_set PICO_PLATFORM=rp2350 #ifndef _BOARDS_AMETHYST_FPGA_H From 6d8588d62ca17e0c63865021187b26cb7f66dc92 Mon Sep 17 00:00:00 2001 From: Christopher Chamberlain Date: Tue, 18 Mar 2025 13:39:38 -0500 Subject: [PATCH 084/224] Adjust generated name to match pio_mov_status_type (#2324) The enum pio_mov_status_type expects the member name to be STATUS_IRQ_SET. --- tools/pioasm/c_sdk_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pioasm/c_sdk_output.cpp b/tools/pioasm/c_sdk_output.cpp index c1730db4c..d62d47c35 100644 --- a/tools/pioasm/c_sdk_output.cpp +++ b/tools/pioasm/c_sdk_output.cpp @@ -139,7 +139,7 @@ struct c_sdk_output : public output_format { const char *types[] = { "STATUS_TX_LESSTHAN", "STATUS_RX_LESSTHAN", - "STATUS_IRQ_INDEX", + "STATUS_IRQ_SET", }; if (program.mov_status_type < 0 || program.mov_status_type >= 3) { throw std::runtime_error("unknown mov_status type"); From 26e7dc5c48e15cd253ad5d8fb11a46cc83f943b8 Mon Sep 17 00:00:00 2001 From: Michael Brase Date: Tue, 18 Mar 2025 13:41:14 -0500 Subject: [PATCH 085/224] Add Bazel label flag for overriding tusb_config.h (#2264) This adds `//bazel/config:PICO_TINYUSB_CONFIG`, which is used to select which tusb_config.h gets linked into the tinyUSB port. This defaults to the tusb_config.h from the pico_stdio_usb (same as before), but allows Bazel users to override this config with their own. --- bazel/config/BUILD.bazel | 6 ++++++ src/rp2_common/pico_stdio_usb/BUILD.bazel | 7 +++---- src/rp2_common/tinyusb/BUILD.bazel | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index 4e622af5c..3d75654eb 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -186,6 +186,12 @@ int_flag( build_setting_default = 0, ) +# PICO_BAZEL_CONFIG: PICO_TINYUSB_CONFIG, [Bazel only] The library that provides TinyUSB config header (e.g. tusb_config.h), default=//src/rp2_common/pico_stdio_usb:tusb_config, group=build +label_flag( + name = "PICO_TINYUSB_CONFIG", + build_setting_default = "//src/rp2_common/pico_stdio_usb:tusb_config", +) + # PICO_BAZEL_CONFIG: PICO_TINYUSB_LIB, [Bazel only] The library that provides TinyUSB, default=@tinyusb//:tinyusb, group=build label_flag( name = "PICO_TINYUSB_LIB", diff --git a/src/rp2_common/pico_stdio_usb/BUILD.bazel b/src/rp2_common/pico_stdio_usb/BUILD.bazel index be9506554..1e8817142 100644 --- a/src/rp2_common/pico_stdio_usb/BUILD.bazel +++ b/src/rp2_common/pico_stdio_usb/BUILD.bazel @@ -24,6 +24,9 @@ cc_library( hdrs = ["include/tusb_config.h"], includes = ["include"], target_compatible_with = compatible_with_rp2(), + deps = [ + ":pico_stdio_usb_headers", + ], ) pico_sdk_define( @@ -43,10 +46,6 @@ cc_library( hdrs = ["include/pico/stdio_usb.h"], includes = ["include"], target_compatible_with = compatible_with_rp2(), - visibility = [ - ":__pkg__", - "//src/rp2_common/tinyusb:__pkg__", - ], deps = [ ":LIB_PICO_STDIO_USB", ":PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS", diff --git a/src/rp2_common/tinyusb/BUILD.bazel b/src/rp2_common/tinyusb/BUILD.bazel index 4accbb5ef..fcc0405a2 100644 --- a/src/rp2_common/tinyusb/BUILD.bazel +++ b/src/rp2_common/tinyusb/BUILD.bazel @@ -15,6 +15,7 @@ cc_library( includes = ["include"], target_compatible_with = compatible_with_rp2(), deps = [ + "//bazel/config:PICO_TINYUSB_CONFIG", "//src/common/pico_binary_info", "//src/common/pico_stdlib_headers", "//src/common/pico_sync", @@ -30,7 +31,6 @@ cc_library( "//src/rp2_common/pico_stdio_semihosting", "//src/rp2_common/pico_stdio_uart", "//src/rp2_common/pico_stdio_usb:pico_stdio_usb_headers", - "//src/rp2_common/pico_stdio_usb:tusb_config", "//src/rp2_common/pico_unique_id", ], ) From a995b975ec8c5cfce5a7e3e36a193baba829e473 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 18 Mar 2025 13:41:43 -0500 Subject: [PATCH 086/224] Missed doc change in #850 (#2302) --- src/rp2_common/hardware_gpio/include/hardware/gpio.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rp2_common/hardware_gpio/include/hardware/gpio.h b/src/rp2_common/hardware_gpio/include/hardware/gpio.h index bd1f4b687..f6f089523 100644 --- a/src/rp2_common/hardware_gpio/include/hardware/gpio.h +++ b/src/rp2_common/hardware_gpio/include/hardware/gpio.h @@ -782,6 +782,8 @@ static inline void gpio_add_raw_irq_handler(uint gpio, irq_handler_t handler) { * * This method removes such a callback, and enables the "default" callback for the specified GPIOs. * + * \note You should always use the same gpio_mask as you used when you added the raw IRQ handler. + * * @param gpio_mask a bit mask of the GPIO numbers that will now be passed to the default callback for this core * @param handler the handler to remove from the list of GPIO IRQ handlers for this core */ From 7d0f44b8b7dc5f401185815a97e064ac5471fd09 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 18 Mar 2025 18:43:03 +0000 Subject: [PATCH 087/224] Fix tools/build_all_headers.py to cope with chip-specific headers (#2292) --- tools/build_all_headers.py | 104 ++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 14 deletions(-) diff --git a/tools/build_all_headers.py b/tools/build_all_headers.py index fc047d999..a3e4f04b3 100755 --- a/tools/build_all_headers.py +++ b/tools/build_all_headers.py @@ -24,11 +24,15 @@ IGNORE_DIRS.add('rp2_common/cmsis') IGNORE_DIRS.add('rp2_common/pico_async_context') IGNORE_DIRS.add('rp2_common/pico_btstack') -IGNORE_DIRS.add('rp2_common/pico_cyw43_arch') +#IGNORE_DIRS.add('rp2_common/pico_cyw43_arch') IGNORE_DIRS.add('rp2_common/pico_cyw43_driver') IGNORE_DIRS.add('rp2_common/pico_lwip') IGNORE_DIRS.add('rp2_common/pico_stdio_semihosting') IGNORE_DIRS.add('rp2_common/pico_stdio_usb') +IGNORE_DIRS.add('rp2_common/pico_clib_interface') +IGNORE_DIRS.add('rp2_common/pico_mbedtls') + +SORT_HEADERS_BY_DIRECTORY = True # if False, sort by filename if len(sys.argv) != 3: print("Usage: {} top_dir output_header".format(os.path.basename(sys.argv[0]))) @@ -54,7 +58,12 @@ include_dirs.add(os.path.join(root, 'include')) dirs.remove('include') -include_files = list() +include_files_by_chip = { + 'none': list(), + 'rp2040': list(), + 'rp2350': list(), +} +all_include_files = set() include_locations = dict() for d in sorted(include_dirs): for root, dirs, files in os.walk(d): @@ -62,13 +71,69 @@ if f.endswith('.h'): include_file = os.path.relpath(os.path.join(root, f), d) include_path = os.path.relpath(d, top_dir) - if include_file in include_files: - raise Exception("Duplicate include file '{}' (found in both {} and {})".format(include_file, include_locations[include_file], include_path)) - include_files.append(include_file) + if 'rp2040/' in include_path: + include_files_by_chip['rp2040'].append(include_file) + elif 'rp2350/' in include_path: + include_files_by_chip['rp2350'].append(include_file) + else: + if include_file in include_files_by_chip['none']: + raise Exception("Duplicate include file '{}' (found in both {} and {})".format(include_file, include_locations[include_file], include_path)) + include_files_by_chip['none'].append(include_file) include_locations[include_file] = include_path + all_include_files.add(include_file) + +# figure out which includes are applicable to both chips +include_files_by_chip['both'] = [] +for f in include_files_by_chip['rp2040']: + if f in include_files_by_chip['rp2350']: + include_files_by_chip['both'].append(f) + include_locations[f] = include_locations[f].replace('rp2350/', 'rp2xxx/') +for f in include_files_by_chip['both']: + include_files_by_chip['rp2040'].remove(f) + include_files_by_chip['rp2350'].remove(f) + +if SORT_HEADERS_BY_DIRECTORY: + with open(output_header, 'w') as fh: + fh.write('''/* + * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ -with open(output_header, 'w') as fh: - fh.write('''/* +// This file is autogenerated, do not edit by hand + +''') + last_location = '' + for f in include_files_by_chip['none']: + if include_locations[f] != last_location: + fh.write('\n// {}\n'.format(include_locations[f])) + fh.write('#include "{}"\n'.format(f)) + last_location = include_locations[f] + for f in include_files_by_chip['both']: + if include_locations[f] != last_location: + fh.write('\n// {}\n'.format(include_locations[f])) + fh.write('#include "{}"\n'.format(f)) + last_location = include_locations[f] + if include_files_by_chip['rp2040']: + fh.write('\n#if PICO_RP2040\n') + for f in include_files_by_chip['rp2040']: + if include_locations[f] != last_location: + fh.write('\n// {}\n'.format(include_locations[f])) + fh.write('#include "{}"\n'.format(f)) + last_location = include_locations[f] + fh.write('\n#endif\n') + if include_files_by_chip['rp2350']: + fh.write('\n#if PICO_RP2350\n') + for f in include_files_by_chip['rp2350']: + if include_locations[f] != last_location: + fh.write('\n// {}\n'.format(include_locations[f])) + fh.write('#include "{}"\n'.format(f)) + last_location = include_locations[f] + fh.write('\n#endif\n') + fh.write('\n') +else: + with open(output_header, 'w') as fh: + fh.write('''/* * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause @@ -77,11 +142,22 @@ // This file is autogenerated, do not edit by hand ''') - last_location = '' - for f in include_files: - if include_locations[f] != last_location: - fh.write('\n// {}\n'.format(include_locations[f])) - fh.write('#include "{}"\n'.format(f)) - last_location = include_locations[f] - fh.write('\n') + last_define = None + for f in sorted(all_include_files, key=lambda x: os.path.split(x)): + if f in include_files_by_chip['rp2040']: + define = 'PICO_RP2040' + elif f in include_files_by_chip['rp2350']: + define = 'PICO_RP2350' + else: + define = None + if define != last_define: + if last_define is not None: + fh.write('#endif\n') + if define is not None: + fh.write('#if {}\n'.format(define)) + fh.write('#include "{}"\n'.format(f)) + last_define = define + if last_define is not None: + fh.write('#endif\n') + fh.write('\n') From ba936d3049267bb367ab877acd169a9979e33259 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 18 Mar 2025 14:06:40 -0500 Subject: [PATCH 088/224] pico_lwip_arch is actually what depends on pico_rand (#2303) --- src/rp2_common/pico_lwip/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rp2_common/pico_lwip/CMakeLists.txt b/src/rp2_common/pico_lwip/CMakeLists.txt index 1a523b781..e412f3727 100644 --- a/src/rp2_common/pico_lwip/CMakeLists.txt +++ b/src/rp2_common/pico_lwip/CMakeLists.txt @@ -299,8 +299,7 @@ if (EXISTS ${PICO_LWIP_PATH}/${LWIP_TEST_PATH}) pico_mirrored_target_link_libraries(pico_lwip_freertos INTERFACE pico_async_context_base pico_lwip - pico_lwip_contrib_freertos - pico_rand) + pico_lwip_contrib_freertos) pico_add_subdirectory(tools) pico_promote_common_scope_vars() From 3241bdc2f5906e15d1df741a68f8dc12c7fffe5a Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Tue, 18 Mar 2025 19:18:37 +0000 Subject: [PATCH 089/224] Fix PICO_PREVIOUS_PLATFORM error (#2357) `INTERNAL` should be the type of the variable, not placed at the end of the `set` invocation - it implies `FORCE` --- cmake/pico_pre_load_platform.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/pico_pre_load_platform.cmake b/cmake/pico_pre_load_platform.cmake index df9aebdd7..ea1127574 100644 --- a/cmake/pico_pre_load_platform.cmake +++ b/cmake/pico_pre_load_platform.cmake @@ -122,7 +122,7 @@ if (PICO_PREVIOUS_PLATFORM AND NOT PICO_PREVIOUS_PLATFORM STREQUAL PICO_PLATFORM The best practice is to use separate build directories for different platforms.") endif() set(PICO_PLATFORM ${PICO_PLATFORM} CACHE STRING "PICO Build platform (e.g. rp2040, rp2350, rp2350-riscv, host)" FORCE) -set(PICO_PREVIOUS_PLATFORM ${PICO_PLATFORM} CACHE STRING "Saved PICO Build platform (e.g. rp2040, rp2350, rp2350-riscv, host)" INTERNAL) +set(PICO_PREVIOUS_PLATFORM ${PICO_PLATFORM} CACHE INTERNAL "Saved PICO Build platform (e.g. rp2040, rp2350, rp2350-riscv, host)") # PICO_CMAKE_CONFIG: PICO_CMAKE_PRELOAD_PLATFORM_FILE, Custom CMake file to use to set up the platform environment, type=string, group=build set(PICO_CMAKE_PRELOAD_PLATFORM_FILE ${PICO_CMAKE_PRELOAD_PLATFORM_FILE} CACHE INTERNAL "") From 645b33c31f4a3624b1c89c259697f87cd5db286e Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 19 Mar 2025 16:03:53 +0000 Subject: [PATCH 090/224] Update hellbender_0001.h (#2359) Replace the incorrect `#define PICO_RP2350B 1` with the correct `#define PICO_RP2350A 0` Fixes #2286 --- src/boards/include/boards/hellbender_0001.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boards/include/boards/hellbender_0001.h b/src/boards/include/boards/hellbender_0001.h index 9091f9124..9f43803e6 100644 --- a/src/boards/include/boards/hellbender_0001.h +++ b/src/boards/include/boards/hellbender_0001.h @@ -138,7 +138,7 @@ #define HELLBENDER_0001_BLACKBOX_FLASH_SIZE_BYTES (16 * 1024 * 1024) // --- RP2350 VARIANT --- -#define PICO_RP2350B 1 +#define PICO_RP2350A 0 // pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 #ifndef PICO_RP2350_A2_SUPPORTED From 005759d7914d5a2a78369109ba6d3394e3b6d285 Mon Sep 17 00:00:00 2001 From: David Dyck Date: Wed, 19 Mar 2025 11:16:43 -1000 Subject: [PATCH 091/224] Fix #2253 cybt_printf by wrapping with NDEBUG (#2323) Observe that src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus_driver.c wraps the definition of cybt_printf with #ifndef NDEBUG Apply this to src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c Co-authored-by: David Dyck --- .../pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c index b464b3f78..9b454b6d5 100644 --- a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c +++ b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c @@ -39,7 +39,11 @@ extern const int brcm_patch_ram_length; #else #define cybt_debug(format, ...) ((void)0) #endif +#ifndef NDEBUG #define cybt_printf(format, args...) printf("%d.%d: " format, (int)cyw43_hal_ticks_ms() / 1000, (int)cyw43_hal_ticks_ms() % 1000, ## args) +#else +#define cybt_printf(...) +#endif #define ROUNDUP(x, a) ((((x) + ((a) - 1)) / (a)) * (a)) #define ROUNDDN(x, a) ((x) & ~((a) - 1)) From 332eb5345b5ab800139630c655aaa987f4498e85 Mon Sep 17 00:00:00 2001 From: Michael Brase Date: Sat, 22 Mar 2025 12:49:58 -0500 Subject: [PATCH 092/224] Add new feature defines to pico_stdio_usb (#2296) This change adds the following to pico_stdio_usb: - `PICO_STDIO_USB_ENABLE_IRQ_BACKGROUND_TASK` - `PICO_STDIO_USB_ENABLE_TINYUSB_INIT` - `PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS` These defines replace some ifdefs that were previously gated by the `LIB_TINYUSB_DEVICE` define and will allow finer grained control. All of these defines default to 1 if LIB_TINYUSB_DEVICE is not defined and 0 if LIB_TINYUSB_DEVICE is defined, which should preserve the old behavior. --- .../pico_stdio_usb/include/pico/stdio_usb.h | 35 +++++++++++++++++-- src/rp2_common/pico_stdio_usb/stdio_usb.c | 11 +++--- .../pico_stdio_usb/stdio_usb_descriptors.c | 7 ++-- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index b1cb0354c..54f73beea 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -44,10 +44,30 @@ // this variable is no longer set by default (one is claimed dynamically), but will be respected if specified #endif +// PICO_CONFIG: PICO_STDIO_USB_ENABLE_IRQ_BACKGROUND_TASK, Enable/disable the use of a background task to call tud_task(), type=bool, default=1 if the application is not using tinyUSB directly, group=pico_stdio_usb +#ifndef PICO_STDIO_USB_ENABLE_IRQ_BACKGROUND_TASK +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_ENABLE_IRQ_BACKGROUND_TASK 1 +#else +#define PICO_STDIO_USB_ENABLE_IRQ_BACKGROUND_TASK 0 +#endif +#endif + +// PICO_CONFIG: PICO_STDIO_USB_ENABLE_TINYUSB_INIT, Enable/disable calling tinyUSB tusb_init() during initialization, type=bool, default=1 if the application is not using tinyUSB directly, group=pico_stdio_usb +#ifndef PICO_STDIO_USB_ENABLE_TINYUSB_INIT +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_ENABLE_TINYUSB_INIT 1 +#else +#define PICO_STDIO_USB_ENABLE_TINYUSB_INIT 0 +#endif +#endif + // PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE), type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb #ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE -#if !defined(LIB_TINYUSB_HOST) && !defined(LIB_TINYUSB_DEVICE) +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE #define PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE 1 +#else +#define PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE 0 #endif #endif @@ -91,8 +111,10 @@ // PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb #ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE -#if !defined(LIB_TINYUSB_HOST) && !defined(LIB_TINYUSB_DEVICE) +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE #define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 +#else +#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0 #endif #endif @@ -116,6 +138,15 @@ #define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 #endif +// PICO_CONFIG: PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS, Defines the default USB descriptors needed for USB communication, type=bool, default=1 if the application is not using tinyUSB directly, group=pico_stdio_usb +#ifndef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS +#if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE +#define PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS 1 +#else +#define PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS 0 +#endif +#endif + // PICO_CONFIG: PICO_STDIO_USB_CONNECTION_WITHOUT_DTR, Disable use of DTR for connection checking meaning connection is assumed to be valid, type=bool, default=0, group=pico_stdio_usb #ifndef PICO_STDIO_USB_CONNECTION_WITHOUT_DTR #define PICO_STDIO_USB_CONNECTION_WITHOUT_DTR 0 diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb.c b/src/rp2_common/pico_stdio_usb/stdio_usb.c index 0f9e3188d..798624095 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb.c @@ -26,8 +26,7 @@ static void (*chars_available_callback)(void*); static void *chars_available_param; #endif -// when tinyusb_device is explicitly linked we do no background tud processing -#if !LIB_TINYUSB_DEVICE +#if PICO_STDIO_USB_ENABLE_IRQ_BACKGROUND_TASK // if this crit_sec is initialized, we are not in periodic timer mode, and must make sure // we don't either create multiple one shot timers, or miss creating one. this crit_sec // is used to protect the one_shot_timer_pending flag @@ -197,8 +196,8 @@ bool stdio_usb_init(void) { bi_decl_if_func_used(bi_program_feature("USB stdin / stdout")); #endif -#if !defined(LIB_TINYUSB_DEVICE) - // initialize TinyUSB, as user hasn't explicitly linked it +#if PICO_STDIO_USB_ENABLE_TINYUSB_INIT + // initialize TinyUSB tusb_init(); #else assert(tud_inited()); // we expect the caller to have initialized if they are using TinyUSB @@ -206,7 +205,7 @@ bool stdio_usb_init(void) { if (!mutex_is_initialized(&stdio_usb_mutex)) mutex_init(&stdio_usb_mutex); bool rc = true; -#if !LIB_TINYUSB_DEVICE +#if PICO_STDIO_USB_ENABLE_IRQ_BACKGROUND_TASK #ifdef PICO_STDIO_USB_LOW_PRIORITY_IRQ user_irq_claim(PICO_STDIO_USB_LOW_PRIORITY_IRQ); #else @@ -265,7 +264,7 @@ bool stdio_usb_deinit(void) { sleep_ms(PICO_STDIO_USB_DEINIT_DELAY_MS); #endif -#if !LIB_TINYUSB_DEVICE +#if PICO_STDIO_USB_ENABLE_IRQ_BACKGROUND_TASK if (irq_has_shared_handler(USBCTRL_IRQ)) { spin_lock_unclaim(spin_lock_get_num(one_shot_timer_crit_sec.spin_lock)); critical_section_deinit(&one_shot_timer_crit_sec); diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c index 2f6e75877..b805e8fb2 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c @@ -26,11 +26,12 @@ * THE SOFTWARE. */ -#if !defined(LIB_TINYUSB_HOST) && !defined(LIB_TINYUSB_DEVICE) - -#include "tusb.h" +#include "pico/stdio_usb.h" #include "pico/stdio_usb/reset_interface.h" #include "pico/unique_id.h" +#include "tusb.h" + +#if PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS #ifndef USBD_VID #define USBD_VID (0x2E8A) // Raspberry Pi From bbb94e51f9bfc36d10412b62c83358e789c08f49 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Sat, 22 Mar 2025 22:59:05 +0000 Subject: [PATCH 093/224] Add rom_pick_ab_update_partition function (#2182) --- src/BUILD.bazel | 1 + src/rp2_common/hardware_rcp/BUILD.bazel | 13 +++ .../hardware_rcp/include/hardware/rcp.h | 9 +- src/rp2_common/pico_bootrom/BUILD.bazel | 1 + src/rp2_common/pico_bootrom/bootrom.c | 88 +++++++++++++++++++ .../pico_bootrom/include/pico/bootrom.h | 27 ++++++ 6 files changed, 136 insertions(+), 3 deletions(-) diff --git a/src/BUILD.bazel b/src/BUILD.bazel index 58d564ba2..a397b486507 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -19,6 +19,7 @@ alias( "//src/rp2_common/boot_bootrom_headers:__pkg__", "//src/rp2_common/hardware_boot_lock:__pkg__", "//src/rp2_common/pico_flash:__pkg__", + "//src/rp2_common/hardware_rcp:__pkg__", ], ) diff --git a/src/rp2_common/hardware_rcp/BUILD.bazel b/src/rp2_common/hardware_rcp/BUILD.bazel index 750ae819e..6f8be1be3 100644 --- a/src/rp2_common/hardware_rcp/BUILD.bazel +++ b/src/rp2_common/hardware_rcp/BUILD.bazel @@ -2,6 +2,19 @@ load("//bazel:defs.bzl", "compatible_with_rp2") package(default_visibility = ["//visibility:public"]) +# Picotool needs this (transitively through +# //src/rp2_common/pico_bootrom:pico_bootrom_headers), so we can't strictly +# constrain compatibility. +cc_library( + name = "hardware_rcp_headers", + hdrs = ["include/hardware/rcp.h"], + includes = ["include"], + visibility = ["//src/rp2_common/pico_bootrom:__pkg__"], + deps = [ + "//src:pico_platform_internal", + ], +) + cc_library( name = "hardware_rcp", hdrs = ["include/hardware/rcp.h"], diff --git a/src/rp2_common/hardware_rcp/include/hardware/rcp.h b/src/rp2_common/hardware_rcp/include/hardware/rcp.h index b75f182d9..64c88c5a1 100644 --- a/src/rp2_common/hardware_rcp/include/hardware/rcp.h +++ b/src/rp2_common/hardware_rcp/include/hardware/rcp.h @@ -15,13 +15,15 @@ */ // ---------------------------------------------------------------------------- -// RCP instructions (this header is Arm-only) -#if defined(PICO_RP2350) && !defined(__riscv) +// RCP masks +#if !PICO_RP2040 #define RCP_MASK_TRUE _u(0xa500a500) #define RCP_MASK_FALSE _u(0x00c300c3) #define RCP_MASK_INTXOR _u(0x96009600) +// RCP instructions (these instructions are Arm-only) +#if HAS_REDUNDANCY_COPROCESSOR // ---------------------------------------------------------------------------- // Macros and inline functions for use in C files #ifndef __ASSEMBLER__ @@ -994,7 +996,8 @@ rcp_switch_u8_to_ch_cl rcp_canary_check_nodelay_impl \tag, \x cdp p7, #0, c0, c0, c0, #1 .endm -#endif // !__riscv +#endif // HAS_REDUNDANCY_COPROCESSOR +#endif // !PICO_RP2040 #endif // __ASSEMBLER__ // ---------------------------------------------------------------------------- diff --git a/src/rp2_common/pico_bootrom/BUILD.bazel b/src/rp2_common/pico_bootrom/BUILD.bazel index 53a24b105..1463216d3 100644 --- a/src/rp2_common/pico_bootrom/BUILD.bazel +++ b/src/rp2_common/pico_bootrom/BUILD.bazel @@ -18,6 +18,7 @@ cc_library( "//src/rp2_common/boot_bootrom_headers", "//src/rp2_common/hardware_boot_lock:hardware_boot_lock_headers", "//src/rp2_common/pico_flash:pico_flash_headers", + "//src/rp2_common/hardware_rcp:hardware_rcp_headers", ] + select({ "//bazel/constraint:host": ["//src/host/hardware_sync"], "//conditions:default": ["//src/rp2_common/hardware_sync"], diff --git a/src/rp2_common/pico_bootrom/bootrom.c b/src/rp2_common/pico_bootrom/bootrom.c index 1120f006a..cedc27fc8 100644 --- a/src/rp2_common/pico_bootrom/bootrom.c +++ b/src/rp2_common/pico_bootrom/bootrom.c @@ -7,6 +7,9 @@ #include "pico/bootrom.h" #include "boot/picoboot.h" #include "boot/picobin.h" +#if !PICO_RP2040 +#include "hardware/rcp.h" +#endif /// \tag::table_lookup[] @@ -108,4 +111,89 @@ int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32 } return PICO_ERROR_INSUFFICIENT_RESOURCES; } + +int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num) { +#if PICO_RP2350 + // Generated from adding the following code into the bootrom + // scan_workarea_t* scan_workarea = (scan_workarea_t*)workarea; + // printf("VERSION_DOWNGRADE_ERASE_ADDR %08x\n", &(always->zero_init.version_downgrade_erase_flash_addr)); + // printf("TBYB_FLAG_ADDR %08x\n", &(always->zero_init.tbyb_flag_flash_addr)); + // printf("IMAGE_DEF_VERIFIED %08x\n", (uint32_t)&(scan_workarea->parsed_block_loops[0].image_def.core.verified) - (uint32_t)scan_workarea); + // printf("IMAGE_DEF_TBYB_FLAGGED %08x\n", (uint32_t)&(scan_workarea->parsed_block_loops[0].image_def.core.tbyb_flagged) - (uint32_t)scan_workarea); + // printf("IMAGE_DEF_BASE %08x\n", (uint32_t)&(scan_workarea->parsed_block_loops[0].image_def.core.enclosing_window.base) - (uint32_t)scan_workarea); + // printf("IMAGE_DEF_REL_BLOCK_OFFSET %08x\n", (uint32_t)&(scan_workarea->parsed_block_loops[0].image_def.core.window_rel_block_offset) - (uint32_t)scan_workarea); + #define VERSION_DOWNGRADE_ERASE_ADDR *(uint32_t*)0x400e0338 + #define TBYB_FLAG_ADDR *(uint32_t*)0x400e0348 + #define IMAGE_DEF_VERIFIED(scan_workarea) *(uint32_t*)(0x64 + (uint32_t)scan_workarea) + #define IMAGE_DEF_TBYB_FLAGGED(scan_workarea) *(bool*)(0x4c + (uint32_t)scan_workarea) + #define IMAGE_DEF_BASE(scan_workarea) *(uint32_t*)(0x54 + (uint32_t)scan_workarea) + #define IMAGE_DEF_REL_BLOCK_OFFSET(scan_workarea) *(uint32_t*)(0x5c + (uint32_t)scan_workarea) +#else + // Prevent linting errors + #define VERSION_DOWNGRADE_ERASE_ADDR *(uint32_t*)NULL + #define TBYB_FLAG_ADDR *(uint32_t*)NULL + #define IMAGE_DEF_VERIFIED(scan_workarea) *(uint32_t*)(NULL + (uint32_t)scan_workarea) + #define IMAGE_DEF_TBYB_FLAGGED(scan_workarea) *(bool*)(NULL + (uint32_t)scan_workarea) + #define IMAGE_DEF_BASE(scan_workarea) *(uint32_t*)(NULL + (uint32_t)scan_workarea) + #define IMAGE_DEF_REL_BLOCK_OFFSET(scan_workarea) *(uint32_t*)(NULL + (uint32_t)scan_workarea) + + panic_unsupported(); +#endif + + uint32_t flash_update_base = 0; + bool tbyb_boot = false; + uint32_t saved_erase_addr = 0; + if (rom_get_last_boot_type() == BOOT_TYPE_FLASH_UPDATE) { + // For a flash update boot, get the flash update base + boot_info_t boot_info = {}; + int ret = rom_get_boot_info(&boot_info); + if (ret) { + flash_update_base = boot_info.reboot_params[0]; + if (boot_info.tbyb_and_update_info & BOOT_TBYB_AND_UPDATE_FLAG_BUY_PENDING) { + // A buy is pending, so the main software has not been bought + tbyb_boot = true; + // Save the erase address, as this will be overwritten by rom_pick_ab_partition + saved_erase_addr = VERSION_DOWNGRADE_ERASE_ADDR; + } + } + } + + int rc = rom_pick_ab_partition((uint8_t*)workarea_base, workarea_size, partition_a_num, flash_update_base); + + if (IMAGE_DEF_VERIFIED(workarea_base) != RCP_MASK_TRUE) { + // Chosen partition failed verification + return BOOTROM_ERROR_NOT_FOUND; + } + + if (IMAGE_DEF_TBYB_FLAGGED(workarea_base)) { + // The chosen partition is TBYB + if (tbyb_boot) { + // The boot partition is also TBYB - cannot update both, so prioritise boot partition + // Restore the erase address saved earlier + VERSION_DOWNGRADE_ERASE_ADDR = saved_erase_addr; + return BOOTROM_ERROR_NOT_PERMITTED; + } else { + // Update the tbyb flash address, so that explicit_buy will clear the flag for the chosen partition + TBYB_FLAG_ADDR = + IMAGE_DEF_BASE(workarea_base) + + IMAGE_DEF_REL_BLOCK_OFFSET(workarea_base) + 4; + } + } else { + // The chosen partition is not TBYB + if (tbyb_boot && saved_erase_addr) { + // The boot partition was TBYB, and requires an erase + if (VERSION_DOWNGRADE_ERASE_ADDR) { + // But both the chosen partition requires an erase too + // As before, prioritise the boot partition, and restore it's saved erase_address + VERSION_DOWNGRADE_ERASE_ADDR = saved_erase_addr; + return BOOTROM_ERROR_NOT_PERMITTED; + } else { + // The chosen partition doesn't require an erase, so we're fine + VERSION_DOWNGRADE_ERASE_ADDR = saved_erase_addr; + } + } + } + + return rc; +} #endif \ No newline at end of file diff --git a/src/rp2_common/pico_bootrom/include/pico/bootrom.h b/src/rp2_common/pico_bootrom/include/pico/bootrom.h index bb5b8ba2f..76ef30300 100644 --- a/src/rp2_common/pico_bootrom/include/pico/bootrom.h +++ b/src/rp2_common/pico_bootrom/include/pico/bootrom.h @@ -749,6 +749,9 @@ static inline int rom_load_partition_table(uint8_t *workarea_base, uint32_t work * * NOTE: This method does not look at owner partitions, only the A partition passed and it's corresponding B partition. * + * NOTE: You should not call this method directly when performing a Flash Update Boot before calling `explicit_buy`, as it may prevent + * any version downgrade from occuring - instead \see rom_pick_ab_update_partition() which wraps this function. + * * \param workarea_base base address of work area * \param workarea_size size of work area * \param partition_a_num the A partition of the pair @@ -1091,6 +1094,30 @@ static inline int rom_get_last_boot_type(void) { */ int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32_t permissions); +/*! \brief Pick A/B partition without disturbing any in progress update or TBYB boot + * \ingroup pico_bootrom + * + * This will call `rom_pick_ab_partition` using the `flash_update_boot_window_base` from the current boot, while performing extra checks to prevent disrupting + * a main image TBYB boot. It requires the same minimum workarea size as `rom_pick_ab_partition`. + * \see rom_pick_ab_partition() + * + * For example, if an `explicit_buy` is pending then calling `pick_ab_partition` would normally clear the saved flash erase address for the version downgrade, + * so the required erase of the other partition would not occur when `explicit_buy` is called - this function saves and restores that address to prevent this + * issue, and returns `BOOTROM_ERROR_NOT_PERMITTED` if the partition chosen by `pick_ab_partition` also requires a flash erase version downgrade (as you can't + * erase 2 partitions with one `explicit_buy` call). + * + * It also checks that the chosen partition contained a valid image (e.g. a signed image when using secure boot), and returns `BOOTROM_ERROR_NOT_FOUND` + * if it does not. + * + * \param workarea_base base address of work area + * \param workarea_size size of work area + * \param partition_a_num the A partition of the pair + * \return >= 0 the partition number picked + * BOOTROM_ERROR_NOT_PERMITTED if not possible to do an update correctly, e.g. if both main image and data image are TBYB + * BOOTROM_ERROR_NOT_FOUND if the chosen partition failed verification + */ +int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num); + #endif #ifdef __cplusplus From f81851a2cbc398e10f6162405faef98c6d302ce0 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Sat, 22 Mar 2025 23:22:37 +0000 Subject: [PATCH 094/224] Throw a warning when using the example signing/encryption keys (#2352) * Raise a warning when using the example signing/encryption keys This is automatically disabled for pico-examples, and can be manually disabled by setting PICO_ALLOW_EXAMPLE_KEYS --- tools/CMakeLists.txt | 28 ++++++++++++++++++++++++++++ tools/example_keys/private.pem | 8 ++++++++ tools/example_keys/privateaes.bin | Bin 0 -> 128 bytes 3 files changed, 36 insertions(+) create mode 100644 tools/example_keys/private.pem create mode 100644 tools/example_keys/privateaes.bin diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index c2fbe3281..7d68c9107 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -153,6 +153,28 @@ function(picotool_check_configurable TARGET) endif() endfunction() +# Compare 2 key files, used by picotool_check_default_keys +function(picotool_compare_keys TARGET KEY DEFAULT TYPE) + if (KEY) + execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files "${KEY}" "${PICO_SDK_PATH}/tools/example_keys/${DEFAULT}" + RESULT_VARIABLE compare_result + ) + if(compare_result EQUAL 0) + message(WARNING "${TARGET} is using a default ${TYPE} key - this must be changed before production") + endif() + endif() +endfunction() + +# Check if default signing/encryption keys are being used +function(picotool_check_default_keys TARGET) + get_target_property(picotool_sigfile ${TARGET} PICOTOOL_SIGFILE) + picotool_compare_keys(${TARGET} ${picotool_sigfile} private.pem "signing") + get_target_property(picotool_aesfile ${TARGET} PICOTOOL_AESFILE) + picotool_compare_keys(${TARGET} ${picotool_aesfile} privateaes.bin "encryption") + get_target_property(picotool_enc_sigfile ${TARGET} PICOTOOL_ENC_SIGFILE) + picotool_compare_keys(${TARGET} ${picotool_enc_sigfile} private.pem "encrypted signing") +endfunction() + # Generate pio header and include it in the build # PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build function(pico_generate_pio_header TARGET) @@ -449,6 +471,12 @@ function(picotool_postprocess_binary TARGET) set_target_properties(${TARGET} PROPERTIES PICOTOOL_PROCESSING_CONFIGURED true ) + + # PICO_CMAKE_CONFIG: PICO_ALLOW_EXAMPLE_KEYS, Don't raise a warning when using default signing/encryption keys, type=bool, default=0, group=build + if (NOT PICO_ALLOW_EXAMPLE_KEYS) + picotool_check_default_keys(${TARGET}) + endif() + # Read target properties get_target_property(picotool_sign_output ${TARGET} PICOTOOL_SIGN_OUTPUT) if (picotool_sign_output) diff --git a/tools/example_keys/private.pem b/tools/example_keys/private.pem new file mode 100644 index 000000000..bf777d897 --- /dev/null +++ b/tools/example_keys/private.pem @@ -0,0 +1,8 @@ +-----BEGIN EC PARAMETERS----- +BgUrgQQACg== +-----END EC PARAMETERS----- +-----BEGIN EC PRIVATE KEY----- +MHQCAQEEIAXAdiilH8wT07TESUzWPt+BY9+NcchvYU3xbnpK+CBNoAcGBSuBBAAK +oUQDQgAEYYJtMQFGW4AB94tU3u/Qir5sRcYjBYMqCa+8gxsYd9OwMS3dqWKsnVBz +dyy7bFWdJzXDMb9o20xRRd57Q9xSYw== +-----END EC PRIVATE KEY----- diff --git a/tools/example_keys/privateaes.bin b/tools/example_keys/privateaes.bin new file mode 100644 index 0000000000000000000000000000000000000000..21a47756d7b947b1e8a7c3a74b0ef5edc3984f87 GIT binary patch literal 128 zcmV-`0Du26w%8aWE_-~VvA2+WFG12#wF6?-Aq=&R7v|M#4Tp^@bfmhu6m^K31uZgB z!8HkZyKTa|re2kzDKa!$EYtX1;$I`{C#21=j`VJnh8dGO*q3D~C0Auh1OCS8i=%!k iQ-EmQ1rQg?!>9y}60g}wscn#avtv&-#Q?Q&bmp4XE<5l5 literal 0 HcmV?d00001 From e43b7534ba5bea44ca2129995abf0e72bc715b92 Mon Sep 17 00:00:00 2001 From: Michael Brase Date: Sat, 22 Mar 2025 18:47:40 -0500 Subject: [PATCH 095/224] Add new stdio_usb_call_chars_available_callback() function (#2300) When the user links in tinyUSB directly, the pico_stdio_usb library disables some of its functionality, including its built-in background processing thread. The user can implement their own background thread in order to continue using the stdio functionality, except that there is no wey to trigger the registered chars_available_callback. This commit adds a new `stdio_usb_run_chars_available_callback()` method to allow user's background threads to run the callback. --- .../pico_stdio_usb/include/pico/stdio_usb.h | 13 +++++++++++++ src/rp2_common/pico_stdio_usb/stdio_usb.c | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index 54f73beea..c487f96ab 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -192,6 +192,19 @@ bool stdio_usb_deinit(void); * \return true if stdio is connected over CDC */ bool stdio_usb_connected(void); + +#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK +/*! \brief Explicitly calls the registered USB stdio chars_available_callback + * \ingroup pico_stdio_usb + * + * \ref This method is normally called by the internal USB stdio background thread when there is new USB CDC + * data available to read. However, if the internal background thread is disabled (e.g. when the user + * directly links tinyUSB), the user will need to implement their own background thread and call this + * method directly. + */ +void stdio_usb_call_chars_available_callback(void); +#endif + #ifdef __cplusplus } #endif diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb.c b/src/rp2_common/pico_stdio_usb/stdio_usb.c index 798624095..61aa7089b 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb.c @@ -170,6 +170,12 @@ void stdio_usb_set_chars_available_callback(void (*fn)(void*), void *param) { chars_available_callback = fn; chars_available_param = param; } + +void stdio_usb_call_chars_available_callback(void) { + if (chars_available_callback) { + chars_available_callback(chars_available_param); + } +} #endif stdio_driver_t stdio_usb = { From fa94f6448a274b610f63a58d2ab7065ef98530d1 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Mon, 24 Mar 2025 22:28:59 +0000 Subject: [PATCH 096/224] Look for PICO_CONFIG: entries in .S files too (#2368) (and fix the errors that this found) --- src/rp2_common/pico_divider/divider_hardware.S | 14 ++++++++++---- tools/extract_configs.py | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/rp2_common/pico_divider/divider_hardware.S b/src/rp2_common/pico_divider/divider_hardware.S index cb3f54162..049c6f755 100644 --- a/src/rp2_common/pico_divider/divider_hardware.S +++ b/src/rp2_common/pico_divider/divider_hardware.S @@ -12,21 +12,27 @@ #warning "Building divider_hardware.S on a platform with no SIO divider hardware" #endif -// PICO_CONFIG: PICO_DIVIDER_DISABLE_INTERRUPTS, Disable interrupts around division such that divider state need not be saved/restored in exception handlers, default=0, group=pico_divider +// PICO_CONFIG: PICO_DIVIDER_DISABLE_INTERRUPTS, Disable interrupts around division such that divider state need not be saved/restored in exception handlers, default=0, type=bool, group=pico_divider +#if 0 // make tooling checks happy +#define PICO_DIVIDER_DISABLE_INTERRUPTS 0 +#endif -// PICO_CONFIG: PICO_DIVIDER_CALL_IDIV0, Whether 32 bit division by zero should call __aeabi_idiv0, default=1, group=pico_divider +// PICO_CONFIG: PICO_DIVIDER_CALL_IDIV0, Whether 32 bit division by zero should call __aeabi_idiv0, default=1, type=bool, group=pico_divider #ifndef PICO_DIVIDER_CALL_IDIV0 #define PICO_DIVIDER_CALL_IDIV0 1 #endif -// PICO_CONFIG: PICO_DIVIDER_CALL_IDIV0, Whether 64 bit division by zero should call __aeabi_ldiv0, default=1, group=pico_divider +// PICO_CONFIG: PICO_DIVIDER_CALL_LDIV0, Whether 64 bit division by zero should call __aeabi_ldiv0, default=1, type=bool, group=pico_divider #ifndef PICO_DIVIDER_CALL_LDIV0 #define PICO_DIVIDER_CALL_LDIV0 1 #endif pico_default_asm_setup -// PICO_CONFIG: PICO_DIVIDER_IN_RAM, Whether divider functions should be placed in RAM, default=0, group=pico_divider +// PICO_CONFIG: PICO_DIVIDER_IN_RAM, Whether divider functions should be placed in RAM, default=0, type=bool, group=pico_divider +#if 0 // make tooling checks happy +#define PICO_DIVIDER_IN_RAM 0 +#endif .macro div_section name #if PICO_DIVIDER_IN_RAM .section RAM_SECTION_NAME(\name), "ax" diff --git a/tools/extract_configs.py b/tools/extract_configs.py index 30705d5cb..81f57625a 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -133,12 +133,12 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): -# Scan all .c and .h files in the specific path, recursively. +# Scan all .c and .h and .S files in the specific path, recursively. for dirpath, dirnames, filenames in os.walk(scandir): for filename in filenames: file_ext = os.path.splitext(filename)[1] - if file_ext in ('.c', '.h'): + if file_ext in ('.c', '.h', '.S'): file_path = os.path.join(dirpath, filename) applicable = "all" for chip in (*CHIP_NAMES, "host"): From 39fafaa4344a795c70e15568f8032ac656fb1b10 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 25 Mar 2025 13:14:28 -0500 Subject: [PATCH 097/224] Add SPARE_IRQs to the SVD (#2271) * Add SPARE_IRQ to RP2350 SVD (note not having an `` or one with a size of zero is not a legal SVD, so including something hopefully harmless * Add SPARE_IRQ definitions to RP2040 intctrl.h, and add assertions on competing #defines as these were called USER_IRQs in the SDK 1.x * Add SPAREIRQ_IRQ to rp2040 assembler, and fix name on rp2350 - this is backwards incompatible, but unlikely used * add SPARE_IRQs to RP2040 svd too --- src/rp2040/hardware_regs/RP2040.svd | 33 +++++++++++++++++ .../include/hardware/regs/intctrl.h | 18 ++++++++++ src/rp2350/hardware_regs/RP2350.svd | 35 +++++++++++++++++++ .../include/hardware/regs/intctrl.h | 12 +++---- src/rp2_common/hardware_irq/irq.c | 6 ++++ 5 files changed, 98 insertions(+), 6 deletions(-) diff --git a/src/rp2040/hardware_regs/RP2040.svd b/src/rp2040/hardware_regs/RP2040.svd index 2bac8265d..50a5a93f7 100644 --- a/src/rp2040/hardware_regs/RP2040.svd +++ b/src/rp2040/hardware_regs/RP2040.svd @@ -51022,5 +51022,38 @@ SPDX-License-Identifier: BSD-3-Clause + + SPARE_IRQ + 0x00000000 + + 0 + 4 + reserved + + + SPARE_IRQ_0 + 26 + + + SPARE_IRQ_1 + 27 + + + SPARE_IRQ_2 + 28 + + + SPARE_IRQ_3 + 29 + + + SPARE_IRQ_4 + 30 + + + SPARE_IRQ_5 + 31 + + diff --git a/src/rp2040/hardware_regs/include/hardware/regs/intctrl.h b/src/rp2040/hardware_regs/include/hardware/regs/intctrl.h index 3190b413d..71c6eb90b 100644 --- a/src/rp2040/hardware_regs/include/hardware/regs/intctrl.h +++ b/src/rp2040/hardware_regs/include/hardware/regs/intctrl.h @@ -39,6 +39,12 @@ #define I2C0_IRQ 23 #define I2C1_IRQ 24 #define RTC_IRQ 25 +#define SPARE_IRQ_0 26 +#define SPARE_IRQ_1 27 +#define SPARE_IRQ_2 28 +#define SPARE_IRQ_3 29 +#define SPARE_IRQ_4 30 +#define SPARE_IRQ_5 31 #else /** * \brief Interrupt numbers on RP2040 (used as typedef \ref irq_num_t) @@ -71,6 +77,12 @@ typedef enum irq_num_rp2040 { I2C0_IRQ = 23, ///< Select I2C0's IRQ output I2C1_IRQ = 24, ///< Select I2C1's IRQ output RTC_IRQ = 25, ///< Select RTC's IRQ output + SPARE_IRQ_0 = 26, ///< Select SPARE IRQ 0 + SPARE_IRQ_1 = 27, ///< Select SPARE IRQ 1 + SPARE_IRQ_2 = 28, ///< Select SPARE IRQ 2 + SPARE_IRQ_3 = 29, ///< Select SPARE IRQ 3 + SPARE_IRQ_4 = 30, ///< Select SPARE IRQ 4 + SPARE_IRQ_5 = 31, ///< Select SPARE IRQ 5 IRQ_COUNT } irq_num_t; #endif @@ -101,6 +113,12 @@ typedef enum irq_num_rp2040 { #define isr_i2c0 isr_irq23 #define isr_i2c1 isr_irq24 #define isr_rtc isr_irq25 +#define isr_spare_0 isr_irq26 +#define isr_spare_1 isr_irq27 +#define isr_spare_2 isr_irq28 +#define isr_spare_3 isr_irq29 +#define isr_spare_4 isr_irq30 +#define isr_spare_5 isr_irq31 #endif // _INTCTRL_H diff --git a/src/rp2350/hardware_regs/RP2350.svd b/src/rp2350/hardware_regs/RP2350.svd index fc6479ebb..c942b3a57 100644 --- a/src/rp2350/hardware_regs/RP2350.svd +++ b/src/rp2350/hardware_regs/RP2350.svd @@ -105846,5 +105846,40 @@ SPDX-License-Identifier: BSD-3-Clause + + + SPARE_IRQ + 0x00000000 + + 0 + 4 + reserved + + + SPARE_IRQ_0 + 46 + + + SPARE_IRQ_1 + 47 + + + SPARE_IRQ_2 + 48 + + + SPARE_IRQ_3 + 49 + + + SPARE_IRQ_4 + 50 + + + SPARE_IRQ_5 + 51 + + + diff --git a/src/rp2350/hardware_regs/include/hardware/regs/intctrl.h b/src/rp2350/hardware_regs/include/hardware/regs/intctrl.h index 96ce815e4..4db58399e 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/intctrl.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/intctrl.h @@ -59,12 +59,12 @@ #define PLL_USB_IRQ 43 #define POWMAN_IRQ_POW 44 #define POWMAN_IRQ_TIMER 45 -#define SPAREIRQ_IRQ_0 46 -#define SPAREIRQ_IRQ_1 47 -#define SPAREIRQ_IRQ_2 48 -#define SPAREIRQ_IRQ_3 49 -#define SPAREIRQ_IRQ_4 50 -#define SPAREIRQ_IRQ_5 51 +#define SPARE_IRQ_0 46 +#define SPARE_IRQ_1 47 +#define SPARE_IRQ_2 48 +#define SPARE_IRQ_3 49 +#define SPARE_IRQ_4 50 +#define SPARE_IRQ_5 51 #else /** * \brief Interrupt numbers on RP2350 (used as typedef \ref irq_num_t) diff --git a/src/rp2_common/hardware_irq/irq.c b/src/rp2_common/hardware_irq/irq.c index b06db13c9..f25046850 100644 --- a/src/rp2_common/hardware_irq/irq.c +++ b/src/rp2_common/hardware_irq/irq.c @@ -15,6 +15,12 @@ PICO_RUNTIME_INIT_FUNC_PER_CORE(runtime_init_per_core_irq_priorities, PICO_RUNTIME_INIT_PER_CORE_IRQ_PRIORITIES); #endif +static_assert(IRQ_COUNT == NUM_IRQS, ""); +// "USER IRQs" use the spare irq numbers +#if NUM_USER_IRQS +static_assert(IRQ_COUNT - NUM_USER_IRQS == SPARE_IRQ_0, ""); +#endif + #if PICO_VTABLE_PER_CORE static uint8_t user_irq_claimed[NUM_CORES]; static inline uint8_t *user_irq_claimed_ptr(void) { From a5ba689cb551cb36583619e0d57811ad98192f1b Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Wed, 26 Mar 2025 21:44:21 +0000 Subject: [PATCH 098/224] Initial commit pulled in a bunch of stuff - see description * Add `PICO_MINIMAL_STORED_VECTOR_TABLE` config replacing (`PICO_NO_STORED_VECTOR_TABLE` which was a lie * Add `PICO_NUM_VTABLE_IRQS`` which allows you to limit the number of IRQs included in both the STORED or RAM vector tables, and make the rest of the SDK behave properly based on that * Because these new variables in `pico_crt0` are circularly dependent somewhat with variables in `hardware_irq` hoist all the interdependent variables into a new `pico_platform_common` which is common to all `rp2` platforms * Move some previously duplicated `pico_platform` code into `pico_platform_common` Net effect: 1. if you set PICO_MINIMAL_STORED_VECTOR_TABLE=1, you get a 4 word VTABLE on Arm.. you still get a RAM vector table with up to PICO_NUM_VTABLE_IRQs (defaults to NUM_IRQs) but everything - including things like `isr_pendsv` point to `__unhandled_user_irq`. 2. PICO_NUM_VTABLE_IRQs (default NUM_IRQS) sets the number of IRQs that have handlers in the VTABLE (this affects the space reserved, and what the irq APIs let you touch - at least as far as invalid_params_if!) 3. If you set PICO_MINIMAL_STORED_VECTOR_TABLE=1 for a no flash binary, then PICO_NUM_VTABLE_IRQs is forced to 0 as there is no reserved space for the handlers. Co-authored-by: graham sanderson --- src/cmake/rp2_common.cmake | 1 + src/common/pico_base_headers/BUILD.bazel | 1 + src/host/hardware_irq/include/hardware/irq.h | 2 +- src/host/hardware_irq/irq.c | 2 +- src/rp2040/pico_platform/BUILD.bazel | 2 + src/rp2040/pico_platform/CMakeLists.txt | 1 + .../pico_platform/include/pico/platform.h | 29 +--- src/rp2040/pico_platform/platform.c | 15 -- src/rp2350/pico_platform/BUILD.bazel | 2 + src/rp2350/pico_platform/CMakeLists.txt | 1 + .../pico_platform/include/pico/platform.h | 41 +----- src/rp2350/pico_platform/platform.c | 26 +--- src/rp2_common/hardware_exception/exception.c | 8 +- .../hardware_irq/include/hardware/irq.h | 2 +- src/rp2_common/hardware_irq/irq.c | 36 +++-- src/rp2_common/pico_crt0/crt0.S | 68 +++++---- src/rp2_common/pico_crt0/crt0_riscv.S | 131 ++++-------------- .../pico_platform_common/BUILD.bazel | 25 ++++ .../pico_platform_common/CMakeLists.txt | 8 ++ src/rp2_common/pico_platform_common/common.c | 30 ++++ .../include/pico/platform/common.h | 85 ++++++++++++ .../include/pico/platform/compiler.h | 4 +- .../pico_runtime_init/runtime_init.c | 27 ++-- 23 files changed, 283 insertions(+), 264 deletions(-) create mode 100644 src/rp2_common/pico_platform_common/BUILD.bazel create mode 100644 src/rp2_common/pico_platform_common/CMakeLists.txt create mode 100644 src/rp2_common/pico_platform_common/common.c create mode 100644 src/rp2_common/pico_platform_common/include/pico/platform/common.h diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index 726bab933..9e6f9f3fa 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -82,6 +82,7 @@ endif() # Basic bootrom headers pico_add_subdirectory(rp2_common/boot_bootrom_headers) +pico_add_subdirectory(rp2_common/pico_platform_common) pico_add_subdirectory(rp2_common/pico_platform_compiler) pico_add_subdirectory(rp2_common/pico_platform_sections) pico_add_subdirectory(rp2_common/pico_platform_panic) diff --git a/src/common/pico_base_headers/BUILD.bazel b/src/common/pico_base_headers/BUILD.bazel index 5525c309b..c22f9ae8b 100644 --- a/src/common/pico_base_headers/BUILD.bazel +++ b/src/common/pico_base_headers/BUILD.bazel @@ -112,6 +112,7 @@ cc_library( "//src/rp2_common/hardware_watchdog:__pkg__", "//src/rp2_common/hardware_xosc:__pkg__", "//src/rp2_common/pico_crt0:__pkg__", + "//src/rp2_common/pico_platform_common:__pkg__", "//src/rp2_common/pico_printf:__pkg__", "//src/rp2_common/pico_runtime:__pkg__", "//src/rp2_common/pico_runtime_init:__pkg__", diff --git a/src/host/hardware_irq/include/hardware/irq.h b/src/host/hardware_irq/include/hardware/irq.h index 0e881b7a7..ef90ee703 100644 --- a/src/host/hardware_irq/include/hardware/irq.h +++ b/src/host/hardware_irq/include/hardware/irq.h @@ -128,7 +128,7 @@ extern "C" { typedef void (*irq_handler_t)(void); static inline void check_irq_param(__unused uint num) { - invalid_params_if(HARDWARE_IRQ, num >= NUM_IRQS); + invalid_params_if(HARDWARE_IRQ, num >= PICO_NUM_VTABLE_IRQS); } /*! \brief Set specified interrupt's priority diff --git a/src/host/hardware_irq/irq.c b/src/host/hardware_irq/irq.c index ad793c19d..db452ab12 100644 --- a/src/host/hardware_irq/irq.c +++ b/src/host/hardware_irq/irq.c @@ -96,7 +96,7 @@ void PICO_WEAK_FUNCTION_IMPL_NAME(irq_init_priorities)() { } static uint get_user_irq_claim_index(uint irq_num) { - invalid_params_if(HARDWARE_IRQ, irq_num < FIRST_USER_IRQ || irq_num >= NUM_IRQS); + invalid_params_if(HARDWARE_IRQ, irq_num < FIRST_USER_IRQ || irq_num >= PICO_NUM_VTABLE_IRQS); // we count backwards from the last, to match the existing hard coded uses of user IRQs in the SDK which were previously using 31 static_assert(NUM_IRQS - FIRST_USER_IRQ <= 8, ""); // we only use a single byte's worth of claim bits today. return NUM_IRQS - irq_num - 1u; diff --git a/src/rp2040/pico_platform/BUILD.bazel b/src/rp2040/pico_platform/BUILD.bazel index bc860f1f4..47b90e434 100644 --- a/src/rp2040/pico_platform/BUILD.bazel +++ b/src/rp2040/pico_platform/BUILD.bazel @@ -27,6 +27,7 @@ cc_library( deps = [ "//src/rp2040/hardware_regs", "//src/rp2040/hardware_regs:platform_defs", + "//src/rp2_common/pico_platform_common:pico_platform_common_headers", "//src/rp2_common/pico_platform_compiler", "//src/rp2_common/pico_platform_panic:pico_platform_panic_headers", "//src/rp2_common/pico_platform_sections", @@ -44,6 +45,7 @@ cc_library( "//src/rp2040/hardware_regs", "//src/rp2040/hardware_regs:platform_defs", "//src/rp2_common/hardware_base", + "//src/rp2_common/pico_platform_common", "//src/rp2_common/pico_platform_compiler", "//src/rp2_common/pico_platform_panic", "//src/rp2_common/pico_platform_sections", diff --git a/src/rp2040/pico_platform/CMakeLists.txt b/src/rp2040/pico_platform/CMakeLists.txt index f7c607a4f..9c91df3ea 100644 --- a/src/rp2040/pico_platform/CMakeLists.txt +++ b/src/rp2040/pico_platform/CMakeLists.txt @@ -17,6 +17,7 @@ if (NOT TARGET pico_platform) target_link_libraries(pico_platform_headers INTERFACE hardware_regs) pico_mirrored_target_link_libraries(pico_platform INTERFACE + pico_platform_common pico_platform_compiler pico_platform_panic pico_platform_sections diff --git a/src/rp2040/pico_platform/include/pico/platform.h b/src/rp2040/pico_platform/include/pico/platform.h index 5c157f532..437ff31f4 100644 --- a/src/rp2040/pico_platform/include/pico/platform.h +++ b/src/rp2040/pico_platform/include/pico/platform.h @@ -23,6 +23,7 @@ #include "pico/platform/compiler.h" #include "pico/platform/sections.h" #include "pico/platform/panic.h" +#include "pico/platform/common.h" #include "hardware/regs/addressmap.h" #include "hardware/regs/sio.h" @@ -66,10 +67,6 @@ #define PICO_RP2040_B2_SUPPORTED 1 #endif -#ifndef PICO_RAM_VECTOR_TABLE_SIZE -#define PICO_RAM_VECTOR_TABLE_SIZE (VTABLE_FIRST_IRQ + NUM_IRQS) -#endif - // PICO_CONFIG: PICO_CLKDIV_ROUND_NEAREST, True if floating point clock divisors should be rounded to the nearest possible clock divisor by default rather than rounding down, type=bool, default=1, group=pico_platform #ifndef PICO_CLKDIV_ROUND_NEAREST #define PICO_CLKDIV_ROUND_NEAREST 1 @@ -80,16 +77,6 @@ #ifdef __cplusplus extern "C" { #endif - -/*! \brief No-op function for the body of tight loops - * \ingroup pico_platform - * - * No-op function intended to be called by any tight hardware polling loop. Using this ubiquitously - * makes it much easier to find tight loops, but also in the future \#ifdef-ed support for lockup - * debugging might be added - */ -static __force_inline void tight_loop_contents(void) {} - /*! \brief Helper method to busy-wait for at least the given number of cycles * \ingroup pico_platform * @@ -112,17 +99,6 @@ static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) { ); } -// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime -#ifndef PICO_NO_FPGA_CHECK -#define PICO_NO_FPGA_CHECK 1 -#endif - -#if PICO_NO_FPGA_CHECK -static inline bool running_on_fpga(void) {return false;} -#else -bool running_on_fpga(void); -#endif - /*! \brief Execute a breakpoint instruction * \ingroup pico_platform */ @@ -158,9 +134,6 @@ static __force_inline uint __get_current_exception(void) { return exception; } -#define host_safe_hw_ptr(x) ((uintptr_t)(x)) -#define native_safe_hw_ptr(x) host_safe_hw_ptr(x) - /*! \brief Returns the RP2040 chip revision number * \ingroup pico_platform * @return the RP2040 chip revision number (1 for B0/B1, 2 for B2) diff --git a/src/rp2040/pico_platform/platform.c b/src/rp2040/pico_platform/platform.c index 9b0016535..5468670d6 100644 --- a/src/rp2040/pico_platform/platform.c +++ b/src/rp2040/pico_platform/platform.c @@ -6,23 +6,8 @@ #include "pico.h" #include "hardware/address_mapped.h" -#include "hardware/regs/tbman.h" #include "hardware/regs/sysinfo.h" -// Note we leave the FPGA check in by default so that we can run bug repro -// binaries coming in from the wild on the FPGA platform. It takes up around -// 48 bytes if you include all the calls, so you can pass PICO_NO_FPGA_CHECK=1 -// to remove it. The FPGA check is used to skip initialisation of hardware -// (mainly clock generators and oscillators) that aren't present on FPGA. - -#if !PICO_NO_FPGA_CHECK -// Inline stub provided in header if this code is unused (so folding can be -// done in each TU instead of relying on LTO) -bool running_on_fpga(void) { - return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS; -} -#endif - #define MANUFACTURER_RPI 0x927 #define PART_RP2 0x2 diff --git a/src/rp2350/pico_platform/BUILD.bazel b/src/rp2350/pico_platform/BUILD.bazel index 8b51a2dd6..b24291a2b 100644 --- a/src/rp2350/pico_platform/BUILD.bazel +++ b/src/rp2350/pico_platform/BUILD.bazel @@ -27,6 +27,7 @@ cc_library( deps = [ "//src/rp2350/hardware_regs", "//src/rp2350/hardware_regs:platform_defs", + "//src/rp2_common/pico_platform_common:pico_platform_common_headers", "//src/rp2_common/pico_platform_compiler", "//src/rp2_common/pico_platform_panic:pico_platform_panic_headers", "//src/rp2_common/pico_platform_sections", @@ -44,6 +45,7 @@ cc_library( "//src/rp2350/hardware_regs", "//src/rp2350/hardware_regs:platform_defs", "//src/rp2_common/hardware_base", + "//src/rp2_common/pico_platform_common", "//src/rp2_common/pico_platform_compiler", "//src/rp2_common/pico_platform_panic", "//src/rp2_common/pico_platform_sections", diff --git a/src/rp2350/pico_platform/CMakeLists.txt b/src/rp2350/pico_platform/CMakeLists.txt index 80a5103e3..7f875bf32 100644 --- a/src/rp2350/pico_platform/CMakeLists.txt +++ b/src/rp2350/pico_platform/CMakeLists.txt @@ -23,6 +23,7 @@ if (NOT TARGET pico_platform) hardware_regs ) pico_mirrored_target_link_libraries(pico_platform INTERFACE + pico_platform_common pico_platform_compiler pico_platform_panic pico_platform_sections diff --git a/src/rp2350/pico_platform/include/pico/platform.h b/src/rp2350/pico_platform/include/pico/platform.h index 35a6a0bd6..571efd8b8 100644 --- a/src/rp2350/pico_platform/include/pico/platform.h +++ b/src/rp2350/pico_platform/include/pico/platform.h @@ -23,13 +23,14 @@ #include "pico/platform/compiler.h" #include "pico/platform/sections.h" #include "pico/platform/panic.h" +#include "pico/platform/common.h" #include "hardware/regs/addressmap.h" #include "hardware/regs/sio.h" #ifdef __riscv #include "hardware/regs/rvcsr.h" #endif -// PICO_CONFIG: PICO_RP2350A, Whether the current board has an RP2350 in an A (30 GPIO) package, type=bool, default=Usually provided via board header, group=pico_platform +// PICO_CONFIG: PICO_RP2350A, Whether the current board has an RP2350 in an A (30 GPIO) package - set to 0 for RP2350 in a B (48 GPIO) package, type=bool, default=Usually provided via board header, group=pico_platform #if 0 // make tooling checks happy #define PICO_RP2350A 0 #endif @@ -54,10 +55,6 @@ #define PICO_NO_RAM_VECTOR_TABLE 0 #endif -#ifndef PICO_RAM_VECTOR_TABLE_SIZE -#define PICO_RAM_VECTOR_TABLE_SIZE (VTABLE_FIRST_IRQ + NUM_IRQS) -#endif - // PICO_CONFIG: PICO_USE_STACK_GUARDS, Enable/disable stack guards, type=bool, default=0, advanced=true, group=pico_platform #ifndef PICO_USE_STACK_GUARDS #define PICO_USE_STACK_GUARDS 0 @@ -73,16 +70,6 @@ #ifdef __cplusplus extern "C" { #endif - -/*! \brief No-op function for the body of tight loops - * \ingroup pico_platform - * - * No-op function intended to be called by any tight hardware polling loop. Using this ubiquitously - * makes it much easier to find tight loops, but also in the future \#ifdef-ed support for lockup - * debugging might be added - */ -static __force_inline void tight_loop_contents(void) {} - /*! \brief Helper method to busy-wait for at least the given number of cycles * \ingroup pico_platform * @@ -116,27 +103,6 @@ static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) { ); } -// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime -#ifndef PICO_NO_FPGA_CHECK -#define PICO_NO_FPGA_CHECK 1 -#endif - -// PICO_CONFIG: PICO_NO_SIM_CHECK, Remove the SIM platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime -#ifndef PICO_NO_SIM_CHECK -#define PICO_NO_SIM_CHECK 1 -#endif - -#if PICO_NO_FPGA_CHECK -static inline bool running_on_fpga(void) {return false;} -#else -bool running_on_fpga(void); -#endif -#if PICO_NO_SIM_CHECK -static inline bool running_in_sim(void) {return false;} -#else -bool running_in_sim(void); -#endif - /*! \brief Execute a breakpoint instruction * \ingroup pico_platform */ @@ -221,9 +187,6 @@ __force_inline static bool pico_processor_state_is_nonsecure(void) { #endif } -#define host_safe_hw_ptr(x) ((uintptr_t)(x)) -#define native_safe_hw_ptr(x) host_safe_hw_ptr(x) - /*! \brief Returns the RP2350 chip revision number * \ingroup pico_platform * @return the RP2350 chip revision number (1 for B0/B1, 2 for B2) diff --git a/src/rp2350/pico_platform/platform.c b/src/rp2350/pico_platform/platform.c index 97960478f..a71b8a0aa 100644 --- a/src/rp2350/pico_platform/platform.c +++ b/src/rp2350/pico_platform/platform.c @@ -6,28 +6,8 @@ #include "pico.h" #include "hardware/address_mapped.h" -#include "hardware/regs/tbman.h" #include "hardware/regs/sysinfo.h" -// Note we leave the FPGA check in by default so that we can run bug repro -// binaries coming in from the wild on the FPGA platform. It takes up around -// 48 bytes if you include all the calls, so you can pass PICO_NO_FPGA_CHECK=1 -// to remove it. The FPGA check is used to skip initialisation of hardware -// (mainly clock generators and oscillators) that aren't present on FPGA. - -#if !PICO_NO_FPGA_CHECK -// Inline stub provided in header if this code is unused (so folding can be -// done in each TU instead of relying on LTO) -bool __attribute__((weak)) running_on_fpga(void) { - return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS; -} -#endif -#if !PICO_NO_SIM_CHECK -bool __attribute__((weak)) running_in_sim(void) { - return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_HDLSIM_BITS; -} -#endif - #define MANUFACTURER_RPI 0x926 #define PART_RP4 0x4 @@ -36,9 +16,9 @@ uint8_t rp2350_chip_version(void) { uint32_t chip_id = *((io_ro_32*)(SYSINFO_BASE + SYSINFO_CHIP_ID_OFFSET)); uint32_t __unused manufacturer = chip_id & SYSINFO_CHIP_ID_MANUFACTURER_BITS; uint32_t __unused part = (chip_id & SYSINFO_CHIP_ID_PART_BITS) >> SYSINFO_CHIP_ID_PART_LSB; - assert(manufacturer == MANUFACTURER_RPI); - assert(part == PART_RP4); + assert(manufacturer == MANUFACTURER_RPI && part == PART_RP4); // 0 == A0, 1 == A1, 2 == A2 - uint version = (chip_id & SYSINFO_CHIP_ID_REVISION_BITS) >> SYSINFO_CHIP_ID_REVISION_LSB; + uint32_t version = (chip_id & SYSINFO_CHIP_ID_REVISION_BITS) >> SYSINFO_CHIP_ID_REVISION_LSB; + version = (version & 3u) | ((version & 8u) >> 1); return (uint8_t)version; } \ No newline at end of file diff --git a/src/rp2_common/hardware_exception/exception.c b/src/rp2_common/hardware_exception/exception.c index d3134fbc8..52a5b64c0 100644 --- a/src/rp2_common/hardware_exception/exception.c +++ b/src/rp2_common/hardware_exception/exception.c @@ -31,12 +31,14 @@ static inline exception_handler_t *get_exception_table(void) { #endif } +#if !PICO_NO_RAM_VECTOR_TABLE static void set_raw_exception_handler_and_restore_interrupts(enum exception_number num, exception_handler_t handler, uint32_t save) { // update vtable (vtable_handler may be same or updated depending on cases, but we do it anyway for compactness) get_exception_table()[num] = handler; __dmb(); restore_interrupts_from_disabled(save); } +#endif static inline void check_exception_param(__unused enum exception_number num) { invalid_params_if(HARDWARE_EXCEPTION, num < MIN_EXCEPTION_NUM || num > MAX_EXCEPTION_NUM); @@ -54,10 +56,12 @@ exception_handler_t exception_set_exclusive_handler(enum exception_number num, e exception_handler_t current = exception_get_vtable_handler(num); hard_assert(handler == current || exception_is_compile_time_default(current)); set_raw_exception_handler_and_restore_interrupts(num, handler, save); + return current; #else + ((void)num); + ((void)handler); panic_unsupported(); #endif - return current; } void exception_restore_handler(enum exception_number num, exception_handler_t original_handler) { @@ -66,6 +70,8 @@ void exception_restore_handler(enum exception_number num, exception_handler_t or uint32_t save = save_and_disable_interrupts(); set_raw_exception_handler_and_restore_interrupts(num, original_handler, save); #else + ((void)num); + ((void)original_handler); panic_unsupported(); #endif } diff --git a/src/rp2_common/hardware_irq/include/hardware/irq.h b/src/rp2_common/hardware_irq/include/hardware/irq.h index d671903dc..0dcc49d59 100644 --- a/src/rp2_common/hardware_irq/include/hardware/irq.h +++ b/src/rp2_common/hardware_irq/include/hardware/irq.h @@ -195,7 +195,7 @@ extern "C" { typedef void (*irq_handler_t)(void); static inline void check_irq_param(__unused uint num) { - invalid_params_if(HARDWARE_IRQ, num >= NUM_IRQS); + invalid_params_if(HARDWARE_IRQ, num >= PICO_NUM_VTABLE_IRQS); } /*! \brief Set specified interrupt's priority diff --git a/src/rp2_common/hardware_irq/irq.c b/src/rp2_common/hardware_irq/irq.c index f25046850..9006b5d7a 100644 --- a/src/rp2_common/hardware_irq/irq.c +++ b/src/rp2_common/hardware_irq/irq.c @@ -57,13 +57,6 @@ static inline void *remove_thumb_bit(void *addr) { #endif } -static void set_raw_irq_handler_and_unlock(uint num, irq_handler_t handler, uint32_t save) { - // update vtable (vtable_handler may be same or updated depending on cases, but we do it anyway for compactness) - get_vtable()[VTABLE_FIRST_IRQ + num] = handler; - __dmb(); - spin_unlock(spin_lock_instance(PICO_SPINLOCK_ID_IRQ), save); -} - void irq_set_enabled(uint num, bool enabled) { check_irq_param(num); // really should update irq_set_mask_enabled? @@ -82,7 +75,7 @@ bool irq_is_enabled(uint num) { } static inline void irq_set_mask_n_enabled_internal(uint n, uint32_t mask, bool enabled) { - invalid_params_if(HARDWARE_IRQ, n * 32u >= ((NUM_IRQS + 31u) & ~31u)); + invalid_params_if(HARDWARE_IRQ, n * 32u >= ((PICO_NUM_VTABLE_IRQS + 31u) & ~31u)); #if defined(__riscv) if (enabled) { hazard3_irqarray_clear(RVCSR_MEIFA_OFFSET, 2 * n, mask & 0xffffu); @@ -135,7 +128,7 @@ void irq_set_pending(uint num) { #endif } -#if !PICO_DISABLE_SHARED_IRQ_HANDLERS +#if !PICO_DISABLE_SHARED_IRQ_HANDLERS && !PICO_NO_RAM_VECTOR_TABLE // limited by 8 bit relative links (and reality) static_assert(PICO_MAX_SHARED_IRQ_HANDLERS >= 1 && PICO_MAX_SHARED_IRQ_HANDLERS < 0x7f, ""); @@ -215,9 +208,17 @@ bool irq_has_shared_handler(uint irq_num) { return is_shared_irq_raw_handler(handler); } -#else // PICO_DISABLE_SHARED_IRQ_HANDLERS +static void set_raw_irq_handler_and_unlock(uint num, irq_handler_t handler, uint32_t save) { + // update vtable (vtable_handler may be same or updated depending on cases, but we do it anyway for compactness) + get_vtable()[VTABLE_FIRST_IRQ + num] = handler; + __dmb(); + spin_unlock(spin_lock_instance(PICO_SPINLOCK_ID_IRQ), save); +} + +#else // PICO_DISABLE_SHARED_IRQ_HANDLERS && PICO_NO_RAM_VECTOR_TABLE #define is_shared_irq_raw_handler(h) false bool irq_has_shared_handler(uint irq_num) { + ((void)irq_num); return false; } #endif @@ -237,6 +238,7 @@ void irq_set_exclusive_handler(uint num, irq_handler_t handler) { hard_assert(current == __unhandled_user_irq || current == handler); set_raw_irq_handler_and_unlock(num, handler, save); #else + ((void)handler); panic_unsupported(); #endif } @@ -258,7 +260,7 @@ irq_handler_t irq_get_exclusive_handler(uint num) { } -#if !PICO_DISABLE_SHARED_IRQ_HANDLERS +#if !PICO_DISABLE_SHARED_IRQ_HANDLERS && !PICO_NO_RAM_VECTOR_TABLE #ifndef __riscv @@ -368,6 +370,8 @@ static inline int8_t get_slot_index(struct irq_handler_chain_slot *slot) { void irq_add_shared_handler(uint num, irq_handler_t handler, uint8_t order_priority) { check_irq_param(num); #if PICO_NO_RAM_VECTOR_TABLE + ((void)handler); + ((void)order_priority); panic_unsupported(); #elif PICO_DISABLE_SHARED_IRQ_HANDLERS irq_set_exclusive_handler(num, handler); @@ -461,7 +465,7 @@ void irq_add_shared_handler(uint num, irq_handler_t handler, uint8_t order_prior #endif // !PICO_NO_RAM_VECTOR_TABLE && !PICO_DISABLE_SHARED_IRQ_HANDLERS } -#if !PICO_DISABLE_SHARED_IRQ_HANDLERS +#if !PICO_DISABLE_SHARED_IRQ_HANDLERS && !PICO_NO_RAM_VECTOR_TABLE static inline irq_handler_t handler_from_slot(struct irq_handler_chain_slot *slot) { #ifndef __riscv return slot->handler; @@ -586,6 +590,8 @@ void irq_remove_handler(uint num, irq_handler_t handler) { } set_raw_irq_handler_and_unlock(num, vtable_handler, save); #else + ((void)num); + ((void)handler); panic_unsupported(); #endif } @@ -626,7 +632,7 @@ uint irq_get_priority(uint num) { #endif } -#if !PICO_DISABLE_SHARED_IRQ_HANDLERS +#if !PICO_DISABLE_SHARED_IRQ_HANDLERS && !PICO_NO_RAM_VECTOR_TABLE // used by irq_handler_chain.S to remove the last link in a handler chain after it executes // note this must be called only with the last slot in a chain (and during the exception) void irq_add_tail_to_free_list(struct irq_handler_chain_slot *slot) { @@ -670,7 +676,7 @@ __weak void runtime_init_per_core_irq_priorities(void) { *p++ = prio4; } #else - for (uint i = 0; i < NUM_IRQS; ++i) { + for (uint i = 0; i < PICO_NUM_VTABLE_IRQS; ++i) { irq_set_priority(i, PICO_DEFAULT_IRQ_PRIORITY); } #endif @@ -678,7 +684,7 @@ __weak void runtime_init_per_core_irq_priorities(void) { } static uint get_user_irq_claim_index(uint irq_num) { - invalid_params_if(HARDWARE_IRQ, irq_num < FIRST_USER_IRQ || irq_num >= NUM_IRQS); + invalid_params_if(HARDWARE_IRQ, irq_num < FIRST_USER_IRQ || irq_num >= PICO_NUM_VTABLE_IRQS); // we count backwards from the last, to match the existing hard coded uses of user IRQs in the SDK which were previously using 31 static_assert(NUM_IRQS - FIRST_USER_IRQ <= 8, ""); // we only use a single byte's worth of claim bits today. return NUM_IRQS - irq_num - 1u; diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index e408b7ded..eb477bd1e 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -23,14 +23,23 @@ pico_default_asm_setup +#ifdef PICO_NO_STORED_VECTOR_TABLE +#warning PICO_NO_STORED_VECTOR_TABLE is no longer used. PICO_MINIMAL_STORED_VECTOR_TABLE is not identical but usually serves the same purpose +#endif + .section .vectors, "ax" .align 2 -.global __vectors, __VECTOR_TABLE +.global __vectors, __VECTOR_TABLE, __vectors_end __VECTOR_TABLE: __vectors: .word __StackTop .word _reset_handler + +#if PICO_MINIMAL_STORED_VECTOR_TABLE +.word isr_invalid // NMI +.word isr_invalid // HardFault +#else .word isr_nmi .word isr_hardfault .word isr_invalid // Reserved, should never fire @@ -45,15 +54,9 @@ __vectors: .word isr_invalid // Reserved, should never fire .word isr_pendsv .word isr_systick -#if PICO_NO_STORED_VECTOR_TABLE && !PICO_NO_FLASH // note in no flash binary, we only have the single RAM vector table anyway -#if PICO_NO_RAM_VECTOR_TABLE -#error Can't specify PICO_NO_STORED_VECTOR_TABLE and PICO_NO_RAM_VECTOR_TABLE -#endif -// we don't include any IRQ vectors; we will initialize them during runtime_init in the RAM vector table -#else .macro if_irq_word num func -.if \num < NUM_IRQS +.if \num < PICO_NUM_VTABLE_IRQS .word \func .endif .endm @@ -142,10 +145,11 @@ if_irq_word 76 isr_irq76 if_irq_word 77 isr_irq77 if_irq_word 78 isr_irq78 if_irq_word 79 isr_irq79 -#if NUM_IRQS > 80 +#if PICO_NUM_VTABLE_IRQS > 80 #error more IRQ entries required #endif -#endif +#endif // #if !PICO_MINIMAL_STORED_VECTOR_TABLE +__vectors_end: // all default exception handlers do nothing, and we can check for them being set to our // default values by seeing if they point to somewhere between __defaults_isrs_start and __default_isrs_end @@ -164,24 +168,14 @@ __default_isrs_start: bkpt #0 .endm -// these are separated out for clarity -decl_isr_bkpt isr_invalid -decl_isr_bkpt isr_nmi -decl_isr_bkpt isr_hardfault -decl_isr_bkpt isr_svcall -decl_isr_bkpt isr_pendsv -decl_isr_bkpt isr_systick - -.global __default_isrs_end -__default_isrs_end: - .altmacro .macro decl_isr name -#if !PICO_NO_STORED_VECTOR_TABLE | PICO_NO_FLASH +#if !PICO_MINIMAL_STORED_VECTOR_TABLE | PICO_NO_FLASH // We declare a weak label, so user can override .weak \name #else -// We declare a strong label, so user can't override (their version would not automatically be used) +// We declare a strong global label, so user can't override (their version would not automatically be used) +.global \name #endif .type \name,%function .thumb_func @@ -189,8 +183,14 @@ __default_isrs_end: .endm .macro if_irq_decl num func -.if \num < NUM_IRQS +.if \num < PICO_NUM_VTABLE_IRQS decl_isr \func +.elseif \num < NUM_IRQS +// We declare a strong global label, so user can't override (their version would not automatically be used) +.global \func +.type \func,%function +.thumb_func +\func: .endif .endm @@ -274,7 +274,7 @@ if_irq_decl 76 isr_irq76 if_irq_decl 77 isr_irq77 if_irq_decl 78 isr_irq78 if_irq_decl 79 isr_irq79 -#if NUM_IRQS > 80 +#if PICO_NUM_VTABLE_IRQS > 80 #error more IRQ entries required #endif @@ -282,12 +282,30 @@ if_irq_decl 79 isr_irq79 .global __unhandled_user_irq .thumb_func __unhandled_user_irq: +// if we include the implementation if there could be a valid IRQ hanler in the vtable that uses it +#if !(PICO_NO_RAM_VECTOR_TABLE && PICO_MINIMAL_STORED_VECTOR_TABLE) mrs r0, ipsr subs r0, #16 .global unhandled_user_irq_num_in_r0 unhandled_user_irq_num_in_r0: +#endif + // note the next instruction is a breakpoint too, however we have a 2 byte alignment hole + // and it is preferrable to have distinct labels, to inform the user what has happened in the debugger. bkpt #0 +decl_isr_bkpt isr_invalid +#if !PICO_MINIMAL_STORED_VECTOR_TABLE +// these are separated out for clarity +decl_isr_bkpt isr_nmi +decl_isr_bkpt isr_hardfault +decl_isr_bkpt isr_svcall +decl_isr_bkpt isr_pendsv +decl_isr_bkpt isr_systick +#endif + +.global __default_isrs_end +__default_isrs_end: + // ---------------------------------------------------------------------------- .section .binary_info_header, "a" diff --git a/src/rp2_common/pico_crt0/crt0_riscv.S b/src/rp2_common/pico_crt0/crt0_riscv.S index 0e89ab150..e9fc7d94c 100644 --- a/src/rp2_common/pico_crt0/crt0_riscv.S +++ b/src/rp2_common/pico_crt0/crt0_riscv.S @@ -160,64 +160,22 @@ check_irq_before_exit: addi sp, sp, 80 mret + // Default software vector table for system interrupts, routed through // mip.meip. Note this is assumed in e.g. hardware_irq to begin exactly 0x34 // words after the hardware vector table indicated by mtvec (defined above). .p2align 4 .global __soft_vector_table __soft_vector_table: -.word isr_irq0 -.word isr_irq1 -.word isr_irq2 -.word isr_irq3 -.word isr_irq4 -.word isr_irq5 -.word isr_irq6 -.word isr_irq7 -.word isr_irq8 -.word isr_irq9 -.word isr_irq10 -.word isr_irq11 -.word isr_irq12 -.word isr_irq13 -.word isr_irq14 -.word isr_irq15 -.word isr_irq16 -.word isr_irq17 -.word isr_irq18 -.word isr_irq19 -.word isr_irq20 -.word isr_irq21 -.word isr_irq22 -.word isr_irq23 -.word isr_irq24 -.word isr_irq25 -.word isr_irq26 -.word isr_irq27 -.word isr_irq28 -.word isr_irq29 -.word isr_irq30 -.word isr_irq31 -.word isr_irq32 -.word isr_irq33 -.word isr_irq34 -.word isr_irq35 -.word isr_irq36 -.word isr_irq37 -.word isr_irq38 -.word isr_irq39 -.word isr_irq40 -.word isr_irq41 -.word isr_irq42 -.word isr_irq43 -.word isr_irq44 -.word isr_irq45 -.word isr_irq46 -.word isr_irq47 -.word isr_irq48 -.word isr_irq49 -.word isr_irq50 -.word isr_irq51 +.macro vtable_irq_n n +.word isr_irq\n +.endm + +.set IRQN, 0 +.rept PICO_NUM_VTABLE_IRQS +vtable_irq_n IRQN +.set IRQN, IRQN + 1 +.endr // all default trap handlers do nothing, and we can check for them being set to our // default values by seeing if they point to somewhere between __defaults_isrs_start and __default_isrs_end @@ -252,58 +210,23 @@ decl_isr isr_riscv_machine_exception decl_isr_bkpt isr_riscv_machine_timer decl_isr_bkpt isr_riscv_machine_soft_irq -decl_isr isr_irq0 -decl_isr isr_irq1 -decl_isr isr_irq2 -decl_isr isr_irq3 -decl_isr isr_irq4 -decl_isr isr_irq5 -decl_isr isr_irq6 -decl_isr isr_irq7 -decl_isr isr_irq8 -decl_isr isr_irq9 -decl_isr isr_irq10 -decl_isr isr_irq11 -decl_isr isr_irq12 -decl_isr isr_irq13 -decl_isr isr_irq14 -decl_isr isr_irq15 -decl_isr isr_irq16 -decl_isr isr_irq17 -decl_isr isr_irq18 -decl_isr isr_irq19 -decl_isr isr_irq20 -decl_isr isr_irq21 -decl_isr isr_irq22 -decl_isr isr_irq23 -decl_isr isr_irq24 -decl_isr isr_irq25 -decl_isr isr_irq26 -decl_isr isr_irq27 -decl_isr isr_irq28 -decl_isr isr_irq29 -decl_isr isr_irq30 -decl_isr isr_irq31 -decl_isr isr_irq32 -decl_isr isr_irq33 -decl_isr isr_irq34 -decl_isr isr_irq35 -decl_isr isr_irq36 -decl_isr isr_irq37 -decl_isr isr_irq38 -decl_isr isr_irq39 -decl_isr isr_irq40 -decl_isr isr_irq41 -decl_isr isr_irq42 -decl_isr isr_irq43 -decl_isr isr_irq44 -decl_isr isr_irq45 -decl_isr isr_irq46 -decl_isr isr_irq47 -decl_isr isr_irq48 -decl_isr isr_irq49 -decl_isr isr_irq50 -decl_isr isr_irq51 +// Declare all the ISR labels +.macro decl_isr_n n +.if \n < PICO_NUM_VTABLE_IRQS + decl_isr isr_irq\n +.elseif \n < NUM_IRQS + // We declare a strong label, so user can't override, since there is no vtable entry + .type isr_irq\n,%function + .thumb_func + isr_irq\n: +.endif +.endm + +.set IRQN, 0 +.rept PICO_NUM_VTABLE_IRQS +decl_isr_n IRQN +.set IRQN, IRQN + 1 +.endr // fall through // All unhandled USER IRQs fall through to here. Note there is no way to get diff --git a/src/rp2_common/pico_platform_common/BUILD.bazel b/src/rp2_common/pico_platform_common/BUILD.bazel new file mode 100644 index 000000000..18a373a51 --- /dev/null +++ b/src/rp2_common/pico_platform_common/BUILD.bazel @@ -0,0 +1,25 @@ +load("//bazel:defs.bzl", "compatible_with_rp2") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_platform_common_headers", + hdrs = ["include/pico/platform/common.h"], + includes = ["include"], + visibility = [ + "//src/rp2040/pico_platform:__pkg__", + "//src/rp2350/pico_platform:__pkg__", + ], +) + +cc_library( + name = "pico_platform_common", + srcs = ["common.c"], + target_compatible_with = compatible_with_rp2(), + deps = [ + ":pico_platform_common_headers", + "//src/rp2_common:platform_defs", + "//src/rp2_common/hardware_base", + "//src/common/pico_base_headers", + ], +) diff --git a/src/rp2_common/pico_platform_common/CMakeLists.txt b/src/rp2_common/pico_platform_common/CMakeLists.txt new file mode 100644 index 000000000..8e6da4e13 --- /dev/null +++ b/src/rp2_common/pico_platform_common/CMakeLists.txt @@ -0,0 +1,8 @@ +if (NOT TARGET pico_platform_common) + pico_add_library(pico_platform_common) + target_sources(pico_platform_common INTERFACE ${CMAKE_CURRENT_LIST_DIR}/common.c) + + target_include_directories(pico_platform_common_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) + + target_link_libraries(pico_platform_common_headers INTERFACE hardware_regs) +endif() diff --git a/src/rp2_common/pico_platform_common/common.c b/src/rp2_common/pico_platform_common/common.c new file mode 100644 index 000000000..af5bf1833 --- /dev/null +++ b/src/rp2_common/pico_platform_common/common.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico.h" +#include "hardware/address_mapped.h" +#include "hardware/regs/tbman.h" + +// Note we leave the FPGA check in by default so that we can run bug repro +// binaries coming in from the wild on the FPGA platform. It takes up around +// 48 bytes if you include all the calls, so you can pass PICO_NO_FPGA_CHECK=1 +// to remove it. The FPGA check is used to skip initialisation of hardware +// (mainly clock generators and oscillators) that aren't present on FPGA. + +#if !PICO_NO_FPGA_CHECK +// Inline stub provided in header if this code is unused (so folding can be +// done in each TU instead of relying on LTO) +bool __attribute__((weak)) running_on_fpga(void) { + return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS; +} +#endif + +#if !PICO_NO_SIM_CHECK +bool __attribute__((weak)) running_in_sim(void) { + return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_HDLSIM_BITS; +} +#endif + diff --git a/src/rp2_common/pico_platform_common/include/pico/platform/common.h b/src/rp2_common/pico_platform_common/include/pico/platform/common.h new file mode 100644 index 000000000..c4645d6e0 --- /dev/null +++ b/src/rp2_common/pico_platform_common/include/pico/platform/common.h @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _PICO_PLATFORM_COMMON_H +#define _PICO_PLATFORM_COMMON_H + +/** \file pico/platform/common.h + * \ingroup pico_platform + * + * \brief Macros and definitions common to all rp2 platforms but not specific to any library + * + * This header may be included by assembly code + * + * Note certain library specific defines are defined here when they are interdpedent across libraries, + * but making an explicit library dependency does not make sense. + */ + +// PICO_CONFIG: PICO_MINIMAL_STORED_VECTOR_TABLE, Only store a very minimal vector table in the binary on Arm, type=bool, default=0, advanced=true, group=pico_crt0 +#ifndef PICO_MINIMAL_STORED_VECTOR_TABLE +#define PICO_MINIMAL_STORED_VECTOR_TABLE 0 +#endif + +#if PICO_MINIMAL_STORED_VECTOR_TABLE && (PICO_NO_FLASH && !defined(__riscv)) +#if PICO_NUM_VTABLE_IRQS +#warning PICO_NUM_VTABLE_IRQS is specied with PICO_MINIMAL_STORED_VECTOR_TABLE for NO_FLASH Arm binary; ignored +#undef PICO_NUM_VTABLE_IRQS +#endif +#define PICO_NUM_VTABLE_IRQS 0 +#else +// PICO_CONFIG: PICO_NUM_VTABLE_IRQS, Number of IRQ handlers in the vector table - can be lowered to save space if you aren't using some higher IRQs, type=int, default=NUM_IRQS, group=hardware_irq +#ifndef PICO_NUM_VTABLE_IRQS +#define PICO_NUM_VTABLE_IRQS NUM_IRQS +#endif +#endif + +#ifndef __ASSEMBLER__ + +// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime +#ifndef PICO_NO_FPGA_CHECK +#define PICO_NO_FPGA_CHECK 1 +#endif + +// PICO_CONFIG: PICO_NO_SIM_CHECK, Remove the SIM platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime +#ifndef PICO_NO_SIM_CHECK +#define PICO_NO_SIM_CHECK 1 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if PICO_NO_FPGA_CHECK +static inline bool running_on_fpga(void) {return false;} +#else +bool running_on_fpga(void); +#endif + +#if PICO_NO_SIM_CHECK +static inline bool running_in_sim(void) {return false;} +#else +bool running_in_sim(void); +#endif + +/*! \brief No-op function for the body of tight loops + * \ingroup pico_platform + * + * No-op function intended to be called by any tight hardware polling loop. Using this ubiquitously + * makes it much easier to find tight loops, but also in the future \#ifdef-ed support for lockup + * debugging might be added + */ +static __force_inline void tight_loop_contents(void) {} + +#define host_safe_hw_ptr(x) ((uintptr_t)(x)) +#define native_safe_hw_ptr(x) host_safe_hw_ptr(x) + +#ifdef __cplusplus +} +#endif +#endif // __ASSEMBLER__ + + +#endif \ No newline at end of file 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 486758be3..7f24008a2 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 @@ -7,8 +7,8 @@ #ifndef _PICO_PLATFORM_COMPILER_H #define _PICO_PLATFORM_COMPILER_H -/** \file platform_compiler.h - * \defgroup pico_platform pico_platform +/** \file pico/platform/compiler.h + * \ingroup pico_platform * * \brief Macros and definitions (and functions when included by non assembly code) to adapt for different compilers * diff --git a/src/rp2_common/pico_runtime_init/runtime_init.c b/src/rp2_common/pico_runtime_init/runtime_init.c index 2b69c8069..e028a5131 100644 --- a/src/rp2_common/pico_runtime_init/runtime_init.c +++ b/src/rp2_common/pico_runtime_init/runtime_init.c @@ -195,23 +195,32 @@ PICO_RUNTIME_INIT_FUNC_RUNTIME(runtime_init_spin_locks_reset, PICO_RUNTIME_INIT_ // RISC-V to have an initial flash-resident vector table at a well-known // location, unlike Cortex-M which can take an NMI on cycle 0. #ifndef __riscv +#include "hardware/structs/scb.h" +#include "hardware/irq.h" #if !PICO_RUNTIME_NO_INIT_INSTALL_RAM_VECTOR_TABLE +// note that this is not a safely overridable value, you should use override PICO_NUM_VTABLE_IRQs instead. +// keeping around as a #define though as it used to be supported +#ifdef PICO_RAM_VECTOR_TABLE_SIZE +#warning Overriding PICO_RAM_VECTOR_TABLE_SIZE is deprecated; specify PICO_NUM_VTABLE_IRQS instead +#endif +#ifndef PICO_RAM_VECTOR_TABLE_SIZE +#define PICO_RAM_VECTOR_TABLE_SIZE (VTABLE_FIRST_IRQ + PICO_NUM_VTABLE_IRQS) +#endif + + uint32_t __attribute__((section(".ram_vector_table"))) ram_vector_table[PICO_RAM_VECTOR_TABLE_SIZE]; -#include "hardware/structs/scb.h" void runtime_init_install_ram_vector_table(void) { // Note on RISC-V the RAM vector table is initialised during crt0 -#if !(PICO_NO_RAM_VECTOR_TABLE || PICO_NO_FLASH) && !defined(__riscv) -#if !PICO_NO_STORED_VECTOR_TABLE - __builtin_memcpy(ram_vector_table, (uint32_t *) scb_hw->vtor, sizeof(ram_vector_table)); -#else - __builtin_memcpy(ram_vector_table, (uint32_t *) scb_hw->vtor, MIN(VTABLE_FIRST_IRQ, sizeof(ram_vector_table))); - for(uint i = VTABLE_FIRST_IRQ; ivtor = (uintptr_t) ram_vector_table; #endif } From bb5b5f96e2bfca6baaa5604bea5408b5f0e9d5c2 Mon Sep 17 00:00:00 2001 From: Patrick Plenefisch Date: Sat, 29 Mar 2025 13:02:03 -0400 Subject: [PATCH 099/224] Move unique_id (configurably) earlier in the static init process (#2379) This enables using the unique_id in C++ static initializers by default --- .../pico_unique_id/include/pico/unique_id.h | 22 +++++++++++++++++++ src/rp2_common/pico_unique_id/unique_id.c | 8 ++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_unique_id/include/pico/unique_id.h b/src/rp2_common/pico_unique_id/include/pico/unique_id.h index 367d32bff..9f91733de 100644 --- a/src/rp2_common/pico_unique_id/include/pico/unique_id.h +++ b/src/rp2_common/pico_unique_id/include/pico/unique_id.h @@ -41,6 +41,28 @@ extern "C" { #define PICO_UNIQUE_BOARD_ID_SIZE_BYTES 8 +/** + * \brief Static initialization order + * \ingroup pico_unique_id + * + * This defines the init_priority of the pico_unique_id. By default, it is 1000. The valid range is + * from 101-65535. Set it to -1 to set the priority to none, thus putting it after 65535. Changing + * this value will initialize the unique_id earlier or later in the static initialization order. + * This is most useful for C++ consumers of the pico-sdk. + * + * See https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-constructor-function-attribute + * and https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html#index-init_005fpriority-variable-attribute + * + * Here is an example of C++ static initializers that will run before, and then after, pico_unique_id is loaded: + * + * [[gnu::init_priority(500)]] my_class before_instance; + * [[gnu::init_priority(2000)]] my_class after_instance; + * + */ +#ifndef PICO_UNIQUE_BOARD_ID_INIT_PRIORITY +#define PICO_UNIQUE_BOARD_ID_INIT_PRIORITY 1000 +#endif + /** * \brief Unique board identifier * \ingroup pico_unique_id diff --git a/src/rp2_common/pico_unique_id/unique_id.c b/src/rp2_common/pico_unique_id/unique_id.c index c027bf27d..28204eda0 100644 --- a/src/rp2_common/pico_unique_id/unique_id.c +++ b/src/rp2_common/pico_unique_id/unique_id.c @@ -12,7 +12,13 @@ static_assert(PICO_UNIQUE_BOARD_ID_SIZE_BYTES <= FLASH_UNIQUE_ID_SIZE_BYTES, "Bo static pico_unique_board_id_t retrieved_id; -static void __attribute__((constructor)) _retrieve_unique_id_on_boot(void) { +#if PICO_UNIQUE_BOARD_ID_INIT_PRIORITY == -1 +#define PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES constructor +#else +#define PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES constructor(PICO_UNIQUE_BOARD_ID_INIT_PRIORITY) +#endif + +static void __attribute__((PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES)) _retrieve_unique_id_on_boot(void) { #if PICO_RP2040 #if PICO_NO_FLASH // The hardware_flash call will panic() if called directly on a NO_FLASH From 472c781a31e5f0858cb97678ba169918cb9421cb Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Wed, 2 Apr 2025 16:29:29 +0100 Subject: [PATCH 100/224] Fix sign conversion error introduced by #2233 (#2392) --- src/rp2_common/pico_runtime_init/runtime_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_runtime_init/runtime_init.c b/src/rp2_common/pico_runtime_init/runtime_init.c index e028a5131..2e1ce89fc 100644 --- a/src/rp2_common/pico_runtime_init/runtime_init.c +++ b/src/rp2_common/pico_runtime_init/runtime_init.c @@ -216,7 +216,7 @@ void runtime_init_install_ram_vector_table(void) { #if !(PICO_NO_RAM_VECTOR_TABLE || PICO_NO_FLASH) extern uint32_t __vectors; extern uint32_t __vectors_end; - uint32_t stored_words = &__vectors_end - &__vectors; + uint32_t stored_words = (uint32_t)(&__vectors_end - &__vectors); __builtin_memcpy(ram_vector_table, &__vectors, 4 * MIN(stored_words, PICO_RAM_VECTOR_TABLE_SIZE)); for(uint i = stored_words; i Date: Thu, 3 Apr 2025 09:57:25 -0500 Subject: [PATCH 101/224] move irq_has_handler() so it can be used without shared handlers (#2383) --- src/rp2_common/hardware_irq/irq.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/rp2_common/hardware_irq/irq.c b/src/rp2_common/hardware_irq/irq.c index 9006b5d7a..9b6f5ecd1 100644 --- a/src/rp2_common/hardware_irq/irq.c +++ b/src/rp2_common/hardware_irq/irq.c @@ -196,12 +196,6 @@ static inline bool is_shared_irq_raw_handler(irq_handler_t raw_handler) { return (uintptr_t)raw_handler - (uintptr_t)irq_handler_chain_slots < sizeof(irq_handler_chain_slots); } -bool irq_has_handler(uint irq_num) { - check_irq_param(irq_num); - irq_handler_t handler = irq_get_vtable_handler(irq_num); - return handler && handler != __unhandled_user_irq; -} - bool irq_has_shared_handler(uint irq_num) { check_irq_param(irq_num); irq_handler_t handler = irq_get_vtable_handler(irq_num); @@ -223,12 +217,17 @@ bool irq_has_shared_handler(uint irq_num) { } #endif - irq_handler_t irq_get_vtable_handler(uint num) { check_irq_param(num); return get_vtable()[VTABLE_FIRST_IRQ + num]; } +bool irq_has_handler(uint irq_num) { + check_irq_param(irq_num); + irq_handler_t handler = irq_get_vtable_handler(irq_num); + return handler && handler != __unhandled_user_irq; +} + void irq_set_exclusive_handler(uint num, irq_handler_t handler) { check_irq_param(num); #if !PICO_NO_RAM_VECTOR_TABLE From f154f58cf955f4390f12f22ffcc538ef1d1cad86 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 3 Apr 2025 09:57:59 -0500 Subject: [PATCH 102/224] unclaim alarm on correct timer in ta_disable_irq_handler (#2382) --- src/rp2_common/pico_time_adapter/include/pico/time_adapter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h b/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h index 639e91498..9392fe779 100644 --- a/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h +++ b/src/rp2_common/pico_time_adapter/include/pico/time_adapter.h @@ -80,7 +80,7 @@ static inline void ta_disable_irq_handler(alarm_pool_timer_t *timer, uint alarm_ hw_clear_bits(&timer_hw_from_timer(timer)->inte, 1u << alarm_num); irq_set_enabled(irq_num, true); irq_remove_handler(irq_num, irq_handler); - hardware_alarm_unclaim(alarm_num); + timer_hardware_alarm_unclaim(timer, alarm_num); } static inline void ta_hardware_alarm_claim(alarm_pool_timer_t *timer, uint hardware_alaram_num) { From f62bc4f5ea63c87f4631c0525b2f5bad2d28afcc Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 3 Apr 2025 09:58:41 -0500 Subject: [PATCH 103/224] Properly respect setting PICO_DEFAULT_BINARY_TYPE (#2381) * Properly respect setting PICO_DEFAULT_BINARY_TYPE (rather than say PICO_NO_FLASH), and add a build error for specifying different types simulataneously * remove dead code --- .../pico_standard_link/CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index a428eb69d..53eaa84fa 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -30,6 +30,7 @@ if (NOT TARGET pico_standard_link) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BINARY_TYPE ${TYPE}) endfunction() + # slightly messy as we support both the preferred PICO_DEFAULT_BINARY_TYPE and the individual variables if (NOT PICO_DEFAULT_BINARY_TYPE) if (PICO_NO_FLASH) set(PICO_DEFAULT_BINARY_TYPE no_flash) @@ -40,6 +41,23 @@ if (NOT TARGET pico_standard_link) else() set(PICO_DEFAULT_BINARY_TYPE default) endif() + else() + # we must set the individual variables here, as they are used in generator expressions, + # but also for our checks below + if (PICO_DEFAULT_BINARY_TYPE STREQUAL no_flash) + set(PICO_NO_FLASH 1) + endif() + if (PICO_DEFAULT_BINARY_TYPE STREQUAL blocked_ram) + set(PICO_USE_BLOCKED_RAM 1) + endif() + if (PICO_DEFAULT_BINARY_TYPE STREQUAL copy_to_ram) + set(PICO_COPY_TO_RAM 1) + endif() + endif() + if ((PICO_NO_FLASH AND PICO_USE_BLOCKED_RAM) OR + (PICO_USE_BLOCKED_RAM AND PICO_COPY_TO_RAM) OR + (PICO_COPY_TO_RAM AND PICO_NO_FLASH)) + message(FATAL_ERROR "Conflicting binary types specified amongst PICO_DEFAULT_BINARY_TYPE, PICO_NO_FLASH, PICO_USE_BLOCKED_RAM and PICO_COPY_TO_RAM") endif() # todo only needed if not using a custom linker script From ad0bca9c8526bcbdeb4b757ae553b3b2fc2d8569 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Fri, 4 Apr 2025 17:33:18 +0100 Subject: [PATCH 104/224] Fix bug in extract_configs.py (#2389) This bug was actually introduced by #1845 , but I never noticed until now because it depended on which order the filesystem traversed the directories --- tools/extract_configs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/extract_configs.py b/tools/extract_configs.py index 81f57625a..00ff3437b 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -241,6 +241,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): for applicable, all_configs in chips_all_configs.items(): all_defines = chips_all_defines[applicable] + resolved_defines = chips_resolved_defines[applicable] for config_name, config_obj in all_configs.items(): file_path = os.path.join(scandir, config_obj['filename']) linenum = config_obj['line_number'] From 5edf1a0a3c09ea82bb3308913e1818f8ce5a20b5 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Fri, 4 Apr 2025 17:34:30 +0100 Subject: [PATCH 105/224] Fix WindowsCI (again) (#2388) Use newer version of ninja --- .github/workflows/choco_packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/choco_packages.config b/.github/workflows/choco_packages.config index d443f751c..9f1dea0ec 100644 --- a/.github/workflows/choco_packages.config +++ b/.github/workflows/choco_packages.config @@ -2,5 +2,5 @@ - + From c88bd53a68fe2199fa4a5e6473ba88278f339a2b Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Fri, 4 Apr 2025 17:35:42 +0100 Subject: [PATCH 106/224] Ensure that all RP2350 board-headers explicitly define PICO_RP2350A (#2370) --- src/boards/include/boards/pimoroni_pga2350.h | 3 +++ .../include/boards/pimoroni_pico_plus2_rp2350.h | 3 +++ .../include/boards/pimoroni_pico_plus2_w_rp2350.h | 3 +++ src/boards/include/boards/seeed_xiao_rp2350.h | 3 +++ tools/check_board_header.py | 14 +++++++++----- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/boards/include/boards/pimoroni_pga2350.h b/src/boards/include/boards/pimoroni_pga2350.h index f4f0a3d2a..1bd02dc48 100644 --- a/src/boards/include/boards/pimoroni_pga2350.h +++ b/src/boards/include/boards/pimoroni_pga2350.h @@ -20,6 +20,9 @@ #define PIMORONI_PGA2350 #define PIMORONI_PGA2350_16MB +// --- RP2350 VARIANT --- +#define PICO_RP2350A 0 + // --- BOARD SPECIFIC --- #define PIMORONI_PGA2350_PSRAM_CS_PIN 47 diff --git a/src/boards/include/boards/pimoroni_pico_plus2_rp2350.h b/src/boards/include/boards/pimoroni_pico_plus2_rp2350.h index 34c5fb38f..40fff17d7 100644 --- a/src/boards/include/boards/pimoroni_pico_plus2_rp2350.h +++ b/src/boards/include/boards/pimoroni_pico_plus2_rp2350.h @@ -19,6 +19,9 @@ // For board detection #define PIMORONI_PICO_PLUS2_RP2350 +// --- RP2350 VARIANT --- +#define PICO_RP2350A 0 + // --- BOARD SPECIFIC --- #define SPCE_SPI 0 #define SPCE_TX_MISO_PIN 32 diff --git a/src/boards/include/boards/pimoroni_pico_plus2_w_rp2350.h b/src/boards/include/boards/pimoroni_pico_plus2_w_rp2350.h index ba3c0e56c..7a4f1741f 100644 --- a/src/boards/include/boards/pimoroni_pico_plus2_w_rp2350.h +++ b/src/boards/include/boards/pimoroni_pico_plus2_w_rp2350.h @@ -20,6 +20,9 @@ // For board detection #define PIMORONI_PICO_PLUS2_W_RP2350 +// --- RP2350 VARIANT --- +#define PICO_RP2350A 0 + // --- BOARD SPECIFIC --- #define PIMORONI_PICO_PLUS2_W_USER_SW_PIN 45 #define PIMORONI_PICO_PLUS2_W_PSRAM_CS_PIN 47 diff --git a/src/boards/include/boards/seeed_xiao_rp2350.h b/src/boards/include/boards/seeed_xiao_rp2350.h index 52e163654..69a2ba40b 100644 --- a/src/boards/include/boards/seeed_xiao_rp2350.h +++ b/src/boards/include/boards/seeed_xiao_rp2350.h @@ -17,6 +17,9 @@ // For board detection #define SEEED_XIAO_RP2350 +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + //------------- UART -------------// #ifndef PICO_DEFAULT_UART #define PICO_DEFAULT_UART 0 diff --git a/tools/check_board_header.py b/tools/check_board_header.py index 4efeef4c7..3bfce1c5b 100755 --- a/tools/check_board_header.py +++ b/tools/check_board_header.py @@ -196,6 +196,7 @@ def read_defines_from(header_file, defines_dict): if board_header_basename == "amethyst_fpga.h": defines['PICO_RP2350'] = DefineType('PICO_RP2350', 1, 1, -1) + defines['PICO_RP2350A'] = DefineType('PICO_RP2350A', 0, 0, -1) with open(board_header) as header_fh: last_ifndef = None @@ -347,7 +348,7 @@ def read_defines_from(header_file, defines_dict): raise Exception("{}:{} Include-guard #define {} is missing an #ifndef".format(board_header, lineno, name)) if value: raise Exception("{}:{} Include-guard #define {} shouldn't have a value".format(board_header, lineno, name)) - if len(defines) and not (len(defines) == 1 and defines[list(defines.keys())[0]].lineno < 0): + if any(defines[d].lineno >= 0 for d in defines): raise Exception("{}:{} Include-guard #define {} should be the first define".format(board_header, lineno, name)) if name == expected_include_guard: has_include_guard = True @@ -387,12 +388,15 @@ def read_defines_from(header_file, defines_dict): other_chip = 'RP2350' elif cmake_settings['PICO_PLATFORM'].value == "rp2350": other_chip = 'RP2040' - if 'PICO_RP2350A' in defines and defines['PICO_RP2350A'].resolved_value == 1: - chip = 'RP2350A' - else: - chip = 'RP2350B' if 'PICO_RP2350B' in defines: raise Exception("{} sets #define {} {} (should probably be #define {} {})".format(board_header, 'PICO_RP2350B', defines['PICO_RP2350B'].resolved_value, 'PICO_RP2350A', 1 - defines['PICO_RP2350B'].resolved_value)) + if 'PICO_RP2350A' not in defines: + raise Exception("{} has no #define for {} (set to 1 for RP2350A, or 0 for RP2350B)".format(board_header, 'PICO_RP2350A')) + else: + if defines['PICO_RP2350A'].resolved_value == 1: + chip = 'RP2350A' + else: + chip = 'RP2350B' if not board_header.endswith("amethyst_fpga.h"): if 'PICO_RP2350_A2_SUPPORTED' not in cmake_default_settings: raise Exception("{} uses chip {} but is missing a pico_cmake_set_default {} comment".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) From 701c1933aff2f3a767f6a76cc2982c0470c3a8c3 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Fri, 4 Apr 2025 17:36:32 +0100 Subject: [PATCH 107/224] Set default GATT path to CMAKE_CURRENT_LIST_DIR if not specified (#2385) This ensures the GATT_PATH variable is set to the calling directory when just a filename is provided with no path Fixes #2366 --- src/rp2_common/pico_btstack/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rp2_common/pico_btstack/CMakeLists.txt b/src/rp2_common/pico_btstack/CMakeLists.txt index 010cc9e39..dcfcad4fe 100644 --- a/src/rp2_common/pico_btstack/CMakeLists.txt +++ b/src/rp2_common/pico_btstack/CMakeLists.txt @@ -308,6 +308,9 @@ if (EXISTS ${PICO_BTSTACK_PATH}/${BTSTACK_TEST_PATH}) find_package (Python3 REQUIRED COMPONENTS Interpreter) get_filename_component(GATT_NAME "${GATT_FILE}" NAME_WE) get_filename_component(GATT_PATH "${GATT_FILE}" PATH) + if (NOT GATT_PATH) + set(GATT_PATH "${CMAKE_CURRENT_LIST_DIR}") + endif() set(TARGET_GATT "${TARGET_LIB}_gatt_header") set(GATT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/${TARGET_GATT}") set(GATT_HEADER "${GATT_BINARY_DIR}/${GATT_NAME}.h") From 5912699dd02317997303c1c6e4f325fbaf49d4b2 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Fri, 4 Apr 2025 17:39:39 +0100 Subject: [PATCH 108/224] Lots of small doxygen fixes (#2390) --- docs/index.h | 6 +-- .../pico_base_headers/include/pico/types.h | 24 +++++------ src/common/pico_time/include/pico/time.h | 6 +-- .../hardware_dma/include/hardware/dma.h | 2 +- .../hardware_gpio/include/hardware/gpio.h | 5 +++ .../hardware_i2c/include/hardware/i2c.h | 8 ++-- .../hardware_interp/include/hardware/interp.h | 2 +- .../hardware_pio/include/hardware/pio.h | 28 ++++++------- .../hardware_resets/include/hardware/resets.h | 42 ++++++++++++++++++- .../hardware_sha256/include/hardware/sha256.h | 2 +- .../hardware_spi/include/hardware/spi.h | 2 +- .../hardware_timer/include/hardware/timer.h | 12 +++--- .../include/pico/async_context.h | 8 ++-- .../pico_bootrom/include/pico/bootrom.h | 2 +- .../pico_cyw43_arch/include/pico/cyw43_arch.h | 18 ++++---- .../pico_multicore/include/pico/multicore.h | 8 ++-- src/rp2_common/pico_rand/include/pico/rand.h | 4 +- .../pico_stdio_usb/include/pico/stdio_usb.h | 2 +- 18 files changed, 112 insertions(+), 69 deletions(-) diff --git a/docs/index.h b/docs/index.h index b760936c8..a4f88a431 100644 --- a/docs/index.h +++ b/docs/index.h @@ -48,9 +48,9 @@ * \cond hardware_watchdog \defgroup hardware_watchdog hardware_watchdog \endcond * \cond hardware_xip_cache \defgroup hardware_xip_cache hardware_xip_cache \endcond * \cond hardware_xosc \defgroup hardware_xosc hardware_xosc \endcond - * \cond hardware_powman hardware_powman - * \cond hardware_hazard3 hardware_hazard3 - * \cond hardware_riscv hardware_riscv + * \cond hardware_powman \defgroup hardware_powman hardware_powman \endcond + * \cond hardware_hazard3 \defgroup hardware_hazard3 hardware_hazard3 \endcond + * \cond hardware_riscv \defgroup hardware_riscv hardware_riscv \endcond * @} * diff --git a/src/common/pico_base_headers/include/pico/types.h b/src/common/pico_base_headers/include/pico/types.h index 2e9c39642..010181eef 100644 --- a/src/common/pico_base_headers/include/pico/types.h +++ b/src/common/pico_base_headers/include/pico/types.h @@ -23,18 +23,18 @@ typedef unsigned int uint; #endif /*! \typedef absolute_time_t - \brief An opaque 64 bit timestamp in microseconds - - The type is used instead of a raw uint64_t to prevent accidentally passing relative times or times in the wrong - time units where an absolute time is required. - - note: As of SDK 2.0.0 this type defaults to being a uin64_t (i.e. no protection); it is enabled - by setting PICO_OPAQUE_ABSOLUTE_TIME_T to 1 - - \see to_us_since_boot() - \see update_us_since_boot() - \ingroup timestamp -*/ + * \brief An opaque 64 bit timestamp in microseconds + * + * The type is used instead of a raw uint64_t to prevent accidentally passing relative times or times in the wrong + * time units where an absolute time is required. + * + * note: As of SDK 2.0.0 this type defaults to being a uin64_t (i.e. no protection); it is enabled + * by setting PICO_OPAQUE_ABSOLUTE_TIME_T to 1 + * + * \see to_us_since_boot() + * \see update_us_since_boot() + * \ingroup timestamp + */ #if PICO_OPAQUE_ABSOLUTE_TIME_T typedef struct { uint64_t _private_us_since_boot; diff --git a/src/common/pico_time/include/pico/time.h b/src/common/pico_time/include/pico/time.h index 771fe42d6..43d5ed7a9 100644 --- a/src/common/pico_time/include/pico/time.h +++ b/src/common/pico_time/include/pico/time.h @@ -216,7 +216,7 @@ static inline bool is_nil_time(absolute_time_t t) { * \note These functions should not be called from an IRQ handler. * * \note Lower powered sleep requires use of the \link alarm_pool_get_default default alarm pool\endlink which may - * be disabled by the PICO_TIME_DEFAULT_ALARM_POOL_DISABLED #define or currently full in which case these functions + * be disabled by the PICO_TIME_DEFAULT_ALARM_POOL_DISABLED \#define or currently full in which case these functions * become busy waits instead. * * \note Whilst \a sleep_ functions are preferable to \a busy_wait functions from a power perspective, the \a busy_wait equivalent function @@ -420,7 +420,7 @@ alarm_pool_timer_t *alarm_pool_get_default_timer(void); * \param max_timers the maximum number of timers * \note For implementation reasons this is limited to PICO_PHEAP_MAX_ENTRIES which defaults to 255 * \sa alarm_pool_get_default() - * \sa hardware_claiming + * \sa hardware_claim */ static inline alarm_pool_t *alarm_pool_create(uint timer_alarm_num, uint max_timers) { return alarm_pool_create_on_timer(alarm_pool_get_default_timer(), timer_alarm_num, max_timers); @@ -443,7 +443,7 @@ alarm_pool_t *alarm_pool_create_on_timer_with_unused_hardware_alarm(alarm_pool_t * \param max_timers the maximum number of timers * \note For implementation reasons this is limited to PICO_PHEAP_MAX_ENTRIES which defaults to 255 * \sa alarm_pool_get_default() - * \sa hardware_claiming + * \sa hardware_claim */ static inline alarm_pool_t *alarm_pool_create_with_unused_hardware_alarm(uint max_timers) { return alarm_pool_create_on_timer_with_unused_hardware_alarm(alarm_pool_get_default_timer(), max_timers); diff --git a/src/rp2_common/hardware_dma/include/hardware/dma.h b/src/rp2_common/hardware_dma/include/hardware/dma.h index 94b74cb7f..27dd92286 100644 --- a/src/rp2_common/hardware_dma/include/hardware/dma.h +++ b/src/rp2_common/hardware_dma/include/hardware/dma.h @@ -123,7 +123,7 @@ int dma_claim_unused_channel(bool required); * \param channel the dma channel * \return true if the channel is claimed, false otherwise * \see dma_channel_claim - * \see dma_channel_claim_mask + * \see dma_claim_mask */ bool dma_channel_is_claimed(uint channel); diff --git a/src/rp2_common/hardware_gpio/include/hardware/gpio.h b/src/rp2_common/hardware_gpio/include/hardware/gpio.h index f6f089523..f05bc0002 100644 --- a/src/rp2_common/hardware_gpio/include/hardware/gpio.h +++ b/src/rp2_common/hardware_gpio/include/hardware/gpio.h @@ -204,6 +204,11 @@ enum gpio_irq_level { */ typedef void (*gpio_irq_callback_t)(uint gpio, uint32_t event_mask); +/*! \brief GPIO override modes + * \ingroup hardware_gpio + * + * \sa gpio_set_irqover, gpio_set_outover, gpio_set_inover, gpio_set_oeover + */ enum gpio_override { GPIO_OVERRIDE_NORMAL = 0, ///< peripheral signal selected via \ref gpio_set_function GPIO_OVERRIDE_INVERT = 1, ///< invert peripheral signal selected via \ref gpio_set_function diff --git a/src/rp2_common/hardware_i2c/include/hardware/i2c.h b/src/rp2_common/hardware_i2c/include/hardware/i2c.h index 604b89f98..5453752e8 100644 --- a/src/rp2_common/hardware_i2c/include/hardware/i2c.h +++ b/src/rp2_common/hardware_i2c/include/hardware/i2c.h @@ -324,10 +324,10 @@ int i2c_write_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t * (for example) without having to send address byte(s) repeatedly * * \param i2c Either \ref i2c0 or \ref i2c1 - * \param addr 7-bit address of device to read from - * \param dst Pointer to buffer to receive data - * \param len Length of data in bytes to receive - * \return Number of bytes read, or PICO_ERROR_GENERIC if address not acknowledged or no device present. + * \param addr 7-bit address of device to write to + * \param src Pointer to data to send + * \param len Length of data in bytes to send + * \return Number of bytes written, or PICO_ERROR_GENERIC if address not acknowledged or no device present. */ int i2c_write_burst_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len); diff --git a/src/rp2_common/hardware_interp/include/hardware/interp.h b/src/rp2_common/hardware_interp/include/hardware/interp.h index 634af0f46..befe1f8ca 100644 --- a/src/rp2_common/hardware_interp/include/hardware/interp.h +++ b/src/rp2_common/hardware_interp/include/hardware/interp.h @@ -107,7 +107,7 @@ void interp_unclaim_lane(interp_hw_t *interp, uint lane); */ bool interp_lane_is_claimed(interp_hw_t *interp, uint lane); -/*! \brief Release previously claimed interpolator lanes \see interp_claim_lane_mask +/*! \brief Release previously claimed interpolator lanes, see \ref interp_claim_lane_mask * \ingroup hardware_interp * * \param interp Interpolator on which to release lanes. interp0 or interp1 diff --git a/src/rp2_common/hardware_pio/include/hardware/pio.h b/src/rp2_common/hardware_pio/include/hardware/pio.h index b11733092..8654d32a7 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio.h @@ -680,7 +680,7 @@ static inline void sm_config_set_out_shift(pio_sm_config *c, bool shift_right, b * \ingroup sm_config * * \param c Pointer to the configuration structure to modify - * \param join Specifies the join type. \see enum pio_fifo_join + * \param join Specifies the join type. See \ref pio_fifo_join */ static inline void sm_config_set_fifo_join(pio_sm_config *c, enum pio_fifo_join join) { valid_params_if(HARDWARE_PIO, join == PIO_FIFO_JOIN_NONE || join == PIO_FIFO_JOIN_TX || join == PIO_FIFO_JOIN_RX @@ -720,7 +720,7 @@ static inline void sm_config_set_out_special(pio_sm_config *c, bool sticky, bool * \ingroup sm_config * * \param c Pointer to the configuration structure to modify - * \param status_sel the status operation selector. \see enum pio_mov_status_type + * \param status_sel the status operation selector. See \ref pio_mov_status_type * \param status_n parameter for the mov status operation (currently a bit count) */ static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_status_type status_sel, uint status_n) { @@ -849,7 +849,7 @@ static inline uint pio_get_index(PIO pio) { * * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 * \return the PIO instance number (0, 1, ...) - * \see gpio_function + * \see gpio_function_t */ static inline uint pio_get_funcsel(PIO pio) { check_pio_param(pio); @@ -948,7 +948,7 @@ bool pio_can_add_program_at_offset(PIO pio, const pio_program_t *program, uint o /*! \brief Attempt to load the program * \ingroup hardware_pio * - * \see pio_can_add_program() if you need to check whether the program can be loaded + * See pio_can_add_program() if you need to check whether the program can be loaded * * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 * \param program the program definition @@ -960,7 +960,7 @@ int pio_add_program(PIO pio, const pio_program_t *program); /*! \brief Attempt to load the program at the specified instruction memory offset * \ingroup hardware_pio * - * \see pio_can_add_program_at_offset() if you need to check whether the program can be loaded + * See pio_can_add_program_at_offset() if you need to check whether the program can be loaded * * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 * \param program the program definition @@ -998,7 +998,7 @@ void pio_clear_instruction_memory(PIO pio); * * The state machine is left disabled on return from this call. * -* * \if rp2350_specific + * \if rp2350_specific * See \ref sm_config_pins "sm_config_ pins" for more detail on why this method might fail on RP2350B * \endif * @@ -1006,7 +1006,7 @@ void pio_clear_instruction_memory(PIO pio); * \param sm State machine index (0..3) * \param initial_pc the initial program memory offset to run from * \param config the configuration to apply (or NULL to apply defaults) - * \return PICO_OK, or < 0 for an error (see \enum pico_error_codes) + * \return PICO_OK, or < 0 for an error (see \ref pico_error_codes) */ int pio_sm_init(PIO pio, uint sm, uint initial_pc, const pio_sm_config *config); @@ -1029,7 +1029,7 @@ static inline void pio_sm_set_enabled(PIO pio, uint sm, bool enabled) { * Note that this method just sets the enabled state of the state machine; * if now enabled they continue exactly from where they left off. * - * \see pio_enable_sm_mask_in_sync() if you wish to enable multiple state machines + * See pio_enable_sm_mask_in_sync() if you wish to enable multiple state machines * and ensure their clock dividers are in sync. * * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 @@ -1049,7 +1049,7 @@ static inline void pio_set_sm_mask_enabled(PIO pio, uint32_t mask, bool enabled) * Note that this method just sets the enabled state of the state machine; * if now enabled they continue exactly from where they left off. * - * \see pio_enable_sm_mask_in_sync() if you wish to enable multiple state machines + * See pio_enable_sm_mask_in_sync() if you wish to enable multiple state machines * and ensure their clock dividers are in sync. * * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 @@ -1419,7 +1419,7 @@ static inline uint8_t pio_sm_get_pc(PIO pio, uint sm) { * * This instruction is executed instead of the next instruction in the normal control flow on the state machine. * Subsequent calls to this method replace the previous executed - * instruction if it is still running. \see pio_sm_is_exec_stalled() to see if an executed instruction + * instruction if it is still running. See pio_sm_is_exec_stalled() to see if an executed instruction * is still running (i.e. it is stalled on some condition) * * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 @@ -1450,7 +1450,7 @@ static inline bool pio_sm_is_exec_stalled(PIO pio, uint sm) { * * This instruction is executed instead of the next instruction in the normal control flow on the state machine. * Subsequent calls to this method replace the previous executed - * instruction if it is still running. \see pio_sm_is_exec_stalled() to see if an executed instruction + * instruction if it is still running. See pio_sm_is_exec_stalled() to see if an executed instruction * is still running (i.e. it is stalled on some condition) * * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 @@ -1982,7 +1982,7 @@ bool pio_sm_is_claimed(PIO pio, uint sm); * \param sm Returns the index of the PIO state machine that was claimed * \param offset Returns the instruction memory offset of the start of the program * \return true on success, false otherwise - * \see pio_remove_program_unclaim_sm + * \see pio_remove_program_and_unclaim_sm */ bool pio_claim_free_sm_and_add_program(const pio_program_t *program, PIO *pio, uint *sm, uint *offset); @@ -1994,7 +1994,7 @@ bool pio_claim_free_sm_and_add_program(const pio_program_t *program, PIO *pio, u * PIO instance can interact with both pins 0->15 or 32->47 at the same time. * * This method takes additional information about the GPIO pins needed (via gpio_base and gpio_count), - * and optionally will set the GPIO base (\see pio_set_gpio_base) of an unused PIO instance if necessary + * and optionally will set the GPIO base (see \ref pio_set_gpio_base) of an unused PIO instance if necessary * * \param program PIO program to add * \param pio Returns the PIO hardware instance or NULL if no PIO is available @@ -2006,7 +2006,7 @@ bool pio_claim_free_sm_and_add_program(const pio_program_t *program, PIO *pio, u * instance, then that PIO will be reconfigured so that this method can succeed * * \return true on success, false otherwise - * \see pio_remove_program_unclaim_sm + * \see pio_remove_program_and_unclaim_sm */ bool pio_claim_free_sm_and_add_program_for_gpio_range(const pio_program_t *program, PIO *pio, uint *sm, uint *offset, uint gpio_base, uint gpio_count, bool set_gpio_base); diff --git a/src/rp2_common/hardware_resets/include/hardware/resets.h b/src/rp2_common/hardware_resets/include/hardware/resets.h index 8baef728b..f75775717 100644 --- a/src/rp2_common/hardware_resets/include/hardware/resets.h +++ b/src/rp2_common/hardware_resets/include/hardware/resets.h @@ -23,6 +23,8 @@ * * Multiple blocks are referred to using a bitmask as follows: * + * \if rp2040_specific + * For RP2040: * Block to reset | Bit * ---------------|---- * USB | 24 @@ -41,15 +43,51 @@ * PIO 1 | 11 * PIO 0 | 10 * Pads - QSPI | 9 - * Pads - bank 0 | 8 + * Pads - Bank 0 | 8 * JTAG | 7 - * IO Bank 1 | 6 + * IO QSPI | 6 * IO Bank 0 | 5 * I2C 1 | 4 * I2C 0 | 3 * DMA | 2 * Bus Control | 1 * ADC 0 | 0 + * \endif + * + * \if rp2350_specific + * For RP2350: + * Block to reset | Bit + * ---------------|---- + * USB | 28 + * UART 1 | 27 + * UART 0 | 26 + * TRNG | 25 + * Timer 1 | 24 + * Timer 0 | 23 + * TB Manager | 22 + * SysInfo | 21 + * System Config | 20 + * SPI 1 | 19 + * SPI 0 | 18 + * SHA256 | 17 + * PWM | 16 + * PLL USB | 15 + * PLL System | 14 + * PIO 2 | 13 + * PIO 1 | 12 + * PIO 0 | 11 + * Pads - QSPI | 10 + * Pads - Bank 0 | 9 + * JTAG | 8 + * IO QSPI | 7 + * IO Bank 0 | 6 + * I2C 1 | 5 + * I2C 0 | 4 + * HSTX | 3 + * DMA | 2 + * Bus Control | 1 + * ADC 0 | 0 + * \endif * * \subsection reset_example Example * \addtogroup hardware_resets diff --git a/src/rp2_common/hardware_sha256/include/hardware/sha256.h b/src/rp2_common/hardware_sha256/include/hardware/sha256.h index db8fca6ff..dcbf1043d 100644 --- a/src/rp2_common/hardware_sha256/include/hardware/sha256.h +++ b/src/rp2_common/hardware_sha256/include/hardware/sha256.h @@ -122,7 +122,7 @@ static inline bool sha256_is_sum_valid(void) { * \ingroup hardware_sha256 * * After writing 64 bytes of data to the hardware, it will be unable to accept more data for a time. - * Call this to check if the hardware is ready for more data to be written. \see sha256_err_not_ready + * Call this to check if the hardware is ready for more data to be written. See \ref sha256_err_not_ready * * \return True if the hardware is ready to receive more data */ diff --git a/src/rp2_common/hardware_spi/include/hardware/spi.h b/src/rp2_common/hardware_spi/include/hardware/spi.h index cf79645da..bd83770c1 100644 --- a/src/rp2_common/hardware_spi/include/hardware/spi.h +++ b/src/rp2_common/hardware_spi/include/hardware/spi.h @@ -202,7 +202,7 @@ uint spi_set_baudrate(spi_inst_t *spi, uint baudrate); /*! \brief Get SPI baudrate * \ingroup hardware_spi * - * Get SPI baudrate which was set by \see spi_set_baudrate + * Get SPI baudrate which was set by \ref spi_set_baudrate * * \param spi SPI instance specifier, either \ref spi0 or \ref spi1 * \return The actual baudrate set diff --git a/src/rp2_common/hardware_timer/include/hardware/timer.h b/src/rp2_common/hardware_timer/include/hardware/timer.h index 289a28a34..b26964083 100644 --- a/src/rp2_common/hardware_timer/include/hardware/timer.h +++ b/src/rp2_common/hardware_timer/include/hardware/timer.h @@ -351,7 +351,7 @@ typedef void (*hardware_alarm_callback_t)(uint alarm_num); * \param timer the timer instance * \param alarm_num the hardware alarm to claim * \sa hardware_alarm_claim - * \sa hardware_claiming + * \sa hardware_claim */ void timer_hardware_alarm_claim(timer_hw_t *timer, uint alarm_num); @@ -362,7 +362,7 @@ void timer_hardware_alarm_claim(timer_hw_t *timer, uint alarm_num); * * \param alarm_num the hardware alarm to claim * \sa timer_hardware_alarm_claim - * \sa hardware_claiming + * \sa hardware_claim */ void hardware_alarm_claim(uint alarm_num); @@ -375,7 +375,7 @@ void hardware_alarm_claim(uint alarm_num); * \param required if true the function will panic if none are available * \return alarm_num the hardware alarm claimed or -1 if required was false, and none are available * \sa hardware_alarm_claim_unused - * \sa hardware_claiming + * \sa hardware_claim */ int timer_hardware_alarm_claim_unused(timer_hw_t *timer, bool required); @@ -387,7 +387,7 @@ int timer_hardware_alarm_claim_unused(timer_hw_t *timer, bool required); * \param required if true the function will panic if none are available * \return alarm_num the hardware alarm claimed or -1 if required was false, and none are available * \sa timer_hardware_alarm_claim_unused - * \sa hardware_claiming + * \sa hardware_claim */ int hardware_alarm_claim_unused(bool required); @@ -397,7 +397,7 @@ int hardware_alarm_claim_unused(bool required); * \param timer the timer instance * \param alarm_num the hardware alarm to unclaim * \sa hardware_alarm_unclaim - * \sa hardware_claiming + * \sa hardware_claim */ void timer_hardware_alarm_unclaim(timer_hw_t *timer, uint alarm_num); @@ -406,7 +406,7 @@ void timer_hardware_alarm_unclaim(timer_hw_t *timer, uint alarm_num); * * \param alarm_num the hardware alarm to unclaim * \sa timer_hardware_alarm_unclaim - * \sa hardware_claiming + * \sa hardware_claim */ void hardware_alarm_unclaim(uint alarm_num); diff --git a/src/rp2_common/pico_async_context/include/pico/async_context.h b/src/rp2_common/pico_async_context/include/pico/async_context.h index 6f7c4f0dc..8a19b9ca3 100644 --- a/src/rp2_common/pico_async_context/include/pico/async_context.h +++ b/src/rp2_common/pico_async_context/include/pico/async_context.h @@ -84,8 +84,8 @@ typedef struct async_context async_context_t; * A "timeout" represents some future action that must be taken at a specific time. * Its methods are called from the async_context under lock at the given time * - * \see async_context_add_worker_at - * \see async_context_add_worker_in_ms + * \see async_context_add_at_time_worker_at + * \see async_context_add_at_time_worker_in_ms */ typedef struct async_work_on_timeout { /*! @@ -119,8 +119,8 @@ typedef struct async_work_on_timeout { * to some external stimulus (usually an IRQ). * Its methods are called from the async_context under lock at the given time * - * \see async_context_add_worker_at - * \see async_context_add_worker_in_ms + * \see async_context_add_at_time_worker_at + * \see async_context_add_at_time_worker_in_ms */ typedef struct async_when_pending_worker { /*! diff --git a/src/rp2_common/pico_bootrom/include/pico/bootrom.h b/src/rp2_common/pico_bootrom/include/pico/bootrom.h index 76ef30300..db2f23d28 100644 --- a/src/rp2_common/pico_bootrom/include/pico/bootrom.h +++ b/src/rp2_common/pico_bootrom/include/pico/bootrom.h @@ -750,7 +750,7 @@ static inline int rom_load_partition_table(uint8_t *workarea_base, uint32_t work * NOTE: This method does not look at owner partitions, only the A partition passed and it's corresponding B partition. * * NOTE: You should not call this method directly when performing a Flash Update Boot before calling `explicit_buy`, as it may prevent - * any version downgrade from occuring - instead \see rom_pick_ab_update_partition() which wraps this function. + * any version downgrade from occuring - instead see \ref rom_pick_ab_update_partition() which wraps this function. * * \param workarea_base base address of work area * \param workarea_size size of work area diff --git a/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h b/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h index 46aa09896..5eb43d1b3 100644 --- a/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h +++ b/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h @@ -59,7 +59,7 @@ extern "C" { * * As of right now, lwIP is the only supported TCP/IP stack, however the use of \c pico_cyw43_arch is intended to be independent of * the particular TCP/IP stack used (and possibly Bluetooth stack used) in the future. For this reason, the integration of lwIP - * is handled in the base (\c pico_cyw43_arch) library based on the #define \ref CYW43_LWIP used by the \c cyw43_driver. + * is handled in the base (\c pico_cyw43_arch) library based on the \#define \ref CYW43_LWIP used by the \c cyw43_driver. * * \note As of version 1.5.0 of the Raspberry Pi Pico SDK, the \c pico_cyw43_arch library no longer directly implements * the distinct behavioral abstractions. This is now handled by the more general \ref pico_async_context library. The @@ -169,7 +169,7 @@ extern "C" { * \ref cyw43_arch_init_default_async_context, however the user can specify use of their own async_context * by calling \ref cyw43_arch_set_async_context() before calling this method * - * \return 0 if the initialization is successful, an error code otherwise \see pico_error_codes + * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes */ int cyw43_arch_init(void); @@ -186,7 +186,7 @@ int cyw43_arch_init(void); * by calling \ref cyw43_arch_set_async_context() before calling this method * * \param country the country code to use (see \ref CYW43_COUNTRY_) - * \return 0 if the initialization is successful, an error code otherwise \see pico_error_codes + * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes */ int cyw43_arch_init_with_country(uint32_t country); @@ -399,7 +399,7 @@ void cyw43_arch_disable_ap_mode(void); * \param auth the authorization type to use when the password is enabled. Values are \ref CYW43_AUTH_WPA_TKIP_PSK, * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * - * \return 0 if the initialization is successful, an error code otherwise \see pico_error_codes + * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes */ int cyw43_arch_wifi_connect_blocking(const char *ssid, const char *pw, uint32_t auth); @@ -413,7 +413,7 @@ int cyw43_arch_wifi_connect_blocking(const char *ssid, const char *pw, uint32_t * \param auth the authorization type to use when the password is enabled. Values are \ref CYW43_AUTH_WPA_TKIP_PSK, * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * - * \return 0 if the initialization is successful, an error code otherwise \see pico_error_codes + * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes */ int cyw43_arch_wifi_connect_bssid_blocking(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth); @@ -427,7 +427,7 @@ int cyw43_arch_wifi_connect_bssid_blocking(const char *ssid, const uint8_t *bssi * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * \param timeout how long to wait in milliseconds for a connection to succeed before giving up * - * \return 0 if the initialization is successful, an error code otherwise \see pico_error_codes + * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes */ int cyw43_arch_wifi_connect_timeout_ms(const char *ssid, const char *pw, uint32_t auth, uint32_t timeout); @@ -442,7 +442,7 @@ int cyw43_arch_wifi_connect_timeout_ms(const char *ssid, const char *pw, uint32_ * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * \param timeout how long to wait in milliseconds for a connection to succeed before giving up * - * \return 0 if the initialization is successful, an error code otherwise \see pico_error_codes + * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes */ int cyw43_arch_wifi_connect_bssid_timeout_ms(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth, uint32_t timeout); @@ -458,7 +458,7 @@ int cyw43_arch_wifi_connect_bssid_timeout_ms(const char *ssid, const uint8_t *bs * \param auth the authorization type to use when the password is enabled. Values are \ref CYW43_AUTH_WPA_TKIP_PSK, * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * - * \return 0 if the scan was started successfully, an error code otherwise \see pico_error_codes + * \return 0 if the scan was started successfully, an error code otherwise see \ref pico_error_codes */ int cyw43_arch_wifi_connect_async(const char *ssid, const char *pw, uint32_t auth); @@ -475,7 +475,7 @@ int cyw43_arch_wifi_connect_async(const char *ssid, const char *pw, uint32_t aut * \param auth the authorization type to use when the password is enabled. Values are \ref CYW43_AUTH_WPA_TKIP_PSK, * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * - * \return 0 if the scan was started successfully, an error code otherwise \see pico_error_codes + * \return 0 if the scan was started successfully, an error code otherwise see \ref pico_error_codes */ int cyw43_arch_wifi_connect_bssid_async(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth); diff --git a/src/rp2_common/pico_multicore/include/pico/multicore.h b/src/rp2_common/pico_multicore/include/pico/multicore.h index 5eb49ddce..9b4622a98 100644 --- a/src/rp2_common/pico_multicore/include/pico/multicore.h +++ b/src/rp2_common/pico_multicore/include/pico/multicore.h @@ -151,7 +151,7 @@ static inline bool multicore_fifo_rvalid(void) { * * See the note in the \ref multicore_fifo section for considerations regarding use of the inter-core FIFOs * - * @return true if the FIFO has room for more data, false otherwise + * \return true if the FIFO has room for more data, false otherwise */ static inline bool multicore_fifo_wready(void) { return sio_hw->fifo_st & SIO_FIFO_ST_RDY_BITS; @@ -316,7 +316,7 @@ static inline void check_doorbell_num_param(__unused uint doorbell_num) { * * \param doorbell_num the doorbell number to claim * \param core_mask 0b01: core 0, 0b10: core 1, 0b11 both core 0 and core 1 - * \sa hardware_claiming + * \sa hardware_claim */ void multicore_doorbell_claim(uint doorbell_num, uint core_mask); @@ -328,7 +328,7 @@ void multicore_doorbell_claim(uint doorbell_num, uint core_mask); * \param core_mask 0b01: core 0, 0b10: core 1, 0b11 both core 0 and core 1 * \param required if true the function will panic if none are available * \return the doorbell number claimed or -1 if required was false, and none are available - * \sa hardware_claiming + * \sa hardware_claim */ int multicore_doorbell_claim_unused(uint core_mask, bool required); @@ -337,7 +337,7 @@ int multicore_doorbell_claim_unused(uint core_mask, bool required); * * \param doorbell_num the doorbell number to unclaim * \param core_mask 0b01: core 0, 0b10: core 1, 0b11 both core 0 and core 1 - * \sa hardware_claiming + * \sa hardware_claim */ void multicore_doorbell_unclaim(uint doorbell_num, uint core_mask); diff --git a/src/rp2_common/pico_rand/include/pico/rand.h b/src/rp2_common/pico_rand/include/pico/rand.h index b0a337f24..e3bbe2df8 100644 --- a/src/rp2_common/pico_rand/include/pico/rand.h +++ b/src/rp2_common/pico_rand/include/pico/rand.h @@ -25,7 +25,7 @@ extern "C" { * The random numbers (32 to 128 bit) to be supplied are read from the PRNG which is used * to help provide a large number space. * - * The following (multiple) sources of entropy are available (of varying quality), each enabled by a #define: + * The following (multiple) sources of entropy are available (of varying quality), each enabled by a \#define: * * - The Ring Oscillator (ROSC) (\ref PICO_RAND_ENTROPY_SRC_ROSC == 1): * \ref PICO_RAND_ROSC_BIT_SAMPLE_COUNT bits are gathered from the ring oscillator "random bit" and mixed in each @@ -47,7 +47,7 @@ extern "C" { * - Time (\ref PICO_RAND_SEED_ENTROPY_SRC_TIME == 1): The 64-bit microsecond timer is mixed into the seed. * - Board Identifier (PICO_RAND_SEED_ENTROPY_SRC_BOARD_ID == 1): The board id via \ref pico_get_unique_board_id * is mixed into the seed. - * - RAM hash (\ref PICO_RAND_SEED_ENTROPY_SRC_RAM_HASH (\ref PICO_RAND_SEED_ENTROPY_SRC_RAM_HASH): The hashed contents of a + * - RAM hash (\ref PICO_RAND_SEED_ENTROPY_SRC_RAM_HASH): The hashed contents of a * subset of RAM are mixed in. Initial RAM contents are undefined on power up, so provide a reasonable source of entropy. * By default the last 1K of RAM (which usually contains the core 0 stack) is hashed, which may also provide for differences * after each warm reset. diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index c487f96ab..9e6575a30 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -197,7 +197,7 @@ bool stdio_usb_connected(void); /*! \brief Explicitly calls the registered USB stdio chars_available_callback * \ingroup pico_stdio_usb * - * \ref This method is normally called by the internal USB stdio background thread when there is new USB CDC + * This method is normally called by the internal USB stdio background thread when there is new USB CDC * data available to read. However, if the internal background thread is disabled (e.g. when the user * directly links tinyUSB), the user will need to implement their own background thread and call this * method directly. From 950a68f80ee5783d63baa4155a98d896723e0c77 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 4 Apr 2025 13:18:28 -0500 Subject: [PATCH 109/224] define __force_inline in host compiles (#2396) --- src/host/pico_platform/include/pico/platform.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/host/pico_platform/include/pico/platform.h b/src/host/pico_platform/include/pico/platform.h index 2854ab6f7..0338354e5 100644 --- a/src/host/pico_platform/include/pico/platform.h +++ b/src/host/pico_platform/include/pico/platform.h @@ -60,6 +60,12 @@ extern void tight_loop_contents(); #define __noinline __attribute__((noinline)) #endif +#ifndef __force_inline +// don't think it is critical to inline in host mode, and this is simpler than picking the +// correct attribute incantation for always_inline on different compiler versions +#define __force_inline inline +#endif + #ifndef __aligned #define __aligned(x) __attribute__((aligned(x))) #endif From 93ea2616778149cf862fa8cbde4ab284d81a546e Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Sat, 5 Apr 2025 21:43:06 -0700 Subject: [PATCH 110/224] Force inline critical_section_{enter,exit} (#2393) Otherwise it may end up in flash when we want it to follow the caller's placement (maybe in RAM.) --- src/common/pico_sync/include/pico/critical_section.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/pico_sync/include/pico/critical_section.h b/src/common/pico_sync/include/pico/critical_section.h index 0e9907a9c..9874f9fff 100644 --- a/src/common/pico_sync/include/pico/critical_section.h +++ b/src/common/pico_sync/include/pico/critical_section.h @@ -7,6 +7,7 @@ #ifndef _PICO_CRITICAL_SECTION_H #define _PICO_CRITICAL_SECTION_H +#include "pico.h" #include "pico/lock_core.h" #ifdef __cplusplus @@ -58,7 +59,7 @@ void critical_section_init_with_lock_num(critical_section_t *crit_sec, uint lock * * \param crit_sec Pointer to critical_section structure */ -static inline void critical_section_enter_blocking(critical_section_t *crit_sec) { +__force_inline static void critical_section_enter_blocking(critical_section_t *crit_sec) { crit_sec->save = spin_lock_blocking(crit_sec->spin_lock); } @@ -67,7 +68,7 @@ static inline void critical_section_enter_blocking(critical_section_t *crit_sec) * * \param crit_sec Pointer to critical_section structure */ -static inline void critical_section_exit(critical_section_t *crit_sec) { +__force_inline static void critical_section_exit(critical_section_t *crit_sec) { spin_unlock(crit_sec->spin_lock, crit_sec->save); } From d47c0c89ce247b1736c5916a06af7ec0843ff50c Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:14:02 +0100 Subject: [PATCH 111/224] Update mbedtls, lwip and cyw43-driver (#2405) * Update LwIP to 2.2.1 * Update to mbedtls to 3.6.1 * Update lib/cyw43-driver to 1.1.0 * Support using a more recent version of mbedtls altcp_tls_mbedtls.c is not compatible with mbedtls 3.x so use a patched version until this is resolved. * Make sure MBEDTLS_VERSION_MAJOR is visible to LwIP. * Test mbedtls in kitchen sink * Add mbedtls to bazel --- .github/workflows/cmake.yml | 2 +- MODULE.bazel | 11 +- bazel/config/BUILD.bazel | 6 + bazel/constraint/BUILD.bazel | 6 + bazel/util/transition.bzl | 2 + docs/index.h | 1 + lib/cyw43-driver | 2 +- lib/lwip | 2 +- lib/mbedtls | 2 +- src/cmake/rp2_common.cmake | 2 +- src/rp2_common/pico_btstack/CMakeLists.txt | 1 + .../pico_cyw43_driver/CMakeLists.txt | 1 + src/rp2_common/pico_lwip/BUILD.bazel | 9 +- src/rp2_common/pico_lwip/CMakeLists.txt | 18 +- src/rp2_common/pico_lwip/altcp_tls_mbedtls.c | 1401 +++++++++++++++++ src/rp2_common/pico_lwip/lwip.BUILD | 22 +- src/rp2_common/pico_mbedtls/BUILD.bazel | 21 +- src/rp2_common/pico_mbedtls/CMakeLists.txt | 307 ++-- src/rp2_common/pico_mbedtls/doc.h | 11 + .../include/pico_mbedtls_config.h | 3 + src/rp2_common/pico_mbedtls/mbedtls.BUILD | 23 + src/rp2_common/pico_mbedtls/pico_mbedtls.c | 3 +- src/rp2_common/tinyusb/CMakeLists.txt | 1 + test/kitchen_sink/BUILD.bazel | 7 + test/kitchen_sink/lwipopts.h | 8 +- test/kitchen_sink/mbedtls_config.h | 1 + tools/compare_build_systems.py | 1 + 27 files changed, 1724 insertions(+), 150 deletions(-) create mode 100644 src/rp2_common/pico_lwip/altcp_tls_mbedtls.c create mode 100644 src/rp2_common/pico_mbedtls/doc.h create mode 100644 src/rp2_common/pico_mbedtls/include/pico_mbedtls_config.h create mode 100644 src/rp2_common/pico_mbedtls/mbedtls.BUILD diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 28ee68bd6..75ce8324e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init + run: git submodule update --init --recursive - name: Create Build Environment # Some projects don't allow in-source building, so create a separate build directory diff --git a/MODULE.bazel b/MODULE.bazel index d3afd78ff..1cc03bd1a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -106,7 +106,7 @@ new_git_repository( new_git_repository( name = "cyw43-driver", build_file = "//src/rp2_common/pico_cyw43_driver:cyw43-driver.BUILD", - commit = "c1075d4bc440422cf2b2fd12c64a1f53f77660ee", # keep-in-sync-with-submodule: lib/cyw43-driver + commit = "dd7568229f3bf7a37737b9e1ef250c26efe75b23", # keep-in-sync-with-submodule: lib/cyw43-driver remote = "https://github.com/georgerobotics/cyw43-driver.git", ) @@ -114,10 +114,17 @@ new_git_repository( new_git_repository( name = "lwip", build_file = "//src/rp2_common/pico_lwip:lwip.BUILD", - commit = "0a0452b2c39bdd91e252aef045c115f88f6ca773", # keep-in-sync-with-submodule: lib/lwip + commit = "77dcd25a72509eb83f72b033d219b1d40cd8eb95", # keep-in-sync-with-submodule: lib/lwip remote = "https://github.com/lwip-tcpip/lwip.git", ) +new_git_repository( + name = "mbedtls", + build_file = "//src/rp2_common/pico_mbedtls:mbedtls.BUILD", + commit = "107ea89daaefb9867ea9121002fbbdf926780e98", # keep-in-sync-with-submodule: lib/mbedtls + remote = "https://github.com/Mbed-TLS/mbedtls.git", +) + register_toolchains( "//bazel/toolchain:linux-aarch64-rp2040", "//bazel/toolchain:linux-aarch64-rp2350", diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index 3d75654eb..ac6dc387a 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -294,3 +294,9 @@ label_flag( name = "PICO_FREERTOS_LIB", build_setting_default = "//bazel:empty_cc_lib", ) + +# PICO_BAZEL_CONFIG: PICO_MBEDTL_CONFIG, [Bazel only] The cc_library that provides mbedtls_config.h, default=//bazel:empty_cc_lib, group=pico_mbedtls +label_flag( + name = "PICO_MBEDTLS_CONFIG", + build_setting_default = "//bazel:empty_cc_lib", +) diff --git a/bazel/constraint/BUILD.bazel b/bazel/constraint/BUILD.bazel index a4fe918b8..3ce282065 100644 --- a/bazel/constraint/BUILD.bazel +++ b/bazel/constraint/BUILD.bazel @@ -252,3 +252,9 @@ label_flag_matches( flag = "//bazel/config:PICO_FREERTOS_LIB", value = "//bazel:empty_cc_lib", ) + +label_flag_matches( + name = "pico_mbedtls_config_unset", + flag = "//bazel/config:PICO_MBEDTLS_CONFIG", + value = "//bazel:empty_cc_lib", +) diff --git a/bazel/util/transition.bzl b/bazel/util/transition.bzl index 67f0d616e..aa943d602 100644 --- a/bazel/util/transition.bzl +++ b/bazel/util/transition.bzl @@ -114,6 +114,7 @@ kitchen_sink_test_binary = declare_transtion( attrs = { "bt_stack_config": attr.label(mandatory = True), "lwip_config": attr.label(mandatory = True), + "mbedtls_config": attr.label(mandatory = True), "enable_ble": attr.bool(default = False), "enable_bt_classic": attr.bool(default = False), # This could be shared, but we don't in order to make it clearer that @@ -127,6 +128,7 @@ kitchen_sink_test_binary = declare_transtion( "@pico-sdk//bazel/config:PICO_LWIP_CONFIG": "lwip_config", "@pico-sdk//bazel/config:PICO_BT_ENABLE_BLE": "enable_ble", "@pico-sdk//bazel/config:PICO_BT_ENABLE_CLASSIC": "enable_bt_classic", + "@pico-sdk//bazel/config:PICO_MBEDTLS_CONFIG": "mbedtls_config", }, ) diff --git a/docs/index.h b/docs/index.h index a4f88a431..be52f6a0d 100644 --- a/docs/index.h +++ b/docs/index.h @@ -80,6 +80,7 @@ * \defgroup tinyusb_device tinyusb_device * \defgroup tinyusb_host tinyusb_host * \endcond + * \cond pico_mbedtls \defgroup pico_mbedtls pico_mbedtls \endcond * @} * * \defgroup networking Networking Libraries diff --git a/lib/cyw43-driver b/lib/cyw43-driver index c1075d4bc..dd7568229 160000 --- a/lib/cyw43-driver +++ b/lib/cyw43-driver @@ -1 +1 @@ -Subproject commit c1075d4bc440422cf2b2fd12c64a1f53f77660ee +Subproject commit dd7568229f3bf7a37737b9e1ef250c26efe75b23 diff --git a/lib/lwip b/lib/lwip index 0a0452b2c..77dcd25a7 160000 --- a/lib/lwip +++ b/lib/lwip @@ -1 +1 @@ -Subproject commit 0a0452b2c39bdd91e252aef045c115f88f6ca773 +Subproject commit 77dcd25a72509eb83f72b033d219b1d40cd8eb95 diff --git a/lib/mbedtls b/lib/mbedtls index 5a764e555..107ea89da 160000 --- a/lib/mbedtls +++ b/lib/mbedtls @@ -1 +1 @@ -Subproject commit 5a764e5555c64337ed17444410269ff21cb617b1 +Subproject commit 107ea89daaefb9867ea9121002fbbdf926780e98 diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index 9e6f9f3fa..c02f9e2ca 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -127,9 +127,9 @@ if (NOT PICO_BARE_METAL) pico_add_subdirectory(rp2_common/pico_async_context) pico_add_subdirectory(rp2_common/pico_btstack) pico_add_subdirectory(rp2_common/pico_cyw43_driver) + pico_add_subdirectory(rp2_common/pico_mbedtls) pico_add_subdirectory(rp2_common/pico_lwip) pico_add_subdirectory(rp2_common/pico_cyw43_arch) - pico_add_subdirectory(rp2_common/pico_mbedtls) pico_add_subdirectory(rp2_common/pico_time_adapter) diff --git a/src/rp2_common/pico_btstack/CMakeLists.txt b/src/rp2_common/pico_btstack/CMakeLists.txt index dcfcad4fe..7c277bd67 100644 --- a/src/rp2_common/pico_btstack/CMakeLists.txt +++ b/src/rp2_common/pico_btstack/CMakeLists.txt @@ -1,3 +1,4 @@ +# PICO_CMAKE_CONFIG: PICO_BTSTACK_PATH, Path to an alternative version of btstack overriding the version in pico-sdk/libs/btstack. Can be passed to cmake or set in your environment, type=string, group=pico_btstack if (DEFINED ENV{PICO_BTSTACK_PATH} AND (NOT PICO_BTSTACK_PATH)) set(PICO_BTSTACK_PATH $ENV{PICO_BTSTACK_PATH}) message("Using PICO_BTSTACK_PATH from environment ('${PICO_BTSTACK_PATH}')") diff --git a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt index 289a22ab4..13ac2043c 100644 --- a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt +++ b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt @@ -1,3 +1,4 @@ +# PICO_CMAKE_CONFIG: PICO_CYW43_DRIVER_PATH, Path to an alternative version of cyw43-driver overriding the version in pico-sdk/libs/cyw43-driver, type=string, group=pico_cyw43_driver if (DEFINED ENV{PICO_CYW43_DRIVER_PATH} AND (NOT PICO_CYW43_DRIVER_PATH)) set(PICO_CYW43_DRIVER_PATH $ENV{PICO_CYW43_DRIVER_PATH}) message("Using PICO_CYW43_DRIVER_PATH from environment ('${PICO_CYW43_DRIVER_PATH}')") diff --git a/src/rp2_common/pico_lwip/BUILD.bazel b/src/rp2_common/pico_lwip/BUILD.bazel index c98ff92a2..cc5de44c8 100644 --- a/src/rp2_common/pico_lwip/BUILD.bazel +++ b/src/rp2_common/pico_lwip/BUILD.bazel @@ -131,14 +131,15 @@ alias( actual = "@lwip//:pico_lwip_tftp", ) -alias( +cc_library( name = "pico_lwip_mbedtls", - actual = "@lwip//:pico_lwip_mbedtls", + srcs = ["altcp_tls_mbedtls.c"], + deps = ["@lwip//:pico_lwip_mbedtls"], ) alias( - name = "pico_lwip_mqttt", - actual = "@lwip//:pico_lwip_mqttt", + name = "pico_lwip_mqtt", + actual = "@lwip//:pico_lwip_mqtt", ) alias( diff --git a/src/rp2_common/pico_lwip/CMakeLists.txt b/src/rp2_common/pico_lwip/CMakeLists.txt index e412f3727..42dd1dfd7 100644 --- a/src/rp2_common/pico_lwip/CMakeLists.txt +++ b/src/rp2_common/pico_lwip/CMakeLists.txt @@ -1,3 +1,4 @@ +# PICO_CMAKE_CONFIG: PICO_LWIP_PATH, Path to an alternative version of lwip overriding the version in pico-sdk/libs/lwip. Can be passed to cmake or set in your environment, type=string, group=pico_lwip if (DEFINED ENV{PICO_LWIP_PATH} AND (NOT PICO_LWIP_PATH)) set(PICO_LWIP_PATH $ENV{PICO_LWIP_PATH}) message("Using PICO_LWIP_PATH from environment ('${PICO_LWIP_PATH}')") @@ -234,14 +235,29 @@ if (EXISTS ${PICO_LWIP_PATH}/${LWIP_TEST_PATH}) ${PICO_LWIP_PATH}/src/apps/tftp/tftp.c ) + # Mbed TLS files pico_add_library(pico_lwip_mbedtls NOFLAG) target_sources(pico_lwip_mbedtls INTERFACE - ${PICO_LWIP_PATH}/src/apps/altcp_tls/altcp_tls_mbedtls.c ${PICO_LWIP_PATH}/src/apps/altcp_tls/altcp_tls_mbedtls_mem.c ${PICO_LWIP_PATH}/src/apps/snmp/snmpv3_mbedtls.c ) + # altcp_tls_mbedtls.c is not compatible with mbedtls 3.x so use a patched version until this is resolved + # See https://savannah.nongnu.org/patch/index.php?10448 + if (MBEDTLS_VERSION_MAJOR AND MBEDTLS_VERSION_MAJOR GREATER_EQUAL 3) + target_sources(pico_lwip_mbedtls INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/altcp_tls_mbedtls.c + ) + target_include_directories(pico_lwip_mbedtls INTERFACE + ${PICO_LWIP_PATH}/src/apps/altcp_tls + ) + else() + target_sources(pico_lwip_mbedtls INTERFACE + ${PICO_LWIP_PATH}/src/apps/altcp_tls/altcp_tls_mbedtls.c + ) + endif() + # MQTT client files pico_add_library(pico_lwip_mqtt NOFLAG) target_sources(pico_lwip_mqtt INTERFACE diff --git a/src/rp2_common/pico_lwip/altcp_tls_mbedtls.c b/src/rp2_common/pico_lwip/altcp_tls_mbedtls.c new file mode 100644 index 000000000..669379db9 --- /dev/null +++ b/src/rp2_common/pico_lwip/altcp_tls_mbedtls.c @@ -0,0 +1,1401 @@ +/** + * @file + * Application layered TCP/TLS connection API (to be used from TCPIP thread) + * + * This file provides a TLS layer using mbedTLS + * + * This version is currently compatible with the 2.x.x branch (current LTS). + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + * Watch out: + * - 'sent' is always called with len==0 to the upper layer. This is because keeping + * track of the ratio of application data and TLS overhead would be too much. + * + * Mandatory security-related configuration: + * - ensure to add at least one strong entropy source to your mbedtls port (implement + * mbedtls_platform_entropy_poll or mbedtls_hardware_poll providing strong entropy) + * - define ALTCP_MBEDTLS_ENTROPY_PTR and ALTCP_MBEDTLS_ENTROPY_LEN to something providing + * GOOD custom entropy + * + * Missing things / @todo: + * - some unhandled/untested things might be caught by LWIP_ASSERTs... + */ + +#include "lwip/opt.h" +#include "lwip/sys.h" + +#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/apps/altcp_tls_mbedtls_opts.h" + +#if LWIP_ALTCP_TLS && LWIP_ALTCP_TLS_MBEDTLS + +#include "lwip/altcp.h" +#include "lwip/altcp_tls.h" +#include "lwip/priv/altcp_priv.h" + +#include "altcp_tls_mbedtls_structs.h" +#include "altcp_tls_mbedtls_mem.h" + +/* @todo: which includes are really needed? */ +#include "mbedtls/entropy.h" +#include "mbedtls/ctr_drbg.h" +#if MBEDTLS_VERSION_MAJOR < 3 +#include "mbedtls/certs.h" +#endif +#include "mbedtls/x509.h" +#include "mbedtls/ssl.h" +#include "mbedtls/net_sockets.h" +#include "mbedtls/error.h" +#include "mbedtls/debug.h" +#include "mbedtls/platform.h" +#include "mbedtls/memory_buffer_alloc.h" +#include "mbedtls/ssl_cache.h" +#include "mbedtls/ssl_ticket.h" + +#if MBEDTLS_VERSION_MAJOR < 3 +#include "mbedtls/ssl_internal.h" /* to call mbedtls_flush_output after ERR_MEM */ +#else +int mbedtls_ssl_flush_output(mbedtls_ssl_context *ssl); +size_t mbedtls_ssl_get_output_max_frag_len(const mbedtls_ssl_context *ssl); +#endif + +#include + +#ifndef ALTCP_MBEDTLS_ENTROPY_PTR +#define ALTCP_MBEDTLS_ENTROPY_PTR NULL +#endif +#ifndef ALTCP_MBEDTLS_ENTROPY_LEN +#define ALTCP_MBEDTLS_ENTROPY_LEN 0 +#endif +#ifndef ALTCP_MBEDTLS_RNG_FN +#define ALTCP_MBEDTLS_RNG_FN mbedtls_entropy_func +#endif + +/* Variable prototype, the actual declaration is at the end of this file + since it contains pointers to static functions declared here */ +extern const struct altcp_functions altcp_mbedtls_functions; + +/** Our global mbedTLS configuration (server-specific, not connection-specific) */ +struct altcp_tls_config { + mbedtls_ssl_config conf; + mbedtls_x509_crt *cert; + mbedtls_pk_context *pkey; + u8_t cert_count; + u8_t cert_max; + u8_t pkey_count; + u8_t pkey_max; + mbedtls_x509_crt *ca; +#if defined(MBEDTLS_SSL_CACHE_C) && ALTCP_MBEDTLS_USE_SESSION_CACHE + /** Inter-connection cache for fast connection startup */ + struct mbedtls_ssl_cache_context cache; +#endif +#if defined(MBEDTLS_SSL_SESSION_TICKETS) && ALTCP_MBEDTLS_USE_SESSION_TICKETS + mbedtls_ssl_ticket_context ticket_ctx; +#endif +}; + +/** Entropy and random generator are shared by all mbedTLS configuration */ +struct altcp_tls_entropy_rng { + mbedtls_entropy_context entropy; + mbedtls_ctr_drbg_context ctr_drbg; + int ref; +}; +static struct altcp_tls_entropy_rng *altcp_tls_entropy_rng; + +static err_t altcp_mbedtls_lower_recv(void *arg, struct altcp_pcb *inner_conn, struct pbuf *p, err_t err); +static err_t altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_conn); +static err_t altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *state); +static err_t altcp_mbedtls_handle_rx_appldata(struct altcp_pcb *conn, altcp_mbedtls_state_t *state); +static int altcp_mbedtls_bio_send(void *ctx, const unsigned char *dataptr, size_t size); + + +static void +altcp_mbedtls_flush_output(altcp_mbedtls_state_t* state) +{ + int flushed = mbedtls_ssl_flush_output(&state->ssl_context); + if (flushed) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_flush_output failed: %d\n", flushed)); + } +} + +/* callback functions from inner/lower connection: */ + +/** Accept callback from lower connection (i.e. TCP) + * Allocate one of our structures, assign it to the new connection's 'state' and + * call the new connection's 'accepted' callback. If that succeeds, we wait + * to receive connection setup handshake bytes from the client. + */ +static err_t +altcp_mbedtls_lower_accept(void *arg, struct altcp_pcb *accepted_conn, err_t err) +{ + struct altcp_pcb *listen_conn = (struct altcp_pcb *)arg; + if (listen_conn && listen_conn->state && listen_conn->accept) { + err_t setup_err; + altcp_mbedtls_state_t *listen_state = (altcp_mbedtls_state_t *)listen_conn->state; + /* create a new altcp_conn to pass to the next 'accept' callback */ + struct altcp_pcb *new_conn = altcp_alloc(); + if (new_conn == NULL) { + return ERR_MEM; + } + setup_err = altcp_mbedtls_setup(listen_state->conf, new_conn, accepted_conn); + if (setup_err != ERR_OK) { + altcp_free(new_conn); + return setup_err; + } + return listen_conn->accept(listen_conn->arg, new_conn, err); + } + return ERR_ARG; +} + +/** Connected callback from lower connection (i.e. TCP). + * Not really implemented/tested yet... + */ +static err_t +altcp_mbedtls_lower_connected(void *arg, struct altcp_pcb *inner_conn, err_t err) +{ + struct altcp_pcb *conn = (struct altcp_pcb *)arg; + LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */ + if (conn && conn->state) { + altcp_mbedtls_state_t *state; + LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn); + /* upper connected is called when handshake is done */ + if (err != ERR_OK) { + if (conn->connected) { + return conn->connected(conn->arg, conn, err); + } + } + state = (altcp_mbedtls_state_t *)conn->state; + /* ensure overhead value is valid before first write */ + state->overhead_bytes_adjust = 0; + return altcp_mbedtls_lower_recv_process(conn, state); + } + return ERR_VAL; +} + +/* Call recved for possibly more than an u16_t */ +static void +altcp_mbedtls_lower_recved(struct altcp_pcb *inner_conn, int recvd_cnt) +{ + while (recvd_cnt > 0) { + u16_t recvd_part = (u16_t)LWIP_MIN(recvd_cnt, 0xFFFF); + altcp_recved(inner_conn, recvd_part); + recvd_cnt -= recvd_part; + } +} + +/** Recv callback from lower connection (i.e. TCP) + * This one mainly differs between connection setup/handshake (data is fed into mbedTLS only) + * and application phase (data is decoded by mbedTLS and passed on to the application). + */ +static err_t +altcp_mbedtls_lower_recv(void *arg, struct altcp_pcb *inner_conn, struct pbuf *p, err_t err) +{ + altcp_mbedtls_state_t *state; + struct altcp_pcb *conn = (struct altcp_pcb *)arg; + + LWIP_ASSERT("no err expected", err == ERR_OK); + LWIP_UNUSED_ARG(err); + + if (!conn) { + /* no connection given as arg? should not happen, but prevent pbuf/conn leaks */ + if (p != NULL) { + pbuf_free(p); + } + altcp_close(inner_conn); + return ERR_CLSD; + } + state = (altcp_mbedtls_state_t *)conn->state; + LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn); + if (!state) { + /* already closed */ + if (p != NULL) { + pbuf_free(p); + } + altcp_close(inner_conn); + return ERR_CLSD; + } + + /* handle NULL pbuf (inner connection closed) */ + if (p == NULL) { + /* remote host sent FIN, remember this (SSL state is destroyed + when both sides are closed only!) */ + if ((state->flags & (ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE | ALTCP_MBEDTLS_FLAGS_UPPER_CALLED)) == + (ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE | ALTCP_MBEDTLS_FLAGS_UPPER_CALLED)) { + /* need to notify upper layer (e.g. 'accept' called or 'connect' succeeded) */ + if ((state->rx != NULL) || (state->rx_app != NULL)) { + state->flags |= ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED; + /* this is a normal close (FIN) but we have unprocessed data, so delay the FIN */ + altcp_mbedtls_handle_rx_appldata(conn, state); + return ERR_OK; + } + state->flags |= ALTCP_MBEDTLS_FLAGS_RX_CLOSED; + if (conn->recv) { + return conn->recv(conn->arg, conn, NULL, ERR_OK); + } + } else { + /* before connection setup is done: call 'err' */ + if (conn->err) { + conn->err(conn->arg, ERR_ABRT); + } + altcp_close(conn); + } + return ERR_OK; + } + + /* If we come here, the connection is in good state (handshake phase or application data phase). + Queue up the pbuf for processing as handshake data or application data. */ + if (state->rx == NULL) { + state->rx = p; + } else { + LWIP_ASSERT("rx pbuf overflow", (int)p->tot_len + (int)p->len <= 0xFFFF); + pbuf_cat(state->rx, p); + } + return altcp_mbedtls_lower_recv_process(conn, state); +} + +static err_t +altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *state) +{ + if (!(state->flags & ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE)) { + /* handle connection setup (handshake not done) */ + int ret = mbedtls_ssl_handshake(&state->ssl_context); + /* try to send data... */ + altcp_output(conn->inner_conn); + if (state->bio_bytes_read) { + /* acknowledge all bytes read */ + altcp_mbedtls_lower_recved(conn->inner_conn, state->bio_bytes_read); + state->bio_bytes_read = 0; + } + + if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) { + /* handshake not done, wait for more recv calls */ + LWIP_ASSERT("in this state, the rx chain should be empty", state->rx == NULL); + return ERR_OK; + } + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_handshake failed: %d\n", ret)); + /* handshake failed, connection has to be closed */ + if (conn->err) { + conn->err(conn->arg, ERR_CLSD); + } + + if (altcp_close(conn) != ERR_OK) { + altcp_abort(conn); + } + return ERR_OK; + } + /* If we come here, handshake succeeded. */ + LWIP_ASSERT("state", state->bio_bytes_read == 0); + LWIP_ASSERT("state", state->bio_bytes_appl == 0); + state->flags |= ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE; + /* issue "connect" callback" to upper connection (this can only happen for active open) */ + if (conn->connected) { + err_t err; + err = conn->connected(conn->arg, conn, ERR_OK); + if (err != ERR_OK) { + return err; + } + } + if (state->rx == NULL) { + return ERR_OK; + } + } + /* handle application data */ + return altcp_mbedtls_handle_rx_appldata(conn, state); +} + +/* Pass queued decoded rx data to application */ +static err_t +altcp_mbedtls_pass_rx_data(struct altcp_pcb *conn, altcp_mbedtls_state_t *state) +{ + err_t err; + struct pbuf *buf; + LWIP_ASSERT("conn != NULL", conn != NULL); + LWIP_ASSERT("state != NULL", state != NULL); + buf = state->rx_app; + if (buf) { + state->rx_app = NULL; + if (conn->recv) { + u16_t tot_len = buf->tot_len; + /* this needs to be increased first because the 'recved' call may come nested */ + state->rx_passed_unrecved += tot_len; + state->flags |= ALTCP_MBEDTLS_FLAGS_UPPER_CALLED; + err = conn->recv(conn->arg, conn, buf, ERR_OK); + if (err != ERR_OK) { + if (err == ERR_ABRT) { + return ERR_ABRT; + } + /* not received, leave the pbuf(s) queued (and decrease 'unrecved' again) */ + LWIP_ASSERT("state == conn->state", state == conn->state); + state->rx_app = buf; + state->rx_passed_unrecved -= tot_len; + LWIP_ASSERT("state->rx_passed_unrecved >= 0", state->rx_passed_unrecved >= 0); + if (state->rx_passed_unrecved < 0) { + state->rx_passed_unrecved = 0; + } + return err; + } + } else { + pbuf_free(buf); + } + } else if ((state->flags & (ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED | ALTCP_MBEDTLS_FLAGS_RX_CLOSED)) == + ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED) { + state->flags |= ALTCP_MBEDTLS_FLAGS_RX_CLOSED; + if (conn->recv) { + return conn->recv(conn->arg, conn, NULL, ERR_OK); + } + } + + /* application may have close the connection */ + if (conn->state != state) { + /* return error code to ensure altcp_mbedtls_handle_rx_appldata() exits the loop */ + return ERR_ARG; + } + return ERR_OK; +} + +/* Helper function that processes rx application data stored in rx pbuf chain */ +static err_t +altcp_mbedtls_handle_rx_appldata(struct altcp_pcb *conn, altcp_mbedtls_state_t *state) +{ + int ret; + LWIP_ASSERT("state != NULL", state != NULL); + if (!(state->flags & ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE)) { + /* handshake not done yet */ + return ERR_VAL; + } + do { + /* allocate a full-sized unchained PBUF_POOL: this is for RX! */ + struct pbuf *buf = pbuf_alloc(PBUF_RAW, PBUF_POOL_BUFSIZE, PBUF_POOL); + if (buf == NULL) { + /* We're short on pbufs, try again later from 'poll' or 'recv' callbacks. + @todo: close on excessive allocation failures or leave this up to upper conn? */ + return ERR_OK; + } + + /* decrypt application data, this pulls encrypted RX data off state->rx pbuf chain */ + ret = mbedtls_ssl_read(&state->ssl_context, (unsigned char *)buf->payload, PBUF_POOL_BUFSIZE); + if (ret < 0) { + if (ret == MBEDTLS_ERR_SSL_CLIENT_RECONNECT) { + /* client is initiating a new connection using the same source port -> close connection or make handshake */ + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("new connection on same source port\n")); + LWIP_ASSERT("TODO: new connection on same source port, close this connection", 0); + } else if ((ret != MBEDTLS_ERR_SSL_WANT_READ) && (ret != MBEDTLS_ERR_SSL_WANT_WRITE)) { + if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("connection was closed gracefully\n")); + } else if (ret == MBEDTLS_ERR_NET_CONN_RESET) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("connection was reset by peer\n")); + } + pbuf_free(buf); + return ERR_OK; + } else { + pbuf_free(buf); + return ERR_OK; + } + pbuf_free(buf); + altcp_abort(conn); + return ERR_ABRT; + } else { + err_t err; + if (ret) { + LWIP_ASSERT("bogus receive length", ret <= (int)PBUF_POOL_BUFSIZE); + /* trim pool pbuf to actually decoded length */ + pbuf_realloc(buf, (u16_t)ret); + + state->bio_bytes_appl += ret; + if (mbedtls_ssl_get_bytes_avail(&state->ssl_context) == 0) { + /* Record is done, now we know the share between application and protocol bytes + and can adjust the RX window by the protocol bytes. + The rest is 'recved' by the application calling our 'recved' fn. */ + int overhead_bytes; + LWIP_ASSERT("bogus byte counts", state->bio_bytes_read > state->bio_bytes_appl); + overhead_bytes = state->bio_bytes_read - state->bio_bytes_appl; + altcp_mbedtls_lower_recved(conn->inner_conn, overhead_bytes); + state->bio_bytes_read = 0; + state->bio_bytes_appl = 0; + } + + if (state->rx_app == NULL) { + state->rx_app = buf; + } else { + pbuf_cat(state->rx_app, buf); + } + } else { + pbuf_free(buf); + buf = NULL; + } + err = altcp_mbedtls_pass_rx_data(conn, state); + if (err != ERR_OK) { + if (err == ERR_ABRT) { + /* recv callback needs to return this as the pcb is deallocated */ + return ERR_ABRT; + } + /* we hide all other errors as we retry feeding the pbuf to the app later */ + return ERR_OK; + } + } + } while (ret > 0); + return ERR_OK; +} + +/** Receive callback function called from mbedtls (set via mbedtls_ssl_set_bio) + * This function mainly copies data from pbufs and frees the pbufs after copying. + */ +static int +altcp_mbedtls_bio_recv(void *ctx, unsigned char *buf, size_t len) +{ + struct altcp_pcb *conn = (struct altcp_pcb *)ctx; + altcp_mbedtls_state_t *state; + struct pbuf *p; + u16_t ret; + u16_t copy_len; + err_t err; + + LWIP_UNUSED_ARG(err); /* for LWIP_NOASSERT */ + if ((conn == NULL) || (conn->state == NULL)) { + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + } + state = (altcp_mbedtls_state_t *)conn->state; + LWIP_ASSERT("state != NULL", state != NULL); + p = state->rx; + + /* @todo: return MBEDTLS_ERR_NET_CONN_RESET/MBEDTLS_ERR_NET_RECV_FAILED? */ + + if ((p == NULL) || ((p->len == 0) && (p->next == NULL))) { + if (p) { + pbuf_free(p); + } + state->rx = NULL; + if ((state->flags & (ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED | ALTCP_MBEDTLS_FLAGS_RX_CLOSED)) == + ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED) { + /* close queued but not passed up yet */ + return 0; + } + return MBEDTLS_ERR_SSL_WANT_READ; + } + /* limit number of bytes again to copy from first pbuf in a chain only */ + copy_len = (u16_t)LWIP_MIN(len, p->len); + /* copy the data */ + ret = pbuf_copy_partial(p, buf, copy_len, 0); + LWIP_ASSERT("ret == copy_len", ret == copy_len); + /* hide the copied bytes from the pbuf */ + err = pbuf_remove_header(p, ret); + LWIP_ASSERT("error", err == ERR_OK); + if (p->len == 0) { + /* the first pbuf has been fully read, free it */ + state->rx = p->next; + p->next = NULL; + pbuf_free(p); + } + + state->bio_bytes_read += (int)ret; + return ret; +} + +/** Sent callback from lower connection (i.e. TCP) + * This only informs the upper layer the number of ACKed bytes. + * This now take care of TLS added bytes so application receive + * correct ACKed bytes. + */ +static err_t +altcp_mbedtls_lower_sent(void *arg, struct altcp_pcb *inner_conn, u16_t len) +{ + struct altcp_pcb *conn = (struct altcp_pcb *)arg; + LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */ + if (conn) { + int overhead; + u16_t app_len; + altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state; + LWIP_ASSERT("state", state != NULL); + LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn); + /* calculate TLS overhead part to not send it to application */ + overhead = state->overhead_bytes_adjust + state->ssl_context.out_left; + if ((unsigned)overhead > len) { + overhead = len; + } + /* remove ACKed bytes from overhead adjust counter */ + state->overhead_bytes_adjust -= len; + /* try to send more if we failed before (may increase overhead adjust counter) */ + altcp_mbedtls_flush_output(state); + /* remove calculated overhead from ACKed bytes len */ + app_len = len - (u16_t)overhead; + /* update application write counter and inform application */ + if (app_len) { + state->overhead_bytes_adjust += app_len; + if (conn->sent) + return conn->sent(conn->arg, conn, app_len); + } + } + return ERR_OK; +} + +/** Poll callback from lower connection (i.e. TCP) + * Just pass this on to the application. + * @todo: retry sending? + */ +static err_t +altcp_mbedtls_lower_poll(void *arg, struct altcp_pcb *inner_conn) +{ + struct altcp_pcb *conn = (struct altcp_pcb *)arg; + LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */ + if (conn) { + LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn); + /* check if there's unreceived rx data */ + if (conn->state) { + altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state; + /* try to send more if we failed before */ + altcp_mbedtls_flush_output(state); + if (altcp_mbedtls_handle_rx_appldata(conn, state) == ERR_ABRT) { + return ERR_ABRT; + } + } + if (conn->poll) { + return conn->poll(conn->arg, conn); + } + } + return ERR_OK; +} + +static void +altcp_mbedtls_lower_err(void *arg, err_t err) +{ + struct altcp_pcb *conn = (struct altcp_pcb *)arg; + if (conn) { + conn->inner_conn = NULL; /* already freed */ + if (conn->err) { + conn->err(conn->arg, err); + } + altcp_free(conn); + } +} + +/* setup functions */ + +static void +altcp_mbedtls_remove_callbacks(struct altcp_pcb *inner_conn) +{ + altcp_arg(inner_conn, NULL); + altcp_recv(inner_conn, NULL); + altcp_sent(inner_conn, NULL); + altcp_err(inner_conn, NULL); + altcp_poll(inner_conn, NULL, inner_conn->pollinterval); +} + +static void +altcp_mbedtls_setup_callbacks(struct altcp_pcb *conn, struct altcp_pcb *inner_conn) +{ + altcp_arg(inner_conn, conn); + altcp_recv(inner_conn, altcp_mbedtls_lower_recv); + altcp_sent(inner_conn, altcp_mbedtls_lower_sent); + altcp_err(inner_conn, altcp_mbedtls_lower_err); + /* tcp_poll is set when interval is set by application */ + /* listen is set totally different :-) */ +} + +static err_t +altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_conn) +{ + int ret; + struct altcp_tls_config *config = (struct altcp_tls_config *)conf; + altcp_mbedtls_state_t *state; + if (!conf) { + return ERR_ARG; + } + LWIP_ASSERT("invalid inner_conn", conn != inner_conn); + + /* allocate mbedtls context */ + state = altcp_mbedtls_alloc(conf); + if (state == NULL) { + return ERR_MEM; + } + /* initialize mbedtls context: */ + mbedtls_ssl_init(&state->ssl_context); + ret = mbedtls_ssl_setup(&state->ssl_context, &config->conf); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_setup failed\n")); + /* @todo: convert 'ret' to err_t */ + altcp_mbedtls_free(conf, state); + return ERR_MEM; + } + /* tell mbedtls about our I/O functions */ + mbedtls_ssl_set_bio(&state->ssl_context, conn, altcp_mbedtls_bio_send, altcp_mbedtls_bio_recv, NULL); + + altcp_mbedtls_setup_callbacks(conn, inner_conn); + conn->inner_conn = inner_conn; + conn->fns = &altcp_mbedtls_functions; + conn->state = state; + return ERR_OK; +} + +struct altcp_pcb * +altcp_tls_wrap(struct altcp_tls_config *config, struct altcp_pcb *inner_pcb) +{ + struct altcp_pcb *ret; + if (inner_pcb == NULL) { + return NULL; + } + ret = altcp_alloc(); + if (ret != NULL) { + if (altcp_mbedtls_setup(config, ret, inner_pcb) != ERR_OK) { + altcp_free(ret); + return NULL; + } + } + return ret; +} + +void +altcp_tls_init_session(struct altcp_tls_session *session) +{ + if (session) + mbedtls_ssl_session_init(&session->data); +} + +err_t +altcp_tls_get_session(struct altcp_pcb *conn, struct altcp_tls_session *session) +{ + if (session && conn && conn->state) { + altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state; + int ret = mbedtls_ssl_get_session(&state->ssl_context, &session->data); + return ret < 0 ? ERR_VAL : ERR_OK; + } + return ERR_ARG; +} + +err_t +altcp_tls_set_session(struct altcp_pcb *conn, struct altcp_tls_session *session) +{ + if (session && conn && conn->state) { + altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state; + int ret = -1; + if (session->data.start) + ret = mbedtls_ssl_set_session(&state->ssl_context, &session->data); + return ret < 0 ? ERR_VAL : ERR_OK; + } + return ERR_ARG; +} + +void +altcp_tls_free_session(struct altcp_tls_session *session) +{ + if (session) + mbedtls_ssl_session_free(&session->data); +} + +void * +altcp_tls_context(struct altcp_pcb *conn) +{ + if (conn && conn->state) { + altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state; + return &state->ssl_context; + } + return NULL; +} + +#if ALTCP_MBEDTLS_LIB_DEBUG != LWIP_DBG_OFF +static void +altcp_mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) +{ + LWIP_UNUSED_ARG(ctx); + LWIP_UNUSED_ARG(file); + LWIP_UNUSED_ARG(line); + LWIP_UNUSED_ARG(str); + + if (level >= ALTCP_MBEDTLS_LIB_DEBUG_LEVEL_MIN) { + LWIP_DEBUGF(ALTCP_MBEDTLS_LIB_DEBUG, ("%s:%04d: %s\n", file, line, str)); + } +} +#endif + +static err_t +altcp_mbedtls_ref_entropy(void) +{ + LWIP_ASSERT_CORE_LOCKED(); + + if (!altcp_tls_entropy_rng) { + altcp_tls_entropy_rng = (struct altcp_tls_entropy_rng *)altcp_mbedtls_alloc_config(sizeof(struct altcp_tls_entropy_rng)); + if (altcp_tls_entropy_rng) { + int ret; + altcp_tls_entropy_rng->ref = 1; + mbedtls_entropy_init(&altcp_tls_entropy_rng->entropy); + mbedtls_ctr_drbg_init(&altcp_tls_entropy_rng->ctr_drbg); + /* Seed the RNG, only once */ + ret = mbedtls_ctr_drbg_seed(&altcp_tls_entropy_rng->ctr_drbg, + ALTCP_MBEDTLS_RNG_FN, &altcp_tls_entropy_rng->entropy, + ALTCP_MBEDTLS_ENTROPY_PTR, ALTCP_MBEDTLS_ENTROPY_LEN); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ctr_drbg_seed failed: %d\n", ret)); + mbedtls_ctr_drbg_free(&altcp_tls_entropy_rng->ctr_drbg); + mbedtls_entropy_free(&altcp_tls_entropy_rng->entropy); + altcp_mbedtls_free_config(altcp_tls_entropy_rng); + altcp_tls_entropy_rng = NULL; + return ERR_ARG; + } + } else { + return ERR_MEM; + } + } else { + altcp_tls_entropy_rng->ref++; + } + return ERR_OK; +} + +static void +altcp_mbedtls_unref_entropy(void) +{ + LWIP_ASSERT_CORE_LOCKED(); + + if (altcp_tls_entropy_rng && altcp_tls_entropy_rng->ref) { + altcp_tls_entropy_rng->ref--; + } +} + +/** Create new TLS configuration + * ATTENTION: Server certificate and private key have to be added outside this function! + */ +static struct altcp_tls_config * +altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int have_ca) +{ + size_t sz; + int ret; + struct altcp_tls_config *conf; + mbedtls_x509_crt *mem; + +#if MBEDTLS_VERSION_MAJOR < 3 + if (TCP_WND < MBEDTLS_SSL_MAX_CONTENT_LEN) { +#else + if (TCP_WND < MBEDTLS_SSL_IN_CONTENT_LEN) { +#endif + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG|LWIP_DBG_LEVEL_SERIOUS, + ("altcp_tls: TCP_WND is smaller than the RX decrypion buffer, connection RX might stall!\n")); + } + + altcp_mbedtls_mem_init(); + + sz = sizeof(struct altcp_tls_config); + if (cert_count > 0) { + sz += (cert_count * sizeof(mbedtls_x509_crt)); + } + if (have_ca) { + sz += sizeof(mbedtls_x509_crt); + } + if (pkey_count > 0) { + sz += (pkey_count * sizeof(mbedtls_pk_context)); + } + + conf = (struct altcp_tls_config *)altcp_mbedtls_alloc_config(sz); + if (conf == NULL) { + return NULL; + } + conf->cert_max = cert_count; + mem = (mbedtls_x509_crt *)(conf + 1); + if (cert_count > 0) { + conf->cert = mem; + mem += cert_count; + } + if (have_ca) { + conf->ca = mem; + mem++; + } + conf->pkey_max = pkey_count; + if (pkey_count > 0) { + conf->pkey = (mbedtls_pk_context *)mem; + } + + mbedtls_ssl_config_init(&conf->conf); + + if (altcp_mbedtls_ref_entropy() != ERR_OK) { + altcp_mbedtls_free_config(conf); + return NULL; + } + + /* Setup ssl context (@todo: what's different for a client here? -> might better be done on listen/connect) */ + ret = mbedtls_ssl_config_defaults(&conf->conf, is_server ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT, + MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_config_defaults failed: %d\n", ret)); + altcp_mbedtls_unref_entropy(); + altcp_mbedtls_free_config(conf); + return NULL; + } + mbedtls_ssl_conf_authmode(&conf->conf, ALTCP_MBEDTLS_AUTHMODE); + + mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg); +#if ALTCP_MBEDTLS_LIB_DEBUG != LWIP_DBG_OFF + mbedtls_ssl_conf_dbg(&conf->conf, altcp_mbedtls_debug, stdout); +#endif +#if defined(MBEDTLS_SSL_CACHE_C) && ALTCP_MBEDTLS_USE_SESSION_CACHE + mbedtls_ssl_conf_session_cache(&conf->conf, &conf->cache, mbedtls_ssl_cache_get, mbedtls_ssl_cache_set); + mbedtls_ssl_cache_set_timeout(&conf->cache, ALTCP_MBEDTLS_SESSION_CACHE_TIMEOUT_SECONDS); + mbedtls_ssl_cache_set_max_entries(&conf->cache, ALTCP_MBEDTLS_SESSION_CACHE_SIZE); +#endif + +#if defined(MBEDTLS_SSL_SESSION_TICKETS) && ALTCP_MBEDTLS_USE_SESSION_TICKETS + mbedtls_ssl_ticket_init(&conf->ticket_ctx); + + ret = mbedtls_ssl_ticket_setup(&conf->ticket_ctx, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg, + ALTCP_MBEDTLS_SESSION_TICKET_CIPHER, ALTCP_MBEDTLS_SESSION_TICKET_TIMEOUT_SECONDS); + if (ret) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_ticket_setup failed: %d\n", ret)); + altcp_mbedtls_unref_entropy(); + altcp_mbedtls_free_config(conf); + return NULL; + } + + mbedtls_ssl_conf_session_tickets_cb(&conf->conf, mbedtls_ssl_ticket_write, mbedtls_ssl_ticket_parse, + &conf->ticket_ctx); +#endif + + return conf; +} + +struct altcp_tls_config *altcp_tls_create_config_server(u8_t cert_count) +{ + struct altcp_tls_config *conf = altcp_tls_create_config(1, cert_count, cert_count, 0); + if (conf == NULL) { + return NULL; + } + + mbedtls_ssl_conf_ca_chain(&conf->conf, NULL, NULL); + return conf; +} + +err_t altcp_tls_config_server_add_privkey_cert(struct altcp_tls_config *config, + const u8_t *privkey, size_t privkey_len, + const u8_t *privkey_pass, size_t privkey_pass_len, + const u8_t *cert, size_t cert_len) +{ + int ret; + mbedtls_x509_crt *srvcert; + mbedtls_pk_context *pkey; + + if (config->cert_count >= config->cert_max) { + return ERR_MEM; + } + if (config->pkey_count >= config->pkey_max) { + return ERR_MEM; + } + + srvcert = config->cert + config->cert_count; + mbedtls_x509_crt_init(srvcert); + + pkey = config->pkey + config->pkey_count; + mbedtls_pk_init(pkey); + + /* Load the certificates and private key */ + ret = mbedtls_x509_crt_parse(srvcert, cert, cert_len); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_x509_crt_parse failed: %d\n", ret)); + return ERR_VAL; + } + +#if MBEDTLS_VERSION_MAJOR < 3 + ret = mbedtls_pk_parse_key(pkey, (const unsigned char *) privkey, privkey_len, privkey_pass, privkey_pass_len); +#else + ret = mbedtls_pk_parse_key(pkey, (const unsigned char *) privkey, privkey_len, privkey_pass, privkey_pass_len, NULL, NULL); +#endif + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_pk_parse_public_key failed: %d\n", ret)); + mbedtls_x509_crt_free(srvcert); + return ERR_VAL; + } + + ret = mbedtls_ssl_conf_own_cert(&config->conf, srvcert, pkey); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_conf_own_cert failed: %d\n", ret)); + mbedtls_x509_crt_free(srvcert); + mbedtls_pk_free(pkey); + return ERR_VAL; + } + + config->cert_count++; + config->pkey_count++; + return ERR_OK; +} + +/** Create new TLS configuration + * This is a suboptimal version that gets the encrypted private key and its password, + * as well as the server certificate. + */ +struct altcp_tls_config * +altcp_tls_create_config_server_privkey_cert(const u8_t *privkey, size_t privkey_len, + const u8_t *privkey_pass, size_t privkey_pass_len, + const u8_t *cert, size_t cert_len) +{ + struct altcp_tls_config *conf = altcp_tls_create_config_server(1); + if (conf == NULL) { + return NULL; + } + + if (altcp_tls_config_server_add_privkey_cert(conf, privkey, privkey_len, + privkey_pass, privkey_pass_len, cert, cert_len) != ERR_OK) { + altcp_tls_free_config(conf); + return NULL; + } + + return conf; +} + +static struct altcp_tls_config * +altcp_tls_create_config_client_common(const u8_t *ca, size_t ca_len, int is_2wayauth) +{ + int ret; + struct altcp_tls_config *conf = altcp_tls_create_config(0, (is_2wayauth) ? 1 : 0, (is_2wayauth) ? 1 : 0, ca != NULL); + if (conf == NULL) { + return NULL; + } + + /* Initialize the CA certificate if provided + * CA certificate is optional (to save memory) but recommended for production environment + * Without CA certificate, connection will be prone to man-in-the-middle attacks */ + if (ca) { + mbedtls_x509_crt_init(conf->ca); + ret = mbedtls_x509_crt_parse(conf->ca, ca, ca_len); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_x509_crt_parse ca failed: %d 0x%x\n", ret, -1*ret)); + altcp_tls_free_config(conf); + return NULL; + } + + mbedtls_ssl_conf_ca_chain(&conf->conf, conf->ca, NULL); + } + return conf; +} + +struct altcp_tls_config * +altcp_tls_create_config_client(const u8_t *ca, size_t ca_len) +{ + return altcp_tls_create_config_client_common(ca, ca_len, 0); +} + +struct altcp_tls_config * +altcp_tls_create_config_client_2wayauth(const u8_t *ca, size_t ca_len, const u8_t *privkey, size_t privkey_len, + const u8_t *privkey_pass, size_t privkey_pass_len, + const u8_t *cert, size_t cert_len) +{ + int ret; + struct altcp_tls_config *conf; + + if (!cert || !privkey) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("altcp_tls_create_config_client_2wayauth: certificate and priv key required\n")); + return NULL; + } + + conf = altcp_tls_create_config_client_common(ca, ca_len, 1); + if (conf == NULL) { + return NULL; + } + + /* Initialize the client certificate and corresponding private key */ + mbedtls_x509_crt_init(conf->cert); + ret = mbedtls_x509_crt_parse(conf->cert, cert, cert_len); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_x509_crt_parse cert failed: %d 0x%x\n", ret, -1*ret)); + altcp_tls_free_config(conf); + return NULL; + } + + mbedtls_pk_init(conf->pkey); +#if MBEDTLS_VERSION_MAJOR < 3 + ret = mbedtls_pk_parse_key(conf->pkey, privkey, privkey_len, privkey_pass, privkey_pass_len); +#else + ret = mbedtls_pk_parse_key(conf->pkey, privkey, privkey_len, privkey_pass, privkey_pass_len, NULL, NULL); +#endif + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_pk_parse_key failed: %d 0x%x\n", ret, -1*ret)); + altcp_tls_free_config(conf); + return NULL; + } + + ret = mbedtls_ssl_conf_own_cert(&conf->conf, conf->cert, conf->pkey); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_conf_own_cert failed: %d 0x%x\n", ret, -1*ret)); + altcp_tls_free_config(conf); + return NULL; + } + + return conf; +} + +int +altcp_tls_configure_alpn_protocols(struct altcp_tls_config *conf, const char **protos) +{ +#if defined(MBEDTLS_SSL_ALPN) + int ret = mbedtls_ssl_conf_alpn_protocols(&conf->conf, protos); + if (ret != 0) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_conf_alpn_protocols failed: %d\n", ret)); + } + + return ret; +#else + (void)conf; + (void)protos; + return -1; +#endif +} + +void +altcp_tls_free_config(struct altcp_tls_config *conf) +{ + if (conf->pkey) { + mbedtls_pk_free(conf->pkey); + } + if (conf->cert) { + mbedtls_x509_crt_free(conf->cert); + } + if (conf->ca) { + mbedtls_x509_crt_free(conf->ca); + } + mbedtls_ssl_config_free(&conf->conf); + altcp_mbedtls_free_config(conf); + altcp_mbedtls_unref_entropy(); +} + +void +altcp_tls_free_entropy(void) +{ + LWIP_ASSERT_CORE_LOCKED(); + + if (altcp_tls_entropy_rng && altcp_tls_entropy_rng->ref == 0) { + mbedtls_ctr_drbg_free(&altcp_tls_entropy_rng->ctr_drbg); + mbedtls_entropy_free(&altcp_tls_entropy_rng->entropy); + altcp_mbedtls_free_config(altcp_tls_entropy_rng); + altcp_tls_entropy_rng = NULL; + } +} + +/* "virtual" functions */ +static void +altcp_mbedtls_set_poll(struct altcp_pcb *conn, u8_t interval) +{ + if (conn != NULL) { + altcp_poll(conn->inner_conn, altcp_mbedtls_lower_poll, interval); + } +} + +static void +altcp_mbedtls_recved(struct altcp_pcb *conn, u16_t len) +{ + u16_t lower_recved; + altcp_mbedtls_state_t *state; + if (conn == NULL) { + return; + } + state = (altcp_mbedtls_state_t *)conn->state; + if (state == NULL) { + return; + } + if (!(state->flags & ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE)) { + return; + } + lower_recved = len; + if (lower_recved > state->rx_passed_unrecved) { + LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("bogus recved count (len > state->rx_passed_unrecved / %d / %d)\n", + len, state->rx_passed_unrecved)); + lower_recved = (u16_t)state->rx_passed_unrecved; + } + state->rx_passed_unrecved -= lower_recved; + + altcp_recved(conn->inner_conn, lower_recved); +} + +static err_t +altcp_mbedtls_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected) +{ + if (conn == NULL) { + return ERR_VAL; + } + conn->connected = connected; + return altcp_connect(conn->inner_conn, ipaddr, port, altcp_mbedtls_lower_connected); +} + +static struct altcp_pcb * +altcp_mbedtls_listen(struct altcp_pcb *conn, u8_t backlog, err_t *err) +{ + struct altcp_pcb *lpcb; + if (conn == NULL) { + return NULL; + } + lpcb = altcp_listen_with_backlog_and_err(conn->inner_conn, backlog, err); + if (lpcb != NULL) { + altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state; + /* Free members of the ssl context (not used on listening pcb). This + includes freeing input/output buffers, so saves ~32KByte by default */ + mbedtls_ssl_free(&state->ssl_context); + + conn->inner_conn = lpcb; + altcp_accept(lpcb, altcp_mbedtls_lower_accept); + return conn; + } + return NULL; +} + +static void +altcp_mbedtls_abort(struct altcp_pcb *conn) +{ + if (conn != NULL) { + altcp_abort(conn->inner_conn); + } +} + +static err_t +altcp_mbedtls_close(struct altcp_pcb *conn) +{ + struct altcp_pcb *inner_conn; + if (conn == NULL) { + return ERR_VAL; + } + inner_conn = conn->inner_conn; + if (inner_conn) { + err_t err; + altcp_poll_fn oldpoll = inner_conn->poll; + altcp_mbedtls_remove_callbacks(conn->inner_conn); + err = altcp_close(conn->inner_conn); + if (err != ERR_OK) { + /* not closed, set up all callbacks again */ + altcp_mbedtls_setup_callbacks(conn, inner_conn); + /* poll callback is not included in the above */ + altcp_poll(inner_conn, oldpoll, inner_conn->pollinterval); + return err; + } + conn->inner_conn = NULL; + } + altcp_free(conn); + return ERR_OK; +} + +/** Allow caller of altcp_write() to limit to negotiated chunk size + * or remaining sndbuf space of inner_conn. + */ +static u16_t +altcp_mbedtls_sndbuf(struct altcp_pcb *conn) +{ + if (conn) { + altcp_mbedtls_state_t *state; + state = (altcp_mbedtls_state_t*)conn->state; + if (!state || !(state->flags & ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE)) { + return 0; + } + if (conn->inner_conn) { + u16_t sndbuf = altcp_sndbuf(conn->inner_conn); + /* Take care of record header, IV, AuthTag */ + int ssl_expan = mbedtls_ssl_get_record_expansion(&state->ssl_context); + if (ssl_expan > 0) { + size_t ssl_added = (u16_t)LWIP_MIN(ssl_expan, 0xFFFF); + /* internal sndbuf smaller than our offset */ + if (ssl_added < sndbuf) { + size_t max_len = 0xFFFF; + size_t ret; +#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) + /* @todo: adjust ssl_added to real value related to negotiated cipher */ +#if MBEDTLS_VERSION_MAJOR < 3 + size_t max_frag_len = mbedtls_ssl_get_max_frag_len(&state->ssl_context); +#else + size_t max_frag_len = mbedtls_ssl_get_output_max_frag_len(&state->ssl_context); +#endif + max_len = LWIP_MIN(max_frag_len, max_len); +#endif + /* Adjust sndbuf of inner_conn with what added by SSL */ + ret = LWIP_MIN(sndbuf - ssl_added, max_len); + LWIP_ASSERT("sndbuf overflow", ret <= 0xFFFF); + return (u16_t)ret; + } + } + } + } + /* fallback: use sendbuf of the inner connection */ + return altcp_default_sndbuf(conn); +} + +/** Write data to a TLS connection. Calls into mbedTLS, which in turn calls into + * @ref altcp_mbedtls_bio_send() to send the encrypted data + */ +static err_t +altcp_mbedtls_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags) +{ + int ret; + altcp_mbedtls_state_t *state; + + LWIP_UNUSED_ARG(apiflags); + + if (conn == NULL) { + return ERR_VAL; + } + + state = (altcp_mbedtls_state_t *)conn->state; + if (state == NULL) { + /* @todo: which error? */ + return ERR_ARG; + } + if (!(state->flags & ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE)) { + /* @todo: which error? */ + return ERR_VAL; + } + + /* HACK: if there is something left to send, try to flush it and only + allow sending more if this succeeded (this is a hack because neither + returning 0 nor MBEDTLS_ERR_SSL_WANT_WRITE worked for me) */ + if (state->ssl_context.out_left) { + altcp_mbedtls_flush_output(state); + if (state->ssl_context.out_left) { + return ERR_MEM; + } + } + ret = mbedtls_ssl_write(&state->ssl_context, (const unsigned char *)dataptr, len); + /* try to send data... */ + altcp_output(conn->inner_conn); + if (ret >= 0) { + if (ret == len) { + /* update application sent counter */ + state->overhead_bytes_adjust -= ret; + return ERR_OK; + } else { + /* @todo/@fixme: assumption: either everything sent or error */ + LWIP_ASSERT("ret <= 0", 0); + return ERR_MEM; + } + } else { + if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) { + /* @todo: convert error to err_t */ + return ERR_MEM; + } + LWIP_ASSERT("unhandled error", 0); + return ERR_VAL; + } +} + +/** Send callback function called from mbedtls (set via mbedtls_ssl_set_bio) + * This function is either called during handshake or when sending application + * data via @ref altcp_mbedtls_write (or altcp_write) + */ +static int +altcp_mbedtls_bio_send(void *ctx, const unsigned char *dataptr, size_t size) +{ + struct altcp_pcb *conn = (struct altcp_pcb *) ctx; + altcp_mbedtls_state_t *state; + int written = 0; + size_t size_left = size; + u8_t apiflags = TCP_WRITE_FLAG_COPY; + + LWIP_ASSERT("conn != NULL", conn != NULL); + if ((conn == NULL) || (conn->inner_conn == NULL)) { + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + } + state = (altcp_mbedtls_state_t *)conn->state; + LWIP_ASSERT("state != NULL", state != NULL); + + while (size_left) { + u16_t write_len = (u16_t)LWIP_MIN(size_left, 0xFFFF); + err_t err = altcp_write(conn->inner_conn, (const void *)dataptr, write_len, apiflags); + if (err == ERR_OK) { + written += write_len; + size_left -= write_len; + state->overhead_bytes_adjust += write_len; + } else if (err == ERR_MEM) { + if (written) { + return written; + } + return 0; /* MBEDTLS_ERR_SSL_WANT_WRITE; */ + } else { + LWIP_ASSERT("tls_write, tcp_write: err != ERR MEM", 0); + /* @todo: return MBEDTLS_ERR_NET_CONN_RESET or MBEDTLS_ERR_NET_SEND_FAILED */ + return MBEDTLS_ERR_NET_SEND_FAILED; + } + } + return written; +} + +static u16_t +altcp_mbedtls_mss(struct altcp_pcb *conn) +{ + if (conn == NULL) { + return 0; + } + /* @todo: LWIP_MIN(mss, mbedtls_ssl_get_max_frag_len()) ? */ + return altcp_mss(conn->inner_conn); +} + +static void +altcp_mbedtls_dealloc(struct altcp_pcb *conn) +{ + /* clean up and free tls state */ + if (conn) { + altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state; + if (state) { + mbedtls_ssl_free(&state->ssl_context); + state->flags = 0; + if (state->rx) { + /* free leftover (unhandled) rx pbufs */ + pbuf_free(state->rx); + state->rx = NULL; + } + altcp_mbedtls_free(state->conf, state); + conn->state = NULL; + } + } +} + +const struct altcp_functions altcp_mbedtls_functions = { + altcp_mbedtls_set_poll, + altcp_mbedtls_recved, + altcp_default_bind, + altcp_mbedtls_connect, + altcp_mbedtls_listen, + altcp_mbedtls_abort, + altcp_mbedtls_close, + altcp_default_shutdown, + altcp_mbedtls_write, + altcp_default_output, + altcp_mbedtls_mss, + altcp_mbedtls_sndbuf, + altcp_default_sndqueuelen, + altcp_default_nagle_disable, + altcp_default_nagle_enable, + altcp_default_nagle_disabled, + altcp_default_setprio, + altcp_mbedtls_dealloc, + altcp_default_get_tcp_addrinfo, + altcp_default_get_ip, + altcp_default_get_port +#if LWIP_TCP_KEEPALIVE + , altcp_default_keepalive_disable + , altcp_default_keepalive_enable +#endif +#ifdef LWIP_DEBUG + , altcp_default_dbg_get_tcp_state +#endif +}; + +#endif /* LWIP_ALTCP_TLS && LWIP_ALTCP_TLS_MBEDTLS */ +#endif /* LWIP_ALTCP */ diff --git a/src/rp2_common/pico_lwip/lwip.BUILD b/src/rp2_common/pico_lwip/lwip.BUILD index c94b881c5..c76d42dc7 100644 --- a/src/rp2_common/pico_lwip/lwip.BUILD +++ b/src/rp2_common/pico_lwip/lwip.BUILD @@ -25,7 +25,15 @@ cc_library( deps = [ ":pico_lwip_headers", "@pico-sdk//bazel/config:PICO_LWIP_CONFIG", - ], + ] + # altcp_alloc.c *might* depend on mbedtls + + select({ + "@pico-sdk//bazel/constraint:pico_mbedtls_config_unset": [], + "//conditions:default": [ + "@pico-sdk//src/rp2_common/pico_mbedtls:pico_mbedtls_library", + ] + }) + , target_compatible_with = incompatible_with_config("@pico-sdk//bazel/constraint:pico_lwip_config_unset") ) @@ -138,15 +146,21 @@ cc_library( cc_library( name = "pico_lwip_mbedtls", srcs = [ - "src/apps/altcp_tls/altcp_tls_mbedtls.c", + # This source file has issues with mbedtls 3.x + # See https://savannah.nongnu.org/patch/index.php?10448 + #"src/apps/altcp_tls/altcp_tls_mbedtls.c", "src/apps/altcp_tls/altcp_tls_mbedtls_mem.c", "src/apps/snmp/snmpv3_mbedtls.c", ], - deps = [":pico_lwip_core"], + includes = ["src/apps/altcp_tls"], + deps = [ + ":pico_lwip_core", + "@pico-sdk//src/rp2_common/pico_mbedtls:pico_mbedtls_config" + ], ) cc_library( - name = "pico_lwip_mqttt", + name = "pico_lwip_mqtt", srcs = ["src/apps/mqtt/mqtt.c"], deps = [":pico_lwip_core"], ) diff --git a/src/rp2_common/pico_mbedtls/BUILD.bazel b/src/rp2_common/pico_mbedtls/BUILD.bazel index c339941cd..843ae821e 100644 --- a/src/rp2_common/pico_mbedtls/BUILD.bazel +++ b/src/rp2_common/pico_mbedtls/BUILD.bazel @@ -2,6 +2,13 @@ load("//bazel:defs.bzl", "compatible_with_rp2") package(default_visibility = ["//visibility:public"]) +cc_library( + name = "pico_mbedtls_config", + includes = ["include"], + hdrs = ["include/pico_mbedtls_config.h"], + defines = ['MBEDTLS_CONFIG_FILE=\\"pico_mbedtls_config.h\\"'], +) + cc_library( name = "pico_mbedtls", srcs = ["pico_mbedtls.c"], @@ -9,9 +16,17 @@ cc_library( includes = ["include"], target_compatible_with = compatible_with_rp2(), deps = [ - "//bazel/config:PICO_MBEDTLS_LIB", + ":pico_mbedtls_library", + ":pico_mbedtls_config", "//src/rp2_common:pico_platform", "//src/rp2_common/pico_rand", - "//src/rp2_common/pico_sha256", - ], + ] + select({ + "//bazel/constraint:rp2350": [ "//src/rp2_common/pico_sha256" ], + "//conditions:default": [ ], + }), +) + +alias( + name = "pico_mbedtls_library", + actual = "@mbedtls//:pico_mbedtls_library", ) diff --git a/src/rp2_common/pico_mbedtls/CMakeLists.txt b/src/rp2_common/pico_mbedtls/CMakeLists.txt index 13976d6fb..d9b90a674 100644 --- a/src/rp2_common/pico_mbedtls/CMakeLists.txt +++ b/src/rp2_common/pico_mbedtls/CMakeLists.txt @@ -1,3 +1,4 @@ +# PICO_CMAKE_CONFIG: PICO_MBEDTLS_PATH, Path to an alternative version of mbedtls overriding the version in pico-sdk/libs/mbedtls. Can be passed to cmake or set in your environment, type=string, group=pico_mbedtls if (DEFINED ENV{PICO_MBEDTLS_PATH} AND (NOT PICO_MBEDTLS_PATH)) set(PICO_MBEDTLS_PATH $ENV{PICO_MBEDTLS_PATH}) message("Using PICO_MBEDTLS_PATH from environment ('${PICO_MBEDTLS_PATH}')") @@ -15,117 +16,168 @@ if (EXISTS ${PICO_MBEDTLS_PATH}/${MBEDTLS_TEST_PATH}) pico_register_common_scope_var(PICO_MBEDTLS_PATH) - set(src_crypto - aes.c - aesni.c - arc4.c - aria.c - asn1parse.c - asn1write.c - base64.c - bignum.c - blowfish.c - camellia.c - ccm.c - chacha20.c - chachapoly.c - cipher.c - cipher_wrap.c - constant_time.c - cmac.c - ctr_drbg.c - des.c - dhm.c - ecdh.c - ecdsa.c - ecjpake.c - ecp.c - ecp_curves.c - entropy.c - entropy_poll.c - error.c - gcm.c - havege.c - hkdf.c - hmac_drbg.c - md.c - md2.c - md4.c - md5.c - memory_buffer_alloc.c - mps_reader.c - mps_trace.c - nist_kw.c - oid.c - padlock.c - pem.c - pk.c - pk_wrap.c - pkcs12.c - pkcs5.c - pkparse.c - pkwrite.c - platform.c - platform_util.c - poly1305.c - psa_crypto.c - psa_crypto_aead.c - psa_crypto_cipher.c - psa_crypto_client.c - psa_crypto_driver_wrappers.c - psa_crypto_ecp.c - psa_crypto_hash.c - psa_crypto_mac.c - psa_crypto_rsa.c - psa_crypto_se.c - psa_crypto_slot_management.c - psa_crypto_storage.c - psa_its_file.c - ripemd160.c - rsa.c - rsa_internal.c - sha1.c - sha256.c - sha512.c - threading.c - timing.c - version.c - version_features.c - xtea.c - ) - list(TRANSFORM src_crypto PREPEND ${PICO_MBEDTLS_PATH}/library/) + # Support version 2.28.8 or 3.6.2 + if (NOT MBEDTLS_VERSION_MAJOR) + if (EXISTS ${PICO_MBEDTLS_PATH}/library/ssl_cli.c) + set(MBEDTLS_VERSION_MAJOR 2) + elseif (EXISTS ${PICO_MBEDTLS_PATH}/library/ssl_client.c) + set(MBEDTLS_VERSION_MAJOR 3) + else() + message(WARNING "Cannot determine the version of mbedtls") + endif() + pico_register_common_scope_var(MBEDTLS_VERSION_MAJOR) + endif() + + function(src_crypto_list) + set(src_crypto + aes.c + aesni.c + aria.c + asn1parse.c + asn1write.c + base64.c + bignum.c + camellia.c + ccm.c + chacha20.c + chachapoly.c + cipher.c + cipher_wrap.c + constant_time.c + cmac.c + ctr_drbg.c + des.c + dhm.c + ecdh.c + ecdsa.c + ecjpake.c + ecp.c + ecp_curves.c + entropy.c + entropy_poll.c + error.c + gcm.c + hkdf.c + hmac_drbg.c + md.c + md5.c + memory_buffer_alloc.c + mps_reader.c + mps_trace.c + nist_kw.c + oid.c + padlock.c + pem.c + pk.c + pk_wrap.c + pkcs12.c + pkcs5.c + pkparse.c + pkwrite.c + platform.c + platform_util.c + poly1305.c + psa_crypto.c + psa_crypto_aead.c + psa_crypto_cipher.c + psa_crypto_client.c + psa_crypto_ecp.c + psa_crypto_hash.c + psa_crypto_mac.c + psa_crypto_rsa.c + psa_crypto_se.c + psa_crypto_slot_management.c + psa_crypto_storage.c + psa_its_file.c + ripemd160.c + rsa.c + sha1.c + sha256.c + sha512.c + threading.c + timing.c + version.c + version_features.c + ) + if (MBEDTLS_VERSION_MAJOR EQUAL 2) + list(APPEND src_crypto + arc4.c + blowfish.c + havege.c + md2.c + md4.c + psa_crypto_driver_wrappers.c + rsa_internal.c xtea.c + ) + elseif (MBEDTLS_VERSION_MAJOR EQUAL 3) + list(APPEND src_crypto + bignum_core.c + rsa_alt_helpers.c + pk_ecc.c + ) + endif() + list(TRANSFORM src_crypto PREPEND ${PICO_MBEDTLS_PATH}/library/) + set(src_crypto ${src_crypto} PARENT_SCOPE) + endfunction() + + src_crypto_list() pico_add_library(pico_mbedtls_crypto NOFLAG) target_sources(pico_mbedtls_crypto INTERFACE ${src_crypto}) - set(src_x509 - certs.c - pkcs11.c - x509.c - x509_create.c - x509_crl.c - x509_crt.c - x509_csr.c - x509write_crt.c - x509write_csr.c - ) - list(TRANSFORM src_x509 PREPEND ${PICO_MBEDTLS_PATH}/library/) + function(src_x509_list) + set(src_x509 + x509.c + x509_create.c + x509_crl.c + x509_crt.c + x509_csr.c + x509write_crt.c + x509write_csr.c + ) + if (MBEDTLS_VERSION_MAJOR EQUAL 2) + list(APPEND src_x509 + certs.c + pkcs11.c + ) + endif() + list(TRANSFORM src_x509 PREPEND ${PICO_MBEDTLS_PATH}/library/) + set(src_x509 ${src_x509} PARENT_SCOPE) + endfunction() + + src_x509_list() pico_add_library(pico_mbedtls_x509 NOFLAG) target_sources(pico_mbedtls_x509 INTERFACE ${src_x509}) - set(src_tls - debug.c - net_sockets.c - ssl_cache.c - ssl_ciphersuites.c - ssl_cli.c - ssl_cookie.c - ssl_msg.c - ssl_srv.c - ssl_ticket.c - ssl_tls.c - ssl_tls13_keys.c - ) - list(TRANSFORM src_tls PREPEND ${PICO_MBEDTLS_PATH}/library/) + function(src_tls_list) + set(src_tls + debug.c + net_sockets.c + ssl_cache.c + ssl_ciphersuites.c + ssl_cookie.c + ssl_msg.c + ssl_ticket.c + ssl_tls.c + ssl_tls13_keys.c + ) + if (MBEDTLS_VERSION_MAJOR EQUAL 2) + list(APPEND src_tls + ssl_cli.c + ssl_srv.c + ) + elseif (MBEDTLS_VERSION_MAJOR EQUAL 3) + list(APPEND src_tls + ssl_client.c + ssl_debug_helpers_generated.c + ssl_tls12_client.c + ssl_tls12_server.c + ) + endif() + list(TRANSFORM src_tls PREPEND ${PICO_MBEDTLS_PATH}/library/) + set(src_tls ${src_tls} PARENT_SCOPE) + endfunction() + + src_tls_list() pico_add_library(pico_mbedtls_tls NOFLAG) target_sources(pico_mbedtls_tls INTERFACE ${src_tls}) @@ -134,7 +186,12 @@ if (EXISTS ${PICO_MBEDTLS_PATH}/${MBEDTLS_TEST_PATH}) if (DEFINED PICO_MBEDTLS_CONFIG_FILE) target_compile_definitions(pico_mbedtls_headers INTERFACE MBEDTLS_CONFIG_FILE="${PICO_MBEDTLS_CONFIG_FILE}") else() - target_compile_definitions(pico_mbedtls_headers INTERFACE MBEDTLS_CONFIG_FILE="mbedtls_config.h") + if (MBEDTLS_VERSION_MAJOR EQUAL 2) + target_compile_definitions(pico_mbedtls_headers INTERFACE MBEDTLS_CONFIG_FILE="mbedtls_config.h") + else() + # Avoid including mbedtls/include/mbedtls_config.h + target_compile_definitions(pico_mbedtls_headers INTERFACE MBEDTLS_CONFIG_FILE="pico_mbedtls_config.h") + endif() endif() if (TARGET pico_sha256) pico_mirrored_target_link_libraries(pico_mbedtls INTERFACE pico_sha256) @@ -143,32 +200,26 @@ if (EXISTS ${PICO_MBEDTLS_PATH}/${MBEDTLS_TEST_PATH}) target_include_directories(pico_mbedtls_headers SYSTEM INTERFACE ${PICO_MBEDTLS_PATH}/include/ ${PICO_MBEDTLS_PATH}/library/ ${CMAKE_CURRENT_LIST_DIR}/include/) function(suppress_mbedtls_warnings) + # It seems everything needs this due to mbedtls_get_unaligned_uint64 + src_crypto_list() + src_x509_list() + src_tls_list() + foreach(src_file IN LISTS src_crypto src_x509 src_tls) + set_source_files_properties( + ${src_file} + PROPERTIES + COMPILE_OPTIONS "-Wno-cast-qual" + ) + endforeach() + set_source_files_properties( - ${PICO_MBEDTLS_PATH}/library/ecdsa.c - ${PICO_MBEDTLS_PATH}/library/ecp.c - ${PICO_MBEDTLS_PATH}/library/ecp_curves.c - ${PICO_MBEDTLS_PATH}/library/pk_wrap.c - ${PICO_MBEDTLS_PATH}/library/pkparse.c - ${PICO_MBEDTLS_PATH}/library/ssl_cli.c - PROPERTIES - COMPILE_OPTIONS "-Wno-cast-qual" - ) - set_source_files_properties( - ${PICO_MBEDTLS_PATH}/library/psa_crypto_client.c - ${PICO_MBEDTLS_PATH}/library/psa_crypto_driver_wrappers.c - PROPERTIES - COMPILE_OPTIONS "-Wno-redundant-decls" - ) - set_source_files_properties( + ${PICO_MBEDTLS_PATH}/library/ssl_srvx.c ${PICO_MBEDTLS_PATH}/library/x509_crt.c - PROPERTIES - COMPILE_OPTIONS "-Wno-cast-qual;-Wno-null-dereference" - ) - set_source_files_properties( - ${PICO_MBEDTLS_PATH}/library/ssl_srv.c + ${PICO_MBEDTLS_PATH}/library/pk_ecc.c + ${PICO_MBEDTLS_PATH}/library/ssl_tls12_server.c ${PICO_MBEDTLS_PATH}/library/ssl_tls.c PROPERTIES - COMPILE_OPTIONS "-Wno-null-dereference" + COMPILE_OPTIONS "-Wno-cast-qual;-Wno-null-dereference" ) endfunction() diff --git a/src/rp2_common/pico_mbedtls/doc.h b/src/rp2_common/pico_mbedtls/doc.h new file mode 100644 index 000000000..91591fc99 --- /dev/null +++ b/src/rp2_common/pico_mbedtls/doc.h @@ -0,0 +1,11 @@ +/** + * \defgroup pico_mbedtls pico_mbedtls + * \brief pico-sdk wrapper library for mbedtls + * the documentation for which is here. + * + * Builds mbedtls for pico-sdk and implements functions to take advantage of hardware support, if enabled in mbedtls_config.h + * + * * \c \b MBEDTLS_ENTROPY_HARDWARE_ALT, implementation of a hardware entropy collector that uses \ref get_rand_64 + * * \c \b MBEDTLS_SHA256_ALT, use SHA256 hardware acceleration. Only valid if LIB_PICO_SHA256 is defined (i.e. not available for rp2040) + * + */ diff --git a/src/rp2_common/pico_mbedtls/include/pico_mbedtls_config.h b/src/rp2_common/pico_mbedtls/include/pico_mbedtls_config.h new file mode 100644 index 000000000..6c86b8e7c --- /dev/null +++ b/src/rp2_common/pico_mbedtls/include/pico_mbedtls_config.h @@ -0,0 +1,3 @@ +// Latest versions of mbedtls include mbedtls/include/mbedtls_config.h and we used to set MBEDTLS_CONFIG_FILE=mbedtls_config.h +// To maintain compatibility with this and avoid including the mbedtls version of mbedtls_config.h we include pico_mbedtls_config.h first +#include "mbedtls_config.h" \ No newline at end of file diff --git a/src/rp2_common/pico_mbedtls/mbedtls.BUILD b/src/rp2_common/pico_mbedtls/mbedtls.BUILD new file mode 100644 index 000000000..c8b856492 --- /dev/null +++ b/src/rp2_common/pico_mbedtls/mbedtls.BUILD @@ -0,0 +1,23 @@ +load("@pico-sdk//bazel:defs.bzl", "incompatible_with_config") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_mbedtls_library", + srcs = glob( + ["library/*.c"], + exclude = ["*mbedtls.c"], + ), + hdrs = glob( + include = [ + "include/**/*.h", + "library/*.h", + ], + ), + includes = ["include"], + target_compatible_with = incompatible_with_config("@pico-sdk//bazel/constraint:pico_mbedtls_config_unset"), + deps = [ + "@pico-sdk//src/rp2_common/pico_mbedtls:pico_mbedtls_config", + "@pico-sdk//bazel/config:PICO_MBEDTLS_CONFIG", + ], +) diff --git a/src/rp2_common/pico_mbedtls/pico_mbedtls.c b/src/rp2_common/pico_mbedtls/pico_mbedtls.c index 853d97cdf..c7b61c077 100644 --- a/src/rp2_common/pico_mbedtls/pico_mbedtls.c +++ b/src/rp2_common/pico_mbedtls/pico_mbedtls.c @@ -8,7 +8,6 @@ #include "pico.h" #include "pico/rand.h" #include "mbedtls/sha256.h" -#include "common.h" /* Function to feed mbedtls entropy. */ int mbedtls_hardware_poll(void *data __unused, unsigned char *output, size_t len, size_t *olen) { @@ -27,7 +26,7 @@ int mbedtls_hardware_poll(void *data __unused, unsigned char *output, size_t len #error SHA256 hardware acceleration not supported #endif -// PICO_CONFIG: PICO_MBEDTLS_SHA256_ALT_USE_DMA, Whether to use DMA for writing to hardware for the mbedtls SHA-256 hardware acceleration, type=int, default=1, group=pico_stdlib +// PICO_CONFIG: PICO_MBEDTLS_SHA256_ALT_USE_DMA, Whether to use DMA for writing to hardware for the mbedtls SHA-256 hardware acceleration, type=int, default=1, group=pico_mbedtls #ifndef PICO_MBEDTLS_SHA256_ALT_USE_DMA #define PICO_MBEDTLS_SHA256_ALT_USE_DMA 1 #endif diff --git a/src/rp2_common/tinyusb/CMakeLists.txt b/src/rp2_common/tinyusb/CMakeLists.txt index e305b36c0..88c79b8af 100644 --- a/src/rp2_common/tinyusb/CMakeLists.txt +++ b/src/rp2_common/tinyusb/CMakeLists.txt @@ -1,3 +1,4 @@ +# PICO_CMAKE_CONFIG: PICO_TINYUSB_PATH, Path to an alternative version of tinyusb overriding the version in pico-sdk/libs/tinyusb. Can be passed to cmake or set in your environment, type=string, group=tinyusb_device if (DEFINED ENV{PICO_TINYUSB_PATH} AND (NOT PICO_TINYUSB_PATH)) set(PICO_TINYUSB_PATH $ENV{PICO_TINYUSB_PATH}) message("Using PICO_TINYUSB_PATH from environment ('${PICO_TINYUSB_PATH}')") diff --git a/test/kitchen_sink/BUILD.bazel b/test/kitchen_sink/BUILD.bazel index 1bd595c3e..d703ff320 100644 --- a/test/kitchen_sink/BUILD.bazel +++ b/test/kitchen_sink/BUILD.bazel @@ -110,6 +110,8 @@ cc_binary( ":kitchen_sink_common", "//src/rp2_common/pico_cyw43_arch:pico_cyw43_arch_lwip_poll", "//src/rp2_common/pico_btstack:pico_btstack", + "//src/rp2_common/pico_lwip:pico_lwip_mbedtls", + "//src/rp2_common/pico_mbedtls", ], ) @@ -121,6 +123,9 @@ cc_binary( deps = [ ":kitchen_sink_common", "//src/rp2_common/pico_cyw43_arch:pico_cyw43_arch_lwip_threadsafe_background", + "//src/rp2_common/pico_btstack:pico_btstack", + "//src/rp2_common/pico_lwip:pico_lwip_mbedtls", + "//src/rp2_common/pico_mbedtls", ], ) @@ -130,6 +135,7 @@ kitchen_sink_test_binary( src = ":kitchen_sink_lwip_poll_actual", bt_stack_config = ":btstack_config", lwip_config = ":lwip_config", + mbedtls_config = ":mbedtls_config", enable_ble = True, enable_bt_classic = True, target_compatible_with = compatible_with_rp2(), @@ -141,6 +147,7 @@ kitchen_sink_test_binary( src = ":kitchen_sink_lwip_background_actual", bt_stack_config = ":btstack_config", lwip_config = ":lwip_config", + mbedtls_config = ":mbedtls_config", enable_ble = True, enable_bt_classic = True, target_compatible_with = compatible_with_rp2(), diff --git a/test/kitchen_sink/lwipopts.h b/test/kitchen_sink/lwipopts.h index 58b704a1c..510a20449 100644 --- a/test/kitchen_sink/lwipopts.h +++ b/test/kitchen_sink/lwipopts.h @@ -11,4 +11,10 @@ #define LWIP_DNS 1 #define LWIP_SOCKET 0 #define LWIP_NETCONN 0 -#endif \ No newline at end of file + +// For testing mbedtls +#define LWIP_ALTCP 1 +#define LWIP_ALTCP_TLS 1 +#define LWIP_ALTCP_TLS_MBEDTLS 1 + +#endif diff --git a/test/kitchen_sink/mbedtls_config.h b/test/kitchen_sink/mbedtls_config.h index dae339567..4df2e168f 100644 --- a/test/kitchen_sink/mbedtls_config.h +++ b/test/kitchen_sink/mbedtls_config.h @@ -61,3 +61,4 @@ #define MBEDTLS_ECDSA_C #define MBEDTLS_ASN1_WRITE_C +#define MBEDTLS_PLATFORM_MS_TIME_ALT diff --git a/tools/compare_build_systems.py b/tools/compare_build_systems.py index badeadee1..86dc615a1 100755 --- a/tools/compare_build_systems.py +++ b/tools/compare_build_systems.py @@ -135,6 +135,7 @@ # Bazel configuration for 3p deps. "PICO_BTSTACK_CONFIG", "PICO_LWIP_CONFIG", + "PICO_MBEDTLS_CONFIG", "PICO_FREERTOS_LIB", "PICO_MBEDTLS_LIB", # CMake has PICO_DEFAULT_CLIB, but it's not user-facing. From f674850f0e600932ce8f2c58a20d0e16da7a9156 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:14:26 +0100 Subject: [PATCH 112/224] Fix DST bug in aon_timer_get_time for rp2040 (#2409) If you set the timezone, aon_timer_get_time can wrongly apply a daylight saving time adjustment based on the stack contents. This can make it appear that time has gone backwards. Make sure datetime_to_tm initialises tm_isdst to -1. Fixes #2374 --- src/common/pico_util/datetime.c | 1 + test/pico_time_test/pico_time_test.c | 42 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/common/pico_util/datetime.c b/src/common/pico_util/datetime.c index 130e2d5a6..6b59f287e 100644 --- a/src/common/pico_util/datetime.c +++ b/src/common/pico_util/datetime.c @@ -63,6 +63,7 @@ void datetime_to_tm(const datetime_t *dt, struct tm *tm) { tm->tm_hour = dt->hour; tm->tm_min = dt->min; tm->tm_sec = dt->sec; + tm->tm_isdst = -1; } void tm_to_datetime(const struct tm *tm, datetime_t *dt) { diff --git a/test/pico_time_test/pico_time_test.c b/test/pico_time_test/pico_time_test.c index b8f4cba3c..8b23c5a42 100644 --- a/test/pico_time_test/pico_time_test.c +++ b/test/pico_time_test/pico_time_test.c @@ -85,6 +85,7 @@ static int issue_1953_test(void); static int issue_2118_test(void); static int issue_2148_test(void); static int issue_2186_test(void); +static int issue_2374_test(void); int main() { setup_default_uart(); @@ -263,6 +264,8 @@ int main() { issue_2186_test(); + issue_2374_test(); + PICOTEST_END_TEST(); } @@ -421,3 +424,42 @@ static int issue_2148_test(void) { #endif return 0; } + +static void fill_stack(int val) { + uint8_t array[50]; + memset(array, val, sizeof(array)); +} + +// aon_timer_get_time called aon_timer_get_time_calendar which called datetime_to_tm +// which didn't initialise tm_isdst +static int issue_2374_test(void) { +#if HAS_RP2040_RTC && !__clang__ + PICOTEST_START_SECTION("Issue #2374 defect - time goes backwards"); + setenv("TZ", "PST8PDT7,M3.2.0/2,M11.1.0/02:00:00", 1); + tzset(); + + struct timespec ts = { .tv_sec = 1743055938, .tv_nsec = 0 }; + aon_timer_start(&ts); + + struct timespec ts1; + fill_stack(1); // Setting tm_isdst if it's uninitialised + hard_assert(aon_timer_get_time(&ts1)); + + sleep_ms(1000); + + struct timespec ts2; + fill_stack(0); // Setting tm_isdst if it's uninitialised + hard_assert(aon_timer_get_time(&ts2)); + + // Check time hasn't been adjusted due to dst + hard_assert(ts1.tv_sec == ts2.tv_sec - 1); + + setenv("TZ", "", 1); + tzset(); + + aon_timer_stop(); + + PICOTEST_END_SECTION(); +#endif + return 0; +} From 1721f9db47ba8c1e318b31ea5d3fab776ca17e7a Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:20:49 +0100 Subject: [PATCH 113/224] Add some docs for pico_set_lwip_httpd_content (#2411) --- src/rp2_common/pico_lwip/doc.h | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/rp2_common/pico_lwip/doc.h b/src/rp2_common/pico_lwip/doc.h index 0825fabb6..bbf353387 100644 --- a/src/rp2_common/pico_lwip/doc.h +++ b/src/rp2_common/pico_lwip/doc.h @@ -44,3 +44,47 @@ * \ingroup pico_lwip * \brief lwIP compiler adapters. This is not included by default in \c \b pico_lwip in case you wish to implement your own. */ + +/** \defgroup pico_lwip_http pico_lwip_http + * \ingroup pico_lwip + * \brief LwIP HTTP client and server library + * + * This library enables you to make use of the LwIP HTTP client and server library + * + * \par LwIP HTTP server + * + * To make use of the LwIP HTTP server you need to provide the HTML that the server will return to the client. + * This is done by compiling the content directly into the executable. + * + * \par makefsdata + * + * LwIP provides a c-library tool `makefsdata` to compile your HTML into a source file for inclusion into your program. + * This is quite hard to use as you need to compile the tool as a native binary, then run the tool to generate a source file + * before compiling your code for the Pico device. + * + * \par pico_set_lwip_httpd_content + * + * To make this whole process easier, a python script `makefsdata.py` is provided to generate a source file for your HTML content. + * A CMake function `pico_set_lwip_httpd_content` takes care of running the `makefsdata.py` python script for you. + * To make use of this, specify the name of the source file as `pico_fsdata.inc` in `lwipopts.h`. + * + * \code + * #define HTTPD_FSDATA_FILE "pico_fsdata.inc" + * \endcode + * + * Then call the CMake function `pico_set_lwip_httpd_content` in your `CMakeLists.txt` to add your content to a library. + * Make sure you add this library to your executable by adding it to your target_link_libraries list. + * Here is an example from the httpd example in pico-examples. + * + * \code + * pico_add_library(pico_httpd_content NOFLAG) + * pico_set_lwip_httpd_content(pico_httpd_content INTERFACE + * ${CMAKE_CURRENT_LIST_DIR}/content/404.html + * ${CMAKE_CURRENT_LIST_DIR}/content/index.shtml + * ${CMAKE_CURRENT_LIST_DIR}/content/test.shtml + * ${CMAKE_CURRENT_LIST_DIR}/content/ledpass.shtml + * ${CMAKE_CURRENT_LIST_DIR}/content/ledfail.shtml + * ${CMAKE_CURRENT_LIST_DIR}/content/img/rpi.png + * ) + * \endcode + */ From 6fea77f584f324c9a17186ae206f769eecf96e69 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:22:20 +0100 Subject: [PATCH 114/224] Change BT flash storage default for rp2350 A2 (#2412) The workaround for errata RP2350-E10 overwrites the last block in flash. This will overwrite the BT flash storage causing a paired BT connection to fail. Move the default flash storage location to 3 sectors from the end of flash for RP2350 where A2 support is required. This will require existing BT pairings to a Pico device to be removed and readded. Fixes #2322 --- .../pico_btstack/include/pico/btstack_flash_bank.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_btstack/include/pico/btstack_flash_bank.h b/src/rp2_common/pico_btstack/include/pico/btstack_flash_bank.h index 6d914f00e..d9c838c0f 100644 --- a/src/rp2_common/pico_btstack/include/pico/btstack_flash_bank.h +++ b/src/rp2_common/pico_btstack/include/pico/btstack_flash_bank.h @@ -20,16 +20,24 @@ extern "C" { #define PICO_FLASH_BANK_TOTAL_SIZE (FLASH_SECTOR_SIZE * 2u) #endif -// PICO_CONFIG: PICO_FLASH_BANK_STORAGE_OFFSET, Offset in flash of the Bluetooth flash storage, type=int, default=PICO_FLASH_SIZE_BYTES - PICO_FLASH_BANK_TOTAL_SIZE, group=pico_btstack +// PICO_CONFIG: PICO_FLASH_BANK_STORAGE_OFFSET, Offset in flash of the Bluetooth flash storage, type=int, default=PICO_FLASH_SIZE_BYTES - FLASH_SECTOR_SIZE - PICO_FLASH_BANK_TOTAL_SIZE on RP2350 otherwise PICO_FLASH_SIZE_BYTES - PICO_FLASH_BANK_TOTAL_SIZE, group=pico_btstack #ifndef PICO_FLASH_BANK_STORAGE_OFFSET +#if PICO_RP2350 && PICO_RP2350_A2_SUPPORTED +#define PICO_FLASH_BANK_STORAGE_OFFSET (PICO_FLASH_SIZE_BYTES - FLASH_SECTOR_SIZE - PICO_FLASH_BANK_TOTAL_SIZE) +#else #define PICO_FLASH_BANK_STORAGE_OFFSET (PICO_FLASH_SIZE_BYTES - PICO_FLASH_BANK_TOTAL_SIZE) #endif +#endif /** * \brief Return the singleton BTstack HAL flash instance, used for non-volatile storage * \ingroup pico_btstack * - * \note By default two sectors at the end of flash are used (see \c PICO_FLASH_BANK_STORAGE_OFFSET and \c PICO_FLASH_BANK_TOTAL_SIZE) + * \note By default, two sectors near the end of flash are used. + * For RP2350 when PICO_RP2350_A2_SUPPORTED is true, two sectors that are three sectors from the end of flash are used. + * This keeps the last sector free for a workaround for chip errata RP2350-E10. See the RP2350 datasheet for more details about this. + * Otherwise, two sectors directly at the end of flash are used. + * See \c PICO_FLASH_BANK_STORAGE_OFFSET and \c PICO_FLASH_BANK_TOTAL_SIZE) */ const hal_flash_bank_t *pico_flash_bank_instance(void); From 1ff632128f655ca0c3e3f0ef839a285e3e679c60 Mon Sep 17 00:00:00 2001 From: David Dyck Date: Fri, 11 Apr 2025 06:36:29 -1000 Subject: [PATCH 115/224] Fix #2413 - Misleading comment about bootloader in rp2350/memmap_copy_to_ram.ld (#2415) --- src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld index 89d63a9f0..145faf817 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld @@ -33,10 +33,10 @@ ENTRY(_entry_point) SECTIONS { - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Raspberry Pi Pico SDK - */ + /* On Arm, the bootrom expects a VT at the start of the + image by default; on RISC-V, the default is to enter the image at its + lowest address, so an IMAGEDEF item is required to specify the + nondefault entry point. */ .flash_begin : { __flash_binary_start = .; From 5592322465b449ef01ca5b4290f2f03fdff71381 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Sat, 12 Apr 2025 05:35:09 +0100 Subject: [PATCH 116/224] Add --recursive flag to git submodule cmd (#2416) Update all github workflows because picotool is (properly) using mbedtls in pico-sdk and it now has its own submodules. --- .github/workflows/macOS.yml | 2 +- .github/workflows/multi-gcc.yml | 2 +- .github/workflows/scripts/generate_multi_gcc_workflow.py | 2 +- .github/workflows/windows.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macOS.yml b/.github/workflows/macOS.yml index 42282672f..63048ee73 100644 --- a/.github/workflows/macOS.yml +++ b/.github/workflows/macOS.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init + run: git submodule update --init --recursive - name: Install dependencies run: | brew install cmake diff --git a/.github/workflows/multi-gcc.yml b/.github/workflows/multi-gcc.yml index f20062458..73f42fd36 100644 --- a/.github/workflows/multi-gcc.yml +++ b/.github/workflows/multi-gcc.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init + run: git submodule update --init --recursive - name: Host Release run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) diff --git a/.github/workflows/scripts/generate_multi_gcc_workflow.py b/.github/workflows/scripts/generate_multi_gcc_workflow.py index 7e36f63af..81980f65d 100755 --- a/.github/workflows/scripts/generate_multi_gcc_workflow.py +++ b/.github/workflows/scripts/generate_multi_gcc_workflow.py @@ -94,7 +94,7 @@ def __repr__(self): uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init + run: git submodule update --init --recursive - name: Host Release run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index ea4394af5..64be455a4 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init + run: git submodule update --init --recursive - name: Install dependencies run: choco install .github/workflows/choco_packages.config From fed7188e527baa922f4130b90b39dc64e3dd8eef Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 14 Apr 2025 08:50:25 -0700 Subject: [PATCH 117/224] Rework use of pico_cmake_set in board headers to make it slightly less magic/confusing (#2397) * Rework use of pico_cmake_set in board headers to make it slightly less magic/confusing - prefer "pico_cmake_set(var, value)" over "// pico_cmake_set var = value" - prefer "pico_cmake_set_default(var, value)" over "// pico_cmake_set_default var = value" - move these inside the header include guards as CLion complains Note that the macros are defined in "pico.h" however that is not explicitly included by the board headers; this will probably confuse some VS code syntax highligting, so lets see how it looks - i'd prefer to avoid having to include a header just for this * Update check_board_header.py with the new pico_cmake_set formats * Add brackets back around `PICO_FLASH_SIZE_BYTES` settings The python script checks for an exact match between the #define and the pico_cmake_set_default, so fails without the brackets * Rename to pico_board_cmake_set and pico_board_cmake_set_default * Fix support for old versions --------- Co-authored-by: William Vinnicombe --- cmake/generic_board.cmake | 18 ++++++++-- src/boards/include/boards/0xcb_helios.h | 6 ++-- .../include/boards/adafruit_feather_rp2040.h | 6 ++-- .../boards/adafruit_feather_rp2040_usb_host.h | 6 ++-- .../include/boards/adafruit_feather_rp2350.h | 8 ++--- .../boards/adafruit_itsybitsy_rp2040.h | 6 ++-- src/boards/include/boards/adafruit_kb2040.h | 6 ++-- .../include/boards/adafruit_macropad_rp2040.h | 6 ++-- .../include/boards/adafruit_qtpy_rp2040.h | 6 ++-- .../include/boards/adafruit_trinkey_qt2040.h | 6 ++-- src/boards/include/boards/amethyst_fpga.h | 6 ++-- src/boards/include/boards/archi.h | 6 ++-- .../boards/arduino_nano_rp2040_connect.h | 6 ++-- .../include/boards/cytron_maker_pi_rp2040.h | 6 ++-- .../include/boards/datanoisetv_rp2040_dsp.h | 6 ++-- .../include/boards/datanoisetv_rp2350_dsp.h | 8 ++--- src/boards/include/boards/defcon32_badge.h | 8 ++--- .../boards/eelectronicparts_picomini_16mb.h | 6 ++-- .../boards/eelectronicparts_picomini_2mb.h | 6 ++-- .../boards/eelectronicparts_picomini_4mb.h | 6 ++-- .../boards/eelectronicparts_picomini_8mb.h | 6 ++-- .../include/boards/eetree_gamekit_rp2040.h | 6 ++-- .../boards/garatronic_pybstick26_rp2040.h | 6 ++-- src/boards/include/boards/gen4_rp2350_24.h | 8 ++--- src/boards/include/boards/gen4_rp2350_24ct.h | 8 ++--- src/boards/include/boards/gen4_rp2350_24t.h | 8 ++--- src/boards/include/boards/gen4_rp2350_28.h | 8 ++--- src/boards/include/boards/gen4_rp2350_28ct.h | 8 ++--- src/boards/include/boards/gen4_rp2350_28t.h | 8 ++--- src/boards/include/boards/gen4_rp2350_32.h | 8 ++--- src/boards/include/boards/gen4_rp2350_32ct.h | 8 ++--- src/boards/include/boards/gen4_rp2350_32t.h | 8 ++--- src/boards/include/boards/gen4_rp2350_35.h | 8 ++--- src/boards/include/boards/gen4_rp2350_35ct.h | 8 ++--- src/boards/include/boards/gen4_rp2350_35t.h | 8 ++--- src/boards/include/boards/hellbender_0001.h | 6 ++-- .../boards/hellbender_2350A_devboard.h | 6 ++-- .../boards/ilabs_challenger_rp2350_bconnect.h | 8 ++--- .../boards/ilabs_challenger_rp2350_wifi_ble.h | 8 ++--- src/boards/include/boards/ilabs_opendec02.h | 6 ++-- src/boards/include/boards/machdyne_werkzeug.h | 6 ++-- .../boards/melopero_perpetuo_rp2350_lora.h | 8 ++--- .../include/boards/melopero_shake_rp2040.h | 6 ++-- .../include/boards/metrotech_xerxes_rp2040.h | 6 ++-- .../include/boards/net8086_usb_interposer.h | 6 ++-- .../include/boards/nullbits_bit_c_pro.h | 6 ++-- .../include/boards/phyx_rick_tny_rp2350.h | 8 ++--- src/boards/include/boards/pi-plates_micropi.h | 6 ++-- src/boards/include/boards/pico.h | 6 ++-- src/boards/include/boards/pico2.h | 8 ++--- src/boards/include/boards/pico2_w.h | 10 +++--- src/boards/include/boards/pico_w.h | 8 ++--- .../include/boards/pimoroni_badger2040.h | 6 ++-- .../include/boards/pimoroni_interstate75.h | 6 ++-- .../include/boards/pimoroni_keybow2040.h | 6 ++-- .../include/boards/pimoroni_motor2040.h | 6 ++-- src/boards/include/boards/pimoroni_pga2040.h | 6 ++-- src/boards/include/boards/pimoroni_pga2350.h | 8 ++--- .../boards/pimoroni_pico_plus2_rp2350.h | 8 ++--- .../boards/pimoroni_pico_plus2_w_rp2350.h | 10 +++--- .../include/boards/pimoroni_picolipo_16mb.h | 6 ++-- .../include/boards/pimoroni_picolipo_4mb.h | 6 ++-- .../include/boards/pimoroni_picosystem.h | 6 ++-- .../include/boards/pimoroni_plasma2040.h | 6 ++-- .../include/boards/pimoroni_plasma2350.h | 8 ++--- .../include/boards/pimoroni_servo2040.h | 6 ++-- src/boards/include/boards/pimoroni_tiny2040.h | 6 ++-- .../include/boards/pimoroni_tiny2040_2mb.h | 6 ++-- src/boards/include/boards/pimoroni_tiny2350.h | 8 ++--- .../include/boards/pololu_3pi_2040_robot.h | 6 ++-- .../include/boards/pololu_zumo_2040_robot.h | 6 ++-- src/boards/include/boards/seeed_xiao_rp2040.h | 6 ++-- src/boards/include/boards/seeed_xiao_rp2350.h | 8 ++--- .../include/boards/solderparty_rp2040_stamp.h | 6 ++-- .../boards/solderparty_rp2040_stamp_carrier.h | 4 +-- .../solderparty_rp2040_stamp_round_carrier.h | 4 +-- .../include/boards/solderparty_rp2350_stamp.h | 8 ++--- .../boards/solderparty_rp2350_stamp_xl.h | 8 ++--- .../boards/sparkfun_iotnode_lorawan_rp2350.h | 8 ++--- .../boards/sparkfun_iotredboard_rp2350.h | 10 +++--- src/boards/include/boards/sparkfun_micromod.h | 6 ++-- src/boards/include/boards/sparkfun_promicro.h | 6 ++-- .../include/boards/sparkfun_promicro_rp2350.h | 8 ++--- .../include/boards/sparkfun_thingplus.h | 6 ++-- .../boards/sparkfun_thingplus_rp2350.h | 10 +++--- .../include/boards/sparkfun_xrp_controller.h | 10 +++--- .../switchscience_picossci2_conta_base.h | 8 ++--- .../switchscience_picossci2_dev_board.h | 8 ++--- .../boards/switchscience_picossci2_micro.h | 8 ++--- .../switchscience_picossci2_rp2350_breakout.h | 8 ++--- .../boards/switchscience_picossci2_tiny.h | 8 ++--- .../boards/tinycircuits_thumby_color_rp2350.h | 8 ++--- .../include/boards/waveshare_pico_cam_a.h | 6 ++-- .../include/boards/waveshare_rp2040_ble.h | 6 ++-- .../include/boards/waveshare_rp2040_eth.h | 6 ++-- .../include/boards/waveshare_rp2040_geek.h | 6 ++-- .../boards/waveshare_rp2040_lcd_0.96.h | 6 ++-- .../boards/waveshare_rp2040_lcd_1.28.h | 6 ++-- .../include/boards/waveshare_rp2040_matrix.h | 6 ++-- .../include/boards/waveshare_rp2040_one.h | 6 ++-- .../include/boards/waveshare_rp2040_pizero.h | 6 ++-- .../boards/waveshare_rp2040_plus_16mb.h | 6 ++-- .../boards/waveshare_rp2040_plus_4mb.h | 6 ++-- .../waveshare_rp2040_power_management_hat_b.h | 6 ++-- .../include/boards/waveshare_rp2040_tiny.h | 6 ++-- .../boards/waveshare_rp2040_touch_lcd_1.28.h | 6 ++-- .../include/boards/waveshare_rp2040_zero.h | 6 ++-- .../include/boards/waveshare_rp2350_eth.h | 8 ++--- .../include/boards/waveshare_rp2350_geek.h | 8 ++--- .../boards/waveshare_rp2350_lcd_0.96.h | 8 ++--- .../boards/waveshare_rp2350_lcd_1.28.h | 8 ++--- .../include/boards/waveshare_rp2350_one.h | 8 ++--- .../boards/waveshare_rp2350_plus_16mb.h | 8 ++--- .../boards/waveshare_rp2350_plus_4mb.h | 8 ++--- .../include/boards/waveshare_rp2350_tiny.h | 8 ++--- .../boards/waveshare_rp2350_touch_lcd_1.28.h | 8 ++--- .../include/boards/waveshare_rp2350_zero.h | 8 ++--- .../include/boards/weact_studio_rp2040_16mb.h | 6 ++-- .../include/boards/weact_studio_rp2040_2mb.h | 6 ++-- .../include/boards/weact_studio_rp2040_4mb.h | 6 ++-- .../include/boards/weact_studio_rp2040_8mb.h | 6 ++-- .../include/boards/wiznet_w5100s_evb_pico.h | 6 ++-- src/common/pico_base_headers/include/pico.h | 29 +++++++++++++++ .../boot_stage2/include/boot_stage2/config.h | 2 +- tools/check_board_header.py | 36 +++++++++---------- 125 files changed, 480 insertions(+), 439 deletions(-) diff --git a/cmake/generic_board.cmake b/cmake/generic_board.cmake index c7fdfe5a0..9dd917d50 100644 --- a/cmake/generic_board.cmake +++ b/cmake/generic_board.cmake @@ -20,10 +20,22 @@ if (EXISTS ${PICO_BOARD_HEADER_FILE}) while(HEADER_FILE_CONTENTS) list(POP_FRONT HEADER_FILE_CONTENTS LINE) - if (LINE MATCHES "^[ \t\]*//[ \t\]*pico_cmake_set[ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*=[ \t\]*(.*)") + # pico_board_cmake_set(var, value) + if (LINE MATCHES "^[ \t\]*pico_board_cmake_set[ \t\]*\\([ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*,[ \t\]*(.*)[ \t\]*\\)[ \t\]*") set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") - endif() - if (LINE MATCHES "^[ \t\]*//[ \t\]*pico_cmake_set_default[ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*=[ \t\]*(.*)") + # pico_board_cmake_set_default(var, value) + elseif (LINE MATCHES "^[ \t\]*pico_board_cmake_set_default[ \t\]*\\([ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*,[ \t\]*(.*)[ \t\]*\\)[ \t\]*") + if (NOT DEFINED "${CMAKE_MATCH_1}") + set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") + else() + list(APPEND PICO_BOARD_CMAKE_OVERRIDES ${CMAKE_MATCH_1}) + endif() + # continue to support these for now + # // pico_cmake_set var = value + elseif (LINE MATCHES "^[ \t\]*//[ \t\]*pico_cmake_set[ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*=[ \t\]*(.*)") + set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") + # // pico_cmake_set_default var = value + elseif (LINE MATCHES "^[ \t\]*//[ \t\]*pico_cmake_set_default[ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*=[ \t\]*(.*)") if (NOT DEFINED "${CMAKE_MATCH_1}") set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") else() diff --git a/src/boards/include/boards/0xcb_helios.h b/src/boards/include/boards/0xcb_helios.h index e06c552b5..2f075c063 100644 --- a/src/boards/include/boards/0xcb_helios.h +++ b/src/boards/include/boards/0xcb_helios.h @@ -12,11 +12,11 @@ //------------------------------------------------------------------------------------------ // Board definition for the 0xCB Helios -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_0XCB_HELIOS_H #define _BOARDS_0XCB_HELIOS_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define _0XCB_HELIOS @@ -73,7 +73,7 @@ #endif // board has 16M onboard flash -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/adafruit_feather_rp2040.h b/src/boards/include/boards/adafruit_feather_rp2040.h index c9a6d618d..bbbb80182 100644 --- a/src/boards/include/boards/adafruit_feather_rp2040.h +++ b/src/boards/include/boards/adafruit_feather_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ADAFRUIT_FEATHER_RP2040_H #define _BOARDS_ADAFRUIT_FEATHER_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ADAFRUIT_FEATHER_RP2040 @@ -83,7 +83,7 @@ #define PICO_FLASH_SPI_CLKDIV 4 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/adafruit_feather_rp2040_usb_host.h b/src/boards/include/boards/adafruit_feather_rp2040_usb_host.h index 6175b9423..684f3d1f9 100644 --- a/src/boards/include/boards/adafruit_feather_rp2040_usb_host.h +++ b/src/boards/include/boards/adafruit_feather_rp2040_usb_host.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ADAFRUIT_FEATHER_RP2040_USB_HOST_H #define _BOARDS_ADAFRUIT_FEATHER_RP2040_USB_HOST_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ADAFRUIT_FEATHER_RP2040_USB_HOST @@ -79,7 +79,7 @@ #define PICO_FLASH_SPI_CLKDIV 4 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/adafruit_feather_rp2350.h b/src/boards/include/boards/adafruit_feather_rp2350.h index 75aaaf902..08227df8a 100644 --- a/src/boards/include/boards/adafruit_feather_rp2350.h +++ b/src/boards/include/boards/adafruit_feather_rp2350.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/adafruit_feather_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_ADAFRUIT_FEATHER_RP2350_H #define _BOARDS_ADAFRUIT_FEATHER_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // On some samples, the xosc can take longer to stabilize than is usual #ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER #define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 @@ -78,12 +78,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/adafruit_itsybitsy_rp2040.h b/src/boards/include/boards/adafruit_itsybitsy_rp2040.h index ee5cf9cd4..5bd06ca77 100644 --- a/src/boards/include/boards/adafruit_itsybitsy_rp2040.h +++ b/src/boards/include/boards/adafruit_itsybitsy_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ADAFRUIT_ITSYBITSY_RP2040_H #define _BOARDS_ADAFRUIT_ITSYBITSY_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ADAFRUIT_ITSYBITSY_RP2040 @@ -86,7 +86,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/adafruit_kb2040.h b/src/boards/include/boards/adafruit_kb2040.h index f63fc77e3..affb90cbb 100644 --- a/src/boards/include/boards/adafruit_kb2040.h +++ b/src/boards/include/boards/adafruit_kb2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ADAFRUIT_KB2040_H #define _BOARDS_ADAFRUIT_KB2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ADAFRUIT_KB2040 @@ -78,7 +78,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/adafruit_macropad_rp2040.h b/src/boards/include/boards/adafruit_macropad_rp2040.h index 672ada963..1b61d1314 100644 --- a/src/boards/include/boards/adafruit_macropad_rp2040.h +++ b/src/boards/include/boards/adafruit_macropad_rp2040.h @@ -12,11 +12,11 @@ #ifndef _BOARDS_ADAFRUIT_MACROPAD_RP2040_H #define _BOARDS_ADAFRUIT_MACROPAD_RP2040_H -// pico_cmake_set PICO_PLATFORM=rp2040 - // For board detection #define ADAFRUIT_MACROPAD_RP2040 +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // On some samples, the xosc can take longer to stabilize than is usual #ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER #define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 @@ -173,7 +173,7 @@ #define PICO_FLASH_SPI_CLKDIV 4 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/adafruit_qtpy_rp2040.h b/src/boards/include/boards/adafruit_qtpy_rp2040.h index 722d23003..60c891595 100644 --- a/src/boards/include/boards/adafruit_qtpy_rp2040.h +++ b/src/boards/include/boards/adafruit_qtpy_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ADAFRUIT_QTPY_RP2040_H #define _BOARDS_ADAFRUIT_QTPY_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ADAFRUIT_QTPY_RP2040 @@ -85,7 +85,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/adafruit_trinkey_qt2040.h b/src/boards/include/boards/adafruit_trinkey_qt2040.h index 06e294940..4af1809ce 100644 --- a/src/boards/include/boards/adafruit_trinkey_qt2040.h +++ b/src/boards/include/boards/adafruit_trinkey_qt2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ADAFRUIT_TRINKEY_QT2040_H #define _BOARDS_ADAFRUIT_TRINKEY_QT2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ADAFRUIT_TRINKEY_QT2040 @@ -63,7 +63,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/amethyst_fpga.h b/src/boards/include/boards/amethyst_fpga.h index 190a07675..fbe7bd25a 100644 --- a/src/boards/include/boards/amethyst_fpga.h +++ b/src/boards/include/boards/amethyst_fpga.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_AMETHYST_FPGA_H #define _BOARDS_AMETHYST_FPGA_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + #if !PICO_RP2350 #error "Invalid PICO_PLATFORM for amethyst_fpga.h: must be rp2350 or rp2350-riscv" #endif @@ -98,7 +98,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/archi.h b/src/boards/include/boards/archi.h index 13b7d7ea0..076cfe096 100644 --- a/src/boards/include/boards/archi.h +++ b/src/boards/include/boards/archi.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/archi.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ARCHI_H #define _BOARDS_ARCHI_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ARCHI @@ -104,7 +104,7 @@ #define PICO_FLASH_SPI_CLKDIV 4 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/arduino_nano_rp2040_connect.h b/src/boards/include/boards/arduino_nano_rp2040_connect.h index 9cd3035f5..57d5e0c1d 100644 --- a/src/boards/include/boards/arduino_nano_rp2040_connect.h +++ b/src/boards/include/boards/arduino_nano_rp2040_connect.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ARDUINO_NANO_RP2040_CONNECT_H #define _BOARDS_ARDUINO_NANO_RP2040_CONNECT_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ARDUINO_NANO_RP2040_CONNECT @@ -74,7 +74,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/cytron_maker_pi_rp2040.h b/src/boards/include/boards/cytron_maker_pi_rp2040.h index 9d2f0eb69..52be09cad 100644 --- a/src/boards/include/boards/cytron_maker_pi_rp2040.h +++ b/src/boards/include/boards/cytron_maker_pi_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_CYTRON_MAKER_PI_RP2040_H #define _BOARDS_CYTRON_MAKER_PI_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define CYTRON_MAKER_PI_RP2040 @@ -179,7 +179,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/datanoisetv_rp2040_dsp.h b/src/boards/include/boards/datanoisetv_rp2040_dsp.h index ae583baa4..6084efe26 100644 --- a/src/boards/include/boards/datanoisetv_rp2040_dsp.h +++ b/src/boards/include/boards/datanoisetv_rp2040_dsp.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/datanoisetv_rp2040_dsp.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_DATANOISETV_RP2040_DSP_H #define _BOARDS_DATANOISETV_RP2040_DSP_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define DATANOISETV_RP2040_DSP @@ -40,7 +40,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/datanoisetv_rp2350_dsp.h b/src/boards/include/boards/datanoisetv_rp2350_dsp.h index feb5792c0..1195e3c1e 100644 --- a/src/boards/include/boards/datanoisetv_rp2350_dsp.h +++ b/src/boards/include/boards/datanoisetv_rp2350_dsp.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/datanoisetv_rp2350_dsp.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_DATANOISETV_RP2350_DSP_H #define _BOARDS_DATANOISETV_RP2350_DSP_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define DATANOISETV_RP2350_DSP @@ -43,12 +43,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/defcon32_badge.h b/src/boards/include/boards/defcon32_badge.h index 3466fc711..ce18d6157 100644 --- a/src/boards/include/boards/defcon32_badge.h +++ b/src/boards/include/boards/defcon32_badge.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_DEFCON32_BADGE_H #define _BOARDS_DEFCON32_BADGE_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define DEFCON32_BADGE @@ -103,12 +103,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/eelectronicparts_picomini_16mb.h b/src/boards/include/boards/eelectronicparts_picomini_16mb.h index 52a530813..2121628d4 100644 --- a/src/boards/include/boards/eelectronicparts_picomini_16mb.h +++ b/src/boards/include/boards/eelectronicparts_picomini_16mb.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/eelectronicparts_picomini_16mb.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_EELECTRONICPARTS_PICOMINI_16MB_H #define _BOARDS_EELECTRONICPARTS_PICOMINI_16MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define EELECTRONICPARTS_PICOMINI_16MB @@ -72,7 +72,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES // This board comes in 2MB, 4MB, 8MB, and 16MB variants #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) diff --git a/src/boards/include/boards/eelectronicparts_picomini_2mb.h b/src/boards/include/boards/eelectronicparts_picomini_2mb.h index e0fcab1ff..e10fc35ab 100644 --- a/src/boards/include/boards/eelectronicparts_picomini_2mb.h +++ b/src/boards/include/boards/eelectronicparts_picomini_2mb.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/eelectronicparts_picomini_2mb.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_EELECTRONICPARTS_PICOMINI_2MB_H #define _BOARDS_EELECTRONICPARTS_PICOMINI_2MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define EELECTRONICPARTS_PICOMINI_2MB @@ -72,7 +72,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES // This board comes in 2MB, 4MB, 8MB, and 16MB variants #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) diff --git a/src/boards/include/boards/eelectronicparts_picomini_4mb.h b/src/boards/include/boards/eelectronicparts_picomini_4mb.h index 132dc0c90..a8bc8e571 100644 --- a/src/boards/include/boards/eelectronicparts_picomini_4mb.h +++ b/src/boards/include/boards/eelectronicparts_picomini_4mb.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/eelectronicparts_picomini_4mb.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_EELECTRONICPARTS_PICOMINI_4MB_H #define _BOARDS_EELECTRONICPARTS_PICOMINI_4MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define EELECTRONICPARTS_PICOMINI_4MB @@ -72,7 +72,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES // This board comes in 2MB, 4MB, 8MB, and 16MB variants #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) diff --git a/src/boards/include/boards/eelectronicparts_picomini_8mb.h b/src/boards/include/boards/eelectronicparts_picomini_8mb.h index 479e11050..d7f19f348 100644 --- a/src/boards/include/boards/eelectronicparts_picomini_8mb.h +++ b/src/boards/include/boards/eelectronicparts_picomini_8mb.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/eelectronicparts_picomini_8mb.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_EELECTRONICPARTS_PICOMINI_8MB_H #define _BOARDS_EELECTRONICPARTS_PICOMINI_8MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define EELECTRONICPARTS_PICOMINI_8MB @@ -72,7 +72,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES // This board comes in 2MB, 4MB, 8MB, and 16MB variants #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) diff --git a/src/boards/include/boards/eetree_gamekit_rp2040.h b/src/boards/include/boards/eetree_gamekit_rp2040.h index 3df871988..f1e72dac0 100644 --- a/src/boards/include/boards/eetree_gamekit_rp2040.h +++ b/src/boards/include/boards/eetree_gamekit_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_EETREE_GAMEKIT_RP2040_H #define _BOARDS_EETREE_GAMEKIT_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define EETREE_GAMEKIT_RP2040 @@ -69,7 +69,7 @@ #ifndef PICO_FLASH_SPI_CLKDIV #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/garatronic_pybstick26_rp2040.h b/src/boards/include/boards/garatronic_pybstick26_rp2040.h index d245c8209..190cefe40 100644 --- a/src/boards/include/boards/garatronic_pybstick26_rp2040.h +++ b/src/boards/include/boards/garatronic_pybstick26_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_GARATRONIC_PYBSTICK26_RP2040_H #define _BOARDS_GARATRONIC_PYBSTICK26_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define GARATRONIC_PYBSTICK26_RP2040 @@ -70,7 +70,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (1 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (1 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (1 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/gen4_rp2350_24.h b/src/boards/include/boards/gen4_rp2350_24.h index ec479653e..06e0bb1d0 100644 --- a/src/boards/include/boards/gen4_rp2350_24.h +++ b/src/boards/include/boards/gen4_rp2350_24.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_24_H #define _BOARDS_GEN4_RP2350_24_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_24 @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_24ct.h b/src/boards/include/boards/gen4_rp2350_24ct.h index 71b8f2e66..864a023ec 100644 --- a/src/boards/include/boards/gen4_rp2350_24ct.h +++ b/src/boards/include/boards/gen4_rp2350_24ct.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_24CT_H #define _BOARDS_GEN4_RP2350_24CT_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_24CT // CLB variants are exactly the same in operation @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_24t.h b/src/boards/include/boards/gen4_rp2350_24t.h index df086fae5..129fec9c8 100644 --- a/src/boards/include/boards/gen4_rp2350_24t.h +++ b/src/boards/include/boards/gen4_rp2350_24t.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_24T_H #define _BOARDS_GEN4_RP2350_24T_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_24T @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_28.h b/src/boards/include/boards/gen4_rp2350_28.h index b460b8780..39cef5c90 100644 --- a/src/boards/include/boards/gen4_rp2350_28.h +++ b/src/boards/include/boards/gen4_rp2350_28.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_28_H #define _BOARDS_GEN4_RP2350_28_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_28 @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_28ct.h b/src/boards/include/boards/gen4_rp2350_28ct.h index 11153e143..e581a97c4 100644 --- a/src/boards/include/boards/gen4_rp2350_28ct.h +++ b/src/boards/include/boards/gen4_rp2350_28ct.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_28CT_H #define _BOARDS_GEN4_RP2350_28CT_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_28CT // CLB variants are exactly the same in operation @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_28t.h b/src/boards/include/boards/gen4_rp2350_28t.h index c948c9eb1..a2c3af327 100644 --- a/src/boards/include/boards/gen4_rp2350_28t.h +++ b/src/boards/include/boards/gen4_rp2350_28t.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_28T_H #define _BOARDS_GEN4_RP2350_28T_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_28T @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_32.h b/src/boards/include/boards/gen4_rp2350_32.h index 896937744..2adc570ea 100644 --- a/src/boards/include/boards/gen4_rp2350_32.h +++ b/src/boards/include/boards/gen4_rp2350_32.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_32_H #define _BOARDS_GEN4_RP2350_32_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_32 @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_32ct.h b/src/boards/include/boards/gen4_rp2350_32ct.h index 0e137357e..9624c2d36 100644 --- a/src/boards/include/boards/gen4_rp2350_32ct.h +++ b/src/boards/include/boards/gen4_rp2350_32ct.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_32CT_H #define _BOARDS_GEN4_RP2350_32CT_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_32CT // CLB variants are exactly the same in operation @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_32t.h b/src/boards/include/boards/gen4_rp2350_32t.h index 6280f0d7d..a335e6233 100644 --- a/src/boards/include/boards/gen4_rp2350_32t.h +++ b/src/boards/include/boards/gen4_rp2350_32t.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_32T_H #define _BOARDS_GEN4_RP2350_32T_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_32T @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_35.h b/src/boards/include/boards/gen4_rp2350_35.h index d26f53034..2dd4eca69 100644 --- a/src/boards/include/boards/gen4_rp2350_35.h +++ b/src/boards/include/boards/gen4_rp2350_35.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_35_H #define _BOARDS_GEN4_RP2350_35_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_35 @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_35ct.h b/src/boards/include/boards/gen4_rp2350_35ct.h index 8576ac503..fbdd13d40 100644 --- a/src/boards/include/boards/gen4_rp2350_35ct.h +++ b/src/boards/include/boards/gen4_rp2350_35ct.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_35CT_H #define _BOARDS_GEN4_RP2350_35CT_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_35CT // CLB variants are exactly the same in operation @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/gen4_rp2350_35t.h b/src/boards/include/boards/gen4_rp2350_35t.h index ee8cb2385..bec4bfd39 100644 --- a/src/boards/include/boards/gen4_rp2350_35t.h +++ b/src/boards/include/boards/gen4_rp2350_35t.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_GEN4_RP2350_35T_H #define _BOARDS_GEN4_RP2350_35T_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define GEN4_RP2350_35T @@ -71,12 +71,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/hellbender_0001.h b/src/boards/include/boards/hellbender_0001.h index 9f43803e6..5f9ceca13 100644 --- a/src/boards/include/boards/hellbender_0001.h +++ b/src/boards/include/boards/hellbender_0001.h @@ -12,7 +12,7 @@ #ifndef _BOARDS_HELLBENDER_0001_H #define _BOARDS_HELLBENDER_0001_H -// pico_cmake_set PICO_PLATFORM=rp2350 +pico_board_cmake_set(PICO_PLATFORM, rp2350) // For board detection #define HELLBENDER_0001 @@ -130,7 +130,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif @@ -140,7 +140,7 @@ // --- RP2350 VARIANT --- #define PICO_RP2350A 0 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/hellbender_2350A_devboard.h b/src/boards/include/boards/hellbender_2350A_devboard.h index 63753bcca..b2be28d3a 100644 --- a/src/boards/include/boards/hellbender_2350A_devboard.h +++ b/src/boards/include/boards/hellbender_2350A_devboard.h @@ -12,7 +12,7 @@ #ifndef _BOARDS_HELLBENDER_2350A_DEVBOARD_H #define _BOARDS_HELLBENDER_2350A_DEVBOARD_H -// pico_cmake_set PICO_PLATFORM=rp2350 +pico_board_cmake_set(PICO_PLATFORM, rp2350) // For board detection #define HELLBENDER_2350A_DEVBOARD @@ -84,14 +84,14 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif // --- RP2350 VARIANT --- #define PICO_RP2350A 1 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/ilabs_challenger_rp2350_bconnect.h b/src/boards/include/boards/ilabs_challenger_rp2350_bconnect.h index 92d8960b8..97645a456 100644 --- a/src/boards/include/boards/ilabs_challenger_rp2350_bconnect.h +++ b/src/boards/include/boards/ilabs_challenger_rp2350_bconnect.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/ilabs_challenger_rp2350_bconnect.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_ILABS_CHALLENGER_RP2350_BCONNECT_H #define _BOARDS_ILABS_CHALLENGER_RP2350_BCONNECT_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define ILABS_CHALLENGER_RP2350_BCONNECT @@ -78,12 +78,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/ilabs_challenger_rp2350_wifi_ble.h b/src/boards/include/boards/ilabs_challenger_rp2350_wifi_ble.h index 1278209b8..b056cbcab 100644 --- a/src/boards/include/boards/ilabs_challenger_rp2350_wifi_ble.h +++ b/src/boards/include/boards/ilabs_challenger_rp2350_wifi_ble.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/ilabs_challenger_rp2350_wifi_ble.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_ILABS_CHALLENGER_RP2350_WIFI_BLE_H #define _BOARDS_ILABS_CHALLENGER_RP2350_WIFI_BLE_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define ILABS_CHALLENGER_RP2350_WIFI_BLE @@ -75,12 +75,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/ilabs_opendec02.h b/src/boards/include/boards/ilabs_opendec02.h index 197a024ec..f9b76a805 100644 --- a/src/boards/include/boards/ilabs_opendec02.h +++ b/src/boards/include/boards/ilabs_opendec02.h @@ -12,11 +12,11 @@ //------------------------------------------------------------------------------------------ // Board definition for the opendec02 open source dcc decoder // -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_ILABS_OPENDEC02_H #define _BOARDS_ILABS_OPENDEC02_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define ILABS_OPENDEC02 @@ -50,7 +50,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/machdyne_werkzeug.h b/src/boards/include/boards/machdyne_werkzeug.h index 8b45829b7..f624750cf 100644 --- a/src/boards/include/boards/machdyne_werkzeug.h +++ b/src/boards/include/boards/machdyne_werkzeug.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_MACHDYNE_WERKZEUG_H #define _BOARDS_MACHDYNE_WERKZEUG_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define MACHDYNE_WERKZEUG @@ -75,7 +75,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (1 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (1 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (1 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/melopero_perpetuo_rp2350_lora.h b/src/boards/include/boards/melopero_perpetuo_rp2350_lora.h index e86492b39..03e6568f4 100644 --- a/src/boards/include/boards/melopero_perpetuo_rp2350_lora.h +++ b/src/boards/include/boards/melopero_perpetuo_rp2350_lora.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/melopero_perpetuo_rp2350_lora.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_MELOPERO_PERPETUO_RP2350_LORA_H #define _BOARDS_MELOPERO_PERPETUO_RP2350_LORA_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define MELOPERO_PERPETUO_RP2350_LORA @@ -75,14 +75,14 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/melopero_shake_rp2040.h b/src/boards/include/boards/melopero_shake_rp2040.h index 49059c9ab..6a2f8564e 100644 --- a/src/boards/include/boards/melopero_shake_rp2040.h +++ b/src/boards/include/boards/melopero_shake_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_MELOPERO_SHAKE_RP2040_H #define _BOARDS_MELOPERO_SHAKE_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define MELOPERO_SHAKE_RP2040 @@ -82,7 +82,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/metrotech_xerxes_rp2040.h b/src/boards/include/boards/metrotech_xerxes_rp2040.h index a91d893ff..9998e92e3 100644 --- a/src/boards/include/boards/metrotech_xerxes_rp2040.h +++ b/src/boards/include/boards/metrotech_xerxes_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_METROTECH_XERXES_RP2040_H #define _BOARDS_METROTECH_XERXES_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + #define USR_SW_PIN 18 #define USR_BTN_PIN 24 #define USR_LED_PIN 25 @@ -144,7 +144,7 @@ #define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 16 #endif // !PICO_XOSC_STARTUP_DELAY_MULTIPLIER -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES /** * @brief 16MiB, Flash size in bytes diff --git a/src/boards/include/boards/net8086_usb_interposer.h b/src/boards/include/boards/net8086_usb_interposer.h index 4de560f44..09bd7724d 100644 --- a/src/boards/include/boards/net8086_usb_interposer.h +++ b/src/boards/include/boards/net8086_usb_interposer.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_NET8086_USB_INTERPOSER_H #define _BOARDS_NET8086_USB_INTERPOSER_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define NET8086_USB_INTERPOSER @@ -62,7 +62,7 @@ #define PICO_FLASH_SPI_CLKDIV 4 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/nullbits_bit_c_pro.h b/src/boards/include/boards/nullbits_bit_c_pro.h index 58bb1adc8..d9e6b3149 100644 --- a/src/boards/include/boards/nullbits_bit_c_pro.h +++ b/src/boards/include/boards/nullbits_bit_c_pro.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/nullbits_bit_c_pro.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_NULLBITS_BIT_C_PRO_H #define _BOARDS_NULLBITS_BIT_C_PRO_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define NULLBITS_BIT_C_PRO @@ -100,7 +100,7 @@ #endif // Bit-C PRO has 4MB SPI flash -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/phyx_rick_tny_rp2350.h b/src/boards/include/boards/phyx_rick_tny_rp2350.h index 7012ac141..c0a5a9cb9 100644 --- a/src/boards/include/boards/phyx_rick_tny_rp2350.h +++ b/src/boards/include/boards/phyx_rick_tny_rp2350.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/phyx_rick_tny_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_PHYX_RICK_TNY_RP2350_H #define _BOARDS_PHYX_RICK_TNY_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define PHYX_RICK_TNY_RP2350 @@ -75,12 +75,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/pi-plates_micropi.h b/src/boards/include/boards/pi-plates_micropi.h index 9c0dd62f2..3ae5c67ae 100644 --- a/src/boards/include/boards/pi-plates_micropi.h +++ b/src/boards/include/boards/pi-plates_micropi.h @@ -11,11 +11,11 @@ // Board definition for the Pi-Plates MICROPi processor board -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PI_PLATES_MICROPI_H #define _BOARDS_PI_PLATES_MICROPI_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PI_PLATES_MICROPI @@ -72,7 +72,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) //change to (16 * 1024 * 1024) on final product #endif diff --git a/src/boards/include/boards/pico.h b/src/boards/include/boards/pico.h index 800feb364..6eb8600b6 100644 --- a/src/boards/include/boards/pico.h +++ b/src/boards/include/boards/pico.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/pico.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PICO_H #define _BOARDS_PICO_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define RASPBERRYPI_PICO @@ -72,7 +72,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pico2.h b/src/boards/include/boards/pico2.h index 4dbb232d2..9998939ea 100644 --- a/src/boards/include/boards/pico2.h +++ b/src/boards/include/boards/pico2.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/pico2.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_PICO2_H #define _BOARDS_PICO2_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define RASPBERRYPI_PICO2 @@ -75,7 +75,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif @@ -93,7 +93,7 @@ #define PICO_VSYS_PIN 29 #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/pico2_w.h b/src/boards/include/boards/pico2_w.h index 42acdc4cc..74f5a739b 100644 --- a/src/boards/include/boards/pico2_w.h +++ b/src/boards/include/boards/pico2_w.h @@ -11,12 +11,12 @@ // This header may be included by other board headers as "boards/pico2_w.h" -// pico_cmake_set PICO_PLATFORM=rp2350 -// pico_cmake_set PICO_CYW43_SUPPORTED = 1 - #ifndef _BOARDS_PICO2_W_H #define _BOARDS_PICO2_W_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) +pico_board_cmake_set(PICO_CYW43_SUPPORTED, 1) + // For board detection #define RASPBERRYPI_PICO2_W @@ -74,7 +74,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif @@ -109,7 +109,7 @@ #define PICO_VSYS_PIN 29 #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/pico_w.h b/src/boards/include/boards/pico_w.h index 250662f1b..6e825f680 100644 --- a/src/boards/include/boards/pico_w.h +++ b/src/boards/include/boards/pico_w.h @@ -9,14 +9,14 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM = rp2040 -// pico_cmake_set PICO_CYW43_SUPPORTED = 1 - // This header may be included by other board headers as "boards/pico_w.h" #ifndef _BOARDS_PICO_W_H #define _BOARDS_PICO_W_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) +pico_board_cmake_set(PICO_CYW43_SUPPORTED, 1) + // For board detection #define RASPBERRYPI_PICO_W @@ -71,7 +71,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_badger2040.h b/src/boards/include/boards/pimoroni_badger2040.h index d05c4d4b5..d4e8a34bd 100644 --- a/src/boards/include/boards/pimoroni_badger2040.h +++ b/src/boards/include/boards/pimoroni_badger2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_BADGER2040_H #define _BOARDS_PIMORONI_BADGER2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_BADGER2040 @@ -106,7 +106,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_interstate75.h b/src/boards/include/boards/pimoroni_interstate75.h index e7baa07b2..067632c0b 100644 --- a/src/boards/include/boards/pimoroni_interstate75.h +++ b/src/boards/include/boards/pimoroni_interstate75.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_INTERSTATE75_H #define _BOARDS_PIMORONI_INTERSTATE75_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_INTERSTATE75 @@ -96,7 +96,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_keybow2040.h b/src/boards/include/boards/pimoroni_keybow2040.h index 083140294..e661b9e9d 100644 --- a/src/boards/include/boards/pimoroni_keybow2040.h +++ b/src/boards/include/boards/pimoroni_keybow2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_KEYBOW2040_H #define _BOARDS_PIMORONI_KEYBOW2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_KEYBOW2040 @@ -85,7 +85,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_motor2040.h b/src/boards/include/boards/pimoroni_motor2040.h index e183090c3..1e202f6e2 100644 --- a/src/boards/include/boards/pimoroni_motor2040.h +++ b/src/boards/include/boards/pimoroni_motor2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_MOTOR2040_H #define _BOARDS_PIMORONI_MOTOR2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_MOTOR2040 @@ -128,7 +128,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_pga2040.h b/src/boards/include/boards/pimoroni_pga2040.h index 25b9dd2b5..a33831fe5 100644 --- a/src/boards/include/boards/pimoroni_pga2040.h +++ b/src/boards/include/boards/pimoroni_pga2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_PGA2040_H #define _BOARDS_PIMORONI_PGA2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_PGA2040 @@ -69,7 +69,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_pga2350.h b/src/boards/include/boards/pimoroni_pga2350.h index 1bd02dc48..7849444f5 100644 --- a/src/boards/include/boards/pimoroni_pga2350.h +++ b/src/boards/include/boards/pimoroni_pga2350.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/pimoroni_pga2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_PIMORONI_PGA2350_H #define _BOARDS_PIMORONI_PGA2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define PIMORONI_PGA2350 #define PIMORONI_PGA2350_16MB @@ -79,7 +79,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif @@ -88,7 +88,7 @@ // no PICO_VBUS_PIN // no PICO_VSYS_PIN -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/pimoroni_pico_plus2_rp2350.h b/src/boards/include/boards/pimoroni_pico_plus2_rp2350.h index 40fff17d7..6cae74b11 100644 --- a/src/boards/include/boards/pimoroni_pico_plus2_rp2350.h +++ b/src/boards/include/boards/pimoroni_pico_plus2_rp2350.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/pimoroni_pico_plus2_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_PIMORONI_PICO_PLUS2_RP2350_H #define _BOARDS_PIMORONI_PICO_PLUS2_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define PIMORONI_PICO_PLUS2_RP2350 @@ -86,7 +86,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif @@ -102,7 +102,7 @@ #define PICO_VSYS_PIN 43 #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/pimoroni_pico_plus2_w_rp2350.h b/src/boards/include/boards/pimoroni_pico_plus2_w_rp2350.h index 7a4f1741f..7f125aaa0 100644 --- a/src/boards/include/boards/pimoroni_pico_plus2_w_rp2350.h +++ b/src/boards/include/boards/pimoroni_pico_plus2_w_rp2350.h @@ -11,12 +11,12 @@ // This header may be included by other board headers as "boards/pimoroni_pico_plus2_w_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 -// pico_cmake_set PICO_CYW43_SUPPORTED = 1 - #ifndef _BOARDS_PIMORONI_PICO_PLUS2_W_RP2350_H #define _BOARDS_PIMORONI_PICO_PLUS2_W_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) +pico_board_cmake_set(PICO_CYW43_SUPPORTED, 1) + // For board detection #define PIMORONI_PICO_PLUS2_W_RP2350 @@ -78,7 +78,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif @@ -89,7 +89,7 @@ #define PICO_VSYS_PIN 43 #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/pimoroni_picolipo_16mb.h b/src/boards/include/boards/pimoroni_picolipo_16mb.h index ad5bdf37c..d628b4422 100644 --- a/src/boards/include/boards/pimoroni_picolipo_16mb.h +++ b/src/boards/include/boards/pimoroni_picolipo_16mb.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_PICOLIPO_16MB_H #define _BOARDS_PIMORONI_PICOLIPO_16MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_PICOLIPO_16MB @@ -74,7 +74,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_picolipo_4mb.h b/src/boards/include/boards/pimoroni_picolipo_4mb.h index 981156fc3..1ea1beb91 100644 --- a/src/boards/include/boards/pimoroni_picolipo_4mb.h +++ b/src/boards/include/boards/pimoroni_picolipo_4mb.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_PICOLIPO_4MB_H #define _BOARDS_PIMORONI_PICOLIPO_4MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_PICOLIPO_4MB @@ -74,7 +74,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_picosystem.h b/src/boards/include/boards/pimoroni_picosystem.h index bacbd5734..59b8322b6 100644 --- a/src/boards/include/boards/pimoroni_picosystem.h +++ b/src/boards/include/boards/pimoroni_picosystem.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_PICOSYSTEM_H #define _BOARDS_PIMORONI_PICOSYSTEM_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_PICOSYSTEM @@ -91,7 +91,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_plasma2040.h b/src/boards/include/boards/pimoroni_plasma2040.h index c9937ef2f..d9d7db7f8 100644 --- a/src/boards/include/boards/pimoroni_plasma2040.h +++ b/src/boards/include/boards/pimoroni_plasma2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_PLASMA2040_H #define _BOARDS_PIMORONI_PLASMA2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_PLASMA2040 @@ -83,7 +83,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_plasma2350.h b/src/boards/include/boards/pimoroni_plasma2350.h index 7525a8a84..497bdbc80 100644 --- a/src/boards/include/boards/pimoroni_plasma2350.h +++ b/src/boards/include/boards/pimoroni_plasma2350.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/pimoroni_plasma2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_PIMORONI_PLASMA2350_H #define _BOARDS_PIMORONI_PLASMA2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define PIMORONI_PLASMA2350 @@ -104,12 +104,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/pimoroni_servo2040.h b/src/boards/include/boards/pimoroni_servo2040.h index 21f7049d7..55443c641 100644 --- a/src/boards/include/boards/pimoroni_servo2040.h +++ b/src/boards/include/boards/pimoroni_servo2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_SERVO2040_H #define _BOARDS_PIMORONI_SERVO2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_SERVO2040 @@ -104,7 +104,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_tiny2040.h b/src/boards/include/boards/pimoroni_tiny2040.h index 34e21f908..e38902083 100644 --- a/src/boards/include/boards/pimoroni_tiny2040.h +++ b/src/boards/include/boards/pimoroni_tiny2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_TINY2040_H #define _BOARDS_PIMORONI_TINY2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_TINY2040 #define PIMORONI_TINY2040_8MB @@ -92,7 +92,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_tiny2040_2mb.h b/src/boards/include/boards/pimoroni_tiny2040_2mb.h index 8e411cfdb..f7b24725d 100644 --- a/src/boards/include/boards/pimoroni_tiny2040_2mb.h +++ b/src/boards/include/boards/pimoroni_tiny2040_2mb.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_PIMORONI_TINY2040_2MB_H #define _BOARDS_PIMORONI_TINY2040_2MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define PIMORONI_TINY2040_2MB #define PIMORONI_TINY2040 @@ -92,7 +92,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/pimoroni_tiny2350.h b/src/boards/include/boards/pimoroni_tiny2350.h index bf00cbdb9..94e522c7e 100644 --- a/src/boards/include/boards/pimoroni_tiny2350.h +++ b/src/boards/include/boards/pimoroni_tiny2350.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/pimoroni_tiny2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_PIMORONI_TINY2350_H #define _BOARDS_PIMORONI_TINY2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define PIMORONI_TINY2350 #define PIMORONI_TINY2350_8MB @@ -84,12 +84,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/pololu_3pi_2040_robot.h b/src/boards/include/boards/pololu_3pi_2040_robot.h index 53e0db449..5479c0c83 100644 --- a/src/boards/include/boards/pololu_3pi_2040_robot.h +++ b/src/boards/include/boards/pololu_3pi_2040_robot.h @@ -9,18 +9,18 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_POLOLU_3PI_2040_ROBOT_H #define _BOARDS_POLOLU_3PI_2040_ROBOT_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define POLOLU_3PI_2040_ROBOT #define PICO_DEFAULT_LED_PIN 25 #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 #define PICO_FLASH_SPI_CLKDIV 2 -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) // All boards have at least the B1 revision diff --git a/src/boards/include/boards/pololu_zumo_2040_robot.h b/src/boards/include/boards/pololu_zumo_2040_robot.h index 756b45a82..63abd1c24 100644 --- a/src/boards/include/boards/pololu_zumo_2040_robot.h +++ b/src/boards/include/boards/pololu_zumo_2040_robot.h @@ -9,18 +9,18 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_POLOLU_ZUMO_2040_ROBOT_H #define _BOARDS_POLOLU_ZUMO_2040_ROBOT_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define POLOLU_ZUMO_2040_ROBOT #define PICO_DEFAULT_LED_PIN 25 #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 #define PICO_FLASH_SPI_CLKDIV 2 -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) // All boards have at least the B1 revision diff --git a/src/boards/include/boards/seeed_xiao_rp2040.h b/src/boards/include/boards/seeed_xiao_rp2040.h index efdb4cb18..a6b8f27d4 100644 --- a/src/boards/include/boards/seeed_xiao_rp2040.h +++ b/src/boards/include/boards/seeed_xiao_rp2040.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_SEEED_XIAO_RP2040_H #define _BOARDS_SEEED_XIAO_RP2040_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define SEEED_XIAO_RP2040 @@ -90,7 +90,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/seeed_xiao_rp2350.h b/src/boards/include/boards/seeed_xiao_rp2350.h index 69a2ba40b..949d6741d 100644 --- a/src/boards/include/boards/seeed_xiao_rp2350.h +++ b/src/boards/include/boards/seeed_xiao_rp2350.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SEEED_XIAO_RP2350_H #define _BOARDS_SEEED_XIAO_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SEEED_XIAO_RP2350 @@ -140,12 +140,12 @@ #define PICO_FLASH_SPI_CLKDIV 4 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/solderparty_rp2040_stamp.h b/src/boards/include/boards/solderparty_rp2040_stamp.h index af107f65a..fc95bec08 100644 --- a/src/boards/include/boards/solderparty_rp2040_stamp.h +++ b/src/boards/include/boards/solderparty_rp2040_stamp.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/solderparty_rp2040_stamp.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_SOLDERPARTY_RP2040_STAMP_H #define _BOARDS_SOLDERPARTY_RP2040_STAMP_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define SOLDERPARTY_RP2040_STAMP @@ -73,7 +73,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/solderparty_rp2040_stamp_carrier.h b/src/boards/include/boards/solderparty_rp2040_stamp_carrier.h index 811f13c46..8711d38bc 100644 --- a/src/boards/include/boards/solderparty_rp2040_stamp_carrier.h +++ b/src/boards/include/boards/solderparty_rp2040_stamp_carrier.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/solderparty_rp2040_stamp_carrier.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_SOLDERPARTY_RP2040_STAMP_CARRIER_H #define _BOARDS_SOLDERPARTY_RP2040_STAMP_CARRIER_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define SOLDERPARTY_RP2040_STAMP_CARRIER diff --git a/src/boards/include/boards/solderparty_rp2040_stamp_round_carrier.h b/src/boards/include/boards/solderparty_rp2040_stamp_round_carrier.h index 3dc0f6013..4e908c302 100644 --- a/src/boards/include/boards/solderparty_rp2040_stamp_round_carrier.h +++ b/src/boards/include/boards/solderparty_rp2040_stamp_round_carrier.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/solderparty_rp2040_stamp_round_carrier.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_SOLDERPARTY_RP2040_STAMP_ROUND_CARRIER_H #define _BOARDS_SOLDERPARTY_RP2040_STAMP_ROUND_CARRIER_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define SOLDERPARTY_RP2040_STAMP_ROUND_CARRIER diff --git a/src/boards/include/boards/solderparty_rp2350_stamp.h b/src/boards/include/boards/solderparty_rp2350_stamp.h index bb2fd7b52..9ce3930c3 100644 --- a/src/boards/include/boards/solderparty_rp2350_stamp.h +++ b/src/boards/include/boards/solderparty_rp2350_stamp.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/solderparty_rp2350_stamp.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SOLDERPARTY_RP2350_STAMP_H #define _BOARDS_SOLDERPARTY_RP2350_STAMP_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SOLDERPARTY_RP2350_STAMP @@ -73,12 +73,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/solderparty_rp2350_stamp_xl.h b/src/boards/include/boards/solderparty_rp2350_stamp_xl.h index 33233f7d6..1904d8448 100644 --- a/src/boards/include/boards/solderparty_rp2350_stamp_xl.h +++ b/src/boards/include/boards/solderparty_rp2350_stamp_xl.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/solderparty_rp2350_stamp_xl.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SOLDERPARTY_RP2350_STAMP_XL_H #define _BOARDS_SOLDERPARTY_RP2350_STAMP_XL_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SOLDERPARTY_RP2350_STAMP_XL @@ -73,12 +73,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/sparkfun_iotnode_lorawan_rp2350.h b/src/boards/include/boards/sparkfun_iotnode_lorawan_rp2350.h index 5bea33cc4..e0e329786 100644 --- a/src/boards/include/boards/sparkfun_iotnode_lorawan_rp2350.h +++ b/src/boards/include/boards/sparkfun_iotnode_lorawan_rp2350.h @@ -12,11 +12,11 @@ // // This header may be included by other board headers as "boards/sparkfun_iotnode_lorawan_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SPARKFUN_IOTNODE_LORAWAN_RP2350_H #define _BOARDS_SPARKFUN_IOTNODE_LORAWAN_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SPARKFUN_IOTNODE_LORAWAN_RP2350 @@ -75,12 +75,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/sparkfun_iotredboard_rp2350.h b/src/boards/include/boards/sparkfun_iotredboard_rp2350.h index ac0972eb2..0c1d425bc 100644 --- a/src/boards/include/boards/sparkfun_iotredboard_rp2350.h +++ b/src/boards/include/boards/sparkfun_iotredboard_rp2350.h @@ -12,12 +12,12 @@ // // This header may be included by other board headers as "boards/sparkfun_iotredboard_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 -// pico_cmake_set PICO_CYW43_SUPPORTED = 1 - #ifndef _BOARDS_SPARKFUN_IOTREDBOARD_RP2350_H #define _BOARDS_SPARKFUN_IOTREDBOARD_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) +pico_board_cmake_set(PICO_CYW43_SUPPORTED, 1) + // For board detection #define SPARKFUN_IOTREDBOARD_RP2350 @@ -85,7 +85,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif @@ -113,7 +113,7 @@ #define PICO_VSYS_PIN 46 #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/sparkfun_micromod.h b/src/boards/include/boards/sparkfun_micromod.h index 5806bd19e..9403baa26 100644 --- a/src/boards/include/boards/sparkfun_micromod.h +++ b/src/boards/include/boards/sparkfun_micromod.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/sparkfun_micromod.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_SPARKFUN_MICROMOD_H #define _BOARDS_SPARKFUN_MICROMOD_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define SPARKFUN_MICROMOD @@ -75,7 +75,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/sparkfun_promicro.h b/src/boards/include/boards/sparkfun_promicro.h index da48c45f8..95d2da2cd 100644 --- a/src/boards/include/boards/sparkfun_promicro.h +++ b/src/boards/include/boards/sparkfun_promicro.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/sparkfun_promicro.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_SPARKFUN_PROMICRO_H #define _BOARDS_SPARKFUN_PROMICRO_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define SPARKFUN_PROMICRO @@ -75,7 +75,7 @@ #endif // board has 16M onboard flash -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/sparkfun_promicro_rp2350.h b/src/boards/include/boards/sparkfun_promicro_rp2350.h index 8709e8dca..d247e597b 100644 --- a/src/boards/include/boards/sparkfun_promicro_rp2350.h +++ b/src/boards/include/boards/sparkfun_promicro_rp2350.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/sparkfun_promicro_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SPARKFUN_PROMICRO_RP2350_H #define _BOARDS_SPARKFUN_PROMICRO_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SPARKFUN_PROMICRO_RP2350 @@ -73,7 +73,7 @@ #endif // board has 16M onboard flash -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif @@ -81,7 +81,7 @@ // --- RP2350 VARIANT --- #define PICO_RP2350A 1 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/sparkfun_thingplus.h b/src/boards/include/boards/sparkfun_thingplus.h index 1ed52b86c..0928387f8 100644 --- a/src/boards/include/boards/sparkfun_thingplus.h +++ b/src/boards/include/boards/sparkfun_thingplus.h @@ -14,11 +14,11 @@ // // This header may be included by other board headers as "boards/sparkfun_thingplus.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_SPARKFUN_THINGPLUS_H #define _BOARDS_SPARKFUN_THINGPLUS_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define SPARKFUN_THINGPLUS @@ -74,7 +74,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/sparkfun_thingplus_rp2350.h b/src/boards/include/boards/sparkfun_thingplus_rp2350.h index d023f943e..5b77ef324 100644 --- a/src/boards/include/boards/sparkfun_thingplus_rp2350.h +++ b/src/boards/include/boards/sparkfun_thingplus_rp2350.h @@ -12,12 +12,12 @@ // // This header may be included by other board headers as "boards/sparkfun_thingplus_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 -// pico_cmake_set PICO_CYW43_SUPPORTED = 1 - #ifndef _BOARDS_SPARKFUN_THINGPLUS_RP2350_H #define _BOARDS_SPARKFUN_THINGPLUS_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) +pico_board_cmake_set(PICO_CYW43_SUPPORTED, 1) + // For board detection #define SPARKFUN_THINGPLUS_RP2350 @@ -77,7 +77,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif @@ -114,7 +114,7 @@ #define CYW43_WL_GPIO_VBUS_PIN 2 #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/sparkfun_xrp_controller.h b/src/boards/include/boards/sparkfun_xrp_controller.h index 70c2f13c7..6b7099559 100644 --- a/src/boards/include/boards/sparkfun_xrp_controller.h +++ b/src/boards/include/boards/sparkfun_xrp_controller.h @@ -12,12 +12,12 @@ // // This header may be included by other board headers as "boards/sparkfun_xrp_controller.h" -// pico_cmake_set PICO_PLATFORM=rp2350 -// pico_cmake_set PICO_CYW43_SUPPORTED = 1 - #ifndef _BOARDS_SPARKFUN_XRP_CONTROLLER_H #define _BOARDS_SPARKFUN_XRP_CONTROLLER_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) +pico_board_cmake_set(PICO_CYW43_SUPPORTED, 1) + // For board detection #define SPARKFUN_XRP_CONTROLLER @@ -77,7 +77,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif @@ -90,7 +90,7 @@ #define CYW43_WL_GPIO_LED_PIN 0 #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/switchscience_picossci2_conta_base.h b/src/boards/include/boards/switchscience_picossci2_conta_base.h index 638e47e57..6c84dd708 100644 --- a/src/boards/include/boards/switchscience_picossci2_conta_base.h +++ b/src/boards/include/boards/switchscience_picossci2_conta_base.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/switchscience_picossci2_conta_base.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SWITCHSCIENCE_PICOSSCI2_CONTA_BASE_H #define _BOARDS_SWITCHSCIENCE_PICOSSCI2_CONTA_BASE_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SWITCHSCIENCE_PICOSSCI2_CONTA_BASE @@ -74,12 +74,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/switchscience_picossci2_dev_board.h b/src/boards/include/boards/switchscience_picossci2_dev_board.h index b674362bd..6c2e86a29 100644 --- a/src/boards/include/boards/switchscience_picossci2_dev_board.h +++ b/src/boards/include/boards/switchscience_picossci2_dev_board.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/switchscience_picossci2_dev_board.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SWITCHSCIENCE_PICOSSCI2_DEV_BOARD_H #define _BOARDS_SWITCHSCIENCE_PICOSSCI2_DEV_BOARD_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SWITCHSCIENCE_PICOSSCI2_DEV_BOARD @@ -75,12 +75,12 @@ #endif // board has 4MB onboard flash -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/switchscience_picossci2_micro.h b/src/boards/include/boards/switchscience_picossci2_micro.h index e1ccf359a..e5521dc20 100644 --- a/src/boards/include/boards/switchscience_picossci2_micro.h +++ b/src/boards/include/boards/switchscience_picossci2_micro.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/switchscience_picossci2_micro.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SWITCHSCIENCE_PICOSSCI2_MICRO_H #define _BOARDS_SWITCHSCIENCE_PICOSSCI2_MICRO_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SWITCHSCIENCE_PICOSSCI2_MICRO @@ -61,12 +61,12 @@ #endif // board has 4MB onboard flash -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/switchscience_picossci2_rp2350_breakout.h b/src/boards/include/boards/switchscience_picossci2_rp2350_breakout.h index ec53d1658..7f6106129 100644 --- a/src/boards/include/boards/switchscience_picossci2_rp2350_breakout.h +++ b/src/boards/include/boards/switchscience_picossci2_rp2350_breakout.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/switchscience_picossci2_rp2350_breakout.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SWITCHSCIENCE_PICOSSCI2_RP2350_BREAKOUT_H #define _BOARDS_SWITCHSCIENCE_PICOSSCI2_RP2350_BREAKOUT_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SWITCHSCIENCE_PICOSSCI2_RP2350_BREAKOUT @@ -74,12 +74,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/switchscience_picossci2_tiny.h b/src/boards/include/boards/switchscience_picossci2_tiny.h index f422017bd..a88ef9905 100644 --- a/src/boards/include/boards/switchscience_picossci2_tiny.h +++ b/src/boards/include/boards/switchscience_picossci2_tiny.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/switchscience_picossci2_tiny.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_SWITCHSCIENCE_PICOSSCI2_TINY_H #define _BOARDS_SWITCHSCIENCE_PICOSSCI2_TINY_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define SWITCHSCIENCE_PICOSSCI2_TINY @@ -74,12 +74,12 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/tinycircuits_thumby_color_rp2350.h b/src/boards/include/boards/tinycircuits_thumby_color_rp2350.h index 58088e581..5725291c9 100644 --- a/src/boards/include/boards/tinycircuits_thumby_color_rp2350.h +++ b/src/boards/include/boards/tinycircuits_thumby_color_rp2350.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/tinycircuits_thumby_color_rp2350.h" -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_TINYCIRCUITS_THUMBY_COLOR_RP2350_H #define _BOARDS_TINYCIRCUITS_THUMBY_COLOR_RP2350_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define TINYCIRCUITS_THUMBY_COLOR_RP2350 @@ -75,7 +75,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif @@ -93,7 +93,7 @@ #define PICO_VSYS_PIN 29 #endif -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_pico_cam_a.h b/src/boards/include/boards/waveshare_pico_cam_a.h index a8b3b40e8..1bb1f7dd0 100755 --- a/src/boards/include/boards/waveshare_pico_cam_a.h +++ b/src/boards/include/boards/waveshare_pico_cam_a.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_PICO_CAM_A_H #define _BOARDS_WAVESHARE_PICO_CAM_A_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_PICO_CAM_A @@ -68,7 +68,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_ble.h b/src/boards/include/boards/waveshare_rp2040_ble.h index 8a56e9c58..060d2152c 100755 --- a/src/boards/include/boards/waveshare_rp2040_ble.h +++ b/src/boards/include/boards/waveshare_rp2040_ble.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_BLE_H #define _BOARDS_WAVESHARE_RP2040_BLE_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_BLE @@ -68,7 +68,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_eth.h b/src/boards/include/boards/waveshare_rp2040_eth.h index 8d3912e60..a2e955120 100755 --- a/src/boards/include/boards/waveshare_rp2040_eth.h +++ b/src/boards/include/boards/waveshare_rp2040_eth.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_ETH_H #define _BOARDS_WAVESHARE_RP2040_ETH_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_ETH @@ -68,7 +68,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_geek.h b/src/boards/include/boards/waveshare_rp2040_geek.h index cba41cf7f..50d9af18f 100755 --- a/src/boards/include/boards/waveshare_rp2040_geek.h +++ b/src/boards/include/boards/waveshare_rp2040_geek.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_GEEK_H #define _BOARDS_WAVESHARE_RP2040_GEEK_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_GEEK @@ -88,7 +88,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_lcd_0.96.h b/src/boards/include/boards/waveshare_rp2040_lcd_0.96.h index 267dc1753..024db9399 100644 --- a/src/boards/include/boards/waveshare_rp2040_lcd_0.96.h +++ b/src/boards/include/boards/waveshare_rp2040_lcd_0.96.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_LCD_0_96_H #define _BOARDS_WAVESHARE_RP2040_LCD_0_96_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_LCD_0_96 @@ -89,7 +89,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_lcd_1.28.h b/src/boards/include/boards/waveshare_rp2040_lcd_1.28.h index f88b9ed3d..c219b03a2 100644 --- a/src/boards/include/boards/waveshare_rp2040_lcd_1.28.h +++ b/src/boards/include/boards/waveshare_rp2040_lcd_1.28.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_LCD_1_28_H #define _BOARDS_WAVESHARE_RP2040_LCD_1_28_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_LCD_1_28 @@ -92,7 +92,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_matrix.h b/src/boards/include/boards/waveshare_rp2040_matrix.h index 9233a3639..0b31d7f91 100755 --- a/src/boards/include/boards/waveshare_rp2040_matrix.h +++ b/src/boards/include/boards/waveshare_rp2040_matrix.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_MATRIX_H #define _BOARDS_WAVESHARE_RP2040_MATRIX_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_MATRIX @@ -69,7 +69,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_one.h b/src/boards/include/boards/waveshare_rp2040_one.h index 389d2992d..5a48aee43 100644 --- a/src/boards/include/boards/waveshare_rp2040_one.h +++ b/src/boards/include/boards/waveshare_rp2040_one.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_ONE_H #define _BOARDS_WAVESHARE_RP2040_ONE_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_ONE @@ -68,7 +68,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_pizero.h b/src/boards/include/boards/waveshare_rp2040_pizero.h index 7c598fa59..be6b3c185 100755 --- a/src/boards/include/boards/waveshare_rp2040_pizero.h +++ b/src/boards/include/boards/waveshare_rp2040_pizero.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_PIZERO_H #define _BOARDS_WAVESHARE_RP2040_PIZERO_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_PIZERO @@ -65,7 +65,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_plus_16mb.h b/src/boards/include/boards/waveshare_rp2040_plus_16mb.h index 2d32acc9c..9471c529d 100644 --- a/src/boards/include/boards/waveshare_rp2040_plus_16mb.h +++ b/src/boards/include/boards/waveshare_rp2040_plus_16mb.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_PLUS_16MB_H #define _BOARDS_WAVESHARE_RP2040_PLUS_16MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_PLUS_16MB @@ -70,7 +70,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_plus_4mb.h b/src/boards/include/boards/waveshare_rp2040_plus_4mb.h index f5be65768..decdd19f1 100644 --- a/src/boards/include/boards/waveshare_rp2040_plus_4mb.h +++ b/src/boards/include/boards/waveshare_rp2040_plus_4mb.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_PLUS_4MB_H #define _BOARDS_WAVESHARE_RP2040_PLUS_4MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_PLUS_4MB @@ -70,7 +70,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_power_management_hat_b.h b/src/boards/include/boards/waveshare_rp2040_power_management_hat_b.h index 8290eb022..e81ef6e1b 100755 --- a/src/boards/include/boards/waveshare_rp2040_power_management_hat_b.h +++ b/src/boards/include/boards/waveshare_rp2040_power_management_hat_b.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_POWER_MANAGEMENT_HAT_B_H #define _BOARDS_WAVESHARE_RP2040_POWER_MANAGEMENT_HAT_B_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_POWER_MANAGEMENT_HAT_B @@ -65,7 +65,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_tiny.h b/src/boards/include/boards/waveshare_rp2040_tiny.h index 84f646280..6d21a5b5f 100755 --- a/src/boards/include/boards/waveshare_rp2040_tiny.h +++ b/src/boards/include/boards/waveshare_rp2040_tiny.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_TINY_H #define _BOARDS_WAVESHARE_RP2040_TINY_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_TINY @@ -68,7 +68,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_touch_lcd_1.28.h b/src/boards/include/boards/waveshare_rp2040_touch_lcd_1.28.h index 35a340197..c785e4cb0 100755 --- a/src/boards/include/boards/waveshare_rp2040_touch_lcd_1.28.h +++ b/src/boards/include/boards/waveshare_rp2040_touch_lcd_1.28.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_TOUCH_LCD_1_28_H #define _BOARDS_WAVESHARE_RP2040_TOUCH_LCD_1_28_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_TOUCH_LCD_1_28 @@ -93,7 +93,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2040_zero.h b/src/boards/include/boards/waveshare_rp2040_zero.h index 85be7c7f9..9298f474e 100644 --- a/src/boards/include/boards/waveshare_rp2040_zero.h +++ b/src/boards/include/boards/waveshare_rp2040_zero.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WAVESHARE_RP2040_ZERO_H #define _BOARDS_WAVESHARE_RP2040_ZERO_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WAVESHARE_RP2040_ZERO @@ -68,7 +68,7 @@ #define PICO_FLASH_SPI_CLKDIV 4 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/waveshare_rp2350_eth.h b/src/boards/include/boards/waveshare_rp2350_eth.h index f4aa7ee48..c90189aad 100755 --- a/src/boards/include/boards/waveshare_rp2350_eth.h +++ b/src/boards/include/boards/waveshare_rp2350_eth.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_ETH_H #define _BOARDS_WAVESHARE_RP2350_ETH_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_ETH @@ -72,14 +72,14 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_geek.h b/src/boards/include/boards/waveshare_rp2350_geek.h index ff065cbda..4c29348aa 100755 --- a/src/boards/include/boards/waveshare_rp2350_geek.h +++ b/src/boards/include/boards/waveshare_rp2350_geek.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_GEEK_H #define _BOARDS_WAVESHARE_RP2350_GEEK_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_GEEK @@ -92,14 +92,14 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_lcd_0.96.h b/src/boards/include/boards/waveshare_rp2350_lcd_0.96.h index fd6c9f778..a54bd3739 100755 --- a/src/boards/include/boards/waveshare_rp2350_lcd_0.96.h +++ b/src/boards/include/boards/waveshare_rp2350_lcd_0.96.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_LCD_0_96_H #define _BOARDS_WAVESHARE_RP2350_LCD_0_96_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_LCD_0_96 @@ -92,14 +92,14 @@ #define PICO_FLASH_SPI_CLKDIV 3 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_lcd_1.28.h b/src/boards/include/boards/waveshare_rp2350_lcd_1.28.h index 4d4e0e022..7c325193b 100755 --- a/src/boards/include/boards/waveshare_rp2350_lcd_1.28.h +++ b/src/boards/include/boards/waveshare_rp2350_lcd_1.28.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_LCD_1_28_H #define _BOARDS_WAVESHARE_RP2350_LCD_1_28_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_LCD_1_28 @@ -97,14 +97,14 @@ #define PICO_FLASH_SPI_CLKDIV 3 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_one.h b/src/boards/include/boards/waveshare_rp2350_one.h index 937e1b682..93cb5553c 100755 --- a/src/boards/include/boards/waveshare_rp2350_one.h +++ b/src/boards/include/boards/waveshare_rp2350_one.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_ONE_H #define _BOARDS_WAVESHARE_RP2350_ONE_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_ONE @@ -72,14 +72,14 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_plus_16mb.h b/src/boards/include/boards/waveshare_rp2350_plus_16mb.h index 8de280b1c..c674b1b74 100755 --- a/src/boards/include/boards/waveshare_rp2350_plus_16mb.h +++ b/src/boards/include/boards/waveshare_rp2350_plus_16mb.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_PLUS_16MB_H #define _BOARDS_WAVESHARE_RP2350_PLUS_16MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_PLUS_16MB @@ -74,14 +74,14 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_plus_4mb.h b/src/boards/include/boards/waveshare_rp2350_plus_4mb.h index 3c8b98617..0ae163f9f 100755 --- a/src/boards/include/boards/waveshare_rp2350_plus_4mb.h +++ b/src/boards/include/boards/waveshare_rp2350_plus_4mb.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_PLUS_4MB_H #define _BOARDS_WAVESHARE_RP2350_PLUS_4MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_PLUS_4MB @@ -74,14 +74,14 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_tiny.h b/src/boards/include/boards/waveshare_rp2350_tiny.h index 23af13c0f..d66ee2dda 100755 --- a/src/boards/include/boards/waveshare_rp2350_tiny.h +++ b/src/boards/include/boards/waveshare_rp2350_tiny.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_TINY_H #define _BOARDS_WAVESHARE_RP2350_TINY_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_TINY @@ -72,14 +72,14 @@ #define PICO_FLASH_SPI_CLKDIV 3 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_touch_lcd_1.28.h b/src/boards/include/boards/waveshare_rp2350_touch_lcd_1.28.h index 52eea9eb4..c8b4ce21c 100755 --- a/src/boards/include/boards/waveshare_rp2350_touch_lcd_1.28.h +++ b/src/boards/include/boards/waveshare_rp2350_touch_lcd_1.28.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_TOUCH_LCD_1_28_H #define _BOARDS_WAVESHARE_RP2350_TOUCH_LCD_1_28_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_TOUCH_LCD_1_28 @@ -96,14 +96,14 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/waveshare_rp2350_zero.h b/src/boards/include/boards/waveshare_rp2350_zero.h index 10b5d8b91..43a96f7c5 100755 --- a/src/boards/include/boards/waveshare_rp2350_zero.h +++ b/src/boards/include/boards/waveshare_rp2350_zero.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2350 - #ifndef _BOARDS_WAVESHARE_RP2350_ZERO_H #define _BOARDS_WAVESHARE_RP2350_ZERO_H +pico_board_cmake_set(PICO_PLATFORM, rp2350) + // For board detection #define WAVESHARE_RP2350_ZERO @@ -72,14 +72,14 @@ #define PICO_FLASH_SPI_CLKDIV 3 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) #define PICO_SMPS_MODE_PIN 23 -// pico_cmake_set_default PICO_RP2350_A2_SUPPORTED = 1 +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) #ifndef PICO_RP2350_A2_SUPPORTED #define PICO_RP2350_A2_SUPPORTED 1 #endif diff --git a/src/boards/include/boards/weact_studio_rp2040_16mb.h b/src/boards/include/boards/weact_studio_rp2040_16mb.h index c8d3aa2ef..a27df8ef0 100644 --- a/src/boards/include/boards/weact_studio_rp2040_16mb.h +++ b/src/boards/include/boards/weact_studio_rp2040_16mb.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/weact_studio_rp2040_16mb.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WEACT_STUDIO_RP2040_16MB_H #define _BOARDS_WEACT_STUDIO_RP2040_16MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WEACT_STUDIO_RP2040_16MB @@ -75,7 +75,7 @@ #define PICO_RP2040_B0_SUPPORTED 0 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/weact_studio_rp2040_2mb.h b/src/boards/include/boards/weact_studio_rp2040_2mb.h index 4b0c00590..c1fba01f8 100644 --- a/src/boards/include/boards/weact_studio_rp2040_2mb.h +++ b/src/boards/include/boards/weact_studio_rp2040_2mb.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/weact_studio_rp2040_2mb.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WEACT_STUDIO_RP2040_2MB_H #define _BOARDS_WEACT_STUDIO_RP2040_2MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WEACT_STUDIO_RP2040_2MB @@ -75,7 +75,7 @@ #define PICO_RP2040_B0_SUPPORTED 0 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/weact_studio_rp2040_4mb.h b/src/boards/include/boards/weact_studio_rp2040_4mb.h index 405620d47..2557f1cbf 100644 --- a/src/boards/include/boards/weact_studio_rp2040_4mb.h +++ b/src/boards/include/boards/weact_studio_rp2040_4mb.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/weact_studio_rp2040_4mb.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WEACT_STUDIO_RP2040_4MB_H #define _BOARDS_WEACT_STUDIO_RP2040_4MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WEACT_STUDIO_RP2040_4MB @@ -75,7 +75,7 @@ #define PICO_RP2040_B0_SUPPORTED 0 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (4 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (4 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/weact_studio_rp2040_8mb.h b/src/boards/include/boards/weact_studio_rp2040_8mb.h index 72778c178..f90934fc3 100644 --- a/src/boards/include/boards/weact_studio_rp2040_8mb.h +++ b/src/boards/include/boards/weact_studio_rp2040_8mb.h @@ -11,11 +11,11 @@ // This header may be included by other board headers as "boards/weact_studio_rp2040_8mb.h" -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WEACT_STUDIO_RP2040_8MB_H #define _BOARDS_WEACT_STUDIO_RP2040_8MB_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WEACT_STUDIO_RP2040_8MB @@ -75,7 +75,7 @@ #define PICO_RP2040_B0_SUPPORTED 0 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif diff --git a/src/boards/include/boards/wiznet_w5100s_evb_pico.h b/src/boards/include/boards/wiznet_w5100s_evb_pico.h index 0640eadfb..9d33ffba7 100644 --- a/src/boards/include/boards/wiznet_w5100s_evb_pico.h +++ b/src/boards/include/boards/wiznet_w5100s_evb_pico.h @@ -9,11 +9,11 @@ // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES // ----------------------------------------------------- -// pico_cmake_set PICO_PLATFORM=rp2040 - #ifndef _BOARDS_WIZNET_W5100S_EVB_PICO_H #define _BOARDS_WIZNET_W5100S_EVB_PICO_H +pico_board_cmake_set(PICO_PLATFORM, rp2040) + // For board detection #define WIZNET_W5100S_EVB_PICO @@ -89,7 +89,7 @@ #define PICO_FLASH_SPI_CLKDIV 2 #endif -// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) #endif diff --git a/src/common/pico_base_headers/include/pico.h b/src/common/pico_base_headers/include/pico.h index 3b0f2f14a..2f33f19e7 100644 --- a/src/common/pico_base_headers/include/pico.h +++ b/src/common/pico_base_headers/include/pico.h @@ -26,6 +26,35 @@ #include "pico/types.h" #include "pico/version.h" +/** + * \brief A marker used in board headers to specify a CMake variable and value that should be set in the CMake build when the board header is used + * \ingroup pico_base + * + * Based on the PICO_BOARD CMake variable, the build will scan the board header for `pico_board_cmake_set(var, value)` and set these variables + * very early in the build configuration process. This allows setting CMake variables like `PICO_PLATFORM` from the board header, and thus + * affecting, for example, the choice of compiler made by the build + * + * \note use of this macro will overwrite the CMake variable if it is already set + * + * \note this macro's definition is empty as it is not intended to have any effect on actual compilation + */ +#define pico_board_cmake_set(x, y) + +/** + * \brief A marker used in board headers to specify a CMake variable and value that should be set in the CMake build when the board header is used, + * if that CMake variable has not already been set + * \ingroup pico_base + * + * Based on the PICO_BOARD CMake variable, the build will scan the board header for `pico_board_cmake_set_default(var, value)` and set these variables + * very early in the build configuration process. This allows setting CMake variables like `PICO_PLATFORM` from the board header, and thus + * affecting, for example, the choice of compiler made by the build + * + * \note use of this macro will not overwrite the CMake variable if it is already set + * + * \note this macro's definition is empty as it is not intended to have any effect on actual compilation + */ +#define pico_board_cmake_set_default(x, y) + // PICO_CONFIG: PICO_CONFIG_HEADER, Unquoted path to header include in place of the default pico/config.h which may be desirable for build systems which can't easily generate the config_autogen header, group=pico_base #ifdef PICO_CONFIG_HEADER #include __PICO_XSTRING(PICO_CONFIG_HEADER) diff --git a/src/rp2350/boot_stage2/include/boot_stage2/config.h b/src/rp2350/boot_stage2/include/boot_stage2/config.h index 61f9b9b53..a73778af6 100644 --- a/src/rp2350/boot_stage2/include/boot_stage2/config.h +++ b/src/rp2350/boot_stage2/include/boot_stage2/config.h @@ -9,7 +9,7 @@ // NOTE THIS HEADER IS INCLUDED FROM ASSEMBLY -#include "pico/config.h" +#include "pico.h" // PICO_CONFIG: PICO_BUILD_BOOT_STAGE2_NAME, Name of the boot stage 2 if selected in the build system, group=boot_stage2 #ifdef PICO_BUILD_BOOT_STAGE2_NAME diff --git a/tools/check_board_header.py b/tools/check_board_header.py index 3bfce1c5b..4f2e44e2f 100755 --- a/tools/check_board_header.py +++ b/tools/check_board_header.py @@ -75,8 +75,8 @@ def read_defines_from(header_file, defines_dict): # strip trailing comments line = re.sub(r"(?<=\S)\s*//.*$", "", line) - # look for "// pico_cmake_set BLAH_BLAH=42" - m = re.match(r"^\s*//\s*pico_cmake_set\s+(\w+)\s*=\s*(.+?)\s*$", line) + # look for "pico_board_cmake_set(BLAH_BLAH, 42)" + m = re.match(r"^\s*pico_board_cmake_set\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(.*)\s*\)\s*$", line) if m: #print(m.groups()) name = m.group(1) @@ -87,16 +87,16 @@ def read_defines_from(header_file, defines_dict): # check for multiply-defined values if name in cmake_settings: if cmake_settings[name].value != value: - raise Exception("{}:{} Conflicting values for pico_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + raise Exception("{}:{} Conflicting values for pico_board_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) else: if show_warnings: - warnings.warn("{}:{} Multiple values for pico_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + warnings.warn("{}:{} Multiple values for pico_board_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) else: cmake_settings[name] = DefineType(name, value, None, lineno) continue - # look for "// pico_cmake_set_default BLAH_BLAH=42" - m = re.match(r"^\s*//\s*pico_cmake_set_default\s+(\w+)\s*=\s*(.+?)\s*$", line) + # look for "pico_board_cmake_set_default(BLAH_BLAH, 42)" + m = re.match(r"^\s*pico_board_cmake_set_default\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(.*)\s*\)\s*$", line) if m: #print(m.groups()) name = m.group(1) @@ -223,8 +223,8 @@ def read_defines_from(header_file, defines_dict): raise Exception("{}:{} Suggests including \"{}\" but file is named \"{}\"".format(board_header, lineno, include_suggestion, expected_include_suggestion)) continue - # look for "// pico_cmake_set BLAH_BLAH=42" - m = re.match(r"^\s*//\s*pico_cmake_set\s+(\w+)\s*=\s*(.+?)\s*$", line) + # look for "pico_board_cmake_set(BLAH_BLAH, 42)" + m = re.match(r"^\s*pico_board_cmake_set\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(.*)\s*\)\s*$", line) if m: #print(m.groups()) name = m.group(1) @@ -234,7 +234,7 @@ def read_defines_from(header_file, defines_dict): raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) # check for multiply-defined values if name in cmake_settings: - raise Exception("{}:{} Multiple values for pico_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + raise Exception("{}:{} Multiple values for pico_board_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) else: if value: try: @@ -245,8 +245,8 @@ def read_defines_from(header_file, defines_dict): cmake_settings[name] = DefineType(name, value, None, lineno) continue - # look for "// pico_cmake_set_default BLAH_BLAH=42" - m = re.match(r"^\s*//\s*pico_cmake_set_default\s+(\w+)\s*=\s*(.+?)\s*$", line) + # look for "pico_board_cmake_set_default(BLAH_BLAH, 42)" + m = re.match(r"^\s*pico_board_cmake_set_default\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(.*)\s*\)\s*$", line) if m: #print(m.groups()) name = m.group(1) @@ -256,7 +256,7 @@ def read_defines_from(header_file, defines_dict): raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) # check for multiply-defined values if name in cmake_default_settings: - raise Exception("{}:{} Multiple values for pico_cmake_set_default {} ({} and {})".format(board_header, lineno, name, cmake_default_settings[name].value, value)) + raise Exception("{}:{} Multiple values for pico_board_cmake_set_default {} ({} and {})".format(board_header, lineno, name, cmake_default_settings[name].value, value)) else: if value: try: @@ -382,7 +382,7 @@ def read_defines_from(header_file, defines_dict): else: for setting in compulsory_cmake_settings: if setting not in cmake_settings: - raise Exception("{} is missing a pico_cmake_set {} comment".format(board_header, setting)) + raise Exception("{} is missing a pico_board_cmake_set {} comment".format(board_header, setting)) if cmake_settings['PICO_PLATFORM'].value == "rp2040": chip = 'RP2040' other_chip = 'RP2350' @@ -399,22 +399,22 @@ def read_defines_from(header_file, defines_dict): chip = 'RP2350B' if not board_header.endswith("amethyst_fpga.h"): if 'PICO_RP2350_A2_SUPPORTED' not in cmake_default_settings: - raise Exception("{} uses chip {} but is missing a pico_cmake_set_default {} comment".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) + raise Exception("{} uses chip {} but is missing a pico_board_cmake_set_default {} comment".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) if 'PICO_RP2350_A2_SUPPORTED' not in defines: raise Exception("{} uses chip {} but is missing a #define {}".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) if defines['PICO_RP2350_A2_SUPPORTED'].resolved_value != 1: raise Exception("{} sets #define {} {} (should be 1)".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED', defines['PICO_RP2350_A2_SUPPORTED'].resolved_value)) for setting in compulsory_cmake_default_settings: if setting not in cmake_default_settings: - raise Exception("{} is missing a pico_cmake_set_default {} comment".format(board_header, setting)) + raise Exception("{} is missing a pico_board_cmake_set_default {} comment".format(board_header, setting)) for setting in matching_cmake_default_settings: if setting in cmake_default_settings and setting not in defines: - raise Exception("{} has pico_cmake_set_default {} but is missing a matching #define".format(board_header, setting)) + raise Exception("{} has pico_board_cmake_set_default {} but is missing a matching #define".format(board_header, setting)) elif setting in defines and setting not in cmake_default_settings: - raise Exception("{} has #define {} but is missing a matching pico_cmake_set_default comment".format(board_header, setting)) + raise Exception("{} has #define {} but is missing a matching pico_board_cmake_set_default comment".format(board_header, setting)) elif setting in defines and setting in cmake_default_settings: if cmake_default_settings[setting].value != defines[setting].resolved_value: - raise Exception("{} has mismatched pico_cmake_set_default and #define values for {}".format(board_header, setting)) + raise Exception("{} has mismatched pico_board_cmake_set_default and #define values for {}".format(board_header, setting)) for setting in compulsory_defines: if setting not in defines: raise Exception("{} is missing a #define {}".format(board_header, setting)) From 65a8907828ad87acd6a8e3363f175a64337b65cd Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 15 Apr 2025 16:28:07 +0100 Subject: [PATCH 118/224] Make doxygen buildable again (#2423) Remove `\par` doxygen syntax which isn't supported by https://github.com/raspberrypi/doxygentoasciidoc --- src/rp2_common/pico_lwip/doc.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/rp2_common/pico_lwip/doc.h b/src/rp2_common/pico_lwip/doc.h index bbf353387..7f8bbfd01 100644 --- a/src/rp2_common/pico_lwip/doc.h +++ b/src/rp2_common/pico_lwip/doc.h @@ -51,19 +51,13 @@ * * This library enables you to make use of the LwIP HTTP client and server library * - * \par LwIP HTTP server - * * To make use of the LwIP HTTP server you need to provide the HTML that the server will return to the client. * This is done by compiling the content directly into the executable. * - * \par makefsdata - * * LwIP provides a c-library tool `makefsdata` to compile your HTML into a source file for inclusion into your program. * This is quite hard to use as you need to compile the tool as a native binary, then run the tool to generate a source file * before compiling your code for the Pico device. * - * \par pico_set_lwip_httpd_content - * * To make this whole process easier, a python script `makefsdata.py` is provided to generate a source file for your HTML content. * A CMake function `pico_set_lwip_httpd_content` takes care of running the `makefsdata.py` python script for you. * To make use of this, specify the name of the source file as `pico_fsdata.inc` in `lwipopts.h`. From 829c067ee7282f33a8e69e536dce03f3009a2597 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Sun, 20 Apr 2025 17:25:29 -0700 Subject: [PATCH 119/224] add word alignment for rtwopi (#2429) --- src/rp2_common/pico_float/float_sci_m33_vfp.S | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/pico_float/float_sci_m33_vfp.S b/src/rp2_common/pico_float/float_sci_m33_vfp.S index 86e8b2750..d105496ba 100644 --- a/src/rp2_common/pico_float/float_sci_m33_vfp.S +++ b/src/rp2_common/pico_float/float_sci_m33_vfp.S @@ -29,6 +29,7 @@ float_section WRAPPER_FUNC_NAME(\func) float_section frrcore_v +.p2align 2 // 1/2π to plenty of accuracy .long 0 @ this allows values of e down to -32 rtwopi: @@ -152,7 +153,7 @@ wrapper_func expf mov r0,#0 bx r14 -.align 3 +.p2align 3 k_exp2: .float 0.693147181 @ log2 .float 0.240226507 @ log²2/2 @@ -254,7 +255,7 @@ wrapper_func logf movlong r0,0xff800000 bx r14 -.align 3 +.p2align 3 k_log3: .float 0.5 .float 0.333333333333333 @@ -501,7 +502,7 @@ fsc_sintail: and r0,r0,#0x80000000 @ make signed zero b 22b -.align 2 +.p2align 2 2: vmul.f32 s3,s3,s9 @ ε³/3! vsub.f32 s1,s1,s3 @ ε-ε³/3! ~ sinε @@ -515,7 +516,7 @@ fsc_costail: eor r0,r0,r12,lsl#31 bx r14 -.align 3 +.p2align 3 k_sc3: .word 0x3EFFFEC1 @ ~ 1/2! with PMC .word 0x3e2aaa25 @ ~ 1/3! with PMC From 8421b451f706203a826422735cff8b67ccd12578 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 23 Apr 2025 19:57:31 +0100 Subject: [PATCH 120/224] Revert "Make doxygen buildable again (#2423)" (#2437) This reverts commit 65a8907828ad87acd6a8e3363f175a64337b65cd. --- src/rp2_common/pico_lwip/doc.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rp2_common/pico_lwip/doc.h b/src/rp2_common/pico_lwip/doc.h index 7f8bbfd01..bbf353387 100644 --- a/src/rp2_common/pico_lwip/doc.h +++ b/src/rp2_common/pico_lwip/doc.h @@ -51,13 +51,19 @@ * * This library enables you to make use of the LwIP HTTP client and server library * + * \par LwIP HTTP server + * * To make use of the LwIP HTTP server you need to provide the HTML that the server will return to the client. * This is done by compiling the content directly into the executable. * + * \par makefsdata + * * LwIP provides a c-library tool `makefsdata` to compile your HTML into a source file for inclusion into your program. * This is quite hard to use as you need to compile the tool as a native binary, then run the tool to generate a source file * before compiling your code for the Pico device. * + * \par pico_set_lwip_httpd_content + * * To make this whole process easier, a python script `makefsdata.py` is provided to generate a source file for your HTML content. * A CMake function `pico_set_lwip_httpd_content` takes care of running the `makefsdata.py` python script for you. * To make use of this, specify the name of the source file as `pico_fsdata.inc` in `lwipopts.h`. From eee72cdca7e81949a83cc6a52abe588a66e2913b Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 23 Apr 2025 19:58:11 +0100 Subject: [PATCH 121/224] Fix submodule path typos (#2424) --- src/rp2_common/pico_btstack/CMakeLists.txt | 2 +- src/rp2_common/pico_cyw43_driver/CMakeLists.txt | 2 +- src/rp2_common/pico_lwip/CMakeLists.txt | 2 +- src/rp2_common/pico_mbedtls/CMakeLists.txt | 2 +- src/rp2_common/tinyusb/CMakeLists.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rp2_common/pico_btstack/CMakeLists.txt b/src/rp2_common/pico_btstack/CMakeLists.txt index 7c277bd67..a36816032 100644 --- a/src/rp2_common/pico_btstack/CMakeLists.txt +++ b/src/rp2_common/pico_btstack/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_BTSTACK_PATH, Path to an alternative version of btstack overriding the version in pico-sdk/libs/btstack. Can be passed to cmake or set in your environment, type=string, group=pico_btstack +# PICO_CMAKE_CONFIG: PICO_BTSTACK_PATH, Path to an alternative version of btstack overriding the version in pico-sdk/lib/btstack. Can be passed to cmake or set in your environment, type=string, group=pico_btstack if (DEFINED ENV{PICO_BTSTACK_PATH} AND (NOT PICO_BTSTACK_PATH)) set(PICO_BTSTACK_PATH $ENV{PICO_BTSTACK_PATH}) message("Using PICO_BTSTACK_PATH from environment ('${PICO_BTSTACK_PATH}')") diff --git a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt index 13ac2043c..6fd1998ba 100644 --- a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt +++ b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_CYW43_DRIVER_PATH, Path to an alternative version of cyw43-driver overriding the version in pico-sdk/libs/cyw43-driver, type=string, group=pico_cyw43_driver +# PICO_CMAKE_CONFIG: PICO_CYW43_DRIVER_PATH, Path to an alternative version of cyw43-driver overriding the version in pico-sdk/lib/cyw43-driver, type=string, group=pico_cyw43_driver if (DEFINED ENV{PICO_CYW43_DRIVER_PATH} AND (NOT PICO_CYW43_DRIVER_PATH)) set(PICO_CYW43_DRIVER_PATH $ENV{PICO_CYW43_DRIVER_PATH}) message("Using PICO_CYW43_DRIVER_PATH from environment ('${PICO_CYW43_DRIVER_PATH}')") diff --git a/src/rp2_common/pico_lwip/CMakeLists.txt b/src/rp2_common/pico_lwip/CMakeLists.txt index 42dd1dfd7..7897754e6 100644 --- a/src/rp2_common/pico_lwip/CMakeLists.txt +++ b/src/rp2_common/pico_lwip/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_LWIP_PATH, Path to an alternative version of lwip overriding the version in pico-sdk/libs/lwip. Can be passed to cmake or set in your environment, type=string, group=pico_lwip +# PICO_CMAKE_CONFIG: PICO_LWIP_PATH, Path to an alternative version of lwip overriding the version in pico-sdk/lib/lwip. Can be passed to cmake or set in your environment, type=string, group=pico_lwip if (DEFINED ENV{PICO_LWIP_PATH} AND (NOT PICO_LWIP_PATH)) set(PICO_LWIP_PATH $ENV{PICO_LWIP_PATH}) message("Using PICO_LWIP_PATH from environment ('${PICO_LWIP_PATH}')") diff --git a/src/rp2_common/pico_mbedtls/CMakeLists.txt b/src/rp2_common/pico_mbedtls/CMakeLists.txt index d9b90a674..19fe47822 100644 --- a/src/rp2_common/pico_mbedtls/CMakeLists.txt +++ b/src/rp2_common/pico_mbedtls/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_MBEDTLS_PATH, Path to an alternative version of mbedtls overriding the version in pico-sdk/libs/mbedtls. Can be passed to cmake or set in your environment, type=string, group=pico_mbedtls +# PICO_CMAKE_CONFIG: PICO_MBEDTLS_PATH, Path to an alternative version of mbedtls overriding the version in pico-sdk/lib/mbedtls. Can be passed to cmake or set in your environment, type=string, group=pico_mbedtls if (DEFINED ENV{PICO_MBEDTLS_PATH} AND (NOT PICO_MBEDTLS_PATH)) set(PICO_MBEDTLS_PATH $ENV{PICO_MBEDTLS_PATH}) message("Using PICO_MBEDTLS_PATH from environment ('${PICO_MBEDTLS_PATH}')") diff --git a/src/rp2_common/tinyusb/CMakeLists.txt b/src/rp2_common/tinyusb/CMakeLists.txt index 88c79b8af..3e12439c0 100644 --- a/src/rp2_common/tinyusb/CMakeLists.txt +++ b/src/rp2_common/tinyusb/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_TINYUSB_PATH, Path to an alternative version of tinyusb overriding the version in pico-sdk/libs/tinyusb. Can be passed to cmake or set in your environment, type=string, group=tinyusb_device +# PICO_CMAKE_CONFIG: PICO_TINYUSB_PATH, Path to an alternative version of tinyusb overriding the version in pico-sdk/lib/tinyusb. Can be passed to cmake or set in your environment, type=string, group=tinyusb_device if (DEFINED ENV{PICO_TINYUSB_PATH} AND (NOT PICO_TINYUSB_PATH)) set(PICO_TINYUSB_PATH $ENV{PICO_TINYUSB_PATH}) message("Using PICO_TINYUSB_PATH from environment ('${PICO_TINYUSB_PATH}')") From 174cafc31a7e705fc54c175c667811aece1d9df3 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Wed, 23 Apr 2025 20:02:06 +0100 Subject: [PATCH 122/224] Add CYW43_WL_GPIO_SMPS_PIN for pico_w and pico2_w (#2410) Fixes #2361 --- src/boards/include/boards/pico2_w.h | 6 ++++++ src/boards/include/boards/pico_w.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/boards/include/boards/pico2_w.h b/src/boards/include/boards/pico2_w.h index 74f5a739b..32bc4a531 100644 --- a/src/boards/include/boards/pico2_w.h +++ b/src/boards/include/boards/pico2_w.h @@ -89,6 +89,12 @@ pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (4 * 1024 * 1024)) #define CYW43_WL_GPIO_LED_PIN 0 #endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +// As this is a CYW43 pin you can do this by calling cyw43_gpio_set +#ifndef CYW43_WL_GPIO_SMPS_PIN +#define CYW43_WL_GPIO_SMPS_PIN 1 +#endif + // If CYW43_WL_GPIO_VBUS_PIN is defined then a CYW43 GPIO has to be used to read VBUS. // This can be passed to cyw43_arch_gpio_get to determine if the device is battery powered. // PICO_VBUS_PIN and CYW43_WL_GPIO_VBUS_PIN should not both be defined. diff --git a/src/boards/include/boards/pico_w.h b/src/boards/include/boards/pico_w.h index 6e825f680..670cb3057 100644 --- a/src/boards/include/boards/pico_w.h +++ b/src/boards/include/boards/pico_w.h @@ -94,6 +94,12 @@ pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) #define CYW43_WL_GPIO_LED_PIN 0 #endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +// As this is a CYW43 pin you can do this by calling cyw43_gpio_set +#ifndef CYW43_WL_GPIO_SMPS_PIN +#define CYW43_WL_GPIO_SMPS_PIN 1 +#endif + // If CYW43_WL_GPIO_VBUS_PIN is defined then a CYW43 GPIO has to be used to read VBUS. // This can be passed to cyw43_arch_gpio_get to determine if the device is battery powered. // PICO_VBUS_PIN and CYW43_WL_GPIO_VBUS_PIN should not both be defined. From ae332b3522e98ff4a8426a43aa1469641b082ad9 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Sat, 26 Apr 2025 18:13:36 +0100 Subject: [PATCH 123/224] Ensure each test has a unique name (followup to #2208) (#2443) mainly by fixing typos! --- .../pico_double/double_aeabi_rp2040.S | 4 ++-- .../custom_double_funcs_test.c | 22 +++++++++---------- .../pico_float_test/custom_float_funcs_test.c | 8 +++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/rp2_common/pico_double/double_aeabi_rp2040.S b/src/rp2_common/pico_double/double_aeabi_rp2040.S index 448b28355..6ec3d7958 100644 --- a/src/rp2_common/pico_double/double_aeabi_rp2040.S +++ b/src/rp2_common/pico_double/double_aeabi_rp2040.S @@ -649,7 +649,7 @@ regular_func double2fix_z lsrs r3, #21 // adjust adds r3, r2 - ble 2f // adjusted input is zero or dedornmal or < 1 + ble 2f // adjusted input is zero or denormal or < 1 lsrs r3, r3, #11 bne 3f // adjusted input is > infinite @@ -933,4 +933,4 @@ double_wrapper_section log wrapper_func_d1 log shimmable_table_tail_call SF_TABLE_FLN dln_shim -#endif \ No newline at end of file +#endif diff --git a/test/pico_float_test/custom_double_funcs_test.c b/test/pico_float_test/custom_double_funcs_test.c index 85624d4cb..e8f291f4c 100644 --- a/test/pico_float_test/custom_double_funcs_test.c +++ b/test/pico_float_test/custom_double_funcs_test.c @@ -162,16 +162,16 @@ int test() { test_checku(double2ufix(3.25, 2), 13, "double2ufix7"); test_checku(double2ufix(3.0, -1), 1, "double2ufix8"); // not very useful test_checki(double2ufix(0.0, 16), 0, "double2ufix12"); - test_checki(double2ufix(-0.0, 16), 0, "double2fix13"); + test_checki(double2ufix(-0.0, 16), 0, "double2ufix13"); test_checki(double2ufix(0.0, -16), 0, "double2ufix14"); - test_checki(double2ufix(-0.0, -16), 0, "double2fix15"); + test_checki(double2ufix(-0.0, -16), 0, "double2ufix15"); printf("double2fix64\n"); test_checki64(double2fix64(3.5, 8), 0x380, "double2fix641"); test_checki64(double2fix64(-3.5, 8), -0x380, "double2fix642"); test_checki64(double2fix64(32768.0, 16), 32768ll << 16, "double2fix643"); test_checki64(double2fix64(65536.0, 16), 65536ll << 16, "double2fix644"); - test_checki64(double2fix64(2147483648.0, 16), 2147483648ll << 16, "double2ufix644b"); + test_checki64(double2fix64(2147483648.0, 16), 2147483648ll << 16, "double2fix644b"); test_checki64(double2fix64(65536.0 * 65536.0 * 32768.0, 16), INT64_MAX, "double2fix644c"); test_checki64(double2fix64(INFINITY, 16), INT64_MAX, "double2fix645"); test_checki64(double2fix64(-INFINITY, 16), INT64_MIN, "double2fix645b"); @@ -257,10 +257,10 @@ int test() { test_checku(double2ufix_z(3.24999, 2), 12, "double2ufix_z6"); test_checku(double2ufix_z(3.25, 2), 13, "double2ufix_z7"); test_checku(double2ufix_z(3.0, -1), 1, "double2ufix_z8"); // not very useful - test_checki(double2ufix_z(0.0, 16), 0, "double2fix_z9"); - test_checki(double2ufix_z(-0.0, 16), 0, "double2fix_z10"); - test_checki(double2ufix_z(0.0, -16), 0, "double2fix_z11"); - test_checki(double2ufix_z(-0.0, -16), 0, "double2fix_z12"); + test_checki(double2ufix_z(0.0, 16), 0, "double2ufix_z9"); + test_checki(double2ufix_z(-0.0, 16), 0, "double2ufix_z10"); + test_checki(double2ufix_z(0.0, -16), 0, "double2ufix_z11"); + test_checki(double2ufix_z(-0.0, -16), 0, "double2ufix_z12"); printf("double2fix64_z\n"); test_checki64(double2fix64_z(3.5, 8), 0x380, "double2fix64_z1"); @@ -269,9 +269,9 @@ int test() { test_checki64(double2fix64_z(65536.0, 16), 65536ll << 16, "double2fix64_z4"); test_checki64(double2fix64_z(65536.0 * 65536.0 * 32768.0, 16), INT64_MAX, "double2fix64_z4b"); test_checki64(double2fix64_z(INFINITY, 16), INT64_MAX, "double2fix64_z5"); - test_checki64(double2fix64_z(-INFINITY, 16), INT64_MIN, "double2fix64_z5"); - test_checki64(double2fix64_z(INFINITY, 16), INT64_MAX, "double2fix64_z5"); - test_checki64(double2fix64_z(-INFINITY, 16), INT64_MIN, "double2fix64_z5"); + test_checki64(double2fix64_z(-INFINITY, 16), INT64_MIN, "double2fix64_z5b"); + test_checki64(double2fix64_z(INFINITY, 16), INT64_MAX, "double2fix64_z5c"); + test_checki64(double2fix64_z(-INFINITY, 16), INT64_MIN, "double2fix64_z5d"); test_checki64(double2fix64_z(3.24999, 2), 12, "double2fix64_z6"); test_checki64(double2fix64_z(3.25, 2), 13, "double2fix64_z7"); test_checki64(double2fix64_z(-3.24999, 2), -12, "double2fix64_z8"); @@ -308,7 +308,7 @@ int test() { test_checku64(double2ufix64_z(-3.5, 8), 0, "double2ufix64_z2"); test_checku64(double2ufix64_z(32768.0, 16), 32768ll << 16, "double2ufix64_z3"); test_checku64(double2ufix64_z(65536.0, 16), 65536ll << 16, "double2ufix64_z4"); - test_checki64(double2ufix64_z(65536.0 * 65536.0 * 65536.0, 16), UINT64_MAX, "double2fix64_z4b"); + test_checki64(double2ufix64_z(65536.0 * 65536.0 * 65536.0, 16), UINT64_MAX, "double2ufix64_z4b"); test_checku64(double2ufix64_z(INFINITY, 16), UINT64_MAX, "double2ufix64_z5"); test_checku64(double2ufix64_z(-INFINITY, 16), 0, "double2ufix64_z5b"); test_checku64(double2ufix64_z(INFINITY, 16), UINT64_MAX, "double2ufix64_z5c"); diff --git a/test/pico_float_test/custom_float_funcs_test.c b/test/pico_float_test/custom_float_funcs_test.c index d749f778a..570ca0543 100644 --- a/test/pico_float_test/custom_float_funcs_test.c +++ b/test/pico_float_test/custom_float_funcs_test.c @@ -179,7 +179,7 @@ int test() { test_checki64(float2fix64(-3.5f, 8), -0x380, "float2fix642"); test_checki64(float2fix64(32768.0f, 16), 32768ll << 16, "float2fix643"); test_checki64(float2fix64(65536.0f, 16), 65536ll << 16, "float2fix644"); - test_checki64(float2fix64(2147483648.0f, 16), 2147483648ll << 16, "float2ufix644b"); + test_checki64(float2fix64(2147483648.0f, 16), 2147483648ll << 16, "float2fix644b"); test_checki64(float2fix64(65536.0f * 65536.0f * 32768.0f, 16), INT64_MAX, "float2fix644c"); test_checki64(float2fix64(INFINITY, 16), INT64_MAX, "float2fix645"); test_checki64(float2fix64(3.24999f, 2), 12, "float2fix646"); @@ -227,9 +227,9 @@ int test() { test_checku(float2ufix_z(3.25f, 2), 13, "float2ufix_z7"); test_checku(float2ufix_z(3.0f, -1), 1, "float2ufix_z8"); // not very useful u32f.u = 0x7f012345; - test_checku(float2ufix_z(u32f.f, 1), UINT32_MAX, "float2fix_z9"); + test_checku(float2ufix_z(u32f.f, 1), UINT32_MAX, "float2ufix_z9"); u32f.u = 0xff012345; - test_checku(float2ufix_z(u32f.f, 1), 0, "float2fix_z10"); + test_checku(float2ufix_z(u32f.f, 1), 0, "float2ufix_z10"); printf("float2fix64_z\n"); test_checki64(float2fix64_z(3.5f, 8), 0x380, "float2fix64_z1"); @@ -249,7 +249,7 @@ int test() { test_checku64(float2ufix64_z(-3.5f, 8), 0, "float2ufix64_z2"); test_checku64(float2ufix64_z(32768.0f, 16), 32768ll << 16, "float2ufix64_z3"); test_checku64(float2ufix64_z(65536.0f, 16), 65536ll << 16, "float2ufix64_z4"); - test_checki64(float2ufix64_z(65536.0f * 65536.0f * 65536.0f, 16), UINT64_MAX, "float2fix64_z4b"); + test_checki64(float2ufix64_z(65536.0f * 65536.0f * 65536.0f, 16), UINT64_MAX, "float2ufix64_z4b"); test_checku64(float2ufix64_z(INFINITY, 16), UINT64_MAX, "float2ufix64_z5"); test_checku64(float2ufix64_z(3.24999f, 2), 12, "float2ufix64_z6"); test_checku64(float2ufix64_z(3.25f, 2), 13, "float2ufix64_z7"); From 082d9f75cde8c2b4ace0de60dbe41b570a1d9929 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Sat, 26 Apr 2025 18:15:26 +0100 Subject: [PATCH 124/224] More board-header checks (followup to #2397) (#2442) - make the error messages less misleading - suggest replacing the old comment-style syntax with the new macro-style syntax --- tools/check_board_header.py | 40 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/tools/check_board_header.py b/tools/check_board_header.py index 4f2e44e2f..da7b53408 100755 --- a/tools/check_board_header.py +++ b/tools/check_board_header.py @@ -75,6 +75,17 @@ def read_defines_from(header_file, defines_dict): # strip trailing comments line = re.sub(r"(?<=\S)\s*//.*$", "", line) + # look for "// old_comment BLAH_BLAH=42" and suggest changing it to "new_macro(BLAH_BLAH, 42)" + for (old_comment, new_macro) in ( + ('pico_cmake_set', 'pico_board_cmake_set'), + ('pico_cmake_set_default', 'pico_board_cmake_set_default') + ): + m = re.match(r"^\s*//\s*{}\s+(\w+)\s*=\s*(.+?)\s*$".format(old_comment), line) + if m: + name = m.group(1) + value = m.group(2) + raise Exception("{}:{} \"// {} {}={}\" should be replaced with \"{}({}, {})\"".format(board_header, lineno, old_comment, name, value, new_macro, name, value)) + # look for "pico_board_cmake_set(BLAH_BLAH, 42)" m = re.match(r"^\s*pico_board_cmake_set\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(.*)\s*\)\s*$", line) if m: @@ -87,10 +98,10 @@ def read_defines_from(header_file, defines_dict): # check for multiply-defined values if name in cmake_settings: if cmake_settings[name].value != value: - raise Exception("{}:{} Conflicting values for pico_board_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + raise Exception("{}:{} Conflicting values for pico_board_cmake_set({}) ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) else: if show_warnings: - warnings.warn("{}:{} Multiple values for pico_board_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + warnings.warn("{}:{} Multiple values for pico_board_cmake_set({}) ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) else: cmake_settings[name] = DefineType(name, value, None, lineno) continue @@ -223,6 +234,17 @@ def read_defines_from(header_file, defines_dict): raise Exception("{}:{} Suggests including \"{}\" but file is named \"{}\"".format(board_header, lineno, include_suggestion, expected_include_suggestion)) continue + # look for "// old_comment BLAH_BLAH=42" and suggest changing it to "new_macro(BLAH_BLAH, 42)" + for (old_comment, new_macro) in ( + ('pico_cmake_set', 'pico_board_cmake_set'), + ('pico_cmake_set_default', 'pico_board_cmake_set_default') + ): + m = re.match(r"^\s*//\s*{}\s+(\w+)\s*=\s*(.+?)\s*$".format(old_comment), line) + if m: + name = m.group(1) + value = m.group(2) + raise Exception("{}:{} \"// {} {}={}\" should be replaced with \"{}({}, {})\"".format(board_header, lineno, old_comment, name, value, new_macro, name, value)) + # look for "pico_board_cmake_set(BLAH_BLAH, 42)" m = re.match(r"^\s*pico_board_cmake_set\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(.*)\s*\)\s*$", line) if m: @@ -234,7 +256,7 @@ def read_defines_from(header_file, defines_dict): raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) # check for multiply-defined values if name in cmake_settings: - raise Exception("{}:{} Multiple values for pico_board_cmake_set {} ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + raise Exception("{}:{} Multiple values for pico_board_cmake_set({}) ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) else: if value: try: @@ -256,7 +278,7 @@ def read_defines_from(header_file, defines_dict): raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) # check for multiply-defined values if name in cmake_default_settings: - raise Exception("{}:{} Multiple values for pico_board_cmake_set_default {} ({} and {})".format(board_header, lineno, name, cmake_default_settings[name].value, value)) + raise Exception("{}:{} Multiple values for pico_board_cmake_set_default({}) ({} and {})".format(board_header, lineno, name, cmake_default_settings[name].value, value)) else: if value: try: @@ -382,7 +404,7 @@ def read_defines_from(header_file, defines_dict): else: for setting in compulsory_cmake_settings: if setting not in cmake_settings: - raise Exception("{} is missing a pico_board_cmake_set {} comment".format(board_header, setting)) + raise Exception("{} is missing a pico_board_cmake_set({}, XXX) call".format(board_header, setting)) if cmake_settings['PICO_PLATFORM'].value == "rp2040": chip = 'RP2040' other_chip = 'RP2350' @@ -399,19 +421,19 @@ def read_defines_from(header_file, defines_dict): chip = 'RP2350B' if not board_header.endswith("amethyst_fpga.h"): if 'PICO_RP2350_A2_SUPPORTED' not in cmake_default_settings: - raise Exception("{} uses chip {} but is missing a pico_board_cmake_set_default {} comment".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) + raise Exception("{} uses chip {} but is missing a pico_board_cmake_set_default({}, XXX) call".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) if 'PICO_RP2350_A2_SUPPORTED' not in defines: raise Exception("{} uses chip {} but is missing a #define {}".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) if defines['PICO_RP2350_A2_SUPPORTED'].resolved_value != 1: raise Exception("{} sets #define {} {} (should be 1)".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED', defines['PICO_RP2350_A2_SUPPORTED'].resolved_value)) for setting in compulsory_cmake_default_settings: if setting not in cmake_default_settings: - raise Exception("{} is missing a pico_board_cmake_set_default {} comment".format(board_header, setting)) + raise Exception("{} is missing a pico_board_cmake_set_default({}, XXX) call".format(board_header, setting)) for setting in matching_cmake_default_settings: if setting in cmake_default_settings and setting not in defines: - raise Exception("{} has pico_board_cmake_set_default {} but is missing a matching #define".format(board_header, setting)) + raise Exception("{} has pico_board_cmake_set_default({}, XXX) but is missing a matching #define".format(board_header, setting)) elif setting in defines and setting not in cmake_default_settings: - raise Exception("{} has #define {} but is missing a matching pico_board_cmake_set_default comment".format(board_header, setting)) + raise Exception("{} has #define {} but is missing a matching pico_board_cmake_set_default({}, XXX) call".format(board_header, setting, setting)) elif setting in defines and setting in cmake_default_settings: if cmake_default_settings[setting].value != defines[setting].resolved_value: raise Exception("{} has mismatched pico_board_cmake_set_default and #define values for {}".format(board_header, setting)) From 333944ac672255f37c7d38e1021987739a2de5fc Mon Sep 17 00:00:00 2001 From: Caleb Jamison Date: Tue, 29 Apr 2025 12:05:12 -0400 Subject: [PATCH 125/224] Update hellbender_2350A_devboard.h for release version of the board. (#2441) * Update hellbender_2350A_devboard.h for release version of the board. * Remove PICO_DEFAULT_SPI_CSN_PIN --- .../boards/hellbender_2350A_devboard.h | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/boards/include/boards/hellbender_2350A_devboard.h b/src/boards/include/boards/hellbender_2350A_devboard.h index b2be28d3a..aa41f69b6 100644 --- a/src/boards/include/boards/hellbender_2350A_devboard.h +++ b/src/boards/include/boards/hellbender_2350A_devboard.h @@ -22,16 +22,17 @@ pico_board_cmake_set(PICO_PLATFORM, rp2350) #define HB_2350A_IMU_INT_PIN 1 #define HB_2350A_USER_QWIIC_SDA_PIN 2 #define HB_2350A_USER_QWIIC_SCL_PIN 3 -#define HB_2350A_RTC_INT_PIN 8 +#define HB_2350A_RTC_INT_PIN 22 #define HB_2350A_SDCARD_CS_PIN 9 #define HB_2350A_LORA_IO1_PIN 10 #define HB_2350A_LORA_IO3_PIN 11 -#define HB_2350A_LORA_CS_PIN 21 -#define HB_2350A_RTC_CLKIN_PIN 22 -#define HB_2350A_IMU_CLKOUT_PIN 23 +#define HB_2350A_LORA_CS_PIN 28 #define HB_2350A_LORA_BUSY_PIN 24 -#define HB_2350A_FUSB307_INT_PIN 25 #define HB_2350A_LORA_RESET_PIN 29 +#define HB_2350A_RTC_CLKIN_PIN 22 +#define HB_2350A_IMU_CLKOUT_PIN 23 +#define HB_2350A_FUSB307_INT_PIN 21 +#define HB_2350A_BQ25792_INT_PIN 8 // --- UART --- // Note, conflicts with HSTX range @@ -45,7 +46,11 @@ pico_board_cmake_set(PICO_PLATFORM, rp2350) #define PICO_DEFAULT_UART_RX_PIN 13 #endif -// no PICO_DEFAULT_LED_PIN +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif + // no PICO_DEFAULT_WS2812_PIN // --- I2C --- @@ -72,9 +77,8 @@ pico_board_cmake_set(PICO_PLATFORM, rp2350) #ifndef PICO_DEFAULT_SPI_RX_PIN #define PICO_DEFAULT_SPI_RX_PIN 20 #endif -#ifndef PICO_DEFAULT_SPI_CSN_PIN -#define PICO_DEFAULT_SPI_CSN_PIN 21 -#endif +// multiple devices, so this doesn't make much sense +// no PICO_DEFAULT_SPI_CSN_PIN // --- FLASH --- From 6e315799f5bdf8159b5d1a14047d85c0884a8de3 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Tue, 29 Apr 2025 17:09:06 +0100 Subject: [PATCH 126/224] Add script to extract CMake function descriptions (#2422) --- src/cmake/on_device.cmake | 10 + src/common/pico_binary_info/CMakeLists.txt | 16 ++ src/rp2040/boot_stage2/CMakeLists.txt | 13 +- src/rp2350/boot_stage2/CMakeLists.txt | 13 +- src/rp2_common/pico_btstack/CMakeLists.txt | 12 +- .../pico_cyw43_driver/CMakeLists.txt | 24 +- src/rp2_common/pico_lwip/tools/CMakeLists.txt | 12 +- src/rp2_common/pico_runtime/CMakeLists.txt | 30 +-- .../pico_standard_link/CMakeLists.txt | 13 +- src/rp2_common/pico_stdio/CMakeLists.txt | 16 ++ tools/CMakeLists.txt | 94 ++++++-- tools/extract_cmake_functions.py | 207 ++++++++++++++++++ 12 files changed, 407 insertions(+), 53 deletions(-) create mode 100755 tools/extract_cmake_functions.py diff --git a/src/cmake/on_device.cmake b/src/cmake/on_device.cmake index 00a5fffc6..b4c53b967 100644 --- a/src/cmake/on_device.cmake +++ b/src/cmake/on_device.cmake @@ -15,16 +15,22 @@ function(pico_get_runtime_output_directory TARGET output_path_name) set(${output_path_name} ${output_path} PARENT_SCOPE) endfunction() +# pico_add_hex_output(TARGET) +# \brief\ Generate a hex file for the target function(pico_add_hex_output TARGET) pico_get_runtime_output_directory(${TARGET} output_path) add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex $ ${output_path}$>,$,$>.hex VERBATIM) endfunction() +# pico_add_bin_output(TARGET) +# \brief\ Generate a bin file for the target function(pico_add_bin_output TARGET) pico_get_runtime_output_directory(${TARGET} output_path) add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${output_path}$>,$,$>.bin VERBATIM) endfunction() +# pico_add_dis_output(TARGET) +# \brief\ Generate a disassembly file for the target function(pico_add_dis_output TARGET) pico_get_runtime_output_directory(${TARGET} output_path) @@ -45,6 +51,10 @@ function(pico_add_dis_output TARGET) ) endfunction() +# pico_add_extra_outputs(TARGET) +# \brief_nodesc\ Perform post-build actions for the target +# +# Perform picotool processing and add disassembly, hex, bin, map, and uf2 outputs for the target function(pico_add_extra_outputs TARGET) # Disassembly will be nonsense for encrypted binaries, # so disassemble before picotool processing diff --git a/src/common/pico_binary_info/CMakeLists.txt b/src/common/pico_binary_info/CMakeLists.txt index d2bfd6914..5da8fb5aa 100644 --- a/src/common/pico_binary_info/CMakeLists.txt +++ b/src/common/pico_binary_info/CMakeLists.txt @@ -9,11 +9,19 @@ endif() target_link_libraries(pico_binary_info INTERFACE pico_binary_info_headers) +# pico_set_program_name(TARGET name) +# \brief\ Set the program name for the target +# +# \param\ name The program name to set function(pico_set_program_name TARGET name) # PICO_BUILD_DEFINE: PICO_PROGRAM_NAME, value passed to pico_set_program_name, type=string, group=pico_binary_info target_compile_definitions(${TARGET} PRIVATE -DPICO_PROGRAM_NAME="${name}") endfunction() +# pico_set_program_description(TARGET description) +# \brief\ Set the program description for the target +# +# \param\ description The program description to set function(pico_set_program_description TARGET description) # since this is the command line, we will remove newlines string(REPLACE "\n" " " description ${description}) @@ -22,11 +30,19 @@ function(pico_set_program_description TARGET description) target_compile_definitions(${TARGET} PRIVATE -DPICO_PROGRAM_DESCRIPTION="${description}") endfunction() +# pico_set_program_url(TARGET url) +# \brief\ Set the program URL for the target +# +# \param\ url The program URL to set function(pico_set_program_url TARGET url) # PICO_BUILD_DEFINE: PICO_PROGRAM_URL, value passed to pico_set_program_url, type=string, group=pico_binary_info target_compile_definitions(${TARGET} PRIVATE -DPICO_PROGRAM_URL="${url}") endfunction() +# pico_set_program_version(TARGET version) +# \brief\ Set the program version for the target +# +# \param\ version The program version to set function(pico_set_program_version TARGET version) # PICO_BUILD_DEFINE: PICO_PROGRAM_VERSION_STRING, value passed to pico_set_program_version, type=string, group=pico_binary_info target_compile_definitions(${TARGET} PRIVATE -DPICO_PROGRAM_VERSION_STRING="${version}") diff --git a/src/rp2040/boot_stage2/CMakeLists.txt b/src/rp2040/boot_stage2/CMakeLists.txt index ba42256b7..2798b3640 100644 --- a/src/rp2040/boot_stage2/CMakeLists.txt +++ b/src/rp2040/boot_stage2/CMakeLists.txt @@ -33,7 +33,13 @@ set(PICO_BOOT_STAGE2_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "") pico_add_library(boot_stage2_headers) target_include_directories(boot_stage2_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) -# by convention the first source file name without extension is used for the binary info name +# pico_define_boot_stage2(NAME SOURCES) +# \brief\ Define a boot stage 2 target. +# +# By convention the first source file name without extension is used for the binary info name +# +# \param\ NAME The name of the boot stage 2 target +# \param\ SOURCES The source files to link into the boot stage 2 function(pico_define_boot_stage2 NAME SOURCES) add_executable(${NAME} ${SOURCES} @@ -97,7 +103,12 @@ endmacro() pico_define_boot_stage2(bs2_default ${PICO_DEFAULT_BOOT_STAGE2_FILE}) +# pico_clone_default_boot_stage2(NAME) +# \brief_nodesc\ Clone the default boot stage 2 target. +# # Create a new boot stage 2 target using the default implementation for the current build (PICO_BOARD derived) +# +# \param\ NAME The name of the new boot stage 2 target function(pico_clone_default_boot_stage2 NAME) pico_define_boot_stage2(${NAME} ${PICO_DEFAULT_BOOT_STAGE2_FILE}) endfunction() diff --git a/src/rp2350/boot_stage2/CMakeLists.txt b/src/rp2350/boot_stage2/CMakeLists.txt index e878ccc5b..fbf95b53a 100644 --- a/src/rp2350/boot_stage2/CMakeLists.txt +++ b/src/rp2350/boot_stage2/CMakeLists.txt @@ -33,7 +33,13 @@ set(PICO_BOOT_STAGE2_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "") pico_add_library(boot_stage2_headers) target_include_directories(boot_stage2_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) -# by convention the first source file name without extension is used for the binary info name +# pico_define_boot_stage2(NAME SOURCES) +# \brief\ Define a boot stage 2 target. +# +# By convention the first source file name without extension is used for the binary info name +# +# \param\ NAME The name of the boot stage 2 target +# \param\ SOURCES The source files to link into the boot stage 2 function(pico_define_boot_stage2 NAME SOURCES) add_executable(${NAME} ${SOURCES} @@ -97,7 +103,12 @@ endmacro() pico_define_boot_stage2(bs2_default ${PICO_DEFAULT_BOOT_STAGE2_FILE}) +# pico_clone_default_boot_stage2(NAME) +# \brief_nodesc\ Clone the default boot stage 2 target. +# # Create a new boot stage 2 target using the default implementation for the current build (PICO_BOARD derived) +# +# \param\ NAME The name of the new boot stage 2 target function(pico_clone_default_boot_stage2 NAME) pico_define_boot_stage2(${NAME} ${PICO_DEFAULT_BOOT_STAGE2_FILE}) endfunction() diff --git a/src/rp2_common/pico_btstack/CMakeLists.txt b/src/rp2_common/pico_btstack/CMakeLists.txt index a36816032..593b666ff 100644 --- a/src/rp2_common/pico_btstack/CMakeLists.txt +++ b/src/rp2_common/pico_btstack/CMakeLists.txt @@ -302,9 +302,15 @@ if (EXISTS ${PICO_BTSTACK_PATH}/${BTSTACK_TEST_PATH}) pico_promote_common_scope_vars() - # Make a GATT header file from a BTstack GATT file - # Pass the target library name library type and path to the GATT input file - # To add additional directories to the gatt #import path, add them to the end of the argument list. + # pico_btstack_make_gatt_header(TARGET_LIB TARGET_TYPE GATT_FILE) + # \brief\ Make a GATT header file from a BTstack GATT file. + # + # Pass the target library name, library type, and path to the GATT input file. + # To add additional directories to the gatt import path, add them to the end of the argument list. + # + # \param\ TARGET_LIB The target library name + # \param\ TARGET_TYPE The target library type + # \param\ GATT_FILE The path to the GATT input file function(pico_btstack_make_gatt_header TARGET_LIB TARGET_TYPE GATT_FILE) find_package (Python3 REQUIRED COMPONENTS Interpreter) get_filename_component(GATT_NAME "${GATT_FILE}" NAME_WE) diff --git a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt index 6fd1998ba..a7570a294 100644 --- a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt +++ b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt @@ -131,16 +131,22 @@ if (EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE}) ) endif() - # Set an ip address in a compile definition - # target name, target type, compile definition name to set then address in a string - # This can be used to set the following compile definitions - # CYW43_DEFAULT_IP_STA_ADDRESS - # CYW43_DEFAULT_IP_STA_GATEWAY - # CYW43_DEFAULT_IP_AP_ADDRESS - # CYW43_DEFAULT_IP_AP_GATEWAY - # CYW43_DEFAULT_IP_MASK - # CYW43_DEFAULT_IP_DNS + # pico_configure_ip4_address(TARGET_LIB TARGET_TYPE DEF_NAME IP_ADDRESS_STR) + # \brief\ Set an ip address in a compile definition + # + # This can be used to set the following compile definitions; + # CYW43_DEFAULT_IP_STA_ADDRESS; + # CYW43_DEFAULT_IP_STA_GATEWAY; + # CYW43_DEFAULT_IP_AP_ADDRESS; + # CYW43_DEFAULT_IP_AP_GATEWAY; + # CYW43_DEFAULT_IP_MASK; + # CYW43_DEFAULT_IP_DNS; # e.g. pico_configure_ip4_address(picow_tcpip_server_background PRIVATE CYW43_DEFAULT_IP_STA_ADDRESS "10.3.15.204") + # + # \param\ TARGET_LIB The target library to set the ip address for + # \param\ TARGET_TYPE The type of target library + # \param\ DEF_NAME The name of the compile definition to set + # \param\ IP_ADDRESS_STR The ip address to set function(pico_configure_ip4_address TARGET_LIB TARGET_TYPE DEF_NAME IP_ADDRESS_STR) string(REGEX MATCHALL "[0-9]+" IP_ADDRESS_LIST ${IP_ADDRESS_STR}) list(LENGTH IP_ADDRESS_LIST IP_ADDRESS_COMPONENT_COUNT) diff --git a/src/rp2_common/pico_lwip/tools/CMakeLists.txt b/src/rp2_common/pico_lwip/tools/CMakeLists.txt index 1539ac00d..796075f39 100644 --- a/src/rp2_common/pico_lwip/tools/CMakeLists.txt +++ b/src/rp2_common/pico_lwip/tools/CMakeLists.txt @@ -1,5 +1,13 @@ -# Compile the http content into a source file "pico_fsdata.inc" in a format suitable for the lwip httpd server -# Pass the target library name library type and the list of httpd content +# pico_set_lwip_httpd_content(TARGET_LIB TARGET_TYPE HTTPD_FILES...) +# \ingroup\ pico_lwip +# \brief_nodesc\ Compile the http content into a source file for lwip. +# +# Compile the http content into a source file "pico_fsdata.inc" in a format suitable for the lwip httpd server. +# Pass the target library name, library type, and the list of httpd content files to compile. +# +# \param\ TARGET_LIB The target library name +# \param\ TARGET_TYPE The type of the target library +# \param\ HTTPD_FILES The list of httpd content files to compile function(pico_set_lwip_httpd_content TARGET_LIB TARGET_TYPE) find_package (Python3 REQUIRED COMPONENTS Interpreter) set(HTTPD_CONTENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") diff --git a/src/rp2_common/pico_runtime/CMakeLists.txt b/src/rp2_common/pico_runtime/CMakeLists.txt index da329e695..59c825201 100644 --- a/src/rp2_common/pico_runtime/CMakeLists.txt +++ b/src/rp2_common/pico_runtime/CMakeLists.txt @@ -51,22 +51,26 @@ elseif (PICO_C_COMPILER_IS_CLANG) # target_link_options(pico_runtime INTERFACE "-nostdlib") endif() -# pico_minimize_runtime((INCLUDE ...) (EXCLUDE ...)) +# pico_minimize_runtime(TARGET [INCLUDE ...] [EXCLUDE ...]) +# \brief\ Minimize the runtime components for the target # # INCLUDE/EXCLUDE can contain any of the following (all defaulting to not included) # -# DEFAULT_ALARM_POOL - default alarm pool setup -# PRINTF - full printf support -# PRINTF_MINIMAL - printf support without the following -# PRINTF_FLOAT - to control float support if printf is enabled -# PRINTF_EXPONENTIAL -# PRINTF_LONG_LONG -# PRINTF_PTRDIFF_T -# FLOAT - support for single-precision floating point -# DOUBLE - support for double-precision floating point -# FPGA_CHECK - checks for FPGA which allows Raspberry Pi to run your binary on FPGA -# PANIC - default panic impl which brings in stdio -# AUTO_INIT_MUTEX - auto init mutexes; without this you get no printf mutex either - +# DEFAULT_ALARM_POOL - default alarm pool setup; +# PRINTF - full printf support; +# PRINTF_MINIMAL - printf support without the following; +# PRINTF_FLOAT - to control float support if printf is enabled; +# PRINTF_EXPONENTIAL - to control exponential support if printf is enabled; +# PRINTF_LONG_LONG - to control long long support if printf is enabled; +# PRINTF_PTRDIFF_T - to control ptrdiff_t support if printf is enabled; +# FLOAT - support for single-precision floating point; +# DOUBLE - support for double-precision floating point; +# FPGA_CHECK - checks for FPGA which allows Raspberry Pi to run your binary on FPGA; +# PANIC - default panic impl which brings in stdio; +# AUTO_INIT_MUTEX - auto init mutexes, without this you get no printf mutex either; +# +# \param\ INCLUDE The items to include +# \param\ EXCLUDE The items to exclude function(pico_minimize_runtime TARGET) set(ALL_ITEMS DEFAULT_ALARM_POOL diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 53eaa84fa..484abc892 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -5,6 +5,10 @@ if (NOT TARGET pico_standard_link) target_link_libraries(pico_standard_link INTERFACE boot_stage2_headers) endif() + # pico_add_link_depend(TARGET dependency) + # \brief\ Add a link time dependency to the target + # + # \param\ dependency The dependency to add function(pico_add_link_depend TARGET dependency) get_target_property(target_type ${TARGET} TYPE) if (${target_type} STREQUAL "INTERFACE_LIBRARY") @@ -21,11 +25,18 @@ if (NOT TARGET pico_standard_link) set_target_properties(${TARGET} PROPERTIES ${PROP} "${_LINK_DEPENDS}") endfunction() - # need this because cmake does not appear to have a way to override an INTERFACE variable + # pico_set_linker_script(TARGET LDSCRIPT) + # \brief\ Set the linker script for the target + # + # \param\ LDSCRIPT Full path to the linker script to set function(pico_set_linker_script TARGET LDSCRIPT) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${LDSCRIPT}) endfunction() + # pico_set_binary_type(TARGET TYPE) + # \brief\ Set the binary type for the target + # + # \param\ TYPE The binary type to set function(pico_set_binary_type TARGET TYPE) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BINARY_TYPE ${TYPE}) endfunction() diff --git a/src/rp2_common/pico_stdio/CMakeLists.txt b/src/rp2_common/pico_stdio/CMakeLists.txt index 5798b8d24..195a5b361 100644 --- a/src/rp2_common/pico_stdio/CMakeLists.txt +++ b/src/rp2_common/pico_stdio/CMakeLists.txt @@ -26,18 +26,34 @@ if (NOT TARGET pico_stdio) pico_mirrored_target_link_libraries(pico_stdio INTERFACE pico_printf) endif() + # pico_enable_stdio_uart(TARGET ENABLED) + # \brief\ Enable stdio UART for the target + # + # \param\ ENABLED Whether to enable stdio UART function(pico_enable_stdio_uart TARGET ENABLED) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_STDIO_UART ${ENABLED}) endfunction() + # pico_enable_stdio_usb(TARGET ENABLED) + # \brief\ Enable stdio USB for the target + # + # \param\ ENABLED Whether to enable stdio USB function(pico_enable_stdio_usb TARGET ENABLED) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_STDIO_USB ${ENABLED}) endfunction() + # pico_enable_stdio_semihosting(TARGET ENABLED) + # \brief\ Enable stdio semi-hosting for the target + # + # \param\ ENABLED Whether to enable stdio semi-hosting function(pico_enable_stdio_semihosting TARGET ENABLED) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_STDIO_SEMIHOSTING ${ENABLED}) endfunction() + # pico_enable_stdio_rtt(TARGET ENABLED) + # \brief\ Enable stdio RTT for the target + # + # \param\ ENABLED Whether to enable stdio RTT function(pico_enable_stdio_rtt TARGET ENABLED) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_STDIO_RTT ${ENABLED}) endfunction() diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 7d68c9107..5273840a5 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -175,13 +175,19 @@ function(picotool_check_default_keys TARGET) picotool_compare_keys(${TARGET} ${picotool_enc_sigfile} private.pem "encrypted signing") endfunction() -# Generate pio header and include it in the build -# PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build +# pico_generate_pio_header(TARGET PIO_FILES... [OUTPUT_FORMAT ] [OUTPUT_DIR ]) +# \ingroup\ pico_pio +# \brief\ Generate pio header and include it in the build +# +# \param\ PIO_FILES The PIO files to generate the header for +# \param\ OUTPUT_FORMAT The output format to use for the pio header +# \param\ OUTPUT_DIR The directory to output the pio header to function(pico_generate_pio_header TARGET) pico_init_pioasm() # Note that PATH is not a valid argument but was previously ignored (and happens to be passed by pico-extras) cmake_parse_arguments(pico_generate_pio_header "" "OUTPUT_FORMAT;OUTPUT_DIR;PATH" "" ${ARGN} ) + # PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build if (pico_generate_pio_header_OUTPUT_FORMAT) set(OUTPUT_FORMAT "${pico_generate_pio_header_OUTPUT_FORMAT}") elseif(DEFINED PICO_DEFAULT_PIOASM_OUTPUT_FORMAT) @@ -230,10 +236,13 @@ function(pico_generate_pio_header TARGET) endfunction() # pico_package_uf2_output(TARGET PACKADDR) -# Package a UF2 output to be written to the PACKADDR address. This can be -# used with a no_flash binary to write the UF2 to flash when dragging & +# \brief\ Package a UF2 output to be written to the PACKADDR address. +# This can be used with a no_flash binary to write the UF2 to flash when dragging & # dropping, and it will be copied to SRAM by the bootrom before execution. -# This sets PICOTOOL_UF2_PACKAGE_ADDR to PACKADDR. +# +# This sets the target property PICOTOOL_UF2_PACKAGE_ADDR to PACKADDR. +# +# \param\ PACKADDR The address to package the UF2 to function(pico_package_uf2_output TARGET PACKADDR) picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES @@ -242,8 +251,11 @@ function(pico_package_uf2_output TARGET PACKADDR) endfunction() # pico_set_otp_key_output_file(TARGET OTPFILE) -# Output the public key hash and other necessary rows to an otp JSON file. -# This sets PICOTOOL_OTP_FILE to OTPFILE. +# \brief\ Output the public key hash and other necessary rows to an otp JSON file. +# +# This sets the target property PICOTOOL_OTP_FILE to OTPFILE. +# +# \param\ OTPFILE The OTP file to output the public key hash and other necessary rows to function(pico_set_otp_key_output_file TARGET OTPFILE) picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES @@ -252,9 +264,12 @@ function(pico_set_otp_key_output_file TARGET OTPFILE) endfunction() # pico_load_map_clear_sram(TARGET) +# \brief_nodesc\ Adds a load map entry to clear all of SRAM +# # Adds an entry to the load map to instruct the bootrom to clear all of SRAM -# before loading the binary. This appends the `--clear` argument -# to PICOTOOL_EXTRA_PROCESS_ARGS. +# before loading the binary. +# +# This appends the `--clear` argument to the target property PICOTOOL_EXTRA_PROCESS_ARGS. function(pico_load_map_clear_sram TARGET) picotool_check_configurable(${TARGET}) # get and set, to inherit list @@ -268,11 +283,20 @@ function(pico_load_map_clear_sram TARGET) ) endfunction() -# pico_set_binary_version( [MAJOR ] [MINOR ] [ROLLBACK ] [ROLLBACK_ROWS ]) +# pico_set_binary_version(TARGET [MAJOR ] [MINOR ] [ROLLBACK ] [ROWS ]) +# \brief_nodesc\ Add a version item to the metadata block +# # Adds a version item to the metadata block, with the given major, minor and -# rollback version, along with the rollback rows. These are appended as arguments -# to PICOTOOL_EXTRA_PROCESS_ARGS if setting the rollback version, or set as compile -# definitions if only setting the major/minor versions. +# rollback version, along with the rollback rows. +# +# These are appended as arguments to the target property PICOTOOL_EXTRA_PROCESS_ARGS if setting the +# rollback version, or set as compile definitions if only setting the major/minor +# versions. +# +# \param\ MAJOR The major version to set +# \param\ MINOR The minor version to set +# \param\ ROLLBACK The rollback version to set +# \param\ ROWS The OTP rows to use for the rollback version function(pico_set_binary_version TARGET) picotool_check_configurable(${TARGET}) set(oneValueArgs MAJOR MINOR ROLLBACK) @@ -321,8 +345,11 @@ function(pico_set_binary_version TARGET) endfunction() # pico_set_uf2_family(TARGET FAMILY) -# Set the UF2 family to use when creating the UF2. -# This sets PICOTOOL_UF2_FAMILY to FAMILY. +# \brief\ Set the UF2 family to use when creating the UF2. +# +# This sets the target property PICOTOOL_UF2_FAMILY to FAMILY. +# +# \param\ FAMILY The UF2 family to use function(pico_set_uf2_family TARGET FAMILY) picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES @@ -331,11 +358,16 @@ function(pico_set_uf2_family TARGET FAMILY) endfunction() # pico_sign_binary(TARGET [SIGFILE]) -# Sign the target binary with the given PEM signature. This sets -# PICOTOOL_SIGN_OUTPUT to true, PICOTOOL_SIGFILE to SIGFILE (if specified), -# and PICOTOOL_OTP_FILE to ${TARGET}.otp.json (if not already set). To -# specify a common SIGFILE for multiple targets, the SIGFILE property can be +# \brief\ Sign the target binary with the given PEM signature. +# +# This sets the target properties PICOTOOL_SIGN_OUTPUT to true, +# PICOTOOL_SIGFILE to SIGFILE (if specified), and PICOTOOL_OTP_FILE to +# ${TARGET}.otp.json (if not already set). +# +# To specify a common SIGFILE for multiple targets, the SIGFILE property can be # set for a given scope, and then the SIGFILE argument is optional. +# +# \param\ SIGFILE The PEM signature file to use function(pico_sign_binary TARGET) picotool_check_configurable(${TARGET}) # Enforce signing through target properties @@ -361,7 +393,9 @@ function(pico_sign_binary TARGET) endfunction() # pico_hash_binary(TARGET) -# Hash the target binary. This sets PICOTOOL_HASH_OUTPUT to true. +# \brief\ Hash the target binary. +# +# This sets the target property PICOTOOL_HASH_OUTPUT to true. function(pico_hash_binary TARGET) picotool_check_configurable(${TARGET}) # Enforce hashing through target properties @@ -371,8 +405,14 @@ function(pico_hash_binary TARGET) endfunction() # pico_embed_pt_in_binary(TARGET PTFILE) +# \brief_nodesc\ Embed a partition table in the binary +# # Create the specified partition table from JSON, and embed it in the -# block loop. This sets PICOTOOL_EMBED_PT to PTFILE. +# block loop. +# +# This sets the target property PICOTOOL_EMBED_PT to PTFILE. +# +# \param\ PTFILE The partition table JSON file to use function(pico_embed_pt_in_binary TARGET PTFILE) picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES @@ -381,10 +421,16 @@ function(pico_embed_pt_in_binary TARGET PTFILE) endfunction() # pico_encrypt_binary(TARGET AESFILE [SIGFILE]) +# \brief_nodesc\ Encrypt the taget binary +# # Encrypt the target binary with the given AES key (should be a binary # file containing 32 bytes of a random key), and sign the encrypted binary. -# This sets PICOTOOL_AESFILE to AESFILE, and PICOTOOL_ENC_SIGFILE to SIGFILE -# if present, else PICOTOOL_SIGFILE. +# +# This sets the target properties PICOTOOL_AESFILE to AESFILE, +# and PICOTOOL_ENC_SIGFILE to SIGFILE if present, else PICOTOOL_SIGFILE. +# +# \param\ AESFILE The AES key file to use +# \param\ SIGFILE The PEM signature file to use function(pico_encrypt_binary TARGET AESFILE) picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES @@ -410,6 +456,8 @@ function(pico_encrypt_binary TARGET AESFILE) endfunction() # pico_add_uf2_output(TARGET) +# \brief_nodesc\ Add a UF2 output using picotool +# # Add a UF2 output using picotool - must be called after # all required properties have been set function(pico_add_uf2_output TARGET) diff --git a/tools/extract_cmake_functions.py b/tools/extract_cmake_functions.py new file mode 100755 index 000000000..bc0b03ede --- /dev/null +++ b/tools/extract_cmake_functions.py @@ -0,0 +1,207 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2025 Raspberry Pi (Trading) Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# +# Script to scan the Raspberry Pi Pico SDK tree searching for CMake functions +# Outputs a tab separated file of the functions: +# name group signature brief description params +# +# Usage: +# +# tools/extract_cmake_functions.py [output file] +# +# If not specified, output file will be `pico_cmake_functions.tsv` + + +import os +import sys +import re +import csv +import logging + +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + +scandir = sys.argv[1] +outfile = sys.argv[2] if len(sys.argv) > 2 else 'pico_cmake_functions.tsv' + +CMAKE_FUNCTION_RE = re.compile(r'^\s*#(.*)((\n\s*#.*)*)\n\s*function\(([^\s]*)', re.MULTILINE) + +CMAKE_PICO_FUNCTIONS_RE = re.compile(r'^\s*function\((pico_[^\s\)]*)', re.MULTILINE) + +# Files containing internal functions that don't need to be documented publicly +skip_files = set([ + "pico_sdk_init.cmake", + "pico_utils.cmake", + "no_hardware.cmake", + "find_compiler.cmake", +]) + +skip_groups = set([ + "src", # skip the root src/CMakeLists.txt +]) + +# Other internal functions that don't need to be documented publicly +allowed_missing_functions = set([ + "pico_init_pioasm", + "pico_init_picotool", + "pico_add_platform_library", + "pico_get_runtime_output_directory", + "pico_set_printf_implementation", + "pico_expand_pico_platform", +]) + +# Group descriptions +group_names_descriptions = { + 'boot_stage2': ('Boot Stage 2', 'CMake functions to create stage 2 bootloaders'), + 'pico_binary_info': ('Pico Binary Info', 'CMake functions to add binary info to the output binary'), + 'pico_btstack': ('Pico BTstack', 'CMake functions to configure the bluetooth stack'), + 'pico_lwip': ('Pico LwIP', 'CMake functions to configure LwIP'), + 'pico_cyw43_driver': ('Pico CYW43 Driver', 'CMake functions to configure the CYW43 driver'), + 'pico_runtime': ('Pico Runtime', 'CMake functions to configure the runtime environment'), + 'pico_standard_link': ('Pico Standard Link', 'CMake functions to configure the linker'), + 'pico_stdio': ('Pico Standard I/O', 'CMake functions to configure the standard I/O library'), + 'pico_pio': ('Pico PIO', 'CMake functions to generate PIO headers'), + 'other': ('Other', 'Other CMake functions'), +} + + +all_functions = {} + +for group, (brief, description) in group_names_descriptions.items(): + all_functions['_desc_{group}'.format(group=group)] = { + 'name': '_desc_{group}'.format(group=group), + 'group': group, + 'signature': '', + 'brief': brief, + 'description': description, + 'params': '', + } + +# Supported commands: +# \brief\ +# \brief_nodesc\ +# \param\ +# \ingroup\ +# +# Commands in the middle of a line are not supported +# +# The ; character at the end of a line denotes a hard line break in the description +# The \ character (outside of a command) and the # character are not supported in descriptions +def process_commands(description, name, group, signature): + brief = '' + params = [] + desc = '' + for line in description.split('\n'): + line = line.strip() + if line.startswith('\\'): + _, command, remainder = line.split('\\', 2) + remainder = remainder.strip() + if command == 'param': + # Parameter name and description + params.append(remainder) + elif command == 'brief': + # Brief description + brief = remainder + desc += brief + '\\n' + elif command == 'brief_nodesc': + # Brief description which should not be included in the main description + brief = remainder + elif command == 'ingroup': + # Group name override + group = remainder + else: + logger.error("{}:{} has unknown command: {}".format(group, name, command)) + elif '\\' in line: + logger.error("{}:{} has a line containing '\\': {}".format(group, name, line)) + else: + desc += line + '\\n' + # Check that there are no semicolons in the parameter descriptions, as that's the delimiter for the parameter list + if any([';' in x for x in params]): + logger.error("{}:{} has a parameter description containing ';'".format(group, name)) + # Check that all parameters are in the signature + signature_words = set(re.split('\W+', signature)) + for param in params: + param_name = param.split(' ', maxsplit=1)[0] + if param_name not in signature_words: + logger.error("{}:{} has a parameter {} which is not in the signature {}".format(group, name, param_name, signature)) + # Check that the brief description is not empty + if not brief: + logger.warning("{}:{} has no brief description".format(group, name)) + # Check that the group has a description + if group not in group_names_descriptions: + logger.error("{} has no group description (referenced from {})".format(group, name)) + + desc = re.sub(r'^(\\n)*(.*?)(\\n)*$', r'\2', desc) + return desc.strip(), brief, ';'.join(params), group + + +def sort_functions(item): + group = item['group'] + name = item['name'] + + precedence = 5 + if name.startswith('_desc_'): + precedence = 0 + elif group == 'other': + if re.match(r'^pico_add_.*_output$', name): + precedence = 1 + elif name == 'pico_add_extra_outputs': + precedence = 2 + elif re.match(r'^pico_.*_binary$', name): + precedence = 3 + return group + str(precedence) + name + + +# Scan all CMakeLists.txt and .cmake files in the specific path, recursively. + +for dirpath, dirnames, filenames in os.walk(scandir): + for filename in filenames: + if filename in skip_files: + continue + # Default group is the directory name - can be overridden by the \ingroup\ command + group = os.path.basename(dirpath) + if group in skip_groups: + continue + if group in ['tools', 'cmake']: + group = 'other' + file_ext = os.path.splitext(filename)[1] + if filename == 'CMakeLists.txt' or file_ext == '.cmake': + file_path = os.path.join(dirpath, filename) + + with open(file_path, encoding="ISO-8859-1") as fh: + text = fh.read() + for match in CMAKE_FUNCTION_RE.finditer(text): + name = match.group(4) + signature = match.group(1).strip() + if signature.startswith(name): + description, brief, params, processed_group = process_commands(match.group(2).replace('#', ''), name, group, signature) + new_dict = { + 'name': name, + 'group': processed_group, + 'signature': signature, + 'brief': brief, + 'description': description, + 'params': params + } + if all_functions.get(name): + if new_dict != all_functions[name]: + logger.warning("{}:{} has multiple different definitions - using the new one from {}".format(processed_group, name, file_path)) + all_functions[name] = new_dict + + for match in CMAKE_PICO_FUNCTIONS_RE.finditer(text): + name = match.group(1) + if name not in all_functions and name not in allowed_missing_functions: + logger.warning("{} function has no description in {}".format(name, file_path)) + + +with open(outfile, 'w', newline='') as csvfile: + fieldnames = ('name', 'group', 'signature', 'brief', 'description', 'params') + writer = csv.DictWriter(csvfile, fieldnames=fieldnames, extrasaction='ignore', dialect='excel-tab') + + writer.writeheader() + for row in sorted(all_functions.values(), key=sort_functions): + writer.writerow(row) From 31fadf42eb400485873a99540a24ba7deb2f5191 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Thu, 1 May 2025 16:31:35 +0100 Subject: [PATCH 127/224] Revert "Add --recursive flag to git submodule cmd (#2416)" (#2445) This reverts commit 5592322465b449ef01ca5b4290f2f03fdff71381. --- .github/workflows/macOS.yml | 2 +- .github/workflows/multi-gcc.yml | 2 +- .github/workflows/scripts/generate_multi_gcc_workflow.py | 2 +- .github/workflows/windows.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macOS.yml b/.github/workflows/macOS.yml index 63048ee73..42282672f 100644 --- a/.github/workflows/macOS.yml +++ b/.github/workflows/macOS.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init --recursive + run: git submodule update --init - name: Install dependencies run: | brew install cmake diff --git a/.github/workflows/multi-gcc.yml b/.github/workflows/multi-gcc.yml index 73f42fd36..f20062458 100644 --- a/.github/workflows/multi-gcc.yml +++ b/.github/workflows/multi-gcc.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init --recursive + run: git submodule update --init - name: Host Release run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) diff --git a/.github/workflows/scripts/generate_multi_gcc_workflow.py b/.github/workflows/scripts/generate_multi_gcc_workflow.py index 81980f65d..7e36f63af 100755 --- a/.github/workflows/scripts/generate_multi_gcc_workflow.py +++ b/.github/workflows/scripts/generate_multi_gcc_workflow.py @@ -94,7 +94,7 @@ def __repr__(self): uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init --recursive + run: git submodule update --init - name: Host Release run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 64be455a4..ea4394af5 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Checkout submodules - run: git submodule update --init --recursive + run: git submodule update --init - name: Install dependencies run: choco install .github/workflows/choco_packages.config From 0de8847b99d9dbc8f21b6a317c63350d2e592da2 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Thu, 1 May 2025 16:35:29 +0100 Subject: [PATCH 128/224] Crashes after calling btstack_cyw43_deinit (#2446) You can deinitialise cyw43 and btstack by calling btstack_cyw43_deinit but its pending and timeout workers are not removed which means they can keep running, whcih causes a crash. Add a btstack_run_loop_async_context_deinit method and call this from btstack_cyw43_deinit. --- .../pico_btstack/btstack_run_loop_async_context.c | 8 ++++++++ .../include/pico/btstack_run_loop_async_context.h | 6 ++++++ src/rp2_common/pico_cyw43_driver/btstack_cyw43.c | 1 + 3 files changed, 15 insertions(+) diff --git a/src/rp2_common/pico_btstack/btstack_run_loop_async_context.c b/src/rp2_common/pico_btstack/btstack_run_loop_async_context.c index 9847be90d..dd66d01fc 100644 --- a/src/rp2_common/pico_btstack/btstack_run_loop_async_context.c +++ b/src/rp2_common/pico_btstack/btstack_run_loop_async_context.c @@ -129,6 +129,14 @@ const btstack_run_loop_t *btstack_run_loop_async_context_get_instance(async_cont return &btstack_run_loop_async_context; } +void btstack_run_loop_async_context_deinit(void) { + if (btstack_async_context) { + async_context_remove_at_time_worker(btstack_async_context, &btstack_timeout_worker); + async_context_remove_when_pending_worker(btstack_async_context, &btstack_processing_worker); + btstack_async_context = NULL; + } +} + static void btstack_timeout_reached(__unused async_context_t *context, __unused async_at_time_worker_t *worker) { // simply wakeup worker async_context_set_work_pending(btstack_async_context, &btstack_processing_worker); diff --git a/src/rp2_common/pico_btstack/include/pico/btstack_run_loop_async_context.h b/src/rp2_common/pico_btstack/include/pico/btstack_run_loop_async_context.h index d1b09b7dc..b3a404025 100644 --- a/src/rp2_common/pico_btstack/include/pico/btstack_run_loop_async_context.h +++ b/src/rp2_common/pico_btstack/include/pico/btstack_run_loop_async_context.h @@ -23,6 +23,12 @@ extern "C" { */ const btstack_run_loop_t *btstack_run_loop_async_context_get_instance(async_context_t *context); +/** + * \brief Deinitialize the BTstack state to stop it using the async_context API + * \ingroup pico_btstack + */ +void btstack_run_loop_async_context_deinit(void); + #ifdef __cplusplus } #endif diff --git a/src/rp2_common/pico_cyw43_driver/btstack_cyw43.c b/src/rp2_common/pico_cyw43_driver/btstack_cyw43.c index 75061f167..dd15835e8 100644 --- a/src/rp2_common/pico_cyw43_driver/btstack_cyw43.c +++ b/src/rp2_common/pico_cyw43_driver/btstack_cyw43.c @@ -69,6 +69,7 @@ bool btstack_cyw43_init(async_context_t *context) { void btstack_cyw43_deinit(__unused async_context_t *context) { hci_power_control(HCI_POWER_OFF); hci_close(); + btstack_run_loop_async_context_deinit(); btstack_run_loop_deinit(); btstack_memory_deinit(); } \ No newline at end of file From 4bbd53371e9966228df22625be6aa0127de4bd59 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Fri, 2 May 2025 14:42:53 +0100 Subject: [PATCH 129/224] Fix sha build issues with mbedtls 3.x (#2447) The mbedtls methods have dropped the "_ret" from the function names in mbedtls 3.x. Use the new function names but support the old names if mbedtls 2.x is used. --- src/rp2_common/pico_mbedtls/pico_mbedtls.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/pico_mbedtls/pico_mbedtls.c b/src/rp2_common/pico_mbedtls/pico_mbedtls.c index c7b61c077..914ea15d8 100644 --- a/src/rp2_common/pico_mbedtls/pico_mbedtls.c +++ b/src/rp2_common/pico_mbedtls/pico_mbedtls.c @@ -8,6 +8,13 @@ #include "pico.h" #include "pico/rand.h" #include "mbedtls/sha256.h" +#include "mbedtls/version.h" + +#if MBEDTLS_VERSION_MAJOR < 3 +#define mbedtls_sha256_starts mbedtls_sha256_starts_ret +#define mbedtls_sha256_update mbedtls_sha256_update_ret +#define mbedtls_sha256_finish mbedtls_sha256_finish_ret +#endif /* Function to feed mbedtls entropy. */ int mbedtls_hardware_poll(void *data __unused, unsigned char *output, size_t len, size_t *olen) { @@ -38,17 +45,17 @@ void mbedtls_sha256_free(__unused mbedtls_sha256_context *ctx) { pico_sha256_cleanup(ctx); } -int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224) { +int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) { hard_assert(!is224); // that's annoying return pico_sha256_start_blocking(ctx, SHA256_BIG_ENDIAN, PICO_MBEDTLS_SHA256_ALT_USE_DMA); } -int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen) { +int mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen) { pico_sha256_update_blocking(ctx, input, ilen); return 0; } -int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32]) { +int mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32]) { sha256_result_t result; pico_sha256_finish(ctx, &result); memcpy(output, result.bytes, 32); From ec25563b827b99885878c6369e55f03a6efbe04f Mon Sep 17 00:00:00 2001 From: Andrew Brock Date: Mon, 5 May 2025 03:57:04 +1000 Subject: [PATCH 130/224] Fix binary_info compilation in C++ due to out-of-order designated initialisers (#2438) --- src/common/pico_binary_info/include/pico/binary_info/code.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/pico_binary_info/include/pico/binary_info/code.h b/src/common/pico_binary_info/include/pico/binary_info/code.h index 63239a963..b7fedc9ad 100644 --- a/src/common/pico_binary_info/include/pico/binary_info/code.h +++ b/src/common/pico_binary_info/include/pico/binary_info/code.h @@ -156,8 +156,8 @@ static const struct _binary_info_named_group __bi_lineno_var_name = { \ .tag = _parent_tag, \ },\ .parent_id = _parent_id, \ - .group_tag = _group_tag, \ .flags = _flags, \ + .group_tag = _group_tag, \ .group_id = _group_id, \ .label = _label \ } From 25789c433f95a09ba317ce4a842e4a9b368ba02d Mon Sep 17 00:00:00 2001 From: Tommy G <7865781+tommy-gilligan@users.noreply.github.com> Date: Mon, 5 May 2025 05:21:00 +1000 Subject: [PATCH 131/224] Fix wrong value used for lposc_freq_khz_frac and xosc_freq_khz_frac --- src/rp2_common/hardware_powman/powman.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/hardware_powman/powman.c b/src/rp2_common/hardware_powman/powman.c index b9c556482..2f9b9c367 100644 --- a/src/rp2_common/hardware_powman/powman.c +++ b/src/rp2_common/hardware_powman/powman.c @@ -69,7 +69,7 @@ void powman_timer_set_1khz_tick_source_lposc_with_hz(uint32_t lposc_freq_hz) { bool was_running = powman_timer_is_running(); if (was_running) powman_timer_stop(); uint32_t lposc_freq_khz = lposc_freq_hz / 1000; - uint32_t lposc_freq_khz_frac16 = (lposc_freq_khz % 1000) * 65536 / 1000; + uint32_t lposc_freq_khz_frac16 = (lposc_freq_hz % 1000) * 65536 / 1000; powman_write(&powman_hw->lposc_freq_khz_int, lposc_freq_khz); powman_write(&powman_hw->lposc_freq_khz_frac, lposc_freq_khz_frac16); powman_set_bits(&powman_hw->timer, POWMAN_TIMER_USE_LPOSC_BITS); @@ -87,7 +87,7 @@ void powman_timer_set_1khz_tick_source_xosc_with_hz(uint32_t xosc_freq_hz) { bool was_running = powman_timer_is_running(); if (was_running) powman_timer_stop(); uint32_t xosc_freq_khz = xosc_freq_hz / 1000; - uint32_t xosc_freq_khz_frac16 = (xosc_freq_khz % 1000) * 65536 / 1000; + uint32_t xosc_freq_khz_frac16 = (xosc_freq_hz % 1000) * 65536 / 1000; powman_write(&powman_hw->xosc_freq_khz_int, xosc_freq_khz); powman_write(&powman_hw->xosc_freq_khz_frac, xosc_freq_khz_frac16); powman_set_bits(&powman_hw->timer, POWMAN_TIMER_USE_XOSC_BITS); From 0779dfe3eb753d58df447aafd28be4cf9bb8ec3d Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 6 May 2025 15:14:20 +0100 Subject: [PATCH 132/224] Small PICO_CONFIG tweak (#2456) --- src/rp2_common/pico_mbedtls/pico_mbedtls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_mbedtls/pico_mbedtls.c b/src/rp2_common/pico_mbedtls/pico_mbedtls.c index 914ea15d8..b767b136f 100644 --- a/src/rp2_common/pico_mbedtls/pico_mbedtls.c +++ b/src/rp2_common/pico_mbedtls/pico_mbedtls.c @@ -33,7 +33,7 @@ int mbedtls_hardware_poll(void *data __unused, unsigned char *output, size_t len #error SHA256 hardware acceleration not supported #endif -// PICO_CONFIG: PICO_MBEDTLS_SHA256_ALT_USE_DMA, Whether to use DMA for writing to hardware for the mbedtls SHA-256 hardware acceleration, type=int, default=1, group=pico_mbedtls +// PICO_CONFIG: PICO_MBEDTLS_SHA256_ALT_USE_DMA, Whether to use DMA for writing to hardware for the mbedtls SHA-256 hardware acceleration, type=bool, default=1, group=pico_mbedtls #ifndef PICO_MBEDTLS_SHA256_ALT_USE_DMA #define PICO_MBEDTLS_SHA256_ALT_USE_DMA 1 #endif From 7cdb8eca574a61dbff0ee253c70d6f37b0e906e4 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 7 May 2025 08:56:19 -0500 Subject: [PATCH 133/224] Add PICO_CRT0_NO_RESET_SECTION (#2453) --- src/rp2_common/pico_crt0/crt0.S | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index eb477bd1e..9b4aa6e78 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -23,6 +23,11 @@ pico_default_asm_setup +// PICO_CONFIG: PICO_CRT0_NO_RESET_SECTION, Omit .reset section contents containing the startup code. This must be set if you want to replace the startup code while still keeping the rest of pico_crt0 as the reset section define here is not garbage collected, type=bool, default=0, advanced=true, group=pico_crt0 +#ifndef PICO_CRT0_NO_RESET_SECTION +#define PICO_CRT0_NO_RESET_SECTION 0 +#endif + #ifdef PICO_NO_STORED_VECTOR_TABLE #warning PICO_NO_STORED_VECTOR_TABLE is no longer used. PICO_MINIMAL_STORED_VECTOR_TABLE is not identical but usually serves the same purpose #endif @@ -328,6 +333,7 @@ binary_info_header: // ---------------------------------------------------------------------------- +#if !PICO_CRT0_NO_RESET_SECTION .section .reset, "ax" // On flash builds, the vector table comes first in the image (conventional). @@ -492,7 +498,7 @@ data_cpy: // Note the data copy table is still included for NO_FLASH builds, even though // we skip the copy, because it is listed in binary info -.align 2 +.p2align 2 data_cpy_table: #if PICO_RP2350 && PICO_EMBED_XIP_SETUP && !PICO_NO_FLASH .word __boot2_start__ @@ -529,6 +535,7 @@ data_cpy_table: runtime_init: bx lr +#endif // PICO_CRT0_NO_RESET_SECTION // ---------------------------------------------------------------------------- // Stack/heap dummies to set size From 799225d550394392b8a26947529971b12b2544b9 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 7 May 2025 08:56:40 -0500 Subject: [PATCH 134/224] Add PICO_CRT0_NEAR_CALLS to indicate that crt0 can call runtimine_init/main/exit etc via near calls (#2452) --------- Co-authored-by: will-v-pi <108662275+will-v-pi@users.noreply.github.com> --- src/rp2_common/pico_crt0/crt0.S | 26 +++++++++++++++++----- src/rp2_common/pico_runtime/CMakeLists.txt | 6 ++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index 9b4aa6e78..502c4fdba 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -15,6 +15,11 @@ #include "boot/picobin.h" #include "pico/bootrom.h" +// PICO_CONFIG: PICO_CRT0_NEAR_CALLS, Whether calls from crt0 into the binary are near (<16M away) - ignored for PICO_COPY_TO_RAM, default=0, type=bool, group=pico_crt0 +#ifndef PICO_CRT0_NEAR_CALLS +#define PICO_CRT0_NEAR_CALLS 0 +#endif + #ifdef NDEBUG #ifndef COLLAPSE_IRQS #define COLLAPSE_IRQS @@ -377,6 +382,12 @@ _entry_point: sev 1: #endif +#if !__ARM_ARCH_6M__ + // Make sure stack limit is 0 if we came in thru the debugger; we do not know what it should be + movs r0, #0 + msr msplim, r0 +#endif + ldr r0, =__vectors // Vector through our own table (SP, VTOR will not have been set up at // this point). Same path for debugger entry and bootloader entry. @@ -403,6 +414,9 @@ _enter_vtable_in_r0: .type _reset_handler,%function .thumb_func _reset_handler: + // Note if we entered thru here on core 0, then we should have gone thru bootrom, so SP (and MSPLIM) on Armv8-M + // should already be set + // Only core 0 should run the C runtime startup code; core 1 is normally // sleeping in the bootrom at this point but check to be sure (e.g. if // debugger put core 1 at the ELF entry point for some reason) @@ -465,20 +479,20 @@ bss_fill_test: bne bss_fill_loop platform_entry: // symbol for stack traces +#if PICO_CRT0_NEAR_CALLS && !PICO_COPY_TO_RAM + bl runtime_init + bl main + bl exit +#else // Use 32-bit jumps, in case these symbols are moved out of branch range // (e.g. if main is in SRAM and crt0 in flash) -#if !__ARM_ARCH_6M__ - // Make sure stack limit is 0 - the user can set it themselves - // todo probably worth adding to the EXE_DEF in the future - movs r0, #0 - msr msplim, r0 -#endif ldr r1, =runtime_init blx r1 ldr r1, =main blx r1 ldr r1, =exit blx r1 +#endif // exit should not return. If it does, hang the core. 1: // separate label because _exit can be moved out of branch range bkpt #0 diff --git a/src/rp2_common/pico_runtime/CMakeLists.txt b/src/rp2_common/pico_runtime/CMakeLists.txt index 59c825201..e190d5106 100644 --- a/src/rp2_common/pico_runtime/CMakeLists.txt +++ b/src/rp2_common/pico_runtime/CMakeLists.txt @@ -68,6 +68,7 @@ endif() # FPGA_CHECK - checks for FPGA which allows Raspberry Pi to run your binary on FPGA; # PANIC - default panic impl which brings in stdio; # AUTO_INIT_MUTEX - auto init mutexes, without this you get no printf mutex either; +# CRT0_FAR_CALLS - use blx not bl for calls from crt0 to user overridable functions; # # \param\ INCLUDE The items to include # \param\ EXCLUDE The items to exclude @@ -148,4 +149,7 @@ function(pico_minimize_runtime TARGET) if (NOT RUNTIME_INCLUDE_FPGA_CHECK) target_compile_definitions(${TARGET} PRIVATE PICO_NO_FPGA_CHECK=1) endif() -endfunction() \ No newline at end of file + if (NOT RUNTIME_CRT0_FAR_CALLS) + target_compile_definitions(${TARGET} PRIVATE PICO_CRT0_NEAR_CALLS=1) + endif() +endfunction() From 792f55628efb043e98c96b3486953cdfd3957df8 Mon Sep 17 00:00:00 2001 From: Michael Brase Date: Thu, 8 May 2025 09:26:08 -0600 Subject: [PATCH 135/224] Use cyw43_delay_ms() in cyw43_spi_reset() instead of sleep_ms() (#2431) Since cyw43_spi_reset() may be executed from an async context, we should use cyw43_delay_ms() instead of sleep_ms(). This is particularly a problem when using the async_context_threadsafe_background backend, because sleep_ms() will assert in an ISR. --- src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c b/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c index 30b184736..06d5beff3 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c @@ -359,9 +359,9 @@ void cyw43_spi_gpio_setup(void) { // Reset wifi chip void cyw43_spi_reset(void) { gpio_put(CYW43_PIN_WL_REG_ON, false); // off - sleep_ms(20); + cyw43_delay_ms(20); gpio_put(CYW43_PIN_WL_REG_ON, true); // on - sleep_ms(250); + cyw43_delay_ms(250); // Setup IRQ (24) - also used for DO, DI gpio_init(CYW43_PIN_WL_HOST_WAKE); From 550aa09624391dfbc3afae55ede3e008a3879614 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Sun, 11 May 2025 20:34:17 -0500 Subject: [PATCH 136/224] fix typo in PICO_RUNTIME_SKIP_INIT_POST_CLOCK_RESETS (was missing INIT) (#2457) --- src/rp2_common/pico_runtime_init/runtime_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_runtime_init/runtime_init.c b/src/rp2_common/pico_runtime_init/runtime_init.c index 2e1ce89fc..5e1ad04ae 100644 --- a/src/rp2_common/pico_runtime_init/runtime_init.c +++ b/src/rp2_common/pico_runtime_init/runtime_init.c @@ -152,7 +152,7 @@ void __weak runtime_init_post_clock_resets(void) { } #endif -#if !PICO_RUNTIME_SKIP_POST_CLOCK_RESETS +#if !PICO_RUNTIME_SKIP_INIT_POST_CLOCK_RESETS PICO_RUNTIME_INIT_FUNC_HW(runtime_init_post_clock_resets, PICO_RUNTIME_INIT_POST_CLOCK_RESETS); #endif From 14d75c0b78e2b222e32cb9896500ddf48a7b1ef4 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Tue, 20 May 2025 21:29:41 +0100 Subject: [PATCH 137/224] Add printout of picotool location (#2475) This prints out the location of the picotool executable being used For example: * `Using picotool from /usr/local/bin/picotool` for a system install * `Using picotool from /home/name/pico-examples/build/_deps/picotool/picotool` for a picotool fetched by the SDK --- tools/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 5273840a5..bb9f7eaa3 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -139,6 +139,14 @@ function(pico_init_picotool) endif() endif() + if (TARGET picotool AND NOT DEFINED ENV{_PICOTOOL_FOUND_THIS_RUN}) + # Internal environment variable to prevent printing multiple times + set(ENV{_PICOTOOL_FOUND_THIS_RUN} 1) + + get_property(picotool_location TARGET picotool PROPERTY LOCATION) + message("Using picotool from ${picotool_location}") + endif() + if (TARGET picotool) set(picotool_FOUND 1 PARENT_SCOPE) else() From 66540fe88e86a9f324422b7451a3b5dff4c0449f Mon Sep 17 00:00:00 2001 From: 27Onion Nebell <57032603+onion108@users.noreply.github.com> Date: Wed, 21 May 2025 04:30:17 +0800 Subject: [PATCH 138/224] Fix pioasm build failure caused by GCC 15 changes (#2448) (#2468) --- tools/pioasm/output_format.h | 3 ++- tools/pioasm/pio_types.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/pioasm/output_format.h b/tools/pioasm/output_format.h index 405a5ae75..d42ea73b4 100644 --- a/tools/pioasm/output_format.h +++ b/tools/pioasm/output_format.h @@ -7,6 +7,7 @@ #ifndef _OUTPUT_FORMAT_H #define _OUTPUT_FORMAT_H +#include #include #include #include @@ -120,4 +121,4 @@ struct output_format { output_format(std::string name) : name(std::move(name)) {} }; -#endif \ No newline at end of file +#endif diff --git a/tools/pioasm/pio_types.h b/tools/pioasm/pio_types.h index 9f9fb0e3e..755eb75a0 100644 --- a/tools/pioasm/pio_types.h +++ b/tools/pioasm/pio_types.h @@ -7,6 +7,7 @@ #ifndef _PIO_TYPES_H #define _PIO_TYPES_H +#include #include #include #include From 8066bee734a2d3f6c74174ea68259d8b67fce2b6 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 20 May 2025 15:32:27 -0500 Subject: [PATCH 139/224] give user more control over embedded_start_block.S contents (#2470) --- .../pico_crt0/embedded_start_block.inc.S | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/rp2_common/pico_crt0/embedded_start_block.inc.S b/src/rp2_common/pico_crt0/embedded_start_block.inc.S index e4632255b..4618a3a94 100644 --- a/src/rp2_common/pico_crt0/embedded_start_block.inc.S +++ b/src/rp2_common/pico_crt0/embedded_start_block.inc.S @@ -5,6 +5,21 @@ #endif #endif +#ifndef PICO_CRT0_INCLUDE_PICOBIN_VECTOR_TABLE_ITEM +// If no_flash bin, then include a vector table item +#if PICO_NO_FLASH && !PICO_RP2040 +#define PICO_CRT0_INCLUDE_PICOBIN_VECTOR_TABLE_ITEM 1 +#endif +#endif + +#ifndef PICO_CRT0_INCLUDE_PICOBIN_ENTRY_POINT_ITEM +// On RISC-V the default entry point from bootrom is the start of the binary, but +// we have our vtable at the start, so we must include an entry point +#ifdef __riscv +#define PICO_CRT0_INCLUDE_PICOBIN_ENTRY_POINT_ITEM 1 +#endif +#endif + #ifndef PICO_CRT0_INCLUDE_PICOBIN_BLOCK #define PICO_CRT0_INCLUDE_PICOBIN_BLOCK PICO_CRT0_INCLUDE_PICOBIN_IMAGE_TYPE_ITEM #endif @@ -73,9 +88,7 @@ embedded_block: .hword PICO_CRT0_VERSION_MAJOR #endif -#ifdef __riscv -// On RISC-V the default entry point from bootrom is the start of the binary, but -// we have our vtable at the start, so we must include an entry point +#if PICO_CRT0_INCLUDE_PICOBIN_ENTRY_POINT_ITEM .byte PICOBIN_BLOCK_ITEM_1BS_ENTRY_POINT .byte 0x3 // word size to next item .byte 0 // pad @@ -84,15 +97,12 @@ embedded_block: .word SRAM_END // stack pointer #endif -#if !PICO_RP2040 -#if PICO_NO_FLASH -// If no_flash bin, then include a vector table item +#if PICO_CRT0_INCLUDE_PICOBIN_VECTOR_TABLE_ITEM .byte PICOBIN_BLOCK_ITEM_1BS_VECTOR_TABLE .byte 0x2 .hword 0 .word __vectors #endif -#endif .byte PICOBIN_BLOCK_ITEM_2BS_LAST .hword (embedded_block_end - embedded_block - 16 ) / 4 // total size of all @@ -106,4 +116,4 @@ embedded_block: #endif .word PICOBIN_BLOCK_MARKER_END embedded_block_end: -#endif \ No newline at end of file +#endif From cbd765644b40db5e0090ce001c86caaa30fb33d5 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Tue, 20 May 2025 21:41:30 +0100 Subject: [PATCH 140/224] Minor fixups to compile with TF-M (#2403) * Minor fixups to compile with TF-M TF-M requires c99 compatibility, which throws errors at these lines This patch fixes those errors and is currently applied by TF-M when cloning the SDK, but it would be better to get it into the SDK by default so that patch isn't needed * #ifdef only on __STRICT_ANSI__ Also fix devinfo type --- src/common/pico_sync/sem.c | 2 +- src/rp2_common/hardware_flash/flash.c | 4 ++++ src/rp2_common/pico_multicore/multicore.c | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common/pico_sync/sem.c b/src/common/pico_sync/sem.c index 904481706..8fc44580f 100644 --- a/src/common/pico_sync/sem.c +++ b/src/common/pico_sync/sem.c @@ -15,7 +15,7 @@ void sem_init(semaphore_t *sem, int16_t initial_permits, int16_t max_permits) { } int __time_critical_func(sem_available)(semaphore_t *sem) { -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) return *(volatile typeof(sem->permits) *) &sem->permits; #else static_assert(sizeof(sem->permits) == 2, ""); diff --git a/src/rp2_common/hardware_flash/flash.c b/src/rp2_common/hardware_flash/flash.c index adae07878..dab5d6b46 100644 --- a/src/rp2_common/hardware_flash/flash.c +++ b/src/rp2_common/hardware_flash/flash.c @@ -299,7 +299,11 @@ static void flash_devinfo_update_field(uint16_t wdata, uint16_t mask) { // Boot RAM does not support exclusives, but does support RWTYPE SET/CLR/XOR (with byte // strobes). Can't use hw_write_masked because it performs a 32-bit write. io_rw_16 *devinfo = flash_devinfo_ptr(); +#ifdef __STRICT_ANSI__ + *(io_rw_16 *)hw_xor_alias_untyped(devinfo) = (*devinfo ^ wdata) & mask; +#else *hw_xor_alias(devinfo) = (*devinfo ^ wdata) & mask; +#endif } // This is a RAM function because may be called during flash programming to enable save/restore of diff --git a/src/rp2_common/pico_multicore/multicore.c b/src/rp2_common/pico_multicore/multicore.c index f8f5660db..27ec3c644 100644 --- a/src/rp2_common/pico_multicore/multicore.c +++ b/src/rp2_common/pico_multicore/multicore.c @@ -101,8 +101,13 @@ int core1_wrapper(int (*entry)(void), void *stack_base) { void multicore_reset_core1(void) { // Use atomic aliases just in case core 1 is also manipulating some PSM state io_rw_32 *power_off = (io_rw_32 *) (PSM_BASE + PSM_FRCE_OFF_OFFSET); +#ifdef __STRICT_ANSI__ + io_rw_32 *power_off_set = hw_set_alias_untyped(power_off); + io_rw_32 *power_off_clr = hw_clear_alias_untyped(power_off); +#else io_rw_32 *power_off_set = hw_set_alias(power_off); io_rw_32 *power_off_clr = hw_clear_alias(power_off); +#endif // Hard-reset core 1. // Reading back confirms the core 1 reset is in the correct state, but also From 47f288b5d67c9503734c76484e7df6f95218fbe2 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Tue, 20 May 2025 17:41:49 -0300 Subject: [PATCH 141/224] Add support for wiznet_w5100s_evb_pico2 (#2458) * Add support for wiznet_w5100s_evb_pico2 This board has an RP2350 and a smaller 2MB flash Signed-off-by: Sergio R. Caprile * update to new syntax Signed-off-by: Sergio R. Caprile * fix missing definition Signed-off-by: Sergio R. Caprile --------- Signed-off-by: Sergio R. Caprile --- .../include/boards/wiznet_w5100s_evb_pico2.h | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/boards/include/boards/wiznet_w5100s_evb_pico2.h diff --git a/src/boards/include/boards/wiznet_w5100s_evb_pico2.h b/src/boards/include/boards/wiznet_w5100s_evb_pico2.h new file mode 100644 index 000000000..0db645455 --- /dev/null +++ b/src/boards/include/boards/wiznet_w5100s_evb_pico2.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +#ifndef _BOARDS_WIZNET_W5100S_EVB_PICO2_H +#define _BOARDS_WIZNET_W5100S_EVB_PICO2_H + +pico_board_cmake_set(PICO_PLATFORM, rp2350) + +// For board detection +#define WIZNET_W5100S_EVB_PICO2 + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- BOARD SPECIFIC --- +#ifndef W5100S_EVB_PICO2_INTN_PIN +#define W5100S_EVB_PICO2_INTN_PIN 21 +#endif + +#ifndef W5100S_EVB_PICO2_RSTN_PIN +#define W5100S_EVB_PICO2_RSTN_PIN 20 +#endif + +#ifndef W5100S_EVB_PICO2_A0_PIN +#define W5100S_EVB_PICO2_A0_PIN 26 +#endif +#ifndef W5100S_EVB_PICO2_A1_PIN +#define W5100S_EVB_PICO2_A1_PIN 27 +#endif +#ifndef W5100S_EVB_PICO2_A2_PIN +#define W5100S_EVB_PICO2_A2_PIN 28 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 4 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 5 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) +#endif +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +// The GPIO Pin used to read VBUS to determine if the device is battery powered. +#ifndef PICO_VBUS_PIN +#define PICO_VBUS_PIN 24 +#endif + +// The GPIO Pin used to monitor VSYS. Typically you would use this with ADC. +// There is an example in adc/read_vsys in pico-examples. +#ifndef PICO_VSYS_PIN +#define PICO_VSYS_PIN 29 +#endif + +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif From 3515dad632caf27720e6431b2d085e96841ad992 Mon Sep 17 00:00:00 2001 From: Jack Whitham Date: Tue, 20 May 2025 21:43:06 +0100 Subject: [PATCH 142/224] Fix multicore_lockout features so that the victim core cannot become stuck in an infinite loop if the lockout attempt times out (#2467) * Fix issue 2454 flash safe execute lockout The lockout state is controlled by a shared variable. The FIFO is used to begin a lockout and acknowledge it (i.e. multicore_lockout_handshake works as before) but the end of the lockout is now signalled by updating the shared variable. This ensures that timeouts are recognised reliably by the victim core. __wfe and __sev are used to signal updates to the shared variable in order to avoid polling. * Update documentation for multicore_lockout_end functions * Simplification, remove magic number (not required) * Review improvements * Restore use of non-zero magic number --- .../pico_multicore/include/pico/multicore.h | 24 ++++---- src/rp2_common/pico_multicore/multicore.c | 57 ++++++++++++------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/rp2_common/pico_multicore/include/pico/multicore.h b/src/rp2_common/pico_multicore/include/pico/multicore.h index 9b4622a98..fe198aed6 100644 --- a/src/rp2_common/pico_multicore/include/pico/multicore.h +++ b/src/rp2_common/pico_multicore/include/pico/multicore.h @@ -437,7 +437,7 @@ static inline uint multicore_doorbell_irq_num(uint doorbell_num) { * The core which wishes to lockout the other core calls \ref multicore_lockout_start_blocking or * \ref multicore_lockout_start_timeout_us to interrupt the other "victim" core and wait for it to be in a * "locked out" state. Once the lockout is no longer needed it calls \ref multicore_lockout_end_blocking or - * \ref multicore_lockout_end_timeout_us to release the lockout and wait for confirmation. + * \ref multicore_lockout_end_timeout_us to release the lockout. * * \note Because multicore lockout uses the intercore FIFOs, the FIFOs cannot be used for any other purpose */ @@ -491,27 +491,31 @@ void multicore_lockout_start_blocking(void); */ bool multicore_lockout_start_timeout_us(uint64_t timeout_us); -/*! \brief Release the other core from a locked out state amd wait for it to acknowledge +/*! \brief Release the other core from a locked out state * \ingroup multicore_lockout * - * \note The other core must previously have been "locked out" by calling a `multicore_lockout_start_` function - * from this core + * The other core must previously have been "locked out" by calling a `multicore_lockout_start_` function + * from this core. + * + * \note The other core will leave the lockout state if this function is called. + * The function only blocks for access to a lockout mutex, it does not wait for the other core + * to leave the lockout state. */ void multicore_lockout_end_blocking(void); -/*! \brief Release the other core from a locked out state amd wait up to a time limit for it to acknowledge +/*! \brief Release the other core from a locked out state * \ingroup multicore_lockout * * The other core must previously have been "locked out" by calling a `multicore_lockout_start_` function * from this core * - * \note be very careful using small timeout values, as a timeout here will leave the "lockout" functionality - * in a bad state. It is probably preferable to use \ref multicore_lockout_end_blocking anyway as if you have - * already waited for the victim core to enter the lockout state, then the victim core will be ready to exit - * the lockout state very quickly. + * \note The other core will leave the lockout state if this function returns true. + * The function only blocks for access to a lockout mutex, it does not wait for the other core + * to leave the lockout state. If the lockout mutex could not be acquired, the function returns + * false and no action is taken. * * \param timeout_us the timeout in microseconds - * \return true if the other core successfully exited locked out state within the timeout, false otherwise + * \return true if the other core will leave the lockout state, false otherwise */ bool multicore_lockout_end_timeout_us(uint64_t timeout_us); diff --git a/src/rp2_common/pico_multicore/multicore.c b/src/rp2_common/pico_multicore/multicore.c index 27ec3c644..73a1a999a 100644 --- a/src/rp2_common/pico_multicore/multicore.c +++ b/src/rp2_common/pico_multicore/multicore.c @@ -207,25 +207,27 @@ void multicore_launch_core1_raw(void (*entry)(void), uint32_t *sp, uint32_t vect irq_set_enabled(irq_num, enabled); } -#define LOCKOUT_MAGIC_START 0x73a8831eu -#define LOCKOUT_MAGIC_END (~LOCKOUT_MAGIC_START) - +// A non-zero initialisation value is used in order to reduce the chance of +// entering the lock handler on bootup due to a 0-word being present in the FIFO +static volatile uint32_t lockout_request_id = 0x73a8831eu; static mutex_t lockout_mutex; -static bool lockout_in_progress; // note this method is in RAM because lockout is used when writing to flash // it only makes inline calls static void __isr __not_in_flash_func(multicore_lockout_handler)(void) { multicore_fifo_clear_irq(); while (multicore_fifo_rvalid()) { - if (sio_hw->fifo_rd == LOCKOUT_MAGIC_START) { + uint32_t request_id = sio_hw->fifo_rd; + if (request_id == lockout_request_id) { + // valid lockout request received uint32_t save = save_and_disable_interrupts(); - multicore_fifo_push_blocking_inline(LOCKOUT_MAGIC_START); - while (multicore_fifo_pop_blocking_inline() != LOCKOUT_MAGIC_END) { - tight_loop_contents(); // not tight but endless potentially + multicore_fifo_push_blocking_inline(request_id); + // wait for the lockout to expire + while (request_id == lockout_request_id) { + // when lockout_request_id is updated, the other CPU core calls __sev + __wfe(); } restore_interrupts_from_disabled(save); - multicore_fifo_push_blocking_inline(LOCKOUT_MAGIC_END); } } } @@ -262,7 +264,7 @@ void multicore_lockout_victim_deinit(void) { } } -static bool multicore_lockout_handshake(uint32_t magic, absolute_time_t until) { +static bool multicore_lockout_handshake(uint32_t request_id, absolute_time_t until) { uint irq_num = SIO_FIFO_IRQ_NUM(get_core_num()); bool enabled = irq_is_enabled(irq_num); if (enabled) irq_set_enabled(irq_num, false); @@ -272,7 +274,7 @@ static bool multicore_lockout_handshake(uint32_t magic, absolute_time_t until) { if (next_timeout_us < 0) { break; } - multicore_fifo_push_timeout_us(magic, (uint64_t)next_timeout_us); + multicore_fifo_push_timeout_us(request_id, (uint64_t)next_timeout_us); next_timeout_us = absolute_time_diff_us(get_absolute_time(), until); if (next_timeout_us < 0) { break; @@ -281,7 +283,7 @@ static bool multicore_lockout_handshake(uint32_t magic, absolute_time_t until) { if (!multicore_fifo_pop_timeout_us((uint64_t)next_timeout_us, &word)) { break; } - if (word == magic) { + if (word == request_id) { rc = true; } } while (!rc); @@ -289,14 +291,28 @@ static bool multicore_lockout_handshake(uint32_t magic, absolute_time_t until) { return rc; } +static uint32_t update_lockout_request_id(void) { + // generate new number and then update shared variable + uint32_t new_request_id = lockout_request_id + 1; + lockout_request_id = new_request_id; + // notify other core + __sev(); + return new_request_id; +} + static bool multicore_lockout_start_block_until(absolute_time_t until) { check_lockout_mutex_init(); if (!mutex_enter_block_until(&lockout_mutex, until)) { return false; } - hard_assert(!lockout_in_progress); - bool rc = multicore_lockout_handshake(LOCKOUT_MAGIC_START, until); - lockout_in_progress = rc; + // generate a new request_id number + uint32_t request_id = update_lockout_request_id(); + // attempt to lock out + bool rc = multicore_lockout_handshake(request_id, until); + if (!rc) { + // lockout failed - cancel it + update_lockout_request_id(); + } mutex_exit(&lockout_mutex); return rc; } @@ -314,13 +330,10 @@ static bool multicore_lockout_end_block_until(absolute_time_t until) { if (!mutex_enter_block_until(&lockout_mutex, until)) { return false; } - assert(lockout_in_progress); - bool rc = multicore_lockout_handshake(LOCKOUT_MAGIC_END, until); - if (rc) { - lockout_in_progress = false; - } + // lockout finished - cancel it + update_lockout_request_id(); mutex_exit(&lockout_mutex); - return rc; + return true; } bool multicore_lockout_end_timeout_us(uint64_t timeout_us) { @@ -407,4 +420,4 @@ void multicore_doorbell_unclaim(uint doorbell_num, uint core_mask) { } -#endif \ No newline at end of file +#endif From c9c38252ecff4ce7dd658fc8c6553925c9aaa50c Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 21 May 2025 06:57:09 -0500 Subject: [PATCH 143/224] remove assembler warning if StackSize or HeapSize are explicitly set to zero (#2465) --- src/rp2_common/pico_crt0/crt0.S | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index 502c4fdba..3e6c692d8 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -573,11 +573,15 @@ spacer_section .stack // align to allow for memory protection (although this alignment is pretty much ignored by linker script) .p2align 5 .equ StackSize, PICO_STACK_SIZE +.if StackSize != 0 .space StackSize +.endif spacer_section .heap .p2align 2 .equ HeapSize, PICO_HEAP_SIZE +.if HeapSize != 0 .space HeapSize +.endif #include "embedded_end_block.inc.S" From 9fdfe110dc2f44cb4c23f49370db45a6689a5a08 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Fri, 23 May 2025 13:15:44 +0100 Subject: [PATCH 144/224] Remove accidental comment words in stdio.h (#2480) --- src/rp2_common/pico_stdio/include/pico/stdio.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rp2_common/pico_stdio/include/pico/stdio.h b/src/rp2_common/pico_stdio/include/pico/stdio.h index cba3b27c4..8f259d57a 100644 --- a/src/rp2_common/pico_stdio/include/pico/stdio.h +++ b/src/rp2_common/pico_stdio/include/pico/stdio.h @@ -186,35 +186,35 @@ int stdio_get_until(char *buf, int len, absolute_time_t until); */ int stdio_put_string(const char *s, int len, bool newline, bool cr_translation); -/*! \brief stdio_getchar Alias for \ref getchar that definitely does not go thru the implementation +/*! \brief Alias for \ref getchar that definitely does not go thru the implementation * in the standard C library even when \ref PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS == 0 * * \ingroup pico_stdio */ int stdio_getchar(void); -/*! \brief stdio_getchar Alias for \ref putchar that definitely does not go thru the implementation +/*! \brief Alias for \ref putchar that definitely does not go thru the implementation * in the standard C library even when \ref PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS == 0 * * \ingroup pico_stdio */ int stdio_putchar(int); -/*! \brief stdio_getchar Alias for \ref puts that definitely does not go thru the implementation +/*! \brief Alias for \ref puts that definitely does not go thru the implementation * in the standard C library even when \ref PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS == 0 * * \ingroup pico_stdio */ int stdio_puts(const char *s); -/*! \brief stdio_getchar Alias for \ref vprintf that definitely does not go thru the implementation +/*! \brief Alias for \ref vprintf that definitely does not go thru the implementation * in the standard C library even when \ref PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS == 0 * * \ingroup pico_stdio */ int stdio_vprintf(const char *format, va_list va); -/*! \brief stdio_getchar Alias for \ref printf that definitely does not go thru the implementation +/*! \brief Alias for \ref printf that definitely does not go thru the implementation * in the standard C library even when \ref PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS == 0 * * \ingroup pico_stdio From 6613aa45a567d0e0eac7bd7c9cd6515c01656fa6 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Thu, 29 May 2025 14:12:29 +0100 Subject: [PATCH 145/224] Add support for creating self-decrypting binaries (#2315) Note: this support is experimental until the next release Co-authored-by: graham sanderson --- tools/CMakeLists.txt | 122 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 112 insertions(+), 10 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index bb9f7eaa3..1d98f0312 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -41,6 +41,30 @@ define_property(TARGET BRIEF_DOCS "AES key for encrypting" FULL_DOCS "AES key for encrypting" ) +define_property(TARGET + PROPERTY PICOTOOL_IVFILE + INHERITED + BRIEF_DOCS "IV OTP salt for encrypting" + FULL_DOCS "IV OTP salt for encrypting" +) +define_property(TARGET + PROPERTY PICOTOOL_EMBED_DECRYPTION + INHERITED + BRIEF_DOCS "Embed decryption stage into encrypted binary" + FULL_DOCS "Embed decryption stage into encrypted binary" +) +define_property(TARGET + PROPERTY PICOTOOL_USE_MBEDTLS_DECRYPTION + INHERITED + BRIEF_DOCS "Use MbedTLS based decryption stage - this is faster, but not secure against power snooping" + FULL_DOCS "Use MbedTLS based decryption stage - this is faster, but not secure against power snooping" +) +define_property(TARGET + PROPERTY PICOTOOL_OTP_KEY_PAGE + INHERITED + BRIEF_DOCS "OTP page storing the AES key" + FULL_DOCS "OTP page storing the AES key" +) define_property(TARGET PROPERTY PICOTOOL_ENC_SIGFILE INHERITED @@ -428,25 +452,78 @@ function(pico_embed_pt_in_binary TARGET PTFILE) ) endfunction() -# pico_encrypt_binary(TARGET AESFILE [SIGFILE]) +# pico_encrypt_binary(TARGET AESFILE IVFILE [SIGFILE ] [EMBED] [MBEDTLS] [OTP_KEY_PAGE ]) # \brief_nodesc\ Encrypt the taget binary # # Encrypt the target binary with the given AES key (should be a binary -# file containing 32 bytes of a random key), and sign the encrypted binary. +# file containing 128 bytes of a random key share, or 32 bytes of a random key), +# and sign the encrypted binary. +# +# Salts the public IV with the provided IVFILE (should be a binary file +# containing 16 bytes of a random IV), to give the IV used by the encryption. +# +# This sets the target properties PICOTOOL_AESFILE to AESFILE, PICOTOOL_IVFILE to IVFILE, and +# PICOTOOL_ENC_SIGFILE to SIGFILE if specified, else PICOTOOL_SIGFILE. +# +# Optionally, use EMBED to embed a decryption stage into the encrypted binary. +# This sets the target property PICOTOOL_EMBED_DECRYPTION to TRUE. +# +# Optionally, use MBEDTLS to to use the MbedTLS based decryption stage - this +# is faster, but offers no security against power or timing sniffing attacks, +# and takes up more code size. +# This sets the target property PICOTOOL_USE_MBEDTLS_DECRYPTION to TRUE. # -# This sets the target properties PICOTOOL_AESFILE to AESFILE, -# and PICOTOOL_ENC_SIGFILE to SIGFILE if present, else PICOTOOL_SIGFILE. +# Optionally, use OTP_KEY_PAGE to specify the OTP page storing the AES key. +# This sets the target property PICOTOOL_OTP_KEY_PAGE to OTP_KEY_PAGE. # # \param\ AESFILE The AES key file to use +# \param\ IVFILE The IV file to use # \param\ SIGFILE The PEM signature file to use -function(pico_encrypt_binary TARGET AESFILE) +# \param\ EMBED Embed a decryption stage into the encrypted binary +# \param\ MBEDTLS Use MbedTLS based decryption stage (faster, but less secure) +# \param\ OTP_KEY_PAGE The OTP page storing the AES key +function(pico_encrypt_binary TARGET AESFILE IVFILE) + set(options EMBED MBEDTLS) + set(oneValueArgs OTP_KEY_PAGE SIGFILE) + # set(multiValueArgs ) + cmake_parse_arguments(PARSE_ARGV 3 ENC "${options}" "${oneValueArgs}" "${multiValueArgs}") picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES PICOTOOL_AESFILE ${AESFILE} ) - if (ARGC EQUAL 3) + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_IVFILE ${IVFILE} + ) + + if (ENC_EMBED) set_target_properties(${TARGET} PROPERTIES - PICOTOOL_ENC_SIGFILE ${ARGV2} + PICOTOOL_EMBED_DECRYPTION TRUE + ) + + # Embedded decryption stage only works with packaged binaries + get_target_property(uf2_package_addr ${TARGET} PICOTOOL_UF2_PACKAGE_ADDR) + if (NOT uf2_package_addr) + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_UF2_PACKAGE_ADDR 0x10000000 + ) + endif() + endif() + + if (ENC_MBEDTLS) + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_USE_MBEDTLS_DECRYPTION TRUE + ) + endif() + + if (ENC_OTP_KEY_PAGE) + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_OTP_KEY_PAGE ${ENC_OTP_KEY_PAGE} + ) + endif() + + if (ENC_SIGFILE) + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_ENC_SIGFILE ${ENC_SIGFILE} ) else() get_target_property(enc_sig_file ${TARGET} PICOTOOL_ENC_SIGFILE) @@ -563,6 +640,10 @@ function(picotool_postprocess_binary TARGET) if (picotool_aesfile) pico_add_link_depend(${TARGET} ${picotool_aesfile}) endif() + get_target_property(picotool_ivfile ${TARGET} PICOTOOL_IVFILE) + if (picotool_ivfile) + pico_add_link_depend(${TARGET} ${picotool_ivfile}) + endif() get_target_property(picotool_enc_sigfile ${TARGET} PICOTOOL_ENC_SIGFILE) if (picotool_enc_sigfile) pico_add_link_depend(${TARGET} ${picotool_enc_sigfile}) @@ -602,10 +683,31 @@ function(picotool_postprocess_binary TARGET) VERBATIM) endif() # Encryption - if (picotool_aesfile) + if (picotool_aesfile AND picotool_ivfile) + get_target_property(picotool_embed_decryption ${TARGET} PICOTOOL_EMBED_DECRYPTION) + if (picotool_embed_decryption) + list(APPEND picotool_encrypt_args "--embed") + endif() + + get_target_property(picotool_mbedtls_decryption ${TARGET} PICOTOOL_USE_MBEDTLS_DECRYPTION) + if (picotool_mbedtls_decryption) + list(APPEND picotool_encrypt_args "--use-mbedtls") + endif() + + get_target_property(otp_key_page ${TARGET} PICOTOOL_OTP_KEY_PAGE) + if (otp_key_page) + list(APPEND picotool_encrypt_args "--otp-key-page" ${otp_key_page}) + endif() + add_custom_command(TARGET ${TARGET} POST_BUILD - DEPENDS ${picotool_enc_sigfile} ${picotool_aesfile} - COMMAND picotool encrypt --quiet --hash --sign $ $ ${picotool_aesfile} ${picotool_enc_sigfile} + DEPENDS ${picotool_enc_sigfile} ${picotool_aesfile} ${picotool_ivfile} + COMMAND picotool + ARGS encrypt + --quiet --hash --sign + ${picotool_encrypt_args} + $ $ + ${picotool_aesfile} ${picotool_ivfile} ${picotool_enc_sigfile} ${otp_file} + COMMAND_EXPAND_LISTS VERBATIM) if (ARGC EQUAL 2) set(${ARGV1} TRUE PARENT_SCOPE) From 0722de395ccbe2165f6b8c2f20efd8d6cb759f97 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 29 May 2025 08:18:05 -0500 Subject: [PATCH 146/224] add new M33 processor exception handlers (#2482) --- .../cmsis/include/cmsis/rename_exceptions.h | 5 ++++ src/rp2_common/pico_crt0/crt0.S | 27 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/cmsis/include/cmsis/rename_exceptions.h b/src/rp2_common/cmsis/include/cmsis/rename_exceptions.h index 0db37f4ca..5ab49e824 100644 --- a/src/rp2_common/cmsis/include/cmsis/rename_exceptions.h +++ b/src/rp2_common/cmsis/include/cmsis/rename_exceptions.h @@ -52,7 +52,12 @@ #if PICO_RP2350 #define isr_nmi NMI_Handler #define isr_hardfault HardFault_Handler +#define isr_memmanage MemManage_Handler +#define isr_busfault BusFault_Handler +#define isr_usagefault UsageFault_Handler +#define isr_securefault SecureFault_Handler #define isr_svcall SVC_Handler +#define isr_debugmonitor DebugMon_Handler #define isr_pendsv PendSV_Handler #define isr_systick SysTick_Handler #define isr_irq0 TIMER0_IRQ_0_Handler diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index 3e6c692d8..43ce5ed34 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -52,15 +52,26 @@ __vectors: #else .word isr_nmi .word isr_hardfault +#if PICO_RP2040 .word isr_invalid // Reserved, should never fire .word isr_invalid // Reserved, should never fire .word isr_invalid // Reserved, should never fire .word isr_invalid // Reserved, should never fire +#else +.word isr_memmanage +.word isr_busfault +.word isr_usagefault +.word isr_securefault +#endif .word isr_invalid // Reserved, should never fire .word isr_invalid // Reserved, should never fire .word isr_invalid // Reserved, should never fire .word isr_svcall +#if PICO_RP2040 .word isr_invalid // Reserved, should never fire +#else +.word isr_debugmonitor +#endif .word isr_invalid // Reserved, should never fire .word isr_pendsv .word isr_systick @@ -287,8 +298,20 @@ if_irq_decl 79 isr_irq79 #if PICO_NUM_VTABLE_IRQS > 80 #error more IRQ entries required #endif +#if !PICO_RP2040 +// since these are disabled by default, map them all to __unhandled_user_irq (will have +// a negative number +decl_isr isr_memmanage +decl_isr isr_busfault +decl_isr isr_usagefault +decl_isr isr_securefault +decl_isr isr_debugmonitor +#endif -// All unhandled USER IRQs fall through to here +// All unhandled USER IRQs fall through to here. +// Additionally, if the Armv9-M MemManage/BusFault/UsageFault/SecureFault/DebugMonitor exceptions +// are enabled, but the handlers are not defined, then unhandled_user_irq_num_in_r0 will +// also be reached, but with a negative exception number (e.g. MemManage == -12) .global __unhandled_user_irq .thumb_func __unhandled_user_irq: @@ -305,7 +328,7 @@ unhandled_user_irq_num_in_r0: decl_isr_bkpt isr_invalid #if !PICO_MINIMAL_STORED_VECTOR_TABLE -// these are separated out for clarity +// these are separated out into individual BKPT instructions with label for clarity decl_isr_bkpt isr_nmi decl_isr_bkpt isr_hardfault decl_isr_bkpt isr_svcall From 67f89e44aac6b4ccc91043e2ac3a8aa4e261795d Mon Sep 17 00:00:00 2001 From: armandomontanez Date: Thu, 29 May 2025 06:25:46 -0700 Subject: [PATCH 147/224] Update Bazel pin, ignore build-* directories (#2461) Updates the Bazel pin to 8.1.0 so that build-* directories can be properly ignored. --- .bazelignore | 4 ---- .bazelrc | 4 ++++ .bazelversion | 2 +- REPO.bazel | 10 ++++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) delete mode 100644 .bazelignore create mode 100644 REPO.bazel diff --git a/.bazelignore b/.bazelignore deleted file mode 100644 index a086fff4b..000000000 --- a/.bazelignore +++ /dev/null @@ -1,4 +0,0 @@ -# Don't accidentally pick up external CMake deps with Bazel build files. -build -# Don't treat submodules as part of this project. -lib diff --git a/.bazelrc b/.bazelrc index 96b4eca24..8eae3bc20 100644 --- a/.bazelrc +++ b/.bazelrc @@ -4,3 +4,7 @@ common --host_per_file_copt=external/.*@-w # Produce useful output when the build fails. common --verbose_failures + +# Silence warnings about old bazel_dep pins. Bazel 8 brings along newer ones, +# but we can support Bazel 7 (for now). +common --check_direct_dependencies=off diff --git a/.bazelversion b/.bazelversion index b26a34e47..8104cabd3 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -7.2.1 +8.1.0 diff --git a/REPO.bazel b/REPO.bazel new file mode 100644 index 000000000..031d5dd9d --- /dev/null +++ b/REPO.bazel @@ -0,0 +1,10 @@ +ignore_directories( + [ + # Don't accidentally pick up external CMake deps with Bazel build files. + "cmake-*", + "build", + "build-*", + # Don't treat submodules as part of this project. + "lib", + ], +) From 6860f0d8821219bd450a3ae8f9e1a7dc7d099e47 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Fri, 30 May 2025 14:33:04 +0100 Subject: [PATCH 148/224] Call enable_interrupts when initialising IRQs (#2491) * Call enable_interrupts when initialising IRQs Fixes raspberrypi/pico-examples#584, supercedes raspberrypi/pico-examples#588 * move enable_interrupts to the end though it doesn't make much difference * guard enable_interrupts by !RP2040 as it isn't needed there --------- Co-authored-by: Graham Sanderson --- src/rp2_common/hardware_irq/irq.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rp2_common/hardware_irq/irq.c b/src/rp2_common/hardware_irq/irq.c index 9b6f5ecd1..fc3d6f12c 100644 --- a/src/rp2_common/hardware_irq/irq.c +++ b/src/rp2_common/hardware_irq/irq.c @@ -680,6 +680,10 @@ __weak void runtime_init_per_core_irq_priorities(void) { } #endif #endif +#if !PICO_RP2040 + // enable interrupts that might be disabled by a previous bootloader stage (guarded for RP2040 as there is no bootrom chain_image call there) + enable_interrupts(); +#endif } static uint get_user_irq_claim_index(uint irq_num) { From 6841d4d15be57a30e8e7265ee3b9cb101404b39f Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Fri, 30 May 2025 14:35:25 +0100 Subject: [PATCH 149/224] Remove DEPENDS argument from add_custom_command(TARGET functions (#2489) This raises a warning with recent CMake versions, and isn't required due to the `pico_add_link_depend` already added for these files Fixes raspberrypi/picotool#235 --- tools/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 1d98f0312..74745af4f 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -660,7 +660,6 @@ function(picotool_postprocess_binary TARGET) # Embed PT if (picotool_embed_pt) add_custom_command(TARGET ${TARGET} POST_BUILD - DEPENDS ${picotool_embed_pt} COMMAND picotool partition create --quiet ${picotool_embed_pt} $ $ VERBATIM) endif() @@ -672,7 +671,6 @@ function(picotool_postprocess_binary TARGET) extra_process_args ) add_custom_command(TARGET ${TARGET} POST_BUILD - DEPENDS ${picotool_sigfile} COMMAND picotool ARGS seal --quiet @@ -700,7 +698,6 @@ function(picotool_postprocess_binary TARGET) endif() add_custom_command(TARGET ${TARGET} POST_BUILD - DEPENDS ${picotool_enc_sigfile} ${picotool_aesfile} ${picotool_ivfile} COMMAND picotool ARGS encrypt --quiet --hash --sign From 1ae2f0e32ccf66a7ded2955c4edff8a826cc2f2b Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Fri, 30 May 2025 22:17:46 +0100 Subject: [PATCH 150/224] Don't include the picobin end block when sealing (#2492) * Don't include the picobin end block when signing, as picotool will add a new end block anyway * small whitespace fix --------- Co-authored-by: Graham Sanderson --- tools/CMakeLists.txt | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 74745af4f..9ec5a232c 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -664,21 +664,21 @@ function(picotool_postprocess_binary TARGET) VERBATIM) endif() # Signing/hashing/load maps for packaging - if ( - picotool_sign_output OR + if (picotool_sign_output OR picotool_hash_output OR uf2_package_addr OR - extra_process_args - ) - add_custom_command(TARGET ${TARGET} POST_BUILD - COMMAND picotool - ARGS seal - --quiet - $ $ - ${picotool_sigfile} ${otp_file} - ${picotool_args} - COMMAND_EXPAND_LISTS - VERBATIM) + extra_process_args) + # We don't need the extra end block, as picotool seal will add one + target_compile_definitions(${TARGET} PRIVATE PICO_CRT0_INCLUDE_PICOBIN_END_BLOCK=0) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND picotool + ARGS seal + --quiet + $ $ + ${picotool_sigfile} ${otp_file} + ${picotool_args} + COMMAND_EXPAND_LISTS + VERBATIM) endif() # Encryption if (picotool_aesfile AND picotool_ivfile) From a9146b65add0820e751699f8d7155a248c71571a Mon Sep 17 00:00:00 2001 From: Goran Miskovic Date: Tue, 3 Jun 2025 18:06:35 +0200 Subject: [PATCH 151/224] fix(async_context_threadsafe_background_execute_sync): prevent use-after-return by removing worker before semaphore release (#2494) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensures the async worker is unregistered from the context before releasing the blocking thread. This prevents the `sync_func_call_t` stack object from being accessed after it goes out of scope, avoiding a use-after-return condition in multicore `async_context_execute_sync()` scenarios. Fixes raspberrypi/pico-sdk#2433 Signed-off-by: Goran Mišković --- .../pico_async_context/async_context_threadsafe_background.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c index 730d8a5a7..bce8ae726 100644 --- a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c +++ b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c @@ -98,8 +98,8 @@ typedef struct sync_func_call{ static void handle_sync_func_call(async_context_t *context, async_when_pending_worker_t *worker) { sync_func_call_t *call = (sync_func_call_t *)worker; call->rc = call->func(call->param); - sem_release(&call->sem); async_context_remove_when_pending_worker(context, worker); + sem_release(&call->sem); } #endif From d7abd66dea32cd4a2b2602f24c67a7892e991bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20K=C3=BCthe?= Date: Mon, 9 Jun 2025 14:37:20 +0000 Subject: [PATCH 152/224] Fix typo (#2508) --- src/rp2_common/pico_stdio/include/pico/stdio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_stdio/include/pico/stdio.h b/src/rp2_common/pico_stdio/include/pico/stdio.h index 8f259d57a..b9a96805f 100644 --- a/src/rp2_common/pico_stdio/include/pico/stdio.h +++ b/src/rp2_common/pico_stdio/include/pico/stdio.h @@ -159,7 +159,7 @@ static inline int puts_raw(const char *s) { */ void stdio_set_chars_available_callback(void (*fn)(void*), void *param); -/*! \brief Waits until a timeout to reard at least one character into a buffer +/*! \brief Waits until a timeout to read at least one character into a buffer * \ingroup pico_stdio * * This method returns as soon as input is available, but more characters may From a1faacff07b9faa89915d4d7cc9f0262320165d8 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Tue, 10 Jun 2025 14:49:04 +0100 Subject: [PATCH 153/224] Remove reference to wafer_id (#2512) `wafer_id` is not correct, as it is a 64-bit `device_ID` instead of a separate `device_id` and `wafer_id` --- .../boot_bootrom_headers/include/boot/bootrom_constants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h index c1107f66b..7f891f7ee 100644 --- a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h +++ b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h @@ -230,7 +230,7 @@ typedef int (*bootrom_api_callback_generic_t)(uint32_t r0, uint32_t r1, uint32_t #define PT_INFO_PARTITION_NAME 0x0080 // items are returned in order -// 3 words package_id, device_id, wafer_id +// 3 words package_id, device_id_lo, device_id_hi #define SYS_INFO_CHIP_INFO 0x0001 // 1 word: chip specific critical bits #define SYS_INFO_CRITICAL 0x0002 From e6d18920c72b23e2a3465af60b56fe6bb6f50e95 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 12 Jun 2025 23:43:53 +0100 Subject: [PATCH 154/224] RP2040 and RP2350 have different maximum watchdog delays (#2500) --- .../hardware_watchdog/include/hardware/watchdog.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/hardware_watchdog/include/hardware/watchdog.h b/src/rp2_common/hardware_watchdog/include/hardware/watchdog.h index e6adf65af..7ebfa60cc 100644 --- a/src/rp2_common/hardware_watchdog/include/hardware/watchdog.h +++ b/src/rp2_common/hardware_watchdog/include/hardware/watchdog.h @@ -74,6 +74,13 @@ void watchdog_update(void); * \note If \ref watchdog_start_tick value does not give a 1MHz clock to the watchdog system, then the \p delay_ms * parameter will not be in milliseconds. See the datasheet for more details. * + * \if rp2040_specific + * On RP2040 the maximum delay is 8388 milliseconds, which is approximately 8.3 seconds (this is due to RP2040-E1). + * \endif + * \if rp2350_specific + * On RP2350 the maximum delay is 16777 milliseconds, which is approximately 16.7 seconds. + * \endif + * * By default the SDK assumes a 12MHz XOSC and sets the \ref watchdog_start_tick appropriately. * * This method sets a marker in the watchdog scratch register 4 that is checked by \ref watchdog_enable_caused_reboot. @@ -81,7 +88,7 @@ void watchdog_update(void); * onto the RPI-RP2), then this value will be cleared, and so \ref watchdog_enable_caused_reboot will * return false. * - * \param delay_ms Number of milliseconds before watchdog will reboot without watchdog_update being called. Maximum of 8388, which is approximately 8.3 seconds + * \param delay_ms Number of milliseconds before watchdog will reboot without watchdog_update being called * \param pause_on_debug If the watchdog should be paused when the debugger is stepping through code */ void watchdog_enable(uint32_t delay_ms, bool pause_on_debug); @@ -124,7 +131,7 @@ bool watchdog_enable_caused_reboot(void); * \brief Returns the number of microseconds before the watchdog will reboot the chip. * \ingroup hardware_watchdog * - * \if rp2040_specicifc + * \if rp2040_specific * On RP2040 this method returns the last value set instead of the remaining time due to a h/w bug. * \endif * From be549183e86e3947368e4a69031afc84375d73e9 Mon Sep 17 00:00:00 2001 From: Brad Nolan <34460782+NolanBrad@users.noreply.github.com> Date: Fri, 13 Jun 2025 10:45:44 +1200 Subject: [PATCH 155/224] Bazel build implementation, doesn't provide options for the compilation modes opt and debug (#2395) * Bazel add default compliation args for opt and debug. Can be overriden * Add docstrings for new compilation mode override flags * Remove cc_args_list shims, which arent needed anymore for cc_feature * Add Compilation mode overrides to the BAZEL_ONLY_ALLOWLIST, these dont exist in Cmake * For completness add the fastbuild default options, and override flag * Remove the default options for fastbuiild, as the bazel doc defaults didnt make much sense, nor work. Leaving these for completness and future addition * Rename the config and constraint labels from OVERRIDE to REMOVE_DEFS * Change naming of flags from PICO_COMPILATION_XXX_REMOVE_DEFS to PICO_COMPILATION_NO_XXX_ARGS for OPT, FASTBUILD & DEBUG variants * Fixup spellling mistakes, and comments * Fix typo PICO_COMPILATION_NO_FASBUILD_ARGS to FASTBUILD --- bazel/config/BUILD.bazel | 18 +++++++++ bazel/constraint/BUILD.bazel | 15 ++++++++ bazel/toolchain/BUILD.bazel | 70 ++++++++++++++++++++++++++-------- tools/compare_build_systems.py | 4 ++ 4 files changed, 92 insertions(+), 15 deletions(-) diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index ac6dc387a..b27cbdd54 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -300,3 +300,21 @@ label_flag( name = "PICO_MBEDTLS_CONFIG", build_setting_default = "//bazel:empty_cc_lib", ) + +# PICO_BAZEL_CONFIG: PICO_COMPILATION_NO_OPT_ARGS, Makes the opt compilation mode a no-op so custom optimization arguments can be injected via the --copt flag instead, type=bool, default=0, group=build +bool_flag( + name = "PICO_COMPILATION_NO_OPT_ARGS", + build_setting_default = False, +) + +# PICO_BAZEL_CONFIG: PICO_COMPILATION_NO_DEBUG_ARGS, Makes the debug compilation mode a no-op so custom debug arguments can be injected via the --copt flag instead, type=bool, default=0, group=build +bool_flag( + name = "PICO_COMPILATION_NO_DEBUG_ARGS", + build_setting_default = False, +) + +# PICO_BAZEL_CONFIG: PICO_COMPILATION_NO_FASTBUILD_ARGS, Makes the fastbuild compilation mode a no-op so custom fastbuild arguments can be injected via the --copt flag instead, type=bool, default=0, group=build +bool_flag( + name = "PICO_COMPILATION_NO_FASTBUILD_ARGS", + build_setting_default = False, +) diff --git a/bazel/constraint/BUILD.bazel b/bazel/constraint/BUILD.bazel index 3ce282065..acd112469 100644 --- a/bazel/constraint/BUILD.bazel +++ b/bazel/constraint/BUILD.bazel @@ -258,3 +258,18 @@ label_flag_matches( flag = "//bazel/config:PICO_MBEDTLS_CONFIG", value = "//bazel:empty_cc_lib", ) + +config_setting( + name = "pico_compilation_no_opt_args_set", + flag_values = {"//bazel/config:PICO_COMPILATION_NO_OPT_ARGS": "True"}, +) + +config_setting( + name = "pico_compilation_no_debug_args_set", + flag_values = {"//bazel/config:PICO_COMPILATION_NO_DEBUG_ARGS": "True"}, +) + +config_setting( + name = "pico_compilation_no_fastbuild_args_set", + flag_values = {"//bazel/config:PICO_COMPILATION_NO_FASTBUILD_ARGS": "True"}, +) diff --git a/bazel/toolchain/BUILD.bazel b/bazel/toolchain/BUILD.bazel index ba8d947ca..dacd35389 100644 --- a/bazel/toolchain/BUILD.bazel +++ b/bazel/toolchain/BUILD.bazel @@ -89,15 +89,46 @@ cc_args( ) cc_args( - name = "opt_debug_args", + name = "debug_args", actions = [ "@rules_cc//cc/toolchains/actions:compile_actions", "@rules_cc//cc/toolchains/actions:link_actions", ], - args = [ - "-Og", # TODO: Make this configurable. - "-g3", + args = select({ + "//bazel/constraint:pico_compilation_no_debug_args_set": [], + "//conditions:default": [ + "-Og", + "-g3", + ], + }) +) + +cc_args( + name = "opt_args", + actions = [ + "@rules_cc//cc/toolchains/actions:compile_actions", + "@rules_cc//cc/toolchains/actions:link_actions", + ], + args = select({ + "//bazel/constraint:pico_compilation_no_opt_args_set": [], + "//conditions:default": [ + "-O2", + "-DNDEBUG", + ], + }) +) + +cc_args( + name = "fastbuild_args", + actions = [ + "@rules_cc//cc/toolchains/actions:compile_actions", + "@rules_cc//cc/toolchains/actions:link_actions", ], + args = select({ + "//bazel/constraint:pico_compilation_no_fastbuild_args_set": [], + # The conditions default are kept as nothing here, The bazel docs default are -gmlt -Wl,-S. + "//conditions:default": [], + }) ) configurable_toolchain_feature( @@ -132,18 +163,25 @@ configurable_toolchain_feature( linkopts = ["-Wl,-z,max-page-size=4096"], ) -# TODO: Make this shim unnecessary. -cc_args_list( - name = "all_opt_debug_args", - args = [":opt_debug_args"], -) cc_feature( - name = "override_debug", - args = [":all_opt_debug_args"], + name = "dbg", + args = [":debug_args"], overrides = "@rules_cc//cc/toolchains/features:dbg", ) +cc_feature( + name = "opt", + args = [":opt_args"], + overrides = "@rules_cc//cc/toolchains/features:opt", +) + +cc_feature( + name = "fastbuild", + args = [":fastbuild_args"], + overrides = "@rules_cc//cc/toolchains/features:fastbuild", +) + HOSTS = ( ("linux", "x86_64"), ("linux", "aarch64"), @@ -180,7 +218,9 @@ _HOST_CPU_CONSTRAINTS = { tags = ["manual"], # Don't try to build this in wildcard builds. known_features = [ "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features", - "@pico-sdk//bazel/toolchain:override_debug", + "@pico-sdk//bazel/toolchain:dbg", + "@pico-sdk//bazel/toolchain:opt", + "@pico-sdk//bazel/toolchain:fastbuild", "@pico-sdk//bazel/toolchain:gc_sections", "@pico-sdk//bazel/toolchain:cxx_no_exceptions", "@pico-sdk//bazel/toolchain:cxx_no_rtti", @@ -189,7 +229,6 @@ _HOST_CPU_CONSTRAINTS = { ], enabled_features = [ "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features", - "@pico-sdk//bazel/toolchain:override_debug", ] + select({ "//bazel/constraint:pico_no_gc_sections_enabled": [], "//conditions:default": [":gc_sections"], @@ -232,7 +271,9 @@ _HOST_CPU_CONSTRAINTS = { tags = ["manual"], # Don't try to build this in wildcard builds. known_features = [ "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features", - "@pico-sdk//bazel/toolchain:override_debug", + "@pico-sdk//bazel/toolchain:dbg", + "@pico-sdk//bazel/toolchain:opt", + "@pico-sdk//bazel/toolchain:fastbuild", "@pico-sdk//bazel/toolchain:gc_sections", "@pico-sdk//bazel/toolchain:cxx_no_exceptions", "@pico-sdk//bazel/toolchain:cxx_no_rtti", @@ -241,7 +282,6 @@ _HOST_CPU_CONSTRAINTS = { ], enabled_features = [ "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features", - "@pico-sdk//bazel/toolchain:override_debug", ] + select({ "//bazel/constraint:pico_no_gc_sections_enabled": [], "//conditions:default": [":gc_sections"], diff --git a/tools/compare_build_systems.py b/tools/compare_build_systems.py index 86dc615a1..583e51838 100755 --- a/tools/compare_build_systems.py +++ b/tools/compare_build_systems.py @@ -158,6 +158,10 @@ "PICO_BT_ENABLE_BLE", "PICO_BT_ENABLE_CLASSIC", "PICO_BT_ENABLE_MESH", + # Compilation modes remove, These allow the user to remove the defaults, with no args. See --compilation_mode cmd line option + "PICO_COMPILATION_NO_OPT_ARGS", + "PICO_COMPILATION_NO_DEBUG_ARGS", + "PICO_COMPILATION_NO_FASTBUILD_ARGS", ) From a9851a157763f2ff9668b99a852c05122eb6437c Mon Sep 17 00:00:00 2001 From: Mark Hermeling Date: Mon, 16 Jun 2025 18:46:08 -0400 Subject: [PATCH 156/224] remove unnecessary escaping (#2526) * remove unnecessary escaping * Removed one too many \ * I removed 2 necessary \ --- cmake/generic_board.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/generic_board.cmake b/cmake/generic_board.cmake index 9dd917d50..85f59780a 100644 --- a/cmake/generic_board.cmake +++ b/cmake/generic_board.cmake @@ -21,10 +21,10 @@ if (EXISTS ${PICO_BOARD_HEADER_FILE}) while(HEADER_FILE_CONTENTS) list(POP_FRONT HEADER_FILE_CONTENTS LINE) # pico_board_cmake_set(var, value) - if (LINE MATCHES "^[ \t\]*pico_board_cmake_set[ \t\]*\\([ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*,[ \t\]*(.*)[ \t\]*\\)[ \t\]*") + if (LINE MATCHES "^[ \t]*pico_board_cmake_set[ \t]*\\([ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*,[ \t]*(.*)[ \t]*\\)[ \t]*") set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") # pico_board_cmake_set_default(var, value) - elseif (LINE MATCHES "^[ \t\]*pico_board_cmake_set_default[ \t\]*\\([ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*,[ \t\]*(.*)[ \t\]*\\)[ \t\]*") + elseif (LINE MATCHES "^[ \t]*pico_board_cmake_set_default[ \t]*\\([ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*,[ \t]*(.*)[ \t]*\\)[ \t]*") if (NOT DEFINED "${CMAKE_MATCH_1}") set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") else() @@ -32,10 +32,10 @@ if (EXISTS ${PICO_BOARD_HEADER_FILE}) endif() # continue to support these for now # // pico_cmake_set var = value - elseif (LINE MATCHES "^[ \t\]*//[ \t\]*pico_cmake_set[ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*=[ \t\]*(.*)") + elseif (LINE MATCHES "^[ \t]*//[ \t]*pico_cmake_set[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)") set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") # // pico_cmake_set_default var = value - elseif (LINE MATCHES "^[ \t\]*//[ \t\]*pico_cmake_set_default[ \t\]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t\]*=[ \t\]*(.*)") + elseif (LINE MATCHES "^[ \t]*//[ \t]*pico_cmake_set_default[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)") if (NOT DEFINED "${CMAKE_MATCH_1}") set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") else() From a7ec8c3f79c2d0a2f749c8da52c56411d8f4c76f Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 18 Jun 2025 14:34:48 +0100 Subject: [PATCH 157/224] Fix the "type" of SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US (#2531) It's int, not bool --- src/rp2_common/hardware_clocks/include/hardware/clocks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_clocks/include/hardware/clocks.h b/src/rp2_common/hardware_clocks/include/hardware/clocks.h index 68f4b1a50..ee8e95535 100644 --- a/src/rp2_common/hardware_clocks/include/hardware/clocks.h +++ b/src/rp2_common/hardware_clocks/include/hardware/clocks.h @@ -231,7 +231,7 @@ extern "C" { #endif #endif // PICO_RP2040 && SYS_CLK_KHZ == 200000 && XOSC_KHZ == 12000 && PLL_COMMON_REFDIV == 1 -// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US, Number of microseconds to wait after updating regulator voltage due to SYS_CLK_VREG_VOLTAGE_MIN to allow voltage to settle, type=bool, default=1000, advanced=true, group=hardware_clocks +// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US, Number of microseconds to wait after updating regulator voltage due to SYS_CLK_VREG_VOLTAGE_MIN to allow voltage to settle, type=int, default=1000, advanced=true, group=hardware_clocks #ifndef SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US #define SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US 1000 #endif From 287196517bbde54f9b3dc6b35417f675049badb0 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Wed, 18 Jun 2025 16:18:25 +0100 Subject: [PATCH 158/224] Add config check action (#2525) * Add action to check configs & defines * Check for all errors before exiting scripts * Add extract_cmake_functions to the checks * Fix invalid escape sequence warning --- .github/workflows/check_configs.yml | 33 +++++++++++++++++ tools/extract_build_defines.py | 50 ++++++++++++++++--------- tools/extract_cmake_configs.py | 51 ++++++++++++++++---------- tools/extract_cmake_functions.py | 29 +++++++++++---- tools/extract_configs.py | 57 ++++++++++++++++++----------- 5 files changed, 153 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/check_configs.yml diff --git a/.github/workflows/check_configs.yml b/.github/workflows/check_configs.yml new file mode 100644 index 000000000..0d034d308 --- /dev/null +++ b/.github/workflows/check_configs.yml @@ -0,0 +1,33 @@ +name: Check Configs + +on: + push: + pull_request: + +jobs: + check-configs: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check Build Defines + if: always() + run: | + tools/extract_build_defines.py . + + - name: Check CMake Configs + if: always() + run: | + tools/extract_cmake_configs.py . + + - name: Check CMake Functions + if: always() + run: | + tools/extract_cmake_functions.py . + + - name: Check Configs + if: always() + run: | + tools/extract_configs.py . diff --git a/tools/extract_build_defines.py b/tools/extract_build_defines.py index 179f084ec..69181cf88 100755 --- a/tools/extract_build_defines.py +++ b/tools/extract_build_defines.py @@ -24,6 +24,13 @@ from collections import defaultdict +if sys.version_info < (3, 11): + # Python <3.11 doesn't have ExceptionGroup, so define a simple one + class ExceptionGroup(Exception): + def __init__(self, message, errors): + message += "\n" + "\n".join(e.__str__() for e in errors) + super().__init__(message) + logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) @@ -51,11 +58,12 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): _type = config_attrs.get('type') + errors = [] # Validate attrs for key in config_attrs.keys(): if key not in ALLOWED_CONFIG_PROPERTIES: - raise Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key)) + errors.append(Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key))) if _type == 'int': _min = _max = _default = None @@ -86,13 +94,13 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): pass if _min is not None and _max is not None: if _min > _max: - raise Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max'])) + errors.append(Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max']))) if _min is not None and _default is not None: if _min > _default: - raise Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default'])) + errors.append(Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default']))) if _default is not None and _max is not None: if _default > _max: - raise Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max'])) + errors.append(Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max']))) elif _type == 'bool': assert 'min' not in config_attrs assert 'max' not in config_attrs @@ -111,10 +119,12 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): assert 'max' not in config_attrs _default = config_attrs.get('default', None) else: - raise Exception("Found unknown {} type {} at {}:{}".format(BASE_BUILD_DEFINE_NAME, _type, file_path, linenum)) - + errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_BUILD_DEFINE_NAME, _type, file_path, linenum))) + + return errors +errors = [] # Scan all CMakeLists.txt and .cmake files in the specific path, recursively. @@ -135,14 +145,14 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): linenum += 1 line = line.strip() if BASE_CONFIG_RE.search(line): - raise Exception("Found {} at {}:{} ({}) which isn't expected in {} files".format(BASE_CONFIG_NAME, file_path, linenum, line, filename if filename == 'CMakeLists.txt' else file_ext)) + errors.append(Exception("Found {} at {}:{} ({}) which isn't expected in {} files".format(BASE_CONFIG_NAME, file_path, linenum, line, filename if filename == 'CMakeLists.txt' else file_ext))) elif BASE_BUILD_DEFINE_RE.search(line): m = BUILD_DEFINE_RE.match(line) if not m: if re.match(r"^\s*#\s*# ", line): logger.info("Possible misformatted {} at {}:{} ({})".format(BASE_BUILD_DEFINE_NAME, file_path, linenum, line)) else: - raise Exception("Found misformatted {} at {}:{} ({})".format(BASE_BUILD_DEFINE_NAME, file_path, linenum, line)) + errors.append(Exception("Found misformatted {} at {}:{} ({})".format(BASE_BUILD_DEFINE_NAME, file_path, linenum, line))) else: config_name = m.group(1) config_description = m.group(2) @@ -151,10 +161,10 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): _attrs = re.sub(r'(\(.+\))', lambda m: m.group(1).replace(',', '\0'), _attrs) if '=' in config_description: - raise Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description)) + errors.append(Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description))) all_descriptions = chips_all_descriptions[applicable] if config_description in all_descriptions: - raise Exception("Found description {} at {}:{} but it was already used at {}:{}".format(config_description, file_path, linenum, os.path.join(scandir, all_descriptions[config_description]['filename']), all_descriptions[config_description]['line_number'])) + errors.append(Exception("Found description {} at {}:{} but it was already used at {}:{}".format(config_description, file_path, linenum, os.path.join(scandir, all_descriptions[config_description]['filename']), all_descriptions[config_description]['line_number']))) else: all_descriptions[config_description] = {'config_name': config_name, 'filename': os.path.relpath(file_path, scandir), 'line_number': linenum} @@ -168,19 +178,19 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): try: k, v = (i.strip() for i in item.split('=')) except ValueError: - raise Exception('{} at {}:{} has malformed value {}'.format(config_name, file_path, linenum, item)) + errors.append(Exception('{} at {}:{} has malformed value {}'.format(config_name, file_path, linenum, item))) config_attrs[k] = v.replace('\0', ',') all_attrs.add(k) prev = item #print(file_path, config_name, config_attrs) if 'group' not in config_attrs: - raise Exception('{} at {}:{} has no group attribute'.format(config_name, file_path, linenum)) + errors.append(Exception('{} at {}:{} has no group attribute'.format(config_name, file_path, linenum))) #print(file_path, config_name, config_attrs) all_configs = chips_all_configs[applicable] if config_name in all_configs: - raise Exception("Found {} at {}:{} but it was already declared at {}:{}".format(config_name, file_path, linenum, os.path.join(scandir, all_configs[config_name]['filename']), all_configs[config_name]['line_number'])) + errors.append(Exception("Found {} at {}:{} but it was already declared at {}:{}".format(config_name, file_path, linenum, os.path.join(scandir, all_configs[config_name]['filename']), all_configs[config_name]['line_number']))) else: all_configs[config_name] = {'attrs': config_attrs, 'filename': os.path.relpath(file_path, scandir), 'line_number': linenum, 'description': config_description} @@ -194,14 +204,14 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): file_path = os.path.join(scandir, config_obj['filename']) linenum = config_obj['line_number'] - ValidateAttrs(config_name, config_obj['attrs'], file_path, linenum) + errors.extend(ValidateAttrs(config_name, config_obj['attrs'], file_path, linenum)) # All settings in "host" should also be in "all" for config_name, config_obj in chips_all_configs["host"].items(): if config_name not in chips_all_configs["all"]: file_path = os.path.join(scandir, config_obj['filename']) linenum = config_obj['line_number'] - raise Exception("Found 'host' config {} at {}:{}, but no matching non-host config found".format(config_name, file_path, linenum)) + errors.append(Exception("Found 'host' config {} at {}:{}, but no matching non-host config found".format(config_name, file_path, linenum))) # Any chip-specific settings should not be in "all" for chip in CHIP_NAMES: @@ -212,7 +222,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): chip_linenum = chip_config_obj['line_number'] all_file_path = os.path.join(scandir, all_config_obj['filename']) all_linenum = all_config_obj['line_number'] - raise Exception("'{}' config {} at {}:{} also found at {}:{}".format(chip, config_name, chip_file_path, chip_linenum, all_file_path, all_linenum)) + errors.append(Exception("'{}' config {} at {}:{} also found at {}:{}".format(chip, config_name, chip_file_path, chip_linenum, all_file_path, all_linenum))) def build_mismatch_exception_message(name, thing, config_obj1, value1, config_obj2, value2): obj1_filepath = os.path.join(scandir, config_obj1['filename']) @@ -232,14 +242,18 @@ def build_mismatch_exception_message(name, thing, config_obj1, value1, config_ob applicable_value = applicable_config_obj[field] other_value = other_config_obj[field] if applicable_value != other_value: - raise Exception(build_mismatch_exception_message(config_name, field, applicable_config_obj, applicable_value, other_config_obj, other_value)) + errors.append(Exception(build_mismatch_exception_message(config_name, field, applicable_config_obj, applicable_value, other_config_obj, other_value))) # Check that attributes match for attr in applicable_config_obj['attrs']: if attr != 'default': # totally fine for defaults to vary per-platform applicable_value = applicable_config_obj['attrs'][attr] other_value = other_config_obj['attrs'][attr] if applicable_value != other_value: - raise Exception(build_mismatch_exception_message(config_name, "attribute '{}'".format(attr), applicable_config_obj, applicable_value, other_config_obj, other_value)) + errors.append(Exception(build_mismatch_exception_message(config_name, "attribute '{}'".format(attr), applicable_config_obj, applicable_value, other_config_obj, other_value))) + +# Raise errors if any were found +if errors: + raise ExceptionGroup("Errors in {}".format(outfile), errors) # Sort the output alphabetically by name and then by chip output_rows = set() diff --git a/tools/extract_cmake_configs.py b/tools/extract_cmake_configs.py index 18884330f..6bd5c9b0e 100755 --- a/tools/extract_cmake_configs.py +++ b/tools/extract_cmake_configs.py @@ -24,6 +24,13 @@ from collections import defaultdict +if sys.version_info < (3, 11): + # Python <3.11 doesn't have ExceptionGroup, so define a simple one + class ExceptionGroup(Exception): + def __init__(self, message, errors): + message += "\n" + "\n".join(e.__str__() for e in errors) + super().__init__(message) + logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) @@ -51,11 +58,12 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): _type = config_attrs.get('type') + errors = [] # Validate attrs for key in config_attrs.keys(): if key not in ALLOWED_CONFIG_PROPERTIES: - raise Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key)) + errors.append(Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key))) if _type == 'int': _min = _max = _default = None @@ -86,13 +94,13 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): pass if _min is not None and _max is not None: if _min > _max: - raise Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max'])) + errors.append(Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max']))) if _min is not None and _default is not None: if _min > _default: - raise Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default'])) + errors.append(Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default']))) if _default is not None and _max is not None: if _default > _max: - raise Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max'])) + errors.append(Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max']))) elif _type == 'bool': assert 'min' not in config_attrs assert 'max' not in config_attrs @@ -111,10 +119,11 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): assert 'max' not in config_attrs _default = config_attrs.get('default', None) else: - raise Exception("Found unknown {} type {} at {}:{}".format(BASE_CMAKE_CONFIG_NAME, _type, file_path, linenum)) - + errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_CMAKE_CONFIG_NAME, _type, file_path, linenum))) + return errors +errors = [] # Scan all CMakeLists.txt and .cmake files in the specific path, recursively. @@ -135,14 +144,14 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): linenum += 1 line = line.strip() if BASE_CONFIG_RE.search(line): - raise Exception("Found {} at {}:{} ({}) which isn't expected in {} files".format(BASE_CONFIG_NAME, file_path, linenum, line, filename if filename == 'CMakeLists.txt' else file_ext)) + errors.append(Exception("Found {} at {}:{} ({}) which isn't expected in {} files".format(BASE_CONFIG_NAME, file_path, linenum, line, filename if filename == 'CMakeLists.txt' else file_ext))) elif BASE_CMAKE_CONFIG_RE.search(line): m = CMAKE_CONFIG_RE.match(line) if not m: - if re.match("^\s*#\s*# ", line): + if re.match(r"^\s*#\s*# ", line): logger.info("Possible misformatted {} at {}:{} ({})".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line)) else: - raise Exception("Found misformatted {} at {}:{} ({})".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line)) + errors.append(Exception("Found misformatted {} at {}:{} ({})".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line))) else: config_name = m.group(1) config_description = m.group(2) @@ -151,10 +160,10 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): _attrs = re.sub(r'(\(.+\))', lambda m: m.group(1).replace(',', '\0'), _attrs) if '=' in config_description: - raise Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description)) + errors.append(Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description))) all_descriptions = chips_all_descriptions[applicable] if config_description in all_descriptions: - raise Exception("Found description {} at {}:{} but it was already used at {}:{}".format(config_description, file_path, linenum, os.path.join(scandir, all_descriptions[config_description]['filename']), all_descriptions[config_description]['line_number'])) + errors.append(Exception("Found description {} at {}:{} but it was already used at {}:{}".format(config_description, file_path, linenum, os.path.join(scandir, all_descriptions[config_description]['filename']), all_descriptions[config_description]['line_number']))) else: all_descriptions[config_description] = {'config_name': config_name, 'filename': os.path.relpath(file_path, scandir), 'line_number': linenum} @@ -168,19 +177,19 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): try: k, v = (i.strip() for i in item.split('=')) except ValueError: - raise Exception('{} at {}:{} has malformed value {}'.format(config_name, file_path, linenum, item)) + errors.append(Exception('{} at {}:{} has malformed value {}'.format(config_name, file_path, linenum, item))) config_attrs[k] = v.replace('\0', ',') all_attrs.add(k) prev = item #print(file_path, config_name, config_attrs) if 'group' not in config_attrs: - raise Exception('{} at {}:{} has no group attribute'.format(config_name, file_path, linenum)) + errors.append(Exception('{} at {}:{} has no group attribute'.format(config_name, file_path, linenum))) #print(file_path, config_name, config_attrs) all_configs = chips_all_configs[applicable] if config_name in all_configs: - raise Exception("Found {} at {}:{} but it was already declared at {}:{}".format(config_name, file_path, linenum, os.path.join(scandir, all_configs[config_name]['filename']), all_configs[config_name]['line_number'])) + errors.append(Exception("Found {} at {}:{} but it was already declared at {}:{}".format(config_name, file_path, linenum, os.path.join(scandir, all_configs[config_name]['filename']), all_configs[config_name]['line_number']))) else: all_configs[config_name] = {'attrs': config_attrs, 'filename': os.path.relpath(file_path, scandir), 'line_number': linenum, 'description': config_description} @@ -194,14 +203,14 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): file_path = os.path.join(scandir, config_obj['filename']) linenum = config_obj['line_number'] - ValidateAttrs(config_name, config_obj['attrs'], file_path, linenum) + errors.extend(ValidateAttrs(config_name, config_obj['attrs'], file_path, linenum)) # All settings in "host" should also be in "all" for config_name, config_obj in chips_all_configs["host"].items(): if config_name not in chips_all_configs["all"]: file_path = os.path.join(scandir, config_obj['filename']) linenum = config_obj['line_number'] - raise Exception("Found 'host' config {} at {}:{}, but no matching non-host config found".format(config_name, file_path, linenum)) + errors.append(Exception("Found 'host' config {} at {}:{}, but no matching non-host config found".format(config_name, file_path, linenum))) # Any chip-specific settings should not be in "all" for chip in CHIP_NAMES: @@ -212,7 +221,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): chip_linenum = chip_config_obj['line_number'] all_file_path = os.path.join(scandir, all_config_obj['filename']) all_linenum = all_config_obj['line_number'] - raise Exception("'{}' config {} at {}:{} also found at {}:{}".format(chip, config_name, chip_file_path, chip_linenum, all_file_path, all_linenum)) + errors.append(Exception("'{}' config {} at {}:{} also found at {}:{}".format(chip, config_name, chip_file_path, chip_linenum, all_file_path, all_linenum))) def build_mismatch_exception_message(name, thing, config_obj1, value1, config_obj2, value2): obj1_filepath = os.path.join(scandir, config_obj1['filename']) @@ -232,14 +241,18 @@ def build_mismatch_exception_message(name, thing, config_obj1, value1, config_ob applicable_value = applicable_config_obj[field] other_value = other_config_obj[field] if applicable_value != other_value: - raise Exception(build_mismatch_exception_message(config_name, field, applicable_config_obj, applicable_value, other_config_obj, other_value)) + errors.append(Exception(build_mismatch_exception_message(config_name, field, applicable_config_obj, applicable_value, other_config_obj, other_value))) # Check that attributes match for attr in applicable_config_obj['attrs']: if attr != 'default': # totally fine for defaults to vary per-platform applicable_value = applicable_config_obj['attrs'][attr] other_value = other_config_obj['attrs'][attr] if applicable_value != other_value: - raise Exception(build_mismatch_exception_message(config_name, "attribute '{}'".format(attr), applicable_config_obj, applicable_value, other_config_obj, other_value)) + errors.append(Exception(build_mismatch_exception_message(config_name, "attribute '{}'".format(attr), applicable_config_obj, applicable_value, other_config_obj, other_value))) + +# Raise errors if any were found +if errors: + raise ExceptionGroup("Errors in {}".format(outfile), errors) # Sort the output alphabetically by name and then by chip output_rows = set() diff --git a/tools/extract_cmake_functions.py b/tools/extract_cmake_functions.py index bc0b03ede..94dac8d62 100755 --- a/tools/extract_cmake_functions.py +++ b/tools/extract_cmake_functions.py @@ -22,6 +22,13 @@ import csv import logging +if sys.version_info < (3, 11): + # Python <3.11 doesn't have ExceptionGroup, so define a simple one + class ExceptionGroup(Exception): + def __init__(self, message, errors): + message += "\n" + "\n".join(e.__str__() for e in errors) + super().__init__(message) + logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) @@ -95,6 +102,7 @@ def process_commands(description, name, group, signature): brief = '' params = [] desc = '' + errors = [] for line in description.split('\n'): line = line.strip() if line.startswith('\\'): @@ -114,29 +122,29 @@ def process_commands(description, name, group, signature): # Group name override group = remainder else: - logger.error("{}:{} has unknown command: {}".format(group, name, command)) + errors.append(Exception("{}:{} has unknown command: {}".format(group, name, command))) elif '\\' in line: - logger.error("{}:{} has a line containing '\\': {}".format(group, name, line)) + errors.append(Exception("{}:{} has a line containing '\\': {}".format(group, name, line))) else: desc += line + '\\n' # Check that there are no semicolons in the parameter descriptions, as that's the delimiter for the parameter list if any([';' in x for x in params]): - logger.error("{}:{} has a parameter description containing ';'".format(group, name)) + errors.append(Exception("{}:{} has a parameter description containing ';'".format(group, name))) # Check that all parameters are in the signature - signature_words = set(re.split('\W+', signature)) + signature_words = set(re.split(r'\W+', signature)) for param in params: param_name = param.split(' ', maxsplit=1)[0] if param_name not in signature_words: - logger.error("{}:{} has a parameter {} which is not in the signature {}".format(group, name, param_name, signature)) + errors.append(Exception("{}:{} has a parameter {} which is not in the signature {}".format(group, name, param_name, signature))) # Check that the brief description is not empty if not brief: logger.warning("{}:{} has no brief description".format(group, name)) # Check that the group has a description if group not in group_names_descriptions: - logger.error("{} has no group description (referenced from {})".format(group, name)) + errors.append(Exception("{} has no group description (referenced from {})".format(group, name))) desc = re.sub(r'^(\\n)*(.*?)(\\n)*$', r'\2', desc) - return desc.strip(), brief, ';'.join(params), group + return desc.strip(), brief, ';'.join(params), group, errors def sort_functions(item): @@ -155,6 +163,7 @@ def sort_functions(item): precedence = 3 return group + str(precedence) + name +all_errors = [] # Scan all CMakeLists.txt and .cmake files in the specific path, recursively. @@ -178,7 +187,8 @@ def sort_functions(item): name = match.group(4) signature = match.group(1).strip() if signature.startswith(name): - description, brief, params, processed_group = process_commands(match.group(2).replace('#', ''), name, group, signature) + description, brief, params, processed_group, errors = process_commands(match.group(2).replace('#', ''), name, group, signature) + all_errors.extend(errors) new_dict = { 'name': name, 'group': processed_group, @@ -197,6 +207,9 @@ def sort_functions(item): if name not in all_functions and name not in allowed_missing_functions: logger.warning("{} function has no description in {}".format(name, file_path)) +if all_errors: + raise ExceptionGroup("Errors in {}".format(outfile), all_errors) + with open(outfile, 'w', newline='') as csvfile: fieldnames = ('name', 'group', 'signature', 'brief', 'description', 'params') diff --git a/tools/extract_configs.py b/tools/extract_configs.py index 00ff3437b..71e639031 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -24,6 +24,13 @@ from collections import defaultdict +if sys.version_info < (3, 11): + # Python <3.11 doesn't have ExceptionGroup, so define a simple one + class ExceptionGroup(Exception): + def __init__(self, message, errors): + message += "\n" + "\n".join(e.__str__() for e in errors) + super().__init__(message) + logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) @@ -53,11 +60,12 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): _type = config_attrs.get('type', 'int') + errors = [] # Validate attrs for key in config_attrs.keys(): if key not in ALLOWED_CONFIG_PROPERTIES: - raise Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key)) + errors.append(Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key))) if _type == 'int': assert 'enumvalues' not in config_attrs @@ -95,13 +103,13 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): logger.info('{} at {}:{} has non-integer default value "{}"'.format(config_name, file_path, linenum, config_attrs['default'])) if _min is not None and _max is not None: if _min > _max: - raise Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max'])) + errors.append(Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max']))) if _min is not None and _default is not None: if _min > _default: - raise Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default'])) + errors.append(Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default']))) if _default is not None and _max is not None: if _default > _max: - raise Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max'])) + errors.append(Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max']))) elif _type == 'bool': assert 'min' not in config_attrs @@ -126,12 +134,13 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): _default = config_attrs['default'] if _default is not None: if _default not in _enumvalues: - raise Exception('{} at {}:{} has default value {} which isn\'t in list of enumvalues {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['enumvalues'])) + errors.append(Exception('{} at {}:{} has default value {} which isn\'t in list of enumvalues {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['enumvalues']))) else: - raise Exception("Found unknown {} type {} at {}:{}".format(BASE_CONFIG_NAME, _type, file_path, linenum)) - + errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_CONFIG_NAME, _type, file_path, linenum))) + return errors +errors = [] # Scan all .c and .h and .S files in the specific path, recursively. @@ -152,16 +161,16 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): linenum += 1 line = line.strip() if BASE_CMAKE_CONFIG_RE.search(line): - raise Exception("Found {} at {}:{} ({}) which isn't expected in {} files".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line, file_ext)) + errors.append(Exception("Found {} at {}:{} ({}) which isn't expected in {} files".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line, file_ext))) elif BASE_BUILD_DEFINE_RE.search(line): - raise Exception("Found {} at {}:{} ({}) which isn't expected in {} files".format(BASE_BUILD_DEFINE_NAME, file_path, linenum, line, file_ext)) + errors.append(Exception("Found {} at {}:{} ({}) which isn't expected in {} files".format(BASE_BUILD_DEFINE_NAME, file_path, linenum, line, file_ext))) elif BASE_CONFIG_RE.search(line): m = CONFIG_RE.match(line) if not m: if re.match(r"^\s*//\s*// ", line): logger.info("Possible misformatted {} at {}:{} ({})".format(BASE_CONFIG_NAME, file_path, linenum, line)) else: - raise Exception("Found misformatted {} at {}:{} ({})".format(BASE_CONFIG_NAME, file_path, linenum, line)) + errors.append(Exception("Found misformatted {} at {}:{} ({})".format(BASE_CONFIG_NAME, file_path, linenum, line))) else: config_name = m.group(1) config_description = m.group(2) @@ -170,10 +179,10 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): _attrs = re.sub(r'(\(.+\))', lambda m: m.group(1).replace(',', '\0'), _attrs) if '=' in config_description: - raise Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description)) + errors.append(Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description))) all_descriptions = chips_all_descriptions[applicable] if config_description in all_descriptions: - raise Exception("Found description {} at {}:{} but it was already used at {}:{}".format(config_description, file_path, linenum, os.path.join(scandir, all_descriptions[config_description]['filename']), all_descriptions[config_description]['line_number'])) + errors.append(Exception("Found description {} at {}:{} but it was already used at {}:{}".format(config_description, file_path, linenum, os.path.join(scandir, all_descriptions[config_description]['filename']), all_descriptions[config_description]['line_number']))) else: all_descriptions[config_description] = {'config_name': config_name, 'filename': os.path.relpath(file_path, scandir), 'line_number': linenum} @@ -187,19 +196,19 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): try: k, v = (i.strip() for i in item.split('=')) except ValueError: - raise Exception('{} at {}:{} has malformed value {}'.format(config_name, file_path, linenum, item)) + errors.append(Exception('{} at {}:{} has malformed value {}'.format(config_name, file_path, linenum, item))) config_attrs[k] = v.replace('\0', ',') all_attrs.add(k) prev = item #print(file_path, config_name, config_attrs) if 'group' not in config_attrs: - raise Exception('{} at {}:{} has no group attribute'.format(config_name, file_path, linenum)) + errors.append(Exception('{} at {}:{} has no group attribute'.format(config_name, file_path, linenum))) #print(file_path, config_name, config_attrs) all_configs = chips_all_configs[applicable] if config_name in all_configs: - raise Exception("Found {} at {}:{} but it was already declared at {}:{}".format(config_name, file_path, linenum, os.path.join(scandir, all_configs[config_name]['filename']), all_configs[config_name]['line_number'])) + errors.append(Exception("Found {} at {}:{} but it was already declared at {}:{}".format(config_name, file_path, linenum, os.path.join(scandir, all_configs[config_name]['filename']), all_configs[config_name]['line_number']))) else: all_configs[config_name] = {'attrs': config_attrs, 'filename': os.path.relpath(file_path, scandir), 'line_number': linenum, 'description': config_description} else: @@ -246,7 +255,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): file_path = os.path.join(scandir, config_obj['filename']) linenum = config_obj['line_number'] - ValidateAttrs(config_name, config_obj['attrs'], file_path, linenum) + errors.extend(ValidateAttrs(config_name, config_obj['attrs'], file_path, linenum)) # Check that default values match up if 'default' in config_obj['attrs']: @@ -259,16 +268,16 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): # There _may_ be multiple matching defines, but arbitrarily display just one in the error message first_define_value = list(defines_obj.keys())[0] first_define_file_path, first_define_linenum = defines_obj[first_define_value] - raise Exception('Found {} at {}:{} with a default of {}, but #define says {} (at {}:{})'.format(config_name, file_path, linenum, config_default, first_define_value, first_define_file_path, first_define_linenum)) + errors.append(Exception('Found {} at {}:{} with a default of {}, but #define says {} (at {}:{})'.format(config_name, file_path, linenum, config_default, first_define_value, first_define_file_path, first_define_linenum))) else: - raise Exception('Found {} at {}:{} with a default of {}, but no matching #define found'.format(config_name, file_path, linenum, config_default)) + errors.append(Exception('Found {} at {}:{} with a default of {}, but no matching #define found'.format(config_name, file_path, linenum, config_default))) # All settings in "host" should also be in "all" for config_name, config_obj in chips_all_configs["host"].items(): if config_name not in chips_all_configs["all"]: file_path = os.path.join(scandir, config_obj['filename']) linenum = config_obj['line_number'] - raise Exception("Found 'host' config {} at {}:{}, but no matching non-host config found".format(config_name, file_path, linenum)) + errors.append(Exception("Found 'host' config {} at {}:{}, but no matching non-host config found".format(config_name, file_path, linenum))) # Any chip-specific settings should not be in "all" for chip in CHIP_NAMES: @@ -279,7 +288,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): chip_linenum = chip_config_obj['line_number'] all_file_path = os.path.join(scandir, all_config_obj['filename']) all_linenum = all_config_obj['line_number'] - raise Exception("'{}' config {} at {}:{} also found at {}:{}".format(chip, config_name, chip_file_path, chip_linenum, all_file_path, all_linenum)) + errors.append(Exception("'{}' config {} at {}:{} also found at {}:{}".format(chip, config_name, chip_file_path, chip_linenum, all_file_path, all_linenum))) def build_mismatch_exception_message(name, thing, config_obj1, value1, config_obj2, value2): obj1_filepath = os.path.join(scandir, config_obj1['filename']) @@ -299,14 +308,18 @@ def build_mismatch_exception_message(name, thing, config_obj1, value1, config_ob applicable_value = applicable_config_obj[field] other_value = other_config_obj[field] if applicable_value != other_value: - raise Exception(build_mismatch_exception_message(config_name, field, applicable_config_obj, applicable_value, other_config_obj, other_value)) + errors.append(Exception(build_mismatch_exception_message(config_name, field, applicable_config_obj, applicable_value, other_config_obj, other_value))) # Check that attributes match for attr in applicable_config_obj['attrs']: if attr != 'default': # totally fine for defaults to vary per-platform applicable_value = applicable_config_obj['attrs'][attr] other_value = other_config_obj['attrs'][attr] if applicable_value != other_value: - raise Exception(build_mismatch_exception_message(config_name, "attribute '{}'".format(attr), applicable_config_obj, applicable_value, other_config_obj, other_value)) + errors.append(Exception(build_mismatch_exception_message(config_name, "attribute '{}'".format(attr), applicable_config_obj, applicable_value, other_config_obj, other_value))) + +# Raise errors if any were found +if errors: + raise ExceptionGroup("Errors in {}".format(outfile), errors) # Sort the output alphabetically by name and then by chip output_rows = set() From 7d58f951085de04e1ed5b89a2d6f561f0437445a Mon Sep 17 00:00:00 2001 From: Joel Murphy Date: Wed, 18 Jun 2025 16:19:11 +0100 Subject: [PATCH 159/224] Add board definition for Adafruit Feather RP2040 Adalogger (#2524) * Add board definition for Adafruit Feather RP2040 Adalogger * Fix default SPI instance and pin mapping --- .../adafruit_feather_rp2040_adalogger.h | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/boards/include/boards/adafruit_feather_rp2040_adalogger.h diff --git a/src/boards/include/boards/adafruit_feather_rp2040_adalogger.h b/src/boards/include/boards/adafruit_feather_rp2040_adalogger.h new file mode 100644 index 000000000..7bf8ba442 --- /dev/null +++ b/src/boards/include/boards/adafruit_feather_rp2040_adalogger.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +#ifndef _BOARDS_ADAFRUIT_FEATHER_RP2040_ADALOGGER_H +#define _BOARDS_ADAFRUIT_FEATHER_RP2040_ADALOGGER_H + +pico_board_cmake_set(PICO_PLATFORM, rp2040) + +// For board detection +#define ADAFRUIT_FEATHER_RP2040_ADALOGGER + +// On some samples, the xosc can take longer to stabilize than is usual +#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 +#endif + +//------------- UART -------------// +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif + +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif + +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +//------------- LED -------------// +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 13 +#endif + +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 17 +#endif + +//------------- I2C -------------// +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif + +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 2 +#endif + +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 3 +#endif + +//------------- SPI -------------// +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 1 +#endif + +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 15 +#endif + +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 8 +#endif + +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 14 +#endif + +//------------- SD -------------// +#ifndef PICO_SD_CARD_DETECT_PIN +#define PICO_SD_CARD_DETECT_PIN 16 +#endif + +#ifndef PICO_SD_CLK_PIN +#define PICO_SD_CLK_PIN 18 +#endif + +#ifndef PICO_SD_CMD_PIN +#define PICO_SD_CMD_PIN 19 +#endif + +#ifndef PICO_SD_DAT0_PIN +#define PICO_SD_DAT0_PIN 20 +#endif + +#ifndef PICO_SD_DAT_PIN_INCREMENT +#define PICO_SD_DAT_PIN_INCREMENT 1 +#endif + +#ifndef PICO_SD_DAT_PIN_COUNT +#define PICO_SD_DAT_PIN_COUNT 4 +#endif + +//------------- FLASH -------------// + +// Use slower generic flash access +#define PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 4 +#endif + +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (8 * 1024 * 1024)) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) +#endif +// All boards have B1 RP2040 +#ifndef PICO_RP2040_B0_SUPPORTED +#define PICO_RP2040_B0_SUPPORTED 0 +#endif + +#endif From dddb5146d510c025e0918f634334677f81aa223b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 18 Jun 2025 11:19:59 -0400 Subject: [PATCH 160/224] Adafruit Fruit Jam board (#2363) * Adafruit Fruit Jam board * add Adafruit Fruit Jam specific pins * fix pin typos and errors * update to Fruit Jam rev D, address #2510 review * add additional PICO_DEFAULT_* pins * add PICO_AUDIO_I2S_* pins --- .../include/boards/adafruit_fruit_jam.h | 211 ++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 src/boards/include/boards/adafruit_fruit_jam.h diff --git a/src/boards/include/boards/adafruit_fruit_jam.h b/src/boards/include/boards/adafruit_fruit_jam.h new file mode 100644 index 000000000..b769862c4 --- /dev/null +++ b/src/boards/include/boards/adafruit_fruit_jam.h @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2025 Dan Halbert for Adafruit Industries + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// This header may be included by other board headers as "boards/adafruit_fruit_jam.h" + +pico_board_cmake_set(PICO_PLATFORM, rp2350) + +#ifndef _BOARDS_ADAFRUIT_FRUIT_JAM_H +#define _BOARDS_ADAFRUIT_FRUIT_JAM_H + +// On some samples, the xosc can take longer to stabilize than is usual +#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 +#endif + +// For board detection +#define ADAFRUIT_FRUIT_JAM + +// --- RP2350 VARIANT --- +// This means RP2350B. +#define PICO_RP2350A 0 + +// --- BOARD SPECIFIC --- +// On JST PH connector. +#define ADAFRUIT_FRUIT_JAM_A0_PIN 40 + +// A1-A5 and D6-D10 are on 2x16 socket header. +#define ADAFRUIT_FRUIT_JAM_A1_PIN 41 +#define ADAFRUIT_FRUIT_JAM_A2_PIN 42 +#define ADAFRUIT_FRUIT_JAM_A3_PIN 43 +#define ADAFRUIT_FRUIT_JAM_A4_PIN 44 +#define ADAFRUIT_FRUIT_JAM_A5_PIN 45 + +#define ADAFRUIT_FRUIT_JAM_D6_PIN 6 +#define ADAFRUIT_FRUIT_JAM_D7_PIN 7 +#define ADAFRUIT_FRUIT_JAM_D8_PIN 8 +#define ADAFRUIT_FRUIT_JAM_D9_PIN 9 +#define ADAFRUIT_FRUIT_JAM_D10_PIN 10 + +// Buttons +// Boot button is also known as Button 1. +#define ADAFRUIT_FRUIT_JAM_BOOT_BUTTON_PIN 0 +#define ADAFRUIT_FRUIT_JAM_BUTTON1_PIN 0 +#define ADAFRUIT_FRUIT_JAM_BUTTON2_PIN 4 +#define ADAFRUIT_FRUIT_JAM_BUTTON3_PIN 5 + +// ESP32-C6 co-processor +#define ADAFRUIT_FRUIT_JAM_WIFI_SCK_PIN 30 +#define ADAFRUIT_FRUIT_JAM_WIFI_MOSI_PIN 31 +#define ADAFRUIT_FRUIT_JAM_WIFI_MISO_PIN 28 +#define ADAFRUIT_FRUIT_JAM_WIFI_CS_PIN 46 +#define ADAFRUIT_FRUIT_JAM_WIFI_ACK_PIN 3 +#define ADAFRUIT_FRUIT_JAM_WIFI_RESET_PIN 22 + +// HSTX header +#define ADAFRUIT_FRUIT_JAM_DVI_CKN_PIN 12 +#define ADAFRUIT_FRUIT_JAM_DVI_CKP_PIN 13 +#define ADAFRUIT_FRUIT_JAM_DVI_D0N_PIN 14 +#define ADAFRUIT_FRUIT_JAM_DVI_D0P_PIN 15 +#define ADAFRUIT_FRUIT_JAM_DVI_D1N_PIN 16 +#define ADAFRUIT_FRUIT_JAM_DVI_D1P_PIN 17 +#define ADAFRUIT_FRUIT_JAM_DVI_D2N_PIN 18 +#define ADAFRUIT_FRUIT_JAM_DVI_D2P_PIN 19 + +// Reset for ESP32-C6 and TLV320DAC3100 +#define ADAFRUIT_FRUIT_JAM_PERIPH_RESET_PIN 22 + +#define ADAFRUIT_FRUIT_JAM_I2S_ESP_IRQ_PIN 23 + +// I2S to TLV320DAC3100 +#define ADAFRUIT_FRUIT_JAM_I2S_DIN_PIN 24 +#define ADAFRUIT_FRUIT_JAM_I2S_MCLK_PIN 25 +#define ADAFRUIT_FRUIT_JAM_I2S_BCLK_PIN 26 +#define ADAFRUIT_FRUIT_JAM_I2S_WS_PIN 27 + +// SD and SDIO +#define ADAFRUIT_FRUIT_JAM_SD_SCK_PIN 34 +#define ADAFRUIT_FRUIT_JAM_SDIO_CLOCK_PIN 34 + +#define ADAFRUIT_FRUIT_JAM_SD_MOSI_PIN 35 +#define ADAFRUIT_FRUIT_JAM_SDIO_COMMAND_PIN 35 + +#define ADAFRUIT_FRUIT_JAM_SD_MISO_PIN 36 +#define ADAFRUIT_FRUIT_JAM_SDIO_DATA0_PIN 36 + +#define ADAFRUIT_FRUIT_JAM_SDIO_DATA1_PIN 37 +#define ADAFRUIT_FRUIT_JAM_SDIO_DATA2_PIN 38 + +#define ADAFRUIT_FRUIT_JAM_SD_CS_PIN 39 +#define ADAFRUIT_FRUIT_JAM_SDIO_DATA3_PIN 39 + +#define ADAFRUIT_FRUIT_JAM_SD_CARD_DETECT_PIN 33 + +#define ADAFRUIT_FRUIT_JAM_USB_HOST_DATA_PLUS_PIN 1 +#define ADAFRUIT_FRUIT_JAM_USB_HOST_DATA_MINUS_PIN 2 +#define ADAFRUIT_FRUIT_JAM_USB_HOST_5V_POWER_PIN 11 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 1 +#endif + +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 8 +#endif + +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 9 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 29 +#endif + +// --- RGB (NeoPixel) LED --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 32 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 20 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 21 +#endif + +// --- SPI --- +// Default SPI is also the SPI for the SD card. +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN ADAFRUIT_FRUIT_JAM_SD_SCK_PIN +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN ADAFRUIT_FRUIT_JAM_SD_MOSI_PIN +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN ADAFRUIT_FRUIT_JAM_SD_MISO_PIN +#endif + +//------------- SD ------------ +#ifndef PICO_SD_CARD_DETECT_PIN +#define PICO_SD_CARD_DETECT_PIN ADAFRUIT_FRUIT_JAM_SD_CARD_DETECT_PIN +#endif + +#ifndef PICO_SD_CLK_PIN +#define PICO_SD_CLK_PIN ADAFRUIT_FRUIT_JAM_SDIO_CLOCK_PIN +#endif + +#ifndef PICO_SD_CMD_PIN +#define PICO_SD_CMD_PIN ADAFRUIT_FRUIT_JAM_SDIO_COMMAND_PIN +#endif + +#ifndef PICO_SD_DAT0_PIN +#define PICO_SD_DAT0_PIN ADAFRUIT_FRUIT_JAM_SDIO_DATA0_PIN +#endif + +#ifndef PICO_SD_DAT_PIN_INCREMENT +#define PICO_SD_DAT_PIN_INCREMENT 1 +#endif + +#ifndef PICO_SD_DAT_PIN_COUNT +#define PICO_SD_DAT_PIN_COUNT 4 +#endif + +// --- I2S AUDIO (for pico-extras/src/rp2_common/pico_audio_i2s/) + +#ifndef PICO_AUDIO_I2S_DATA_PIN +#define PICO_AUDIO_I2S_DATA_PIN ADAFRUIT_FRUIT_JAM_I2S_DIN_PIN +#endif + +#ifndef PICO_AUDIO_I2S_CLOCK_PIN_BASE +#define PICO_AUDIO_I2S_CLOCK_PIN_BASE ADAFRUIT_FRUIT_JAM_I2S_BCLK_PIN +#endif + +// --- PIO USB --- +#define PICO_DEFAULT_PIO_USB_DP_PIN ADAFRUIT_FRUIT_JAM_USB_HOST_DATA_PLUS_PIN + +// --- FLASH --- +// Winbond W25Q128 (16MB) flash +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif From 893a06bb80e68ef0e77f9bea63ddb9eebad16b63 Mon Sep 17 00:00:00 2001 From: UUGear Date: Wed, 18 Jun 2025 17:21:18 +0200 Subject: [PATCH 161/224] Add UUGear Witty Pi 5 HAT+ board header file (#2518) * Add UUGear Witty Pi 5 HAT+ board header file * Update uugear_wittypi5_hat_plus.h Fixes detected errors --- .../include/boards/uugear_wittypi5_hat_plus.h | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/boards/include/boards/uugear_wittypi5_hat_plus.h diff --git a/src/boards/include/boards/uugear_wittypi5_hat_plus.h b/src/boards/include/boards/uugear_wittypi5_hat_plus.h new file mode 100644 index 000000000..5050d1956 --- /dev/null +++ b/src/boards/include/boards/uugear_wittypi5_hat_plus.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 Dun Cat B.V.(UUGear) + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// This header may be included by other board headers as "boards/uugear_wittypi5_hat_plus.h" + +#ifndef _BOARDS_UUGEAR_WITTYPI5_HAT_PLUS_H +#define _BOARDS_UUGEAR_WITTYPI5_HAT_PLUS_H + +pico_board_cmake_set(PICO_PLATFORM, rp2350) + +// For board detection +#define UUGEAR_WITTYPI5_HAT_PLUS + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 22 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 4 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 5 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +// Sometimes the xosc may take longer to stabilize +#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 +#endif + +#endif From 5ddb441cf1ead68039bc699d0ac6aef48e49785e Mon Sep 17 00:00:00 2001 From: Michael Brase Date: Wed, 18 Jun 2025 17:06:34 -0500 Subject: [PATCH 162/224] async_context_freertos: Add support for configSUPPORT_STATIC_ALLOCATION (#2436) * async_context_freertos: Add support for configSUPPORT_STATIC_ALLOCATION The implementation of async_context_freertos currently assumes that FreeRTOS has been configured with `configSUPPORT_DYNAMIC_ALLOCATION`, which causes it to allocate semaphores, timers and tasks from the heap. However, some projects may prefer `configSUPPORT_STATIC_ALLOCATION`, which requires memory to be allocated ahead of time. This change allows async_context_freertos to support either static or dynamic allocation. The way this works is when `configSUPPORT_STATIC_ALLOCATION` is enabled, `async_context_freertos` struct will reserve extra space for the static objects (e.g. `StaticSemaphore_t`) and it will prefer to use the static creation functions (e.g. `xSemaphoreCreateBinaryStatic()`). For the task creation, the user will be responsible for allocating the stack memory and setting the task_stack field in `async_context_freertos_config_t`. For convenience, The `cyw43_arch_init_default_async_context()` function will reserve `CYW43_TASK_STACK_SIZE` words of stack space in static memory. * Assert that task_stack is set * Add CYW43_NO_DEFAULT_TASK_STACK In theory you can use your own async context therefore bypassing cyw43_arch_init_default_async_context, which would leave cyw43_async_context_freertos_task_stack unused. Add a #define for this rare situation. * Update documentaton for async_context_freertos_config.task_stack --------- Co-authored-by: Peter Harper --- .../async_context_freertos.c | 33 ++++++++++++++++++- .../include/pico/async_context_freertos.h | 12 +++++++ .../pico_cyw43_arch/cyw43_arch_freertos.c | 7 ++++ .../include/pico/cyw43_arch/arch_freertos.h | 5 +++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_async_context/async_context_freertos.c b/src/rp2_common/pico_async_context/async_context_freertos.c index 9ae72b3af..be7c08110 100644 --- a/src/rp2_common/pico_async_context/async_context_freertos.c +++ b/src/rp2_common/pico_async_context/async_context_freertos.c @@ -109,6 +109,24 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f self->core.type = &template; self->core.flags = ASYNC_CONTEXT_FLAG_CALLBACK_FROM_NON_IRQ; self->core.core_num = get_core_num(); +#if configSUPPORT_STATIC_ALLOCATION + assert(config->task_stack); + self->lock_mutex = xSemaphoreCreateRecursiveMutexStatic(&self->lock_mutex_buf); + self->work_needed_sem = xSemaphoreCreateBinaryStatic(&self->work_needed_sem_buf); + self->timer_handle = xTimerCreateStatic( "async_context_timer", // Just a text name, not used by the kernel. + portMAX_DELAY, + pdFALSE, // The timers will auto-reload themselves when they expire. + self, + timer_handler, + &self->timer_buf); + self->task_handle = xTaskCreateStatic( async_context_task, + "async_context_task", + config->task_stack_size, + self, + config->task_priority, + config->task_stack, + &self->task_buf); +#else self->lock_mutex = xSemaphoreCreateRecursiveMutex(); self->work_needed_sem = xSemaphoreCreateBinary(); self->timer_handle = xTimerCreate( "async_context_timer", // Just a text name, not used by the kernel. @@ -116,12 +134,18 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f pdFALSE, // The timers will auto-reload themselves when they expire. self, timer_handler); +#endif if (!self->lock_mutex || !self->work_needed_sem || !self->timer_handle || +#if configSUPPORT_STATIC_ALLOCATION + !self->task_handle +#else pdPASS != xTaskCreate(async_context_task, "async_context_task", config->task_stack_size, self, - config->task_priority, &self->task_handle)) { + config->task_priority, &self->task_handle) +#endif + ) { async_context_deinit(&self->core); return false; } @@ -179,6 +203,9 @@ void async_context_freertos_lock_check(__unused async_context_t *self_base) { typedef struct sync_func_call{ async_when_pending_worker_t worker; SemaphoreHandle_t sem; +#if configSUPPORT_STATIC_ALLOCATION + StaticSemaphore_t sem_buf; +#endif uint32_t (*func)(void *param); void *param; uint32_t rc; @@ -197,7 +224,11 @@ uint32_t async_context_freertos_execute_sync(async_context_t *self_base, uint32_ call.worker.do_work = handle_sync_func_call; call.func = func; call.param = param; +#if configSUPPORT_STATIC_ALLOCATION + call.sem = xSemaphoreCreateBinaryStatic(&call.sem_buf); +#else call.sem = xSemaphoreCreateBinary(); +#endif async_context_add_when_pending_worker(self_base, &call.worker); async_context_set_work_pending(self_base, &call.worker); xSemaphoreTake(call.sem, portMAX_DELAY); diff --git a/src/rp2_common/pico_async_context/include/pico/async_context_freertos.h b/src/rp2_common/pico_async_context/include/pico/async_context_freertos.h index bc5131258..273d653f2 100644 --- a/src/rp2_common/pico_async_context/include/pico/async_context_freertos.h +++ b/src/rp2_common/pico_async_context/include/pico/async_context_freertos.h @@ -56,6 +56,12 @@ typedef struct async_context_freertos_config { * \brief Stack size for the async_context task */ configSTACK_DEPTH_TYPE task_stack_size; + /** + * \brief Pointer to stack memory for the async_context task. + */ +#if configSUPPORT_STATIC_ALLOCATION + StackType_t *task_stack; +#endif /** * \brief the core ID (see \ref portGET_CORE_ID()) to pin the task to. * This is only relevant in SMP mode. @@ -71,6 +77,12 @@ struct async_context_freertos { SemaphoreHandle_t work_needed_sem; TimerHandle_t timer_handle; TaskHandle_t task_handle; +#if configSUPPORT_STATIC_ALLOCATION + StaticSemaphore_t lock_mutex_buf; + StaticSemaphore_t work_needed_sem_buf; + StaticTimer_t timer_buf; + StaticTask_t task_buf; +#endif uint8_t nesting; volatile bool task_should_exit; }; diff --git a/src/rp2_common/pico_cyw43_arch/cyw43_arch_freertos.c b/src/rp2_common/pico_cyw43_arch/cyw43_arch_freertos.c index 93f73ad5d..53ab62195 100644 --- a/src/rp2_common/pico_cyw43_arch/cyw43_arch_freertos.c +++ b/src/rp2_common/pico_cyw43_arch/cyw43_arch_freertos.c @@ -25,6 +25,10 @@ static async_context_freertos_t cyw43_async_context_freertos; +#if configSUPPORT_STATIC_ALLOCATION && !CYW43_NO_DEFAULT_TASK_STACK +static StackType_t cyw43_async_context_freertos_task_stack[CYW43_TASK_STACK_SIZE]; +#endif + async_context_t *cyw43_arch_init_default_async_context(void) { async_context_freertos_config_t config = async_context_freertos_default_config(); #ifdef CYW43_TASK_PRIORITY @@ -32,6 +36,9 @@ async_context_t *cyw43_arch_init_default_async_context(void) { #endif #ifdef CYW43_TASK_STACK_SIZE config.task_stack_size = CYW43_TASK_STACK_SIZE; +#endif +#if configSUPPORT_STATIC_ALLOCATION && !CYW43_NO_DEFAULT_TASK_STACK + config.task_stack = cyw43_async_context_freertos_task_stack; #endif if (async_context_freertos_init(&cyw43_async_context_freertos, &config)) return &cyw43_async_context_freertos.core; diff --git a/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch/arch_freertos.h b/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch/arch_freertos.h index 1ba23eff9..6944aa707 100644 --- a/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch/arch_freertos.h +++ b/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch/arch_freertos.h @@ -7,6 +7,11 @@ #ifndef _PICO_CYW43_ARCH_ARCH_FREERTOS_H #define _PICO_CYW43_ARCH_ARCH_FREERTOS_H +// PICO_CONFIG: CYW43_NO_DEFAULT_TASK_STACK, Disables the default static allocation of the CYW43 FreeRTOS task stack, type=bool, default=0, group=pico_cyw43_arch +#ifndef CYW43_NO_DEFAULT_TASK_STACK +#define CYW43_NO_DEFAULT_TASK_STACK 0 +#endif + // PICO_CONFIG: CYW43_TASK_STACK_SIZE, Stack size for the CYW43 FreeRTOS task in 4-byte words, type=int, default=1024, group=pico_cyw43_arch #ifndef CYW43_TASK_STACK_SIZE #define CYW43_TASK_STACK_SIZE 1024 From c3c62675e88f45d596a1039efbed7c769133d708 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Wed, 18 Jun 2025 23:07:34 +0100 Subject: [PATCH 163/224] Clean extra output files (#2504) Add bin/uf2/dis/hex output files as byproducts, so they get cleaned up This is only best-effort, because BYPRODUCTS doesn't support generator expressions, so everything must be evaluated at the time pico_add_extra_outputs is called --- src/cmake/on_device.cmake | 20 ++++++++++++++++++-- tools/CMakeLists.txt | 4 +++- tools/extract_cmake_functions.py | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/cmake/on_device.cmake b/src/cmake/on_device.cmake index b4c53b967..69e2f3462 100644 --- a/src/cmake/on_device.cmake +++ b/src/cmake/on_device.cmake @@ -15,24 +15,38 @@ function(pico_get_runtime_output_directory TARGET output_path_name) set(${output_path_name} ${output_path} PARENT_SCOPE) endfunction() +function(pico_get_output_name TARGET output_name_var) + get_target_property(output_name ${TARGET} OUTPUT_NAME) + # Generator expressions not supported in byproducts + set(output_name_copy ${output_name}) + string(GENEX_STRIP "${output_name}" output_name) + if (NOT output_name OR (NOT output_name STREQUAL output_name_copy)) + get_target_property(output_name ${TARGET} NAME) + endif() + set(${output_name_var} ${output_name} PARENT_SCOPE) +endfunction() + # pico_add_hex_output(TARGET) # \brief\ Generate a hex file for the target function(pico_add_hex_output TARGET) pico_get_runtime_output_directory(${TARGET} output_path) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex $ ${output_path}$>,$,$>.hex VERBATIM) + pico_get_output_name(${TARGET} output_name) + add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex $ ${output_path}$>,$,$>.hex VERBATIM BYPRODUCTS "${output_path}${output_name}.hex") endfunction() # pico_add_bin_output(TARGET) # \brief\ Generate a bin file for the target function(pico_add_bin_output TARGET) pico_get_runtime_output_directory(${TARGET} output_path) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${output_path}$>,$,$>.bin VERBATIM) + pico_get_output_name(${TARGET} output_name) + add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${output_path}$>,$,$>.bin VERBATIM BYPRODUCTS "${output_path}${output_name}.bin") endfunction() # pico_add_dis_output(TARGET) # \brief\ Generate a disassembly file for the target function(pico_add_dis_output TARGET) pico_get_runtime_output_directory(${TARGET} output_path) + pico_get_output_name(${TARGET} output_name) # PICO_CMAKE_CONFIG: PICO_NO_COPRO_DIS, Disable disassembly listing postprocessing that disassembles RP2350 coprocessor instructions, type=bool, default=0, group=build if (NOT (PICO_NO_COPRO_DIS OR PICO_NO_PICOTOOL OR PICO_RISCV OR PICO_RP2040)) @@ -48,6 +62,7 @@ function(pico_add_dis_output TARGET) COMMAND ${CMAKE_OBJDUMP} -d ${PICO_DISASM_OBJDUMP_ARGS} $ >> ${output_path}$>,$,$>.dis ${EXTRA_COMMAND} VERBATIM + BYPRODUCTS "${output_path}${output_name}.dis" ) endfunction() @@ -88,6 +103,7 @@ function(pico_add_extra_outputs TARGET) COMMAND rm -f "${PICO_SYMLINK_ELF_AS_FILENAME}" COMMAND ln -s -r $ "${PICO_SYMLINK_ELF_AS_FILENAME}" COMMENT "Symlinking from ${PICO_SYMLINK_ELF_AS_FILENAME} to ${TARGET}" + BYPRODUCTS "${PICO_SYMLINK_ELF_AS_FILENAME}" ) endif () # PICO_CMAKE_CONFIG: PICO_NO_UF2, Disable UF2 output, type=bool, default=0, group=build diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 9ec5a232c..7a0b56160 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -556,6 +556,7 @@ function(pico_add_uf2_output TARGET) else() set(output_path "") endif() + pico_get_output_name(${TARGET} output_name) get_target_property(${TARGET}_uf2_package_addr ${TARGET} PICOTOOL_UF2_PACKAGE_ADDR) if (${TARGET}_uf2_package_addr) @@ -594,7 +595,8 @@ function(pico_add_uf2_output TARGET) --family ${picotool_family} ${extra_uf2_args} COMMAND_EXPAND_LISTS - VERBATIM) + VERBATIM + BYPRODUCTS "${output_path}${output_name}.uf2") endif() endfunction() diff --git a/tools/extract_cmake_functions.py b/tools/extract_cmake_functions.py index 94dac8d62..38e47ca15 100755 --- a/tools/extract_cmake_functions.py +++ b/tools/extract_cmake_functions.py @@ -57,6 +57,7 @@ def __init__(self, message, errors): "pico_init_picotool", "pico_add_platform_library", "pico_get_runtime_output_directory", + "pico_get_output_name", "pico_set_printf_implementation", "pico_expand_pico_platform", ]) From 24af10a6a2536d77975feeda0b0ca943ffb4e9f6 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Wed, 18 Jun 2025 23:08:35 +0100 Subject: [PATCH 164/224] Use cyw43 macros for bluetooth logging (#2490) * Tidy up bt logging Fixes #2253 * Allow logging to be overridden --- .../cybt_shared_bus/BUILD.bazel | 2 +- .../cybt_shared_bus/cybt_logging.h | 57 +++++++++++++++++++ .../cybt_shared_bus/cybt_shared_bus.c | 54 +++++++----------- .../cybt_shared_bus/cybt_shared_bus_driver.c | 44 +++++--------- 4 files changed, 92 insertions(+), 65 deletions(-) create mode 100644 src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_logging.h diff --git a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/BUILD.bazel b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/BUILD.bazel index 24e53b3f9..7ade7c787 100644 --- a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/BUILD.bazel +++ b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/BUILD.bazel @@ -6,7 +6,7 @@ cc_library( "cybt_shared_bus.c", "cybt_shared_bus_driver.c", ], - hdrs = ["cybt_shared_bus_driver.h"], + hdrs = ["cybt_shared_bus_driver.h", "cybt_logging.h"], includes = ["."], deps = [ "@cyw43-driver//:cyw43_driver", diff --git a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_logging.h b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_logging.h new file mode 100644 index 000000000..aad2a1e6e --- /dev/null +++ b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_logging.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef CYBT_LOGGING_H +#define CYBT_LOGGING_H + +// Error messages only enabled in debug by default +#ifndef CYBT_ERROR_ENABLED +#ifndef NDEBUG +#define CYBT_ERROR_ENABLED 1 +#else +#define CYBT_ERROR_ENABLED 0 +#endif +#endif + +// Info messages only enabled in debug by default +#ifndef CYBT_INFO_ENABLED +#ifndef NDEBUG +#define CYBT_INFO_ENABLED 1 +#else +#define CYBT_INFO_ENABLED 0 +#endif +#endif + +// Debug messages disabled by default +#ifndef CYBT_DEBUG_ENABLED +#define CYBT_DEBUG_ENABLED 0 +#endif + +#ifndef cybt_error +#if CYBT_ERROR_ENABLED +#define cybt_error CYW43_WARN +#else +#define cybt_error(...) +#endif +#endif + +#ifndef cybt_info +#if CYBT_INFO_ENABLED +#define cybt_info CYW43_PRINTF +#else +#define cybt_info(...) +#endif +#endif + +#ifndef cybt_debug +#if CYBT_DEBUG_ENABLED +#define cybt_debug CYW43_PRINTF +#else +#define cybt_debug(...) +#endif +#endif + +#endif // CYBT_LOGGING_H \ No newline at end of file diff --git a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c index 9b454b6d5..f256f0e4c 100644 --- a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c +++ b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c @@ -15,6 +15,7 @@ #include "cybt_shared_bus_driver.h" #include "cyw43_btfw_43439.h" +#include "cybt_logging.h" #if CYW43_USE_HEX_BTFW extern const char brcm_patch_version[]; @@ -31,20 +32,6 @@ extern const int brcm_patch_ram_length; #define BTSDIO_FWBUF_OPER_DELAY_US (250) #define BTFW_WAIT_TIME_MS (150) -#define CYBT_DEBUG 0 -#define CYBT_VDEBUG 0 - -#if CYBT_DEBUG -#define cybt_debug(format,args...) printf("%d.%d: " format, (int)cyw43_hal_ticks_ms() / 1000, (int)cyw43_hal_ticks_ms() % 1000, ## args) -#else -#define cybt_debug(format, ...) ((void)0) -#endif -#ifndef NDEBUG -#define cybt_printf(format, args...) printf("%d.%d: " format, (int)cyw43_hal_ticks_ms() / 1000, (int)cyw43_hal_ticks_ms() % 1000, ## args) -#else -#define cybt_printf(...) -#endif - #define ROUNDUP(x, a) ((((x) + ((a) - 1)) / (a)) * (a)) #define ROUNDDN(x, a) ((x) & ~((a) - 1)) #define ISALIGNED(a, x) (((uint32_t)(a) & ((x) - 1)) == 0) @@ -123,7 +110,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) { ret = cybt_fw_download_prepare(&p_write_buf, &p_hex_buf); if (CYBT_SUCCESS != ret) { - cybt_printf("Could not allocate memory\n"); + cybt_error("Could not allocate memory\n"); return ret; } @@ -131,9 +118,9 @@ int cyw43_btbus_init(cyw43_ll_t *self) { const uint8_t *fw_data_buf; uint32_t fw_data_len; #if CYW43_USE_HEX_BTFW - cybt_printf("CYW43_USE_HEX_BTFW is true\n"); + cybt_error("CYW43_USE_HEX_BTFW is true\n"); #ifndef NDEBUG - cybt_printf("BT FW download, version = %s\n", brcm_patch_version); + cybt_info("BT FW download, version = %s\n", brcm_patch_version); #endif fw_data_len = brcm_patch_ram_length; fw_data_buf = brcm_patchram_buf; @@ -151,7 +138,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) { cybt_fw_download_finish(p_write_buf, p_hex_buf); if (CYBT_SUCCESS != ret) { - cybt_printf("hci_open(): FW download failed (0x%x)\n", ret); + cybt_error("hci_open(): FW download failed (0x%x)\n", ret); return CYBT_ERR_HCI_INIT_FAILED; } @@ -161,7 +148,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) { if (CYBT_SUCCESS == ret) { cybt_debug("hci_open(): FW download successfully\n"); } else { - cybt_printf("hci_open(): Failed to download FW\n"); + cybt_error("hci_open(): Failed to download FW\n"); return CYBT_ERR_HCI_INIT_FAILED; } @@ -182,7 +169,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) { return CYBT_SUCCESS; } -#if CYBT_VDEBUG +#if 0 static void dump_bytes(const uint8_t *bptr, uint32_t len) { unsigned int i = 0; @@ -198,6 +185,9 @@ static void dump_bytes(const uint8_t *bptr, uint32_t len) { } printf("\n"); } +#define DUMP_BYTES dump_bytes +#else +#define DUMP_BYTES(...) #endif static cybt_result_t cybt_hci_write_buf(const uint8_t *p_data, uint32_t length) { @@ -206,7 +196,7 @@ static cybt_result_t cybt_hci_write_buf(const uint8_t *p_data, uint32_t length) assert(ISALIGNED(p_data, 4)); if (!ISALIGNED(p_data, 4)) { - cybt_printf("cybt_hci_write_hdr: buffer not aligned\n"); + cybt_error("cybt_hci_write_hdr: buffer not aligned\n"); return CYBT_ERR_BADARG; } @@ -260,7 +250,7 @@ static cybt_result_t cybt_hci_read(uint8_t *p_data, uint32_t *p_length) { assert(ISALIGNED(p_data, 4)); if (!ISALIGNED(p_data, 4)) { assert(false); - cybt_printf("cybt_hci_read: buffer not aligned\n"); + cybt_error("cybt_hci_read: buffer not aligned\n"); return CYBT_ERR_BADARG; } @@ -272,9 +262,9 @@ static cybt_result_t cybt_hci_read(uint8_t *p_data, uint32_t *p_length) { cybt_debug("cybt_hci_read: bt2host_in_val=%lu bt2host_out_val=%lu fw_b2h_buf_count=%ld\n", fw_membuf_info.bt2host_in_val, fw_membuf_info.bt2host_out_val, fw_b2h_buf_count); if (fw_b2h_buf_count < available) { - cybt_printf("error: cybt_hci_read buffer overflow fw_b2h_buf_count=%ld available=%lu\n", fw_b2h_buf_count, + cybt_error("error: cybt_hci_read buffer overflow fw_b2h_buf_count=%ld available=%lu\n", fw_b2h_buf_count, available); - cybt_printf("error: cybt_hci_read bt2host_in_val=%lu bt2host_out_val=%lu\n", fw_membuf_info.bt2host_in_val, + cybt_error("error: cybt_hci_read bt2host_in_val=%lu bt2host_out_val=%lu\n", fw_membuf_info.bt2host_in_val, fw_membuf_info.bt2host_out_val); panic("cyw43 buffer overflow"); } @@ -355,9 +345,7 @@ int cyw43_btbus_write(uint8_t *buf, uint32_t size) { cybt_bus_request(); cybt_debug("cyw43_btbus_write: %d\n", cmd_len); -#if CYBT_VDEBUG - dump_bytes(buf, size); // dump header and data -#endif + DUMP_BYTES(buf, size); // dump header and data cybt_hci_write_buf(buf, size); cybt_bus_release(); @@ -376,7 +364,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t * if (bt_result != CYBT_SUCCESS) { *size = 0; - cybt_printf("cybt_hci_read_packet: error %d", bt_result); + cybt_error("cybt_hci_read_packet: error %d", bt_result); return true; } @@ -390,7 +378,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t * uint32_t hci_read_len = ((buf[2] << 16) & 0xFFFF00) | ((buf[1] << 8) & 0xFF00) | (buf[0] & 0xFF); if (hci_read_len > max_buf_size - 4) { *size = 0; - cybt_printf("cybt_hci_read_packet: too much data len %" PRId32"\n", hci_read_len); + cybt_error("cybt_hci_read_packet: too much data len %" PRId32"\n", hci_read_len); assert(false); return false; } @@ -401,7 +389,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t * bt_result = cybt_hci_read(buf + 4, &total_read_len); if (bt_result != CYBT_SUCCESS) { *size = 0; - cybt_printf("cybt_hci_read_packet: read failed\n"); + cybt_error("cybt_hci_read_packet: read failed\n"); assert(false); return false; } @@ -413,15 +401,13 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t * } else { assert(total_read_len > 0); *size = total_read_len + 4; - cybt_printf("cybt_hci_read_packet: failed to read all data %lu < %lu\n", total_read_len, hci_read_len); + cybt_error("cybt_hci_read_packet: failed to read all data %lu < %lu\n", total_read_len, hci_read_len); //assert(false); return true; } cybt_debug("cybt_hci_read_packet: %ld\n", *size); -#if CYBT_VDEBUG - dump_bytes(buf, *size); -#endif + DUMP_BYTES(buf, *size); return true; } diff --git a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus_driver.c b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus_driver.c index 452337f99..dcfca3a15 100644 --- a/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus_driver.c +++ b/src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus_driver.c @@ -11,6 +11,7 @@ #include "cyw43_ll.h" #include "cybt_shared_bus_driver.h" +#include "cybt_logging.h" // Bluetooth register corruption occurs if both wifi and bluetooth are fully utilised. #define CYBT_CORRUPTION_TEST 1 @@ -23,23 +24,6 @@ static uint32_t last_bt_ctrl_reg; #endif -#ifndef NDEBUG -#define cybt_printf(format, args ...) printf(format,##args) -#else -#define cybt_printf(...) -#endif - -#ifndef CYBT_DEBUG -#define CYBT_DEBUG 0 -#endif - -#if CYBT_DEBUG -#include -#define cybt_debug(format, args ...) printf(format,##args) -#else -#define cybt_debug(format, ...) ((void)0) -#endif - /****************************************************************************** * Constants @@ -319,7 +303,7 @@ cybt_result_t cybt_fw_download(const uint8_t *p_bt_firmware, uint8_t version_len = *p_bt_firmware; assert(*(p_bt_firmware + version_len) == 0); #ifndef NDEBUG - cybt_printf("BT FW download, version = %s\n", p_bt_firmware + 1); + cybt_info("BT FW download, version = %s\n", p_bt_firmware + 1); #endif p_bt_firmware += version_len + 1; // skip over version p_bt_firmware += 1; // skip over record count @@ -409,7 +393,7 @@ cybt_result_t cybt_toggle_bt_intr(void) { cybt_reg_read(HOST_CTRL_REG_ADDR, ®_val); #if CYBT_CORRUPTION_TEST if ((reg_val & ~(BTSDIO_REG_SW_RDY_BITMASK | BTSDIO_REG_WAKE_BT_BITMASK | BTSDIO_REG_DATA_VALID_BITMASK)) != 0) { - cybt_printf("cybt_toggle_bt_intr read HOST_CTRL_REG_ADDR as 0x%08lx\n", reg_val); + cybt_error("cybt_toggle_bt_intr read HOST_CTRL_REG_ADDR as 0x%08lx\n", reg_val); cybt_debug_dump(); panic("cyw43 btsdio register corruption"); } @@ -485,32 +469,32 @@ void cybt_debug_dump(void) { uint32_t reg_val = 0; cybt_fw_membuf_index_t buf_index; - cybt_printf("WLAN_RAM_BASE_ADDR: 0x%08lx\n", WLAN_RAM_BASE_ADDR); - cybt_printf("H2B_BUF_ADDR: 0x%08lx\n", H2B_BUF_ADDR); - cybt_printf("B2H_BUF_ADDR: 0x%08lx\n", B2H_BUF_ADDR); + cybt_debug("WLAN_RAM_BASE_ADDR: 0x%08lx\n", WLAN_RAM_BASE_ADDR); + cybt_debug("H2B_BUF_ADDR: 0x%08lx\n", H2B_BUF_ADDR); + cybt_debug("B2H_BUF_ADDR: 0x%08lx\n", B2H_BUF_ADDR); cybt_reg_read(H2B_BUF_IN_ADDR, &buf_index.host2bt_in_val); - cybt_printf("H2B_BUF_IN_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", H2B_BUF_IN_ADDR, buf_index.host2bt_in_val, + cybt_debug("H2B_BUF_IN_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", H2B_BUF_IN_ADDR, buf_index.host2bt_in_val, last_buf_index.host2bt_in_val); cybt_reg_read(H2B_BUF_OUT_ADDR, &buf_index.host2bt_out_val); - cybt_printf("H2B_BUF_OUT_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", H2B_BUF_OUT_ADDR, buf_index.host2bt_out_val, + cybt_debug("H2B_BUF_OUT_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", H2B_BUF_OUT_ADDR, buf_index.host2bt_out_val, last_buf_index.host2bt_out_val); cybt_reg_read(B2H_BUF_IN_ADDR, &buf_index.bt2host_in_val); - cybt_printf("B2H_BUF_IN_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", B2H_BUF_IN_ADDR, buf_index.bt2host_in_val, + cybt_debug("B2H_BUF_IN_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", B2H_BUF_IN_ADDR, buf_index.bt2host_in_val, last_buf_index.bt2host_in_val); cybt_reg_read(B2H_BUF_OUT_ADDR, &buf_index.bt2host_out_val); - cybt_printf("B2H_BUF_OUT_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", B2H_BUF_OUT_ADDR, buf_index.bt2host_out_val, + cybt_debug("B2H_BUF_OUT_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", B2H_BUF_OUT_ADDR, buf_index.bt2host_out_val, last_buf_index.bt2host_out_val); cybt_reg_read(HOST_CTRL_REG_ADDR, ®_val); - cybt_printf("HOST_CTRL_REG_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", HOST_CTRL_REG_ADDR, reg_val, + cybt_debug("HOST_CTRL_REG_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", HOST_CTRL_REG_ADDR, reg_val, last_host_ctrl_reg); cybt_reg_read(BT_CTRL_REG_ADDR, ®_val); - cybt_printf("BT_CTRL_REG_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", BT_CTRL_REG_ADDR, reg_val, last_bt_ctrl_reg); + cybt_debug("BT_CTRL_REG_ADDR: 0x%08lx = 0x%08lx (last 0x%08lx)\n", BT_CTRL_REG_ADDR, reg_val, last_bt_ctrl_reg); #endif } @@ -533,7 +517,7 @@ cybt_result_t cybt_get_bt_buf_index(cybt_fw_membuf_index_t *p_buf_index) { #if CYBT_CORRUPTION_TEST if (p_buf_index->host2bt_in_val >= BTSDIO_FWBUF_SIZE || p_buf_index->host2bt_out_val >= BTSDIO_FWBUF_SIZE || p_buf_index->bt2host_in_val >= BTSDIO_FWBUF_SIZE || p_buf_index->bt2host_out_val >= BTSDIO_FWBUF_SIZE) { - cybt_printf("cybt_get_bt_buf_index invalid buffer value\n"); + cybt_error("cybt_get_bt_buf_index invalid buffer value\n"); cybt_debug_dump(); } else { memcpy((uint8_t *) &last_buf_index, (uint8_t *) p_buf_index, sizeof(cybt_fw_membuf_index_t)); @@ -567,7 +551,7 @@ static cybt_result_t cybt_reg_read(uint32_t reg_addr, uint32_t *p_value) { return CYBT_SUCCESS; } -#if CYBT_DEBUG +#if 0 static void dump_bytes(const uint8_t *bptr, uint32_t len) { unsigned int i = 0; From d45a09039c9292023d18c788249e5c96c7ee19e7 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 19 Jun 2025 14:43:22 +0100 Subject: [PATCH 165/224] Fix ms/us confusion around watchdog time_remaining functions (#2533) Fix documention for watchdog_get_time_remaining_ms and add a new watchdog_get_time_remaining_us Fixes #2496 --- .../include/hardware/watchdog.h | 16 +++++++++++++-- src/rp2_common/hardware_watchdog/watchdog.c | 20 ++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/rp2_common/hardware_watchdog/include/hardware/watchdog.h b/src/rp2_common/hardware_watchdog/include/hardware/watchdog.h index 7ebfa60cc..b11fd78d5 100644 --- a/src/rp2_common/hardware_watchdog/include/hardware/watchdog.h +++ b/src/rp2_common/hardware_watchdog/include/hardware/watchdog.h @@ -134,14 +134,26 @@ bool watchdog_enable_caused_reboot(void); * \if rp2040_specific * On RP2040 this method returns the last value set instead of the remaining time due to a h/w bug. * \endif - * + * * @return The number of microseconds before the watchdog will reboot the chip. */ +uint32_t watchdog_get_time_remaining_us(void); + +/** + * \brief Returns the number of milliseconds before the watchdog will reboot the chip. + * \ingroup hardware_watchdog + * + * \if rp2040_specific + * On RP2040 this method returns the last value set instead of the remaining time due to a h/w bug. + * \endif + * + * @return The number of milliseconds before the watchdog will reboot the chip. + */ uint32_t watchdog_get_time_remaining_ms(void); // backwards compatibility with SDK < 2.0.0 static inline uint32_t watchdog_get_count(void) { - return watchdog_get_time_remaining_ms(); + return watchdog_get_time_remaining_us(); } #ifdef __cplusplus } diff --git a/src/rp2_common/hardware_watchdog/watchdog.c b/src/rp2_common/hardware_watchdog/watchdog.c index 45528ce43..c03620c14 100644 --- a/src/rp2_common/hardware_watchdog/watchdog.c +++ b/src/rp2_common/hardware_watchdog/watchdog.c @@ -28,16 +28,21 @@ void watchdog_update(void) { } // end::watchdog_update[] -uint32_t watchdog_get_time_remaining_ms(void) { - return watchdog_hw->ctrl & WATCHDOG_CTRL_TIME_BITS; -} - #if PICO_RP2040 -// Note, we have x2 here as the watchdog HW currently decrements twice per tick +// Note, we have x2 here as the watchdog HW currently decrements twice per tick (errata RP2040-E1) #define WATCHDOG_XFACTOR 2 #else #define WATCHDOG_XFACTOR 1 #endif + +uint32_t watchdog_get_time_remaining_us(void) { + return (watchdog_hw->ctrl & WATCHDOG_CTRL_TIME_BITS) / WATCHDOG_XFACTOR; +} + +uint32_t watchdog_get_time_remaining_ms(void) { + return (watchdog_hw->ctrl & WATCHDOG_CTRL_TIME_BITS) / (1000 * WATCHDOG_XFACTOR); +} + // tag::watchdog_enable[] // Helper function used by both watchdog_enable and watchdog_reboot void _watchdog_enable(uint32_t delay_ms, bool pause_on_debug) { @@ -60,10 +65,7 @@ void _watchdog_enable(uint32_t delay_ms, bool pause_on_debug) { if (!delay_ms) { hw_set_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_TRIGGER_BITS); } else { - load_value = delay_ms * 1000; -#if PICO_RP2040 - load_value *= 2; -#endif + load_value = delay_ms * (1000 * WATCHDOG_XFACTOR); if (load_value > WATCHDOG_LOAD_BITS) load_value = WATCHDOG_LOAD_BITS; From a24bc1330153ee725ee3820d0eda8a91146f9894 Mon Sep 17 00:00:00 2001 From: Tom <62671493+sonodima@users.noreply.github.com> Date: Thu, 19 Jun 2025 15:46:12 +0200 Subject: [PATCH 166/224] Add board header for Waveshare RP2350-USB-A (#2435) * Add definition for the Waveshare RP2350-USB-A board * Set XOSC startup delay multiplier for the RP2350-USB-A * Update waveshare_rp2350_usb_a.h Tweak to the PICO_DEFAULT_PIO_USB_DP_PIN define --------- Co-authored-by: Andrew Scheller --- .../include/boards/waveshare_rp2350_usb_a.h | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/boards/include/boards/waveshare_rp2350_usb_a.h diff --git a/src/boards/include/boards/waveshare_rp2350_usb_a.h b/src/boards/include/boards/waveshare_rp2350_usb_a.h new file mode 100644 index 000000000..5720e71bd --- /dev/null +++ b/src/boards/include/boards/waveshare_rp2350_usb_a.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +#ifndef _BOARDS_WAVESHARE_RP2350_USB_A_H +#define _BOARDS_WAVESHARE_RP2350_USB_A_H + +pico_board_cmake_set(PICO_PLATFORM, rp2350) + +// For board detection +#define WAVESHARE_RP2350_USB_A + +// On some samples, the xosc can take longer to stabilize than is usual +#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 +#endif + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 1 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- WS2812 --- +#ifndef PICO_DEFAULT_WS2812_PIN +#define PICO_DEFAULT_WS2812_PIN 16 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 6 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 7 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 2 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 3 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 4 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 5 +#endif + +// --- PIO USB --- +#ifndef WAVESHARE_RP2350_USB_A_USB_DP_PIN +#define WAVESHARE_RP2350_USB_A_USB_DP_PIN 12 +#endif +#ifndef WAVESHARE_RP2350_USB_A_USB_DM_PIN +#define WAVESHARE_RP2350_USB_A_USB_DM_PIN 13 +#endif +#define PICO_DEFAULT_PIO_USB_DP_PIN WAVESHARE_RP2350_USB_A_USB_DP_PIN + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 3 +#endif + +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) +#endif + +// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) +#define PICO_SMPS_MODE_PIN 23 + +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif From b1ca43458161164cce44b9d69820474c2cf0858b Mon Sep 17 00:00:00 2001 From: Goran Miskovic Date: Thu, 19 Jun 2025 15:57:07 +0200 Subject: [PATCH 167/224] async_context_threadsafe_background: fix incorrect mutex assertion in cross-core execute_sync() (#2528) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * async_context_threadsafe_background: fix incorrect mutex assertion in cross-core execute_sync() In multicore configurations, `async_context_threadsafe_background_execute_sync()` contained an overly strict assertion used during cross-core calls: ```c hard_assert(!recursive_mutex_enter_count(&self->lock_mutex)); ``` This check fails whenever the `lock_mutex` is held — regardless of *who* owns it — even in valid situations where the async core is processing background work. The assertion does **not check ownership**, only that the `enter_count` is zero, which leads to false-positive failures on valid cross-core calls. This patch replaces the enter-count check with a core-aware assertion: ```c hard_assert(self->lock_mutex.owner != calling_core); ``` This ensures the current core does not recursively hold the mutex, preventing deadlocks while allowing valid usage where the *other* core owns the lock. The patch ensures that both `get_core_num()` and `hard_assert()` remain inlined as in the original implementation, preserving the performance characteristics under `-Os` and `RelWithDebInfo` builds. Fixes #2527 Signed-off-by: Goran Mišković * fix indents * Update async_context_threadsafe_background.c Use pre-existing mutex owner method; add a comment * oops * typo * Update async_context_threadsafe_background.c --------- Signed-off-by: Goran Mišković Co-authored-by: Graham Sanderson --- .../async_context_threadsafe_background.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c index bce8ae726..0a5d15848 100644 --- a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c +++ b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c @@ -138,8 +138,15 @@ static void lock_release(async_context_threadsafe_background_t *self) { uint32_t async_context_threadsafe_background_execute_sync(async_context_t *self_base, uint32_t (*func)(void *param), void *param) { async_context_threadsafe_background_t *self = (async_context_threadsafe_background_t*)self_base; #if ASYNC_CONTEXT_THREADSAFE_BACKGROUND_MULTI_CORE - if (self_base->core_num != get_core_num()) { - hard_assert(!recursive_mutex_enter_count(&self->lock_mutex)); + const uint calling_core = get_core_num(); + if (self_base->core_num != calling_core) { + // This core must not hold the lock mutex, or this cross-core execute would deadlock. It is fine if the other core holds it. + // It would be a strange set of circumstances for it to do so, hence the hard_assert + + // Note that this read of the owner is not synchronized with the other core; however we only + // care about it being set to `calling_core`, which the other core will not transition + // it either from or to. + hard_assert(recursive_mutex_owner(&self->lock_mutex) != calling_core); sync_func_call_t call = {0}; call.worker.do_work = handle_sync_func_call; call.func = func; From 44527b4f08eaecb88cd9bed83f92b00e62915789 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Thu, 19 Jun 2025 09:10:07 -0500 Subject: [PATCH 168/224] fix compiler warning --- .../pico_async_context/async_context_threadsafe_background.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c index 0a5d15848..e468697d8 100644 --- a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c +++ b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c @@ -138,15 +138,14 @@ static void lock_release(async_context_threadsafe_background_t *self) { uint32_t async_context_threadsafe_background_execute_sync(async_context_t *self_base, uint32_t (*func)(void *param), void *param) { async_context_threadsafe_background_t *self = (async_context_threadsafe_background_t*)self_base; #if ASYNC_CONTEXT_THREADSAFE_BACKGROUND_MULTI_CORE - const uint calling_core = get_core_num(); - if (self_base->core_num != calling_core) { + if (self_base->core_num != get_core_num()) { // This core must not hold the lock mutex, or this cross-core execute would deadlock. It is fine if the other core holds it. // It would be a strange set of circumstances for it to do so, hence the hard_assert // Note that this read of the owner is not synchronized with the other core; however we only // care about it being set to `calling_core`, which the other core will not transition // it either from or to. - hard_assert(recursive_mutex_owner(&self->lock_mutex) != calling_core); + hard_assert(recursive_mutex_owner(&self->lock_mutex) != lock_get_caller_owner_id()); sync_func_call_t call = {0}; call.worker.do_work = handle_sync_func_call; call.func = func; From 52ec9ecd5fcd47eeacc44493f07796c9ecc34d78 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Thu, 19 Jun 2025 09:11:46 -0500 Subject: [PATCH 169/224] downgrade hard_assert to assert --- .../pico_async_context/async_context_threadsafe_background.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c index e468697d8..16571eba0 100644 --- a/src/rp2_common/pico_async_context/async_context_threadsafe_background.c +++ b/src/rp2_common/pico_async_context/async_context_threadsafe_background.c @@ -145,7 +145,7 @@ uint32_t async_context_threadsafe_background_execute_sync(async_context_t *self_ // Note that this read of the owner is not synchronized with the other core; however we only // care about it being set to `calling_core`, which the other core will not transition // it either from or to. - hard_assert(recursive_mutex_owner(&self->lock_mutex) != lock_get_caller_owner_id()); + assert(recursive_mutex_owner(&self->lock_mutex) != lock_get_caller_owner_id()); sync_func_call_t call = {0}; call.worker.do_work = handle_sync_func_call; call.func = func; From 7b4b2b760d9a8014c83cb0102a5bec2b5e5ac264 Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Thu, 19 Jun 2025 16:41:26 +0100 Subject: [PATCH 170/224] Add POWMAN_PASSWORD_BITS to pico_bootsel_via_double_reset. (#2532) Fix pico_bootsel_via_double_reset for RP2350. Signed-off-by: Phil Howard --- .../pico_bootsel_via_double_reset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_bootsel_via_double_reset/pico_bootsel_via_double_reset.c b/src/rp2_common/pico_bootsel_via_double_reset/pico_bootsel_via_double_reset.c index 8028936e2..236328271 100644 --- a/src/rp2_common/pico_bootsel_via_double_reset/pico_bootsel_via_double_reset.c +++ b/src/rp2_common/pico_bootsel_via_double_reset/pico_bootsel_via_double_reset.c @@ -97,11 +97,11 @@ static inline bool double_tap_flag_is_set(void) { } static inline void set_double_tap_flag(void) { - hw_set_bits(&powman_hw->chip_reset, POWMAN_CHIP_RESET_DOUBLE_TAP_BITS); + hw_set_bits(&powman_hw->chip_reset, POWMAN_CHIP_RESET_DOUBLE_TAP_BITS | POWMAN_PASSWORD_BITS); } static inline void clear_double_tap_flag(void) { - hw_clear_bits(&powman_hw->chip_reset, POWMAN_CHIP_RESET_DOUBLE_TAP_BITS); + hw_clear_bits(&powman_hw->chip_reset, POWMAN_CHIP_RESET_DOUBLE_TAP_BITS | POWMAN_PASSWORD_BITS); } #endif From 8fb131a70f1a83f14d1d66860820bccbd5e57067 Mon Sep 17 00:00:00 2001 From: eightycc Date: Fri, 20 Jun 2025 07:00:25 -0700 Subject: [PATCH 171/224] Fix powman powman_configure_wakeup_state and powman_get_power_state (#2516) * fix powman_get_power_state (#2506) * fix powman_configure_wakeup_state (#2511) --- src/rp2_common/hardware_powman/powman.c | 31 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/rp2_common/hardware_powman/powman.c b/src/rp2_common/hardware_powman/powman.c index 2f9b9c367..d654b84d4 100644 --- a/src/rp2_common/hardware_powman/powman.c +++ b/src/rp2_common/hardware_powman/powman.c @@ -125,7 +125,7 @@ void powman_timer_disable_gpio_1hz_sync(void) { } powman_power_state powman_get_power_state(void) { - uint32_t state_reg = powman_hw->state & POWMAN_STATE_CURRENT_BITS; + uint32_t state_reg = ~powman_hw->state & POWMAN_STATE_CURRENT_BITS; // todo we should have hardware/regs/powman.h values for these static_assert(POWMAN_POWER_DOMAIN_SRAM_BANK1 == 0, ""); static_assert(POWMAN_POWER_DOMAIN_SRAM_BANK0 == 1, ""); @@ -181,19 +181,30 @@ int powman_set_power_state(powman_power_state state) { } bool powman_configure_wakeup_state(powman_power_state sleep_state, powman_power_state wakeup_state) { - // When powman wakes up it can keep the state of the sram0 and sram1 banks. Note, it can't - // explicitly - bool valid = powman_power_state_is_domain_on(wakeup_state, POWMAN_POWER_DOMAIN_XIP_CACHE); + // Must be entering a P1 low-power state (SWCORE OFF). + bool valid = !powman_power_state_is_domain_on(sleep_state, POWMAN_POWER_DOMAIN_SWITCHED_CORE); + // Must be waking up in a P0 state (SWCORE ON). valid &= powman_power_state_is_domain_on(wakeup_state, POWMAN_POWER_DOMAIN_SWITCHED_CORE); - valid &= powman_power_state_is_domain_on(sleep_state, POWMAN_POWER_DOMAIN_SRAM_BANK0) == - powman_power_state_is_domain_on(wakeup_state, POWMAN_POWER_DOMAIN_SRAM_BANK0); - valid &= powman_power_state_is_domain_on(sleep_state, POWMAN_POWER_DOMAIN_SRAM_BANK1) == - powman_power_state_is_domain_on(wakeup_state, POWMAN_POWER_DOMAIN_SRAM_BANK1); + powman_power_state current_state = powman_get_power_state(); + bool current_sram0 = powman_power_state_is_domain_on(current_state, POWMAN_POWER_DOMAIN_SRAM_BANK0); + bool current_sram1 = powman_power_state_is_domain_on(current_state, POWMAN_POWER_DOMAIN_SRAM_BANK1); + bool sleep_sram0 = powman_power_state_is_domain_on(sleep_state, POWMAN_POWER_DOMAIN_SRAM_BANK0); + bool sleep_sram1 = powman_power_state_is_domain_on(sleep_state, POWMAN_POWER_DOMAIN_SRAM_BANK1); + bool wakeup_sram0 = powman_power_state_is_domain_on(wakeup_state, POWMAN_POWER_DOMAIN_SRAM_BANK0); + bool wakeup_sram1 = powman_power_state_is_domain_on(wakeup_state, POWMAN_POWER_DOMAIN_SRAM_BANK1); + // Sleep state cannot turn ON SRAM0 or SRAM1 if it is OFF in the current state. + if (!current_sram0) valid &= !sleep_sram0; + if (!current_sram1) valid &= !sleep_sram1; + // Wakeup state cannot turn OFF SRAM0 or SRAM1 if it is ON in the sleep state. + if (sleep_sram0) valid &= wakeup_sram0; + if (sleep_sram1) valid &= wakeup_sram1; if (valid) { + // Prepare power sequencer to power SRAM domains on wakeup. powman_clear_bits(&powman_hw->seq_cfg, POWMAN_SEQ_CFG_HW_PWRUP_SRAM0_BITS | POWMAN_SEQ_CFG_HW_PWRUP_SRAM1_BITS); uint32_t seq_cfg_set = 0; - if (!powman_power_state_is_domain_on(sleep_state, POWMAN_POWER_DOMAIN_SRAM_BANK0)) seq_cfg_set |= POWMAN_SEQ_CFG_HW_PWRUP_SRAM0_BITS; - if (!powman_power_state_is_domain_on(sleep_state, POWMAN_POWER_DOMAIN_SRAM_BANK1)) seq_cfg_set |= POWMAN_SEQ_CFG_HW_PWRUP_SRAM1_BITS; + // Sequencer SRAM power transitions from sleep to wakeup are: OFF->ON (0), ON->ON (1) and OFF->OFF (1) + if (sleep_sram0 == wakeup_sram0) seq_cfg_set |= POWMAN_SEQ_CFG_HW_PWRUP_SRAM0_BITS; + if (sleep_sram1 == wakeup_sram1) seq_cfg_set |= POWMAN_SEQ_CFG_HW_PWRUP_SRAM1_BITS; powman_set_bits(&powman_hw->seq_cfg, seq_cfg_set); } return valid; From 6f856ee4eb0a3b306522fb7738c44d3af617bb3b Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Thu, 26 Jun 2025 15:59:32 +0100 Subject: [PATCH 172/224] Add Board Header Check Action (#2519) * Add action to check board headers when modified * Fix invalid escape warning * Check for more board header errors before exiting script * Also run when action file changes * Add back newline at end of check_all_board_headers.sh * Remove python install step * `e.__str__()` -> `str(e)` --- .github/workflows/check_board.yml | 27 ++++++ tools/check_all_board_headers.sh | 7 +- tools/check_board_header.py | 139 ++++++++++++++++++------------ tools/extract_build_defines.py | 2 +- tools/extract_cmake_configs.py | 2 +- tools/extract_cmake_functions.py | 2 +- tools/extract_configs.py | 2 +- 7 files changed, 121 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/check_board.yml diff --git a/.github/workflows/check_board.yml b/.github/workflows/check_board.yml new file mode 100644 index 000000000..bd0e72344 --- /dev/null +++ b/.github/workflows/check_board.yml @@ -0,0 +1,27 @@ +name: Check Board Headers + +on: + push: + paths: + - 'src/boards/include/boards/**' + - 'tools/check_board_header.py' + - 'tools/check_all_board_headers.sh' + - '.github/workflows/check_board.yml' + pull_request: + paths: + - 'src/boards/include/boards/**' + - 'tools/check_board_header.py' + - 'tools/check_all_board_headers.sh' + - '.github/workflows/check_board.yml' + +jobs: + check-board-headers: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check Board Headers + run: | + tools/check_all_board_headers.sh diff --git a/tools/check_all_board_headers.sh b/tools/check_all_board_headers.sh index bdbe3f773..290921791 100755 --- a/tools/check_all_board_headers.sh +++ b/tools/check_all_board_headers.sh @@ -1,7 +1,12 @@ #!/bin/bash + +EXIT_CODE=0 + for HEADER in src/boards/include/boards/*.h; do tools/check_board_header.py $HEADER if [[ $? -ne 0 ]]; then - break + EXIT_CODE=1 fi done + +exit $EXIT_CODE diff --git a/tools/check_board_header.py b/tools/check_board_header.py index da7b53408..5a5c84e63 100755 --- a/tools/check_board_header.py +++ b/tools/check_board_header.py @@ -20,6 +20,14 @@ from collections import namedtuple +if sys.version_info < (3, 11): + # Python <3.11 doesn't have ExceptionGroup, so define a simple one + class ExceptionGroup(Exception): + def __init__(self, message, errors): + message += "\n" + "\n".join(str(e) for e in errors) + super().__init__(message) + + # warnings off by default, because some boards use the same pin for multiple purposes show_warnings = False @@ -65,6 +73,7 @@ def list_to_string_with(lst, joiner): def read_defines_from(header_file, defines_dict): + errors = [] with open(header_file) as fh: last_ifndef = None last_ifndef_lineno = -1 @@ -84,7 +93,7 @@ def read_defines_from(header_file, defines_dict): if m: name = m.group(1) value = m.group(2) - raise Exception("{}:{} \"// {} {}={}\" should be replaced with \"{}({}, {})\"".format(board_header, lineno, old_comment, name, value, new_macro, name, value)) + errors.append(Exception("{}:{} \"// {} {}={}\" should be replaced with \"{}({}, {})\"".format(board_header, lineno, old_comment, name, value, new_macro, name, value))) # look for "pico_board_cmake_set(BLAH_BLAH, 42)" m = re.match(r"^\s*pico_board_cmake_set\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(.*)\s*\)\s*$", line) @@ -94,11 +103,11 @@ def read_defines_from(header_file, defines_dict): value = m.group(2) # check all uppercase if name != name.upper(): - raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name))) # check for multiply-defined values if name in cmake_settings: if cmake_settings[name].value != value: - raise Exception("{}:{} Conflicting values for pico_board_cmake_set({}) ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + errors.append(Exception("{}:{} Conflicting values for pico_board_cmake_set({}) ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value))) else: if show_warnings: warnings.warn("{}:{} Multiple values for pico_board_cmake_set({}) ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) @@ -114,7 +123,7 @@ def read_defines_from(header_file, defines_dict): value = m.group(2) # check all uppercase if name != name.upper(): - raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name))) if name not in cmake_default_settings: cmake_default_settings[name] = DefineType(name, value, None, lineno) continue @@ -130,7 +139,7 @@ def read_defines_from(header_file, defines_dict): if m: validity_stack.pop() continue - + if validity_stack[-1]: # look for "#include "foo.h" m = re.match(r"""^\s*#include\s+"(.+?)"\s*$""", line) @@ -140,7 +149,7 @@ def read_defines_from(header_file, defines_dict): assert include.endswith(".h") # assume that the include is also in the boards directory assert "/" not in include or include.startswith("boards/") - read_defines_from(os.path.join(os.path.dirname(board_header), os.path.basename(include)), defines) + errors.extend(read_defines_from(os.path.join(os.path.dirname(board_header), os.path.basename(include)), defines)) continue # look for "#if BLAH_BLAH" @@ -175,11 +184,11 @@ def read_defines_from(header_file, defines_dict): value = m.group(2) # check all uppercase if name != name.upper(): - raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name))) # check that adjacent #ifndef and #define lines match up if last_ifndef_lineno + 1 == lineno: if last_ifndef != name: - raise Exception("{}:{} #ifndef {} / #define {} mismatch".format(board_header, last_ifndef_lineno, last_ifndef, name)) + errors.append(Exception("{}:{} #ifndef {} / #define {} mismatch".format(board_header, last_ifndef_lineno, last_ifndef, name))) if value: try: # most board-defines are integer values @@ -197,18 +206,21 @@ def read_defines_from(header_file, defines_dict): # check for multiply-defined values if name in defines_dict: if defines_dict[name].value != value: - raise Exception("{}:{} Conflicting definitions for {} ({} and {})".format(board_header, lineno, name, defines_dict[name].value, value)) + errors.append(Exception("{}:{} Conflicting definitions for {} ({} and {})".format(board_header, lineno, name, defines_dict[name].value, value))) else: if show_warnings: warnings.warn("{}:{} Multiple definitions for {} ({} and {})".format(board_header, lineno, name, defines_dict[name].value, value)) else: defines_dict[name] = DefineType(name, value, resolved_value, lineno) + return errors if board_header_basename == "amethyst_fpga.h": defines['PICO_RP2350'] = DefineType('PICO_RP2350', 1, 1, -1) defines['PICO_RP2350A'] = DefineType('PICO_RP2350A', 0, 0, -1) +errors = [] + with open(board_header) as header_fh: last_ifndef = None last_ifndef_lineno = -1 @@ -220,18 +232,18 @@ def read_defines_from(header_file, defines_dict): line = re.sub(r"(?<=\S)\s*//.*$", "", line) # look for board-detection comment - if re.match("^\s*// For board detection", line): + if re.match(r"^\s*// For board detection", line): board_detection_is_next = True continue # check include-suggestion - m = re.match("^\s*// This header may be included by other board headers as \"(.+?)\"", line) + m = re.match(r"""^\s*// This header may be included by other board headers as "(.+?)"$""", line) if m: include_suggestion = m.group(1) if include_suggestion == expected_include_suggestion: has_include_suggestion = True else: - raise Exception("{}:{} Suggests including \"{}\" but file is named \"{}\"".format(board_header, lineno, include_suggestion, expected_include_suggestion)) + errors.append(Exception("{}:{} Suggests including \"{}\" but file is named \"{}\"".format(board_header, lineno, include_suggestion, expected_include_suggestion))) continue # look for "// old_comment BLAH_BLAH=42" and suggest changing it to "new_macro(BLAH_BLAH, 42)" @@ -243,7 +255,7 @@ def read_defines_from(header_file, defines_dict): if m: name = m.group(1) value = m.group(2) - raise Exception("{}:{} \"// {} {}={}\" should be replaced with \"{}({}, {})\"".format(board_header, lineno, old_comment, name, value, new_macro, name, value)) + errors.append(Exception("{}:{} \"// {} {}={}\" should be replaced with \"{}({}, {})\"".format(board_header, lineno, old_comment, name, value, new_macro, name, value))) # look for "pico_board_cmake_set(BLAH_BLAH, 42)" m = re.match(r"^\s*pico_board_cmake_set\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(.*)\s*\)\s*$", line) @@ -253,10 +265,10 @@ def read_defines_from(header_file, defines_dict): value = m.group(2) # check all uppercase if name != name.upper(): - raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name))) # check for multiply-defined values if name in cmake_settings: - raise Exception("{}:{} Multiple values for pico_board_cmake_set({}) ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value)) + errors.append(Exception("{}:{} Multiple values for pico_board_cmake_set({}) ({} and {})".format(board_header, lineno, name, cmake_settings[name].value, value))) else: if value: try: @@ -275,10 +287,10 @@ def read_defines_from(header_file, defines_dict): value = m.group(2) # check all uppercase if name != name.upper(): - raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name))) # check for multiply-defined values if name in cmake_default_settings: - raise Exception("{}:{} Multiple values for pico_board_cmake_set_default({}) ({} and {})".format(board_header, lineno, name, cmake_default_settings[name].value, value)) + errors.append(Exception("{}:{} Multiple values for pico_board_cmake_set_default({}) ({} and {})".format(board_header, lineno, name, cmake_default_settings[name].value, value))) else: if value: try: @@ -300,7 +312,7 @@ def read_defines_from(header_file, defines_dict): if m: validity_stack.pop() continue - + if validity_stack[-1]: # look for "#include "foo.h" m = re.match(r"""^\s*#include\s+"(.+?)"\s*$""", line) @@ -310,7 +322,7 @@ def read_defines_from(header_file, defines_dict): assert include.endswith(".h") # assume that the include is also in the boards directory assert "/" not in include or include.startswith("boards/") - read_defines_from(os.path.join(os.path.dirname(board_header), os.path.basename(include)), defines) + errors.extend(read_defines_from(os.path.join(os.path.dirname(board_header), os.path.basename(include)), defines)) continue # look for "#if BLAH_BLAH" @@ -344,11 +356,11 @@ def read_defines_from(header_file, defines_dict): value = m.group(2) # check all uppercase if name != name.upper(): - raise Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Expected \"{}\" to be all uppercase".format(board_header, lineno, name))) # check that adjacent #ifndef and #define lines match up if last_ifndef_lineno + 1 == lineno: if last_ifndef != name: - raise Exception("{}:{} #ifndef {} / #define {} mismatch".format(board_header, last_ifndef_lineno, last_ifndef, name)) + errors.append(Exception("{}:{} #ifndef {} / #define {} mismatch".format(board_header, last_ifndef_lineno, last_ifndef, name))) if value: try: # most board-defines are integer values @@ -367,28 +379,28 @@ def read_defines_from(header_file, defines_dict): if re.match(r"^_BOARDS_(\w+)_H$", name): # check it has an #ifndef if last_ifndef_lineno +1 != lineno: - raise Exception("{}:{} Include-guard #define {} is missing an #ifndef".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Include-guard #define {} is missing an #ifndef".format(board_header, lineno, name))) if value: - raise Exception("{}:{} Include-guard #define {} shouldn't have a value".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Include-guard #define {} shouldn't have a value".format(board_header, lineno, name))) if any(defines[d].lineno >= 0 for d in defines): - raise Exception("{}:{} Include-guard #define {} should be the first define".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Include-guard #define {} should be the first define".format(board_header, lineno, name))) if name == expected_include_guard: has_include_guard = True else: - raise Exception("{}:{} Found include-guard #define {} but expected {}".format(board_header, lineno, name, expected_include_guard)) + errors.append(Exception("{}:{} Found include-guard #define {} but expected {}".format(board_header, lineno, name, expected_include_guard))) # check board-detection define if board_detection_is_next: board_detection_is_next = False if value: - raise Exception("{}:{} Board-detection #define {} shouldn't have a value".format(board_header, lineno, name)) + errors.append(Exception("{}:{} Board-detection #define {} shouldn't have a value".format(board_header, lineno, name))) # this is a bit messy because pico.h does "#define RASPBERRYPI_PICO" and metrotech_xerxes_rp2040.h does "#define XERXES_RP2040" if name.endswith(expected_board_detection) or expected_board_detection.endswith(name): has_board_detection = True else: - raise Exception("{}:{} Board-detection #define {} should end with {}".format(board_header, lineno, name, expected_board_detection)) + errors.append(Exception("{}:{} Board-detection #define {} should end with {}".format(board_header, lineno, name, expected_board_detection))) # check for multiply-defined values if name in defines: - raise Exception("{}:{} Multiple definitions for {} ({} and {})".format(board_header, lineno, name, defines[name].value, value)) + errors.append(Exception("{}:{} Multiple definitions for {} ({} and {})".format(board_header, lineno, name, defines[name].value, value))) else: defines[name] = DefineType(name, value, resolved_value, lineno) continue @@ -404,16 +416,20 @@ def read_defines_from(header_file, defines_dict): else: for setting in compulsory_cmake_settings: if setting not in cmake_settings: - raise Exception("{} is missing a pico_board_cmake_set({}, XXX) call".format(board_header, setting)) + errors.append(Exception("{} is missing a pico_board_cmake_set({}, XXX) call".format(board_header, setting))) + + # Must be raised before continuing, in case compulsory settings are missing + if errors: + raise ExceptionGroup("Errors in {}".format(board_header), errors) if cmake_settings['PICO_PLATFORM'].value == "rp2040": chip = 'RP2040' other_chip = 'RP2350' elif cmake_settings['PICO_PLATFORM'].value == "rp2350": other_chip = 'RP2040' if 'PICO_RP2350B' in defines: - raise Exception("{} sets #define {} {} (should probably be #define {} {})".format(board_header, 'PICO_RP2350B', defines['PICO_RP2350B'].resolved_value, 'PICO_RP2350A', 1 - defines['PICO_RP2350B'].resolved_value)) + errors.append(Exception("{} sets #define {} {} (should probably be #define {} {})".format(board_header, 'PICO_RP2350B', defines['PICO_RP2350B'].resolved_value, 'PICO_RP2350A', 1 - defines['PICO_RP2350B'].resolved_value))) if 'PICO_RP2350A' not in defines: - raise Exception("{} has no #define for {} (set to 1 for RP2350A, or 0 for RP2350B)".format(board_header, 'PICO_RP2350A')) + errors.append(Exception("{} has no #define for {} (set to 1 for RP2350A, or 0 for RP2350B)".format(board_header, 'PICO_RP2350A'))) else: if defines['PICO_RP2350A'].resolved_value == 1: chip = 'RP2350A' @@ -421,28 +437,33 @@ def read_defines_from(header_file, defines_dict): chip = 'RP2350B' if not board_header.endswith("amethyst_fpga.h"): if 'PICO_RP2350_A2_SUPPORTED' not in cmake_default_settings: - raise Exception("{} uses chip {} but is missing a pico_board_cmake_set_default({}, XXX) call".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) + errors.append(Exception("{} uses chip {} but is missing a pico_board_cmake_set_default({}, XXX) call".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED'))) if 'PICO_RP2350_A2_SUPPORTED' not in defines: - raise Exception("{} uses chip {} but is missing a #define {}".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED')) - if defines['PICO_RP2350_A2_SUPPORTED'].resolved_value != 1: - raise Exception("{} sets #define {} {} (should be 1)".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED', defines['PICO_RP2350_A2_SUPPORTED'].resolved_value)) + errors.append(Exception("{} uses chip {} but is missing a #define {}".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED'))) + elif defines['PICO_RP2350_A2_SUPPORTED'].resolved_value != 1: + errors.append(Exception("{} sets #define {} {} (should be 1)".format(board_header, chip, 'PICO_RP2350_A2_SUPPORTED', defines['PICO_RP2350_A2_SUPPORTED'].resolved_value))) for setting in compulsory_cmake_default_settings: if setting not in cmake_default_settings: - raise Exception("{} is missing a pico_board_cmake_set_default({}, XXX) call".format(board_header, setting)) + errors.append(Exception("{} is missing a pico_board_cmake_set_default({}, XXX) call".format(board_header, setting))) for setting in matching_cmake_default_settings: if setting in cmake_default_settings and setting not in defines: - raise Exception("{} has pico_board_cmake_set_default({}, XXX) but is missing a matching #define".format(board_header, setting)) + errors.append(Exception("{} has pico_board_cmake_set_default({}, XXX) but is missing a matching #define".format(board_header, setting))) elif setting in defines and setting not in cmake_default_settings: - raise Exception("{} has #define {} but is missing a matching pico_board_cmake_set_default({}, XXX) call".format(board_header, setting, setting)) + errors.append(Exception("{} has #define {} but is missing a matching pico_board_cmake_set_default({}, XXX) call".format(board_header, setting, setting))) elif setting in defines and setting in cmake_default_settings: if cmake_default_settings[setting].value != defines[setting].resolved_value: - raise Exception("{} has mismatched pico_board_cmake_set_default and #define values for {}".format(board_header, setting)) + errors.append(Exception("{} has mismatched pico_board_cmake_set_default and #define values for {}".format(board_header, setting))) for setting in compulsory_defines: if setting not in defines: - raise Exception("{} is missing a #define {}".format(board_header, setting)) + errors.append(Exception("{} is missing a #define {}".format(board_header, setting))) if chip is None: - raise Exception("Couldn't determine chip for {}".format(board_header)) + errors.append(Exception("Couldn't determine chip for {}".format(board_header))) + +# Must be raised before continuing, in case chip is not determined +if errors: + raise ExceptionGroup("Errors in {}".format(board_header), errors) + interfaces_json = chip_interfaces[chip] if not os.path.isfile(interfaces_json): raise Exception("{} doesn't exist".format(interfaces_json)) @@ -465,14 +486,14 @@ def read_defines_from(header_file, defines_dict): # check for other-chip defines if other_chip in name: - raise Exception("{}:{} Header is for {} and so shouldn't have settings for {} ({})".format(board_header, define.lineno, chip, other_chip, name)) + errors.append(Exception("{}:{} Header is for {} and so shouldn't have settings for {} ({})".format(board_header, define.lineno, chip, other_chip, name))) # check for pin-conflicts if name.endswith("_PIN"): if define.resolved_value is None: - raise Exception("{}:{} {} is set to an undefined value".format(board_header, define.lineno, name)) + errors.append(Exception("{}:{} {} is set to an undefined value".format(board_header, define.lineno, name))) elif not isinstance(define.resolved_value, int): - raise Exception("{}:{} {} resolves to a non-integer value {}".format(board_header, define.lineno, name, define.resolved_value)) + errors.append(Exception("{}:{} {} resolves to a non-integer value {}".format(board_header, define.lineno, name, define.resolved_value))) else: if define.resolved_value in pins and define.resolved_value == define.value: if show_warnings: @@ -480,7 +501,7 @@ def read_defines_from(header_file, defines_dict): pins[define.resolved_value].append(define) else: if define.resolved_value not in allowed_pins: - raise Exception("{}:{} Pin {} for {} isn't a valid pin-number".format(board_header, define.lineno, define.resolved_value, name)) + errors.append(Exception("{}:{} Pin {} for {} isn't a valid pin-number".format(board_header, define.lineno, define.resolved_value, name))) pins[define.resolved_value] = [define] # check for invalid DEFAULT mappings @@ -492,44 +513,52 @@ def read_defines_from(header_file, defines_dict): if interface == "WS2812": continue if interface not in allowed_interfaces: - raise Exception("{}:{} {} is defined but {} isn't in {}".format(board_header, define.lineno, name, interface, interfaces_json)) + errors.append(Exception("{}:{} {} is defined but {} isn't in {}".format(board_header, define.lineno, name, interface, interfaces_json))) + continue if instance_name not in defines: - raise Exception("{}:{} {} is defined but {} isn't defined".format(board_header, define.lineno, name, instance_name)) + errors.append(Exception("{}:{} {} is defined but {} isn't defined".format(board_header, define.lineno, name, instance_name))) + continue instance_define = defines[instance_name] instance_num = instance_define.resolved_value if instance_num not in allowed_interfaces[interface]["instances"]: - raise Exception("{}:{} {} is set to an invalid instance {}".format(board_header, instance_define.lineno, instance_define, instance_num)) + errors.append(Exception("{}:{} {} is set to an invalid instance {}".format(board_header, instance_define.lineno, instance_define, instance_num))) + continue interface_instance = allowed_interfaces[interface]["instances"][instance_num] if function not in interface_instance: - raise Exception("{}:{} {} is defined but {} isn't a valid function for {}".format(board_header, define.lineno, name, function, instance_define)) + errors.append(Exception("{}:{} {} is defined but {} isn't a valid function for {}".format(board_header, define.lineno, name, function, instance_define))) + continue if define.resolved_value not in interface_instance[function]: - raise Exception("{}:{} {} is set to {} which isn't a valid pin for {} on {} {}".format(board_header, define.lineno, name, define.resolved_value, function, interface, instance_num)) + errors.append(Exception("{}:{} {} is set to {} which isn't a valid pin for {} on {} {}".format(board_header, define.lineno, name, define.resolved_value, function, interface, instance_num))) # check that each used DEFAULT interface includes (at least) the expected pin-functions m = re.match("^PICO_DEFAULT_([A-Z0-9]+)$", name) if m: interface = m.group(1) if interface not in allowed_interfaces: - raise Exception("{}:{} {} is defined but {} isn't in {}".format(board_header, define.lineno, name, interface, interfaces_json)) + errors.append(Exception("{}:{} {} is defined but {} isn't in {}".format(board_header, define.lineno, name, interface, interfaces_json))) + continue if "expected_functions" in allowed_interfaces[interface]: expected_functions = allowed_interfaces[interface]["expected_functions"] if "required" in expected_functions: for function in expected_functions["required"]: expected_function_pin = "{}_{}_PIN".format(name, function) if expected_function_pin not in defines: - raise Exception("{}:{} {} is defined but {} isn't defined".format(board_header, define.lineno, name, expected_function_pin)) + errors.append(Exception("{}:{} {} is defined but {} isn't defined".format(board_header, define.lineno, name, expected_function_pin))) if "one_of" in expected_functions: expected_function_pins = list("{}_{}_PIN".format(name, function) for function in expected_functions["one_of"]) if not any(func_pin in defines for func_pin in expected_function_pins): - raise Exception("{}:{} {} is defined but none of {} are defined".format(board_header, define.lineno, name, list_to_string_with(expected_function_pins, "or"))) + errors.append(Exception("{}:{} {} is defined but none of {} are defined".format(board_header, define.lineno, name, list_to_string_with(expected_function_pins, "or")))) if not has_include_guard: - raise Exception("{} has no include-guard (expected {})".format(board_header, expected_include_guard)) + errors.append(Exception("{} has no include-guard (expected {})".format(board_header, expected_include_guard))) if not has_board_detection and expected_board_detection != "NONE": - raise Exception("{} has no board-detection #define (expected {})".format(board_header, expected_board_detection)) + errors.append(Exception("{} has no board-detection #define (expected {})".format(board_header, expected_board_detection))) # lots of headers don't have this #if not has_include_suggestion: # raise Exception("{} has no include-suggestion (expected {})".format(board_header, expected_include_suggestion)) +if errors: + raise ExceptionGroup("Errors in {}".format(board_header), errors) + # Check that #if / #ifdef / #ifndef / #else / #endif are correctly balanced assert len(validity_stack) == 1 and validity_stack[0] diff --git a/tools/extract_build_defines.py b/tools/extract_build_defines.py index 69181cf88..8df16ee88 100755 --- a/tools/extract_build_defines.py +++ b/tools/extract_build_defines.py @@ -28,7 +28,7 @@ # Python <3.11 doesn't have ExceptionGroup, so define a simple one class ExceptionGroup(Exception): def __init__(self, message, errors): - message += "\n" + "\n".join(e.__str__() for e in errors) + message += "\n" + "\n".join(str(e) for e in errors) super().__init__(message) logger = logging.getLogger(__name__) diff --git a/tools/extract_cmake_configs.py b/tools/extract_cmake_configs.py index 6bd5c9b0e..b86df28dc 100755 --- a/tools/extract_cmake_configs.py +++ b/tools/extract_cmake_configs.py @@ -28,7 +28,7 @@ # Python <3.11 doesn't have ExceptionGroup, so define a simple one class ExceptionGroup(Exception): def __init__(self, message, errors): - message += "\n" + "\n".join(e.__str__() for e in errors) + message += "\n" + "\n".join(str(e) for e in errors) super().__init__(message) logger = logging.getLogger(__name__) diff --git a/tools/extract_cmake_functions.py b/tools/extract_cmake_functions.py index 38e47ca15..48020768e 100755 --- a/tools/extract_cmake_functions.py +++ b/tools/extract_cmake_functions.py @@ -26,7 +26,7 @@ # Python <3.11 doesn't have ExceptionGroup, so define a simple one class ExceptionGroup(Exception): def __init__(self, message, errors): - message += "\n" + "\n".join(e.__str__() for e in errors) + message += "\n" + "\n".join(str(e) for e in errors) super().__init__(message) logger = logging.getLogger(__name__) diff --git a/tools/extract_configs.py b/tools/extract_configs.py index 71e639031..a95870c6a 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -28,7 +28,7 @@ # Python <3.11 doesn't have ExceptionGroup, so define a simple one class ExceptionGroup(Exception): def __init__(self, message, errors): - message += "\n" + "\n".join(e.__str__() for e in errors) + message += "\n" + "\n".join(str(e) for e in errors) super().__init__(message) logger = logging.getLogger(__name__) From d7c26e68e29edec56d9a95ee60a44f9a8eb78bf4 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 30 Jun 2025 08:11:17 -0500 Subject: [PATCH 173/224] add armv8m.main_soft_nofp_unaligned as a supporter clang runtime (for 20.1.0) (#2542) --- cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake b/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake index c5199e55a..da42da46e 100644 --- a/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake +++ b/cmake/preload/toolchains/pico_arm_cortex_m33_clang.cmake @@ -1,7 +1,7 @@ set(CMAKE_SYSTEM_PROCESSOR cortex-m33) # these are all the directories under LLVM embedded toolchain for ARM (newlib or pibolibc) and under llvm_libc -set(PICO_CLANG_RUNTIMES armv8m.main_soft_nofp armv8m.main-unknown-none-eabi) +set(PICO_CLANG_RUNTIMES armv8m.main_soft_nofp armv8m.main_soft_nofp_unaligned armv8m.main-unknown-none-eabi) set(PICO_COMMON_LANG_FLAGS "-mcpu=cortex-m33 --target=armv8m.main-none-eabi -mfloat-abi=softfp -march=armv8m.main+fp+dsp") set(PICO_DISASM_OBJDUMP_ARGS --mcpu=cortex-m33 --arch=armv8m.main+fp+dsp) From e5acd29d86caa2ead3b2e73f3c241ef91f0e5494 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Wed, 2 Jul 2025 17:41:25 +0300 Subject: [PATCH 174/224] Added Olimex RP2350-PICO2-XL&XXL boards (#2541) https://github.com/OLIMEX/RP2350-PICO2-XXL --- src/boards/include/boards/olimex_rp2350_xl.h | 89 +++++++++++++++ src/boards/include/boards/olimex_rp2350_xxl.h | 106 ++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 src/boards/include/boards/olimex_rp2350_xl.h create mode 100644 src/boards/include/boards/olimex_rp2350_xxl.h diff --git a/src/boards/include/boards/olimex_rp2350_xl.h b/src/boards/include/boards/olimex_rp2350_xl.h new file mode 100644 index 000000000..06d249c22 --- /dev/null +++ b/src/boards/include/boards/olimex_rp2350_xl.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// This header may be included by other board headers as "boards/olimex_rp2350_xl.h" + +#ifndef _BOARDS_OLIMEX_RP2350_XL_H +#define _BOARDS_OLIMEX_RP2350_XL_H + +pico_board_cmake_set(PICO_PLATFORM, rp2350) + +// Check https://github.com/OLIMEX/RP2350-PICO2-XXL + +// For board detection +#define OLIMEX_RP2350_XL + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 0 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 2 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 3 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 6 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 7 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 4 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 5 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (2 * 1024 * 1024)) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) +#endif + +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif diff --git a/src/boards/include/boards/olimex_rp2350_xxl.h b/src/boards/include/boards/olimex_rp2350_xxl.h new file mode 100644 index 000000000..b9c90c95f --- /dev/null +++ b/src/boards/include/boards/olimex_rp2350_xxl.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// This header may be included by other board headers as "boards/olimex_rp2350_xxl.h" + +#ifndef _BOARDS_OLIMEX_RP2350_XXL_H +#define _BOARDS_OLIMEX_RP2350_XXL_H + +pico_board_cmake_set(PICO_PLATFORM, rp2350) + +// Check https://github.com/OLIMEX/RP2350-PICO2-XXL + +// For board detection +#define OLIMEX_RP2350_XXL + +// --- RP2350 VARIANT --- +#define PICO_RP2350A 0 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 1 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 2 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 3 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 6 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 7 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 4 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 5 +#endif + +// --- XXL HAS AN SD CARD --- +#ifndef PICO_SD_CLK_PIN +#define PICO_SD_CLK_PIN 10 +#endif +#ifndef PICO_SD_CMD_PIN +#define PICO_SD_CMD_PIN 11 +#endif +#ifndef PICO_SD_DAT0_PIN +#define PICO_SD_DAT0_PIN 24 +#endif +#ifndef PICO_SD_DAT3_PIN +#define PICO_SD_DAT3_PIN 9 // DAT3 of the SD card is the chip select pin +#endif +#ifndef PICO_SD_DAT_PIN_COUNT +#define PICO_SD_DAT_PIN_COUNT 1 +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif From 214c24386ada42d9fff7b799739c6ea24ae179c0 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Wed, 2 Jul 2025 15:42:53 +0100 Subject: [PATCH 175/224] Add a "quick start" section for RISC-V to the readme (#2537) --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 4d24d9fa2..08a10402c 100644 --- a/README.md +++ b/README.md @@ -201,3 +201,23 @@ instructions for other platforms, and just in general, we recommend you see [Ras # RISC-V support on RP2350 See [Raspberry Pi Pico-series C/C++ SDK](https://rptl.io/pico-c-sdk) for information on setting up a build environment for RISC-V on RP2350. + +## RISC-V quick start + +The [pico-sdk-tools](https://github.com/raspberrypi/pico-sdk-tools/releases) repository contains some prebuilt versions of the RISC-V compiler. + +You can use these to get a working RISC-V compiler on Raspberry Pi OS for example. + +``` +wget https://github.com/raspberrypi/pico-sdk-tools/releases/download/v2.0.0-5/riscv-toolchain-14-aarch64-lin.tar.gz +sudo mkdir -p /opt/riscv/riscv-toolchain-14 +sudo chown $USER /opt/riscv/riscv-toolchain-14 +tar xvf riscv-toolchain-14-aarch64-lin.tar.gz -C /opt/riscv/riscv-toolchain-14 +``` + +To use the RISC-V compiler to build code you need to set a couple of environment variables and run cmake from fresh. + +``` +export PICO_TOOLCHAIN_PATH=/opt/riscv/riscv-toolchain-14/ +export PICO_PLATFORM=rp2350-riscv +``` From 9a4113fbbae65ee82d8cd6537963bc3d3b14bcca Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Mon, 7 Jul 2025 16:33:58 +0100 Subject: [PATCH 176/224] Lock picotool version on master to 2.1.1 (#2401) The master SDK branch (and the SDK release tags eg 2.1.1) should point to specific picotool tags, to ensure you get a compatible picotool (note this is beyond the 2.1.1 tag in master, so will just fix this for users who check out the HEAD of master) --- tools/Findpicotool.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Findpicotool.cmake b/tools/Findpicotool.cmake index e5bfaeaac..4720a79f0 100644 --- a/tools/Findpicotool.cmake +++ b/tools/Findpicotool.cmake @@ -37,7 +37,7 @@ if (NOT TARGET picotool) message("Downloading Picotool") FetchContent_Populate(picotool QUIET GIT_REPOSITORY https://github.com/raspberrypi/picotool.git - GIT_TAG develop + GIT_TAG 2.1.1 SOURCE_DIR ${picotool_INSTALL_DIR}/picotool-src BINARY_DIR ${picotool_INSTALL_DIR}/picotool-build From 4ee09729cf708de912bae17a9057ac99f6f3d3c2 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Mon, 14 Jul 2025 17:20:55 +0100 Subject: [PATCH 177/224] Use platform/generator agnostic CMake commands (#2539) * Use platform/generator agnostic CMake commands Change the README to use platform/generator agnostic commands to create and build the CMake project * review fixup * Apply suggestions from code review Co-authored-by: Andrew Scheller * Whitespace fix --------- Co-authored-by: Andrew Scheller --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 08a10402c..bb89fc0bc 100644 --- a/README.md +++ b/README.md @@ -177,12 +177,11 @@ instructions for other platforms, and just in general, we recommend you see [Ras 1. Setup a CMake build directory. For example, if not using an IDE: ``` - $ mkdir build - $ cd build - $ cmake .. - ``` + $ cmake -S . -B build + ``` + > The cmake -S flag indicates the source directory, and the -B flag tells cmake the name of the output-directory to create. This doesn't have to be named "build", you can call it whatever you want. - When building for a board other than the Raspberry Pi Pico, you should pass `-DPICO_BOARD=board_name` to the `cmake` command above, e.g. `cmake -DPICO_BOARD=pico2 ..` or `cmake -DPICO_BOARD=pico_w ..` to configure the SDK and build options accordingly for that particular board. + When building for a board other than the Raspberry Pi Pico, you should pass `-DPICO_BOARD=board_name` to the `cmake` command above, e.g. `cmake -S . -B build -DPICO_BOARD=pico2` or `cmake -S . -B build -DPICO_BOARD=pico_w` to configure the SDK and build options accordingly for that particular board. Specifying `PICO_BOARD=` sets up various compiler defines (e.g. default pin numbers for UART and other hardware) and in certain cases also enables the use of additional libraries (e.g. wireless support when building for `PICO_BOARD=pico_w`) which cannot @@ -193,8 +192,9 @@ instructions for other platforms, and just in general, we recommend you see [Ras 1. Make your target from the build directory you created. ```sh - $ make hello_world + $ cmake --build build --target hello_world ``` + > The directory-name supplied to the `--build` flag needs to match the directory-name that was passed to the `-B` flag in the earlier cmake command. 1. You now have `hello_world.elf` to load via a debugger, or `hello_world.uf2` that can be installed and run on your Raspberry Pi Pico-series device via drag and drop. From 69e018504d5ff69b3d1811e38758f0b9131bd643 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Mon, 14 Jul 2025 17:21:11 +0100 Subject: [PATCH 178/224] Add PR branch check action (#2536) --- .github/workflows/pr-check.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/pr-check.yml diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml new file mode 100644 index 000000000..6196a08e4 --- /dev/null +++ b/.github/workflows/pr-check.yml @@ -0,0 +1,28 @@ +name: Make sure PRs target the develop branch + +on: + pull_request_target: + +# By default, pull_request_target gets write permissions to the repo - this prevents that +permissions: + pull-requests: write + +jobs: + check-branch: + if: github.event.pull_request.base.ref == 'master' + runs-on: ubuntu-latest + steps: + - name: Add comment + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'Please do not submit against `master`, use `develop` instead' + }) + - name: Throw error + run: | + echo "::error title=wrong-branch::Please do not submit against 'master', use 'develop' instead" + exit 1 From b3aed37a1831ea95f1aefa410ee4299b6c0aba52 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Mon, 14 Jul 2025 17:29:28 +0100 Subject: [PATCH 179/224] Provide an easy way to disable cyw43 logging (#2535) * Provide an easy way to disable cyw43 logging All cyw43 logging uses CYW43_PRINTF by default. To disable logging you have to define this to do nothing. There's no simple way to achieve this. Make it easier by adding PICO_CYW43_LOGGING_ENABLED which can be set to zero to disable CYW43_PRINTF. Fixes #2523 * teensy style change --------- Co-authored-by: Graham Sanderson --- .../pico_cyw43_driver/include/cyw43_configport.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h b/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h index f1c00c2fb..570ba2a11 100644 --- a/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h +++ b/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h @@ -198,9 +198,18 @@ void cyw43_post_poll_hook(void); #define cyw43_free free #endif +// PICO_CONFIG: PICO_CYW43_LOGGING_ENABLED, Enable/disable CYW43_PRINTF used for logging in cyw43 components. Has no effect if CYW43_PRINTF is defined by the user, default=1, type=bool, group=pico_cyw43_driver +#ifndef PICO_CYW43_LOGGING_ENABLED +#define PICO_CYW43_LOGGING_ENABLED 1 +#endif + +#if !defined(CYW43_PRINTF) && !PICO_CYW43_LOGGING_ENABLED +#define CYW43_PRINTF(...) (void)0 +#endif + #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif From a72865be12b0d9dd06b230e3570b61c948c0cf72 Mon Sep 17 00:00:00 2001 From: Markus Gyger <182590275+magy00@users.noreply.github.com> Date: Mon, 14 Jul 2025 23:42:03 +0700 Subject: [PATCH 180/224] Allow pio_encode_sideset_opt(0, value) (#2485) --- src/rp2_common/hardware_pio/include/hardware/pio_instructions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..53349fee7 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h @@ -148,7 +148,7 @@ static inline uint pio_encode_sideset(uint sideset_bit_count, uint value) { * \return the side set bits to be ORed with an instruction encoding */ static inline uint pio_encode_sideset_opt(uint sideset_bit_count, uint value) { - valid_params_if(PIO_INSTRUCTIONS, sideset_bit_count >= 1 && sideset_bit_count <= 4); + valid_params_if(PIO_INSTRUCTIONS, sideset_bit_count >= 0 && sideset_bit_count <= 4); valid_params_if(PIO_INSTRUCTIONS, value <= ((1u << sideset_bit_count) - 1)); return 0x1000u | value << (12u - sideset_bit_count); } From 19904be31f3c9ed7879bf21f6f64e4d78910eacc Mon Sep 17 00:00:00 2001 From: rbryson74 Date: Mon, 14 Jul 2025 11:23:50 -0600 Subject: [PATCH 181/224] Update makefsdata.py to support content encoding Fixes #2548 (#2549) * Update makefsdata.py to support content encoding changed makefsdata.py slightly to allow it to recognize files that have been manually gzipped (e.g. "mysite.css.gz") to send the proper Content-Encoding information in the response headers. * Code review fix --------- Co-authored-by: Peter Harper --- src/rp2_common/pico_lwip/tools/makefsdata.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/pico_lwip/tools/makefsdata.py b/src/rp2_common/pico_lwip/tools/makefsdata.py index 9ee0d88c1..e50c898c5 100755 --- a/src/rp2_common/pico_lwip/tools/makefsdata.py +++ b/src/rp2_common/pico_lwip/tools/makefsdata.py @@ -19,7 +19,7 @@ def process_file(input_dir, file): results = [] # Check content type - content_type, _ = mimetypes.guess_type(file) + content_type, content_encoding = mimetypes.guess_type(file) if content_type is None: content_type = "application/octet-stream" @@ -53,9 +53,15 @@ def process_file(input_dir, file): comment = f"\"Content-Length: {file_size}\" ({len(data)} chars)" results.append({'data': bytes(data, "utf-8"), 'comment': comment}); - # content type - data = f"Content-Type: {content_type}\r\n\r\n" - comment = f"\"Content-Type: {content_type}\" ({len(data)} chars)" + # content type and content encoding + content_type_header = f"Content-Type: {content_type}" + if content_encoding is None: + data = f"{content_type_header}\r\n\r\n" + comment = f"\"{content_type_header}\" ({len(data)} chars)" + else: + content_encoding_header = f"Content-Encoding: {content_encoding}" + data = f"{content_type_header}\r\n{content_encoding_header}\r\n\r\n" + comment = f"\"{content_type_header} {content_encoding_header}\" ({len(data)} chars)" results.append({'data': bytes(data, "utf-8"), 'comment': comment}); # file contents From d2cdf6c953e25b559275726afa856691c6346650 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 15 Jul 2025 15:09:36 -0500 Subject: [PATCH 182/224] add pioasm --version, and print version number in generated files (#2554) * add pioasm --version, and print version number in generated files * Hook up pio version string in Bazel build --------- Co-authored-by: Armando Montanez --- .../include/hardware/pio_instructions.h | 4 ++++ test/kitchen_sink/BUILD.bazel | 7 ++++++- test/kitchen_sink/CMakeLists.txt | 4 ++++ test/kitchen_sink/trivial.pio | 3 +++ tools/Findpioasm.cmake | 1 + tools/pioasm/BUILD.bazel | 12 +++++++++++ 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 ++++++++++++++ 14 files changed, 98 insertions(+), 9 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 53349fee7..edb0ef31a 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/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/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/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 = [ 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 d70cccd56193192c1b78233e96302e906b61d0b6 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Tue, 15 Jul 2025 22:53:05 +0100 Subject: [PATCH 183/224] Add FLASH option to pico_package_uf2_output (#2545) * Add FLASH option to pico_package_uf2_output Allows passing FLASH instead of 0x10000000 (eg pico_package_uf2_output(hello_serial FLASH)) * Add `pico_ensure_load_map` function * Update tools/CMakeLists.txt * Remove FLASH option and just make PACKADDR optional --- tools/CMakeLists.txt | 46 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 7a0b56160..5a6795ef2 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -95,6 +95,12 @@ define_property(TARGET BRIEF_DOCS "Extra arguments to pass to uf2 conversion" FULL_DOCS "Extra arguments to pass to uf2 conversion" ) +define_property(TARGET + PROPERTY PICOTOOL_LOAD_MAP + INHERITED + BRIEF_DOCS "Ensure a load map is added" + FULL_DOCS "Ensure a load map is added" +) # Check pioasm is installed, or build it if not installed function(pico_init_pioasm) @@ -267,19 +273,41 @@ function(pico_generate_pio_header TARGET) endif() endfunction() -# pico_package_uf2_output(TARGET PACKADDR) +# pico_ensure_load_map(TARGET) +# \brief\ Ensure a load map is added to the target. +# This can be used to ensure a load map is present, so the bootrom knows where +# to load the binary if it's stored in a different location (e.g. a packaged +# binary). +# +# This sets the target property PICOTOOL_LOAD_MAP to true. +function(pico_ensure_load_map TARGET) + picotool_check_configurable(${TARGET}) + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_LOAD_MAP true + ) +endfunction() + +# pico_package_uf2_output(TARGET [PACKADDR]) # \brief\ Package a UF2 output to be written to the PACKADDR address. # This can be used with a no_flash binary to write the UF2 to flash when dragging & # dropping, and it will be copied to SRAM by the bootrom before execution. # -# This sets the target property PICOTOOL_UF2_PACKAGE_ADDR to PACKADDR. +# This sets the target property PICOTOOL_UF2_PACKAGE_ADDR to PACKADDR and calls +# pico_ensure_load_map(TARGET). # -# \param\ PACKADDR The address to package the UF2 to -function(pico_package_uf2_output TARGET PACKADDR) +# \param\ PACKADDR The address to package the UF2 to, defaults to start of flash +function(pico_package_uf2_output TARGET) picotool_check_configurable(${TARGET}) - set_target_properties(${TARGET} PROPERTIES - PICOTOOL_UF2_PACKAGE_ADDR ${PACKADDR} - ) + if (ARGC EQUAL 1) + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_UF2_PACKAGE_ADDR 0x10000000 + ) + else() + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_UF2_PACKAGE_ADDR ${ARGV1} + ) + endif() + pico_ensure_load_map(${TARGET}) endfunction() # pico_set_otp_key_output_file(TARGET OTPFILE) @@ -629,7 +657,7 @@ function(picotool_postprocess_binary TARGET) if (NOT otp_file) set(otp_file "") endif() - get_target_property(uf2_package_addr ${TARGET} PICOTOOL_UF2_PACKAGE_ADDR) + get_target_property(ensure_load_map ${TARGET} PICOTOOL_LOAD_MAP) # Embed PT properties get_target_property(picotool_embed_pt ${TARGET} PICOTOOL_EMBED_PT) @@ -668,7 +696,7 @@ function(picotool_postprocess_binary TARGET) # Signing/hashing/load maps for packaging if (picotool_sign_output OR picotool_hash_output OR - uf2_package_addr OR + ensure_load_map OR extra_process_args) # We don't need the extra end block, as picotool seal will add one target_compile_definitions(${TARGET} PRIVATE PICO_CRT0_INCLUDE_PICOBIN_END_BLOCK=0) From c1981f5253956a617fd7ae14b5ebcf11c000ca1e Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Wed, 16 Jul 2025 14:16:02 +0100 Subject: [PATCH 184/224] Fix Windows CI (#2563) Ninja is pre-installed on all Windows runners --- .github/workflows/choco_packages.config | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/choco_packages.config b/.github/workflows/choco_packages.config index 9f1dea0ec..116f47f86 100644 --- a/.github/workflows/choco_packages.config +++ b/.github/workflows/choco_packages.config @@ -2,5 +2,4 @@ - From e62cd02a1bd453803d9dda384a4e74c81c9f9e20 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Wed, 16 Jul 2025 14:17:16 +0100 Subject: [PATCH 185/224] Powman fix (#2499) * Fix powman_timer_use_gpio Fixes #2471 * Fix docs for clock_gpio_init etc for RP2350 You can also use gpios 13 and 15 on RP2350 * macro-ify the mapping from GPI to ext_time_ref_source - note i kept this private for now, as it's a bit murky --------- Co-authored-by: graham sanderson --- .../hardware_clocks/include/hardware/clocks.h | 39 +++++++++++++++++-- src/rp2_common/hardware_powman/powman.c | 17 +++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/rp2_common/hardware_clocks/include/hardware/clocks.h b/src/rp2_common/hardware_clocks/include/hardware/clocks.h index ee8e95535..4376f7caf 100644 --- a/src/rp2_common/hardware_clocks/include/hardware/clocks.h +++ b/src/rp2_common/hardware_clocks/include/hardware/clocks.h @@ -399,7 +399,18 @@ void clocks_enable_resus(resus_callback_t resus_callback); /*! \brief Output an optionally divided clock to the specified gpio pin. * \ingroup hardware_clocks * - * \param gpio The GPIO pin to output the clock to. Valid GPIOs are: 21, 23, 24, 25. These GPIOs are connected to the GPOUT0-3 clock generators. + * \if rp2040_specific + * On RP2040 valid GPIOs are 21, 23, 24, 25. + * These GPIOs are connected to the GPOUT0-3 clock generators. + * \endif + * \if rp2350_specific + * On RP2350 valid GPIOs are 13, 15, 21, 23, 24, 25. + * GPIOs 13 and 21 are connected to the GPOUT0 clock generator. + * GPIOs 15 and 23 are connected to the GPOUT1 clock generator. + * GPIOs 24 and 25 are connected to the GPOUT2-3 clock generators. + * \endif + * + * \param gpio The GPIO pin to output the clock to. * \param src The source clock. See the register field CLOCKS_CLK_GPOUT0_CTRL_AUXSRC for a full list. The list is the same for each GPOUT clock generator. * \param div_int The integer part of the value to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock. This is in range of 1..2^24-1 on RP2040 * and 1..2^16-1 on RP2350 @@ -410,7 +421,18 @@ void clock_gpio_init_int_frac16(uint gpio, uint src, uint32_t div_int, uint16_t /*! \brief Output an optionally divided clock to the specified gpio pin. * \ingroup hardware_clocks * - * \param gpio The GPIO pin to output the clock to. Valid GPIOs are: 21, 23, 24, 25. These GPIOs are connected to the GPOUT0-3 clock generators. + * * \if rp2040_specific + * On RP2040 valid GPIOs are 21, 23, 24, 25. + * These GPIOs are connected to the GPOUT0-3 clock generators. + * \endif + * \if rp2350_specific + * On RP2350 valid GPIOs are 13, 15, 21, 23, 24, 25. + * GPIOs 13 and 21 are connected to the GPOUT0 clock generator. + * GPIOs 15 and 23 are connected to the GPOUT1 clock generator. + * GPIOs 24 and 25 are connected to the GPOUT2-3 clock generators. + * \endif + * + * \param gpio The GPIO pin to output the clock to. * \param src The source clock. See the register field CLOCKS_CLK_GPOUT0_CTRL_AUXSRC for a full list. The list is the same for each GPOUT clock generator. * \param div_int The integer part of the value to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock. This is in range of 1..2^24-1 on RP2040 * and 1..2^16-1 on RP2350 @@ -428,7 +450,18 @@ static inline void clock_gpio_init_int_frac(uint gpio, uint src, uint32_t div_in /*! \brief Output an optionally divided clock to the specified gpio pin. * \ingroup hardware_clocks * - * \param gpio The GPIO pin to output the clock to. Valid GPIOs are: 21, 23, 24, 25. These GPIOs are connected to the GPOUT0-3 clock generators. + * \if rp2040_specific + * On RP2040 valid GPIOs are 21, 23, 24, 25. + * These GPIOs are connected to the GPOUT0-3 clock generators. + * \endif + * \if rp2350_specific + * On RP2350 valid GPIOs are 13, 15, 21, 23, 24, 25. + * GPIOs 13 and 21 are connected to the GPOUT0 clock generator. + * GPIOs 15 and 23 are connected to the GPOUT1 clock generator. + * GPIOs 24 and 25 are connected to the GPOUT2-3 clock generators. + * \endif + * + * \param gpio The GPIO pin to output the clock to. * \param src The source clock. See the register field CLOCKS_CLK_GPOUT0_CTRL_AUXSRC for a full list. The list is the same for each GPOUT clock generator. * \param div The float amount to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock. */ diff --git a/src/rp2_common/hardware_powman/powman.c b/src/rp2_common/hardware_powman/powman.c index d654b84d4..4af59f502 100644 --- a/src/rp2_common/hardware_powman/powman.c +++ b/src/rp2_common/hardware_powman/powman.c @@ -97,12 +97,25 @@ void powman_timer_set_1khz_tick_source_xosc_with_hz(uint32_t xosc_freq_hz) { } } +#ifndef GPIO_TO_POWMAN_EXT_TIME_REF_SOURCE +#define GPIO_TO_POWMAN_EXT_TIME_REF_SOURCE(gpio, default_ext_time_ref_source) \ + ((gpio) == 12 ? 0 : \ + ((gpio) == 20 ? 1 : \ + ((gpio) == 14 ? 2 : \ + ((gpio) == 22 ? 3 : \ + (default_ext_time_ref_source))))) +#endif + +static inline uint32_t gpio_to_powman_ext_time_ref_source(uint gpio, uint32_t default_ext_time_ref_source) { + return GPIO_TO_POWMAN_EXT_TIME_REF_SOURCE(gpio, ({invalid_params_if(HARDWARE_POWMAN, true); default_ext_time_ref_source;})); +} + static void powman_timer_use_gpio(uint32_t gpio, uint32_t use, uint32_t using) { bool was_running = powman_timer_is_running(); if (was_running) powman_timer_stop(); - invalid_params_if(HARDWARE_POWMAN, !((gpio == 12) || (gpio == 14) || (gpio == 20) || (gpio == 22))); + uint32_t source = gpio_to_powman_ext_time_ref_source(gpio, 0); gpio_set_input_enabled(gpio, true); - powman_write(&powman_hw->ext_time_ref, gpio); + powman_write(&powman_hw->ext_time_ref, source); powman_set_bits(&powman_hw->timer, use); if (was_running) { powman_timer_start(); From c7f37fc2113e7c753ab7834bef23006ffce4d72f Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 16 Jul 2025 08:17:40 -0500 Subject: [PATCH 186/224] make gpio_acknowledge_irq inline (#2562) --- src/rp2_common/hardware_gpio/gpio.c | 5 ----- src/rp2_common/hardware_gpio/include/hardware/gpio.h | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/rp2_common/hardware_gpio/gpio.c b/src/rp2_common/hardware_gpio/gpio.c index 2c4e91d40..0a7bf90fa 100644 --- a/src/rp2_common/hardware_gpio/gpio.c +++ b/src/rp2_common/hardware_gpio/gpio.c @@ -253,11 +253,6 @@ void gpio_set_dormant_irq_enabled(uint gpio, uint32_t events, bool enabled) { _gpio_set_irq_enabled(gpio, events, enabled, irq_ctrl_base); } -void gpio_acknowledge_irq(uint gpio, uint32_t events) { - check_gpio_param(gpio); - io_bank0_hw->intr[gpio / 8] = events << (4 * (gpio % 8)); -} - #define DEBUG_PIN_MASK (((1u << PICO_DEBUG_PIN_COUNT)-1) << PICO_DEBUG_PIN_BASE) void gpio_debug_pins_init(void) { gpio_init_mask(DEBUG_PIN_MASK); diff --git a/src/rp2_common/hardware_gpio/include/hardware/gpio.h b/src/rp2_common/hardware_gpio/include/hardware/gpio.h index f05bc0002..3894acaa8 100644 --- a/src/rp2_common/hardware_gpio/include/hardware/gpio.h +++ b/src/rp2_common/hardware_gpio/include/hardware/gpio.h @@ -570,7 +570,10 @@ static inline uint32_t gpio_get_irq_event_mask(uint gpio) { * \note For callbacks set with \ref gpio_set_irq_enabled_with_callback, or \ref gpio_set_irq_callback, this function is called automatically. * \param event_mask Bitmask of events to clear. See \ref gpio_irq_level for details. */ -void gpio_acknowledge_irq(uint gpio, uint32_t event_mask); +static inline void gpio_acknowledge_irq(uint gpio, uint32_t event_mask) { + check_gpio_param(gpio); + io_bank0_hw->intr[gpio / 8] = event_mask << (4 * (gpio % 8)); +} /*! \brief Adds a raw GPIO IRQ handler for the specified GPIOs on the current core * \ingroup hardware_gpio From 8fd7c60f093bba9debeed70b57ca3f9844bb2d00 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Thu, 17 Jul 2025 06:28:59 -0700 Subject: [PATCH 187/224] Add WeAct RP2350B Core board support. (#2570) * Add WeAct RP2350B Core board support. * Update to new format. --- .../boards/weact_studio_rp2350b_core.h | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/boards/include/boards/weact_studio_rp2350b_core.h diff --git a/src/boards/include/boards/weact_studio_rp2350b_core.h b/src/boards/include/boards/weact_studio_rp2350b_core.h new file mode 100644 index 000000000..5e05e24a5 --- /dev/null +++ b/src/boards/include/boards/weact_studio_rp2350b_core.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// This header may be included by other board headers as "boards/weact_studio_rp2350b_core.h" + +#ifndef _BOARDS_WEACT_STUDIO_RP2350B_CORE_H +#define _BOARDS_WEACT_STUDIO_RP2350B_CORE_H + +pico_board_cmake_set(PICO_PLATFORM, rp2350) + +// For board detection +#define WEACT_STUDIO_RP2350B_CORE + +// --- BOARD SPECIFIC --- +#define WEACT_STUDIO_RP2350B_USER_SW_PIN 23 +#define WEACT_STUDIO_RP2350B_PSRAM_CS_PIN 0 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 12 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 13 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 8 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 9 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN 18 +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN 19 +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN 16 +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN 17 +#endif + +// --- FLASH --- +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +pico_board_cmake_set_default(PICO_FLASH_SIZE_BYTES, (16 * 1024 * 1024)) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +// --- RP2350 VARIANT --- +// This means RP2350B. +#define PICO_RP2350A 0 + +pico_board_cmake_set_default(PICO_RP2350_A2_SUPPORTED, 1) +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +#endif From 820a33a39fe424bd6554286710321e7e2ed13db6 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:21:24 +0100 Subject: [PATCH 188/224] Add Wi-Fi firmware partition support for Pico 2 W (#1969) --- .../boot_uf2_headers/include/boot/uf2.h | 10 +- src/rp2_common/pico_cyw43_driver/BUILD.bazel | 10 ++ .../pico_cyw43_driver/CMakeLists.txt | 84 +++++++++++++ .../pico_cyw43_driver/cyw43_driver.c | 110 ++++++++++++++++-- .../pico_cyw43_driver/cyw43_firmware.py | 44 +++++++ .../include/cyw43_configport.h | 4 + .../include/cyw43_partition_firmware.h | 15 +++ .../include/pico/cyw43_driver.h | 8 ++ .../pico_cyw43_driver/wifi_firmware.S | 65 +++++++++++ .../pico_cyw43_driver/wifi_firmware.ld | 14 +++ src/rp2_common/pico_cyw43_driver/wifi_pt.json | 52 +++++++++ 11 files changed, 407 insertions(+), 9 deletions(-) create mode 100644 src/rp2_common/pico_cyw43_driver/cyw43_firmware.py create mode 100644 src/rp2_common/pico_cyw43_driver/include/cyw43_partition_firmware.h create mode 100644 src/rp2_common/pico_cyw43_driver/wifi_firmware.S create mode 100644 src/rp2_common/pico_cyw43_driver/wifi_firmware.ld create mode 100644 src/rp2_common/pico_cyw43_driver/wifi_pt.json diff --git a/src/common/boot_uf2_headers/include/boot/uf2.h b/src/common/boot_uf2_headers/include/boot/uf2.h index ffdcb90d1..279d4a131 100644 --- a/src/common/boot_uf2_headers/include/boot/uf2.h +++ b/src/common/boot_uf2_headers/include/boot/uf2.h @@ -26,13 +26,21 @@ #define UF2_FLAG_MD5_PRESENT 0x00004000u #define UF2_FLAG_EXTENSION_FLAGS_PRESENT 0x00008000u +// Extra family IDs +#define CYW43_FIRMWARE_FAMILY_ID 0xe48bff55u + +// Bootrom supported family IDs #define RP2040_FAMILY_ID 0xe48bff56u #define ABSOLUTE_FAMILY_ID 0xe48bff57u #define DATA_FAMILY_ID 0xe48bff58u #define RP2350_ARM_S_FAMILY_ID 0xe48bff59u #define RP2350_RISCV_FAMILY_ID 0xe48bff5au #define RP2350_ARM_NS_FAMILY_ID 0xe48bff5bu -#define FAMILY_ID_MAX 0xe48bff5bu +#define BOOTROM_FAMILY_ID_MIN RP2040_FAMILY_ID +#define BOOTROM_FAMILY_ID_MAX RP2350_ARM_NS_FAMILY_ID + +// Defined for backwards compatibility +#define FAMILY_ID_MAX BOOTROM_FAMILY_ID_MAX // 04 e3 57 99 #define UF2_EXTENSION_RP2_IGNORE_BLOCK 0x9957e304 diff --git a/src/rp2_common/pico_cyw43_driver/BUILD.bazel b/src/rp2_common/pico_cyw43_driver/BUILD.bazel index 23bec36a7..3810b27c2 100644 --- a/src/rp2_common/pico_cyw43_driver/BUILD.bazel +++ b/src/rp2_common/pico_cyw43_driver/BUILD.bazel @@ -83,3 +83,13 @@ pico_generate_pio_header( name = "cyw43_bus_pio", srcs = ["cyw43_bus_pio_spi.pio"], ) + +# TODO: https://github.com/raspberrypi/pico-sdk/issues/2055 Support storing +# Wi-Fi firmware in a separate partition +filegroup( + name = "pico_use_partition_firmware", + srcs = [ + "wifi_firmware.S", + "include/cyw43_partition_firmware.h", + ] +) diff --git a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt index a7570a294..6334fc843 100644 --- a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt +++ b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt @@ -165,5 +165,89 @@ if (EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE}) ) endfunction() + set(PICO_CYW43_DRIVER_CURRENT_PATH ${CMAKE_CURRENT_LIST_DIR}) + pico_register_common_scope_var(PICO_CYW43_DRIVER_CURRENT_PATH) + pico_promote_common_scope_vars() + + # pico_use_wifi_firmware_partition(TARGET [NO_EMBEDDED_PT]) + # \brief\ Use a partition for the Wi-Fi firmware + # + # This will read the CYW43 firmware from a partition with the ID 0x776966696669726d, + # instead of embedding the firmware blob in the binary. By default it will also embed + # a compatible partition table in the binary, but this can be disabled by passing the + # NO_EMBEDDED_PT argument (for example, if you need to chain into the binary, it + # can't contain a partition table). + # + # \param\ NO_EMBEDDED_PT If set, will not embed a partition table in the binary + function(pico_use_wifi_firmware_partition TARGET) + set(options NO_EMBEDDED_PT) + cmake_parse_arguments(PARSE_ARGV 1 OPTS "${options}" "" "") + if (PICO_PLATFORM STREQUAL "rp2040") + message(FATAL_ERROR "RP2040 does not support storing wi-fi firmware in partitions") + endif() + target_compile_definitions(${TARGET} PRIVATE CYW43_USE_FIRMWARE_PARTITION=1) + + if (NOT OPTS_NO_EMBEDDED_PT) + get_target_property(picotool_embed_pt ${TARGET} PICOTOOL_EMBED_PT) + if (NOT picotool_embed_pt) + pico_embed_pt_in_binary(${TARGET} ${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_pt.json) + endif() + endif() + + find_package (Python3 REQUIRED COMPONENTS Interpreter) + + # CYW43 firmware blob + add_custom_target(${TARGET}_firmware_blob DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/firmware_blob.S) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/firmware_blob.S + COMMAND ${Python3_EXECUTABLE} ${PICO_CYW43_DRIVER_CURRENT_PATH}/cyw43_firmware.py ${PICO_CYW43_DRIVER_PATH}/firmware/wb43439A0_7_95_49_00_combined.h ${CMAKE_CURRENT_BINARY_DIR}/firmware_blob.S + ) + + # Create UF2s for regular and TBYB firmwares + add_executable(${TARGET}_firmware + ${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.S) + add_executable(${TARGET}_firmware_tbyb + ${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.S) + + add_dependencies(${TARGET}_firmware ${TARGET}_firmware_blob) + add_dependencies(${TARGET}_firmware_tbyb ${TARGET}_firmware_blob) + + target_include_directories(${TARGET}_firmware PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_include_directories(${TARGET}_firmware_tbyb PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + + target_compile_definitions(${TARGET}_firmware PRIVATE + NO_PICO_PLATFORM=1 + ) + target_compile_definitions(${TARGET}_firmware_tbyb PRIVATE + NO_PICO_PLATFORM=1 + PICO_CRT0_IMAGE_TYPE_TBYB=1 + ) + + target_link_options(${TARGET}_firmware PRIVATE -nostartfiles -nodefaultlibs LINKER:--script=${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.ld) + target_link_options(${TARGET}_firmware_tbyb PRIVATE -nostartfiles -nodefaultlibs LINKER:--script=${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.ld) + + target_link_libraries(${TARGET}_firmware boot_picobin_headers) + target_link_libraries(${TARGET}_firmware_tbyb boot_picobin_headers) + + get_target_property(hasSigfile ${TARGET} PICOTOOL_SIGFILE) + if (hasSigfile) + pico_sign_binary(${TARGET}_firmware ${sigfile}) + pico_sign_binary(${TARGET}_firmware_tbyb ${sigfile}) + endif() + + pico_hash_binary(${TARGET}_firmware) + pico_hash_binary(${TARGET}_firmware_tbyb) + + pico_set_uf2_family(${TARGET}_firmware cyw43-firmware) + pico_set_uf2_family(${TARGET}_firmware_tbyb cyw43-firmware) + + pico_package_uf2_output(${TARGET}_firmware 0x10000000) + pico_package_uf2_output(${TARGET}_firmware_tbyb 0x10000000) + + pico_add_extra_outputs(${TARGET}_firmware) + pico_add_extra_outputs(${TARGET}_firmware_tbyb) + + add_dependencies(${TARGET} + ${TARGET}_firmware ${TARGET}_firmware_tbyb) + endfunction() endif() diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c index 308d649d9..6287428f3 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c @@ -19,7 +19,18 @@ #define CYW43_SLEEP_CHECK_MS 50 #endif -static async_context_t *cyw43_async_context; +static async_context_t *cyw43_async_context = NULL; + +#if CYW43_USE_FIRMWARE_PARTITION + #include "pico/bootrom.h" + #include "hardware/flash.h" + #include "boot/picobin.h" + #include + + int32_t cyw43_wifi_fw_len; + int32_t cyw43_clm_len; + uintptr_t fw_data; +#endif static void cyw43_sleep_timeout_reached(async_context_t *context, async_at_time_worker_t *worker); static void cyw43_do_poll(async_context_t *context, async_when_pending_worker_t *worker); @@ -104,6 +115,87 @@ static void cyw43_sleep_timeout_reached(async_context_t *context, __unused async } bool cyw43_driver_init(async_context_t *context) { +#if CYW43_USE_FIRMWARE_PARTITION + uint32_t buffer[(16 * 4) + 1] = {}; // maximum of 16 partitions, each with maximum of 4 words returned, plus 1 + int ret = rom_get_partition_table_info(buffer, count_of(buffer), PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID); + + assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID)); + + if (ret > 0) { + int i = 1; + int p = 0; + int picked_p = -1; + while (i < ret) { + i++; + uint32_t flags_and_permissions = buffer[i++]; + bool has_id = (flags_and_permissions & PICOBIN_PARTITION_FLAGS_HAS_ID_BITS); + if (has_id) { + uint64_t id = 0; + id |= buffer[i++]; + id |= ((uint64_t)(buffer[i++]) << 32ull); + if (id == CYW43_FIRMWARE_PARTITION_ID) { + picked_p = p; + break; + } + } + + p++; + } + + if (picked_p >= 0) { + #ifdef __riscv + // Increased bootrom stack is required for this function + bootrom_stack_t stack = { + .base = malloc(0x400), + .size = 0x400 + }; + rom_set_bootrom_stack(&stack); + #endif + uint32_t* workarea = malloc(0x1000); + picked_p = rom_pick_ab_update_partition(workarea, 0x1000, picked_p); + free(workarea); + #ifdef __riscv + // Reset bootrom stack + rom_set_bootrom_stack(&stack); + free(stack.base); + #endif + + if (picked_p < 0) { + if (picked_p == BOOTROM_ERROR_NOT_FOUND) { + CYW43_DEBUG("Chosen CYW43 firmware partition was not verified\n"); + } else if (picked_p == BOOTROM_ERROR_NOT_PERMITTED) { + CYW43_DEBUG("Too many update boots going on at once\n"); + } + return false; + } + + CYW43_DEBUG("Chosen CYW43 firmware in partition %d\n", picked_p); + int ret = rom_get_partition_table_info(buffer, count_of(buffer), PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION | (picked_p << 24)); + assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION)); + assert(ret == 3); + + uint32_t location_and_permissions = buffer[1]; + uint32_t saddr = ((location_and_permissions >> PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_LSB) & 0x1fffu) * FLASH_SECTOR_SIZE; + uint32_t eaddr = (((location_and_permissions >> PICOBIN_PARTITION_LOCATION_LAST_SECTOR_LSB) & 0x1fffu) + 1) * FLASH_SECTOR_SIZE; + // Starts with metadata block + while(saddr < eaddr && *(uint32_t*)(XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE + saddr) != PICOBIN_BLOCK_MARKER_END) { + saddr += 4; + } + saddr += 4; + // Now onto data + cyw43_wifi_fw_len = *(uint32_t*)(XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE + saddr); + cyw43_clm_len = *(uint32_t*)(XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE + saddr + 4); + fw_data = XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE + saddr + 8; + } else { + CYW43_DEBUG("No CYW43 firmware partition found, so cannot get firmware from partition\n"); + return false; + } + } else { + CYW43_DEBUG("No partition table, so cannot get firmware from partition - get_partition_table_info returned %d\n", ret); + return false; + } + +#endif cyw43_init(&cyw43_state); cyw43_async_context = context; // we need the IRQ to be on the same core as the context, because we need to be able to enable/disable the IRQ @@ -114,13 +206,15 @@ bool cyw43_driver_init(async_context_t *context) { } void cyw43_driver_deinit(async_context_t *context) { - assert(context == cyw43_async_context); - async_context_remove_at_time_worker(context, &sleep_timeout_worker); - async_context_remove_when_pending_worker(context, &cyw43_poll_worker); - // the IRQ IS on the same core as the context, so must be de-initialized there - async_context_execute_sync(context, cyw43_irq_deinit, NULL); - cyw43_deinit(&cyw43_state); - cyw43_async_context = NULL; + if (cyw43_async_context != NULL) { + assert(context == cyw43_async_context); + async_context_remove_at_time_worker(context, &sleep_timeout_worker); + async_context_remove_when_pending_worker(context, &cyw43_poll_worker); + // the IRQ IS on the same core as the context, so must be de-initialized there + async_context_execute_sync(context, cyw43_irq_deinit, NULL); + cyw43_deinit(&cyw43_state); + cyw43_async_context = NULL; + } } // todo maybe add an #ifdef in cyw43_driver diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_firmware.py b/src/rp2_common/pico_cyw43_driver/cyw43_firmware.py new file mode 100644 index 000000000..218ec3cd2 --- /dev/null +++ b/src/rp2_common/pico_cyw43_driver/cyw43_firmware.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2024 Raspberry Pi (Trading) Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause + +import sys +import re + +assert len(sys.argv) == 3 + +cyw43_wifi_fw_len = -1 +cyw43_clm_len = -1 + +with open(sys.argv[1], "r") as f: + data = f.read() + statements = data.split(";") + for line in statements[1].split("\n"): + if "#define CYW43_WIFI_FW_LEN" in line: + matches = re.search(r"#define\s+\S+\s+\((\S+)\)", line) + cyw43_wifi_fw_len = int(matches[1]) + elif "#define CYW43_CLM_LEN" in line: + matches = re.search(r"#define\s+\S+\s+\((\S+)\)", line) + cyw43_clm_len = int(matches[1]) + if cyw43_wifi_fw_len > 0 and cyw43_clm_len > 0: + break + data = statements[0] + bits = data.split(",") + bits[0] = bits[0].split("{")[-1] + bits[-1] = bits[-1].split("}")[0] + for i in range(len(bits)): + bits[i] = bits[i].strip() + bits[i] = bits[i].strip(',') + bits[i] = int(bits[i], base=0) + +data = ( + cyw43_wifi_fw_len.to_bytes(4, 'little', signed=True) + + cyw43_clm_len.to_bytes(4, 'little', signed=True) + + bytearray(bits) +) + +with open(sys.argv[2], "w") as f: + for b in data: + f.write(f".byte 0x{b:02x}\n") diff --git a/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h b/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h index 570ba2a11..59b7d240e 100644 --- a/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h +++ b/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h @@ -63,12 +63,16 @@ extern "C" { #endif #ifndef CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE +#if CYW43_USE_FIRMWARE_PARTITION +#define CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE "cyw43_partition_firmware.h" +#else #if CYW43_ENABLE_BLUETOOTH #define CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE "wb43439A0_7_95_49_00_combined.h" #else #define CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE "w43439A0_7_95_49_00_combined.h" #endif #endif +#endif #ifndef CYW43_WIFI_NVRAM_INCLUDE_FILE #define CYW43_WIFI_NVRAM_INCLUDE_FILE "wifi_nvram_43439.h" diff --git a/src/rp2_common/pico_cyw43_driver/include/cyw43_partition_firmware.h b/src/rp2_common/pico_cyw43_driver/include/cyw43_partition_firmware.h new file mode 100644 index 000000000..5df9eb5e8 --- /dev/null +++ b/src/rp2_common/pico_cyw43_driver/include/cyw43_partition_firmware.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +extern int cyw43_wifi_fw_len; +extern int cyw43_clm_len; + +#define CYW43_WIFI_FW_LEN (cyw43_wifi_fw_len) +#define CYW43_CLM_LEN (cyw43_clm_len) +extern uintptr_t fw_data; + +#include "boot/picobin.h" +#include "pico/bootrom.h" diff --git a/src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h b/src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h index 4d17c4b32..cd692963e 100644 --- a/src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h +++ b/src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h @@ -20,6 +20,14 @@ #include "cyw43_configport.h" #endif +#if CYW43_USE_FIRMWARE_PARTITION +// PICO_CONFIG: CYW43_FIRMWARE_PARTITION_ID, ID of Wi-Fi firmware partition which must match the ID used in the partition table JSON, type=int, default=0x776966696669726d, group=pico_cyw43_driver +#ifndef CYW43_FIRMWARE_PARTITION_ID +// The default 0x776966696669726d value is the ASCII encoding of "wififirm" +#define CYW43_FIRMWARE_PARTITION_ID 0x776966696669726d +#endif +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/src/rp2_common/pico_cyw43_driver/wifi_firmware.S b/src/rp2_common/pico_cyw43_driver/wifi_firmware.S new file mode 100644 index 000000000..ed398ff78 --- /dev/null +++ b/src/rp2_common/pico_cyw43_driver/wifi_firmware.S @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "boot/picobin.h" + +#if PICO_CRT0_IMAGE_TYPE_TBYB +#define CRT0_TBYB_FLAG PICOBIN_IMAGE_TYPE_EXE_TBYB_BITS +#else +#define CRT0_TBYB_FLAG 0 +#endif + +.section .wifi_fw, "a" +.global _start +_start: +.word 0 +.word 0 +.word 0 +.word 0 + +.p2align 2 +embedded_block: +.word PICOBIN_BLOCK_MARKER_START + +.byte PICOBIN_BLOCK_ITEM_1BS_IMAGE_TYPE +.byte 0x1 // 1 word +.hword PICOBIN_IMAGE_TYPE_IMAGE_TYPE_AS_BITS(EXE) | \ + PICOBIN_IMAGE_TYPE_EXE_CPU_AS_BITS(RISCV) | \ + PICOBIN_IMAGE_TYPE_EXE_CHIP_AS_BITS(RP2350) | \ + CRT0_TBYB_FLAG + +// Entry point into SRAM +.byte PICOBIN_BLOCK_ITEM_1BS_ENTRY_POINT +.byte 0x3 // word size to next item +.byte 0 // pad +.byte 0 // pad +.word _start +.word 0x20082000 // stack pointer + +_lm_item: +.byte PICOBIN_BLOCK_ITEM_LOAD_MAP +.byte 7 +.byte 0 // pad +.byte 2 // 2 entries +// To sign the firmware +.word (_start - _lm_item) +.word _start +.word (firmware_end - _start) +// But clear SRAM if actually running this, so it doesn't boot +.word 0 +.word _start +.word 0x00082000 + +.byte PICOBIN_BLOCK_ITEM_2BS_LAST +.hword (embedded_block_end - embedded_block - 16 ) / 4 // total size of all +.byte 0 +.word 0 +.word PICOBIN_BLOCK_MARKER_END +embedded_block_end: + +#include "firmware_blob.S" + +firmware_end: diff --git a/src/rp2_common/pico_cyw43_driver/wifi_firmware.ld b/src/rp2_common/pico_cyw43_driver/wifi_firmware.ld new file mode 100644 index 000000000..d239ef933 --- /dev/null +++ b/src/rp2_common/pico_cyw43_driver/wifi_firmware.ld @@ -0,0 +1,14 @@ +MEMORY +{ + RAM(rx) : ORIGIN = 0x20000000, LENGTH = 512k +} + +ENTRY(_start) + +SECTIONS +{ + .wifi_fw : { + *(.wifi_fw*) + . = ALIGN(4); + } > RAM +} diff --git a/src/rp2_common/pico_cyw43_driver/wifi_pt.json b/src/rp2_common/pico_cyw43_driver/wifi_pt.json new file mode 100644 index 000000000..035a19ed8 --- /dev/null +++ b/src/rp2_common/pico_cyw43_driver/wifi_pt.json @@ -0,0 +1,52 @@ +{ + "version": [1, 0], + "unpartitioned": { + "families": ["absolute"], + "permissions": { + "secure": "rw", + "nonsecure": "rw", + "bootloader": "rw" + } + }, + "partitions": [ + { + "name": "Main", + "id": 0, + "start": 0, + "size": "3500K", + "families": ["rp2350-arm-s", "rp2350-riscv"], + "permissions": { + "secure": "rw", + "nonsecure": "rw", + "bootloader": "rw" + } + }, + { + "name": "Wi-Fi Firmware", + "id": "0x776966696669726d", + "start": "3500k", + "size": "256K", + "families": ["cyw43-firmware"], + "permissions": { + "secure": "rw", + "nonsecure": "rw", + "bootloader": "rw" + }, + "ignored_during_riscv_boot": true, + "no_reboot_on_uf2_download": true + }, + { + "start": "3500k", + "size": "256k", + "families": ["cyw43-firmware"], + "permissions": { + "secure": "rw", + "nonsecure": "rw", + "bootloader": "rw" + }, + "link": ["a", 1], + "ignored_during_riscv_boot": true, + "no_reboot_on_uf2_download": true + } + ] +} From d32d315624b3d2154fceb2e1963819f271090fa3 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 17 Jul 2025 11:32:28 -0500 Subject: [PATCH 189/224] minor tidying of hardware_rcp header; add an `rcp_is_true()` that is safe to use on RISC-V too (#2568) --- .../hardware_rcp/include/hardware/rcp.h | 240 ++++++++++-------- src/rp2_common/pico_bootrom/bootrom.c | 2 +- 2 files changed, 130 insertions(+), 112 deletions(-) diff --git a/src/rp2_common/hardware_rcp/include/hardware/rcp.h b/src/rp2_common/hardware_rcp/include/hardware/rcp.h index 64c88c5a1..b9e144a09 100644 --- a/src/rp2_common/hardware_rcp/include/hardware/rcp.h +++ b/src/rp2_common/hardware_rcp/include/hardware/rcp.h @@ -15,15 +15,17 @@ */ // ---------------------------------------------------------------------------- -// RCP masks -#if !PICO_RP2040 +// RCP instructions (this header is Arm-only) +#if HAS_REDUNDANCY_COPROCESSOR +#ifdef __riscv +#error "HAS_REDUNDANCY_COPROCESSOR should be false on RISC-V" +#endif +#define rcp_is_true(x) ((x) == RCP_MASK_TRUE) #define RCP_MASK_TRUE _u(0xa500a500) #define RCP_MASK_FALSE _u(0x00c300c3) #define RCP_MASK_INTXOR _u(0x96009600) -// RCP instructions (these instructions are Arm-only) -#if HAS_REDUNDANCY_COPROCESSOR // ---------------------------------------------------------------------------- // Macros and inline functions for use in C files #ifndef __ASSEMBLER__ @@ -86,6 +88,7 @@ static __rcpinline void rcp_salt_core1_nodelay(uint64_t salt) { // Get a 32-bit canary value. `tag` must be a constant expression. #define rcp_canary_get(tag) ({ \ + static_assert(!((tag) & ~0xffu), "Tag out of range"); \ uint32_t __canary_u32; \ rcp_asm ( \ "mrc p7, #0, %0, c%c1, c%c2, #1\n" \ @@ -96,6 +99,7 @@ static __rcpinline void rcp_salt_core1_nodelay(uint64_t salt) { }) #define rcp_canary_get_nodelay(tag) ({ \ + static_assert(!((tag) & ~0xffu), "Tag out of range"); \ uint32_t __canary_u32; \ rcp_asm ( \ "mrc2 p7, #0, %0, c%c1, c%c2, #1\n" \ @@ -107,6 +111,7 @@ static __rcpinline void rcp_salt_core1_nodelay(uint64_t salt) { // Assert that canary matches result of rcp_canary_get with the same tags: #define rcp_canary_check(tag, canary) ({ \ + static_assert(!((tag) & ~0xffu), "Tag out of range"); \ rcp_asm ( \ "mcr p7, #0, %0, c%c1, c%c2, #1\n" \ : : "r" (canary), \ @@ -115,6 +120,7 @@ static __rcpinline void rcp_salt_core1_nodelay(uint64_t salt) { }) #define rcp_canary_check_nodelay(tag, canary) ({ \ + static_assert(!((tag) & ~0xffu), "Tag out of range"); \ rcp_asm ( \ "mcr2 p7, #0, %0, c%c1, c%c2, #1\n" \ : : "r" (canary), \ @@ -141,6 +147,9 @@ static __rcpinline uint32_t rcp_canary_status_nodelay(void) { // ---------------------------------------------------------------------------- // RCP Boolean instructions +// These instructions assert that all their arguments are valid booleans, in +// addition to any other logical conditions + // Assert b is a valid boolean (0xa500a500u or 0x00c300c3u) static __rcpinline void rcp_bvalid(uint32_t b) { rcp_asm ("mcr p7, #1, %0, c0, c0, #0\n" : : "r" (b)); @@ -308,106 +317,8 @@ static __rcpinline __attribute__((noreturn)) void rcp_panic(void) { #else // __ASSEMBLER__ #ifndef __riscv -// Assert b is a valid boolean (0xa500a500u or 0x00c300c3u) -.macro rcp_bvalid r - mcr p7, #1, \r , c0, c0, #0 -.endm - -.macro rcp_bvalid_nodelay r - mcr2 p7, #1, \r , c0, c0, #0 -.endm - -// Assert b is true (0xa500a500u) -.macro rcp_btrue r - mcr p7, #2, \r , c0, c0, #0 -.endm - -.macro rcp_btrue_nodelay r - mcr2 p7, #2, \r , c0, c0, #0 -.endm - -// Assert b is false (0x00c300c3u) -.macro rcp_bfalse r - mcr p7, #3, \r , c0, c0, #1 -.endm - -.macro rcp_bfalse_nodelay r - mcr2 p7, #3, \r , c0, c0, #1 -.endm - -// Assert b0 and b1 are both valid booleans -.macro rcp_b2valid b0, b1 - mcrr p7, #0, \b0 , \b1 , c8 -.endm - -.macro rcp_b2valid_nodelay b0, b1 - mcrr2 p7, #0, \b0 , \b1 , c8 -.endm - -// Assert b0 and b1 are both true -.macro rcp_b2and b0, b1 - mcrr p7, #1, \b0 , \b1 , c0 -.endm - -.macro rcp_b2and_nodelay b0, b1 - mcrr2 p7, #1, \b0 , \b1 , c0 -.endm - -// Assert b0 and b1 are valid, and at least one is true -.macro rcp_b2or b0, b1 - mcrr p7, #2, \b0 , \b1 , c0 -.endm - -.macro rcp_b2or_nodelay b0, b1 - mcrr2 p7, #2, \b0 , \b1 , c0 -.endm - -// Assert (b ^ mask) is a valid boolean -.macro rcp_bxorvalid b, mask - mcrr p7, #3, \b , \mask , c8 -.endm - -.macro rcp_bxorvalid_nodelay b, mask - mcrr2 p7, #3, \b , \mask , c8 -.endm - -// Assert (b ^ mask) is true -.macro rcp_bxortrue b, mask - mcrr p7, #4, \b , \mask , c0 -.endm - -.macro rcp_bxortrue_nodelay b, mask - mcrr2 p7, #4, \b , \mask , c0 -.endm - -// Assert (b ^ mask) is false -.macro rcp_bxorfalse b, mask - mcrr p7, #5, \b , \mask , c8 -.endm - -.macro rcp_bxorfalse_nodelay b, mask - mcrr2 p7, #5, \b , \mask , c8 -.endm - -// Assert (x ^ parity) == 0x96009600u -.macro rcp_ivalid x, parity - mcrr p7, #6, \x , \parity , c8 -.endm - -.macro rcp_ivalid_nodelay x, parity - mcrr2 p7, #6, \x , \parity , c8 -.endm - -// Assert x == y -.macro rcp_iequal x, y - mcrr p7, #7, \x , \y , c0 -.endm - -.macro rcp_iequal_nodelay x, y - mcrr2 p7, #7, \x , \y , c0 -.endm - -// They call this "metaprogramming" I think +// Meta-macro for evaluating assembler constant expressions and encoding as +// coprocessor register pairs: .macro rcp_switch_u8_to_ch_cl macro_name, x, args:vararg .if (\x) == 0 \macro_name c0, c0, \args @@ -926,6 +837,114 @@ static __rcpinline __attribute__((noreturn)) void rcp_panic(void) { .endif .endm +// ---------------------------------------------------------------------------- +// RCP Boolean instructions + +// Assert b is a valid boolean (0xa500a500u or 0x00c300c3u) +.macro rcp_bvalid r + mcr p7, #1, \r , c0, c0, #0 +.endm + +.macro rcp_bvalid_nodelay r + mcr2 p7, #1, \r , c0, c0, #0 +.endm + +// Assert b is true (0xa500a500u) +.macro rcp_btrue r + mcr p7, #2, \r , c0, c0, #0 +.endm + +.macro rcp_btrue_nodelay r + mcr2 p7, #2, \r , c0, c0, #0 +.endm + +// Assert b is false (0x00c300c3u) +.macro rcp_bfalse r + mcr p7, #3, \r , c0, c0, #1 +.endm + +.macro rcp_bfalse_nodelay r + mcr2 p7, #3, \r , c0, c0, #1 +.endm + +// Assert b0 and b1 are both valid booleans +.macro rcp_b2valid b0, b1 + mcrr p7, #0, \b0 , \b1 , c8 +.endm + +.macro rcp_b2valid_nodelay b0, b1 + mcrr2 p7, #0, \b0 , \b1 , c8 +.endm + +// Assert b0 and b1 are both true +.macro rcp_b2and b0, b1 + mcrr p7, #1, \b0 , \b1 , c0 +.endm + +.macro rcp_b2and_nodelay b0, b1 + mcrr2 p7, #1, \b0 , \b1 , c0 +.endm + +// Assert b0 and b1 are valid, and at least one is true +.macro rcp_b2or b0, b1 + mcrr p7, #2, \b0 , \b1 , c0 +.endm + +.macro rcp_b2or_nodelay b0, b1 + mcrr2 p7, #2, \b0 , \b1 , c0 +.endm + +// Assert (b ^ mask) is a valid boolean +.macro rcp_bxorvalid b, mask + mcrr p7, #3, \b , \mask , c8 +.endm + +.macro rcp_bxorvalid_nodelay b, mask + mcrr2 p7, #3, \b , \mask , c8 +.endm + +// Assert (b ^ mask) is true +.macro rcp_bxortrue b, mask + mcrr p7, #4, \b , \mask , c0 +.endm + +.macro rcp_bxortrue_nodelay b, mask + mcrr2 p7, #4, \b , \mask , c0 +.endm + +// Assert (b ^ mask) is false +.macro rcp_bxorfalse b, mask + mcrr p7, #5, \b , \mask , c8 +.endm + +.macro rcp_bxorfalse_nodelay b, mask + mcrr2 p7, #5, \b , \mask , c8 +.endm + +// ---------------------------------------------------------------------------- +// RCP Integer instructions + +// Assert (x ^ parity) == 0x96009600u +.macro rcp_ivalid x, parity + mcrr p7, #6, \x , \parity , c8 +.endm + +.macro rcp_ivalid_nodelay x, parity + mcrr2 p7, #6, \x , \parity , c8 +.endm + +// Assert x == y +.macro rcp_iequal x, y + mcrr p7, #7, \x , \y , c0 +.endm + +.macro rcp_iequal_nodelay x, y + mcrr2 p7, #7, \x , \y , c0 +.endm + +// ---------------------------------------------------------------------------- +// RCP Sequence count instructions + // Directly write 8-bit constant expression cnt to the sequence counter. .macro rcp_count_set_impl h, l mcr p7, #4, r0, \h , \l , #0 @@ -957,20 +976,20 @@ rcp_switch_u8_to_ch_cl rcp_count_check_impl, \cnt rcp_switch_u8_to_ch_cl rcp_count_check_nodelay_impl, \cnt .endm +// ---------------------------------------------------------------------------- +// RCP Canary instructions + // Get a 32-bit canary value. `tag` must be a constant expression. .macro rcp_canary_get_impl h, l, x mrc p7, #0, \x, \h, \l, #1 .endm - .macro rcp_canary_get x, tag rcp_switch_u8_to_ch_cl rcp_canary_get_impl \tag, \x .endm -// Get a 32-bit canary value. `tag` must be a constant expression. .macro rcp_canary_get_nodelay_impl h, l, x mrc2 p7, #0, \x, \h, \l, #1 .endm - .macro rcp_canary_get_nodelay x, tag rcp_switch_u8_to_ch_cl rcp_canary_get_nodelay_impl \tag, \x .endm @@ -979,7 +998,6 @@ rcp_switch_u8_to_ch_cl rcp_canary_get_nodelay_impl \tag, \x .macro rcp_canary_check_impl h, l, x mcr p7, #0, \x, \h, \l, #1 .endm - .macro rcp_canary_check x, tag rcp_switch_u8_to_ch_cl rcp_canary_check_impl \tag, \x .endm @@ -987,7 +1005,6 @@ rcp_switch_u8_to_ch_cl rcp_canary_check_impl \tag, \x .macro rcp_canary_check_nodelay_impl h, l, x mcr2 p7, #0, \x, \h, \l, #1 .endm - .macro rcp_canary_check_nodelay x, tag rcp_switch_u8_to_ch_cl rcp_canary_check_nodelay_impl \tag, \x .endm @@ -996,13 +1013,14 @@ rcp_switch_u8_to_ch_cl rcp_canary_check_nodelay_impl \tag, \x cdp p7, #0, c0, c0, c0, #1 .endm -#endif // HAS_REDUNDANCY_COPROCESSOR -#endif // !PICO_RP2040 +#endif // !__riscv #endif // __ASSEMBLER__ // ---------------------------------------------------------------------------- #ifdef __cplusplus } #endif +#else +#define rcp_is_true(x) ((int32_t)(x) < 0) #endif #endif diff --git a/src/rp2_common/pico_bootrom/bootrom.c b/src/rp2_common/pico_bootrom/bootrom.c index cedc27fc8..0c0053514 100644 --- a/src/rp2_common/pico_bootrom/bootrom.c +++ b/src/rp2_common/pico_bootrom/bootrom.c @@ -160,7 +160,7 @@ int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size int rc = rom_pick_ab_partition((uint8_t*)workarea_base, workarea_size, partition_a_num, flash_update_base); - if (IMAGE_DEF_VERIFIED(workarea_base) != RCP_MASK_TRUE) { + if (!rcp_is_true(IMAGE_DEF_VERIFIED(workarea_base))) { // Chosen partition failed verification return BOOTROM_ERROR_NOT_FOUND; } From af518de1c3ff0a298d89bf7f9885bd566fd85144 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 17 Jul 2025 11:32:46 -0500 Subject: [PATCH 190/224] add missing libraries to test/kitchen_sink and auto-gen includes (#2567) * add missing libraries to test/kitchen_sink and auto-gen includes * bazel fix --- test/kitchen_sink/CMakeLists.txt | 89 ++++++++++++++++----- test/kitchen_sink/kitchen_sink.c | 128 +++---------------------------- 2 files changed, 78 insertions(+), 139 deletions(-) diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index 60d97fd06..c2c88d9b3 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -2,23 +2,32 @@ add_library(kitchen_sink_libs INTERFACE) set(KITCHEN_SINK_LIBS hardware_adc + hardware_boot_lock + hardware_claim hardware_clocks + hardware_dcp hardware_divider hardware_dma hardware_exception hardware_flash hardware_gpio + hardware_hazard3 hardware_i2c hardware_interp hardware_irq hardware_pio - hardware_powman hardware_pll + hardware_powman hardware_pwm + hardware_rcp hardware_resets + hardware_riscv + hardware_riscv_platform_timer hardware_rtc + hardware_sha256 hardware_spi hardware_sync + hardware_sync_spin_lock hardware_ticks hardware_timer hardware_uart @@ -41,8 +50,12 @@ set(KITCHEN_SINK_LIBS pico_mem_ops pico_multicore pico_platform + pico_printf pico_rand + pico_runtime + pico_runtime_init pico_sha256 + pico_stdio pico_stdlib pico_sync pico_time @@ -50,16 +63,47 @@ set(KITCHEN_SINK_LIBS pico_util ) +set(KITCHEN_SINK_NO_HEADER_LIBS + hardware_dcp + pico_bootsel_via_double_reset + pico_int64_ops # currently empty, and only included by _pico variant + pico_mem_ops # currently empty, and only included by _pico variant +) + +set(KITCHEN_SINK_INCLUDES "#pragma once\n") foreach(LIB IN LISTS KITCHEN_SINK_LIBS) if (TARGET ${LIB}) target_link_libraries(kitchen_sink_libs INTERFACE ${LIB}) + string(REGEX MATCH "([a-z]+)_(.+)" HAS_MATCH ${LIB}) + if (HAS_MATCH AND NOT LIB IN_LIST KITCHEN_SINK_NO_HEADER_LIBS) + # these are few, so just hack fixing for now + if (LIB STREQUAL "pico_util") + string(APPEND KITCHEN_SINK_INCLUDES "#include \"pico/util/datetime.h\"\n") + string(APPEND KITCHEN_SINK_INCLUDES "#include \"pico/util/pheap.h\"\n") + string(APPEND KITCHEN_SINK_INCLUDES "#include \"pico/util/queue.h\"\n") + else() + if ("${CMAKE_MATCH_2}" STREQUAL "fix_rp2040_usb_device_enumeration") + set(CMAKE_MATCH_2 "fix/rp2040_usb_device_enumeration") + elseif ("${CMAKE_MATCH_2}" STREQUAL "sync_spin_lock") + set(CMAKE_MATCH_2 "sync/spin_lock") + endif() + string(APPEND KITCHEN_SINK_INCLUDES "#include \"${CMAKE_MATCH_1}/${CMAKE_MATCH_2}.h\"\n") + endif() + endif() endif() endforeach () +set(KITCHEN_SINK_INCLUDE_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kitchen_sink_includes.h") +file(GENERATE OUTPUT ${KITCHEN_SINK_INCLUDE_HEADER} CONTENT ${KITCHEN_SINK_INCLUDES}) add_library(kitchen_sink_options INTERFACE) -target_compile_options(kitchen_sink_options INTERFACE +if (NOT KITCHEN_SINK_NO_WERROR) + target_compile_options(kitchen_sink_options INTERFACE -Werror + ) +endif() + +target_compile_options(kitchen_sink_options INTERFACE -Wall -Wextra # -pedantic @@ -97,6 +141,7 @@ target_compile_definitions(kitchen_sink_libs INTERFACE PICO_FORBID_ARM_HEADERS_ON_RISCV=1 PARAM_ASSERTIONS_ENABLE_ALL=1 # want to check all the assertions for compilation warnings PICO_AUDIO_DMA_IRQ=1 + KITCHEN_SINK_INCLUDE_HEADER="${KITCHEN_SINK_INCLUDE_HEADER}" ) add_executable(kitchen_sink ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) @@ -147,25 +192,27 @@ target_link_libraries(kitchen_sink_printf_none kitchen_sink_libs kitchen_sink_op pico_add_extra_outputs(kitchen_sink_printf_none) pico_set_printf_implementation(kitchen_sink_printf_none none) -add_executable(kitchen_sink_copy_to_ram ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) -pico_set_binary_type(kitchen_sink_copy_to_ram copy_to_ram) -target_link_libraries(kitchen_sink_copy_to_ram kitchen_sink_libs kitchen_sink_options) -pico_add_extra_outputs(kitchen_sink_copy_to_ram) -target_compile_definitions(kitchen_sink_copy_to_ram PRIVATE KITCHEN_SINK_ID="copy-to-ram binary") - -add_executable(kitchen_sink_no_flash ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) -pico_set_binary_type(kitchen_sink_no_flash no_flash) -target_link_libraries(kitchen_sink_no_flash kitchen_sink_libs kitchen_sink_options) -pico_add_extra_outputs(kitchen_sink_no_flash) -target_compile_definitions(kitchen_sink_no_flash PRIVATE KITCHEN_SINK_ID="no-flash binary") - -if (NOT PICO_RP2350) - # RP2350 does not have blocked ram - add_executable(kitchen_sink_blocked_ram ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) - pico_set_binary_type(kitchen_sink_blocked_ram blocked_ram) - target_link_libraries(kitchen_sink_blocked_ram kitchen_sink_libs kitchen_sink_options) - pico_add_extra_outputs(kitchen_sink_blocked_ram) - target_compile_definitions(kitchen_sink_blocked_ram PRIVATE KITCHEN_SINK_ID="blocked-ram binary") +if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) + add_executable(kitchen_sink_copy_to_ram ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) + pico_set_binary_type(kitchen_sink_copy_to_ram copy_to_ram) + target_link_libraries(kitchen_sink_copy_to_ram kitchen_sink_libs kitchen_sink_options) + pico_add_extra_outputs(kitchen_sink_copy_to_ram) + target_compile_definitions(kitchen_sink_copy_to_ram PRIVATE KITCHEN_SINK_ID="copy-to-ram binary") + + add_executable(kitchen_sink_no_flash ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) + pico_set_binary_type(kitchen_sink_no_flash no_flash) + target_link_libraries(kitchen_sink_no_flash kitchen_sink_libs kitchen_sink_options) + pico_add_extra_outputs(kitchen_sink_no_flash) + target_compile_definitions(kitchen_sink_no_flash PRIVATE KITCHEN_SINK_ID="no-flash binary") + + if (PICO_RP2040) + # RP2040 has blocked ram + add_executable(kitchen_sink_blocked_ram ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) + pico_set_binary_type(kitchen_sink_blocked_ram blocked_ram) + target_link_libraries(kitchen_sink_blocked_ram kitchen_sink_libs kitchen_sink_options) + pico_add_extra_outputs(kitchen_sink_blocked_ram) + target_compile_definitions(kitchen_sink_blocked_ram PRIVATE KITCHEN_SINK_ID="blocked-ram binary") + endif() endif() add_executable(kitchen_sink_cpp ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_cpp.cpp) diff --git a/test/kitchen_sink/kitchen_sink.c b/test/kitchen_sink/kitchen_sink.c index 73417d5a5..7bc2bcd11 100644 --- a/test/kitchen_sink/kitchen_sink.c +++ b/test/kitchen_sink/kitchen_sink.c @@ -5,127 +5,18 @@ */ #include -// Include all headers to check for compiler warnings -#include "hardware/adc.h" -#include "hardware/claim.h" -#include "hardware/clocks.h" -#include "hardware/divider.h" + +#ifndef KITCHEN_SINK_INCLUDE_HEADER +// provided for backwards compatibility for non CMake build systems - just includes enough to compile #include "hardware/dma.h" -#include "hardware/exception.h" -#include "hardware/flash.h" -#include "hardware/gpio.h" -#include "hardware/i2c.h" -#include "hardware/interp.h" -#include "hardware/irq.h" -#include "hardware/pio.h" -#include "hardware/pio_instructions.h" -#include "hardware/pll.h" -#include "hardware/pwm.h" -#include "hardware/resets.h" -#if PICO_RP2040 -#include "hardware/rtc.h" -#endif -#if !PICO_RP2040 -#include "hardware/sha256.h" -#endif -#include "hardware/spi.h" -#include "hardware/sync.h" -#include "hardware/timer.h" -#include "hardware/ticks.h" -#include "hardware/uart.h" -#include "hardware/vreg.h" -#include "hardware/watchdog.h" -#include "hardware/xosc.h" -#include "pico/aon_timer.h" -#include "pico/binary_info.h" -#include "pico/bit_ops.h" -#include "pico/bootrom.h" -#if LIB_PICO_CYW43_ARCH -#include "pico/cyw43_arch.h" -#endif -#include "pico/divider.h" -// todo we should have this but right now double.h is only present with double_implementation == pico -#if PICO_RP2040 -#include "pico/double.h" -#endif -#include "pico/fix/rp2040_usb_device_enumeration.h" -#include "pico/flash.h" -// todo we should have this but right now float.h is only present with float_implementation == pico -#if PICO_RP2040 -#include "pico/float.h" -#endif -#include "pico/i2c_slave.h" -#if LIB_PICO_INT64_OPS_PICO -#include "pico/int64_ops.h" -#endif -#include "pico/malloc.h" -#include "pico/multicore.h" -#include "pico/platform.h" -#include "pico/printf.h" -#include "pico/rand.h" -#include "pico/runtime.h" -#if LIB_PICO_SHA256 -#include "pico/sha256.h" -#endif -#include "pico/stdio.h" -#include "pico/stdlib.h" #include "pico/sync.h" -#include "pico/time.h" -#include "pico/unique_id.h" -#include "pico/util/datetime.h" -#include "pico/util/pheap.h" -#include "pico/util/queue.h" - -#include "hardware/structs/adc.h" -#include "hardware/structs/busctrl.h" -#include "hardware/structs/clocks.h" -#include "hardware/structs/dma.h" -#include "hardware/structs/i2c.h" -#include "hardware/structs/interp.h" -#include "hardware/structs/io_bank0.h" -#include "hardware/structs/io_qspi.h" -#ifndef __riscv -#include "hardware/structs/mpu.h" -#include "hardware/structs/nvic.h" -#endif -#include "hardware/structs/pads_bank0.h" -#include "hardware/structs/pads_qspi.h" -#include "hardware/structs/pio.h" -#include "hardware/structs/pll.h" -#if PICO_RP2350 -#include "hardware/structs/powman.h" -#endif -#include "hardware/structs/psm.h" -#include "hardware/structs/pwm.h" -#include "hardware/structs/resets.h" -#include "hardware/structs/rosc.h" -#if PICO_RP2040 -#include "hardware/structs/rtc.h" -#endif -#ifndef __riscv -#include "hardware/structs/scb.h" -#endif -#include "hardware/structs/sio.h" -#if !PICO_RP2040 -#include "hardware/structs/sha256.h" -#endif -#include "hardware/structs/spi.h" -#if PICO_RP2040 -#include "hardware/structs/ssi.h" -#endif -#include "hardware/structs/syscfg.h" -#ifndef __riscv -#include "hardware/structs/systick.h" +#include "pico/stdlib.h" +#if LIB_PICO_BINARY_INFO +#include "pico/binary_info.h" #endif -#include "hardware/structs/timer.h" -#include "hardware/structs/uart.h" -#include "hardware/structs/usb.h" -#if PICO_RP2040 -#include "hardware/structs/vreg_and_chip_reset.h" +#else +#include KITCHEN_SINK_INCLUDE_HEADER #endif -#include "hardware/structs/watchdog.h" -#include "hardware/structs/xip_ctrl.h" -#include "hardware/structs/xosc.h" #if LIB_PICO_MBEDTLS #include "mbedtls/ssl.h" @@ -133,6 +24,7 @@ #include "lwip/altcp_tls.h" #endif +#if LIB_PICO_BINARY_INFO bi_decl(bi_block_device( BINARY_INFO_MAKE_TAG('K', 'S'), "foo", @@ -141,6 +33,7 @@ bi_decl(bi_block_device( NULL, BINARY_INFO_BLOCK_DEV_FLAG_READ | BINARY_INFO_BLOCK_DEV_FLAG_WRITE | BINARY_INFO_BLOCK_DEV_FLAG_PT_UNKNOWN)); +#endif uint32_t *foo = (uint32_t *) 200; @@ -167,7 +60,6 @@ float __attribute__((noinline)) foox(float x, float b) { return x * b; } - int main(void) { spiggle(); From 968289625be68f28822f1f640cd1c52f16afb67b Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 17 Jul 2025 11:33:05 -0500 Subject: [PATCH 191/224] Gpio to gpout clock handle (#2561) * add gpio_to_gpout_clock_handle to encapsulate GPIO->gpout mapping * oops; wrong parenthesis placement --- src/rp2_common/hardware_clocks/clocks.c | 17 ++------- .../hardware_clocks/include/hardware/clocks.h | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/rp2_common/hardware_clocks/clocks.c b/src/rp2_common/hardware_clocks/clocks.c index 2d41c73d2..1362a3a28 100644 --- a/src/rp2_common/hardware_clocks/clocks.c +++ b/src/rp2_common/hardware_clocks/clocks.c @@ -243,21 +243,8 @@ void clocks_enable_resus(resus_callback_t resus_callback) { } void clock_gpio_init_int_frac16(uint gpio, uint src, uint32_t div_int, uint16_t div_frac16) { - // Bit messy but it's as much code to loop through a lookup - // table. The sources for each gpout generators are the same - // so just call with the sources from GP0 - uint gpclk = 0; - if (gpio == 21) gpclk = clk_gpout0; - else if (gpio == 23) gpclk = clk_gpout1; - else if (gpio == 24) gpclk = clk_gpout2; - else if (gpio == 25) gpclk = clk_gpout3; -#if !PICO_RP2040 - else if (gpio == 13) gpclk = clk_gpout0; - else if (gpio == 15) gpclk = clk_gpout1; -#endif - else { - invalid_params_if(HARDWARE_CLOCKS, true); - } + // note this includes an invalid_params_if before defaulting to clk_gpout0 + uint gpclk = gpio_to_gpout_clock_handle(gpio, clk_gpout0); invalid_params_if(HARDWARE_CLOCKS, div_int >> REG_FIELD_WIDTH(CLOCKS_CLK_GPOUT0_DIV_INT)); // Set up the gpclk generator diff --git a/src/rp2_common/hardware_clocks/include/hardware/clocks.h b/src/rp2_common/hardware_clocks/include/hardware/clocks.h index 4376f7caf..6aeec495b 100644 --- a/src/rp2_common/hardware_clocks/include/hardware/clocks.h +++ b/src/rp2_common/hardware_clocks/include/hardware/clocks.h @@ -577,6 +577,42 @@ static inline bool set_sys_clock_khz(uint32_t freq_khz, bool required) { return false; } +#define GPIO_TO_GPOUT_CLOCK_HANDLE_RP2040(gpio, default_clk_handle) \ + ((gpio) == 21 ? clk_gpout0 : \ + ((gpio) == 23 ? clk_gpout1 : \ + ((gpio) == 24 ? clk_gpout2 : \ + ((gpio) == 25 ? clk_gpout3 : \ + (default_clk_handle))))) + +#define GPIO_TO_GPOUT_CLOCK_HANDLE_RP2350(gpio, default_clk_handle) \ + ((gpio) == 13 ? clk_gpout0 : \ + ((gpio) == 15 ? clk_gpout1 : \ + (GPIO_TO_GPOUT_CLOCK_HANDLE_RP2040(gpio, default_clk_handle)))) + +/** + * \def GPIO_TO_GPOUT_CLOCK_HANDLE(gpio, default_clk_handle) + * \ingroup hardware_clocks + * \hideinitializer + * \brief Returns the GPOUT clock number associated with a particular GPIO if there is one, or default_clk_handle otherwise + * + * Note this macro is intended to resolve at compile time, and does no parameter checking + */ +#ifndef GPIO_TO_GPOUT_CLOCK_HANDLE +#if PICO_RP2040 +#define GPIO_TO_GPOUT_CLOCK_HANDLE GPIO_TO_GPOUT_CLOCK_HANDLE_RP2040 +#else +#define GPIO_TO_GPOUT_CLOCK_HANDLE GPIO_TO_GPOUT_CLOCK_HANDLE_RP2350 +#endif +#endif + +/** + * \brief return the associated GPOUT clock for a given GPIO if any + * \ingroup hardware_clocks + * \return the GPOUT clock number associated with a particular GPIO or default_clk_handle otherwise + */ +static inline clock_handle_t gpio_to_gpout_clock_handle(uint gpio, clock_handle_t default_clk_handle) { + return GPIO_TO_GPOUT_CLOCK_HANDLE(gpio, ({invalid_params_if(HARDWARE_CLOCKS, true); default_clk_handle;})); +} #ifdef __cplusplus } #endif From f5e0371ad52fd1b390ad77a25bc4799fb29d7f44 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Thu, 17 Jul 2025 17:33:23 +0100 Subject: [PATCH 192/224] Make spacer sections allocatable (#2515) * Default to allocating spacer sections (stack & heap), with PICO_CRT0_ALLOCATE_SPACERS config option to disable the behaviour * Add pico_check_linker_script function to check for compatibility of custom linker scripts * tweak error message --------- Co-authored-by: Graham Sanderson --- src/rp2_common/pico_crt0/crt0.S | 10 ++++- .../pico_standard_link/CMakeLists.txt | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index 43ce5ed34..ea3b99a5a 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -582,10 +582,16 @@ runtime_init: // // Strictly the most correct thing to do (as .stack and .heap are unreferenced) is to mark them as "a", and also KEEP, which // works correctly for both GCC and Clang, however doing so may break anyone who already has custom linker scripts without -// the KEEP. Therefore we will only add the "a" on Clang, but will also use KEEP to our own linker scripts. +// the KEEP. Therefore we add a define of PICO_CRT0_ALLOCATE_SPACERS to switch between the old and new behaviour, so anyone +// with custom linker scripts without the KEEP can set it to 0 (or update their linker script). + +// PICO_CONFIG: PICO_CRT0_ALLOCATE_SPACERS, Set spacer sections as allocatable. This makes them appear in print-memory-usage but is incompatible with linker scripts that do not KEEP the sections, type=bool, default=1, advanced=true, group=pico_crt0 +#ifndef PICO_CRT0_ALLOCATE_SPACERS +#define PICO_CRT0_ALLOCATE_SPACERS 1 +#endif .macro spacer_section name -#if PICO_ASSEMBLER_IS_CLANG +#if PICO_CRT0_ALLOCATE_SPACERS .section \name, "a" #else .section \name diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 484abc892..c16968bba 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -25,11 +25,48 @@ if (NOT TARGET pico_standard_link) set_target_properties(${TARGET} PROPERTIES ${PROP} "${_LINK_DEPENDS}") endfunction() + # pico_check_linker_script(LDSCRIPT) + # \brief_nodesc\ Check the linker script for compatibility + # + # Checks the linker script for compatibility with the current SDK version, + # and if not, raises warnings and enables workarounds to maintain + # compatibility where possible. + # + # \param\ LDSCRIPT Full path to the linker script to check + function(pico_check_linker_script TARGET LDSCRIPT) + if (EXISTS ${LDSCRIPT}) + file(READ ${LDSCRIPT} LDSCRIPT_CONTENTS) + else() + return() + endif() + + # Check if the linker script uses KEEP to keep the .stack and .heap sections + # and if not, set PICO_CRT0_ALLOCATE_SPACERS to 0 to maintain compatibility + string(FIND "${LDSCRIPT_CONTENTS}" "KEEP(*(.stack*))" KEEP_STACK_FOUND) + string(FIND "${LDSCRIPT_CONTENTS}" "KEEP(*(.heap*))" KEEP_HEAP_FOUND) + string(FIND "${LDSCRIPT_CONTENTS}" "*(.stack*)" STACK_FOUND) + string(FIND "${LDSCRIPT_CONTENTS}" "*(.heap*)" HEAP_FOUND) + set(PICO_CRT0_ALLOCATE_SPACERS TRUE) + if ((${STACK_FOUND} GREATER -1) AND NOT (${KEEP_STACK_FOUND} GREATER -1)) + message(WARNING "Linker script ${LDSCRIPT} does not KEEP the .stack section - replace `*(.stack*)` with `KEEP(*(.stack*))`") + set(PICO_CRT0_ALLOCATE_SPACERS FALSE) + endif() + if ((${HEAP_FOUND} GREATER -1) AND NOT (${KEEP_HEAP_FOUND} GREATER -1)) + message(WARNING "Linker script ${LDSCRIPT} does not KEEP the .heap section - replace `*(.heap*)` with `KEEP(*(.heap*))`") + set(PICO_CRT0_ALLOCATE_SPACERS FALSE) + endif() + if (NOT ${PICO_CRT0_ALLOCATE_SPACERS}) + message(WARNING "Linker script ${LDSCRIPT} is incompatible with certain Pico SDK >2.1.1 features; setting PICO_CRT0_ALLOCATE_SPACERS=0 as a workaround") + target_compile_definitions(${TARGET} PRIVATE PICO_CRT0_ALLOCATE_SPACERS=0) + endif() + endfunction() + # pico_set_linker_script(TARGET LDSCRIPT) # \brief\ Set the linker script for the target # # \param\ LDSCRIPT Full path to the linker script to set function(pico_set_linker_script TARGET LDSCRIPT) + pico_check_linker_script(${TARGET} ${LDSCRIPT}) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${LDSCRIPT}) endfunction() From 4003a647894e055f862c91c6ac319f4a8930d16e Mon Sep 17 00:00:00 2001 From: Jeunese Date: Fri, 18 Jul 2025 10:27:41 +0100 Subject: [PATCH 193/224] Merge style and grammar updates * Update mainpage.md Re-wrote to be in line with style guidance and to be easier to read. * Changed "adjust" to "refine" (previously "fine-tune"). * Updated first paragraph of the "SDK design" section. * Minor fixes * Minor grammatical updates * Changed "adjust and refine" to "tweak" --- docs/mainpage.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/mainpage.md b/docs/mainpage.md index 307fbb372..f8776e7df 100644 --- a/docs/mainpage.md +++ b/docs/mainpage.md @@ -1,28 +1,28 @@ # Raspberry Pi Pico SDK -The Raspberry Pi Pico SDK (Software Development Kit), henceforth SDK, provides the headers, libraries and build system necessary to write programs for RP-series microcontroller devices such as the Raspberry Pi Pico in C, C++ or assembly language. The SDK is designed to provide an API (Application Programming Interface) and programming environment that is familiar both to non-embedded C developers and embedded C developers alike. +The Raspberry Pi Pico Software Development Kit, hereafter **SDK**, provides the headers, libraries, and build system necessary to write programs for RP-series microcontroller devices such as the Raspberry Pi Pico in C, C++, or assembly language. The SDK is designed to provide an API (Application Programming Interface) and programming environment that's familiar both to both non-embedded and embedded C developers. -A single program runs on the device at a time with a conventional `main()` method. Standard C/C++ libraries are supported along with APIs for accessing the microcontroller's hardware, including DMA, IRQs, and the wide variety of fixed-function peripherals and PIO (Programmable IO). +A single program runs on the device at a time, with a conventional `main()` method. Standard C and C++ libraries are supported, along with APIs for accessing a microcontroller's hardware, including DMA, IRQs, and wide variety of fixed-function peripherals and PIO (Programmable IO). -Additionally the SDK provides higher-level libraries for dealing with timers, USB, synchronization and multi-core programming, along with additional high-level functionality built using PIO, such as audio. The SDK can be used to build anything from simple applications, or full-fledged runtime environments such as MicroPython, to low-level software such as the microcontroller's on-chip bootrom itself. +Additionally, the SDK provides higher-level libraries for dealing with timers, USB, synchronisation, and multi-core programming, along with high-level functionality built using PIO (such as audio). The SDK can be used to build anything from simple applications to full-fledged runtime environments such as MicroPython, or even low-level software, such as the microcontroller's on-chip boot ROM. -This documentation is generated from the SDK source tree using Doxygen. It provides basic information on the APIs used for each library, but does not provide usage information. Please refer to the Databooks for usage and more technical information. +This documentation is generated from the SDK source tree using Doxygen. It provides basic information on the APIs used for each library, but doesn't provide usage information. For more technical information and usage guidance, refer to the Raspberry Pi datasheets. ## SDK Design -The RP-series microcontroller range are powerful chips, however they are used in an embedded environment, so both RAM and program space are at premium. Additionally the trade-offs between performance and other factors (e.g. edge-case error handling, runtime vs compile-time configuration) are necessarily much more visible to the developer than they might be on other higher-level platforms. +The RP-series microcontrollers are powerful chips designed for embedded systems; these chips operate in environments with limited memory (RAM) and storage (program space). As a result, trade-offs between performance and other factors (such as edge-case error handling, runtime versus compile time configuration, and so on) are more apparent than they might be on higher-level platforms (like desktop systems). -The intention within the SDK has been for features to just work out of the box, with sensible defaults, but also to give the developer as much control and power as possible (if they want it) to fine-tune every aspect of the application they are building and the libraries used. +The SDK is designed to be both beginner-friendly and powerful for more experienced users. Its features work out-of-the-box with sensible defaults that cover most use cases. At the same time, it gives developers as much control as possible to tweak the application they're building and the libraries they use, if they choose to. ## The Build System -The SDK uses CMake to manage the build. CMake is widely supported by IDEs (Integrated Development Environments), and allows a simple specification of the build (via `CMakeLists.txt` files), from which CMake can generate a build system (for use by `make`, `ninja` or other build tools) customized for the platform and by any configuration variables the developer chooses. +The SDK uses **CMake** to manage the build process. CMake is a widely used build system for C and C++ development, and is supported by many IDEs (Integrated Development Environments). It allows developers to specify build instructions using `CMakeLists.txt` files, from which CMake can generate platform-specific build systems for tools like `make` and `ninja`. These builds can be customised for the intended platform and configuration variables defined by the developer. -Apart from being a widely-used build system for C/C++ development, CMake is fundamental to the way the SDK is structured, and how applications are configured and built. +Apart from its popularity, CMake is fundamental to how the SDK is structured, and how applications are configured and built. It enables consistent builds across platforms while providing flexibility for more complex embedded projects. -The SDK builds an executable which is bare-metal, i.e. it includes the entirety of the code needed to run on the device (other than device specific floating-point and other optimized code contained in the bootrom within the microcontroller). +The SDK builds a bare-metal executable, which is a standalone binary that includes all the code needed to run directly on a microcontroller, excluding device-specific low-level functionality, such as floating-point routines and other optimized code contained in a microcontroller's boot ROM. ## Examples -This SDK documentation contains a number of example code fragments. An index of these examples can be found [here](@ref examples_page). These examples, and any other source code included in this documentation, is Copyright © 2020 Raspberry Pi Ltd and licensed under the [3-Clause BSD](https://opensource.org/licenses/BSD-3-Clause) license. +This SDK documentation contains example code fragments. An index of these examples can be found in the [examples page](@ref examples_page). These examples, and any other source code included in this documentation, are Copyright © 2020 Raspberry Pi Ltd and licensed under the [3-Clause BSD](https://opensource.org/licenses/BSD-3-Clause) license. From 4242010f11e93e25611964060bfa484a01c2d3cd Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 18 Jul 2025 09:37:21 -0500 Subject: [PATCH 194/224] Misc cleanup (#2569) * miscellaneous cleanup: * cleanup some #ifdefs which were slightly hacky when RP2350 was added; use HAS_ flags in preference to PICO_RP2040/RP2350 * make some dependencies more explicit - i.e. compile if the user doesn't want to include certain libraries * cleanup some directory A -> directory B relative path names in CMakeLists.txt to be SDK root -> directory B --- cmake/pico_pre_load_toolchain.cmake | 2 +- pico_sdk_version.cmake | 26 +++++++++-------- src/cmake/rp2_common.cmake | 6 ++-- .../include/hardware/platform_defs.h | 9 ++++++ .../include/hardware/platform_defs.h | 10 +++++++ .../include/boot/bootrom_constants.h | 6 ++-- src/rp2_common/hardware_clocks/clocks.c | 4 +-- src/rp2_common/hardware_gpio/gpio.c | 2 +- .../hardware_rtc/include/hardware/rtc.h | 2 ++ src/rp2_common/pico_bit_ops/CMakeLists.txt | 5 ++-- src/rp2_common/pico_bit_ops/bit_ops_aeabi.S | 2 ++ src/rp2_common/pico_bootrom/bootrom.c | 2 +- src/rp2_common/pico_btstack/CMakeLists.txt | 2 +- .../rp2040_usb_device_enumeration.c | 2 +- src/rp2_common/pico_lwip/CMakeLists.txt | 2 +- src/rp2_common/pico_mbedtls/CMakeLists.txt | 2 +- src/rp2_common/pico_multicore/multicore.c | 2 +- src/rp2_common/pico_printf/printf_none.S | 1 - src/rp2_common/pico_rand/CMakeLists.txt | 7 ++++- src/rp2_common/pico_rand/rand.c | 8 ++++++ .../pico_runtime_init/CMakeLists.txt | 8 +++++- .../pico_runtime_init/runtime_init_clocks.c | 4 +-- .../runtime_init_stack_guard.c | 2 +- src/rp2_common/pico_stdio_uart/stdio_uart.c | 8 +++--- src/rp2_common/tinyusb/CMakeLists.txt | 28 ++++++++++++------- test/cmsis_test/CMakeLists.txt | 4 +++ test/hardware_irq_test/CMakeLists.txt | 4 +++ test/hardware_pwm_test/CMakeLists.txt | 4 +++ .../CMakeLists.txt | 5 ++++ test/pico_divider_test/CMakeLists.txt | 4 +++ test/pico_float_test/CMakeLists.txt | 5 ++++ test/pico_sha256_test/CMakeLists.txt | 3 +- test/pico_time_test/pico_time_test.c | 2 +- tools/Findpicotool.cmake | 14 ++++++++-- 34 files changed, 143 insertions(+), 54 deletions(-) diff --git a/cmake/pico_pre_load_toolchain.cmake b/cmake/pico_pre_load_toolchain.cmake index b41b386cf..8b03c5f9d 100644 --- a/cmake/pico_pre_load_toolchain.cmake +++ b/cmake/pico_pre_load_toolchain.cmake @@ -4,7 +4,7 @@ set(PICO_TOOLCHAIN_PATH "${PICO_TOOLCHAIN_PATH}" CACHE INTERNAL "") # Set a default build type if none was specified set(default_build_type "Release") -list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PREFIX_PATH) +list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PREFIX_PATH PICO_SDK_PATH) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Defaulting build type to '${default_build_type}' since not specified.") diff --git a/pico_sdk_version.cmake b/pico_sdk_version.cmake index 772ab8237..c294d325b 100644 --- a/pico_sdk_version.cmake +++ b/pico_sdk_version.cmake @@ -1,15 +1,17 @@ -# PICO_BUILD_DEFINE: PICO_SDK_VERSION_MAJOR, SDK major version number, type=int, default=Current SDK major version, group=pico_base -# PICO_CMAKE_CONFIG: PICO_SDK_VERSION_MAJOR, SDK major version number, type=int, default=Current SDK major version, group=pico_base -set(PICO_SDK_VERSION_MAJOR 2) -# PICO_BUILD_DEFINE: PICO_SDK_VERSION_MINOR, SDK minor version number, type=int, default=Current SDK minor version, group=pico_base -# PICO_CMAKE_CONFIG: PICO_SDK_VERSION_MINOR, SDK minor version number, type=int, default=Current SDK minor version, group=pico_base -set(PICO_SDK_VERSION_MINOR 1) -# PICO_BUILD_DEFINE: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base -# PICO_CMAKE_CONFIG: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base -set(PICO_SDK_VERSION_REVISION 2) -# PICO_BUILD_DEFINE: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base -# PICO_CMAKE_CONFIG: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base -set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) +if (NOT DEFINED PICO_SDK_VERSION_MAJOR) + # PICO_BUILD_DEFINE: PICO_SDK_VERSION_MAJOR, SDK major version number, type=int, default=Current SDK major version, group=pico_base + # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_MAJOR, SDK major version number, type=int, default=Current SDK major version, group=pico_base + set(PICO_SDK_VERSION_MAJOR 2) + # PICO_BUILD_DEFINE: PICO_SDK_VERSION_MINOR, SDK minor version number, type=int, default=Current SDK minor version, group=pico_base + # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_MINOR, SDK minor version number, type=int, default=Current SDK minor version, group=pico_base + set(PICO_SDK_VERSION_MINOR 1) + # PICO_BUILD_DEFINE: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base + # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base + set(PICO_SDK_VERSION_REVISION 2) + # PICO_BUILD_DEFINE: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base + # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base + set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) +endif() # PICO_BUILD_DEFINE: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index c02f9e2ca..d94d21f32 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -63,14 +63,14 @@ pico_add_subdirectory(rp2_common/hardware_watchdog) pico_add_subdirectory(rp2_common/hardware_xip_cache) pico_add_subdirectory(rp2_common/hardware_xosc) -if (PICO_RP2350 OR PICO_COMBINED_DOCS) +if (PICO_COMBINED_DOCS OR NOT PICO_RP2040) pico_add_subdirectory(rp2_common/hardware_powman) # Note in spite of the name this is usable on Arm as well as RISC-V: pico_add_subdirectory(rp2_common/hardware_riscv_platform_timer) pico_add_subdirectory(rp2_common/hardware_sha256) endif() -if (PICO_RP2350 OR PICO_COMBINED_DOCS) +if (PICO_COMBINED_DOCS OR NOT PICO_RP2040) pico_add_subdirectory(rp2_common/hardware_dcp) pico_add_subdirectory(rp2_common/hardware_rcp) endif() @@ -108,7 +108,7 @@ if (NOT PICO_BARE_METAL) pico_add_subdirectory(rp2_common/pico_printf) pico_add_subdirectory(rp2_common/pico_rand) - if (PICO_RP2350 OR PICO_COMBINED_DOCS) + if (PICO_COMBINED_DOCS OR NOT PICO_RP2040) pico_add_subdirectory(rp2_common/pico_sha256) endif() diff --git a/src/rp2040/hardware_regs/include/hardware/platform_defs.h b/src/rp2040/hardware_regs/include/hardware/platform_defs.h index 537988846..a877710d0 100644 --- a/src/rp2040/hardware_regs/include/hardware/platform_defs.h +++ b/src/rp2040/hardware_regs/include/hardware/platform_defs.h @@ -46,6 +46,15 @@ #define HAS_SIO_DIVIDER 1 #define HAS_RP2040_RTC 1 + +#ifndef FPGA_CLK_SYS_HZ +#define FPGA_CLK_SYS_HZ (48 * MHZ) +#endif + +#ifndef FPGA_CLK_REF_HZ +#define FPGA_CLK_REF_HZ (12 * MHZ) +#endif + // PICO_CONFIG: XOSC_HZ, Crystal oscillator frequency in Hz, type=int, default=12000000, advanced=true, group=hardware_base // NOTE: The system and USB clocks are generated from the frequency using two PLLs. // If you override this define, or SYS_CLK_HZ/USB_CLK_HZ below, you will *also* need to add your own adjusted PLL set-up defines to diff --git a/src/rp2350/hardware_regs/include/hardware/platform_defs.h b/src/rp2350/hardware_regs/include/hardware/platform_defs.h index 25dc1d624..c919b94c1 100644 --- a/src/rp2350/hardware_regs/include/hardware/platform_defs.h +++ b/src/rp2350/hardware_regs/include/hardware/platform_defs.h @@ -73,6 +73,16 @@ #define HAS_POWMAN_TIMER 1 #define HAS_RP2350_TRNG 1 #define HAS_HSTX 1 +#define HAS_PADS_BANK0_ISOLATION 1 +#define __RISCV_PMP_CHECKED 1 + +#ifndef FPGA_CLK_SYS_HZ +#define FPGA_CLK_SYS_HZ (48 * MHZ) +#endif + +#ifndef FPGA_CLK_REF_HZ +#define FPGA_CLK_REF_HZ (12 * MHZ) +#endif // PICO_CONFIG: XOSC_HZ, Crystal oscillator frequency in Hz, type=int, default=12000000, advanced=true, group=hardware_base // NOTE: The system and USB clocks are generated from the frequency using two PLLs. diff --git a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h index 7f891f7ee..e7fe6f63b 100644 --- a/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h +++ b/src/rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h @@ -255,11 +255,11 @@ typedef int (*bootrom_api_callback_generic_t)(uint32_t r0, uint32_t r1, uint32_t #define BOOTROM_NS_API_get_b_partition 7 #define BOOTROM_NS_API_COUNT 8 -#define OTP_CMD_ROW_BITS 0x0000ffffu +#define OTP_CMD_ROW_BITS _u(0x0000ffff) #define OTP_CMD_ROW_LSB _u(0) -#define OTP_CMD_WRITE_BITS 0x00010000u +#define OTP_CMD_WRITE_BITS _u(0x00010000) #define OTP_CMD_WRITE_LSB _u(16) -#define OTP_CMD_ECC_BITS 0x00020000u +#define OTP_CMD_ECC_BITS _u(0x00020000) #define OTP_CMD_ECC_LSB _u(17) #ifndef __ASSEMBLER__ diff --git a/src/rp2_common/hardware_clocks/clocks.c b/src/rp2_common/hardware_clocks/clocks.c index 1362a3a28..2bcaa5741 100644 --- a/src/rp2_common/hardware_clocks/clocks.c +++ b/src/rp2_common/hardware_clocks/clocks.c @@ -270,12 +270,12 @@ static const uint8_t gpin0_src[CLK_COUNT] = { CLOCKS_CLK_REF_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_REF CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_SYS CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_PERI -#if !PICO_RP2040 +#if HAS_HSTX CLOCKS_CLK_HSTX_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_HSTX #endif CLOCKS_CLK_USB_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_USB CLOCKS_CLK_ADC_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_ADC -#if PICO_RP2040 +#if HAS_RP2040_RTC CLOCKS_CLK_RTC_CTRL_AUXSRC_VALUE_CLKSRC_GPIN0, // CLK_RTC #endif }; diff --git a/src/rp2_common/hardware_gpio/gpio.c b/src/rp2_common/hardware_gpio/gpio.c index 0a7bf90fa..292041a19 100644 --- a/src/rp2_common/hardware_gpio/gpio.c +++ b/src/rp2_common/hardware_gpio/gpio.c @@ -46,7 +46,7 @@ void gpio_set_function(uint gpio, gpio_function_t fn) { // Zero all fields apart from fsel; we want this IO to do what the peripheral tells it. // This doesn't affect e.g. pullup/pulldown, as these are in pad controls. io_bank0_hw->io[gpio].ctrl = fn << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB; -#if !PICO_RP2040 +#if HAS_PADS_BANK0_ISOLATION // Remove pad isolation now that the correct peripheral is in control of the pad hw_clear_bits(&pads_bank0_hw->io[gpio], PADS_BANK0_GPIO0_ISO_BITS); #endif diff --git a/src/rp2_common/hardware_rtc/include/hardware/rtc.h b/src/rp2_common/hardware_rtc/include/hardware/rtc.h index 32317879c..9e05c7afb 100644 --- a/src/rp2_common/hardware_rtc/include/hardware/rtc.h +++ b/src/rp2_common/hardware_rtc/include/hardware/rtc.h @@ -8,7 +8,9 @@ #define _HARDWARE_RTC_H #include "pico.h" +#if HAS_RP2040_RTC #include "hardware/structs/rtc.h" +#endif /** \file hardware/rtc.h * \defgroup hardware_rtc hardware_rtc diff --git a/src/rp2_common/pico_bit_ops/CMakeLists.txt b/src/rp2_common/pico_bit_ops/CMakeLists.txt index a66a441f6..f3e8e1a72 100644 --- a/src/rp2_common/pico_bit_ops/CMakeLists.txt +++ b/src/rp2_common/pico_bit_ops/CMakeLists.txt @@ -19,9 +19,10 @@ if (NOT TARGET pico_bit_ops) ${CMAKE_CURRENT_LIST_DIR}/bit_ops_aeabi.S ) - target_link_libraries(pico_bit_ops_pico INTERFACE pico_bootrom pico_bit_ops_headers) + target_link_libraries(pico_bit_ops_pico INTERFACE pico_bit_ops_headers) - if (NOT PICO_RP2350) + if (PICO_RP2040) + target_link_libraries(pico_bit_ops_pico INTERFACE pico_bootrom) # gcc pico_wrap_function(pico_bit_ops_pico __clzsi2) pico_wrap_function(pico_bit_ops_pico __clzsi2) diff --git a/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S b/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S index 65a1bb4c9..88d0bc618 100644 --- a/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S +++ b/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S @@ -5,7 +5,9 @@ */ #include "pico/asm_helper.S" +#if PICO_RP2040 #include "pico/bootrom.h" +#endif #include "pico/runtime_init.h" pico_default_asm_setup diff --git a/src/rp2_common/pico_bootrom/bootrom.c b/src/rp2_common/pico_bootrom/bootrom.c index 0c0053514..516a9fb50 100644 --- a/src/rp2_common/pico_bootrom/bootrom.c +++ b/src/rp2_common/pico_bootrom/bootrom.c @@ -113,7 +113,7 @@ int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32 } int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num) { -#if PICO_RP2350 +#if !PICO_RP2040 // Generated from adding the following code into the bootrom // scan_workarea_t* scan_workarea = (scan_workarea_t*)workarea; // printf("VERSION_DOWNGRADE_ERASE_ADDR %08x\n", &(always->zero_init.version_downgrade_erase_flash_addr)); diff --git a/src/rp2_common/pico_btstack/CMakeLists.txt b/src/rp2_common/pico_btstack/CMakeLists.txt index 593b666ff..5fb76fcf7 100644 --- a/src/rp2_common/pico_btstack/CMakeLists.txt +++ b/src/rp2_common/pico_btstack/CMakeLists.txt @@ -6,7 +6,7 @@ endif () set(BTSTACK_TEST_PATH "src/bluetooth.h") if (NOT PICO_BTSTACK_PATH) - set(PICO_BTSTACK_PATH ${PROJECT_SOURCE_DIR}/lib/btstack) + set(PICO_BTSTACK_PATH ${PICO_SDK_PATH}/lib/btstack) if (PICO_CYW43_SUPPORTED AND NOT EXISTS ${PICO_BTSTACK_PATH}/${BTSTACK_TEST_PATH}) message(WARNING "btstack submodule has not been initialized; Pico W BLE support will be unavailable. hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).") diff --git a/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c b/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c index 91315d193..88b7c9458 100644 --- a/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c +++ b/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c @@ -5,6 +5,7 @@ */ #include "pico.h" +#if PICO_RP2040_B0_SUPPORTED || PICO_RP2040_B1_SUPPORTED #include "pico/time.h" #include "hardware/structs/usb.h" #include "hardware/gpio.h" @@ -17,7 +18,6 @@ #define LS_K 0b10 #define LS_SE1 0b11 -#if PICO_RP2040_B0_SUPPORTED || PICO_RP2040_B1_SUPPORTED static void hw_enumeration_fix_wait_se0(void); static void hw_enumeration_fix_force_ls_j(void); static void hw_enumeration_fix_finish(void); diff --git a/src/rp2_common/pico_lwip/CMakeLists.txt b/src/rp2_common/pico_lwip/CMakeLists.txt index 7897754e6..71da00176 100644 --- a/src/rp2_common/pico_lwip/CMakeLists.txt +++ b/src/rp2_common/pico_lwip/CMakeLists.txt @@ -6,7 +6,7 @@ endif () set(LWIP_TEST_PATH "src/Filelists.cmake") if (NOT PICO_LWIP_PATH) - set(PICO_LWIP_PATH ${PROJECT_SOURCE_DIR}/lib/lwip) + set(PICO_LWIP_PATH ${PICO_SDK_PATH}/lib/lwip) if (PICO_CYW43_SUPPORTED AND NOT EXISTS ${PICO_LWIP_PATH}/${LWIP_TEST_PATH}) message(WARNING "LWIP submodule has not been initialized; Pico W wireless support will be unavailable #hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).") diff --git a/src/rp2_common/pico_mbedtls/CMakeLists.txt b/src/rp2_common/pico_mbedtls/CMakeLists.txt index 19fe47822..608b457ea 100644 --- a/src/rp2_common/pico_mbedtls/CMakeLists.txt +++ b/src/rp2_common/pico_mbedtls/CMakeLists.txt @@ -6,7 +6,7 @@ endif() set(MBEDTLS_TEST_PATH "library/aes.c") if (NOT PICO_MBEDTLS_PATH) - set(PICO_MBEDTLS_PATH ${PROJECT_SOURCE_DIR}/lib/mbedtls) + set(PICO_MBEDTLS_PATH ${PICO_SDK_PATH}/lib/mbedtls) elseif (NOT EXISTS ${PICO_MBEDTLS_PATH}/${MBEDTLS_TEST_PATH}) message(WARNING "PICO_MBEDTLS_PATH specified but content not present.") endif() diff --git a/src/rp2_common/pico_multicore/multicore.c b/src/rp2_common/pico_multicore/multicore.c index 73a1a999a..219f24a16 100644 --- a/src/rp2_common/pico_multicore/multicore.c +++ b/src/rp2_common/pico_multicore/multicore.c @@ -14,7 +14,7 @@ #include "hardware/structs/scb.h" #endif #include "hardware/structs/sio.h" -#include "hardware/regs/psm.h" +#include "hardware/structs/psm.h" #include "hardware/claim.h" #if !PICO_RP2040 diff --git a/src/rp2_common/pico_printf/printf_none.S b/src/rp2_common/pico_printf/printf_none.S index 0148f265f..57cf34411 100644 --- a/src/rp2_common/pico_printf/printf_none.S +++ b/src/rp2_common/pico_printf/printf_none.S @@ -5,7 +5,6 @@ */ #include "pico/asm_helper.S" -#include "pico/bootrom/sf_table.h" pico_default_asm_setup diff --git a/src/rp2_common/pico_rand/CMakeLists.txt b/src/rp2_common/pico_rand/CMakeLists.txt index 9af7d470d..24db85c29 100644 --- a/src/rp2_common/pico_rand/CMakeLists.txt +++ b/src/rp2_common/pico_rand/CMakeLists.txt @@ -7,8 +7,13 @@ target_sources(pico_rand INTERFACE target_include_directories(pico_rand_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) pico_mirrored_target_link_libraries(pico_rand INTERFACE - pico_unique_id hardware_clocks hardware_timer hardware_sync ) + +if (TARGET pico_unique_id) + pico_mirrored_target_link_libraries(pico_rand INTERFACE + pico_unique_id + ) +endif() \ No newline at end of file diff --git a/src/rp2_common/pico_rand/rand.c b/src/rp2_common/pico_rand/rand.c index 794c63e4c..03b0e3d61 100644 --- a/src/rp2_common/pico_rand/rand.c +++ b/src/rp2_common/pico_rand/rand.c @@ -25,11 +25,19 @@ */ #include "pico/rand.h" +#if PICO_RAND_SEED_ENTROPY_SRC_BOARD_ID #include "pico/unique_id.h" +#endif +#if PICO_RAND_ENTROPY_SRC_TIME #include "pico/time.h" +#endif #include "hardware/clocks.h" +#if PICO_RAND_SEED_ENTROPY_SRC_ROSC || PICO_RAND_ENTROPY_SRC_ROSC #include "hardware/structs/rosc.h" +#endif +#if PICO_RAND_SEED_ENTROPY_SRC_BUS_PERF_COUNTER || PICO_RAND_ENTROPY_SRC_BUS_PERF_COUNTER #include "hardware/structs/busctrl.h" +#endif #include "hardware/sync.h" static bool rng_initialised = false; diff --git a/src/rp2_common/pico_runtime_init/CMakeLists.txt b/src/rp2_common/pico_runtime_init/CMakeLists.txt index 81f6ab47f..60d1833e0 100644 --- a/src/rp2_common/pico_runtime_init/CMakeLists.txt +++ b/src/rp2_common/pico_runtime_init/CMakeLists.txt @@ -13,7 +13,13 @@ pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE ) if (TARGET hardware_clocks) - pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_clocks hardware_timer hardware_vreg) + pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_clocks) +endif() +if (TARGET hardware_timer) + pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_timer) +endif() +if (TARGET hardware_vreg) + pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_vreg) endif() # pico/runtime_init.h includes pico/runtime.h diff --git a/src/rp2_common/pico_runtime_init/runtime_init_clocks.c b/src/rp2_common/pico_runtime_init/runtime_init_clocks.c index 85d473b8e..a86fe8052 100644 --- a/src/rp2_common/pico_runtime_init/runtime_init_clocks.c +++ b/src/rp2_common/pico_runtime_init/runtime_init_clocks.c @@ -41,10 +41,10 @@ void __weak runtime_init_clocks(void) { // Note: These need setting *before* the ticks are started if (running_on_fpga()) { for (uint i = 0; i < CLK_COUNT; i++) { - clock_set_reported_hz(i, 48 * MHZ); + clock_set_reported_hz(i, FPGA_CLK_SYS_HZ); } // clk_ref is 12MHz in both RP2040 and RP2350 FPGA - clock_set_reported_hz(clk_ref, 12 * MHZ); + clock_set_reported_hz(clk_ref, FPGA_CLK_REF_HZ); // RP2040 has an extra clock, the rtc #if HAS_RP2040_RTC clock_set_reported_hz(clk_rtc, RTC_CLOCK_FREQ_HZ); diff --git a/src/rp2_common/pico_runtime_init/runtime_init_stack_guard.c b/src/rp2_common/pico_runtime_init/runtime_init_stack_guard.c index 27480f2ce..964742eb2 100644 --- a/src/rp2_common/pico_runtime_init/runtime_init_stack_guard.c +++ b/src/rp2_common/pico_runtime_init/runtime_init_stack_guard.c @@ -32,7 +32,7 @@ void runtime_init_per_core_install_stack_guard(void *stack_bottom) { | 0x10000000; // XN = disable instruction fetch; no other bits means no permissions #elif defined(__riscv) - #if !PICO_RP2350 +#if !__RISCV_PMP_CHECKED #error "Check PMP configuration for new platform" #endif // RISC-V PMP, RP2350 configuration of Hazard3: 8 non-hardwired regions, diff --git a/src/rp2_common/pico_stdio_uart/stdio_uart.c b/src/rp2_common/pico_stdio_uart/stdio_uart.c index 54cd86e01..2e2619c11 100644 --- a/src/rp2_common/pico_stdio_uart/stdio_uart.c +++ b/src/rp2_common/pico_stdio_uart/stdio_uart.c @@ -128,13 +128,13 @@ void stdio_uart_deinit_full(struct uart_inst *uart, int tx_pin, int rx_pin) { uart_instance = uart; stdio_set_driver_enabled(&stdio_uart, false); uart_deinit(uart_instance); -#if PICO_RP2040 - ((void)tx_pin); - ((void)rx_pin); -#else +#if HAS_PADS_BANK0_ISOLATION // Leave pads isolated if (tx_pin >= 0) hw_set_bits(&pads_bank0_hw->io[tx_pin], PADS_BANK0_GPIO0_ISO_BITS); if (rx_pin >= 0) hw_set_bits(&pads_bank0_hw->io[rx_pin], PADS_BANK0_GPIO0_ISO_BITS); +#else + ((void)tx_pin); + ((void)rx_pin); #endif } diff --git a/src/rp2_common/tinyusb/CMakeLists.txt b/src/rp2_common/tinyusb/CMakeLists.txt index 3e12439c0..e4115f896 100644 --- a/src/rp2_common/tinyusb/CMakeLists.txt +++ b/src/rp2_common/tinyusb/CMakeLists.txt @@ -4,15 +4,19 @@ if (DEFINED ENV{PICO_TINYUSB_PATH} AND (NOT PICO_TINYUSB_PATH)) message("Using PICO_TINYUSB_PATH from environment ('${PICO_TINYUSB_PATH}')") endif () -set(TINYUSB_TEST_PATH "src/portable/raspberrypi/rp2040") +set(TINYUSB_TEST_PATH "hw/bsp/rp2040") if (NOT PICO_TINYUSB_PATH) - set(PICO_TINYUSB_PATH ${PROJECT_SOURCE_DIR}/lib/tinyusb) + set(PICO_TINYUSB_PATH ${PICO_SDK_PATH}/lib/tinyusb) if (NOT EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}) - message(WARNING "TinyUSB submodule has not been initialized; USB support will be unavailable + if (EXISTS "${PICO_TINYUSB_PATH}/LICENSE") + message(WARNING "TinyUSB submodule has been initialized, but does not contain ${TINYUSB_TEST_PATH}; USB support will be unavailable") + else() + message(WARNING "TinyUSB submodule has not been initialized; USB support will be unavailable hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).") + endif() endif() elseif (NOT EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}) - message(WARNING "PICO_TINYUSB_PATH specified but content not present.") + message(WARNING "PICO_TINYUSB_PATH specified, but does not contain ${TINYUSB_TEST_PATH}; USB support will be unavailable") endif() if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}) @@ -35,14 +39,18 @@ if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}) PICO_RP2040_USB_DEVICE_UFRAME_FIX=1 ) - # unmarked version used by stdio USB - target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_common pico_fix_rp2040_usb_device_enumeration tinyusb_device_base) + if (TARGET tinyusb_device_base) + # unmarked version used by stdio USB + target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_common pico_fix_rp2040_usb_device_enumeration tinyusb_device_base) - pico_add_library(tinyusb_device) - target_link_libraries(tinyusb_device INTERFACE tinyusb_device_unmarked) + pico_add_library(tinyusb_device) + target_link_libraries(tinyusb_device INTERFACE tinyusb_device_unmarked) + endif() - pico_add_library(tinyusb_host) - target_link_libraries(tinyusb_host INTERFACE tinyusb_host_base tinyusb_common) + if (TARGET tinyusb_host_base) + pico_add_library(tinyusb_host) + target_link_libraries(tinyusb_host INTERFACE tinyusb_host_base tinyusb_common) + endif() pico_add_library(tinyusb_board) target_include_directories(tinyusb_board INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) diff --git a/test/cmsis_test/CMakeLists.txt b/test/cmsis_test/CMakeLists.txt index ca992eeaf..f6b095b46 100644 --- a/test/cmsis_test/CMakeLists.txt +++ b/test/cmsis_test/CMakeLists.txt @@ -1,3 +1,7 @@ +if (NOT TARGET cmsis_core) + message("Skipping cmsis_test as cmsis_core is unavailable on this platform") + return() +endif() # todo remove check if (NOT PICO_RISCV) add_executable(cmsis_test cmsis_test.c) diff --git a/test/hardware_irq_test/CMakeLists.txt b/test/hardware_irq_test/CMakeLists.txt index 90ef50a2b..f329e6172 100644 --- a/test/hardware_irq_test/CMakeLists.txt +++ b/test/hardware_irq_test/CMakeLists.txt @@ -1,3 +1,7 @@ +if (NOT TARGET hardware_dma) + message("Skipping hardware_irq_test as hardware_dma is unavailable on this platform") + return() +endif() add_executable(hardware_irq_test hardware_irq_test.c) target_link_libraries(hardware_irq_test PRIVATE pico_test hardware_irq hardware_dma) diff --git a/test/hardware_pwm_test/CMakeLists.txt b/test/hardware_pwm_test/CMakeLists.txt index c0e08a464..c26893cca 100644 --- a/test/hardware_pwm_test/CMakeLists.txt +++ b/test/hardware_pwm_test/CMakeLists.txt @@ -1,3 +1,7 @@ +if (NOT TARGET hardware_pwm) + message("Skipping hardware_pwm_test as hardware_pwm is unavailable on this platform") + return() +endif() add_executable(hardware_pwm_test hardware_pwm_test.c) target_link_libraries(hardware_pwm_test PRIVATE pico_test hardware_pwm) diff --git a/test/hardware_sync_spin_lock_test/CMakeLists.txt b/test/hardware_sync_spin_lock_test/CMakeLists.txt index 36edf813c..e81069aa8 100644 --- a/test/hardware_sync_spin_lock_test/CMakeLists.txt +++ b/test/hardware_sync_spin_lock_test/CMakeLists.txt @@ -1,3 +1,8 @@ +if (NOT TARGET pico_multicore) + message("Skipping hardware_sync_spin_lock_test as pico_multicore is unavailable on this platform") + return() +endif() + add_executable(hardware_sync_spin_lock_test hardware_sync_spin_lock_test.c) target_link_libraries(hardware_sync_spin_lock_test PRIVATE pico_test hardware_sync pico_multicore) diff --git a/test/pico_divider_test/CMakeLists.txt b/test/pico_divider_test/CMakeLists.txt index b180b9d77..94d73100e 100644 --- a/test/pico_divider_test/CMakeLists.txt +++ b/test/pico_divider_test/CMakeLists.txt @@ -1,3 +1,7 @@ +if (NOT TARGET pico_divider) + message("Skipping pico_divider_test as pico_divider is unavailable on this platform") + return() +endif() PROJECT(pico_divider_test) if (PICO_ON_DEVICE) diff --git a/test/pico_float_test/CMakeLists.txt b/test/pico_float_test/CMakeLists.txt index 93845bb36..8bf0de201 100644 --- a/test/pico_float_test/CMakeLists.txt +++ b/test/pico_float_test/CMakeLists.txt @@ -1,3 +1,8 @@ +if (NOT TARGET pico_float) + message("Skipping pico_float_test as pico_float is unavailable on this platform") + return() +endif() + PROJECT(pico_float_test) diff --git a/test/pico_sha256_test/CMakeLists.txt b/test/pico_sha256_test/CMakeLists.txt index 8474f3edb..8dc6dd326 100644 --- a/test/pico_sha256_test/CMakeLists.txt +++ b/test/pico_sha256_test/CMakeLists.txt @@ -1,4 +1,5 @@ -if (NOT TARGET hardware_sha256) +if (NOT TARGET pico_sha256) + message("Skipping pico_sha256_test as pico_sha256 is unavailable on this platform") return() endif() diff --git a/test/pico_time_test/pico_time_test.c b/test/pico_time_test/pico_time_test.c index 8b23c5a42..9ed05e209 100644 --- a/test/pico_time_test/pico_time_test.c +++ b/test/pico_time_test/pico_time_test.c @@ -41,8 +41,8 @@ static struct timeout { alarm_id_t alarm_id; absolute_time_t target; absolute_time_t fired_at; - uint pool; uint fired_count; + uint8_t pool; bool cancelled; bool not_cancelled; // tried to cancel but it was done } timeouts[NUM_TIMEOUTS]; diff --git a/tools/Findpicotool.cmake b/tools/Findpicotool.cmake index e5bfaeaac..79a8d2ed3 100644 --- a/tools/Findpicotool.cmake +++ b/tools/Findpicotool.cmake @@ -34,10 +34,20 @@ if (NOT TARGET picotool) ) endif() + if (NOT PICOTOOL_GIT_REPOSITORY_URL) + set(PICOTOOL_GIT_REPOSITORY_URL https://github.com/raspberrypi/picotool.git) + endif() + if (NOT PICOTOOL_GIT_BRANCH) + if (PICO_SDK_VERSION_PRE_RELEASE_ID) + set(PICOTOOL_GIT_BRANCH ${PICO_SDK_VERSION_PRE_RELEASE_ID}) + else() + set(PICOTOOL_GIT_BRANCH ${PICO_SDK_VERSION_STRING}) + endif() + endif() message("Downloading Picotool") FetchContent_Populate(picotool QUIET - GIT_REPOSITORY https://github.com/raspberrypi/picotool.git - GIT_TAG develop + GIT_REPOSITORY ${PICOTOOL_GIT_REPOSITORY_URL} + GIT_TAG ${PICOTOOL_GIT_BRANCH} SOURCE_DIR ${picotool_INSTALL_DIR}/picotool-src BINARY_DIR ${picotool_INSTALL_DIR}/picotool-build From 175abe731515d7cb7e0bb7016f0ddd05b40b2667 Mon Sep 17 00:00:00 2001 From: Luke Wren Date: Fri, 18 Jul 2025 15:51:36 +0100 Subject: [PATCH 195/224] Clarify pio_gpio_init doxygen (fixes #2387) (#2574) --- .../hardware_pio/include/hardware/pio.h | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/hardware_pio/include/hardware/pio.h b/src/rp2_common/hardware_pio/include/hardware/pio.h index 8654d32a7..4363608fc 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio.h @@ -872,9 +872,25 @@ static inline PIO pio_get_instance(uint instance) { * * PIO appears as an alternate function in the GPIO muxing, just like an SPI * or UART. This function configures that multiplexing to connect a given PIO - * instance to a GPIO. Note that this is not necessary for a state machine to - * be able to read the *input* value from a GPIO, but only for it to set the - * output value or output enable. + * instance to a GPIO. It also configures the GPIO pad to pass signals in and + * out, by: + * + * * Clearing the pad output disable (OD) bit + * * Setting the pad input enable (IE) bit + * * (Non-RP2040) removing pad isolation + * + * This function achieves this low-level pad setup by calling gpio_set_function() + * internally. + * + * Note that, if your PIO program only needs the *input* from a given GPIO, + * it's not necessary to select the PIO GPIO function, because PIO input + * paths ignore the GPIO muxing. However, you must still configure the GPIO + * pad itself for input. + * + * Conversely, if using PIO for both input and output on a given pin, you must + * select the PIO GPIO function for the given PIO instance, as well as + * configuring the pad for input and output. Calling this function is + * sufficient for both the input-only and input/output case. * * \param pio The PIO instance; e.g. \ref pio0 or \ref pio1 * \param pin the GPIO pin whose function select to set From dfc26a00b09174c8f54de8b3b19eee359ca5d086 Mon Sep 17 00:00:00 2001 From: Luke Wren Date: Sun, 20 Jul 2025 23:19:38 +0100 Subject: [PATCH 196/224] hardware_flash: preserve QSPI pad state over flash access calls. (#2565) * hardware_flash: preserve QSPI pad state over flash access calls. Add new function, flash_start_xip(), which explicitly performs a first-time XIP setup (including initialising pads). This is mostly useful for PICO_NO_FLASH=1 binaries where there is actually an attached external flash. Fixes #2333 * Address review comments --- src/rp2_common/hardware_flash/flash.c | 114 ++++++++++++++---- .../hardware_flash/include/hardware/flash.h | 26 ++++ 2 files changed, 114 insertions(+), 26 deletions(-) diff --git a/src/rp2_common/hardware_flash/flash.c b/src/rp2_common/hardware_flash/flash.c index dab5d6b46..fbca8de2c 100644 --- a/src/rp2_common/hardware_flash/flash.c +++ b/src/rp2_common/hardware_flash/flash.c @@ -14,6 +14,7 @@ #include "hardware/structs/qmi.h" #include "hardware/regs/otp_data.h" #endif +#include "hardware/structs/pads_qspi.h" #include "hardware/xip_cache.h" #define FLASH_BLOCK_ERASE_CMD 0xd8 @@ -71,7 +72,23 @@ static void __no_inline_not_in_flash_func(flash_enable_xip_via_boot2)(void) { #endif -#if PICO_RP2350 +//----------------------------------------------------------------------------- +// State save/restore + +// Most functions save and restore the QSPI pad state over the call. (The main +// exception is flash_start_xip() which is explicitly intended to initialise +// them). The expectation is that by the time you do any flash operations, +// you have either gone through a normal flash boot process or (in the case +// of PICO_NO_FLASH=1) you have called flash_start_xip(). Any further +// modifications to the pad state are therefore deliberate changes that we +// should preserve. +// +// Additionally, on RP2350, we save and restore the window 1 QMI configuration +// if the user has not opted into bootrom CS1 support via FLASH_DEVINFO OTP +// flags. This avoids clobbering CS1 setup (e.g. PSRAM) performed by the +// application. + +#if !PICO_RP2040 // This is specifically for saving/restoring the registers modified by RP2350 // flash_exit_xip() ROM func, not the entirety of the QMI window state. typedef struct flash_rp2350_qmi_save_state { @@ -108,9 +125,69 @@ static void __no_inline_not_in_flash_func(flash_rp2350_restore_qmi_cs1)(const fl } #endif + +typedef struct flash_hardware_save_state { +#if !PICO_RP2040 + flash_rp2350_qmi_save_state_t qmi_save; +#endif + uint32_t qspi_pads[count_of(pads_qspi_hw->io)]; +} flash_hardware_save_state_t; + +static void __no_inline_not_in_flash_func(flash_save_hardware_state)(flash_hardware_save_state_t *state) { + // Commit any pending writes to external RAM, to avoid losing them in a subsequent flush: + xip_cache_clean_all(); + for (size_t i = 0; i < count_of(pads_qspi_hw->io); ++i) { + state->qspi_pads[i] = pads_qspi_hw->io[i]; + } +#if !PICO_RP2040 + flash_rp2350_save_qmi_cs1(&state->qmi_save); +#endif +} + +static void __no_inline_not_in_flash_func(flash_restore_hardware_state)(flash_hardware_save_state_t *state) { + for (size_t i = 0; i < count_of(pads_qspi_hw->io); ++i) { + pads_qspi_hw->io[i] = state->qspi_pads[i]; + } +#if !PICO_RP2040 + // Tail call! + flash_rp2350_restore_qmi_cs1(&state->qmi_save); +#endif +} + //----------------------------------------------------------------------------- // Actual flash programming shims (work whether or not PICO_NO_FLASH==1) +void __no_inline_not_in_flash_func(flash_start_xip)(void) { + rom_connect_internal_flash_fn connect_internal_flash_func = (rom_connect_internal_flash_fn)rom_func_lookup_inline(ROM_FUNC_CONNECT_INTERNAL_FLASH); + rom_flash_exit_xip_fn flash_exit_xip_func = (rom_flash_exit_xip_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_EXIT_XIP); + rom_flash_flush_cache_fn flash_flush_cache_func = (rom_flash_flush_cache_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_FLUSH_CACHE); + rom_flash_enter_cmd_xip_fn flash_enter_cmd_xip_func = (rom_flash_enter_cmd_xip_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_ENTER_CMD_XIP); + assert(connect_internal_flash_func && flash_exit_xip_func && flash_flush_cache_func && flash_enter_cmd_xip_func); + // Commit any pending writes to external RAM, to avoid losing them in the subsequent flush: + xip_cache_clean_all(); +#if !PICO_RP2040 + flash_rp2350_qmi_save_state_t qmi_save; + flash_rp2350_save_qmi_cs1(&qmi_save); +#endif + + // Use ROM calls to get from ~any state to a state where low-speed flash access works: + connect_internal_flash_func(); + flash_exit_xip_func(); + flash_flush_cache_func(); + flash_enter_cmd_xip_func(); + + // If a boot2 is available then call it now. Slight limitation here is that if this is a + // NO_FLASH binary which was loaded via bootrom LOAD_MAP, we should actually have a better + // flash setup than this available via xip setup func stub left in boot RAM, but we can't + // easily detect this case to take advantage of this. + flash_init_boot2_copyout(); + flash_enable_xip_via_boot2(); + +#if !PICO_RP2040 + flash_rp2350_restore_qmi_cs1(&qmi_save); +#endif +} + void __no_inline_not_in_flash_func(flash_range_erase)(uint32_t flash_offs, size_t count) { #ifdef PICO_FLASH_SIZE_BYTES hard_assert(flash_offs + count <= PICO_FLASH_SIZE_BYTES); @@ -123,12 +200,8 @@ void __no_inline_not_in_flash_func(flash_range_erase)(uint32_t flash_offs, size_ rom_flash_flush_cache_fn flash_flush_cache_func = (rom_flash_flush_cache_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_FLUSH_CACHE); assert(connect_internal_flash_func && flash_exit_xip_func && flash_range_erase_func && flash_flush_cache_func); flash_init_boot2_copyout(); - // Commit any pending writes to external RAM, to avoid losing them in the subsequent flush: - xip_cache_clean_all(); -#if PICO_RP2350 - flash_rp2350_qmi_save_state_t qmi_save; - flash_rp2350_save_qmi_cs1(&qmi_save); -#endif + flash_hardware_save_state_t state; + flash_save_hardware_state(&state); // No flash accesses after this point __compiler_memory_barrier(); @@ -138,9 +211,7 @@ void __no_inline_not_in_flash_func(flash_range_erase)(uint32_t flash_offs, size_ flash_range_erase_func(flash_offs, count, FLASH_BLOCK_SIZE, FLASH_BLOCK_ERASE_CMD); flash_flush_cache_func(); // Note this is needed to remove CSn IO force as well as cache flushing flash_enable_xip_via_boot2(); -#if PICO_RP2350 - flash_rp2350_restore_qmi_cs1(&qmi_save); -#endif + flash_restore_hardware_state(&state); } void __no_inline_not_in_flash_func(flash_flush_cache)(void) { @@ -160,11 +231,8 @@ void __no_inline_not_in_flash_func(flash_range_program)(uint32_t flash_offs, con rom_flash_flush_cache_fn flash_flush_cache_func = (rom_flash_flush_cache_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_FLUSH_CACHE); assert(connect_internal_flash_func && flash_exit_xip_func && flash_range_program_func && flash_flush_cache_func); flash_init_boot2_copyout(); - xip_cache_clean_all(); -#if PICO_RP2350 - flash_rp2350_qmi_save_state_t qmi_save; - flash_rp2350_save_qmi_cs1(&qmi_save); -#endif + flash_hardware_save_state_t state; + flash_save_hardware_state(&state); __compiler_memory_barrier(); @@ -173,9 +241,8 @@ void __no_inline_not_in_flash_func(flash_range_program)(uint32_t flash_offs, con flash_range_program_func(flash_offs, data, count); flash_flush_cache_func(); // Note this is needed to remove CSn IO force as well as cache flushing flash_enable_xip_via_boot2(); -#if PICO_RP2350 - flash_rp2350_restore_qmi_cs1(&qmi_save); -#endif + + flash_restore_hardware_state(&state); } //----------------------------------------------------------------------------- @@ -208,11 +275,8 @@ void __no_inline_not_in_flash_func(flash_do_cmd)(const uint8_t *txbuf, uint8_t * rom_flash_flush_cache_fn flash_flush_cache_func = (rom_flash_flush_cache_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_FLUSH_CACHE); assert(connect_internal_flash_func && flash_exit_xip_func && flash_flush_cache_func); flash_init_boot2_copyout(); - xip_cache_clean_all(); -#if PICO_RP2350 - flash_rp2350_qmi_save_state_t qmi_save; - flash_rp2350_save_qmi_cs1(&qmi_save); -#endif + flash_hardware_save_state_t state; + flash_save_hardware_state(&state); __compiler_memory_barrier(); connect_internal_flash_func(); @@ -260,9 +324,7 @@ void __no_inline_not_in_flash_func(flash_do_cmd)(const uint8_t *txbuf, uint8_t * flash_flush_cache_func(); flash_enable_xip_via_boot2(); -#if PICO_RP2350 - flash_rp2350_restore_qmi_cs1(&qmi_save); -#endif + flash_restore_hardware_state(&state); } #endif diff --git a/src/rp2_common/hardware_flash/include/hardware/flash.h b/src/rp2_common/hardware_flash/include/hardware/flash.h index af6343274..2bb5d5ae3 100644 --- a/src/rp2_common/hardware_flash/include/hardware/flash.h +++ b/src/rp2_common/hardware_flash/include/hardware/flash.h @@ -56,6 +56,32 @@ extern "C" { #endif +/*! \brief Initialise QSPI interface and external QSPI devices for execute-in-place + * \ingroup hardware_flash + * + * This function performs the same first-time flash setup that would normally occur over the course + * of the bootrom locating a flash binary and booting it, and that flash binary executing the SDK + * crt0. Specifically: + * + * * Initialise QSPI pads to their default states, and (non-RP2040) disable pad isolation latches + * * Issue a hardcoded sequence to attached QSPI devices to return them to a serial command state + * * Flush the XIP cache + * * Configure the QSPI interface for low-speed 03h reads + * * If this is not a PICO_NO_FLASH=1 binary: + * * (RP2040) load a boot2 stage from the first 256 bytes of RAM and execute it + * * (non-RP2040) execute an XIP setup function stored in boot RAM by either the bootrom or by crt0 + * + * This is mostly useful for initialising flash on a PICO_NO_FLASH=1 binary. (In spite of the name, + * this binary type really means "preloaded to RAM" and there may still be a flash device.) + * + * This function does not preserve the QSPI interface state or pad state. This is in contrast to + * most other functions in this library, which preserve at least the QSPI pad state. However, on + * RP2350 it does preserve the QMI window 1 configuration if you have not opted into bootrom CS1 + * support via FLASH_DEVINFO. + */ +void flash_start_xip(void); + + /*! \brief Erase areas of flash * \ingroup hardware_flash * From 2e2651f0874af143427b9d2bf6d95e36ddcf6ddd Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 22 Jul 2025 10:39:07 -0500 Subject: [PATCH 197/224] add default implementation of `_get_entropy()` that returns -1 to avoid linker warning (#2578) --- src/rp2_common/pico_clib_interface/newlib_interface.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/rp2_common/pico_clib_interface/newlib_interface.c b/src/rp2_common/pico_clib_interface/newlib_interface.c index 8925e5464..61adeb480 100644 --- a/src/rp2_common/pico_clib_interface/newlib_interface.c +++ b/src/rp2_common/pico_clib_interface/newlib_interface.c @@ -152,6 +152,11 @@ int __attribute__((weak)) _isatty(int fd) { return fd == STDIO_HANDLE_STDIN || fd == STDIO_HANDLE_STDOUT || fd == STDIO_HANDLE_STDERR; } +int __attribute__((weak)) _getentropy (__unused void *buffer, __unused size_t length) { + // note we don't hook this up as it isn't clear if/where it is used, and we don't particularly + // want to pull in pico_rand. the user can supply their own strong implementation if they need it! + return -1; +} // exit is not useful... no desire to pull in __call_exitprocs void exit(int status) { _exit(status); From 2afa2512016082cc71407b6375b7a99f2f4d45ca Mon Sep 17 00:00:00 2001 From: Fadhil Riyanto Date: Wed, 23 Jul 2025 20:46:21 +0700 Subject: [PATCH 198/224] fix typo "serialzed" -> "serialized" (#2583) Signed-off-by: fadhil riyanto --- src/rp2_common/pico_stdio/stdio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/pico_stdio/stdio.c b/src/rp2_common/pico_stdio/stdio.c index d2ce14556..30131da1a 100644 --- a/src/rp2_common/pico_stdio/stdio.c +++ b/src/rp2_common/pico_stdio/stdio.c @@ -315,8 +315,8 @@ int PRIMARY_STDIO_FUNC(puts)(const char *s) { int REAL_FUNC(vprintf)(const char *format, va_list va); int PRIMARY_STDIO_FUNC(vprintf)(const char *format, va_list va) { - bool serialzed = stdout_serialize_begin(); - if (!serialzed) { + bool serialized = stdout_serialize_begin(); + if (!serialized) { #if PICO_STDIO_IGNORE_NESTED_STDOUT return 0; #endif @@ -337,7 +337,7 @@ int PRIMARY_STDIO_FUNC(vprintf)(const char *format, va_list va) { #else ret = REAL_FUNC(vprintf)(format, va); #endif - if (serialzed) { + if (serialized) { stdout_serialize_end(); } return ret; From 9b876bbc243bb068c0295d5c0cdfa214d7939bfe Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Wed, 23 Jul 2025 14:51:36 +0100 Subject: [PATCH 199/224] Fix location of map file on Ninja (#2584) --- src/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f21db2d80..65b1d8c5f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -74,12 +74,11 @@ endfunction() # add map file generation for the given target function(pico_add_map_output TARGET) - pico_get_runtime_output_directory(${TARGET} output_path) get_target_property(target_type ${TARGET} TYPE) if ("EXECUTABLE" STREQUAL "${target_type}") - target_link_options(${TARGET} PRIVATE "LINKER:-Map=${output_path}$>,$,$>${CMAKE_EXECUTABLE_SUFFIX}.map") + target_link_options(${TARGET} PRIVATE "LINKER:-Map=$.map") else () - target_link_options(${TARGET} INTERFACE "LINKER:-Map=${output_path}$>,$,$>${CMAKE_EXECUTABLE_SUFFIX}.map") + target_link_options(${TARGET} INTERFACE "LINKER:-Map=$.map") endif () endfunction() From f194749d47a36f5cd28c702d5098eda26180bd96 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 23 Jul 2025 15:10:24 +0100 Subject: [PATCH 200/224] Update and expand docs/weblinks_page.md (#2575) * Update and expand docs/weblinks_page.md * Add link to RM2 datasheet too * Updated shortlinks --- docs/weblinks_page.md | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/docs/weblinks_page.md b/docs/weblinks_page.md index 4f96db752..047ff7c0e 100644 --- a/docs/weblinks_page.md +++ b/docs/weblinks_page.md @@ -1,17 +1,20 @@ ## Documentation and datasheets {#weblinks_page} -The full documentation for the RP2040 and Raspberry Pi Pico board can be found at the following links - - - [RP2040 Datasheet](https://rptl.io/rp2040-datasheet) - - [Raspberry Pi Pico Datasheet](https://rptl.io/pico-datasheet) - - [RP235x Datasheet](https://rptl.io/rp2040-datasheet) - - [Raspberry Pi Pico2 Datasheet](https://rptl.io/pico-datasheet) - - [Raspberry Pi Pico W Datasheet](https://rptl.io/picow-datasheet) - - [Hardware design with RP2040](https://rptl.io/rp2040-design) - - [Raspberry Pi Pico C/C++ SDK](https://rptl.io/pico-c-sdk) - - [Raspberry Pi Pico Python SDK](https://rptl.io/pico-micropython) - - [Getting started with Raspberry Pi Pico](https://rptl.io/pico-get-started) - - [Connecting to the Internet with Raspberry Pi Pico W](https://rptl.io/picow-connect) +The full documentation for the RP2040, RP2350 and Raspberry Pi Pico-series boards can be found at the following links + + - [RP2040 Datasheet](https://rpltd.co/rp2040-datasheet) + - [Raspberry Pi Pico Datasheet](https://rpltd.co/pico-datasheet) + - [Raspberry Pi Pico W Datasheet](https://rpltd.co/picow-datasheet) + - [Hardware design with RP2040](https://rpltd.co/rp2040-design) + - [RP2350 Datasheet](https://rpltd.co/rp2350-datasheet) + - [Raspberry Pi Pico 2 Datasheet](https://rpltd.co/pico2-datasheet) + - [Raspberry Pi Pico 2 W Datasheet](https://rpltd.co/pico2w-datasheet) + - [Hardware design with RP2350](https://rpltd.co/rp2350-hardware-design) + - [RM2 Datasheet](https://rpltd.co/rm2-datasheet) + - [Raspberry Pi Pico-series C/C++ SDK](https://rpltd.co/pico-c-sdk) + - [Raspberry Pi Pico-series Python SDK](https://rpltd.co/pico-micropython) + - [Getting started with Raspberry Pi Pico-series](https://rpltd.co/pico-get-started) + - [Connecting to the Internet with Raspberry Pi Pico W-series](https://rpltd.co/picow-connect) ### Weblinks @@ -31,4 +34,9 @@ All the source code for the Raspberry Pi Pico SDK, examples and other libraries - [Pico Examples](https://github.com/raspberrypi/pico-examples) - [Pico Extras - Libraries under development](https://github.com/raspberrypi/pico-extras) - [Pico Playground - Examples that use Pico Extras](https://github.com/raspberrypi/pico-playground) - - [Pico Bootrom source code](https://github.com/raspberrypi/pico-bootrom) + - [Pico MicroPython Examples](https://github.com/raspberrypi/pico-micropython-examples) + - [RP2040 Bootrom source code](https://github.com/raspberrypi/pico-bootrom-rp2040) + - [RP2350 Bootrom source code](https://github.com/raspberrypi/pico-bootrom-rp2350) + - [Picotool](https://github.com/raspberrypi/picotool) + - [Pico VS Code extension](https://github.com/raspberrypi/pico-vscode) + - [Pico TensorFlow Lite Port](https://github.com/raspberrypi/pico-tflmicro) From bf4906b1b5bd7901dfa1c469708e50952cba69f1 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Wed, 23 Jul 2025 15:11:18 +0100 Subject: [PATCH 201/224] Improve error code description for some cyw43 connection methods (#2586) * Improve error code description for some cyw43 connection methods Fixes #2564 * Apply suggestions from code review Put error description on separate lines for clarity. Co-authored-by: Andrew Scheller --------- Co-authored-by: Andrew Scheller --- .../pico_cyw43_arch/include/pico/cyw43_arch.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h b/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h index 5eb43d1b3..becc2fa98 100644 --- a/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h +++ b/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h @@ -399,7 +399,9 @@ void cyw43_arch_disable_ap_mode(void); * \param auth the authorization type to use when the password is enabled. Values are \ref CYW43_AUTH_WPA_TKIP_PSK, * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * - * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes + * \return 0 if the connection is successful. + * PICO_ERROR_BADAUTH is returned if the WiFi password is wrong. + * PICO_ERROR_CONNECT_FAILED is returned if the connection failed for some other reason. */ int cyw43_arch_wifi_connect_blocking(const char *ssid, const char *pw, uint32_t auth); @@ -413,7 +415,9 @@ int cyw43_arch_wifi_connect_blocking(const char *ssid, const char *pw, uint32_t * \param auth the authorization type to use when the password is enabled. Values are \ref CYW43_AUTH_WPA_TKIP_PSK, * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * - * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes + * \return 0 if the connection is successful. + * PICO_ERROR_BADAUTH is returned if the WiFi password is wrong. + * PICO_ERROR_CONNECT_FAILED is returned if the connection failed for some other reason. */ int cyw43_arch_wifi_connect_bssid_blocking(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth); @@ -427,7 +431,10 @@ int cyw43_arch_wifi_connect_bssid_blocking(const char *ssid, const uint8_t *bssi * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * \param timeout how long to wait in milliseconds for a connection to succeed before giving up * - * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes + * \return 0 if the connection is successful. + * PICO_ERROR_TIMEOUT is returned if the timeout is reached before a successful connection. + * PICO_ERROR_BADAUTH is returned if the WiFi password is wrong. + * PICO_ERROR_CONNECT_FAILED is returned if the connection failed for some other reason. */ int cyw43_arch_wifi_connect_timeout_ms(const char *ssid, const char *pw, uint32_t auth, uint32_t timeout); @@ -442,7 +449,10 @@ int cyw43_arch_wifi_connect_timeout_ms(const char *ssid, const char *pw, uint32_ * \ref CYW43_AUTH_WPA2_AES_PSK, or \ref CYW43_AUTH_WPA2_MIXED_PSK (see \ref CYW43_AUTH_) * \param timeout how long to wait in milliseconds for a connection to succeed before giving up * - * \return 0 if the initialization is successful, an error code otherwise see \ref pico_error_codes + * \return 0 if the connection is successful. + * PICO_ERROR_TIMEOUT is returned if the timeout is reached before a successful connection. + * PICO_ERROR_BADAUTH is returned if the WiFi password is wrong. + * PICO_ERROR_CONNECT_FAILED is returned if the connection failed for some other reason. */ int cyw43_arch_wifi_connect_bssid_timeout_ms(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth, uint32_t timeout); From 58d000f210f952e64b1b3449abc44dec11e70c91 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Wed, 23 Jul 2025 15:13:10 +0100 Subject: [PATCH 202/224] Improve rom_pick_ab_update_partition docs (#2577) * Improve rom_pick_ab_update_partition docs * Some review fixups Add more `\ref`s and tidy up wording * Move function docs next to rom_pick_ab_partition * Add \return to rom_pick_ab_partition docs * Rename rom_pick_ab_update_partition -> rom_pick_ab_partition_during_update and replace "call" --- src/rp2_common/pico_bootrom/bootrom.c | 2 +- .../pico_bootrom/include/pico/bootrom.h | 53 ++++++++++--------- .../pico_cyw43_driver/cyw43_driver.c | 2 +- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/rp2_common/pico_bootrom/bootrom.c b/src/rp2_common/pico_bootrom/bootrom.c index 516a9fb50..766574802 100644 --- a/src/rp2_common/pico_bootrom/bootrom.c +++ b/src/rp2_common/pico_bootrom/bootrom.c @@ -112,7 +112,7 @@ int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32 return PICO_ERROR_INSUFFICIENT_RESOURCES; } -int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num) { +int rom_pick_ab_partition_during_update(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num) { #if !PICO_RP2040 // Generated from adding the following code into the bootrom // scan_workarea_t* scan_workarea = (scan_workarea_t*)workarea; diff --git a/src/rp2_common/pico_bootrom/include/pico/bootrom.h b/src/rp2_common/pico_bootrom/include/pico/bootrom.h index db2f23d28..4494ae1cf 100644 --- a/src/rp2_common/pico_bootrom/include/pico/bootrom.h +++ b/src/rp2_common/pico_bootrom/include/pico/bootrom.h @@ -750,12 +750,13 @@ static inline int rom_load_partition_table(uint8_t *workarea_base, uint32_t work * NOTE: This method does not look at owner partitions, only the A partition passed and it's corresponding B partition. * * NOTE: You should not call this method directly when performing a Flash Update Boot before calling `explicit_buy`, as it may prevent - * any version downgrade from occuring - instead see \ref rom_pick_ab_update_partition() which wraps this function. + * any version downgrade from occuring - instead see \ref rom_pick_ab_partition_during_update() which wraps this function. * * \param workarea_base base address of work area * \param workarea_size size of work area * \param partition_a_num the A partition of the pair * \param flash_update_boot_window_base the flash update base, to pick that partition instead of the normally "better" partition + * \return >= 0 the chosen partition number out of the A/B pair */ static inline int rom_pick_ab_partition(uint8_t *workarea_base, uint32_t workarea_size, uint partition_a_num, uint32_t flash_update_boot_window_base) { rom_pick_ab_partition_fn func = (rom_pick_ab_partition_fn) rom_func_lookup_inline(ROM_FUNC_PICK_AB_PARTITION); @@ -766,6 +767,32 @@ static inline int rom_pick_ab_partition(uint8_t *workarea_base, uint32_t workare return rc; } +/*! \brief Pick A/B partition without disturbing any in progress Flash Update boot or TBYB boot + * \ingroup pico_bootrom + * + * This will perform the same function as \ref rom_pick_ab_partition(), using the `flash_update_boot_window_base` from the current boot, while performing + * extra checks to prevent disrupting a main image TBYB boot. It requires the same minimum workarea size as \ref rom_pick_ab_partition(). + * + * This should be used instead of \ref rom_pick_ab_partition() when performing a Flash Update Boot before calling \ref rom_explicit_buy(), and can still be + * used without issue when a Flash Update Boot is not in progress. + * + * This function is necessary because if an `explicit_buy` is pending then calling `pick_ab_partition` would clear the saved flash erase address for + * the version downgrade, so the required erase of the other partition would not occur when `explicit_buy` is called. This function saves and restores + * that address to prevent this issue, and returns `BOOTROM_ERROR_NOT_PERMITTED` if the partition chosen by `pick_ab_partition` also requires a flash + * erase version downgrade (as you can't erase two partitions with one `explicit_buy` call). + * + * This function also checks that the chosen partition contained a valid image (e.g. a signed image when using secure boot), and returns + * `BOOTROM_ERROR_NOT_FOUND` if it does not. + * + * \param workarea_base base address of work area + * \param workarea_size size of work area + * \param partition_a_num the A partition of the pair + * \return >= 0 the partition number picked by \ref rom_pick_ab_partition() + * BOOTROM_ERROR_NOT_PERMITTED if not possible to do an update correctly, e.g. if both main image and data image are TBYB + * BOOTROM_ERROR_NOT_FOUND if the chosen partition failed verification + */ +int rom_pick_ab_partition_during_update(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num); + /*! * \brief Get B partition * \ingroup pico_bootrom @@ -1094,30 +1121,6 @@ static inline int rom_get_last_boot_type(void) { */ int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32_t permissions); -/*! \brief Pick A/B partition without disturbing any in progress update or TBYB boot - * \ingroup pico_bootrom - * - * This will call `rom_pick_ab_partition` using the `flash_update_boot_window_base` from the current boot, while performing extra checks to prevent disrupting - * a main image TBYB boot. It requires the same minimum workarea size as `rom_pick_ab_partition`. - * \see rom_pick_ab_partition() - * - * For example, if an `explicit_buy` is pending then calling `pick_ab_partition` would normally clear the saved flash erase address for the version downgrade, - * so the required erase of the other partition would not occur when `explicit_buy` is called - this function saves and restores that address to prevent this - * issue, and returns `BOOTROM_ERROR_NOT_PERMITTED` if the partition chosen by `pick_ab_partition` also requires a flash erase version downgrade (as you can't - * erase 2 partitions with one `explicit_buy` call). - * - * It also checks that the chosen partition contained a valid image (e.g. a signed image when using secure boot), and returns `BOOTROM_ERROR_NOT_FOUND` - * if it does not. - * - * \param workarea_base base address of work area - * \param workarea_size size of work area - * \param partition_a_num the A partition of the pair - * \return >= 0 the partition number picked - * BOOTROM_ERROR_NOT_PERMITTED if not possible to do an update correctly, e.g. if both main image and data image are TBYB - * BOOTROM_ERROR_NOT_FOUND if the chosen partition failed verification - */ -int rom_pick_ab_update_partition(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num); - #endif #ifdef __cplusplus diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c index 6287428f3..c63e18907 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c @@ -152,7 +152,7 @@ bool cyw43_driver_init(async_context_t *context) { rom_set_bootrom_stack(&stack); #endif uint32_t* workarea = malloc(0x1000); - picked_p = rom_pick_ab_update_partition(workarea, 0x1000, picked_p); + picked_p = rom_pick_ab_partition_during_update(workarea, 0x1000, picked_p); free(workarea); #ifdef __riscv // Reset bootrom stack From c650739c4c60c63cef92bf3480bd07f6497e4acf Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 23 Jul 2025 15:18:07 +0100 Subject: [PATCH 203/224] Look for other possible "missing PICO_CONFIG" lines, and make message more obvious (#2477) --- tools/extract_configs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/extract_configs.py b/tools/extract_configs.py index a95870c6a..bb2713b0d 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -240,8 +240,9 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): chips_resolved_defines = defaultdict(dict) for applicable, all_defines in chips_all_defines.items(): for d in all_defines: - if d not in all_config_names and d.startswith("PICO_"): - logger.warning("Potential unmarked PICO define {}".format(d)) + for define_prefix in ('PICO', 'PARAM', 'CYW43'): + if d not in all_config_names and d.startswith(define_prefix+'_'): + logger.warning("#define {} is potentially missing a {}: entry".format(d, BASE_CONFIG_NAME)) resolved_defines = chips_resolved_defines[applicable] # resolve "nested defines" - this allows e.g. USB_DPRAM_MAX to resolve to USB_DPRAM_SIZE which is set to 4096 (which then matches the relevant PICO_CONFIG entry) for val in all_defines[d]: From d011e8abd4d38395705ede4e7765cf1e92311992 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Wed, 23 Jul 2025 13:35:26 -0500 Subject: [PATCH 204/224] add a task completion semaphore to guarantee async_context task is finished before async_context cleanup finishes (#2587) --- .../pico_async_context/async_context_freertos.c | 9 +++++++++ .../include/pico/async_context_freertos.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/rp2_common/pico_async_context/async_context_freertos.c b/src/rp2_common/pico_async_context/async_context_freertos.c index be7c08110..f6b1a5a1a 100644 --- a/src/rp2_common/pico_async_context/async_context_freertos.c +++ b/src/rp2_common/pico_async_context/async_context_freertos.c @@ -73,6 +73,7 @@ static void async_context_task(__unused void *vself) { async_context_freertos_release_lock(&self->core); __sev(); // it is possible regular code is waiting on a WFE on the other core } while (!self->task_should_exit); + xSemaphoreGive(self->task_complete_sem); vTaskDelete(NULL); } @@ -113,6 +114,7 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f assert(config->task_stack); self->lock_mutex = xSemaphoreCreateRecursiveMutexStatic(&self->lock_mutex_buf); self->work_needed_sem = xSemaphoreCreateBinaryStatic(&self->work_needed_sem_buf); + self->task_complete_sem = xSemaphoreCreateBinaryStatic(&self->task_complete_sem_buf); self->timer_handle = xTimerCreateStatic( "async_context_timer", // Just a text name, not used by the kernel. portMAX_DELAY, pdFALSE, // The timers will auto-reload themselves when they expire. @@ -129,6 +131,7 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f #else self->lock_mutex = xSemaphoreCreateRecursiveMutex(); self->work_needed_sem = xSemaphoreCreateBinary(); + self->task_complete_sem = xSemaphoreCreateBinary(); self->timer_handle = xTimerCreate( "async_context_timer", // Just a text name, not used by the kernel. portMAX_DELAY, pdFALSE, // The timers will auto-reload themselves when they expire. @@ -171,6 +174,9 @@ void async_context_freertos_deinit(async_context_t *self_base) { async_context_freertos_t *self = (async_context_freertos_t *)self_base; if (self->task_handle) { async_context_execute_sync(self_base, end_task_func, self_base); + if (self->task_complete_sem) { + xSemaphoreTake(self->task_complete_sem, portMAX_DELAY); + } } if (self->timer_handle) { xTimerDelete(self->timer_handle, 0); @@ -181,6 +187,9 @@ void async_context_freertos_deinit(async_context_t *self_base) { if (self->work_needed_sem) { vSemaphoreDelete(self->work_needed_sem); } + if (self->task_complete_sem) { + vSemaphoreDelete(self->task_complete_sem); + } memset(self, 0, sizeof(*self)); } diff --git a/src/rp2_common/pico_async_context/include/pico/async_context_freertos.h b/src/rp2_common/pico_async_context/include/pico/async_context_freertos.h index 273d653f2..0120410f7 100644 --- a/src/rp2_common/pico_async_context/include/pico/async_context_freertos.h +++ b/src/rp2_common/pico_async_context/include/pico/async_context_freertos.h @@ -75,11 +75,13 @@ struct async_context_freertos { async_context_t core; SemaphoreHandle_t lock_mutex; SemaphoreHandle_t work_needed_sem; + SemaphoreHandle_t task_complete_sem; TimerHandle_t timer_handle; TaskHandle_t task_handle; #if configSUPPORT_STATIC_ALLOCATION StaticSemaphore_t lock_mutex_buf; StaticSemaphore_t work_needed_sem_buf; + StaticSemaphore_t task_complete_sem_buf; StaticTimer_t timer_buf; StaticTask_t task_buf; #endif From b51a993bc18c50c86121166664ba82be1deede1d Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Thu, 24 Jul 2025 22:25:30 +0100 Subject: [PATCH 205/224] Improve pico_use_wifi_firmware_partition docs (#2580) * Improve pico_use_wifi_firmware_partition docs * Replace assert with hard_assert Fixes compilation warning about unused ret variable in release builds * firmware -> wifi_firmware * Maybe improve wording? * Clarify TBYB, and add `-ux` to firmware load --- .../pico_cyw43_driver/CMakeLists.txt | 57 +++++++++++-------- .../pico_cyw43_driver/cyw43_driver.c | 6 +- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt index 6334fc843..ddc5715e6 100644 --- a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt +++ b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt @@ -179,6 +179,17 @@ if (EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE}) # NO_EMBEDDED_PT argument (for example, if you need to chain into the binary, it # can't contain a partition table). # + # This will create additional UF2 files for the CYW43 firmware - both a regular version, + # and a TBYB version to use if you're updating it using the TBYB feature (see section + # 5.1.17 of the RP2350 datasheet). You will need to flash your chosen version to each + # new device once, after loading the partition table. For example using picotool: + # + # `picotool load TARGET.uf2`; + # `picotool reboot -u`; + # `picotool load -ux TARGET_wifi_firmware.uf2`; + # + # Then on subsequent updates, you can just flash the TARGET.uf2 file to the device. + # # \param\ NO_EMBEDDED_PT If set, will not embed a partition table in the binary function(pico_use_wifi_firmware_partition TARGET) set(options NO_EMBEDDED_PT) @@ -204,50 +215,50 @@ if (EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE}) ) # Create UF2s for regular and TBYB firmwares - add_executable(${TARGET}_firmware + add_executable(${TARGET}_wifi_firmware ${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.S) - add_executable(${TARGET}_firmware_tbyb + add_executable(${TARGET}_wifi_firmware_tbyb ${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.S) - add_dependencies(${TARGET}_firmware ${TARGET}_firmware_blob) - add_dependencies(${TARGET}_firmware_tbyb ${TARGET}_firmware_blob) + add_dependencies(${TARGET}_wifi_firmware ${TARGET}_firmware_blob) + add_dependencies(${TARGET}_wifi_firmware_tbyb ${TARGET}_firmware_blob) - target_include_directories(${TARGET}_firmware PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) - target_include_directories(${TARGET}_firmware_tbyb PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_include_directories(${TARGET}_wifi_firmware PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_include_directories(${TARGET}_wifi_firmware_tbyb PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) - target_compile_definitions(${TARGET}_firmware PRIVATE + target_compile_definitions(${TARGET}_wifi_firmware PRIVATE NO_PICO_PLATFORM=1 ) - target_compile_definitions(${TARGET}_firmware_tbyb PRIVATE + target_compile_definitions(${TARGET}_wifi_firmware_tbyb PRIVATE NO_PICO_PLATFORM=1 PICO_CRT0_IMAGE_TYPE_TBYB=1 ) - target_link_options(${TARGET}_firmware PRIVATE -nostartfiles -nodefaultlibs LINKER:--script=${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.ld) - target_link_options(${TARGET}_firmware_tbyb PRIVATE -nostartfiles -nodefaultlibs LINKER:--script=${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.ld) + target_link_options(${TARGET}_wifi_firmware PRIVATE -nostartfiles -nodefaultlibs LINKER:--script=${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.ld) + target_link_options(${TARGET}_wifi_firmware_tbyb PRIVATE -nostartfiles -nodefaultlibs LINKER:--script=${PICO_CYW43_DRIVER_CURRENT_PATH}/wifi_firmware.ld) - target_link_libraries(${TARGET}_firmware boot_picobin_headers) - target_link_libraries(${TARGET}_firmware_tbyb boot_picobin_headers) + target_link_libraries(${TARGET}_wifi_firmware boot_picobin_headers) + target_link_libraries(${TARGET}_wifi_firmware_tbyb boot_picobin_headers) get_target_property(hasSigfile ${TARGET} PICOTOOL_SIGFILE) if (hasSigfile) - pico_sign_binary(${TARGET}_firmware ${sigfile}) - pico_sign_binary(${TARGET}_firmware_tbyb ${sigfile}) + pico_sign_binary(${TARGET}_wifi_firmware ${sigfile}) + pico_sign_binary(${TARGET}_wifi_firmware_tbyb ${sigfile}) endif() - pico_hash_binary(${TARGET}_firmware) - pico_hash_binary(${TARGET}_firmware_tbyb) + pico_hash_binary(${TARGET}_wifi_firmware) + pico_hash_binary(${TARGET}_wifi_firmware_tbyb) - pico_set_uf2_family(${TARGET}_firmware cyw43-firmware) - pico_set_uf2_family(${TARGET}_firmware_tbyb cyw43-firmware) + pico_set_uf2_family(${TARGET}_wifi_firmware cyw43-firmware) + pico_set_uf2_family(${TARGET}_wifi_firmware_tbyb cyw43-firmware) - pico_package_uf2_output(${TARGET}_firmware 0x10000000) - pico_package_uf2_output(${TARGET}_firmware_tbyb 0x10000000) + pico_package_uf2_output(${TARGET}_wifi_firmware 0x10000000) + pico_package_uf2_output(${TARGET}_wifi_firmware_tbyb 0x10000000) - pico_add_extra_outputs(${TARGET}_firmware) - pico_add_extra_outputs(${TARGET}_firmware_tbyb) + pico_add_extra_outputs(${TARGET}_wifi_firmware) + pico_add_extra_outputs(${TARGET}_wifi_firmware_tbyb) add_dependencies(${TARGET} - ${TARGET}_firmware ${TARGET}_firmware_tbyb) + ${TARGET}_wifi_firmware ${TARGET}_wifi_firmware_tbyb) endfunction() endif() diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c index c63e18907..384062fc1 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c @@ -119,7 +119,7 @@ bool cyw43_driver_init(async_context_t *context) { uint32_t buffer[(16 * 4) + 1] = {}; // maximum of 16 partitions, each with maximum of 4 words returned, plus 1 int ret = rom_get_partition_table_info(buffer, count_of(buffer), PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID); - assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID)); + hard_assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_PARTITION_ID)); if (ret > 0) { int i = 1; @@ -171,8 +171,8 @@ bool cyw43_driver_init(async_context_t *context) { CYW43_DEBUG("Chosen CYW43 firmware in partition %d\n", picked_p); int ret = rom_get_partition_table_info(buffer, count_of(buffer), PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION | (picked_p << 24)); - assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION)); - assert(ret == 3); + hard_assert(buffer[0] == (PT_INFO_PARTITION_LOCATION_AND_FLAGS | PT_INFO_SINGLE_PARTITION)); + hard_assert(ret == 3); uint32_t location_and_permissions = buffer[1]; uint32_t saddr = ((location_and_permissions >> PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_LSB) & 0x1fffu) * FLASH_SECTOR_SIZE; From dad01128f4f243491af28fe5783b06b3b221fa31 Mon Sep 17 00:00:00 2001 From: Alexey Vazhnov Date: Thu, 24 Jul 2025 23:33:59 +0200 Subject: [PATCH 206/224] =?UTF-8?q?Fix=20typo:=20IMAGEDEF=20=E2=86=92=20IM?= =?UTF-8?q?AGE=5FDEF,=20as=20it=20is=20defined=20in=20the=20datasheet=20(#?= =?UTF-8?q?2589)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld | 2 +- src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld index 145faf817..44c69f3b9 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld @@ -35,7 +35,7 @@ SECTIONS { /* On Arm, the bootrom expects a VT at the start of the image by default; on RISC-V, the default is to enter the image at its - lowest address, so an IMAGEDEF item is required to specify the + lowest address, so an IMAGE_DEF item is required to specify the nondefault entry point. */ .flash_begin : { diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld b/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld index 98088cdfc..5bedf6d21 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld @@ -35,7 +35,7 @@ SECTIONS /* Note unlike RP2040, we start the image with a vector table even for NO_FLASH builds. On Arm, the bootrom expects a VT at the start of the image by default; on RISC-V, the default is to enter the image at its - lowest address, so an IMAGEDEF item is required to specify the + lowest address, so an IMAGE_DEF item is required to specify the nondefault entry point. */ .text : { From 59d2b0228b2dbc5c0da99c8556d641108ff9745d Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 24 Jul 2025 16:34:21 -0500 Subject: [PATCH 207/224] add some doxygen to hard_assert (#2582) * add some doxygen to hard_assert * typo Co-authored-by: Peter Harper <77111776+peterharperuk@users.noreply.github.com> --------- Co-authored-by: Peter Harper <77111776+peterharperuk@users.noreply.github.com> --- src/common/pico_base_headers/include/pico/assert.h | 10 ++++++++++ src/rp2_common/pico_runtime/runtime.c | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/common/pico_base_headers/include/pico/assert.h b/src/common/pico_base_headers/include/pico/assert.h index 36e25efae..cc33779a4 100644 --- a/src/common/pico_base_headers/include/pico/assert.h +++ b/src/common/pico_base_headers/include/pico/assert.h @@ -38,6 +38,16 @@ extern "C" { #ifdef NDEBUG extern void hard_assertion_failure(void); + +/*! \brief Perform a runtime assertion always (i.e. not just when NDEBUG is undefined) +* \ingroup pico_base +* +* This function is intended to provide useful information in debug builds like a normal assertion, but also +* prevent execution proceeding in other builds +* +* In debug builds this is equivalent to \ref assert, however in release builds it calls \ref hard_assertion_failure +* which, by default, just calls \ref panic with the string "Hard assert" +*/ static inline void hard_assert(bool condition, ...) { if (!condition) hard_assertion_failure(); diff --git a/src/rp2_common/pico_runtime/runtime.c b/src/rp2_common/pico_runtime/runtime.c index 42452e5bb..d8bae8900 100644 --- a/src/rp2_common/pico_runtime/runtime.c +++ b/src/rp2_common/pico_runtime/runtime.c @@ -8,6 +8,15 @@ #include "pico/runtime_init.h" +/*! \brief Handle a hard_assert condition failure +* \ingroup pico_runtime +* +* This weak function provides the default implementation (call \ref panic with "Hard assert") for if a \ref hard_assert +* condition fail in non debug builds. You can provide your own strong implementation to replace the default behavior +* +* \sa hard_assert +*/ + void __weak hard_assertion_failure(void) { panic("Hard assert"); } From 50b4a22ccdebd285d100910d968312313db6b06a Mon Sep 17 00:00:00 2001 From: andygpz11 <111971637+andygpz11@users.noreply.github.com> Date: Fri, 25 Jul 2025 14:38:06 +0100 Subject: [PATCH 208/224] Fix minor typos in error header (#2594) (#2594) --- src/common/pico_base_headers/include/pico/error.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/pico_base_headers/include/pico/error.h b/src/common/pico_base_headers/include/pico/error.h index 9212eda81..26d0f837e 100644 --- a/src/common/pico_base_headers/include/pico/error.h +++ b/src/common/pico_base_headers/include/pico/error.h @@ -42,9 +42,9 @@ enum pico_error_codes { PICO_ERROR_UNSUPPORTED_MODIFICATION = -18, ///< Write is impossible based on previous writes; e.g. attempted to clear an OTP bit PICO_ERROR_LOCK_REQUIRED = -19, ///< A required lock is not owned PICO_ERROR_VERSION_MISMATCH = -20, ///< A version mismatch occurred (e.g. trying to run PIO version 1 code on RP2040) - PICO_ERROR_RESOURCE_IN_USE = -21 ///< The call could not proceed because requires resourcesw were unavailable + PICO_ERROR_RESOURCE_IN_USE = -21 ///< The call could not proceed because the required resources were unavailable }; #endif // !__ASSEMBLER__ -#endif \ No newline at end of file +#endif From de5fb4f71fa587293a1cea460efe55181976089b Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Fri, 25 Jul 2025 15:13:40 +0100 Subject: [PATCH 209/224] Doxygen "group" fixes (#2591) - Add missing libraries to docs/index.h - Remove duplicate libraries from docs/index.h - Add new script to match up doxygen groups with the PICO_CONFIG groups --- docs/index.h | 8 +-- tools/check_all_groups.py | 136 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 5 deletions(-) create mode 100755 tools/check_all_groups.py diff --git a/docs/index.h b/docs/index.h index be52f6a0d..5506b3a34 100644 --- a/docs/index.h +++ b/docs/index.h @@ -15,7 +15,7 @@ * @{ * \cond hardware_adc \defgroup hardware_adc hardware_adc \endcond * \cond hardware_base \defgroup hardware_base hardware_base \endcond - * \cond hardware_bootlock \defgroup hardware_bootlock hardware_bootlock \endcond + * \cond hardware_boot_lock \defgroup hardware_boot_lock hardware_boot_lock \endcond * \cond hardware_claim \defgroup hardware_claim hardware_claim \endcond * \cond hardware_clocks \defgroup hardware_clocks hardware_clocks \endcond * \cond hardware_divider \defgroup hardware_divider hardware_divider \endcond @@ -32,7 +32,6 @@ * \cond hardware_pll \defgroup hardware_pll hardware_pll \endcond * \cond hardware_powman \defgroup hardware_powman hardware_powman \endcond * \cond hardware_pwm \defgroup hardware_pwm hardware_pwm \endcond - * \cond hardware_pwm \defgroup hardware_pwm hardware_pwm \endcond * \cond hardware_resets \defgroup hardware_resets hardware_resets \endcond * \cond hardware_riscv \defgroup hardware_riscv hardware_riscv \endcond * \cond hardware_riscv_platform_timer \defgroup hardware_riscv_platform_timer hardware_riscv_platform_timer \endcond @@ -44,13 +43,11 @@ * \cond hardware_ticks \defgroup hardware_ticks hardware_ticks \endcond * \cond hardware_timer \defgroup hardware_timer hardware_timer \endcond * \cond hardware_uart \defgroup hardware_uart hardware_uart \endcond + * \cond hardware_usb \defgroup hardware_usb hardware_usb \endcond * \cond hardware_vreg \defgroup hardware_vreg hardware_vreg \endcond * \cond hardware_watchdog \defgroup hardware_watchdog hardware_watchdog \endcond * \cond hardware_xip_cache \defgroup hardware_xip_cache hardware_xip_cache \endcond * \cond hardware_xosc \defgroup hardware_xosc hardware_xosc \endcond - * \cond hardware_powman \defgroup hardware_powman hardware_powman \endcond - * \cond hardware_hazard3 \defgroup hardware_hazard3 hardware_hazard3 \endcond - * \cond hardware_riscv \defgroup hardware_riscv hardware_riscv \endcond * @} * @@ -61,6 +58,7 @@ * \cond pico_aon_timer \defgroup pico_aon_timer pico_aon_timer \endcond * \cond pico_async_context \defgroup pico_async_context pico_async_context \endcond * \cond pico_bootsel_via_double_reset \defgroup pico_bootsel_via_double_reset pico_bootsel_via_double_reset \endcond + * \cond pico_fix \defgroup pico_fix pico_fix \endcond * \cond pico_flash \defgroup pico_flash pico_flash \endcond * \cond pico_i2c_slave \defgroup pico_i2c_slave pico_i2c_slave \endcond * \cond pico_multicore \defgroup pico_multicore pico_multicore \endcond diff --git a/tools/check_all_groups.py b/tools/check_all_groups.py new file mode 100755 index 000000000..3a0d0bf6a --- /dev/null +++ b/tools/check_all_groups.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2025 Raspberry Pi Ltd +# +# SPDX-License-Identifier: BSD-3-Clause +# +# +# Script to check that the "groups" in various contexts all match up. (like an enhanced version of check_doxygen_groups.py) +# Note that it only reports the *first* instance of a missing group, not all occurrences. +# +# Usage: +# +# tools/check_all_groups.py +# (you'll probably want to pipe the output through ` | grep -v cmsis` ) + +import re +import sys +import os + +scandir = sys.argv[1] + +DEFGROUP_NAME = r'\defgroup' +DEFGROUP_RE = re.compile(r'{}\s+(\w+)'.format(re.escape(DEFGROUP_NAME))) +INGROUP_NAME = r'\ingroup' +INGROUP_RE = re.compile(r'{}\s+(\w+)'.format(re.escape(INGROUP_NAME))) +DOCS_INDEX_HEADER = 'docs/index.h' + +BASE_CONFIG_NAME = 'PICO_CONFIG' +CONFIG_RE = re.compile(r'//\s+{}:\s+(\w+),\s+([^,]+)(?:,\s+(.*))?$'.format(BASE_CONFIG_NAME)) +BASE_CMAKE_CONFIG_NAME = 'PICO_CMAKE_CONFIG' +CMAKE_CONFIG_RE = re.compile(r'#\s+{}:\s+([\w-]+),\s+([^,]+)(?:,\s+(.*))?$'.format(BASE_CMAKE_CONFIG_NAME)) +BASE_BUILD_DEFINE_NAME = 'PICO_BUILD_DEFINE' +BUILD_DEFINE_RE = re.compile(r'#\s+{}:\s+(\w+),\s+([^,]+)(?:,\s+(.*))?$'.format(BASE_BUILD_DEFINE_NAME)) +BASE_GROUP_NAME = 'group=' +GROUP_RE = re.compile(r'\b{}(\w+)\b'.format(BASE_GROUP_NAME)) + +def_groups = {} +in_groups = {} +doc_groups = {} +config_groups = {} +cmake_config_groups = {} +build_define_groups = {} +any_errors = False + +def get_group_from_config_attrs(attr_str): + m = GROUP_RE.search(attr_str) + if m: + return m.group(1) + +# Scan all .c and .h and .S and .cmake and CMakeLists.txt files in the specific path, recursively. + +for dirpath, dirnames, filenames in os.walk(scandir): + for filename in filenames: + file_ext = os.path.splitext(filename)[1] + if filename == 'CMakeLists.txt' or file_ext in ('.c', '.h', '.S', '.cmake'): + file_path = os.path.join(dirpath, filename) + with open(file_path) as fh: + for line in fh.readlines(): + m = DEFGROUP_RE.search(line) + if m: + group = m.group(1) + if file_path.endswith(DOCS_INDEX_HEADER): + if group in doc_groups: + any_errors = True + print("{} uses {} {} but so does {}".format(doc_groups[group], DEFGROUP_NAME, group, file_path)) + else: + doc_groups[group] = file_path + else: + if group in def_groups: + any_errors = True + print("{} uses {} {} but so does {}".format(def_groups[group], DEFGROUP_NAME, group, file_path)) + else: + def_groups[group] = file_path + else: + m = INGROUP_RE.search(line) + if m: + group = m.group(1) + if group not in in_groups: + in_groups[group] = file_path + else: + m = CONFIG_RE.search(line) + if m: + group = get_group_from_config_attrs(m.group(3)) + if group not in config_groups: + config_groups[group] = file_path + else: + m = CMAKE_CONFIG_RE.search(line) + if m: + group = get_group_from_config_attrs(m.group(3)) + if group not in cmake_config_groups: + cmake_config_groups[group] = file_path + else: + m = BUILD_DEFINE_RE.search(line) + if m: + group = get_group_from_config_attrs(m.group(3)) + if group not in build_define_groups: + build_define_groups[group] = file_path + +seen_groups = set() +for group, file_path in in_groups.items(): + seen_groups.add(group) + if group not in def_groups and group not in doc_groups: + any_errors = True + print("{} uses {} {} which was never defined".format(file_path, INGROUP_NAME, group)) +for group, file_path in config_groups.items(): + seen_groups.add(group) + if group not in def_groups and group not in doc_groups: + any_errors = True + print("{} uses {} {}{} which was never defined".format(file_path, BASE_CONFIG_NAME, BASE_GROUP_NAME, group)) +for group, file_path in cmake_config_groups.items(): + seen_groups.add(group) + if group == 'build': # dummy group + continue + if group not in def_groups and group not in doc_groups: + any_errors = True + print("{} uses {} {}{} which was never defined".format(file_path, BASE_CMAKE_CONFIG_NAME, BASE_GROUP_NAME, group)) +for group, file_path in build_define_groups.items(): + seen_groups.add(group) + if group == 'build': # dummy group + continue + if group not in def_groups and group not in doc_groups: + any_errors = True + print("{} uses {} {}{} which was never defined".format(file_path, BASE_BUILD_DEFINE_NAME, BASE_GROUP_NAME, group)) + +for group in doc_groups.keys(): + seen_groups.add(group) + if group not in seen_groups and group not in def_groups: + any_errors = True + print("{} uses {} {} which doesn't appear anywhere else".format(DOCS_INDEX_HEADER, DEFGROUP_NAME, group)) + +unused_groups = set(def_groups.keys()) - seen_groups +if unused_groups: + any_errors = True + print("The following groups were defined with {} but never referenced:\n{}".format(DEFGROUP_NAME, sorted(unused_groups))) + +sys.exit(any_errors) From 4f5ebb8d260654c2e83955cba6be4438ae9675fb Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Fri, 25 Jul 2025 15:14:31 +0100 Subject: [PATCH 210/224] Refactor extraction-scripts to reduce code-duplication (#2592) extract_configs.py now supports reading min, max or default values from a #define value (which reduces false-positives) --- tools/extract_build_defines.py | 110 +++++++++++---------- tools/extract_cmake_configs.py | 112 +++++++++++---------- tools/extract_configs.py | 175 ++++++++++++++++++++------------- 3 files changed, 219 insertions(+), 178 deletions(-) diff --git a/tools/extract_build_defines.py b/tools/extract_build_defines.py index 8df16ee88..9f0de4eeb 100755 --- a/tools/extract_build_defines.py +++ b/tools/extract_build_defines.py @@ -46,7 +46,17 @@ def __init__(self, message, errors): BUILD_DEFINE_RE = re.compile(r'#\s+{}:\s+(\w+),\s+([^,]+)(?:,\s+(.*))?$'.format(BASE_BUILD_DEFINE_NAME)) -ALLOWED_CONFIG_PROPERTIES = set(['type', 'default', 'min', 'max', 'group']) +PROPERTY_TYPE = 'type' +PROPERTY_DEFAULT = 'default' +PROPERTY_MIN = 'min' +PROPERTY_MAX = 'max' +PROPERTY_GROUP = 'group' +ALLOWED_CONFIG_PROPERTIES = set([PROPERTY_TYPE, PROPERTY_DEFAULT, PROPERTY_MIN, PROPERTY_MAX, PROPERTY_GROUP]) + +PROPERTY_TYPE_INT = 'int' +PROPERTY_TYPE_BOOL = 'bool' +PROPERTY_TYPE_STRING = 'string' +PROPERTY_TYPE_LIST = 'list' CHIP_NAMES = ["rp2040", "rp2350"] @@ -57,7 +67,7 @@ def __init__(self, message, errors): def ValidateAttrs(config_name, config_attrs, file_path, linenum): - _type = config_attrs.get('type') + type_str = config_attrs.get(PROPERTY_TYPE) errors = [] # Validate attrs @@ -65,64 +75,56 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): if key not in ALLOWED_CONFIG_PROPERTIES: errors.append(Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key))) - if _type == 'int': - _min = _max = _default = None - if config_attrs.get('min', None) is not None: - value = config_attrs['min'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) - if m: - _min = int(m.group(1)) * 10**int(m.group(2)) - else: - _min = int(value, 0) - if config_attrs.get('max', None) is not None: - value = config_attrs['max'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) - if m: - _max = int(m.group(1)) * 10**int(m.group(2)) - else: - _max = int(value, 0) - if config_attrs.get('default', None) is not None: - if '/' not in config_attrs['default']: + str_values = dict() + parsed_values = dict() + if type_str == PROPERTY_TYPE_INT: + for attr_name in (PROPERTY_MIN, PROPERTY_MAX, PROPERTY_DEFAULT): + str_values[attr_name] = config_attrs.get(attr_name, None) + if str_values[attr_name] is not None: try: - value = config_attrs['default'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) + m = re.match(r'^(\d+)e(\d+)$', str_values[attr_name].lower()) if m: - _default = int(m.group(1)) * 10**int(m.group(2)) + parsed_values[attr_name] = int(m.group(1)) * 10**int(m.group(2)) else: - _default = int(value, 0) + parsed_values[attr_name] = int(str_values[attr_name], 0) except ValueError: - pass - if _min is not None and _max is not None: - if _min > _max: - errors.append(Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max']))) - if _min is not None and _default is not None: - if _min > _default: - errors.append(Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default']))) - if _default is not None and _max is not None: - if _default > _max: - errors.append(Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max']))) - elif _type == 'bool': - assert 'min' not in config_attrs - assert 'max' not in config_attrs - _default = config_attrs.get('default', None) - if _default is not None: - if '/' not in _default: - if (_default not in ('0', '1')) and (_default not in all_config_names): - logger.info('{} at {}:{} has non-integer default value "{}"'.format(config_name, file_path, linenum, config_attrs['default'])) - - elif _type == 'string': - assert 'min' not in config_attrs - assert 'max' not in config_attrs - _default = config_attrs.get('default', None) - elif _type == 'list': - assert 'min' not in config_attrs - assert 'max' not in config_attrs - _default = config_attrs.get('default', None) + logger.info('{} at {}:{} has non-integer {} value "{}"'.format(config_name, file_path, linenum, attr_name, str_values[attr_name])) + for (small_attr, large_attr) in ( + (PROPERTY_MIN, PROPERTY_MAX), + (PROPERTY_MIN, PROPERTY_DEFAULT), + (PROPERTY_DEFAULT, PROPERTY_MAX), + ): + if small_attr in parsed_values and large_attr in parsed_values and parsed_values[small_attr] > parsed_values[large_attr]: + errors.append(Exception('{} at {}:{} has {} {} > {} {}'.format(config_name, file_path, linenum, small_attr, str_values[small_attr], large_attr, str_values[large_attr]))) + + elif type_str == PROPERTY_TYPE_BOOL: + assert PROPERTY_MIN not in config_attrs + assert PROPERTY_MAX not in config_attrs + + attr_name = PROPERTY_DEFAULT + str_values[attr_name] = config_attrs.get(attr_name, None) + if str_values[attr_name] is not None: + if (str_values[attr_name] not in ('0', '1')) and (str_values[attr_name] not in all_config_names): + logger.info('{} at {}:{} has non-integer {} value "{}"'.format(config_name, file_path, linenum, attr_name, str_values[attr_name])) + + elif type_str == PROPERTY_TYPE_STRING: + assert PROPERTY_MIN not in config_attrs + assert PROPERTY_MAX not in config_attrs + + attr_name = PROPERTY_DEFAULT + str_values[attr_name] = config_attrs.get(attr_name, None) + + elif type_str == PROPERTY_TYPE_LIST: + assert PROPERTY_MIN not in config_attrs + assert PROPERTY_MAX not in config_attrs + + attr_name = PROPERTY_DEFAULT + str_values[attr_name] = config_attrs.get(attr_name, None) + else: - errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_BUILD_DEFINE_NAME, _type, file_path, linenum))) - - return errors + errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_BUILD_DEFINE_NAME, type_str, file_path, linenum))) + return errors errors = [] diff --git a/tools/extract_cmake_configs.py b/tools/extract_cmake_configs.py index b86df28dc..f09a191f4 100755 --- a/tools/extract_cmake_configs.py +++ b/tools/extract_cmake_configs.py @@ -7,7 +7,7 @@ # # Script to scan the Raspberry Pi Pico SDK tree searching for CMake configuration items # Outputs a tab separated file of the configuration item: -# name location platform chip description type advanced default docref group +# name location platform chip description type advanced default docref group max # # Usage: # @@ -46,7 +46,19 @@ def __init__(self, message, errors): CMAKE_CONFIG_RE = re.compile(r'#\s+{}:\s+(\w+),\s+([^,]+)(?:,\s+(.*))?$'.format(BASE_CMAKE_CONFIG_NAME)) -ALLOWED_CONFIG_PROPERTIES = set(['type', 'default', 'min', 'max', 'group', 'advanced', 'docref']) +PROPERTY_TYPE = 'type' +PROPERTY_DEFAULT = 'default' +PROPERTY_MIN = 'min' +PROPERTY_MAX = 'max' +PROPERTY_GROUP = 'group' +PROPERTY_ADVANCED = 'advanced' +PROPERTY_DOCREF = 'docref' +ALLOWED_CONFIG_PROPERTIES = set([PROPERTY_TYPE, PROPERTY_DEFAULT, PROPERTY_MIN, PROPERTY_MAX, PROPERTY_GROUP, PROPERTY_ADVANCED, PROPERTY_DOCREF]) + +PROPERTY_TYPE_INT = 'int' +PROPERTY_TYPE_BOOL = 'bool' +PROPERTY_TYPE_STRING = 'string' +PROPERTY_TYPE_LIST = 'list' CHIP_NAMES = ["rp2040", "rp2350"] @@ -57,7 +69,7 @@ def __init__(self, message, errors): def ValidateAttrs(config_name, config_attrs, file_path, linenum): - _type = config_attrs.get('type') + type_str = config_attrs.get(PROPERTY_TYPE) errors = [] # Validate attrs @@ -65,61 +77,55 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): if key not in ALLOWED_CONFIG_PROPERTIES: errors.append(Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key))) - if _type == 'int': - _min = _max = _default = None - if config_attrs.get('min', None) is not None: - value = config_attrs['min'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) - if m: - _min = int(m.group(1)) * 10**int(m.group(2)) - else: - _min = int(value, 0) - if config_attrs.get('max', None) is not None: - value = config_attrs['max'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) - if m: - _max = int(m.group(1)) * 10**int(m.group(2)) - else: - _max = int(value, 0) - if config_attrs.get('default', None) is not None: - if '/' not in config_attrs['default']: + str_values = dict() + parsed_values = dict() + if type_str == PROPERTY_TYPE_INT: + for attr_name in (PROPERTY_MIN, PROPERTY_MAX, PROPERTY_DEFAULT): + str_values[attr_name] = config_attrs.get(attr_name, None) + if str_values[attr_name] is not None: try: - value = config_attrs['default'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) + m = re.match(r'^(\d+)e(\d+)$', str_values[attr_name].lower()) if m: - _default = int(m.group(1)) * 10**int(m.group(2)) + parsed_values[attr_name] = int(m.group(1)) * 10**int(m.group(2)) else: - _default = int(value, 0) + parsed_values[attr_name] = int(str_values[attr_name], 0) except ValueError: - pass - if _min is not None and _max is not None: - if _min > _max: - errors.append(Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max']))) - if _min is not None and _default is not None: - if _min > _default: - errors.append(Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default']))) - if _default is not None and _max is not None: - if _default > _max: - errors.append(Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max']))) - elif _type == 'bool': - assert 'min' not in config_attrs - assert 'max' not in config_attrs - _default = config_attrs.get('default', None) - if _default is not None: - if '/' not in _default: - if (_default not in ('0', '1')) and (_default not in all_config_names): - logger.info('{} at {}:{} has non-integer default value "{}"'.format(config_name, file_path, linenum, config_attrs['default'])) - - elif _type == 'string': - assert 'min' not in config_attrs - assert 'max' not in config_attrs - _default = config_attrs.get('default', None) - elif _type == 'list': - assert 'min' not in config_attrs - assert 'max' not in config_attrs - _default = config_attrs.get('default', None) + # pass + logger.info('{} at {}:{} has non-integer {} value "{}"'.format(config_name, file_path, linenum, attr_name, str_values[attr_name])) + for (small_attr, large_attr) in ( + (PROPERTY_MIN, PROPERTY_MAX), + (PROPERTY_MIN, PROPERTY_DEFAULT), + (PROPERTY_DEFAULT, PROPERTY_MAX), + ): + if small_attr in parsed_values and large_attr in parsed_values and parsed_values[small_attr] > parsed_values[large_attr]: + errors.append(Exception('{} at {}:{} has {} {} > {} {}'.format(config_name, file_path, linenum, small_attr, str_values[small_attr], large_attr, str_values[large_attr]))) + + elif type_str == PROPERTY_TYPE_BOOL: + assert PROPERTY_MIN not in config_attrs + assert PROPERTY_MAX not in config_attrs + + attr_name = PROPERTY_DEFAULT + str_values[attr_name] = config_attrs.get(attr_name, None) + if str_values[attr_name] is not None: + if (str_values[attr_name] not in ('0', '1')) and (str_values[attr_name] not in all_config_names): + logger.info('{} at {}:{} has non-integer {} value "{}"'.format(config_name, file_path, linenum, attr_name, str_values[attr_name])) + + elif type_str == PROPERTY_TYPE_STRING: + assert PROPERTY_MIN not in config_attrs + assert PROPERTY_MAX not in config_attrs + + attr_name = PROPERTY_DEFAULT + str_values[attr_name] = config_attrs.get(attr_name, None) + + elif type_str == PROPERTY_TYPE_LIST: + assert PROPERTY_MIN not in config_attrs + assert PROPERTY_MAX not in config_attrs + + attr_name = PROPERTY_DEFAULT + str_values[attr_name] = config_attrs.get(attr_name, None) + else: - errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_CMAKE_CONFIG_NAME, _type, file_path, linenum))) + errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_CMAKE_CONFIG_NAME, type_str, file_path, linenum))) return errors diff --git a/tools/extract_configs.py b/tools/extract_configs.py index bb2713b0d..f1b4a92d5 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -47,7 +47,19 @@ def __init__(self, message, errors): CONFIG_RE = re.compile(r'//\s+{}:\s+(\w+),\s+([^,]+)(?:,\s+(.*))?$'.format(BASE_CONFIG_NAME)) DEFINE_RE = re.compile(r'#define\s+(\w+)\s+(.+?)(\s*///.*)?$') -ALLOWED_CONFIG_PROPERTIES = set(['type', 'default', 'min', 'max', 'enumvalues', 'group', 'advanced', 'depends']) +PROPERTY_TYPE = 'type' +PROPERTY_DEFAULT = 'default' +PROPERTY_MIN = 'min' +PROPERTY_MAX = 'max' +PROPERTY_ENUMVALUES = 'enumvalues' +PROPERTY_GROUP = 'group' +PROPERTY_ADVANCED = 'advanced' +PROPERTY_DEPENDS = 'depends' +ALLOWED_CONFIG_PROPERTIES = set([PROPERTY_TYPE, PROPERTY_DEFAULT, PROPERTY_MIN, PROPERTY_MAX, PROPERTY_ENUMVALUES, PROPERTY_GROUP, PROPERTY_ADVANCED, PROPERTY_DEPENDS]) + +PROPERTY_TYPE_INT = 'int' +PROPERTY_TYPE_BOOL = 'bool' +PROPERTY_TYPE_ENUM = 'enum' CHIP_NAMES = ["rp2040", "rp2350"] @@ -57,9 +69,37 @@ def __init__(self, message, errors): chips_all_defines = defaultdict(dict) - -def ValidateAttrs(config_name, config_attrs, file_path, linenum): - _type = config_attrs.get('type', 'int') +def get_first_dict_key(some_dict): + return list(some_dict.keys())[0] + +def look_for_integer_define(config_name, attr_name, attr_str, file_path, linenum, applicable): + defined_str = None + if re.match('^\w+$', attr_str): + # See if we have a matching define + all_defines = chips_all_defines[applicable] + if attr_str in all_defines: + # There _may_ be multiple matching defines, but arbitrarily choose just one + defined_str = get_first_dict_key(all_defines[attr_str]) + else: + if applicable == 'all': + # Look for it in the chip-specific defines + found_chips = [] + missing_chips = [] + for chip in CHIP_NAMES: + all_defines = chips_all_defines[chip] + if attr_str in all_defines: + found_chips.append(chip) + # There _may_ be multiple matching defines, but arbitrarily choose just one + defined_str = get_first_dict_key(all_defines[attr_str]) + else: + missing_chips.append(chip) + # Report if it's found for some chips but not others (but ignore if it's missing for all) + if found_chips and missing_chips: + logger.info('{} at {}:{} has {} value "{}" which has a matching define for {} but not for {}'.format(config_name, file_path, linenum, attr_name, attr_str, found_chips, missing_chips)) + return defined_str + +def ValidateAttrs(config_name, config_attrs, file_path, linenum, applicable): + type_str = config_attrs.get(PROPERTY_TYPE, PROPERTY_TYPE_INT) errors = [] # Validate attrs @@ -67,76 +107,69 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): if key not in ALLOWED_CONFIG_PROPERTIES: errors.append(Exception('{} at {}:{} has unexpected property "{}"'.format(config_name, file_path, linenum, key))) - if _type == 'int': - assert 'enumvalues' not in config_attrs - _min = _max = _default = None - if config_attrs.get('min', None) is not None: - try: - value = config_attrs['min'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) - if m: - _min = int(m.group(1)) * 10**int(m.group(2)) - else: - _min = int(value, 0) - except ValueError: - logger.info('{} at {}:{} has non-integer min value "{}"'.format(config_name, file_path, linenum, config_attrs['min'])) - if config_attrs.get('max', None) is not None: - try: - value = config_attrs['max'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) - if m: - _max = int(m.group(1)) * 10**int(m.group(2)) - else: - _max = int(value, 0) - except ValueError: - logger.info('{} at {}:{} has non-integer max value "{}"'.format(config_name, file_path, linenum, config_attrs['max'])) - if config_attrs.get('default', None) is not None: - if '/' not in config_attrs['default']: + str_values = dict() + parsed_values = dict() + if type_str == PROPERTY_TYPE_INT: + assert PROPERTY_ENUMVALUES not in config_attrs + + for attr_name in (PROPERTY_MIN, PROPERTY_MAX, PROPERTY_DEFAULT): + str_values[attr_name] = config_attrs.get(attr_name, None) + if str_values[attr_name] is not None: try: - value = config_attrs['default'] - m = re.match(r'^(\d+)e(\d+)$', value.lower()) + m = re.match(r'^(\d+)e(\d+)$', str_values[attr_name].lower()) if m: - _default = int(m.group(1)) * 10**int(m.group(2)) + parsed_values[attr_name] = int(m.group(1)) * 10**int(m.group(2)) else: - _default = int(value, 0) + parsed_values[attr_name] = int(str_values[attr_name], 0) except ValueError: - logger.info('{} at {}:{} has non-integer default value "{}"'.format(config_name, file_path, linenum, config_attrs['default'])) - if _min is not None and _max is not None: - if _min > _max: - errors.append(Exception('{} at {}:{} has min {} > max {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['max']))) - if _min is not None and _default is not None: - if _min > _default: - errors.append(Exception('{} at {}:{} has min {} > default {}'.format(config_name, file_path, linenum, config_attrs['min'], config_attrs['default']))) - if _default is not None and _max is not None: - if _default > _max: - errors.append(Exception('{} at {}:{} has default {} > max {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['max']))) - elif _type == 'bool': - - assert 'min' not in config_attrs - assert 'max' not in config_attrs - assert 'enumvalues' not in config_attrs - - _default = config_attrs.get('default', None) - if _default is not None: - if '/' not in _default: - if (_default not in ('0', '1')) and (_default not in all_config_names): - logger.info('{} at {}:{} has non-integer default value "{}"'.format(config_name, file_path, linenum, config_attrs['default'])) - - elif _type == 'enum': - - assert 'min' not in config_attrs - assert 'max' not in config_attrs - assert 'enumvalues' in config_attrs - - _enumvalues = tuple(config_attrs['enumvalues'].split('|')) - _default = None - if config_attrs.get('default', None) is not None: - _default = config_attrs['default'] - if _default is not None: - if _default not in _enumvalues: - errors.append(Exception('{} at {}:{} has default value {} which isn\'t in list of enumvalues {}'.format(config_name, file_path, linenum, config_attrs['default'], config_attrs['enumvalues']))) + defined_str = look_for_integer_define(config_name, attr_name, str_values[attr_name], file_path, linenum, applicable) + if defined_str is not None: + try: + m = re.match(r'^(\d+)e(\d+)$', str_values[attr_name].lower()) + if m: + parsed_values[attr_name] = int(m.group(1)) * 10**int(m.group(2)) + else: + parsed_values[attr_name] = int(defined_str, 0) + except ValueError: + logger.info('{} at {}:{} has {} value "{}" which resolves to the non-integer value "{}"'.format(config_name, file_path, linenum, attr_name, str_values[attr_name], defined_str)) + else: + logger.info('{} at {}:{} has non-integer {} value "{}"'.format(config_name, file_path, linenum, attr_name, str_values[attr_name])) + for (small_attr, large_attr) in ( + (PROPERTY_MIN, PROPERTY_MAX), + (PROPERTY_MIN, PROPERTY_DEFAULT), + (PROPERTY_DEFAULT, PROPERTY_MAX), + ): + if small_attr in parsed_values and large_attr in parsed_values and parsed_values[small_attr] > parsed_values[large_attr]: + errors.append(Exception('{} at {}:{} has {} {} > {} {}'.format(config_name, file_path, linenum, small_attr, str_values[small_attr], large_attr, str_values[large_attr]))) + + elif type_str == PROPERTY_TYPE_BOOL: + assert PROPERTY_MIN not in config_attrs + assert PROPERTY_MAX not in config_attrs + assert PROPERTY_ENUMVALUES not in config_attrs + + attr_name = PROPERTY_DEFAULT + str_values[attr_name] = config_attrs.get(attr_name, None) + if str_values[attr_name] is not None: + if (str_values[attr_name] not in ('0', '1')) and (str_values[attr_name] not in all_config_names): + logger.info('{} at {}:{} has non-integer {} value "{}"'.format(config_name, file_path, linenum, attr_name, str_values[attr_name])) + + elif type_str == PROPERTY_TYPE_ENUM: + assert PROPERTY_ENUMVALUES in config_attrs + assert PROPERTY_MIN not in config_attrs + assert PROPERTY_MAX not in config_attrs + + attr_name = PROPERTY_ENUMVALUES + str_values[attr_name] = config_attrs[attr_name] + parsed_values[attr_name] = tuple(str_values[attr_name].split('|')) + + attr_name = PROPERTY_DEFAULT + str_values[attr_name] = config_attrs.get(attr_name, None) + if str_values[attr_name] is not None: + if str_values[attr_name] not in _enumvalues: + errors.append(Exception('{} at {}:{} has {} value {} which isn\'t in list of {} {}'.format(config_name, file_path, linenum, attr_name, str_values[attr_name], PROPERTY_ENUMVALUES, str_values[PROPERTY_ENUMVALUES]))) + else: - errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_CONFIG_NAME, _type, file_path, linenum))) + errors.append(Exception("Found unknown {} type {} at {}:{}".format(BASE_CONFIG_NAME, type_str, file_path, linenum))) return errors @@ -256,7 +289,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): file_path = os.path.join(scandir, config_obj['filename']) linenum = config_obj['line_number'] - errors.extend(ValidateAttrs(config_name, config_obj['attrs'], file_path, linenum)) + errors.extend(ValidateAttrs(config_name, config_obj['attrs'], file_path, linenum, applicable)) # Check that default values match up if 'default' in config_obj['attrs']: @@ -267,7 +300,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): if '/' in config_default or ' ' in config_default: continue # There _may_ be multiple matching defines, but arbitrarily display just one in the error message - first_define_value = list(defines_obj.keys())[0] + first_define_value = get_first_dict_key(defines_obj) first_define_file_path, first_define_linenum = defines_obj[first_define_value] errors.append(Exception('Found {} at {}:{} with a default of {}, but #define says {} (at {}:{})'.format(config_name, file_path, linenum, config_default, first_define_value, first_define_file_path, first_define_linenum))) else: From c4e30ce6935109cc23516165fc231c7a9b2dae3c Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 25 Jul 2025 09:14:58 -0500 Subject: [PATCH 211/224] Update docs, and add methods for new RP2350 DMA features (#2588) * Update docs, and add methods for new RP2350 dma_transfer modes Update docs, and add methods for handling reversed/double-increment DMA * Apply suggestions from code review Co-authored-by: Andrew Scheller * more review fixes * add typedefs and rename dma_channel_config to be consistent * Apply suggestions from code review Co-authored-by: Andrew Scheller * Apply suggestions from code review Co-authored-by: Andrew Scheller --------- Co-authored-by: Andrew Scheller --- .../hardware_dma/include/hardware/dma.h | 294 +++++++++++++++--- 1 file changed, 254 insertions(+), 40 deletions(-) diff --git a/src/rp2_common/hardware_dma/include/hardware/dma.h b/src/rp2_common/hardware_dma/include/hardware/dma.h index 27dd92286..2ae64d5fa 100644 --- a/src/rp2_common/hardware_dma/include/hardware/dma.h +++ b/src/rp2_common/hardware_dma/include/hardware/dma.h @@ -140,36 +140,128 @@ bool dma_channel_is_claimed(uint channel); * * Names indicate the number of bits. */ -enum dma_channel_transfer_size { +typedef enum dma_channel_transfer_size { DMA_SIZE_8 = 0, ///< Byte transfer (8 bits) DMA_SIZE_16 = 1, ///< Half word transfer (16 bits) DMA_SIZE_32 = 2 ///< Word transfer (32 bits) -}; +} dma_channel_transfer_size_t; +/*! \brief Enumeration of types of updates that can be made to the DMA read or write address after each transfer + * \ingroup hardware_dma + */ +typedef enum dma_address_update_type { + DMA_ADDRESS_UPDATE_NONE = 0, ///< The address remains the same after each transfer + DMA_ADDRESS_UPDATE_INCREMENT = 1, ///< The address is incremented by the transfer size after each transfer +#if !PICO_RP2040 + DMA_ADDRESS_UPDATE_INCREMENT_BY_TWO = 2, ///< (RP2350 only) The address is incremented by twice the transfer size after each transfer + DMA_ADDRESS_UPDATE_DECREMENT = 3, ///< (RP2350 only) The address is decremented by the transfer size after each transfer +#endif +} dma_address_update_type_t; + +/*! \brief Opaque representation of a DMA channel configuration that can be later applied to a hardware DMA channel + * \ingroup channel_config + */ typedef struct { uint32_t ctrl; -} dma_channel_config; +} dma_channel_config_t; -/*! \brief Set DMA channel read increment in a channel configuration object +// backwards compatibility +typedef dma_channel_config_t dma_channel_config; + +#ifndef DMA_ADDRESS_UPDATE_TYPE_TO_DMA_CH_CTRL_READ_BITS +#if PICO_RP2040 +#define DMA_ADDRESS_UPDATE_TYPE_TO_DMA_CH_CTRL_READ_BITS(u) (((u)&1) << DMA_CH0_CTRL_TRIG_INCR_READ_LSB) +#else +#define DMA_ADDRESS_UPDATE_TYPE_TO_DMA_CH_CTRL_READ_BITS(u) \ + ((((u)&1) << DMA_CH0_CTRL_TRIG_INCR_READ_LSB) | \ + (((u)&2) << (DMA_CH0_CTRL_TRIG_INCR_READ_REV_LSB - 1))) +#endif +#endif + +#ifndef DMA_ADDRESS_UPDATE_TYPE_TO_DMA_CH_CTRL_WRITE_BITS +#if PICO_RP2040 +#define DMA_ADDRESS_UPDATE_TYPE_TO_DMA_CH_CTRL_WRITE_BITS(u) (((u)&1) << DMA_CH0_CTRL_TRIG_INCR_WRITE_LSB) +#else +#define DMA_ADDRESS_UPDATE_TYPE_TO_DMA_CH_CTRL_WRITE_BITS(u) \ +((((u)&1) << DMA_CH0_CTRL_TRIG_INCR_WRITE_LSB) | \ +(((u)&2) << (DMA_CH0_CTRL_TRIG_INCR_WRITE_REV_LSB - 1))) +#endif +#endif + +#ifndef DMA_CH_CTRL_ALL_ADDRESS_UPDATE_READ_BITS +#if PICO_RP2040 +#define DMA_CH_CTRL_ALL_ADDRESS_UPDATE_READ_BITS DMA_CH0_CTRL_TRIG_INCR_READ_BITS +#else +#define DMA_CH_CTRL_ALL_ADDRESS_UPDATE_READ_BITS (DMA_CH0_CTRL_TRIG_INCR_READ_BITS | DMA_CH0_CTRL_TRIG_INCR_READ_REV_BITS) +#endif +#endif + +#ifndef DMA_CH_CTRL_ALL_ADDRESS_UPDATE_WRITE_BITS +#if PICO_RP2040 +#define DMA_CH_CTRL_ALL_ADDRESS_UPDATE_WRITE_BITS DMA_CH0_CTRL_TRIG_INCR_WRITE_BITS +#else +#define DMA_CH_CTRL_ALL_ADDRESS_UPDATE_WRITE_BITS (DMA_CH0_CTRL_TRIG_INCR_WRITE_BITS | DMA_CH0_CTRL_TRIG_INCR_WRITE_REV_BITS) +#endif +#endif + +/*! \brief Set DMA channel read address update type in a channel configuration object * \ingroup channel_config * * \param c Pointer to channel configuration object - * \param incr True to enable read address increments, if false, each read will be from the same address - * Usually disabled for peripheral to memory transfers + * \param update_type The type of adjustment to make to the read address after each transfer. + * Usually set to DMA_ADDRESS_UPDATE_NONE for peripheral to memory transfers + * \sa channel_config_set_read_increment */ -static inline void channel_config_set_read_increment(dma_channel_config *c, bool incr) { - c->ctrl = incr ? (c->ctrl | DMA_CH0_CTRL_TRIG_INCR_READ_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_INCR_READ_BITS); +static inline void channel_config_set_read_address_update_type(dma_channel_config_t *c, dma_address_update_type_t update_type) { + c->ctrl = (c->ctrl & ~DMA_CH_CTRL_ALL_ADDRESS_UPDATE_READ_BITS) | + DMA_ADDRESS_UPDATE_TYPE_TO_DMA_CH_CTRL_READ_BITS(update_type); +} + +/*! \brief Set DMA channel write address update type in a channel configuration object + * \ingroup channel_config + * + * \param c Pointer to channel configuration object + * \param update_type The type of adjustment to make to the write address after each transfer. + * Usually set to DMA_ADDRESS_UPDATE_NONE for memory to peripheral transfers + * \sa channel_config_set_write_increment + */ +static inline void channel_config_set_write_address_update_type(dma_channel_config_t *c, dma_address_update_type_t update_type) { + c->ctrl = (c->ctrl & ~DMA_CH_CTRL_ALL_ADDRESS_UPDATE_WRITE_BITS) | + DMA_ADDRESS_UPDATE_TYPE_TO_DMA_CH_CTRL_WRITE_BITS(update_type); +} + +/*! \brief Set DMA channel read increment in a channel configuration object +* \ingroup channel_config +* +* \note this method is equivalent to +* \code +* channel_config_set_read_address_update_type(c, incr ? DMA_ADDRESS_UPDATE_INCREMENT : DMA_ADDRESS_UPDATE_NONE) +* \endcode +* +* \param c Pointer to channel configuration object +* \param incr True to enable read address increments, whereby the read address increments by the transfer size with each transfer. False to perform each read from the same address. +* Usually disabled for peripheral to memory transfers +* \sa channel_config_set_read_address_update_type +*/ +static inline void channel_config_set_read_increment(dma_channel_config_t *c, bool incr) { + channel_config_set_read_address_update_type(c, incr ? DMA_ADDRESS_UPDATE_INCREMENT : DMA_ADDRESS_UPDATE_NONE); } /*! \brief Set DMA channel write increment in a channel configuration object * \ingroup channel_config * + * \note this method is equivalent to + * \code + * channel_config_set_write_address_update_type(c, incr ? DMA_ADDRESS_UPDATE_INCREMENT : DMA_ADDRESS_UPDATE_NONE) + * \endcode + * * \param c Pointer to channel configuration object - * \param incr True to enable write address increments, if false, each write will be to the same address + * \param incr True to enable write address increments, whereby the write address increments by the transfer size with each transfer. False to perform each write to the same address. * Usually disabled for memory to peripheral transfers + * \sa channel_config_set_write_address_update_type */ -static inline void channel_config_set_write_increment(dma_channel_config *c, bool incr) { - c->ctrl = incr ? (c->ctrl | DMA_CH0_CTRL_TRIG_INCR_WRITE_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_INCR_WRITE_BITS); +static inline void channel_config_set_write_increment(dma_channel_config_t *c, bool incr) { + channel_config_set_write_address_update_type(c, incr ? DMA_ADDRESS_UPDATE_INCREMENT : DMA_ADDRESS_UPDATE_NONE); } /*! \brief Select a transfer request signal in a channel configuration object @@ -187,7 +279,7 @@ static inline void channel_config_set_write_increment(dma_channel_config *c, boo * \param c Pointer to channel configuration data * \param dreq Source (see description) */ -static inline void channel_config_set_dreq(dma_channel_config *c, uint dreq) { +static inline void channel_config_set_dreq(dma_channel_config_t *c, uint dreq) { assert(dreq <= DREQ_FORCE); c->ctrl = (c->ctrl & ~DMA_CH0_CTRL_TRIG_TREQ_SEL_BITS) | (dreq << DMA_CH0_CTRL_TRIG_TREQ_SEL_LSB); } @@ -201,7 +293,7 @@ static inline void channel_config_set_dreq(dma_channel_config *c, uint dreq) { * \param c Pointer to channel configuration object * \param chain_to Channel to trigger when this channel completes. */ -static inline void channel_config_set_chain_to(dma_channel_config *c, uint chain_to) { +static inline void channel_config_set_chain_to(dma_channel_config_t *c, uint chain_to) { assert(chain_to <= NUM_DMA_CHANNELS); c->ctrl = (c->ctrl & ~DMA_CH0_CTRL_TRIG_CHAIN_TO_BITS) | (chain_to << DMA_CH0_CTRL_TRIG_CHAIN_TO_LSB); } @@ -215,7 +307,7 @@ static inline void channel_config_set_chain_to(dma_channel_config *c, uint chain * \param c Pointer to channel configuration object * \param size See enum for possible values. */ -static inline void channel_config_set_transfer_data_size(dma_channel_config *c, enum dma_channel_transfer_size size) { +static inline void channel_config_set_transfer_data_size(dma_channel_config_t *c, dma_channel_transfer_size_t size) { assert(size == DMA_SIZE_8 || size == DMA_SIZE_16 || size == DMA_SIZE_32); c->ctrl = (c->ctrl & ~DMA_CH0_CTRL_TRIG_DATA_SIZE_BITS) | (((uint)size) << DMA_CH0_CTRL_TRIG_DATA_SIZE_LSB); } @@ -235,7 +327,7 @@ static inline void channel_config_set_transfer_data_size(dma_channel_config *c, * \param size_bits 0 to disable wrapping. Otherwise the size in bits of the changing part of the address. * Effectively wraps the address on a (1 << size_bits) byte boundary. */ -static inline void channel_config_set_ring(dma_channel_config *c, bool write, uint size_bits) { +static inline void channel_config_set_ring(dma_channel_config_t *c, bool write, uint size_bits) { assert(size_bits < 32); c->ctrl = (c->ctrl & ~(DMA_CH0_CTRL_TRIG_RING_SIZE_BITS | DMA_CH0_CTRL_TRIG_RING_SEL_BITS)) | (size_bits << DMA_CH0_CTRL_TRIG_RING_SIZE_LSB) | @@ -251,7 +343,7 @@ static inline void channel_config_set_ring(dma_channel_config *c, bool write, ui * \param c Pointer to channel configuration object * \param bswap True to enable byte swapping */ -static inline void channel_config_set_bswap(dma_channel_config *c, bool bswap) { +static inline void channel_config_set_bswap(dma_channel_config_t *c, bool bswap) { c->ctrl = bswap ? (c->ctrl | DMA_CH0_CTRL_TRIG_BSWAP_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_BSWAP_BITS); } @@ -265,7 +357,7 @@ static inline void channel_config_set_bswap(dma_channel_config *c, bool bswap) { * \param c Pointer to channel configuration object * \param irq_quiet True to enable quiet mode, false to disable. */ -static inline void channel_config_set_irq_quiet(dma_channel_config *c, bool irq_quiet) { +static inline void channel_config_set_irq_quiet(dma_channel_config_t *c, bool irq_quiet) { c->ctrl = irq_quiet ? (c->ctrl | DMA_CH0_CTRL_TRIG_IRQ_QUIET_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_IRQ_QUIET_BITS); } @@ -283,7 +375,7 @@ static inline void channel_config_set_irq_quiet(dma_channel_config *c, bool irq_ * \param c Pointer to channel configuration object * \param high_priority True to enable high priority */ -static inline void channel_config_set_high_priority(dma_channel_config *c, bool high_priority) { +static inline void channel_config_set_high_priority(dma_channel_config_t *c, bool high_priority) { c->ctrl = high_priority ? (c->ctrl | DMA_CH0_CTRL_TRIG_HIGH_PRIORITY_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_HIGH_PRIORITY_BITS); } @@ -298,7 +390,7 @@ static inline void channel_config_set_high_priority(dma_channel_config *c, bool * \param enable True to enable the DMA channel. When enabled, the channel will respond to triggering events, and start transferring data. * */ -static inline void channel_config_set_enable(dma_channel_config *c, bool enable) { +static inline void channel_config_set_enable(dma_channel_config_t *c, bool enable) { c->ctrl = enable ? (c->ctrl | DMA_CH0_CTRL_TRIG_EN_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_EN_BITS); } @@ -310,7 +402,7 @@ static inline void channel_config_set_enable(dma_channel_config *c, bool enable) * \param c Pointer to channel configuration object * \param sniff_enable True to enable the Sniff HW access to this DMA channel. */ -static inline void channel_config_set_sniff_enable(dma_channel_config *c, bool sniff_enable) { +static inline void channel_config_set_sniff_enable(dma_channel_config_t *c, bool sniff_enable) { c->ctrl = sniff_enable ? (c->ctrl | DMA_CH0_CTRL_TRIG_SNIFF_EN_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_SNIFF_EN_BITS); } @@ -335,8 +427,8 @@ static inline void channel_config_set_sniff_enable(dma_channel_config *c, bool s * \param channel DMA channel * \return the default configuration which can then be modified. */ -static inline dma_channel_config dma_channel_get_default_config(uint channel) { - dma_channel_config c = {0}; +static inline dma_channel_config_t dma_channel_get_default_config(uint channel) { + dma_channel_config_t c = {0}; channel_config_set_read_increment(&c, true); channel_config_set_write_increment(&c, false); channel_config_set_dreq(&c, DREQ_FORCE); @@ -357,8 +449,8 @@ static inline dma_channel_config dma_channel_get_default_config(uint channel) { * \param channel DMA channel * \return The current configuration as read from the HW register (not cached) */ -static inline dma_channel_config dma_get_channel_config(uint channel) { - dma_channel_config c; +static inline dma_channel_config_t dma_get_channel_config(uint channel) { + dma_channel_config_t c; c.ctrl = dma_channel_hw_addr(channel)->ctrl_trig; return c; } @@ -369,7 +461,7 @@ static inline dma_channel_config dma_get_channel_config(uint channel) { * \param config Pointer to a config structure. * \return Register content */ -static inline uint32_t channel_config_get_ctrl_value(const dma_channel_config *config) { +static inline uint32_t channel_config_get_ctrl_value(const dma_channel_config_t *config) { return config->ctrl; } @@ -380,7 +472,7 @@ static inline uint32_t channel_config_get_ctrl_value(const dma_channel_config *c * \param config Pointer to a config structure with required configuration * \param trigger True to trigger the transfer immediately */ -static inline void dma_channel_set_config(uint channel, const dma_channel_config *config, bool trigger) { +static inline void dma_channel_set_config(uint channel, const dma_channel_config_t *config, bool trigger) { // Don't use CTRL_TRIG since we don't want to start a transfer if (!trigger) { dma_channel_hw_addr(channel)->al1_ctrl = channel_config_get_ctrl_value(config); @@ -419,21 +511,110 @@ static inline void dma_channel_set_write_addr(uint channel, volatile void *write } } +/*! \brief Encode the specified transfer length into an "encoded_transfer_length" value suitable for the referenced methods + * \ingroup hardware_dma + * \param transfer_count the number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) + * + * \if rp2040_specific + * On RP2040 the valid range is 0 -> 2^32 - 1 + * \endif + * + * \if rp2350_specific + * On RP2350 the valid range is 0 -> 2^28 - 1 + * \endif + * \return the encoded_transfer_count + * \sa dma_channel_set_transfer_count + * \sa dma_channel_configure + * \sa dma_channel_transfer_from_buffer_now + * \sa dma_channel_transfer_to_buffer_now + */ +static inline uint32_t dma_encode_transfer_count(uint transfer_count) { +#if !PICO_RP2040 + invalid_params_if(HARDWARE_DMA, transfer_count & DMA_CH0_TRANS_COUNT_MODE_BITS); + return transfer_count & DMA_CH0_TRANS_COUNT_COUNT_BITS; +#else + return transfer_count; +#endif +} + +/*! \brief Encode the specified transfer length, along with a flag to indicate the DMA transfer should be self-triggering, into an "encoded_transfer_length" value suitable for the referenced methods + * \ingroup hardware_dma + * \param transfer_count the number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) + * + * \if rp2040_specific + * On RP2040 self-triggering DMA is not supported, so this method should not be used + * \endif + * + * \if rp2350_specific + * On RP2350 the valid range is 0 -> 2^28 - 1 + * \endif + * \return the encoded_transfer_count + * \sa dma_channel_set_transfer_count + * \sa dma_channel_configure + * \sa dma_channel_transfer_from_buffer_now + * \sa dma_channel_transfer_to_buffer_now + */ +static inline uint32_t dma_encode_transfer_count_with_self_trigger(uint transfer_count) { +#if PICO_RP2040 + panic_unsupported(); +#else + return dma_encode_transfer_count(transfer_count) | (DMA_CH0_TRANS_COUNT_MODE_VALUE_TRIGGER_SELF << DMA_CH0_TRANS_COUNT_MODE_LSB); +#endif +} + +/*! \brief Return an endless transfer as an "encoded_transfer_length" value suitable for the referenced methods + * \ingroup hardware_dma + * + * \if rp2040_specific + * On RP2040 endless DMA transfers are not supported, so this method should not be used + * \endif + * \return the encoded_transfer_count + * \sa dma_channel_set_transfer_count + * \sa dma_channel_configure + * \sa dma_channel_transfer_from_buffer_now + * \sa dma_channel_transfer_to_buffer_now + */ +static inline uint32_t dma_encode_endless_transfer_count(void) { +#if PICO_RP2040 + panic_unsupported(); +#else + static_assert(DMA_CH0_TRANS_COUNT_MODE_VALUE_ENDLESS == 0xf); + static_assert(DMA_CH0_TRANS_COUNT_MODE_LSB == 28); + return 0xffffffffu; +#endif +} + /*! \brief Set the number of bus transfers the channel will do * \ingroup hardware_dma * * \param channel DMA channel - * \param trans_count The number of transfers (not NOT bytes, see channel_config_set_transfer_data_size) + * \param encoded_transfer_count The encoded transfer count + * + * \if rp2040_specific + * On RP2040 this is just the number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) from 0 -> 2^32 - 1. + * \endif + * + * \if rp2350_specific + * On RP2350 the low 28 bits are used to encode a number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) and non-zero values of the top 4 bits are used to specify other options. + * \endif + * + * The best practice is always to use either \ref dma_encode_transfer_count, \ref dma_encode_transfer_count_with_self_trigger, or \ref dma_encode_endless_transfer_count to generate a value + * to pass for this argument * \param trigger True to start the transfer immediately */ -static inline void dma_channel_set_trans_count(uint channel, uint32_t trans_count, bool trigger) { +static inline void dma_channel_set_transfer_count(uint channel, uint32_t encoded_transfer_count, bool trigger) { if (!trigger) { - dma_channel_hw_addr(channel)->transfer_count = trans_count; + dma_channel_hw_addr(channel)->transfer_count = encoded_transfer_count; } else { - dma_channel_hw_addr(channel)->al1_transfer_count_trig = trans_count; + dma_channel_hw_addr(channel)->al1_transfer_count_trig = encoded_transfer_count; } } +// backwards compatibility with SDK < 2.2.0 +static inline void dma_channel_set_trans_count(uint channel, uint32_t trans_count, bool trigger) { + dma_channel_set_transfer_count(channel, trans_count, trigger); +} + /*! \brief Configure all DMA parameters and optionally start transfer * \ingroup hardware_dma * @@ -441,15 +622,26 @@ static inline void dma_channel_set_trans_count(uint channel, uint32_t trans_coun * \param config Pointer to DMA config structure * \param write_addr Initial write address * \param read_addr Initial read address - * \param transfer_count Number of transfers to perform + * \param encoded_transfer_count The encoded transfer count + * + * \if rp2040_specific + * On RP2040 this is just the number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) from 0 -> 2^32 - 1. + * \endif + * + * \if rp2350_specific + * On RP2350 the low 28 bits are used to encode a number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) and non-zero values of the top 4 bits are used to specify other options. + * \endif + * + * The best practice is always to use either \ref dma_encode_transfer_count, \ref dma_encode_transfer_count_with_self_trigger, or \ref dma_encode_endless_transfer_count to generate a value + * to pass for this argument * \param trigger True to start the transfer immediately */ -static inline void dma_channel_configure(uint channel, const dma_channel_config *config, volatile void *write_addr, +static inline void dma_channel_configure(uint channel, const dma_channel_config_t *config, volatile void *write_addr, const volatile void *read_addr, - uint transfer_count, bool trigger) { + uint32_t encoded_transfer_count, bool trigger) { dma_channel_set_read_addr(channel, read_addr, false); dma_channel_set_write_addr(channel, write_addr, false); - dma_channel_set_trans_count(channel, transfer_count, false); + dma_channel_set_transfer_count(channel, encoded_transfer_count, false); dma_channel_set_config(channel, config, trigger); } @@ -458,15 +650,26 @@ static inline void dma_channel_configure(uint channel, const dma_channel_config * * \param channel DMA channel * \param read_addr Sets the initial read address - * \param transfer_count Number of transfers to make. Not bytes, but the number of transfers of channel_config_set_transfer_data_size() to be sent. + * \param encoded_transfer_count The encoded transfer count + * + * \if rp2040_specific + * On RP2040 this is just the number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) from 0 -> 2^32 - 1. + * \endif + * + * \if rp2350_specific + * On RP2350 the low 28 bits are used to encode a number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) and non-zero values of the top 4 bits are used to specify other options. + * \endif + * + * The best practice is always to use either \ref dma_encode_transfer_count, \ref dma_encode_transfer_count_with_self_trigger, or \ref dma_encode_endless_transfer_count to generate a value + * to pass for this argument */ inline static void __attribute__((always_inline)) dma_channel_transfer_from_buffer_now(uint channel, const volatile void *read_addr, - uint32_t transfer_count) { + uint32_t encoded_transfer_count) { // check_dma_channel_param(channel); dma_channel_hw_t *hw = dma_channel_hw_addr(channel); hw->read_addr = (uintptr_t) read_addr; - hw->al1_transfer_count_trig = transfer_count; + hw->al1_transfer_count_trig = encoded_transfer_count; } /*! \brief Start a DMA transfer to a buffer immediately @@ -474,12 +677,23 @@ inline static void __attribute__((always_inline)) dma_channel_transfer_from_buff * * \param channel DMA channel * \param write_addr Sets the initial write address - * \param transfer_count Number of transfers to make. Not bytes, but the number of transfers of channel_config_set_transfer_data_size() to be sent. + * \param encoded_transfer_count The encoded transfer count + * + * \if rp2040_specific + * On RP2040 this is just the number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) from 0 -> 2^32 - 1. + * \endif + * + * \if rp2350_specific + * On RP2350 the low 28 bits are used to encode a number of transfers (NOT bytes, see \ref channel_config_set_transfer_data_size) and non-zero values of the top 4 bits are used to specify other options. + * \endif + * + * The best practice is always to use either \ref dma_encode_transfer_count, \ref dma_encode_transfer_count_with_self_trigger, or \ref dma_encode_endless_transfer_count to generate a value + * to pass for this argument */ -inline static void dma_channel_transfer_to_buffer_now(uint channel, volatile void *write_addr, uint32_t transfer_count) { +inline static void dma_channel_transfer_to_buffer_now(uint channel, volatile void *write_addr, uint32_t encoded_transfer_count) { dma_channel_hw_t *hw = dma_channel_hw_addr(channel); hw->write_addr = (uintptr_t) write_addr; - hw->al1_transfer_count_trig = transfer_count; + hw->al1_transfer_count_trig = encoded_transfer_count; } /*! \brief Start one or more channels simultaneously From 3461d65d793059bb324af6c2263d2571379a3771 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 25 Jul 2025 09:44:08 -0500 Subject: [PATCH 212/224] add some missing pico_config and pico_cmake_config entries (#2559) --- bazel/config/BUILD.bazel | 2 +- cmake/pico_pre_load_platform.cmake | 8 +++++++- cmake/pico_pre_load_toolchain.cmake | 1 + .../toolchains/pico_arm_cortex_m33_gcc.cmake | 1 + cmake/preload/toolchains/util/set_flags.cmake | 2 ++ .../boot_stage2/include/boot_stage2/config.h | 14 ++++++++------ .../boot_stage2/include/boot_stage2/config.h | 15 +++++++++------ src/rp2_common/pico_btstack/CMakeLists.txt | 2 +- src/rp2_common/pico_clib_interface/CMakeLists.txt | 1 + src/rp2_common/pico_cyw43_driver/CMakeLists.txt | 2 +- src/rp2_common/pico_float/include/pico/float.h | 2 ++ src/rp2_common/pico_lwip/CMakeLists.txt | 2 +- src/rp2_common/pico_mbedtls/CMakeLists.txt | 2 +- .../pico_stdio_usb/include/pico/stdio_usb.h | 2 +- src/rp2_common/tinyusb/CMakeLists.txt | 2 +- tools/extract_build_defines.py | 2 +- tools/extract_cmake_configs.py | 4 ++-- tools/extract_configs.py | 2 +- 18 files changed, 42 insertions(+), 24 deletions(-) diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index b27cbdd54..84eac746e 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -247,7 +247,7 @@ label_flag( build_setting_default = "//bazel:generate_config_header", ) -# PICO_BAZEL_CONFIG: PICO_CLIB, [Bazel only] The flavor of libc porting layer to use. auto infers the correct value to use from PICO_TOOLCHAIN, group=pico_standard_link +# PICO_BAZEL_CONFIG: PICO_CLIB, The C library to use e.g. newlib/picolibc/llvm_libc, type=string, default=based on PICO_COMPILER, group=build, docref=cmake-toolchain-config string_flag( name = "PICO_CLIB", build_setting_default = "auto", diff --git a/cmake/pico_pre_load_platform.cmake b/cmake/pico_pre_load_platform.cmake index ea1127574..936e2f99c 100644 --- a/cmake/pico_pre_load_platform.cmake +++ b/cmake/pico_pre_load_platform.cmake @@ -15,22 +15,28 @@ set(PICO_SAVED_PLATFORM "${PICO_PLATFORM}") # If PICO_PLATFORM is specified but not PICO_BOARD, we'll make a stab at defaulting if (NOT PICO_DEFAULT_BOARD_rp2040) + # PICO_CMAKE_CONFIG: PICO_DEFAULT_BOARD_rp2040, The default PICO_BOARD when PICO_PLATFORM is rp2040, type=string, default=pico, group=build, docref=cmake-platform-board-config set(PICO_DEFAULT_BOARD_rp2040 "pico") endif() if (NOT PICO_DEFAULT_BOARD_rp2350) + # PICO_CMAKE_CONFIG: PICO_DEFAULT_BOARD_rp2350, The default PICO_BOARD when PICO_PLATFORM is rp2350, type=string, default=pico2, group=build, docref=cmake-platform-board-config set(PICO_DEFAULT_BOARD_rp2350 "pico2") endif() if (NOT PICO_DEFAULT_BOARD_rp2350-arm-s) + # PICO_CMAKE_CONFIG: PICO_DEFAULT_BOARD_rp2350-arm-s, The default PICO_BOARD when PICO_PLATFORM is rp2350-arm-s, type=string, default=pico2, group=build, docref=cmake-platform-board-config set(PICO_DEFAULT_BOARD_rp2350-arm-s "pico2") endif() if (NOT PICO_DEFAULT_BOARD_rp2350-riscv) + # PICO_CMAKE_CONFIG: PICO_DEFAULT_BOARD_rp2350-riscv, The default PICO_BOARD when PICO_PLATFORM is rp2350-riscv, type=string, default=pico2, group=build, docref=cmake-platform-board-config set(PICO_DEFAULT_BOARD_rp2350-riscv "pico2") endif() if (NOT PICO_DEFAULT_BOARD_host) + # PICO_CMAKE_CONFIG: PICO_DEFAULT_BOARD_host, The default PICO_BOARD when PICO_PLATFORM is host, type=string, default=none, group=build, docref=cmake-platform-board-config set(PICO_DEFAULT_BOARD_host "none") endif() if (NOT PICO_DEFAULT_PLATFORM) + # PICO_CMAKE_CONFIG: PICO_DEFAULT_PLATFORM, The default for PICO_PLATFORM if not specified, type=string, default=rp2040, group=build, docref=cmake-platform-board-config set(PICO_DEFAULT_PLATFORM "rp2040") endif() @@ -72,7 +78,7 @@ endif() list(APPEND PICO_INCLUDE_DIRS ${PICO_SDK_PATH}/src/boards/include) # so boards/foo.h can be explicitly included -# PICO_CMAKE_CONFIG: PICO_DEFAULT_RP2350_PLATFORM, Default actual platform to build for if rp2350 is specified for PICO_PLATFORM e.g. rp2350-arm-s/rp2350-riscv, type=string, default=rp2350-arm-s, group=build +# PICO_CMAKE_CONFIG: PICO_DEFAULT_RP2350_PLATFORM, Default actual platform to build for if rp2350 is specified for PICO_PLATFORM e.g. rp2350-arm-s/rp2350-riscv, type=string, default=rp2350-arm-s, group=build, docref=cmake-platform-board-config if (DEFINED ENV{PICO_DEFAULT_RP2350_PLATFORM} AND NOT PICO_DEFAULT_RP2350_PLATFORM) set(PICO_DEFAULT_RP2350_PLATFORM $ENV{PICO_DEFAULT_RP2350_PLATFORM}) endif() diff --git a/cmake/pico_pre_load_toolchain.cmake b/cmake/pico_pre_load_toolchain.cmake index 8b03c5f9d..ffc4a9d0f 100644 --- a/cmake/pico_pre_load_toolchain.cmake +++ b/cmake/pico_pre_load_toolchain.cmake @@ -48,6 +48,7 @@ if (DEFINED PICO_COMPILER) if (NOT PICO_COMPILER STREQUAL ORIG_PICO_COMPILER) message("Accepting PICO_COMPILER value '${ORIG_PICO_COMPILER}' for compatibility, but using '${PICO_COMPILER}' instead") endif() + # PICO_CMAKE_CONFIG: PICO_TOOLCHAIN_DIR, Path to search for toolchain CMake files, type=string, default=/preload/toolchains, group=build, docref=cmake-toolchain-config if (NOT DEFINED PICO_TOOLCHAIN_DIR) set(PICO_TOOLCHAIN_DIR "${CMAKE_CURRENT_LIST_DIR}/preload/toolchains") endif() diff --git a/cmake/preload/toolchains/pico_arm_cortex_m33_gcc.cmake b/cmake/preload/toolchains/pico_arm_cortex_m33_gcc.cmake index 0ba3351f4..013efc9c7 100644 --- a/cmake/preload/toolchains/pico_arm_cortex_m33_gcc.cmake +++ b/cmake/preload/toolchains/pico_arm_cortex_m33_gcc.cmake @@ -3,6 +3,7 @@ set(PICO_DEFAULT_GCC_TRIPLE arm-none-eabi) set(PICO_COMMON_LANG_FLAGS " -mcpu=cortex-m33 -mthumb -march=armv8-m.main+fp+dsp") set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -mfloat-abi=softfp") +# PICO_CMAKE_CONFIG: PICO_NO_CMSE, Disable CMSE compiler extensions, type=bool, default=0, group=build, docref=cmake-toolchain-config if (NOT PICO_NO_CMSE) set(PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -mcmse") endif() diff --git a/cmake/preload/toolchains/util/set_flags.cmake b/cmake/preload/toolchains/util/set_flags.cmake index 5a7067012..ca1a27d15 100644 --- a/cmake/preload/toolchains/util/set_flags.cmake +++ b/cmake/preload/toolchains/util/set_flags.cmake @@ -1,4 +1,6 @@ +# PICO_CMAKE_CONFIG: PICO_DEOPTIMIZED_DEBUG, Disable all compiler optimization in debug builds, type=bool, default=0, group=build, docref=cmake-toolchain-config option(PICO_DEOPTIMIZED_DEBUG "Build debug builds with -O0" 0) +# PICO_CMAKE_CONFIG: PICO_DEBUG_INFO_IN_RELEASE, Include debug information in release builds, type=bool, default=1, group=build, docref=cmake-toolchain-config option(PICO_DEBUG_INFO_IN_RELEASE "Include debug info in release builds" 1) get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) diff --git a/src/rp2040/boot_stage2/include/boot_stage2/config.h b/src/rp2040/boot_stage2/include/boot_stage2/config.h index ba9bb1f8b..568aca1ef 100644 --- a/src/rp2040/boot_stage2/include/boot_stage2/config.h +++ b/src/rp2040/boot_stage2/include/boot_stage2/config.h @@ -11,13 +11,15 @@ #include "pico.h" -// PICO_CONFIG: PICO_BUILD_BOOT_STAGE2_NAME, Name of the boot stage 2 if selected in the build system, group=boot_stage2 +// PICO_CONFIG: PICO_FLASH_SPI_CLKDIV, Clock divider from clk_sys to use for serial flash communications in boot stage 2. On RP2040 this must be a multiple of 2. This define applies to compilation of the boot stage 2 not the main application, type=int, default=varies; often specified in board header, advanced=true, group=boot_stage2 + +// PICO_CONFIG: PICO_BUILD_BOOT_STAGE2_NAME, Name of the boot stage 2 if selected in the build system. This define applies to compilation of the boot stage 2 not the main application, group=boot_stage2 #ifdef PICO_BUILD_BOOT_STAGE2_NAME #define _BOOT_STAGE2_SELECTED #else // check that multiple boot stage 2 options haven't been set... -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_IS25LP080, Select boot2_is25lp080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_IS25LP080, Select boot2_is25lp080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=0, group=boot_stage2 #ifndef PICO_BOOT_STAGE2_CHOOSE_IS25LP080 #define PICO_BOOT_STAGE2_CHOOSE_IS25LP080 0 #elif PICO_BOOT_STAGE2_CHOOSE_IS25LP080 @@ -26,7 +28,7 @@ #endif #define _BOOT_STAGE2_SELECTED #endif -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25Q080, Select boot2_w25q080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25Q080, Select boot2_w25q080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=0, group=boot_stage2 #ifndef PICO_BOOT_STAGE2_CHOOSE_W25Q080 #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 0 #elif PICO_BOOT_STAGE2_CHOOSE_W25Q080 @@ -35,7 +37,7 @@ #endif #define _BOOT_STAGE2_SELECTED #endif -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25X10CL, Select boot2_w25x10cl as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25X10CL, Select boot2_w25x10cl as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=0, group=boot_stage2 #ifndef PICO_BOOT_STAGE2_CHOOSE_W25X10CL #define PICO_BOOT_STAGE2_CHOOSE_W25X10CL 0 #elif PICO_BOOT_STAGE2_CHOOSE_W25X10CL @@ -44,7 +46,7 @@ #endif #define _BOOT_STAGE2_SELECTED #endif -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_AT25SF128A, Select boot2_at25sf128a as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_AT25SF128A, Select boot2_at25sf128a as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=0, group=boot_stage2 #ifndef PICO_BOOT_STAGE2_CHOOSE_AT25SF128A #define PICO_BOOT_STAGE2_CHOOSE_AT25SF128A 0 #elif PICO_BOOT_STAGE2_CHOOSE_AT25SF128A @@ -54,7 +56,7 @@ #define _BOOT_STAGE2_SELECTED #endif -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H, Select boot2_generic_03h as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=1, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H, Select boot2_generic_03h as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=1, group=boot_stage2 #if defined(PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H) && PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H #ifdef _BOOT_STAGE2_SELECTED #error multiple boot stage 2 options chosen diff --git a/src/rp2350/boot_stage2/include/boot_stage2/config.h b/src/rp2350/boot_stage2/include/boot_stage2/config.h index a73778af6..6a951a237 100644 --- a/src/rp2350/boot_stage2/include/boot_stage2/config.h +++ b/src/rp2350/boot_stage2/include/boot_stage2/config.h @@ -11,13 +11,16 @@ #include "pico.h" -// PICO_CONFIG: PICO_BUILD_BOOT_STAGE2_NAME, Name of the boot stage 2 if selected in the build system, group=boot_stage2 +// PICO_CONFIG: PICO_FLASH_SPI_CLKDIV, Clock divider from clk_sys to use for serial flash communications in boot stage 2. On RP2040 this must be a multiple of 2. This define applies to compilation of the boot stage 2 not the main application, type=int, default=varies; often specified in board header, advanced=true, group=boot_stage2 +// PICO_CONFIG: PICO_FLASH_SPI_RXDELAY, Receive delay in 1/2 clock cycles to use for serial flash communications in boot stage 2. This define applies to compilation of the boot stage 2 not the main application, type=int, default=varies; often specified in board header, advanced=true, group=boot_stage2 + +// PICO_CONFIG: PICO_BUILD_BOOT_STAGE2_NAME, Name of the boot stage 2 if selected in the build system. This define applies to compilation of the boot stage 2 not the main application, group=boot_stage2 #ifdef PICO_BUILD_BOOT_STAGE2_NAME #define _BOOT_STAGE2_SELECTED #else // check that multiple boot stage 2 options haven't been set... -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_IS25LP080, Select boot2_is25lp080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_IS25LP080, Select boot2_is25lp080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=0, group=boot_stage2 #ifndef PICO_BOOT_STAGE2_CHOOSE_IS25LP080 #define PICO_BOOT_STAGE2_CHOOSE_IS25LP080 0 #elif PICO_BOOT_STAGE2_CHOOSE_IS25LP080 @@ -26,7 +29,7 @@ #endif #define _BOOT_STAGE2_SELECTED #endif -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25Q080, Select boot2_w25q080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25Q080, Select boot2_w25q080 as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=0, group=boot_stage2 #ifndef PICO_BOOT_STAGE2_CHOOSE_W25Q080 #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 0 #elif PICO_BOOT_STAGE2_CHOOSE_W25Q080 @@ -35,7 +38,7 @@ #endif #define _BOOT_STAGE2_SELECTED #endif -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25X10CL, Select boot2_w25x10cl as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_W25X10CL, Select boot2_w25x10cl as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=0, group=boot_stage2 #ifndef PICO_BOOT_STAGE2_CHOOSE_W25X10CL #define PICO_BOOT_STAGE2_CHOOSE_W25X10CL 0 #elif PICO_BOOT_STAGE2_CHOOSE_W25X10CL @@ -44,7 +47,7 @@ #endif #define _BOOT_STAGE2_SELECTED #endif -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_AT25SF128A, Select boot2_at25sf128a as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=0, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_AT25SF128A, Select boot2_at25sf128a as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=0, group=boot_stage2 #ifndef PICO_BOOT_STAGE2_CHOOSE_AT25SF128A #define PICO_BOOT_STAGE2_CHOOSE_AT25SF128A 0 #elif PICO_BOOT_STAGE2_CHOOSE_AT25SF128A @@ -54,7 +57,7 @@ #define _BOOT_STAGE2_SELECTED #endif -// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H, Select boot2_generic_03h as the boot stage 2 when no boot stage 2 selection is made by the CMake build, type=bool, default=1, group=boot_stage2 +// PICO_CONFIG: PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H, Select boot2_generic_03h as the boot stage 2 when no boot stage 2 selection is made by the CMake build. This define applies to compilation of the boot stage 2 not the main application, type=bool, default=1, group=boot_stage2 #if defined(PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H) && PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H #ifdef _BOOT_STAGE2_SELECTED #error multiple boot stage 2 options chosen diff --git a/src/rp2_common/pico_btstack/CMakeLists.txt b/src/rp2_common/pico_btstack/CMakeLists.txt index 5fb76fcf7..0630fdb24 100644 --- a/src/rp2_common/pico_btstack/CMakeLists.txt +++ b/src/rp2_common/pico_btstack/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_BTSTACK_PATH, Path to an alternative version of btstack overriding the version in pico-sdk/lib/btstack. Can be passed to cmake or set in your environment, type=string, group=pico_btstack +# PICO_CMAKE_CONFIG: PICO_BTSTACK_PATH, Path to BTstack. Can be passed to CMake or set in your environment if you do not wish to use the version included with the SDK, type=string, default=/lib/btstack, group=pico_btstack if (DEFINED ENV{PICO_BTSTACK_PATH} AND (NOT PICO_BTSTACK_PATH)) set(PICO_BTSTACK_PATH $ENV{PICO_BTSTACK_PATH}) message("Using PICO_BTSTACK_PATH from environment ('${PICO_BTSTACK_PATH}')") diff --git a/src/rp2_common/pico_clib_interface/CMakeLists.txt b/src/rp2_common/pico_clib_interface/CMakeLists.txt index 17af8ba56..84d3faf62 100644 --- a/src/rp2_common/pico_clib_interface/CMakeLists.txt +++ b/src/rp2_common/pico_clib_interface/CMakeLists.txt @@ -35,6 +35,7 @@ if (NOT TARGET pico_clib_interface) pico_mirrored_target_link_libraries(pico_llvm_libc_interface INTERFACE pico_stdio) if (NOT PICO_CLIB) + # PICO_CMAKE_CONFIG: PICO_CLIB, The C library to use e.g. newlib/picolibc/llvm_libc, type=string, default=based on PICO_COMPILER, group=build, docref=cmake-toolchain-config set(PICO_CLIB newlib) endif() diff --git a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt index ddc5715e6..b2e25bebb 100644 --- a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt +++ b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_CYW43_DRIVER_PATH, Path to an alternative version of cyw43-driver overriding the version in pico-sdk/lib/cyw43-driver, type=string, group=pico_cyw43_driver +# PICO_CMAKE_CONFIG: PICO_CYW43_DRIVER_PATH, Path to cyw43-driver. Can be passed to CMake or set in your environment if you do not wish to use the version included with the SDK, type=string, default=/lib/cyw43-driver, group=pico_cyw43_driver if (DEFINED ENV{PICO_CYW43_DRIVER_PATH} AND (NOT PICO_CYW43_DRIVER_PATH)) set(PICO_CYW43_DRIVER_PATH $ENV{PICO_CYW43_DRIVER_PATH}) message("Using PICO_CYW43_DRIVER_PATH from environment ('${PICO_CYW43_DRIVER_PATH}')") diff --git a/src/rp2_common/pico_float/include/pico/float.h b/src/rp2_common/pico_float/include/pico/float.h index ef95e1ecd..31bea4687 100644 --- a/src/rp2_common/pico_float/include/pico/float.h +++ b/src/rp2_common/pico_float/include/pico/float.h @@ -149,6 +149,8 @@ extern "C" { * __addsf3, __subsf3, __mulsf3 * \endif */ + +// PICO_CONFIG: PICO_FLOAT_IN_RAM, Force placement of SDK provided single-precision floating point into RAM, type=bool, default=0, group=pico_float #if !defined(__riscv) || PICO_COMBINED_DOCS #if PICO_COMBINED_DOCS || !LIB_PICO_FLOAT_COMPILER diff --git a/src/rp2_common/pico_lwip/CMakeLists.txt b/src/rp2_common/pico_lwip/CMakeLists.txt index 71da00176..05910d96e 100644 --- a/src/rp2_common/pico_lwip/CMakeLists.txt +++ b/src/rp2_common/pico_lwip/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_LWIP_PATH, Path to an alternative version of lwip overriding the version in pico-sdk/lib/lwip. Can be passed to cmake or set in your environment, type=string, group=pico_lwip +# PICO_CMAKE_CONFIG: PICO_LWIP_PATH, Path to lwIP. Can be passed to CMake or set in your environment if you do not wish to use the version included with the SDK, type=string, default=/lib/lwip, group=pico_lwip if (DEFINED ENV{PICO_LWIP_PATH} AND (NOT PICO_LWIP_PATH)) set(PICO_LWIP_PATH $ENV{PICO_LWIP_PATH}) message("Using PICO_LWIP_PATH from environment ('${PICO_LWIP_PATH}')") diff --git a/src/rp2_common/pico_mbedtls/CMakeLists.txt b/src/rp2_common/pico_mbedtls/CMakeLists.txt index 608b457ea..754e734b0 100644 --- a/src/rp2_common/pico_mbedtls/CMakeLists.txt +++ b/src/rp2_common/pico_mbedtls/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_MBEDTLS_PATH, Path to an alternative version of mbedtls overriding the version in pico-sdk/lib/mbedtls. Can be passed to cmake or set in your environment, type=string, group=pico_mbedtls +# PICO_CMAKE_CONFIG: PICO_MBEDTLS_PATH, Path to Mbed TLS. Can be passed to CMake or set in your environment if you do not wish to use the version included with the SDK, type=string, default=/lib/mbedtls, group=pico_mbedtls if (DEFINED ENV{PICO_MBEDTLS_PATH} AND (NOT PICO_MBEDTLS_PATH)) set(PICO_MBEDTLS_PATH $ENV{PICO_MBEDTLS_PATH}) message("Using PICO_MBEDTLS_PATH from environment ('${PICO_MBEDTLS_PATH}')") diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index 9e6575a30..5cf2e1f66 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -138,7 +138,7 @@ #define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 #endif -// PICO_CONFIG: PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS, Defines the default USB descriptors needed for USB communication, type=bool, default=1 if the application is not using tinyUSB directly, group=pico_stdio_usb +// PICO_CONFIG: PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS, Whether `pico_stdio_usb` provides the USB descriptors needed for USB communication, type=bool, default=1 if the application is not using tinyUSB directly, group=pico_stdio_usb #ifndef PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS #if !LIB_TINYUSB_HOST && !LIB_TINYUSB_DEVICE #define PICO_STDIO_USB_USE_DEFAULT_DESCRIPTORS 1 diff --git a/src/rp2_common/tinyusb/CMakeLists.txt b/src/rp2_common/tinyusb/CMakeLists.txt index e4115f896..c9e37e2e5 100644 --- a/src/rp2_common/tinyusb/CMakeLists.txt +++ b/src/rp2_common/tinyusb/CMakeLists.txt @@ -1,4 +1,4 @@ -# PICO_CMAKE_CONFIG: PICO_TINYUSB_PATH, Path to an alternative version of tinyusb overriding the version in pico-sdk/lib/tinyusb. Can be passed to cmake or set in your environment, type=string, group=tinyusb_device +# PICO_CMAKE_CONFIG: PICO_TINYUSB_PATH, Path to TinyUSB. Can be passed to CMake or set in your environment if you do not wish to use the version included with the SDK, type=string, default=/lib/tinyusb, group=tinyusb_device if (DEFINED ENV{PICO_TINYUSB_PATH} AND (NOT PICO_TINYUSB_PATH)) set(PICO_TINYUSB_PATH $ENV{PICO_TINYUSB_PATH}) message("Using PICO_TINYUSB_PATH from environment ('${PICO_TINYUSB_PATH}')") diff --git a/tools/extract_build_defines.py b/tools/extract_build_defines.py index 9f0de4eeb..d80ab3670 100755 --- a/tools/extract_build_defines.py +++ b/tools/extract_build_defines.py @@ -162,7 +162,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): # allow commas to appear inside brackets by converting them to and from NULL chars _attrs = re.sub(r'(\(.+\))', lambda m: m.group(1).replace(',', '\0'), _attrs) - if '=' in config_description: + if '=' in config_description and not '==' in config_description: errors.append(Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description))) all_descriptions = chips_all_descriptions[applicable] if config_description in all_descriptions: diff --git a/tools/extract_cmake_configs.py b/tools/extract_cmake_configs.py index f09a191f4..bf8652720 100755 --- a/tools/extract_cmake_configs.py +++ b/tools/extract_cmake_configs.py @@ -44,7 +44,7 @@ def __init__(self, message, errors): BASE_BUILD_DEFINE_NAME = 'PICO_BUILD_DEFINE' BASE_BUILD_DEFINE_RE = re.compile(r'\b{}\b'.format(BASE_BUILD_DEFINE_NAME)) -CMAKE_CONFIG_RE = re.compile(r'#\s+{}:\s+(\w+),\s+([^,]+)(?:,\s+(.*))?$'.format(BASE_CMAKE_CONFIG_NAME)) +CMAKE_CONFIG_RE = re.compile(r'#\s+{}:\s+([\w-]+),\s+([^,]+)(?:,\s+(.*))?$'.format(BASE_CMAKE_CONFIG_NAME)) PROPERTY_TYPE = 'type' PROPERTY_DEFAULT = 'default' @@ -165,7 +165,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum): # allow commas to appear inside brackets by converting them to and from NULL chars _attrs = re.sub(r'(\(.+\))', lambda m: m.group(1).replace(',', '\0'), _attrs) - if '=' in config_description: + if '=' in config_description and not '==' in config_description: errors.append(Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description))) all_descriptions = chips_all_descriptions[applicable] if config_description in all_descriptions: diff --git a/tools/extract_configs.py b/tools/extract_configs.py index f1b4a92d5..a6bb836db 100755 --- a/tools/extract_configs.py +++ b/tools/extract_configs.py @@ -211,7 +211,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum, applicable): # allow commas to appear inside brackets by converting them to and from NULL chars _attrs = re.sub(r'(\(.+\))', lambda m: m.group(1).replace(',', '\0'), _attrs) - if '=' in config_description: + if '=' in config_description and not '==' in config_description: errors.append(Exception("For {} at {}:{} the description was set to '{}' - has the description field been omitted?".format(config_name, file_path, linenum, config_description))) all_descriptions = chips_all_descriptions[applicable] if config_description in all_descriptions: From bb66fdfac0ea9623dd00fc72afcfd7f6bd42aa34 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 25 Jul 2025 09:45:30 -0500 Subject: [PATCH 213/224] pico_encode_gpio_wait doc improvement (#2579) --- .../hardware_pio/include/hardware/pio_instructions.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 edb0ef31a..e990a7284 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio_instructions.h @@ -18,10 +18,6 @@ * 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 @@ -271,8 +267,12 @@ static inline uint _pio_encode_irq(bool relative, uint irq) { * * This is the equivalent of `WAIT GPIO ` * + * \note gpio here refers to the raw instruction encoding, which only supports 32 GPIOs. So, if you had a PIO + * program with `WAIT GPIO 42` and a GPIO_BASE (see \ref pio_set_gpio_base) of 16, then you'd want to do + * `pio_encode_wait_gpio(polarity, 42-16)` assuming you are using this function to craft instructions for \ref pio_sm_exec. + * * \param polarity true for `WAIT 1`, false for `WAIT 0` - * \param gpio The real GPIO number 0-31 + * \param gpio The GPIO number 0-31 relative to the state machine's GPIO_BASE (see \ref pio_set_gpio_base) * \return The instruction encoding with 0 delay and no side set value * \see pio_encode_delay, pio_encode_sideset, pio_encode_sideset_opt */ From 9227cadf84ac114ff661ed9dabbf838480939666 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Mon, 28 Jul 2025 17:56:15 +0100 Subject: [PATCH 214/224] add pico_status_led (#2501) Co-authored-by: graham sanderson --- docs/index.h | 1 + src/cmake/rp2_common.cmake | 1 + .../pico_cyw43_driver/CMakeLists.txt | 2 +- .../pico_cyw43_driver/cyw43_driver.c | 12 +- .../include/cyw43_configport.h | 5 + src/rp2_common/pico_lwip/lwip_freertos.c | 4 +- src/rp2_common/pico_status_led/BUILD.bazel | 28 ++ src/rp2_common/pico_status_led/CMakeLists.txt | 22 ++ .../pico_status_led/include/pico/status_led.h | 250 ++++++++++++++++++ src/rp2_common/pico_status_led/status_led.c | 176 ++++++++++++ src/rp2_common/pico_status_led/ws2812.pio | 53 ++++ test/kitchen_sink/CMakeLists.txt | 1 + 12 files changed, 546 insertions(+), 9 deletions(-) create mode 100644 src/rp2_common/pico_status_led/BUILD.bazel create mode 100644 src/rp2_common/pico_status_led/CMakeLists.txt create mode 100644 src/rp2_common/pico_status_led/include/pico/status_led.h create mode 100644 src/rp2_common/pico_status_led/status_led.c create mode 100644 src/rp2_common/pico_status_led/ws2812.pio diff --git a/docs/index.h b/docs/index.h index 5506b3a34..572d94c70 100644 --- a/docs/index.h +++ b/docs/index.h @@ -64,6 +64,7 @@ * \cond pico_multicore \defgroup pico_multicore pico_multicore \endcond * \cond pico_rand \defgroup pico_rand pico_rand \endcond * \cond pico_sha256 \defgroup pico_sha256 pico_sha256 \endcond + * \cond pico_status_led \defgroup pico_status_led pico_status_led \endcond * \cond pico_stdlib \defgroup pico_stdlib pico_stdlib \endcond * \cond pico_sync \defgroup pico_sync pico_sync \endcond * \cond pico_time \defgroup pico_time pico_time \endcond diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index d94d21f32..273839f70 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -140,6 +140,7 @@ if (NOT PICO_BARE_METAL) pico_add_subdirectory(rp2_common/pico_standard_link) pico_add_subdirectory(rp2_common/pico_fix) + pico_add_subdirectory(rp2_common/pico_status_led) # at the end as it includes a lot of other stuff pico_add_subdirectory(rp2_common/pico_runtime_init) diff --git a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt index b2e25bebb..9af8a1885 100644 --- a/src/rp2_common/pico_cyw43_driver/CMakeLists.txt +++ b/src/rp2_common/pico_cyw43_driver/CMakeLists.txt @@ -41,7 +41,7 @@ if (EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE}) target_sources(pico_cyw43_driver INTERFACE cyw43_driver.c) target_include_directories(pico_cyw43_driver_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) - pico_mirrored_target_link_libraries(pico_cyw43_driver INTERFACE cyw43_driver) + pico_mirrored_target_link_libraries(pico_cyw43_driver INTERFACE cyw43_driver pico_unique_id) # cyw43_driver_picow is cyw43_driver plus Pico W specific bus implementation pico_add_library(cyw43_driver_picow NOFLAG) diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c index 384062fc1..95e5da5e3 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_driver.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_driver.c @@ -275,20 +275,20 @@ void cyw43_delay_us(uint32_t us) { } #if !CYW43_LWIP -static void no_lwip_fail() { +static void no_lwip_fail(void) { panic("cyw43 has no ethernet interface"); } -void __attribute__((weak)) cyw43_cb_tcpip_init(cyw43_t *self, int itf) { +void __attribute__((weak)) cyw43_cb_tcpip_init(__unused cyw43_t *self, __unused int itf) { } -void __attribute__((weak)) cyw43_cb_tcpip_deinit(cyw43_t *self, int itf) { +void __attribute__((weak)) cyw43_cb_tcpip_deinit(__unused cyw43_t *self, __unused int itf) { } -void __attribute__((weak)) cyw43_cb_tcpip_set_link_up(cyw43_t *self, int itf) { +void __attribute__((weak)) cyw43_cb_tcpip_set_link_up(__unused cyw43_t *self, __unused int itf) { no_lwip_fail(); } -void __attribute__((weak)) cyw43_cb_tcpip_set_link_down(cyw43_t *self, int itf) { +void __attribute__((weak)) cyw43_cb_tcpip_set_link_down(__unused cyw43_t *self, __unused int itf) { no_lwip_fail(); } -void __attribute__((weak)) cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t *buf) { +void __attribute__((weak)) cyw43_cb_process_ethernet(__unused void *cb_data, __unused int itf, __unused size_t len, __unused const uint8_t *buf) { no_lwip_fail(); } #endif diff --git a/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h b/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h index 59b7d240e..b634d6472 100644 --- a/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h +++ b/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h @@ -211,6 +211,11 @@ void cyw43_post_poll_hook(void); #define CYW43_PRINTF(...) (void)0 #endif +// PICO_CONFIG: CYW43_LWIP_DEFAULT, Sets the default value of CYW43_LWIP if it's undefined. CYW43_LWIP defines if cyw43-driver uses LwIP. The default behavior - if it's not defined anywhere - is to set it to 1 and cyw43-driver will use lwIP requiring you to provide an lwipopts.h header file. You can set CYW43_LWIP_DEFAULT to change the default to 0 and avoid using lwIP if CYW43_LWIP is undefined, type=bool, group=pico_cyw43_driver +#if !defined CYW43_LWIP && defined CYW43_LWIP_DEFAULT +#define CYW43_LWIP CYW43_LWIP_DEFAULT +#endif + #ifdef __cplusplus } #endif diff --git a/src/rp2_common/pico_lwip/lwip_freertos.c b/src/rp2_common/pico_lwip/lwip_freertos.c index 7d28d9716..b0ab3edd1 100644 --- a/src/rp2_common/pico_lwip/lwip_freertos.c +++ b/src/rp2_common/pico_lwip/lwip_freertos.c @@ -25,10 +25,10 @@ static void tcpip_init_done(void *param) { } bool lwip_freertos_init(async_context_t *context) { - assert(!lwip_context); - lwip_context = context; + assert(!lwip_context || lwip_context == context); static bool done_lwip_init; if (!done_lwip_init) { + lwip_context = context; done_lwip_init = true; SemaphoreHandle_t init_sem = xSemaphoreCreateBinary(); tcpip_task_blocker = xSemaphoreCreateBinary(); diff --git a/src/rp2_common/pico_status_led/BUILD.bazel b/src/rp2_common/pico_status_led/BUILD.bazel new file mode 100644 index 000000000..6b618de41 --- /dev/null +++ b/src/rp2_common/pico_status_led/BUILD.bazel @@ -0,0 +1,28 @@ +load("//bazel:defs.bzl", "compatible_with_rp2", "pico_generate_pio_header") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_status_led", + srcs = ["status_led.c"], + hdrs = ["include/pico/status_led.h"], + includes = ["include"], + target_compatible_with = compatible_with_rp2(), + deps = [ + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/hardware_pio", + ] + select({ + "//bazel/constraint:is_pico_w": [ + "//src/rp2_common/pico_cyw43_driver", + ], + "//bazel/constraint:is_pico2_w": [ + "//src/rp2_common/pico_cyw43_driver" + ], + "//conditions:default": [], + }), +) + +pico_generate_pio_header( + name = "ws2812", + srcs = ["ws2812.pio"], +) diff --git a/src/rp2_common/pico_status_led/CMakeLists.txt b/src/rp2_common/pico_status_led/CMakeLists.txt new file mode 100644 index 000000000..c14e607bf --- /dev/null +++ b/src/rp2_common/pico_status_led/CMakeLists.txt @@ -0,0 +1,22 @@ +pico_add_library(pico_status_led) +target_sources(pico_status_led INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/status_led.c +) +target_include_directories(pico_status_led_headers SYSTEM INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/include +) +pico_mirrored_target_link_libraries(pico_status_led INTERFACE + hardware_gpio + hardware_pio +) +if (PICO_CYW43_SUPPORTED) + pico_mirrored_target_link_libraries(pico_status_led INTERFACE + pico_cyw43_driver cyw43_driver_picow pico_async_context_threadsafe_background + ) + target_compile_definitions(pico_status_led INTERFACE + CYW43_LWIP_DEFAULT=0 # Disable LwIP by default. Can be overridden if LwIP is needed. + ) +endif() +pico_generate_pio_header(pico_status_led ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio) + +get_target_property(OUT pico_status_led LINK_LIBRARIES) diff --git a/src/rp2_common/pico_status_led/include/pico/status_led.h b/src/rp2_common/pico_status_led/include/pico/status_led.h new file mode 100644 index 000000000..4b900d2bd --- /dev/null +++ b/src/rp2_common/pico_status_led/include/pico/status_led.h @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** \file pico/status_led.h + * \defgroup pico_status_led pico_status_led + * + * \brief Enables access to the on-board status LED(s) + * + * Boards usually have access to an on-board status LEDs which are configured via the board header (\see PICO_DEFAULT_LED_PIN and \see PICO_DEFAULT_WS2812_PIN) + * This library hides the details so you can use the status LEDs for all boards without changing your code. + */ + +#ifndef _PICO_STATUS_LED_H +#define _PICO_STATUS_LED_H + +#include "hardware/gpio.h" + +#if defined(CYW43_WL_GPIO_LED_PIN) +#include "cyw43.h" +#endif + +struct async_context; + +#ifdef __cplusplus +extern "C" { +#endif + +// PICO_CONFIG: PICO_STATUS_LED_AVAILABLE, Indicate whether a non-colored status LED is available, type=bool, default=1 if PICO_DEFAULT_LED_PIN or CYW43_WL_GPIO_LED_PIN is defined; may be set by the user to 0 to not use either even if they are available, group=pico_status_led +#ifndef PICO_STATUS_LED_AVAILABLE +#if defined(PICO_DEFAULT_LED_PIN) || defined(CYW43_WL_GPIO_LED_PIN) +#define PICO_STATUS_LED_AVAILABLE 1 +#else +#define PICO_STATUS_LED_AVAILABLE 0 +#endif +#endif + +// PICO_CONFIG: PICO_COLORED_STATUS_LED_AVAILABLE, Indicate whether a colored status LED is available, type=bool, default=1 if PICO_DEFAULT_WS2812_PIN is defined; may be set by the user to 0 to not use the colored status LED even if available, group=pico_status_led +#ifndef PICO_COLORED_STATUS_LED_AVAILABLE +#ifdef PICO_DEFAULT_WS2812_PIN +#define PICO_COLORED_STATUS_LED_AVAILABLE 1 +#else +#define PICO_COLORED_STATUS_LED_AVAILABLE 0 +#endif +#endif + +// PICO_CONFIG: PICO_STATUS_LED_VIA_COLORED_STATUS_LED, Indicate if the colored status LED should be used for both status_led and colored_status_led APIs, type=bool, default=1 if PICO_COLORED_STATUS_LED_AVAILABLE is 1 and PICO_STATUS_LED_AVAILABLE is 0, group=pico_status_led +#ifndef PICO_STATUS_LED_VIA_COLORED_STATUS_LED +#define PICO_STATUS_LED_VIA_COLORED_STATUS_LED (PICO_COLORED_STATUS_LED_AVAILABLE && !PICO_STATUS_LED_AVAILABLE) +#endif + +// PICO_CONFIG: PICO_COLORED_STATUS_LED_USES_WRGB, Indicate if the colored status LED supports WRGB, type=bool, default=0, group=pico_status_led +#ifndef PICO_COLORED_STATUS_LED_USES_WRGB +#define PICO_COLORED_STATUS_LED_USES_WRGB 0 +#endif + +/*! \brief Generate an RGB color value for /ref colored_status_led_set_on_with_color + * \ingroup pico_status_led + */ +#ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_RGB +#define PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(r, g, b) (((r) << 16) | ((g) << 8) | (b)) +#endif + +/*! \brief Generate an WRGB color value for \ref colored_status_led_set_on_with_color + * \ingroup pico_status_led + * + * \note: If your hardware does not support a white pixel, the white component is ignored + */ +#ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB +#define PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(w, r, g, b) (((w) << 24) | ((r) << 16) | ((g) << 8) | (b)) +#endif + +// PICO_CONFIG: PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR, the default pixel color value of the colored status LED when it is on, type=int, group=pico_status_led +#ifndef PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR +#if PICO_COLORED_STATUS_LED_USES_WRGB +#define PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(0xaa, 0, 0, 0) +#else +#define PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(0xaa, 0xaa, 0xaa) +#endif +#endif + +/*! \brief Initialize the status LED(s) + * \ingroup pico_status_led + * + * Initialize the status LED(s) and the resources they need before use. On some devices (e.g. Pico W, Pico 2 W) accessing + * the status LED requires talking to the WiFi chip, which requires an \ref async_context. + * This method will create an async_context for you. + * + * However an application should only use a single \ref async_context instance to talk to the WiFi chip. + * If the application already has an async context (e.g. created by cyw43_arch_init) you should use \ref + * status_led_init_with_context instead and pass it the \ref async_context already created by your application + * + * \note: You must call this function (or \ref status_led_init_with_context) before using any other pico_status_led functions. + * + * \return Returns true if the LED was initialized successfully, otherwise false on failure + * \sa status_led_init_with_context + */ +bool status_led_init(void); + +/*! \brief Initialise the status LED(s) + * \ingroup pico_status_led + * + * Initialize the status LED(s) and the resources they need before use. + * + * \note: You must call this function (or \ref status_led_init) before using any other pico_status_led functions. + * + * \param context An \ref async_context used to communicate with the status LED (e.g. on Pico W or Pico 2 W) + * \return Returns true if the LED was initialized successfully, otherwise false on failure + * \sa status_led_init_with_context + */ +bool status_led_init_with_context(struct async_context *context); + +/*! \brief Determine if the `colored_status_led_` APIs are supported (i.e. if there is a colored status LED, and its + * use isn't disabled via \ref PICO_COLORED_STATUS_LED_AVAILABLE being set to 0 + * \ingroup pico_status_led + * \return true if the colored status LED API is available and expected to produce visible results + * \sa PICO_COLORED_STATUS_LED_AVAILABLE + */ +static inline bool colored_status_led_supported(void) { + return PICO_COLORED_STATUS_LED_AVAILABLE; +} + +/*! \brief Determine if the colored status LED is being used for the non-colored `status_led_` APIs + * \ingroup pico_status_led + * \return true if the olored status LED is being used for the non-colored `status_led_` API + * \sa PICO_STATUS_LED_VIA_COLORED_STATUS_LED + */ +static inline bool status_led_via_colored_status_led(void) { + return PICO_STATUS_LED_VIA_COLORED_STATUS_LED; +} + +/*! \brief Determine if the non-colored `status_led_` APIs are supported (i.e. if there is a regular LED, and its + * use isn't disabled via \ref PICO_STATUS_LED_AVAILABLE being set to 0, or if the colored status LED is being used for + * \ingroup pico_status_led + * \return true if the non-colored status LED API is available and expected to produce visible results + * \sa PICO_STATUS_LED_AVAILABLE + * \sa PICO_STATUS_LED_VIA_COLORED_STATUS_LED + */ +static inline bool status_led_supported(void) { + if (status_led_via_colored_status_led()) { + return colored_status_led_supported(); + } + return PICO_STATUS_LED_AVAILABLE; +} + +/*! \brief Set the colored status LED on or off + * \ingroup pico_status_led + * + * \note: If your hardware does not support a colored status LED (\see PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false. + * + * \param led_on true to turn the colored LED on. Pass false to turn the colored LED off + * \return true if the colored status LED could be set, otherwise false + */ +bool colored_status_led_set_state(bool led_on); + +/*! \brief Get the state of the colored status LED + * \ingroup pico_status_led + * + * \note: If your hardware does not support a colored status LED (\see PICO_DEFAULT_WS2812_PIN), this function returns false. + * + * \return true if the colored status LED is on, or false if the colored status LED is off + */ +bool colored_status_led_get_state(void); + +/*! \brief Ensure the colored status LED is on, with the specified color + * \ingroup pico_status_led + * + * \note: If your hardware does not support a colored status LED (\see PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false. + * + * \param color The color to use for the colored status LED when it is on, in 0xWWRRGGBB format + * \return true if the coloured status LED could be set, otherwise false on failure + */ +bool colored_status_led_set_on_with_color(uint32_t color); + +/*! \brief Get the color used for the status LED value when it is on + * \ingroup pico_status_led + * + * \note: If your hardware does not support a colored status LED (\see PICO_DEFAULT_WS2812_PIN), this function always returns 0x0. + * +* \return The color used for the colored status LED when it is on, in 0xWWRRGGBB format +*/ +uint32_t colored_status_led_get_on_color(void); + +/*! \brief Set the status LED on or off +* \ingroup pico_status_led +* +* \note: If your hardware does not support a status LED (\see PICO_DEFAULT_LED_PIN), this function does nothing and returns false. +* +* \param led_on true to turn the LED on. Pass false to turn the LED off +* \return true if the status LED could be set, otherwise false +*/ +static inline bool status_led_set_state(bool led_on) { + if (status_led_via_colored_status_led()) { + return colored_status_led_set_state(led_on); + } else if (status_led_supported()) { +#if defined(PICO_DEFAULT_LED_PIN) + #if PICO_DEFAULT_LED_PIN_INVERTED + gpio_put(PICO_DEFAULT_LED_PIN, !led_on); + #else + gpio_put(PICO_DEFAULT_LED_PIN, led_on); + #endif + return true; +#elif defined(CYW43_WL_GPIO_LED_PIN) + cyw43_gpio_set(&cyw43_state, CYW43_WL_GPIO_LED_PIN, led_on); + return true; +#endif + } + return false; +} + +/*! \brief Get the state of the status LED + * \ingroup pico_status_led + * + * \note: If your hardware does not support a status LED (\see PICO_DEFAULT_LED_PIN), this function always returns false. + * + * \return true if the status LED is on, or false if the status LED is off + */ +static inline bool status_led_get_state() { + if (status_led_via_colored_status_led()) { + return colored_status_led_get_state(); + } else if (status_led_supported()) { +#if defined(PICO_DEFAULT_LED_PIN) + #if PICO_DEFAULT_LED_PIN_INVERTED + return !gpio_get(PICO_DEFAULT_LED_PIN); + #else + return gpio_get(PICO_DEFAULT_LED_PIN); + #endif +#elif defined CYW43_WL_GPIO_LED_PIN + bool value = false; + cyw43_gpio_get(&cyw43_state, CYW43_WL_GPIO_LED_PIN, &value); + return value; +#endif + } + return false; +} + +/*! \brief De-initialize the status LED(s) + * \ingroup pico_status_led + * + * De-initializes the status LED(s) when they are no longer needed. + */ +void status_led_deinit(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/rp2_common/pico_status_led/status_led.c b/src/rp2_common/pico_status_led/status_led.c new file mode 100644 index 000000000..4c7134aaf --- /dev/null +++ b/src/rp2_common/pico_status_led/status_led.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico/status_led.h" + +#if PICO_STATUS_LED_AVAILABLE && defined(CYW43_WL_GPIO_LED_PIN) && !defined(PICO_DEFAULT_LED_PIN) +#define STATUS_LED_USING_WL_GPIO 1 +#else +#define STATUS_LED_USING_WL_GPIO 0 +#endif + +#if PICO_STATUS_LED_AVAILABLE && defined(PICO_DEFAULT_LED_PIN) && !STATUS_LED_USING_WL_GPIO +#define STATUS_LED_USING_GPIO 1 +#else +#define STATUS_LED_USING_GPIO 0 +#endif + +#if PICO_COLORED_STATUS_LED_AVAILABLE && defined(PICO_DEFAULT_WS2812_PIN) +#define COLORED_STATUS_LED_USING_WS2812_PIO 1 +#else +#define COLORED_STATUS_LED_USING_WS2812_PIO 0 +#endif + +#if STATUS_LED_USING_WL_GPIO +#include "pico/cyw43_driver.h" +#include "pico/async_context_threadsafe_background.h" +#endif + +static uint32_t colored_status_led_on_color = PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR; +static bool colored_status_led_on; + +#if COLORED_STATUS_LED_USING_WS2812_PIO +#include +#include "ws2812.pio.h" + +// PICO_CONFIG: PICO_COLORED_STATUS_LED_WS2812_FREQ, Frequency per bit for the WS2812 colored status LED, type=int, default=800000, group=pico_status_led +#ifndef PICO_COLORED_STATUS_LED_WS2812_FREQ +#define PICO_COLORED_STATUS_LED_WS2812_FREQ 800000 +#endif + +static PIO pio; +static uint sm; +static int offset = -1; + +// Extract from 0xWWRRGGBB +#define RED(c) (((c) >> 16) & 0xff) +#define GREEN(c) (((c) >> 8) & 0xff) +#define BLUE(c) (((c) >> 0) & 0xff) +#define WHITE(c) (((c) >> 24) && 0xff) + +bool set_ws2812(uint32_t value) { + if (offset > -1) { +#if PICO_COLORED_STATUS_LED_USES_WRGB + // Convert to 0xWWGGRRBB + pio_sm_put_blocking(pio, sm, WHITE(value) << 24 | GREEN(value) << 16 | RED(value) << 8 | BLUE(value)); +#else + // Convert to 0xGGRRBB00 + pio_sm_put_blocking(pio, sm, GREEN(value) << 24 | RED(value) << 16 | BLUE(value) << 8); +#endif + return true; + } + return false; +} +#endif + +bool colored_status_led_set_on_with_color(uint32_t color) { + colored_status_led_on_color = color; + return colored_status_led_set_state(true); +} + +uint32_t colored_status_led_get_on_color(void) { + return colored_status_led_on_color; +} + +bool colored_status_led_set_state(bool led_on) { + bool success = false; + if (colored_status_led_supported()) { +#if COLORED_STATUS_LED_USING_WS2812_PIO + success = true; + if (led_on && !colored_status_led_on) { + success = set_ws2812(colored_status_led_on_color); + } else if (!led_on && colored_status_led_on) { + success = set_ws2812(0); + } +#endif + } + if (success) colored_status_led_on = led_on; + return success; +} + +bool colored_status_led_get_state(void) { + return colored_status_led_on; +} + +#if STATUS_LED_USING_WL_GPIO +static async_context_threadsafe_background_t status_led_owned_context; +static struct async_context *status_led_context; +#endif + +static bool status_led_init_internal(__unused struct async_context *context) { + bool success = false; + // ---- regular status LED ---- +#if STATUS_LED_USING_GPIO + gpio_init(PICO_DEFAULT_LED_PIN); + gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); + success = true; +#elif STATUS_LED_USING_WL_GPIO + assert(!status_led_context); + if (!context) { + // for CYW43 init, we defer to the context method for the real work + async_context_threadsafe_background_config_t config = async_context_threadsafe_background_default_config(); + if (async_context_threadsafe_background_init(&status_led_owned_context, &config)) { + if (cyw43_driver_init(&status_led_owned_context.core)) { + context = &status_led_owned_context.core; + } else { + async_context_deinit(&status_led_owned_context.core); + return false; + } + } + } + status_led_context = context; + success = true; +#endif + + // ---- colored status LED ---- +#if COLORED_STATUS_LED_USING_WS2812_PIO + if (pio_claim_free_sm_and_add_program_for_gpio_range(&ws2812_program, &pio, &sm, &offset, PICO_DEFAULT_WS2812_PIN, 1, true)) { + ws2812_program_init(pio, sm, offset, PICO_DEFAULT_WS2812_PIN, PICO_COLORED_STATUS_LED_WS2812_FREQ, PICO_COLORED_STATUS_LED_USES_WRGB); + } else { + status_led_deinit(); + return false; + } +#ifdef PICO_DEFAULT_WS2812_POWER_PIN + gpio_init(PICO_DEFAULT_WS2812_POWER_PIN); + gpio_set_dir(PICO_DEFAULT_WS2812_POWER_PIN, GPIO_OUT); + gpio_put(PICO_DEFAULT_WS2812_POWER_PIN, true); +#endif + success = true; +#endif + return success; +} + +bool status_led_init(void) { + return status_led_init_internal(NULL); +} + +bool status_led_init_with_context(struct async_context *context) { + assert(context); + return status_led_init_internal(context); +} + +void status_led_deinit(void) { +#if STATUS_LED_USING_GPIO + gpio_deinit(PICO_DEFAULT_LED_PIN); +#elif STATUS_LED_USING_WL_GPIO + // Note: We only deinit if we created it + if (status_led_context == &status_led_owned_context.core) { + cyw43_driver_deinit(status_led_context); + async_context_deinit(status_led_context); + } + status_led_context = NULL; +#endif +#if COLORED_STATUS_LED_USING_WS2812_PIO + if (offset >= 0) { + pio_remove_program_and_unclaim_sm(&ws2812_program, pio, sm, offset); + offset = -1; + } +#ifdef PICO_DEFAULT_WS2812_POWER_PIN + gpio_put(PICO_DEFAULT_WS2812_POWER_PIN, false); + gpio_deinit(PICO_DEFAULT_WS2812_POWER_PIN); +#endif +#endif +} diff --git a/src/rp2_common/pico_status_led/ws2812.pio b/src/rp2_common/pico_status_led/ws2812.pio new file mode 100644 index 000000000..a294f373c --- /dev/null +++ b/src/rp2_common/pico_status_led/ws2812.pio @@ -0,0 +1,53 @@ +; +; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. +; +; SPDX-License-Identifier: BSD-3-Clause +; +.pio_version 0 // only requires PIO version 0 + +.program ws2812 +.side_set 1 + +; The following constants are selected for broad compatibility with WS2812, +; WS2812B, and SK6812 LEDs. Other constants may support higher bandwidths for +; specific LEDs, such as (7,10,8) for WS2812B LEDs. + +.define public T1 3 +.define public T2 3 +.define public T3 4 + +.lang_opt python sideset_init = pico.PIO.OUT_HIGH +.lang_opt python out_init = pico.PIO.OUT_HIGH +.lang_opt python out_shiftdir = 1 + +.wrap_target +bitloop: + out x, 1 side 0 [T3 - 1] ; Side-set still takes place when instruction stalls + jmp !x do_zero side 1 [T1 - 1] ; Branch on the bit we shifted out. Positive pulse +do_one: + jmp bitloop side 1 [T2 - 1] ; Continue driving high, for a long pulse +do_zero: + nop side 0 [T2 - 1] ; Or drive low, for a short pulse +.wrap + +% c-sdk { +#include "hardware/clocks.h" + +static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, float freq, bool rgbw) { + + pio_gpio_init(pio, pin); + pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); + + pio_sm_config c = ws2812_program_get_default_config(offset); + sm_config_set_sideset_pins(&c, pin); + sm_config_set_out_shift(&c, false, true, rgbw ? 32 : 24); + sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); + + int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3; + float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit); + sm_config_set_clkdiv(&c, div); + + pio_sm_init(pio, sm, offset, &c); + pio_sm_set_enabled(pio, sm, true); +} +%} diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index c2c88d9b3..1d6110f4c 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -55,6 +55,7 @@ set(KITCHEN_SINK_LIBS pico_runtime pico_runtime_init pico_sha256 + pico_status_led pico_stdio pico_stdlib pico_sync From 4635b37e68d0078f2311ee86cd384973472596cd Mon Sep 17 00:00:00 2001 From: el-bert0 Date: Mon, 28 Jul 2025 18:56:56 +0200 Subject: [PATCH 215/224] Enable hardware_irq library also in host and not only in rp2_common (#2596) --- src/host.cmake | 2 ++ src/host/hardware_irq/include/hardware/irq.h | 3 ++- src/host/pico_platform/include/hardware/platform_defs.h | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/host.cmake b/src/host.cmake index 3399866f7..8834815b2 100644 --- a/src/host.cmake +++ b/src/host.cmake @@ -9,6 +9,7 @@ include (${CMAKE_DIR}/no_hardware.cmake) pico_add_subdirectory(${COMMON_DIR}/boot_picobin_headers) pico_add_subdirectory(${COMMON_DIR}/boot_picoboot_headers) pico_add_subdirectory(${COMMON_DIR}/boot_uf2_headers) + pico_add_subdirectory(${COMMON_DIR}/hardware_claim) pico_add_subdirectory(${COMMON_DIR}/pico_base_headers) pico_add_subdirectory(${COMMON_DIR}/pico_usb_reset_interface_headers) pico_add_subdirectory(${COMMON_DIR}/pico_bit_ops_headers) @@ -22,6 +23,7 @@ include (${CMAKE_DIR}/no_hardware.cmake) # host-specific pico_add_subdirectory(${HOST_DIR}/hardware_divider) pico_add_subdirectory(${HOST_DIR}/hardware_gpio) + pico_add_subdirectory(${HOST_DIR}/hardware_irq) pico_add_subdirectory(${HOST_DIR}/hardware_sync) pico_add_subdirectory(${HOST_DIR}/hardware_timer) pico_add_subdirectory(${HOST_DIR}/hardware_uart) diff --git a/src/host/hardware_irq/include/hardware/irq.h b/src/host/hardware_irq/include/hardware/irq.h index ef90ee703..04f7335b2 100644 --- a/src/host/hardware_irq/include/hardware/irq.h +++ b/src/host/hardware_irq/include/hardware/irq.h @@ -24,7 +24,8 @@ #endif #include "pico.h" -#include "hardware/regs/intctrl.h" +// TODO: No hardware/regs/intctrl.h for host yet. +// #include "hardware/regs/intctrl.h" /** \file irq.h * \defgroup hardware_irq hardware_irq diff --git a/src/host/pico_platform/include/hardware/platform_defs.h b/src/host/pico_platform/include/hardware/platform_defs.h index 924336a92..c1a6f5f44 100644 --- a/src/host/pico_platform/include/hardware/platform_defs.h +++ b/src/host/pico_platform/include/hardware/platform_defs.h @@ -15,6 +15,9 @@ #define NUM_ALARMS 4u #define NUM_IRQS 32u +#define NUM_USER_IRQS 6u +#define FIRST_USER_IRQ (NUM_IRQS - NUM_USER_IRQS) +#define VTABLE_FIRST_IRQ 16 #define NUM_SPIN_LOCKS 32u From 3f6f0fc0efb0940323294deb56e2be1a0361c895 Mon Sep 17 00:00:00 2001 From: el-bert0 Date: Mon, 28 Jul 2025 19:00:41 +0200 Subject: [PATCH 216/224] pico_rand (#2598) --- src/host.cmake | 1 + src/host/pico_rand/BUILD.bazel | 13 ++ src/host/pico_rand/CMakeLists.txt | 12 ++ src/host/pico_rand/include/pico/rand.h | 89 ++++++++++++++ src/host/pico_rand/rand.c | 161 +++++++++++++++++++++++++ 5 files changed, 276 insertions(+) create mode 100644 src/host/pico_rand/BUILD.bazel create mode 100644 src/host/pico_rand/CMakeLists.txt create mode 100644 src/host/pico_rand/include/pico/rand.h create mode 100644 src/host/pico_rand/rand.c diff --git a/src/host.cmake b/src/host.cmake index 8834815b2..46e575627 100644 --- a/src/host.cmake +++ b/src/host.cmake @@ -31,6 +31,7 @@ include (${CMAKE_DIR}/no_hardware.cmake) pico_add_subdirectory(${HOST_DIR}/pico_divider) pico_add_subdirectory(${HOST_DIR}/pico_multicore) pico_add_subdirectory(${HOST_DIR}/pico_platform) + pico_add_subdirectory(${HOST_DIR}/pico_rand) pico_add_subdirectory(${HOST_DIR}/pico_runtime) pico_add_subdirectory(${HOST_DIR}/pico_printf) pico_add_subdirectory(${HOST_DIR}/pico_stdio) diff --git a/src/host/pico_rand/BUILD.bazel b/src/host/pico_rand/BUILD.bazel new file mode 100644 index 000000000..ce71b11be --- /dev/null +++ b/src/host/pico_rand/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_rand", + srcs = ["rand.c"], + hdrs = ["include/pico/rand.h"], + includes = ["include"], + target_compatible_with = ["//bazel/constraint:host"], + deps = [ + "//src/host/hardware_sync", + "//src/host/hardware_timer", + ], +) diff --git a/src/host/pico_rand/CMakeLists.txt b/src/host/pico_rand/CMakeLists.txt new file mode 100644 index 000000000..bc26553ea --- /dev/null +++ b/src/host/pico_rand/CMakeLists.txt @@ -0,0 +1,12 @@ +pico_add_library(pico_rand) + +target_sources(pico_rand INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/rand.c +) + +target_include_directories(pico_rand_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) + +pico_mirrored_target_link_libraries(pico_rand INTERFACE + hardware_timer + hardware_sync +) \ No newline at end of file diff --git a/src/host/pico_rand/include/pico/rand.h b/src/host/pico_rand/include/pico/rand.h new file mode 100644 index 000000000..4e9453355 --- /dev/null +++ b/src/host/pico_rand/include/pico/rand.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _PICO_RAND_H +#define _PICO_RAND_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** \file pico/rand.h + * \defgroup pico_rand pico_rand + * + * \brief Random Number Generator API + * + * This module generates random numbers at runtime utilizing a number of possible entropy + * sources and uses those sources to modify the state of a 128-bit 'Pseudo + * Random Number Generator' implemented in software. + * + * The random numbers (32 to 128 bit) to be supplied are read from the PRNG which is used + * to help provide a large number space. + * + * The following (multiple) sources of entropy are available (of varying quality), each enabled by a \#define: + * + * - Time (\ref PICO_RAND_ENTROPY_SRC_TIME == 1): The 64-bit microsecond timer is mixed in each time. + * + * \note All entropy sources are hashed before application to the PRNG state machine. + * + * The \em first time a random number is requested, the 128-bit PRNG state + * must be seeded. Multiple entropy sources are also available for the seeding operation: + * + * - Time (\ref PICO_RAND_SEED_ENTROPY_SRC_TIME == 1): The 64-bit microsecond timer is mixed into the seed. + * + */ + +// --------------- +// ENTROPY SOURCES +// --------------- + +// PICO_CONFIG: PICO_RAND_ENTROPY_SRC_TIME, Enable/disable use of hardware timestamp as an entropy source, type=bool, default=1, group=pico_rand +#ifndef PICO_RAND_ENTROPY_SRC_TIME +#define PICO_RAND_ENTROPY_SRC_TIME 1 +#endif + +// -------------------- +// SEED ENTROPY SOURCES +// -------------------- + +// PICO_CONFIG: PICO_RAND_SEED_ENTROPY_SRC_TIME, Enable/disable use of hardware timestamp as an entropy source for the random seed, type=bool, default=PICO_RAND_ENTROPY_SRC_TIME, group=pico_rand +#ifndef PICO_RAND_SEED_ENTROPY_SRC_TIME +#define PICO_RAND_SEED_ENTROPY_SRC_TIME PICO_RAND_ENTROPY_SRC_TIME +#endif + +// We provide a maximum of 128 bits entropy in one go +typedef struct rng_128 { + uint64_t r[2]; +} rng_128_t; + +/*! \brief Get 128-bit random number + * \ingroup pico_rand + * + * \param rand128 Pointer to storage to accept a 128-bit random number + */ +void get_rand_128(rng_128_t *rand128); + +/*! \brief Get 64-bit random number + * \ingroup pico_rand + * + * \return 64-bit random number + */ +uint64_t get_rand_64(void); + +/*! \brief Get 32-bit random number + * \ingroup pico_rand + * + * \return 32-bit random number + */ +uint32_t get_rand_32(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/host/pico_rand/rand.c b/src/host/pico_rand/rand.c new file mode 100644 index 000000000..7eaaf6d37 --- /dev/null +++ b/src/host/pico_rand/rand.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2022 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* xoroshiro128ss(), rotl(): + + Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) + + To the extent possible under law, the author has dedicated all copyright + and related and neighboring rights to this software to the public domain + worldwide. This software is distributed without any warranty. + + See + + splitmix64() implementation: + + Written in 2015 by Sebastiano Vigna (vigna@acm.org) + To the extent possible under law, the author has dedicated all copyright + and related and neighboring rights to this software to the public domain + worldwide. This software is distributed without any warranty. + + See +*/ + +#include "pico/rand.h" +#if PICO_RAND_ENTROPY_SRC_TIME +#include "hardware/timer.h" +#endif +#include "hardware/sync.h" + +static bool rng_initialised = false; + +// Note: By design, do not initialise any of the variables that hold entropy, +// they may have useful junk in them, either from power-up or a previous boot. +static rng_128_t rng_state; + +/* From the original source: + + This is a fixed-increment version of Java 8's SplittableRandom generator + See http://dx.doi.org/10.1145/2714064.2660195 and + http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html + + It is a very fast generator passing BigCrush, and it can be useful if + for some reason you absolutely want 64 bits of state; otherwise, we + rather suggest to use a xoroshiro128+ (for moderately parallel + computations) or xorshift1024* (for massively parallel computations) + generator. + + Note: This can be called with any value (i.e. including 0) +*/ +static __noinline uint64_t splitmix64(uint64_t x) { + uint64_t z = x + 0x9E3779B97F4A7C15ull; + z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull; + z = (z ^ (z >> 27)) * 0x94D049BB133111EBull; + return z ^ (z >> 31); +} + +/* From the original source: + + This is xoroshiro128** 1.0, one of our all-purpose, rock-solid, + small-state generators. It is extremely (sub-ns) fast and it passes all + tests we are aware of, but its state space is large enough only for + mild parallelism. + + For generating just floating-point numbers, xoroshiro128+ is even + faster (but it has a very mild bias, see notes in the comments). + + The state must be seeded so that it is not everywhere zero. If you have + a 64-bit seed, we suggest to seed a splitmix64 generator and use its + output to fill s. +*/ +static inline uint64_t rotl(const uint64_t x, int k) { + return (x << k) | (x >> (64 - k)); +} + +static __noinline uint64_t xoroshiro128ss(rng_128_t *local_rng_state) { + const uint64_t s0 = local_rng_state->r[0]; + uint64_t s1 = local_rng_state->r[1]; + + // Because the state is *modified* outside of this function, there is a + // 1 in 2^128 chance that it could be all zeroes (which is not allowed). + while (s0 == 0 && s1 == 0) { + s1 = time_us_64(); // should not be 0, but loop anyway + } + + const uint64_t result = rotl(s0 * 5, 7) * 9; + + s1 ^= s0; + local_rng_state->r[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b + local_rng_state->r[1] = rotl(s1, 37); // c + + return result; +} + +static void initialise_rand(void) { + rng_128_t local_rng_state = local_rng_state; + uint which = 0; + +#if PICO_RAND_SEED_ENTROPY_SRC_TIME + // Mix in hashed time. This is [possibly] predictable boot-to-boot + // but will vary application-to-application. + local_rng_state.r[which] ^= splitmix64(time_us_64()); + which ^= 1; +#endif + + spin_lock_t *lock = spin_lock_instance(PICO_SPINLOCK_ID_RAND); + uint32_t save = spin_lock_blocking(lock); + if (!rng_initialised) { + (void) xoroshiro128ss(&local_rng_state); + rng_state = local_rng_state; + rng_initialised = true; + } + spin_unlock(lock, save); +} + +uint64_t get_rand_64(void) { + if (!rng_initialised) { + // Do not provide 'RNs' until the system has been initialised. Note: + // The first initialisation can be quite time-consuming depending on + // the amount of RAM hashed, see RAM_HASH_START and RAM_HASH_END + initialise_rand(); + } + + static volatile uint8_t check_byte; + rng_128_t local_rng_state = rng_state; + uint8_t local_check_byte = check_byte; + // Modify PRNG state with the run-time entropy sources, + // hashed to reduce correlation with previous modifications. + uint which = 0; +#if PICO_RAND_ENTROPY_SRC_TIME + local_rng_state.r[which] ^= splitmix64(time_us_64()); + which ^= 1; +#endif + + spin_lock_t *lock = spin_lock_instance(PICO_SPINLOCK_ID_RAND); + uint32_t save = spin_lock_blocking(lock); + if (local_check_byte != check_byte) { + // someone got a random number in the interim, so mix it in + local_rng_state.r[0] ^= rng_state.r[0]; + local_rng_state.r[1] ^= rng_state.r[1]; + } + // Generate a 64-bit RN from the modified PRNG state. + // Note: This also "churns" the 128-bit state for next time. + uint64_t rand64 = xoroshiro128ss(&local_rng_state); + rng_state = local_rng_state; + check_byte++; + spin_unlock(lock, save); + + return rand64; +} + +void get_rand_128(rng_128_t *ptr128) { + ptr128->r[0] = get_rand_64(); + ptr128->r[1] = get_rand_64(); +} + +uint32_t get_rand_32(void) { + return (uint32_t) get_rand_64(); +} From c493a3a64db252f7b60c7327ecc70cb4a9044491 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 28 Jul 2025 12:22:50 -0500 Subject: [PATCH 217/224] fix errors in generated headers/SVD (#2599) --- src/rp2350/hardware_regs/RP2350.svd | 28 +++--- .../include/hardware/regs/clocks.h | 6 +- .../include/hardware/regs/dreq.h | 8 +- .../include/hardware/regs/glitch_detector.h | 6 +- .../include/hardware/regs/intctrl.h | 24 +++--- .../hardware_regs/include/hardware/regs/pio.h | 6 +- .../include/hardware/regs/powman.h | 59 ++++++------- .../include/hardware/regs/rosc.h | 14 +-- .../include/hardware/regs/rvcsr.h | 86 ++++++++++++++++--- .../include/hardware/regs/syscfg.h | 5 +- .../include/hardware/regs/ticks.h | 36 +++----- .../hardware_regs/include/hardware/regs/usb.h | 7 +- .../include/hardware/structs/powman.h | 16 ++-- .../include/hardware/structs/rosc.h | 4 +- .../include/hardware/structs/syscfg.h | 2 +- .../stub/CMSIS/Device/RP2350/Include/RP2350.h | 10 +-- 16 files changed, 187 insertions(+), 130 deletions(-) diff --git a/src/rp2350/hardware_regs/RP2350.svd b/src/rp2350/hardware_regs/RP2350.svd index c942b3a57..dc2e1f2ba 100644 --- a/src/rp2350/hardware_regs/RP2350.svd +++ b/src/rp2350/hardware_regs/RP2350.svd @@ -1759,7 +1759,7 @@ SPDX-License-Identifier: BSD-3-Clause CLK_SYS_CTRL 0x0000003c Clock control, can be changed on-the-fly (except for auxsrc) - 0x00000000 + 0x00000041 AUXSRC @@ -43232,7 +43232,8 @@ SPDX-License-Identifier: BSD-3-Clause AUXCTRL - * Bits 7:2: Reserved + * Bits 7:3: Reserved + * Bit 2: Set to mask OTP power analogue power supply detection from resetting OTP controller and PSM * Bit 1: When clear, the LPOSC output is XORed into the TRNG ROSC output as an additional, uncorrelated entropy source. When set, this behaviour is disabled. @@ -47936,9 +47937,9 @@ SPDX-License-Identifier: BSD-3-Clause FREQ_RANGE Controls the number of delay stages in the ROSC ring LOW uses stages 0 to 7 - MEDIUM uses stages 2 to 7 - HIGH uses stages 4 to 7 - TOOHIGH uses stages 6 to 7 and should not be used because its frequency exceeds design specifications + MEDIUM uses stages 0 to 5 + HIGH uses stages 0 to 3 + TOOHIGH uses stages 0 to 1 and should not be used because its frequency exceeds design specifications The clock output will not glitch when changing the range up one step at a time The clock output will glitch when changing the range down Note: the values here are gray coded which is why HIGH comes before TOOHIGH @@ -47976,7 +47977,7 @@ SPDX-License-Identifier: BSD-3-Clause 2 bits set triples drive strength 3 bits set quadruples drive strength For frequency randomisation set both DS0_RANDOM=1 & DS1_RANDOM=1 - 0x00000000 + 0x00000088 PASSWD @@ -49053,51 +49054,56 @@ SPDX-License-Identifier: BSD-3-Clause bit 0 = SRAM1 0 = powered up 1 = powered down - When POWMAN_STATE_REQ is written, the POWMAN_STATE_WAITING flag is set while the Power Manager determines what is required. If an invalid transition is requested the Power Manager will still register the request in POWMAN_STATE_REQ but will also set the POWMAN_BAD_REQ flag. It will then implement the power-up requests and ignore the power down requests. To do nothing would risk entering an unrecoverable lock-up state. Invalid requests are: any combination of power up and power down requests any request that results in swcore boing powered and xip unpowered If the request is to power down the switched-core domain then POWMAN_STATE_WAITING stays active until the processors halt. During this time the POWMAN_STATE_REQ field can be re-written to change or cancel the request. When the power state transition begins the POWMAN_STATE_WAITING_flag is cleared, the POWMAN_STATE_CHANGING flag is set and POWMAN register writes are ignored until the transition completes. + When POWMAN_STATE_REQ is written, the POWMAN_STATE_WAITING flag is set while the Power Manager determines what is required. If an invalid transition is requested the Power Manager will still register the request in POWMAN_STATE_REQ but will also set the POWMAN_BAD_REQ flag. It will then implement the power-up requests and ignore the power down requests. To do nothing would risk entering an unrecoverable lock-up state. Invalid requests are: any combination of power up and power down requests any request that results in swcore being powered and xip unpowered If the request is to power down the switched-core domain then POWMAN_STATE_WAITING stays active until the processors halt. During this time the POWMAN_STATE_REQ field can be re-written to change or cancel the request. When the power state transition begins the POWMAN_STATE_WAITING_flag is cleared, the POWMAN_STATE_CHANGING flag is set and POWMAN register writes are ignored until the transition completes. 0x0000000f CHANGING + Indicates a power state change is in progress [13:13] read-only WAITING + Indicates the power manager has received a state change request and is waiting for other actions to complete before executing it [12:12] read-only BAD_HW_REQ - Bad hardware initiated state request. Went back to state 0 (i.e. everything powered up) + Invalid hardware initiated state request, power up requests actioned, power down requests ignored [11:11] read-only BAD_SW_REQ - Bad software initiated state request. No action taken. + Invalid software initiated state request ignored [10:10] read-only PWRUP_WHILE_WAITING - Request ignored because of a pending pwrup request. See current_pwrup_req. Note this blocks powering up AND powering down. + Indicates that a power state change request was ignored because of a pending power state change request [9:9] read-write oneToClear REQ_IGNORED + Indicates that a software state change request was ignored because it clashed with an ongoing hardware or debugger request [8:8] read-write oneToClear REQ + This is written by software or hardware to request a new power state [7:4] read-write CURRENT + Indicates the current power state [3:0] read-only @@ -77606,7 +77612,7 @@ SPDX-License-Identifier: BSD-3-Clause SUSPENDED - Bus in suspended state. Valid for device. Device will go into suspend if neither Keep Alive / SOF frames are enabled. + Bus in suspended state. Valid for device and host. Host and device will go into suspend if neither Keep Alive / SOF frames are enabled. [4:4] read-write oneToClear diff --git a/src/rp2350/hardware_regs/include/hardware/regs/clocks.h b/src/rp2350/hardware_regs/include/hardware/regs/clocks.h index fd560c910..ce46345f8 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/clocks.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/clocks.h @@ -615,7 +615,7 @@ // Description : Clock control, can be changed on-the-fly (except for auxsrc) #define CLOCKS_CLK_SYS_CTRL_OFFSET _u(0x0000003c) #define CLOCKS_CLK_SYS_CTRL_BITS _u(0x000000e1) -#define CLOCKS_CLK_SYS_CTRL_RESET _u(0x00000000) +#define CLOCKS_CLK_SYS_CTRL_RESET _u(0x00000041) // ----------------------------------------------------------------------------- // Field : CLOCKS_CLK_SYS_CTRL_AUXSRC // Description : Selects the auxiliary clock source, will glitch when switching @@ -625,7 +625,7 @@ // 0x3 -> xosc_clksrc // 0x4 -> clksrc_gpin0 // 0x5 -> clksrc_gpin1 -#define CLOCKS_CLK_SYS_CTRL_AUXSRC_RESET _u(0x0) +#define CLOCKS_CLK_SYS_CTRL_AUXSRC_RESET _u(0x2) #define CLOCKS_CLK_SYS_CTRL_AUXSRC_BITS _u(0x000000e0) #define CLOCKS_CLK_SYS_CTRL_AUXSRC_MSB _u(7) #define CLOCKS_CLK_SYS_CTRL_AUXSRC_LSB _u(5) @@ -642,7 +642,7 @@ // fly // 0x0 -> clk_ref // 0x1 -> clksrc_clk_sys_aux -#define CLOCKS_CLK_SYS_CTRL_SRC_RESET _u(0x0) +#define CLOCKS_CLK_SYS_CTRL_SRC_RESET _u(0x1) #define CLOCKS_CLK_SYS_CTRL_SRC_BITS _u(0x00000001) #define CLOCKS_CLK_SYS_CTRL_SRC_MSB _u(0) #define CLOCKS_CLK_SYS_CTRL_SRC_LSB _u(0) diff --git a/src/rp2350/hardware_regs/include/hardware/regs/dreq.h b/src/rp2350/hardware_regs/include/hardware/regs/dreq.h index 6d126c0df..edcdae60b 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/dreq.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/dreq.h @@ -121,8 +121,8 @@ typedef enum dreq_num_rp2350 { DREQ_PWM_WRAP7 = 39, ///< Select PWM Counter 7's Wrap Value as DREQ DREQ_PWM_WRAP8 = 40, ///< Select PWM Counter 8's Wrap Value as DREQ DREQ_PWM_WRAP9 = 41, ///< Select PWM Counter 9's Wrap Value as DREQ - DREQ_PWM_WRAP10 = 42, ///< Select PWM Counter 0's Wrap Value as DREQ - DREQ_PWM_WRAP11 = 43, ///< Select PWM Counter 1's Wrap Value as DREQ + DREQ_PWM_WRAP10 = 42, ///< Select PWM Counter 10's Wrap Value as DREQ + DREQ_PWM_WRAP11 = 43, ///< Select PWM Counter 11's Wrap Value as DREQ DREQ_I2C0_TX = 44, ///< Select I2C0's TX FIFO as DREQ DREQ_I2C0_RX = 45, ///< Select I2C0's RX FIFO as DREQ DREQ_I2C1_TX = 46, ///< Select I2C1's TX FIFO as DREQ @@ -135,8 +135,8 @@ typedef enum dreq_num_rp2350 { DREQ_CORESIGHT = 53, ///< Select CORESIGHT as DREQ DREQ_SHA256 = 54, ///< Select SHA256 as DREQ DREQ_DMA_TIMER0 = 59, ///< Select DMA_TIMER0 as DREQ - DREQ_DMA_TIMER1 = 60, ///< Select DMA_TIMER0 as DREQ - DREQ_DMA_TIMER2 = 61, ///< Select DMA_TIMER1 as DREQ + DREQ_DMA_TIMER1 = 60, ///< Select DMA_TIMER1 as DREQ + DREQ_DMA_TIMER2 = 61, ///< Select DMA_TIMER2 as DREQ DREQ_DMA_TIMER3 = 62, ///< Select DMA_TIMER3 as DREQ DREQ_FORCE = 63, ///< Select FORCE as DREQ DREQ_COUNT diff --git a/src/rp2350/hardware_regs/include/hardware/regs/glitch_detector.h b/src/rp2350/hardware_regs/include/hardware/regs/glitch_detector.h index efdf434b3..6e108e2b7 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/glitch_detector.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/glitch_detector.h @@ -37,8 +37,7 @@ #define GLITCH_DETECTOR_ARM_VALUE_YES _u(0x0000) // ============================================================================= // Register : GLITCH_DETECTOR_DISARM -// Description : None -// Forcibly disarm the glitch detectors, if they are armed by OTP. +// Description : Forcibly disarm the glitch detectors, if they are armed by OTP. // Ignored if ARM is YES. // // This register is Secure read/write only. @@ -142,8 +141,7 @@ #define GLITCH_DETECTOR_SENSITIVITY_DET0_ACCESS "RW" // ============================================================================= // Register : GLITCH_DETECTOR_LOCK -// Description : None -// Write any nonzero value to disable writes to ARM, DISARM, +// Description : Write any nonzero value to disable writes to ARM, DISARM, // SENSITIVITY and LOCK. This register is Secure read/write only. #define GLITCH_DETECTOR_LOCK_OFFSET _u(0x0000000c) #define GLITCH_DETECTOR_LOCK_BITS _u(0x000000ff) diff --git a/src/rp2350/hardware_regs/include/hardware/regs/intctrl.h b/src/rp2350/hardware_regs/include/hardware/regs/intctrl.h index 4db58399e..1e19e33d1 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/intctrl.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/intctrl.h @@ -79,8 +79,8 @@ typedef enum irq_num_rp2350 { TIMER1_IRQ_1 = 5, ///< Select TIMER1's IRQ 1 output TIMER1_IRQ_2 = 6, ///< Select TIMER1's IRQ 2 output TIMER1_IRQ_3 = 7, ///< Select TIMER1's IRQ 3 output - PWM_IRQ_WRAP_0 = 8, ///< Select PWM's IRQ_WRAP 0 output - PWM_IRQ_WRAP_1 = 9, ///< Select PWM's IRQ_WRAP 1 output + PWM_IRQ_WRAP_0 = 8, ///< Select PWM's WRAP_0 IRQ output + PWM_IRQ_WRAP_1 = 9, ///< Select PWM's WRAP_1 IRQ output DMA_IRQ_0 = 10, ///< Select DMA's IRQ 0 output DMA_IRQ_1 = 11, ///< Select DMA's IRQ 1 output DMA_IRQ_2 = 12, ///< Select DMA's IRQ 2 output @@ -96,27 +96,27 @@ typedef enum irq_num_rp2350 { IO_IRQ_BANK0_NS = 22, ///< Select IO_BANK0_NS's IRQ output IO_IRQ_QSPI = 23, ///< Select IO_QSPI's IRQ output IO_IRQ_QSPI_NS = 24, ///< Select IO_QSPI_NS's IRQ output - SIO_IRQ_FIFO = 25, ///< Select SIO's IRQ_FIFO output - SIO_IRQ_BELL = 26, ///< Select SIO's IRQ_BELL output - SIO_IRQ_FIFO_NS = 27, ///< Select SIO_NS's IRQ_FIFO output - SIO_IRQ_BELL_NS = 28, ///< Select SIO_NS's IRQ_BELL output - SIO_IRQ_MTIMECMP = 29, ///< Select SIO_IRQ_MTIMECMP's IRQ output + SIO_IRQ_FIFO = 25, ///< Select SIO's FIFO IRQ output + SIO_IRQ_BELL = 26, ///< Select SIO's BELL IRQ output + SIO_IRQ_FIFO_NS = 27, ///< Select SIO_NS's FIFO IRQ output + SIO_IRQ_BELL_NS = 28, ///< Select SIO_NS's BELL IRQ output + SIO_IRQ_MTIMECMP = 29, ///< Select SIO's MTIMECMP IRQ output CLOCKS_IRQ = 30, ///< Select CLOCKS's IRQ output SPI0_IRQ = 31, ///< Select SPI0's IRQ output SPI1_IRQ = 32, ///< Select SPI1's IRQ output UART0_IRQ = 33, ///< Select UART0's IRQ output UART1_IRQ = 34, ///< Select UART1's IRQ output - ADC_IRQ_FIFO = 35, ///< Select ADC's IRQ_FIFO output + ADC_IRQ_FIFO = 35, ///< Select ADC's FIFO IRQ output I2C0_IRQ = 36, ///< Select I2C0's IRQ output I2C1_IRQ = 37, ///< Select I2C1's IRQ output OTP_IRQ = 38, ///< Select OTP's IRQ output TRNG_IRQ = 39, ///< Select TRNG's IRQ output - PROC0_IRQ_CTI = 40, ///< Select PROC0's IRQ_CTI output - PROC1_IRQ_CTI = 41, ///< Select PROC1's IRQ_CTI output + PROC0_IRQ_CTI = 40, ///< Select PROC0's CTI IRQ output + PROC1_IRQ_CTI = 41, ///< Select PROC1's CTI IRQ output PLL_SYS_IRQ = 42, ///< Select PLL_SYS's IRQ output PLL_USB_IRQ = 43, ///< Select PLL_USB's IRQ output - POWMAN_IRQ_POW = 44, ///< Select POWMAN's IRQ_POW output - POWMAN_IRQ_TIMER = 45, ///< Select POWMAN's IRQ_TIMER output + POWMAN_IRQ_POW = 44, ///< Select POWMAN's POW IRQ output + POWMAN_IRQ_TIMER = 45, ///< Select POWMAN's TIMER IRQ output SPARE_IRQ_0 = 46, ///< Select SPARE IRQ 0 SPARE_IRQ_1 = 47, ///< Select SPARE IRQ 1 SPARE_IRQ_2 = 48, ///< Select SPARE IRQ 2 diff --git a/src/rp2350/hardware_regs/include/hardware/regs/pio.h b/src/rp2350/hardware_regs/include/hardware/regs/pio.h index 4a18b5c6f..d20569708 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/pio.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/pio.h @@ -461,8 +461,7 @@ // ============================================================================= // Register : PIO_DBG_PADOUT // Description : Read to sample the pad output values PIO is currently driving -// to the GPIOs. On RP2040 there are 30 GPIOs, so the two most -// significant bits are hardwired to 0. +// to the GPIOs. #define PIO_DBG_PADOUT_OFFSET _u(0x0000003c) #define PIO_DBG_PADOUT_BITS _u(0xffffffff) #define PIO_DBG_PADOUT_RESET _u(0x00000000) @@ -472,8 +471,7 @@ // ============================================================================= // Register : PIO_DBG_PADOE // Description : Read to sample the pad output enables (direction) PIO is -// currently driving to the GPIOs. On RP2040 there are 30 GPIOs, -// so the two most significant bits are hardwired to 0. +// currently driving to the GPIOs. #define PIO_DBG_PADOE_OFFSET _u(0x00000040) #define PIO_DBG_PADOE_BITS _u(0xffffffff) #define PIO_DBG_PADOE_RESET _u(0x00000000) diff --git a/src/rp2350/hardware_regs/include/hardware/regs/powman.h b/src/rp2350/hardware_regs/include/hardware/regs/powman.h index edfbabbcc..8beb5650b 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/powman.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/powman.h @@ -944,7 +944,7 @@ // requests and ignore the power down requests. To do nothing // would risk entering an unrecoverable lock-up state. Invalid // requests are: any combination of power up and power down -// requests any request that results in swcore boing powered and +// requests any request that results in swcore being powered and // xip unpowered If the request is to power down the switched-core // domain then POWMAN_STATE_WAITING stays active until the // processors halt. During this time the POWMAN_STATE_REQ field @@ -957,6 +957,7 @@ #define POWMAN_STATE_RESET _u(0x0000000f) // ----------------------------------------------------------------------------- // Field : POWMAN_STATE_CHANGING +// Description : Indicates a power state change is in progress #define POWMAN_STATE_CHANGING_RESET _u(0x0) #define POWMAN_STATE_CHANGING_BITS _u(0x00002000) #define POWMAN_STATE_CHANGING_MSB _u(13) @@ -964,6 +965,9 @@ #define POWMAN_STATE_CHANGING_ACCESS "RO" // ----------------------------------------------------------------------------- // Field : POWMAN_STATE_WAITING +// Description : Indicates the power manager has received a state change request +// and is waiting for other actions to complete before executing +// it #define POWMAN_STATE_WAITING_RESET _u(0x0) #define POWMAN_STATE_WAITING_BITS _u(0x00001000) #define POWMAN_STATE_WAITING_MSB _u(12) @@ -971,8 +975,8 @@ #define POWMAN_STATE_WAITING_ACCESS "RO" // ----------------------------------------------------------------------------- // Field : POWMAN_STATE_BAD_HW_REQ -// Description : Bad hardware initiated state request. Went back to state 0 -// (i.e. everything powered up) +// Description : Invalid hardware initiated state request, power up requests +// actioned, power down requests ignored #define POWMAN_STATE_BAD_HW_REQ_RESET _u(0x0) #define POWMAN_STATE_BAD_HW_REQ_BITS _u(0x00000800) #define POWMAN_STATE_BAD_HW_REQ_MSB _u(11) @@ -980,7 +984,7 @@ #define POWMAN_STATE_BAD_HW_REQ_ACCESS "RO" // ----------------------------------------------------------------------------- // Field : POWMAN_STATE_BAD_SW_REQ -// Description : Bad software initiated state request. No action taken. +// Description : Invalid software initiated state request ignored #define POWMAN_STATE_BAD_SW_REQ_RESET _u(0x0) #define POWMAN_STATE_BAD_SW_REQ_BITS _u(0x00000400) #define POWMAN_STATE_BAD_SW_REQ_MSB _u(10) @@ -988,9 +992,8 @@ #define POWMAN_STATE_BAD_SW_REQ_ACCESS "RO" // ----------------------------------------------------------------------------- // Field : POWMAN_STATE_PWRUP_WHILE_WAITING -// Description : Request ignored because of a pending pwrup request. See -// current_pwrup_req. Note this blocks powering up AND powering -// down. +// Description : Indicates that a power state change request was ignored because +// of a pending power state change request #define POWMAN_STATE_PWRUP_WHILE_WAITING_RESET _u(0x0) #define POWMAN_STATE_PWRUP_WHILE_WAITING_BITS _u(0x00000200) #define POWMAN_STATE_PWRUP_WHILE_WAITING_MSB _u(9) @@ -998,6 +1001,8 @@ #define POWMAN_STATE_PWRUP_WHILE_WAITING_ACCESS "WC" // ----------------------------------------------------------------------------- // Field : POWMAN_STATE_REQ_IGNORED +// Description : Indicates that a software state change request was ignored +// because it clashed with an ongoing hardware or debugger request #define POWMAN_STATE_REQ_IGNORED_RESET _u(0x0) #define POWMAN_STATE_REQ_IGNORED_BITS _u(0x00000100) #define POWMAN_STATE_REQ_IGNORED_MSB _u(8) @@ -1005,6 +1010,8 @@ #define POWMAN_STATE_REQ_IGNORED_ACCESS "WC" // ----------------------------------------------------------------------------- // Field : POWMAN_STATE_REQ +// Description : This is written by software or hardware to request a new power +// state #define POWMAN_STATE_REQ_RESET _u(0x0) #define POWMAN_STATE_REQ_BITS _u(0x000000f0) #define POWMAN_STATE_REQ_MSB _u(7) @@ -1012,6 +1019,7 @@ #define POWMAN_STATE_REQ_ACCESS "RW" // ----------------------------------------------------------------------------- // Field : POWMAN_STATE_CURRENT +// Description : Indicates the current power state #define POWMAN_STATE_CURRENT_RESET _u(0xf) #define POWMAN_STATE_CURRENT_BITS _u(0x0000000f) #define POWMAN_STATE_CURRENT_MSB _u(3) @@ -1019,8 +1027,7 @@ #define POWMAN_STATE_CURRENT_ACCESS "RO" // ============================================================================= // Register : POWMAN_POW_FASTDIV -// Description : None -// divides the POWMAN clock to provide a tick for the delay module +// Description : divides the POWMAN clock to provide a tick for the delay module // and state machines // when clk_pow is running from the slow clock it is not divided // when clk_pow is running from the fast clock it is divided by @@ -1187,6 +1194,10 @@ #define POWMAN_EXT_TIME_REF_SOURCE_SEL_MSB _u(1) #define POWMAN_EXT_TIME_REF_SOURCE_SEL_LSB _u(0) #define POWMAN_EXT_TIME_REF_SOURCE_SEL_ACCESS "RW" +#define POWMAN_EXT_TIME_REF_SOURCE_SEL_VALUE_GPIO12 _u(0x0) +#define POWMAN_EXT_TIME_REF_SOURCE_SEL_VALUE_GPIO20 _u(0x1) +#define POWMAN_EXT_TIME_REF_SOURCE_SEL_VALUE_GPIO14 _u(0x2) +#define POWMAN_EXT_TIME_REF_SOURCE_SEL_VALUE_GPIO22 _u(0x3) // ============================================================================= // Register : POWMAN_LPOSC_FREQ_KHZ_INT // Description : Informs the AON Timer of the integer component of the clock @@ -1241,8 +1252,7 @@ #define POWMAN_XOSC_FREQ_KHZ_FRAC_ACCESS "RW" // ============================================================================= // Register : POWMAN_SET_TIME_63TO48 -// Description : None -// For setting the time, do not use for reading the time, use +// Description : For setting the time, do not use for reading the time, use // POWMAN_READ_TIME_UPPER and POWMAN_READ_TIME_LOWER. This field // must only be written when POWMAN_TIMER_RUN=0 #define POWMAN_SET_TIME_63TO48_OFFSET _u(0x00000060) @@ -1253,8 +1263,7 @@ #define POWMAN_SET_TIME_63TO48_ACCESS "RW" // ============================================================================= // Register : POWMAN_SET_TIME_47TO32 -// Description : None -// For setting the time, do not use for reading the time, use +// Description : For setting the time, do not use for reading the time, use // POWMAN_READ_TIME_UPPER and POWMAN_READ_TIME_LOWER. This field // must only be written when POWMAN_TIMER_RUN=0 #define POWMAN_SET_TIME_47TO32_OFFSET _u(0x00000064) @@ -1265,8 +1274,7 @@ #define POWMAN_SET_TIME_47TO32_ACCESS "RW" // ============================================================================= // Register : POWMAN_SET_TIME_31TO16 -// Description : None -// For setting the time, do not use for reading the time, use +// Description : For setting the time, do not use for reading the time, use // POWMAN_READ_TIME_UPPER and POWMAN_READ_TIME_LOWER. This field // must only be written when POWMAN_TIMER_RUN=0 #define POWMAN_SET_TIME_31TO16_OFFSET _u(0x00000068) @@ -1277,8 +1285,7 @@ #define POWMAN_SET_TIME_31TO16_ACCESS "RW" // ============================================================================= // Register : POWMAN_SET_TIME_15TO0 -// Description : None -// For setting the time, do not use for reading the time, use +// Description : For setting the time, do not use for reading the time, use // POWMAN_READ_TIME_UPPER and POWMAN_READ_TIME_LOWER. This field // must only be written when POWMAN_TIMER_RUN=0 #define POWMAN_SET_TIME_15TO0_OFFSET _u(0x0000006c) @@ -1289,8 +1296,7 @@ #define POWMAN_SET_TIME_15TO0_ACCESS "RW" // ============================================================================= // Register : POWMAN_READ_TIME_UPPER -// Description : None -// For reading bits 63:32 of the timer. When reading all 64 bits +// Description : For reading bits 63:32 of the timer. When reading all 64 bits // it is possible for the LOWER count to rollover during the read. // It is recommended to read UPPER, then LOWER, then re-read UPPER // and, if it has changed, re-read LOWER. @@ -1302,8 +1308,7 @@ #define POWMAN_READ_TIME_UPPER_ACCESS "RO" // ============================================================================= // Register : POWMAN_READ_TIME_LOWER -// Description : None -// For reading bits 31:0 of the timer. +// Description : For reading bits 31:0 of the timer. #define POWMAN_READ_TIME_LOWER_OFFSET _u(0x00000074) #define POWMAN_READ_TIME_LOWER_BITS _u(0xffffffff) #define POWMAN_READ_TIME_LOWER_RESET _u(0x00000000) @@ -1312,8 +1317,7 @@ #define POWMAN_READ_TIME_LOWER_ACCESS "RO" // ============================================================================= // Register : POWMAN_ALARM_TIME_63TO48 -// Description : None -// This field must only be written when POWMAN_ALARM_ENAB=0 +// Description : This field must only be written when POWMAN_ALARM_ENAB=0 #define POWMAN_ALARM_TIME_63TO48_OFFSET _u(0x00000078) #define POWMAN_ALARM_TIME_63TO48_BITS _u(0x0000ffff) #define POWMAN_ALARM_TIME_63TO48_RESET _u(0x00000000) @@ -1322,8 +1326,7 @@ #define POWMAN_ALARM_TIME_63TO48_ACCESS "RW" // ============================================================================= // Register : POWMAN_ALARM_TIME_47TO32 -// Description : None -// This field must only be written when POWMAN_ALARM_ENAB=0 +// Description : This field must only be written when POWMAN_ALARM_ENAB=0 #define POWMAN_ALARM_TIME_47TO32_OFFSET _u(0x0000007c) #define POWMAN_ALARM_TIME_47TO32_BITS _u(0x0000ffff) #define POWMAN_ALARM_TIME_47TO32_RESET _u(0x00000000) @@ -1332,8 +1335,7 @@ #define POWMAN_ALARM_TIME_47TO32_ACCESS "RW" // ============================================================================= // Register : POWMAN_ALARM_TIME_31TO16 -// Description : None -// This field must only be written when POWMAN_ALARM_ENAB=0 +// Description : This field must only be written when POWMAN_ALARM_ENAB=0 #define POWMAN_ALARM_TIME_31TO16_OFFSET _u(0x00000080) #define POWMAN_ALARM_TIME_31TO16_BITS _u(0x0000ffff) #define POWMAN_ALARM_TIME_31TO16_RESET _u(0x00000000) @@ -1342,8 +1344,7 @@ #define POWMAN_ALARM_TIME_31TO16_ACCESS "RW" // ============================================================================= // Register : POWMAN_ALARM_TIME_15TO0 -// Description : None -// This field must only be written when POWMAN_ALARM_ENAB=0 +// Description : This field must only be written when POWMAN_ALARM_ENAB=0 #define POWMAN_ALARM_TIME_15TO0_OFFSET _u(0x00000084) #define POWMAN_ALARM_TIME_15TO0_BITS _u(0x0000ffff) #define POWMAN_ALARM_TIME_15TO0_RESET _u(0x00000000) diff --git a/src/rp2350/hardware_regs/include/hardware/regs/rosc.h b/src/rp2350/hardware_regs/include/hardware/regs/rosc.h index 4865c2ee3..4caa07a7b 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/rosc.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/rosc.h @@ -39,9 +39,9 @@ // Field : ROSC_CTRL_FREQ_RANGE // Description : Controls the number of delay stages in the ROSC ring // LOW uses stages 0 to 7 -// MEDIUM uses stages 2 to 7 -// HIGH uses stages 4 to 7 -// TOOHIGH uses stages 6 to 7 and should not be used because its +// MEDIUM uses stages 0 to 5 +// HIGH uses stages 0 to 3 +// TOOHIGH uses stages 0 to 1 and should not be used because its // frequency exceeds design specifications // The clock output will not glitch when changing the range up one // step at a time @@ -77,7 +77,7 @@ // DS1_RANDOM=1 #define ROSC_FREQA_OFFSET _u(0x00000004) #define ROSC_FREQA_BITS _u(0xffff77ff) -#define ROSC_FREQA_RESET _u(0x00000000) +#define ROSC_FREQA_RESET _u(0x00000088) // ----------------------------------------------------------------------------- // Field : ROSC_FREQA_PASSWD // Description : Set to 0x9696 to apply the settings @@ -108,7 +108,7 @@ // ----------------------------------------------------------------------------- // Field : ROSC_FREQA_DS1_RANDOM // Description : Randomises the stage 1 drive strength -#define ROSC_FREQA_DS1_RANDOM_RESET _u(0x0) +#define ROSC_FREQA_DS1_RANDOM_RESET _u(0x1) #define ROSC_FREQA_DS1_RANDOM_BITS _u(0x00000080) #define ROSC_FREQA_DS1_RANDOM_MSB _u(7) #define ROSC_FREQA_DS1_RANDOM_LSB _u(7) @@ -124,7 +124,7 @@ // ----------------------------------------------------------------------------- // Field : ROSC_FREQA_DS0_RANDOM // Description : Randomises the stage 0 drive strength -#define ROSC_FREQA_DS0_RANDOM_RESET _u(0x0) +#define ROSC_FREQA_DS0_RANDOM_RESET _u(0x1) #define ROSC_FREQA_DS0_RANDOM_BITS _u(0x00000008) #define ROSC_FREQA_DS0_RANDOM_MSB _u(3) #define ROSC_FREQA_DS0_RANDOM_LSB _u(3) @@ -206,7 +206,7 @@ // On power-up this field is initialised to WAKE // An invalid write will also select WAKE // Warning: setup the irq before selecting dormant mode -// 0x636f6d61 -> dormant +// 0x636f6d61 -> DORMANT // 0x77616b65 -> WAKE #define ROSC_DORMANT_OFFSET _u(0x00000010) #define ROSC_DORMANT_BITS _u(0xffffffff) diff --git a/src/rp2350/hardware_regs/include/hardware/regs/rvcsr.h b/src/rp2350/hardware_regs/include/hardware/regs/rvcsr.h index f5ff378ab..a375a19d1 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/rvcsr.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/rvcsr.h @@ -86,7 +86,7 @@ // In addition the following custom extensions are configured: // Xh3bm, Xh3power, Xh3irq, Xh3pmpm #define RVCSR_MISA_OFFSET _u(0x00000301) -#define RVCSR_MISA_BITS _u(0xc0901107) +#define RVCSR_MISA_BITS _u(0xc0b511bf) #define RVCSR_MISA_RESET _u(0x40901105) // ----------------------------------------------------------------------------- // Field : RVCSR_MISA_MXL @@ -106,6 +106,14 @@ #define RVCSR_MISA_X_LSB _u(23) #define RVCSR_MISA_X_ACCESS "RO" // ----------------------------------------------------------------------------- +// Field : RVCSR_MISA_V +// Description : Vector extension (not implemented). +#define RVCSR_MISA_V_RESET _u(0x0) +#define RVCSR_MISA_V_BITS _u(0x00200000) +#define RVCSR_MISA_V_MSB _u(21) +#define RVCSR_MISA_V_LSB _u(21) +#define RVCSR_MISA_V_ACCESS "RO" +// ----------------------------------------------------------------------------- // Field : RVCSR_MISA_U // Description : Value of 1 indicates U-mode is implemented. #define RVCSR_MISA_U_RESET _u(0x1) @@ -114,6 +122,22 @@ #define RVCSR_MISA_U_LSB _u(20) #define RVCSR_MISA_U_ACCESS "RO" // ----------------------------------------------------------------------------- +// Field : RVCSR_MISA_S +// Description : Supervisor extension (not implemented). +#define RVCSR_MISA_S_RESET _u(0x0) +#define RVCSR_MISA_S_BITS _u(0x00040000) +#define RVCSR_MISA_S_MSB _u(18) +#define RVCSR_MISA_S_LSB _u(18) +#define RVCSR_MISA_S_ACCESS "RO" +// ----------------------------------------------------------------------------- +// Field : RVCSR_MISA_Q +// Description : Quad-precision floating point extension (not implemented). +#define RVCSR_MISA_Q_RESET _u(0x0) +#define RVCSR_MISA_Q_BITS _u(0x00010000) +#define RVCSR_MISA_Q_MSB _u(16) +#define RVCSR_MISA_Q_LSB _u(16) +#define RVCSR_MISA_Q_ACCESS "RO" +// ----------------------------------------------------------------------------- // Field : RVCSR_MISA_M // Description : Value of 1 indicates the M extension (integer multiply/divide) // is implemented. @@ -132,6 +156,39 @@ #define RVCSR_MISA_I_LSB _u(8) #define RVCSR_MISA_I_ACCESS "RO" // ----------------------------------------------------------------------------- +// Field : RVCSR_MISA_H +// Description : Hypervisor extension (not implemented, I agree it would be +// pretty cool on a microcontroller through). +#define RVCSR_MISA_H_RESET _u(0x0) +#define RVCSR_MISA_H_BITS _u(0x00000080) +#define RVCSR_MISA_H_MSB _u(7) +#define RVCSR_MISA_H_LSB _u(7) +#define RVCSR_MISA_H_ACCESS "RO" +// ----------------------------------------------------------------------------- +// Field : RVCSR_MISA_F +// Description : Single-precision floating point extension (not implemented). +#define RVCSR_MISA_F_RESET _u(0x0) +#define RVCSR_MISA_F_BITS _u(0x00000020) +#define RVCSR_MISA_F_MSB _u(5) +#define RVCSR_MISA_F_LSB _u(5) +#define RVCSR_MISA_F_ACCESS "RO" +// ----------------------------------------------------------------------------- +// Field : RVCSR_MISA_E +// Description : RV32E/64E base ISA (not implemented). +#define RVCSR_MISA_E_RESET _u(0x0) +#define RVCSR_MISA_E_BITS _u(0x00000010) +#define RVCSR_MISA_E_MSB _u(4) +#define RVCSR_MISA_E_LSB _u(4) +#define RVCSR_MISA_E_ACCESS "RO" +// ----------------------------------------------------------------------------- +// Field : RVCSR_MISA_D +// Description : Double-precision floating point extension (not implemented). +#define RVCSR_MISA_D_RESET _u(0x0) +#define RVCSR_MISA_D_BITS _u(0x00000008) +#define RVCSR_MISA_D_MSB _u(3) +#define RVCSR_MISA_D_LSB _u(3) +#define RVCSR_MISA_D_ACCESS "RO" +// ----------------------------------------------------------------------------- // Field : RVCSR_MISA_C // Description : Value of 1 indicates the C extension (compressed instructions) // is implemented. @@ -207,7 +264,7 @@ // Description : Timer interrupt enable. The processor transfers to the timer // interrupt vector when `mie.mtie`, `mip.mtip` and `mstatus.mie` // are all 1, unless a software or external interrupt request is -// also valid at this time. +// also both pending and enabled at this time. #define RVCSR_MIE_MTIE_RESET _u(0x0) #define RVCSR_MIE_MTIE_BITS _u(0x00000080) #define RVCSR_MIE_MTIE_MSB _u(7) @@ -216,9 +273,9 @@ // ----------------------------------------------------------------------------- // Field : RVCSR_MIE_MSIE // Description : Software interrupt enable. The processor transfers to the -// software interrupt vector `mie.msie`, `mip.msip` and +// software interrupt vector when `mie.msie`, `mip.msip` and // `mstatus.mie` are all 1, unless an external interrupt request -// is also valid at this time. +// is also both pending and enabled at this time. #define RVCSR_MIE_MSIE_RESET _u(0x0) #define RVCSR_MIE_MSIE_BITS _u(0x00000008) #define RVCSR_MIE_MSIE_MSB _u(3) @@ -336,7 +393,7 @@ #define RVCSR_MENVCFGH_RESET _u(0x00000000) #define RVCSR_MENVCFGH_MSB _u(31) #define RVCSR_MENVCFGH_LSB _u(0) -#define RVCSR_MENVCFGH_ACCESS "RW" +#define RVCSR_MENVCFGH_ACCESS "-" // ============================================================================= // Register : RVCSR_MCOUNTINHIBIT // Description : Count inhibit register for `mcycle`/`minstret` @@ -732,7 +789,7 @@ // Description : Timer interrupt pending. The processor transfers to the timer // interrupt vector when `mie.mtie`, `mip.mtip` and `mstatus.mie` // are all 1, unless a software or external interrupt request is -// also valid at this time. +// also both pending and enabled at this time. #define RVCSR_MIP_MTIP_RESET _u(0x0) #define RVCSR_MIP_MTIP_BITS _u(0x00000080) #define RVCSR_MIP_MTIP_MSB _u(7) @@ -741,9 +798,9 @@ // ----------------------------------------------------------------------------- // Field : RVCSR_MIP_MSIP // Description : Software interrupt pending. The processor transfers to the -// software interrupt vector `mie.msie`, `mip.msip` and +// software interrupt vector when `mie.msie`, `mip.msip` and // `mstatus.mie` are all 1, unless an external interrupt request -// is also valid at this time. +// is also both pending and enabled at this time. #define RVCSR_MIP_MSIP_RESET _u(0x0) #define RVCSR_MIP_MSIP_BITS _u(0x00000008) #define RVCSR_MIP_MSIP_MSB _u(3) @@ -3099,14 +3156,18 @@ #define RVCSR_MVENDORID_RESET _u(0x00000000) // ----------------------------------------------------------------------------- // Field : RVCSR_MVENDORID_BANK -#define RVCSR_MVENDORID_BANK_RESET "-" +// Description : Value of 9 indicates 9 continuation codes, which is JEP106 bank +// 10. +#define RVCSR_MVENDORID_BANK_RESET _u(0x0000009) #define RVCSR_MVENDORID_BANK_BITS _u(0xffffff80) #define RVCSR_MVENDORID_BANK_MSB _u(31) #define RVCSR_MVENDORID_BANK_LSB _u(7) #define RVCSR_MVENDORID_BANK_ACCESS "RO" // ----------------------------------------------------------------------------- // Field : RVCSR_MVENDORID_OFFSET -#define RVCSR_MVENDORID_OFFSET_RESET "-" +// Description : ID 0x13 in bank 10 is the JEP106 ID for Raspberry Pi Ltd, the +// vendor of RP2350. +#define RVCSR_MVENDORID_OFFSET_RESET _u(0x13) #define RVCSR_MVENDORID_OFFSET_BITS _u(0x0000007f) #define RVCSR_MVENDORID_OFFSET_MSB _u(6) #define RVCSR_MVENDORID_OFFSET_LSB _u(0) @@ -3122,10 +3183,11 @@ #define RVCSR_MARCHID_ACCESS "RO" // ============================================================================= // Register : RVCSR_MIMPID -// Description : Implementation ID +// Description : Implementation ID. On RP2350 this reads as 0x86fc4e3f, which is +// release v1.0-rc1 of Hazard3. #define RVCSR_MIMPID_OFFSET _u(0x00000f13) #define RVCSR_MIMPID_BITS _u(0xffffffff) -#define RVCSR_MIMPID_RESET "-" +#define RVCSR_MIMPID_RESET _u(0x86fc4e3f) #define RVCSR_MIMPID_MSB _u(31) #define RVCSR_MIMPID_LSB _u(0) #define RVCSR_MIMPID_ACCESS "RO" diff --git a/src/rp2350/hardware_regs/include/hardware/regs/syscfg.h b/src/rp2350/hardware_regs/include/hardware/regs/syscfg.h index 455ebf175..74fb596f4 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/syscfg.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/syscfg.h @@ -255,7 +255,10 @@ // ============================================================================= // Register : SYSCFG_AUXCTRL // Description : Auxiliary system control register -// * Bits 7:2: Reserved +// * Bits 7:3: Reserved +// +// * Bit 2: Set to mask OTP power analogue power supply detection +// from resetting OTP controller and PSM // // * Bit 1: When clear, the LPOSC output is XORed into the TRNG // ROSC output as an additional, uncorrelated entropy source. When diff --git a/src/rp2350/hardware_regs/include/hardware/regs/ticks.h b/src/rp2350/hardware_regs/include/hardware/regs/ticks.h index 79e13523d..3dac57216 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/ticks.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/ticks.h @@ -36,8 +36,7 @@ #define TICKS_PROC0_CTRL_ENABLE_ACCESS "RW" // ============================================================================= // Register : TICKS_PROC0_CYCLES -// Description : None -// Total number of clk_tick cycles before the next tick. +// Description : Total number of clk_tick cycles before the next tick. #define TICKS_PROC0_CYCLES_OFFSET _u(0x00000004) #define TICKS_PROC0_CYCLES_BITS _u(0x000001ff) #define TICKS_PROC0_CYCLES_RESET _u(0x00000000) @@ -46,8 +45,7 @@ #define TICKS_PROC0_CYCLES_ACCESS "RW" // ============================================================================= // Register : TICKS_PROC0_COUNT -// Description : None -// Count down timer: the remaining number clk_tick cycles before +// Description : Count down timer: the remaining number clk_tick cycles before // the next tick is generated. #define TICKS_PROC0_COUNT_OFFSET _u(0x00000008) #define TICKS_PROC0_COUNT_BITS _u(0x000001ff) @@ -79,8 +77,7 @@ #define TICKS_PROC1_CTRL_ENABLE_ACCESS "RW" // ============================================================================= // Register : TICKS_PROC1_CYCLES -// Description : None -// Total number of clk_tick cycles before the next tick. +// Description : Total number of clk_tick cycles before the next tick. #define TICKS_PROC1_CYCLES_OFFSET _u(0x00000010) #define TICKS_PROC1_CYCLES_BITS _u(0x000001ff) #define TICKS_PROC1_CYCLES_RESET _u(0x00000000) @@ -89,8 +86,7 @@ #define TICKS_PROC1_CYCLES_ACCESS "RW" // ============================================================================= // Register : TICKS_PROC1_COUNT -// Description : None -// Count down timer: the remaining number clk_tick cycles before +// Description : Count down timer: the remaining number clk_tick cycles before // the next tick is generated. #define TICKS_PROC1_COUNT_OFFSET _u(0x00000014) #define TICKS_PROC1_COUNT_BITS _u(0x000001ff) @@ -122,8 +118,7 @@ #define TICKS_TIMER0_CTRL_ENABLE_ACCESS "RW" // ============================================================================= // Register : TICKS_TIMER0_CYCLES -// Description : None -// Total number of clk_tick cycles before the next tick. +// Description : Total number of clk_tick cycles before the next tick. #define TICKS_TIMER0_CYCLES_OFFSET _u(0x0000001c) #define TICKS_TIMER0_CYCLES_BITS _u(0x000001ff) #define TICKS_TIMER0_CYCLES_RESET _u(0x00000000) @@ -132,8 +127,7 @@ #define TICKS_TIMER0_CYCLES_ACCESS "RW" // ============================================================================= // Register : TICKS_TIMER0_COUNT -// Description : None -// Count down timer: the remaining number clk_tick cycles before +// Description : Count down timer: the remaining number clk_tick cycles before // the next tick is generated. #define TICKS_TIMER0_COUNT_OFFSET _u(0x00000020) #define TICKS_TIMER0_COUNT_BITS _u(0x000001ff) @@ -165,8 +159,7 @@ #define TICKS_TIMER1_CTRL_ENABLE_ACCESS "RW" // ============================================================================= // Register : TICKS_TIMER1_CYCLES -// Description : None -// Total number of clk_tick cycles before the next tick. +// Description : Total number of clk_tick cycles before the next tick. #define TICKS_TIMER1_CYCLES_OFFSET _u(0x00000028) #define TICKS_TIMER1_CYCLES_BITS _u(0x000001ff) #define TICKS_TIMER1_CYCLES_RESET _u(0x00000000) @@ -175,8 +168,7 @@ #define TICKS_TIMER1_CYCLES_ACCESS "RW" // ============================================================================= // Register : TICKS_TIMER1_COUNT -// Description : None -// Count down timer: the remaining number clk_tick cycles before +// Description : Count down timer: the remaining number clk_tick cycles before // the next tick is generated. #define TICKS_TIMER1_COUNT_OFFSET _u(0x0000002c) #define TICKS_TIMER1_COUNT_BITS _u(0x000001ff) @@ -208,8 +200,7 @@ #define TICKS_WATCHDOG_CTRL_ENABLE_ACCESS "RW" // ============================================================================= // Register : TICKS_WATCHDOG_CYCLES -// Description : None -// Total number of clk_tick cycles before the next tick. +// Description : Total number of clk_tick cycles before the next tick. #define TICKS_WATCHDOG_CYCLES_OFFSET _u(0x00000034) #define TICKS_WATCHDOG_CYCLES_BITS _u(0x000001ff) #define TICKS_WATCHDOG_CYCLES_RESET _u(0x00000000) @@ -218,8 +209,7 @@ #define TICKS_WATCHDOG_CYCLES_ACCESS "RW" // ============================================================================= // Register : TICKS_WATCHDOG_COUNT -// Description : None -// Count down timer: the remaining number clk_tick cycles before +// Description : Count down timer: the remaining number clk_tick cycles before // the next tick is generated. #define TICKS_WATCHDOG_COUNT_OFFSET _u(0x00000038) #define TICKS_WATCHDOG_COUNT_BITS _u(0x000001ff) @@ -251,8 +241,7 @@ #define TICKS_RISCV_CTRL_ENABLE_ACCESS "RW" // ============================================================================= // Register : TICKS_RISCV_CYCLES -// Description : None -// Total number of clk_tick cycles before the next tick. +// Description : Total number of clk_tick cycles before the next tick. #define TICKS_RISCV_CYCLES_OFFSET _u(0x00000040) #define TICKS_RISCV_CYCLES_BITS _u(0x000001ff) #define TICKS_RISCV_CYCLES_RESET _u(0x00000000) @@ -261,8 +250,7 @@ #define TICKS_RISCV_CYCLES_ACCESS "RW" // ============================================================================= // Register : TICKS_RISCV_COUNT -// Description : None -// Count down timer: the remaining number clk_tick cycles before +// Description : Count down timer: the remaining number clk_tick cycles before // the next tick is generated. #define TICKS_RISCV_COUNT_OFFSET _u(0x00000044) #define TICKS_RISCV_COUNT_BITS _u(0x000001ff) diff --git a/src/rp2350/hardware_regs/include/hardware/regs/usb.h b/src/rp2350/hardware_regs/include/hardware/regs/usb.h index fbf1b7b36..4bb142bf5 100644 --- a/src/rp2350/hardware_regs/include/hardware/regs/usb.h +++ b/src/rp2350/hardware_regs/include/hardware/regs/usb.h @@ -1082,13 +1082,14 @@ #define USB_SIE_STATUS_SPEED_ACCESS "RO" // ----------------------------------------------------------------------------- // Field : USB_SIE_STATUS_SUSPENDED -// Description : Bus in suspended state. Valid for device. Device will go into -// suspend if neither Keep Alive / SOF frames are enabled. +// Description : Bus in suspended state. Valid for device and host. Host and +// device will go into suspend if neither Keep Alive / SOF frames +// are enabled. #define USB_SIE_STATUS_SUSPENDED_RESET _u(0x0) #define USB_SIE_STATUS_SUSPENDED_BITS _u(0x00000010) #define USB_SIE_STATUS_SUSPENDED_MSB _u(4) #define USB_SIE_STATUS_SUSPENDED_LSB _u(4) -#define USB_SIE_STATUS_SUSPENDED_ACCESS "WC" +#define USB_SIE_STATUS_SUSPENDED_ACCESS "RO" // ----------------------------------------------------------------------------- // Field : USB_SIE_STATUS_LINE_STATE // Description : USB bus line state diff --git a/src/rp2350/hardware_structs/include/hardware/structs/powman.h b/src/rp2350/hardware_structs/include/hardware/structs/powman.h index a81890e3c..3aa8015c0 100644 --- a/src/rp2350/hardware_structs/include/hardware/structs/powman.h +++ b/src/rp2350/hardware_structs/include/hardware/structs/powman.h @@ -137,14 +137,14 @@ typedef struct { _REG_(POWMAN_STATE_OFFSET) // POWMAN_STATE // This register controls the power state of the 4 power domains - // 0x00002000 [13] CHANGING (0) - // 0x00001000 [12] WAITING (0) - // 0x00000800 [11] BAD_HW_REQ (0) Bad hardware initiated state request - // 0x00000400 [10] BAD_SW_REQ (0) Bad software initiated state request - // 0x00000200 [9] PWRUP_WHILE_WAITING (0) Request ignored because of a pending pwrup request - // 0x00000100 [8] REQ_IGNORED (0) - // 0x000000f0 [7:4] REQ (0x0) - // 0x0000000f [3:0] CURRENT (0xf) + // 0x00002000 [13] CHANGING (0) Indicates a power state change is in progress + // 0x00001000 [12] WAITING (0) Indicates the power manager has received a state change... + // 0x00000800 [11] BAD_HW_REQ (0) Invalid hardware initiated state request, power up... + // 0x00000400 [10] BAD_SW_REQ (0) Invalid software initiated state request ignored + // 0x00000200 [9] PWRUP_WHILE_WAITING (0) Indicates that a power state change request was ignored... + // 0x00000100 [8] REQ_IGNORED (0) Indicates that a software state change request was... + // 0x000000f0 [7:4] REQ (0x0) This is written by software or hardware to request a new... + // 0x0000000f [3:0] CURRENT (0xf) Indicates the current power state io_rw_32 state; _REG_(POWMAN_POW_FASTDIV_OFFSET) // POWMAN_POW_FASTDIV diff --git a/src/rp2350/hardware_structs/include/hardware/structs/rosc.h b/src/rp2350/hardware_structs/include/hardware/structs/rosc.h index 73503cc15..4147cfb41 100644 --- a/src/rp2350/hardware_structs/include/hardware/structs/rosc.h +++ b/src/rp2350/hardware_structs/include/hardware/structs/rosc.h @@ -35,9 +35,9 @@ typedef struct { // 0xffff0000 [31:16] PASSWD (0x0000) Set to 0x9696 to apply the settings + // 0x00007000 [14:12] DS3 (0x0) Stage 3 drive strength // 0x00000700 [10:8] DS2 (0x0) Stage 2 drive strength - // 0x00000080 [7] DS1_RANDOM (0) Randomises the stage 1 drive strength + // 0x00000080 [7] DS1_RANDOM (1) Randomises the stage 1 drive strength // 0x00000070 [6:4] DS1 (0x0) Stage 1 drive strength - // 0x00000008 [3] DS0_RANDOM (0) Randomises the stage 0 drive strength + // 0x00000008 [3] DS0_RANDOM (1) Randomises the stage 0 drive strength // 0x00000007 [2:0] DS0 (0x0) Stage 0 drive strength io_rw_32 freqa; diff --git a/src/rp2350/hardware_structs/include/hardware/structs/syscfg.h b/src/rp2350/hardware_structs/include/hardware/structs/syscfg.h index 8909c0dbf..71660e5fb 100644 --- a/src/rp2350/hardware_structs/include/hardware/structs/syscfg.h +++ b/src/rp2350/hardware_structs/include/hardware/structs/syscfg.h @@ -72,7 +72,7 @@ typedef struct { _REG_(SYSCFG_AUXCTRL_OFFSET) // SYSCFG_AUXCTRL // Auxiliary system control register - // 0x000000ff [7:0] AUXCTRL (0x00) * Bits 7:2: Reserved + // 0x000000ff [7:0] AUXCTRL (0x00) * Bits 7:3: Reserved io_rw_32 auxctrl; } syscfg_hw_t; diff --git a/src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h b/src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h index 8ae014e04..ba5d206d2 100644 --- a/src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h +++ b/src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h @@ -4,10 +4,10 @@ * @file src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h * @brief CMSIS HeaderFile * @version 0.1 - * @date Thu Aug 8 04:04:02 2024 - * @note Generated by SVDConv V3.3.47 - * from File 'src/rp2_common/cmsis/../../rp2350/hardware_regs/RP2350.svd', - * last modified on Thu Aug 8 03:59:33 2024 + * @date Mon Jul 28 11:37:41 2025 + * @note Generated by SVDConv V3.3.45 + * from File 'src/rp2350/hardware_regs/RP2350.svd', + * last modified on Mon Jul 28 11:35:05 2025 */ @@ -2028,7 +2028,7 @@ typedef struct { /*!< POWMAN Structure ignore the power down requests. To do nothing would risk entering an unrecoverable lock-up state. Invalid requests are: any combination of power up and power down requests - any request that results in swcore boing powered and xip + any request that results in swcore being powered and xip unpowered If the request is to power down the switched-core domain then POWMAN_STATE_WAITING stays active until the processors halt. During this time the POWMAN_STATE_REQ From 9b1e125a3ed859b83a898fe776b3d0359dac9399 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Mon, 28 Jul 2025 21:27:40 +0100 Subject: [PATCH 218/224] pico_status_led doxygen improvements (#2601) --- .../pico_status_led/include/pico/status_led.h | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/rp2_common/pico_status_led/include/pico/status_led.h b/src/rp2_common/pico_status_led/include/pico/status_led.h index 4b900d2bd..be7c0bd49 100644 --- a/src/rp2_common/pico_status_led/include/pico/status_led.h +++ b/src/rp2_common/pico_status_led/include/pico/status_led.h @@ -9,8 +9,9 @@ * * \brief Enables access to the on-board status LED(s) * - * Boards usually have access to an on-board status LEDs which are configured via the board header (\see PICO_DEFAULT_LED_PIN and \see PICO_DEFAULT_WS2812_PIN) - * This library hides the details so you can use the status LEDs for all boards without changing your code. + * Boards usually have access to one or two on-board status LEDs which are configured via the board header (PICO_DEFAULT_LED_PIN, CYW43_WL_GPIO_LED_PIN and/or PICO_DEFAULT_WS2812_PIN). + * This library hides the low-level details so you can use the status LEDs for all boards without changing your code. + * \note If your board has both a single-color LED and a colored LED, you can independently control the single-color LED with the `status_led_` APIs, and the colored LED with the `colored_status_led_` APIs */ #ifndef _PICO_STATUS_LED_H @@ -28,7 +29,7 @@ struct async_context; extern "C" { #endif -// PICO_CONFIG: PICO_STATUS_LED_AVAILABLE, Indicate whether a non-colored status LED is available, type=bool, default=1 if PICO_DEFAULT_LED_PIN or CYW43_WL_GPIO_LED_PIN is defined; may be set by the user to 0 to not use either even if they are available, group=pico_status_led +// PICO_CONFIG: PICO_STATUS_LED_AVAILABLE, Indicate whether a single-color status LED is available, type=bool, default=1 if PICO_DEFAULT_LED_PIN or CYW43_WL_GPIO_LED_PIN is defined; may be set by the user to 0 to not use either even if they are available, group=pico_status_led #ifndef PICO_STATUS_LED_AVAILABLE #if defined(PICO_DEFAULT_LED_PIN) || defined(CYW43_WL_GPIO_LED_PIN) #define PICO_STATUS_LED_AVAILABLE 1 @@ -66,7 +67,7 @@ extern "C" { /*! \brief Generate an WRGB color value for \ref colored_status_led_set_on_with_color * \ingroup pico_status_led * - * \note: If your hardware does not support a white pixel, the white component is ignored + * \note If your hardware does not support a white pixel, the white component is ignored */ #ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB #define PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(w, r, g, b) (((w) << 24) | ((r) << 16) | ((g) << 8) | (b)) @@ -92,7 +93,7 @@ extern "C" { * If the application already has an async context (e.g. created by cyw43_arch_init) you should use \ref * status_led_init_with_context instead and pass it the \ref async_context already created by your application * - * \note: You must call this function (or \ref status_led_init_with_context) before using any other pico_status_led functions. + * \note You must call this function (or \ref status_led_init_with_context) before using any other pico_status_led functions. * * \return Returns true if the LED was initialized successfully, otherwise false on failure * \sa status_led_init_with_context @@ -104,7 +105,7 @@ bool status_led_init(void); * * Initialize the status LED(s) and the resources they need before use. * - * \note: You must call this function (or \ref status_led_init) before using any other pico_status_led functions. + * \note You must call this function (or \ref status_led_init) before using any other pico_status_led functions. * * \param context An \ref async_context used to communicate with the status LED (e.g. on Pico W or Pico 2 W) * \return Returns true if the LED was initialized successfully, otherwise false on failure @@ -122,19 +123,20 @@ static inline bool colored_status_led_supported(void) { return PICO_COLORED_STATUS_LED_AVAILABLE; } -/*! \brief Determine if the colored status LED is being used for the non-colored `status_led_` APIs +/*! \brief Determine if the colored status LED is being used for the single-color `status_led_` APIs * \ingroup pico_status_led - * \return true if the olored status LED is being used for the non-colored `status_led_` API + * \return true if the colored status LED is being used for the single-color `status_led_` API * \sa PICO_STATUS_LED_VIA_COLORED_STATUS_LED */ static inline bool status_led_via_colored_status_led(void) { return PICO_STATUS_LED_VIA_COLORED_STATUS_LED; } -/*! \brief Determine if the non-colored `status_led_` APIs are supported (i.e. if there is a regular LED, and its +/*! \brief Determine if the single-color `status_led_` APIs are supported (i.e. if there is a regular LED, and its * use isn't disabled via \ref PICO_STATUS_LED_AVAILABLE being set to 0, or if the colored status LED is being used for + * the single-color `status_led_` APIs * \ingroup pico_status_led - * \return true if the non-colored status LED API is available and expected to produce visible results + * \return true if the single-color status LED API is available and expected to produce visible results * \sa PICO_STATUS_LED_AVAILABLE * \sa PICO_STATUS_LED_VIA_COLORED_STATUS_LED */ @@ -148,7 +150,7 @@ static inline bool status_led_supported(void) { /*! \brief Set the colored status LED on or off * \ingroup pico_status_led * - * \note: If your hardware does not support a colored status LED (\see PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false. + * \note If your hardware does not support a colored status LED (PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false. * * \param led_on true to turn the colored LED on. Pass false to turn the colored LED off * \return true if the colored status LED could be set, otherwise false @@ -158,7 +160,7 @@ bool colored_status_led_set_state(bool led_on); /*! \brief Get the state of the colored status LED * \ingroup pico_status_led * - * \note: If your hardware does not support a colored status LED (\see PICO_DEFAULT_WS2812_PIN), this function returns false. + * \note If your hardware does not support a colored status LED (PICO_DEFAULT_WS2812_PIN), this function returns false. * * \return true if the colored status LED is on, or false if the colored status LED is off */ @@ -167,17 +169,17 @@ bool colored_status_led_get_state(void); /*! \brief Ensure the colored status LED is on, with the specified color * \ingroup pico_status_led * - * \note: If your hardware does not support a colored status LED (\see PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false. + * \note If your hardware does not support a colored status LED (PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false. * * \param color The color to use for the colored status LED when it is on, in 0xWWRRGGBB format - * \return true if the coloured status LED could be set, otherwise false on failure + * \return true if the colored status LED could be set, otherwise false on failure */ bool colored_status_led_set_on_with_color(uint32_t color); /*! \brief Get the color used for the status LED value when it is on * \ingroup pico_status_led * - * \note: If your hardware does not support a colored status LED (\see PICO_DEFAULT_WS2812_PIN), this function always returns 0x0. + * \note If your hardware does not support a colored status LED (PICO_DEFAULT_WS2812_PIN), this function always returns 0x0. * * \return The color used for the colored status LED when it is on, in 0xWWRRGGBB format */ @@ -186,7 +188,7 @@ uint32_t colored_status_led_get_on_color(void); /*! \brief Set the status LED on or off * \ingroup pico_status_led * -* \note: If your hardware does not support a status LED (\see PICO_DEFAULT_LED_PIN), this function does nothing and returns false. +* \note If your hardware does not support a status LED, this function does nothing and returns false. * * \param led_on true to turn the LED on. Pass false to turn the LED off * \return true if the status LED could be set, otherwise false @@ -213,7 +215,7 @@ static inline bool status_led_set_state(bool led_on) { /*! \brief Get the state of the status LED * \ingroup pico_status_led * - * \note: If your hardware does not support a status LED (\see PICO_DEFAULT_LED_PIN), this function always returns false. + * \note If your hardware does not support a status LED, this function always returns false. * * \return true if the status LED is on, or false if the status LED is off */ From ef5bc2c0440a6a2169d96c1af7fe203477217ca6 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Mon, 28 Jul 2025 21:28:48 +0100 Subject: [PATCH 219/224] Fix build issue with status led (#2600) --- src/rp2_common/pico_status_led/status_led.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/pico_status_led/status_led.c b/src/rp2_common/pico_status_led/status_led.c index 4c7134aaf..fc95a9689 100644 --- a/src/rp2_common/pico_status_led/status_led.c +++ b/src/rp2_common/pico_status_led/status_led.c @@ -43,7 +43,7 @@ static bool colored_status_led_on; static PIO pio; static uint sm; -static int offset = -1; +static uint offset; // Extract from 0xWWRRGGBB #define RED(c) (((c) >> 16) & 0xff) @@ -52,7 +52,7 @@ static int offset = -1; #define WHITE(c) (((c) >> 24) && 0xff) bool set_ws2812(uint32_t value) { - if (offset > -1) { + if (pio) { #if PICO_COLORED_STATUS_LED_USES_WRGB // Convert to 0xWWGGRRBB pio_sm_put_blocking(pio, sm, WHITE(value) << 24 | GREEN(value) << 16 | RED(value) << 8 | BLUE(value)); @@ -164,9 +164,9 @@ void status_led_deinit(void) { status_led_context = NULL; #endif #if COLORED_STATUS_LED_USING_WS2812_PIO - if (offset >= 0) { + if (pio) { pio_remove_program_and_unclaim_sm(&ws2812_program, pio, sm, offset); - offset = -1; + pio = NULL; } #ifdef PICO_DEFAULT_WS2812_POWER_PIN gpio_put(PICO_DEFAULT_WS2812_POWER_PIN, false); From 681574b728ebdc21c51fc8424a70182eaa9a313c Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Mon, 28 Jul 2025 19:30:14 -0500 Subject: [PATCH 220/224] add pico_status_led to host (#2605) --- src/host.cmake | 1 + src/host/pico_status_led/BUILD.bazel | 13 ++ src/host/pico_status_led/CMakeLists.txt | 10 + .../pico_status_led/include/pico/status_led.h | 206 ++++++++++++++++++ src/host/pico_status_led/status_led.c | 57 +++++ 5 files changed, 287 insertions(+) create mode 100644 src/host/pico_status_led/BUILD.bazel create mode 100644 src/host/pico_status_led/CMakeLists.txt create mode 100644 src/host/pico_status_led/include/pico/status_led.h create mode 100644 src/host/pico_status_led/status_led.c diff --git a/src/host.cmake b/src/host.cmake index 46e575627..10cafc7f9 100644 --- a/src/host.cmake +++ b/src/host.cmake @@ -34,6 +34,7 @@ include (${CMAKE_DIR}/no_hardware.cmake) pico_add_subdirectory(${HOST_DIR}/pico_rand) pico_add_subdirectory(${HOST_DIR}/pico_runtime) pico_add_subdirectory(${HOST_DIR}/pico_printf) + pico_add_subdirectory(${HOST_DIR}/pico_status_led) pico_add_subdirectory(${HOST_DIR}/pico_stdio) pico_add_subdirectory(${HOST_DIR}/pico_stdlib) pico_add_subdirectory(${HOST_DIR}/pico_time_adapter) diff --git a/src/host/pico_status_led/BUILD.bazel b/src/host/pico_status_led/BUILD.bazel new file mode 100644 index 000000000..8c4cf3252 --- /dev/null +++ b/src/host/pico_status_led/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_status_led", + srcs = ["status_led.c"], + hdrs = ["include/pico/status_led.h"], + includes = ["include"], + target_compatible_with = ["//bazel/constraint:host"], + deps = [ + "//src/host/hardware_gpio", + ], +) + diff --git a/src/host/pico_status_led/CMakeLists.txt b/src/host/pico_status_led/CMakeLists.txt new file mode 100644 index 000000000..fe6453327 --- /dev/null +++ b/src/host/pico_status_led/CMakeLists.txt @@ -0,0 +1,10 @@ +pico_add_library(pico_status_led) +target_sources(pico_status_led INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/status_led.c +) +target_include_directories(pico_status_led_headers SYSTEM INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/include +) +pico_mirrored_target_link_libraries(pico_status_led INTERFACE + hardware_gpio +) diff --git a/src/host/pico_status_led/include/pico/status_led.h b/src/host/pico_status_led/include/pico/status_led.h new file mode 100644 index 000000000..c4dc21e43 --- /dev/null +++ b/src/host/pico_status_led/include/pico/status_led.h @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** \file pico/status_led.h + * \defgroup pico_status_led pico_status_led + * + * \brief Enables access to the on-board status LED(s) + * + * Boards usually have access to one or two on-board status LEDs which are configured via the board header (PICO_DEFAULT_LED_PIN, CYW43_WL_GPIO_LED_PIN and/or PICO_DEFAULT_WS2812_PIN). + * This library hides the low-level details so you can use the status LEDs for all boards without changing your code. + * \note If your board has both a single-color LED and a colored LED, you can independently control the single-color LED with the `status_led_` APIs, and the colored LED with the `colored_status_led_` APIs + */ + +#ifndef _PICO_STATUS_LED_H +#define _PICO_STATUS_LED_H + +#include "pico.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// PICO_CONFIG: PICO_STATUS_LED_AVAILABLE, Indicate whether a single-color status LED is available, type=bool, default=1 if PICO_DEFAULT_LED_PIN or CYW43_WL_GPIO_LED_PIN is defined; may be set by the user to 0 to not use either even if they are available, group=pico_status_led +#ifndef PICO_STATUS_LED_AVAILABLE +#define PICO_STATUS_LED_AVAILABLE 1 +#endif + +// PICO_CONFIG: PICO_COLORED_STATUS_LED_AVAILABLE, Indicate whether a colored status LED is available, type=bool, default=1 if PICO_DEFAULT_WS2812_PIN is defined; may be set by the user to 0 to not use the colored status LED even if available, group=pico_status_led +#ifndef PICO_COLORED_STATUS_LED_AVAILABLE +#define PICO_COLORED_STATUS_LED_AVAILABLE 1 +#endif + +// PICO_CONFIG: PICO_STATUS_LED_VIA_COLORED_STATUS_LED, Indicate if the colored status LED should be used for both status_led and colored_status_led APIs, type=bool, default=1 if PICO_COLORED_STATUS_LED_AVAILABLE is 1 and PICO_STATUS_LED_AVAILABLE is 0, group=pico_status_led +#ifndef PICO_STATUS_LED_VIA_COLORED_STATUS_LED +#define PICO_STATUS_LED_VIA_COLORED_STATUS_LED (PICO_COLORED_STATUS_LED_AVAILABLE && !PICO_STATUS_LED_AVAILABLE) +#endif + +// PICO_CONFIG: PICO_COLORED_STATUS_LED_USES_WRGB, Indicate if the colored status LED supports WRGB, type=bool, default=0, group=pico_status_led +#ifndef PICO_COLORED_STATUS_LED_USES_WRGB +#define PICO_COLORED_STATUS_LED_USES_WRGB 0 +#endif + +/*! \brief Generate an RGB color value for /ref colored_status_led_set_on_with_color + * \ingroup pico_status_led + */ +#ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_RGB +#define PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(r, g, b) (((r) << 16) | ((g) << 8) | (b)) +#endif + +/*! \brief Generate an WRGB color value for \ref colored_status_led_set_on_with_color + * \ingroup pico_status_led + * + * \note If your hardware does not support a white pixel, the white component is ignored + */ +#ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB +#define PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(w, r, g, b) (((w) << 24) | ((r) << 16) | ((g) << 8) | (b)) +#endif + +// PICO_CONFIG: PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR, the default pixel color value of the colored status LED when it is on, type=int, group=pico_status_led +#ifndef PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR +#if PICO_COLORED_STATUS_LED_USES_WRGB +#define PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(0xaa, 0, 0, 0) +#else +#define PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(0xaa, 0xaa, 0xaa) +#endif +#endif + +struct async_context; + +/*! \brief Initialize the status LED(s) + * \ingroup pico_status_led + * + * Initialize the status LED(s) and the resources they need before use. On some devices (e.g. Pico W, Pico 2 W) accessing + * the status LED requires talking to the WiFi chip, which requires an \ref async_context. + * This method will create an async_context for you. + * + * However an application should only use a single \ref async_context instance to talk to the WiFi chip. + * If the application already has an async context (e.g. created by cyw43_arch_init) you should use \ref + * status_led_init_with_context instead and pass it the \ref async_context already created by your application + * + * \note You must call this function (or \ref status_led_init_with_context) before using any other pico_status_led functions. + * + * \return Returns true if the LED was initialized successfully, otherwise false on failure + * \sa status_led_init_with_context + */ +bool status_led_init(void); + +/*! \brief Initialise the status LED(s) + * \ingroup pico_status_led + * + * Initialize the status LED(s) and the resources they need before use. + * + * \note You must call this function (or \ref status_led_init) before using any other pico_status_led functions. + * + * \param context An \ref async_context used to communicate with the status LED (e.g. on Pico W or Pico 2 W) + * \return Returns true if the LED was initialized successfully, otherwise false on failure + * \sa status_led_init_with_context + */ +bool status_led_init_with_context(struct async_context *context); + +/*! \brief Determine if the `colored_status_led_` APIs are supported (i.e. if there is a colored status LED, and its + * use isn't disabled via \ref PICO_COLORED_STATUS_LED_AVAILABLE being set to 0 + * \ingroup pico_status_led + * \return true if the colored status LED API is available and expected to produce visible results + * \sa PICO_COLORED_STATUS_LED_AVAILABLE + */ +static inline bool colored_status_led_supported(void) { + return PICO_COLORED_STATUS_LED_AVAILABLE; +} + +/*! \brief Determine if the colored status LED is being used for the single-color `status_led_` APIs + * \ingroup pico_status_led + * \return true if the colored status LED is being used for the single-color `status_led_` API + * \sa PICO_STATUS_LED_VIA_COLORED_STATUS_LED + */ +static inline bool status_led_via_colored_status_led(void) { + return PICO_STATUS_LED_VIA_COLORED_STATUS_LED; +} + +/*! \brief Determine if the single-color `status_led_` APIs are supported (i.e. if there is a regular LED, and its + * use isn't disabled via \ref PICO_STATUS_LED_AVAILABLE being set to 0, or if the colored status LED is being used for + * the single-color `status_led_` APIs + * \ingroup pico_status_led + * \return true if the single-color status LED API is available and expected to produce visible results + * \sa PICO_STATUS_LED_AVAILABLE + * \sa PICO_STATUS_LED_VIA_COLORED_STATUS_LED + */ +static inline bool status_led_supported(void) { + if (status_led_via_colored_status_led()) { + return colored_status_led_supported(); + } + return PICO_STATUS_LED_AVAILABLE; +} + +/*! \brief Set the colored status LED on or off + * \ingroup pico_status_led + * + * \note If your hardware does not support a colored status LED (PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false. + * + * \param led_on true to turn the colored LED on. Pass false to turn the colored LED off + * \return true if the colored status LED could be set, otherwise false + */ +bool colored_status_led_set_state(bool led_on); + +/*! \brief Get the state of the colored status LED + * \ingroup pico_status_led + * + * \note If your hardware does not support a colored status LED (PICO_DEFAULT_WS2812_PIN), this function returns false. + * + * \return true if the colored status LED is on, or false if the colored status LED is off + */ +bool colored_status_led_get_state(void); + +/*! \brief Ensure the colored status LED is on, with the specified color + * \ingroup pico_status_led + * + * \note If your hardware does not support a colored status LED (PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false. + * + * \param color The color to use for the colored status LED when it is on, in 0xWWRRGGBB format + * \return true if the colored status LED could be set, otherwise false on failure + */ +bool colored_status_led_set_on_with_color(uint32_t color); + +/*! \brief Get the color used for the status LED value when it is on + * \ingroup pico_status_led + * + * \note If your hardware does not support a colored status LED (PICO_DEFAULT_WS2812_PIN), this function always returns 0x0. + * +* \return The color used for the colored status LED when it is on, in 0xWWRRGGBB format +*/ +uint32_t colored_status_led_get_on_color(void); + +/*! \brief Set the status LED on or off +* \ingroup pico_status_led +* +* \note If your hardware does not support a status LED, this function does nothing and returns false. +* +* \param led_on true to turn the LED on. Pass false to turn the LED off +* \return true if the status LED could be set, otherwise false +*/ +bool status_led_set_state(bool led_on); + +/*! \brief Get the state of the status LED + * \ingroup pico_status_led + * + * \note If your hardware does not support a status LED, this function always returns false. + * + * \return true if the status LED is on, or false if the status LED is off + */ +bool status_led_get_state(); + +/*! \brief De-initialize the status LED(s) + * \ingroup pico_status_led + * + * De-initializes the status LED(s) when they are no longer needed. + */ +void status_led_deinit(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/host/pico_status_led/status_led.c b/src/host/pico_status_led/status_led.c new file mode 100644 index 000000000..b5d079798 --- /dev/null +++ b/src/host/pico_status_led/status_led.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico/status_led.h" + +static bool status_led_on; +static uint32_t colored_status_led_on_color = PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR; +static bool colored_status_led_on; + +bool status_led_set_state(bool led_on) { + bool success = false; + if (status_led_supported()) { + success = true; + } + if (success) status_led_on = led_on; + return success; +} + +bool status_led_get_state(void) { + return status_led_on; +} + +bool colored_status_led_set_on_with_color(uint32_t color) { + colored_status_led_on_color = color; + return colored_status_led_set_state(true); +} + +uint32_t colored_status_led_get_on_color(void) { + return colored_status_led_on_color; +} + +bool colored_status_led_set_state(bool led_on) { + bool success = false; + if (colored_status_led_supported()) { + success = true; + } + if (success) colored_status_led_on = led_on; + return success; +} + +bool colored_status_led_get_state(void) { + return colored_status_led_on; +} + +bool status_led_init(void) { + return true; +} + +bool status_led_init_with_context(__unused struct async_context *context) { + return true; +} + +void status_led_deinit(void) { +} From b375d7fd38c6638355eb488b29b8f292fc10b8db Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 28 Jul 2025 23:37:27 -0500 Subject: [PATCH 221/224] wow; runtime.c has been missing from host/pico_runtime for a while --- src/host/pico_runtime/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/host/pico_runtime/CMakeLists.txt b/src/host/pico_runtime/CMakeLists.txt index dd4d67173..be809c6d5 100644 --- a/src/host/pico_runtime/CMakeLists.txt +++ b/src/host/pico_runtime/CMakeLists.txt @@ -1,5 +1,7 @@ pico_add_library(pico_runtime) +target_sources(pico_runtime INTERFACE ${CMAKE_CURRENT_LIST_DIR}/runtime.c) + target_include_directories(pico_runtime_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) pico_mirrored_target_link_libraries(pico_runtime INTERFACE From a1438dff1d38bd9c65dbd693f0e5db4b9ae91779 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Mon, 28 Jul 2025 19:34:47 -0500 Subject: [PATCH 222/224] SDK 2.2.0 Release --- MODULE.bazel | 4 ++-- pico_sdk_version.cmake | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 1cc03bd1a..31d6105cc 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,12 +1,12 @@ module( name = "pico-sdk", - version = "2.1.2-develop", + version = "2.2.0", ) bazel_dep(name = "platforms", version = "0.0.9") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "rules_python", version = "0.36.0") -bazel_dep(name = "picotool", version = "2.1.1") +bazel_dep(name = "picotool", version = "2.2.0") bazel_dep(name = "rules_cc", version = "0.0.10") http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/pico_sdk_version.cmake b/pico_sdk_version.cmake index c294d325b..0a3525873 100644 --- a/pico_sdk_version.cmake +++ b/pico_sdk_version.cmake @@ -4,13 +4,13 @@ if (NOT DEFINED PICO_SDK_VERSION_MAJOR) set(PICO_SDK_VERSION_MAJOR 2) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_MINOR, SDK minor version number, type=int, default=Current SDK minor version, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_MINOR, SDK minor version number, type=int, default=Current SDK minor version, group=pico_base - set(PICO_SDK_VERSION_MINOR 1) + set(PICO_SDK_VERSION_MINOR 2) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_REVISION, SDK version revision, type=int, default=Current SDK revision, group=pico_base - set(PICO_SDK_VERSION_REVISION 2) + set(PICO_SDK_VERSION_REVISION 0) # PICO_BUILD_DEFINE: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base # PICO_CMAKE_CONFIG: PICO_SDK_VERSION_PRE_RELEASE_ID, Optional SDK pre-release version identifier, default=Current SDK pre-release identifier, type=string, group=pico_base - set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) + #set(PICO_SDK_VERSION_PRE_RELEASE_ID develop) endif() # PICO_BUILD_DEFINE: PICO_SDK_VERSION_STRING, SDK version string, type=string, default=Current SDK version string, group=pico_base From c3c2b7f1554491ddf4ba4c010a9f7b363237ea4c Mon Sep 17 00:00:00 2001 From: Andrew Featherstone Date: Wed, 30 Jul 2025 22:31:37 +0100 Subject: [PATCH 223/224] picod-sdk: Use PICO_MHZ for FPGA_CLK_SYS_HZ and FPGA_CLK_REF_HZ Match changes made in 191f5ba4 to avoid Zephyr's definitions. Signed-off-by: Andrew Featherstone --- src/rp2040/hardware_regs/include/hardware/platform_defs.h | 4 ++-- src/rp2350/hardware_regs/include/hardware/platform_defs.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rp2040/hardware_regs/include/hardware/platform_defs.h b/src/rp2040/hardware_regs/include/hardware/platform_defs.h index a877710d0..d53037bc0 100644 --- a/src/rp2040/hardware_regs/include/hardware/platform_defs.h +++ b/src/rp2040/hardware_regs/include/hardware/platform_defs.h @@ -48,11 +48,11 @@ #define HAS_RP2040_RTC 1 #ifndef FPGA_CLK_SYS_HZ -#define FPGA_CLK_SYS_HZ (48 * MHZ) +#define FPGA_CLK_SYS_HZ (48 * PICO_MHZ) #endif #ifndef FPGA_CLK_REF_HZ -#define FPGA_CLK_REF_HZ (12 * MHZ) +#define FPGA_CLK_REF_HZ (12 * PICO_MHZ) #endif // PICO_CONFIG: XOSC_HZ, Crystal oscillator frequency in Hz, type=int, default=12000000, advanced=true, group=hardware_base diff --git a/src/rp2350/hardware_regs/include/hardware/platform_defs.h b/src/rp2350/hardware_regs/include/hardware/platform_defs.h index c919b94c1..247f306cd 100644 --- a/src/rp2350/hardware_regs/include/hardware/platform_defs.h +++ b/src/rp2350/hardware_regs/include/hardware/platform_defs.h @@ -77,11 +77,11 @@ #define __RISCV_PMP_CHECKED 1 #ifndef FPGA_CLK_SYS_HZ -#define FPGA_CLK_SYS_HZ (48 * MHZ) +#define FPGA_CLK_SYS_HZ (48 * PICO_MHZ) #endif #ifndef FPGA_CLK_REF_HZ -#define FPGA_CLK_REF_HZ (12 * MHZ) +#define FPGA_CLK_REF_HZ (12 * PICO_MHZ) #endif // PICO_CONFIG: XOSC_HZ, Crystal oscillator frequency in Hz, type=int, default=12000000, advanced=true, group=hardware_base From a43ee13325f7343a8d8f8e3b81ac0e3ec668399b Mon Sep 17 00:00:00 2001 From: Andrew Featherstone Date: Fri, 1 Aug 2025 22:30:06 +0100 Subject: [PATCH 224/224] pico-sdk: Replace more use of MHZ with PICO_MHZ Match changes made in 191f5ba4 to avoid Zephyr's definitions. Signed-off-by: Andrew Featherstone --- test/pico_time_test/pico_time_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pico_time_test/pico_time_test.c b/test/pico_time_test/pico_time_test.c index 9b022ea5d..351a14dfe 100644 --- a/test/pico_time_test/pico_time_test.c +++ b/test/pico_time_test/pico_time_test.c @@ -358,7 +358,7 @@ static int issue_2118_test(void) { #if PICO_ON_DEVICE // this problem only happens when running the clock fast as it requires the time between // alarm_pool_irq_handler handling an alarm and setting the next alarm to be <1us - set_sys_clock_hz(200 * MHZ, true); + set_sys_clock_hz(200 * PICO_MHZ, true); setup_default_uart(); #endif