From 17bb8ec732374876c5d5e98c3b4843742e7771c1 Mon Sep 17 00:00:00 2001 From: Tristan Rowley Date: Wed, 11 Feb 2026 21:15:50 +0000 Subject: [PATCH 1/4] RP2350 (Pico 2) support --- README.md | 2 +- .../RP2040UsbUartMasterClock/RP2040UsbUartMasterClock.ino | 2 +- library.json | 2 +- library.properties | 4 ++-- src/uClock.cpp | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f01346f..99e9ab5 100755 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The absence of real-time features necessary for creating professional-level embe - **AVR**: ATmega168/328, ATmega16u4/32u4, ATmega2560 - **ARM**: Teensy (all versions), STM32XX, Seeed Studio XIAO M0 - **ESP32**: All ESP32 family boards -- **RP2040**: Raspberry Pi Pico and compatible boards +- **RP2040/RP2350**: Raspberry Pico, Pico 2, and compatible boards ## Why uClock? diff --git a/examples/RP2040UsbUartMasterClock/RP2040UsbUartMasterClock.ino b/examples/RP2040UsbUartMasterClock/RP2040UsbUartMasterClock.ino index cf5b6eb..7faf971 100644 --- a/examples/RP2040UsbUartMasterClock/RP2040UsbUartMasterClock.ino +++ b/examples/RP2040UsbUartMasterClock/RP2040UsbUartMasterClock.ino @@ -54,7 +54,7 @@ void onClockStop() { } void setup() { -#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040) +#if defined(ARDUINO_ARCH_MBED) && (defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350)) // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040 TinyUSB_Device_Init(0); #endif diff --git a/library.json b/library.json index ffe6d19..a0ec300 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "name": "uClock", "version": "2.3.0", - "description": "A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy, STM32XX, ESP32, Raspberry Pico, Seedstudio XIAO M0 and RP2040)", + "description": "A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy, STM32XX, ESP32, Raspberry Pico, Seedstudio XIAO M0 and RP2040/RP2350)", "keywords": "bpm, clock, timing, tick, music, generator", "repository": { "type": "git", diff --git a/library.properties b/library.properties index 86a95fc..32aa442 100755 --- a/library.properties +++ b/library.properties @@ -3,8 +3,8 @@ version=2.3.0 author=Romulo Silva maintainer=Romulo Silva sentence=BPM clock generator for Arduino platform. -paragraph=A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy, STM32XX, ESP32, Raspberry Pico, Seedstudio XIAO M0 and RP2040) +paragraph=A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy, STM32XX, ESP32, Raspberry Pico, Seedstudio XIAO M0 and RP2040/RP2350) category=Timing url=https://github.com/midilab/uClock -architectures=avr,arm,samd,stm32,esp32,rp2040 +architectures=avr,arm,samd,stm32,esp32,rp2040,rp2350 includes=uClock.h diff --git a/src/uClock.cpp b/src/uClock.cpp index 73a3cf3..c3ff6c2 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -67,9 +67,9 @@ #define UCLOCK_PLATFORM_FOUND #endif // - // RP2040 (Raspberry Pico) family + // RP2040 and RP2350 (Raspberry Pico and Pico 2) family // - #if defined(ARDUINO_ARCH_RP2040) + #if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350) #include "platforms/rp2040.h" #define UCLOCK_PLATFORM_FOUND #endif From d06ff1a4257750f1c60285bbf0528317a82ce0c4 Mon Sep 17 00:00:00 2001 From: Tristan Rowley Date: Thu, 16 Apr 2026 00:02:09 +0100 Subject: [PATCH 2/4] FIX: timer initialization on RP2040/RP2350 -- BPM will now be accurate --- src/platforms/rp2040.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/platforms/rp2040.h b/src/platforms/rp2040.h index eb918c2..896dbf2 100644 --- a/src/platforms/rp2040.h +++ b/src/platforms/rp2040.h @@ -19,12 +19,10 @@ bool handlerISR(repeating_timer *timer) void initTimer(uint32_t init_clock) { // set up RPi interrupt timer - // todo: actually should be -init_clock so that timer is set to start init_clock us after last tick, instead of init_clock us after finished processing last tick! - add_repeating_timer_us(init_clock, &handlerISR, NULL, &timer); + add_repeating_timer_us(-(int32_t)init_clock), &handlerISR, NULL, &timer); } void setTimer(uint32_t us_interval) { cancel_repeating_timer(&timer); - // todo: actually should be -us_interval so that timer is set to start init_clock us after last tick, instead of init_clock us after finished processing last tick! - add_repeating_timer_us(us_interval, &handlerISR, NULL, &timer); -} \ No newline at end of file + add_repeating_timer_us(-(int32_t)us_interval), &handlerISR, NULL, &timer); +} From c7de253c71b37fc01000eca4db15da884ef7bfdb Mon Sep 17 00:00:00 2001 From: Tristan Rowley Date: Thu, 16 Apr 2026 00:15:00 +0100 Subject: [PATCH 3/4] (fix typo in previous commit) --- src/platforms/rp2040.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/rp2040.h b/src/platforms/rp2040.h index 896dbf2..7cfe51a 100644 --- a/src/platforms/rp2040.h +++ b/src/platforms/rp2040.h @@ -19,10 +19,10 @@ bool handlerISR(repeating_timer *timer) void initTimer(uint32_t init_clock) { // set up RPi interrupt timer - add_repeating_timer_us(-(int32_t)init_clock), &handlerISR, NULL, &timer); + add_repeating_timer_us(-(int32_t)init_clock, &handlerISR, NULL, &timer); } void setTimer(uint32_t us_interval) { cancel_repeating_timer(&timer); - add_repeating_timer_us(-(int32_t)us_interval), &handlerISR, NULL, &timer); + add_repeating_timer_us(-(int32_t)us_interval, &handlerISR, NULL, &timer); } From 63f7234229d4065577c3a0ed992e88469d58f73b Mon Sep 17 00:00:00 2001 From: Tristan Rowley Date: Thu, 16 Apr 2026 18:48:41 +0100 Subject: [PATCH 4/4] use static_cast --- src/platforms/rp2040.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/rp2040.h b/src/platforms/rp2040.h index 7cfe51a..e804f33 100644 --- a/src/platforms/rp2040.h +++ b/src/platforms/rp2040.h @@ -19,10 +19,10 @@ bool handlerISR(repeating_timer *timer) void initTimer(uint32_t init_clock) { // set up RPi interrupt timer - add_repeating_timer_us(-(int32_t)init_clock, &handlerISR, NULL, &timer); + add_repeating_timer_us(-static_cast(init_clock), &handlerISR, NULL, &timer); } void setTimer(uint32_t us_interval) { cancel_repeating_timer(&timer); - add_repeating_timer_us(-(int32_t)us_interval, &handlerISR, NULL, &timer); + add_repeating_timer_us(-static_cast(us_interval), &handlerISR, NULL, &timer); }