extra: add RP2350 RISC-V machine timer timing provider - #166
Open
tobiaguiar08 wants to merge 4 commits into
Open
tobiaguiar08 wants to merge 4 commits into
tobiaguiar08 wants to merge 4 commits into
Conversation
RISC-V applications on RP2350 have no timing provider library and must copy one from the getting-started guide into every project. The copy in the guide also enables the timer interrupt during setup and ignores the kernel's request to stop the timer when it passes a zero delay. Add aux_riscv_pico_timer, a ready-to-use timing provider that generates the kernel tick from the RP2350 RISC-V platform timer. It honors the kernel's stop request. The tick period is fixed at setup, so the kernel's tickless mode is not used. The library is only available when building for the rp2350-riscv Pico SDK platform. Update the getting-started guide and the library overview to use the library instead of embedding the implementation. Assisted-by: Claude [claude-opus-5] Signed-off-by: Tobias Aguiar <tobi.aguiar01@gmail.com>
The HAL header states that its CSR accessors exist only for the thread switcher. The RP2350 timing provider now also uses them to control the machine timer interrupt, so the statement no longer holds and could mislead anyone trimming the accessor set. Update the scope comments to cover timing providers. Assisted-by: Claude [claude-opus-5] Signed-off-by: Tobias Aguiar <tobi.aguiar01@gmail.com>
Two passages in the RP2350 RISC-V guide render their markup literally. A warning in the "Linking CMRX to the project" section shows asterisks instead of bold text, because Doxygen does not start bold emphasis when the opening marker is followed by a code span. A note in the step that selects the RISC-V core shows backticks instead of code, because Doxygen does not format a code span wrapped in double quotes. Start the warning with a plain word and drop the quotes around the code span so both passages render as intended. Assisted-by: Claude [claude-opus-5] Signed-off-by: Tobias Aguiar <tobi.aguiar01@gmail.com>
Following the RP2350 RISC-V guide's flashing steps as written hits several problems the guide does not mention. The GDB command it shows may not support RISC-V, the first connection to OpenOCD can fail with a protocol error, and run stops at a confirmation prompt. Name a RISC-V-capable GDB in the command, and list the retry, the prompt answer and the OpenOCD warnings seen during load. Assisted-by: Claude [claude-opus-5] Signed-off-by: Tobias Aguiar <tobi.aguiar01@gmail.com>
ventZl
requested changes
Sep 15, 2026
| hardware_riscv_platform_timer | ||
| ) | ||
| else() | ||
| message(STATUS "aux_riscv_pico_timer: only available for PICO_PLATFORM=rp2350-riscv") |
Owner
There was a problem hiding this comment.
This probably isn't needed. Ignore this case silently.
| run | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| While running these commands, you may see the following: |
Owner
There was a problem hiding this comment.
I'd instruct your AI to not turn this howto into tutorial of using GDB with OpenOCD :)
|
|
||
| Create `src/timing_provider.h`: | ||
| The library implements the timing provider interface the kernel calls into - | ||
| `timing_provider_schedule()` and `timing_provider_delay()` - and `cmrx_machine_timer_handler()`, |
Owner
There was a problem hiding this comment.
People reading this probably don't care what it does as long as it works. Too much detail.
| uint64_t now = riscv_timer_get_mtime(); | ||
| uint64_t end = now + (uint64_t)delay_us; | ||
|
|
||
| while (end > now) { |
Owner
There was a problem hiding this comment.
In rare conditions, this can overflow. mtime may be shortly before overflowing and end may become number actually numerically lower than now, so the while loop below will terminate prematurely.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
aux_riscv_pico_timer, a ready-to-use timing provider library for RP2350 RISC-V that generates the kernel tick from the RISC-V machine timer. RISC-V applications no longer need to write their own timing provider. The PR also fixes problems found by following the RP2350 RISC-V getting-started guide end to end.Problem
RISC-V applications on RP2350 have no timing provider library. The getting-started guide embeds an implementation that every integrator must copy into their project. That copy also enables the timer interrupt during
timing_provider_setup()and ignores the kernel's stop request (delay_us == 0) intiming_provider_schedule().Changes
extra: add RP2350 RISC-V machine timer timing provideraux_riscv_pico_timer(src/extra/riscv_pico_timer.c,include/extra/riscv_pico_timer.h). It only builds whenCMRX_ARCH=riscvandPICO_PLATFORM=rp2350-riscv; otherwise CMake prints a status message and skips it.timing_provider_setup()only stores the tick period.timing_provider_schedule()disables the machine timer interrupt fordelay_us == 0. Otherwise it re-armsmtimecmpfrom the currentmtimeand enables the interrupt.timing_provider_delay()busy-waits onmtime, with nopico_time/hardware_timerdependency.cmrx_machine_timer_handler()is called by the existingquirks/pico-sdk-riscvmachine timer ISR. It re-arms the timer and callsos_sched_timing_callback().target_link_librariesline in the RISC-V guide links it.riscv: note timing provider use of HAL CSR accessorsinclude/cmrx/arch/riscv/hal.h. It said the CSR accessors exist only for the thread switcher, but the new library uses themieaccessors too.docs: fix markup rendering in RP2350 RISC-V getting-started guide**, because Doxygen does not open bold emphasis directly before a code span.docs: clarify GDB flashing steps in RP2350 RISC-V getting-started guidevMustReplyEmptyerror (retry), therunconfirmation prompt (answery), and OpenOCDkeep_alive()warnings duringload.Notes for review
delay_usonly distinguishes stop (0) from run.cmrx_machine_timer_handler()is declared in the public header so its definition is checked against a prototype. It is meant to be called by the quirk ISR, not by applications.timing_provider_setup/schedule/delaywithout doc comments, asextra/systick.hdoes. Doxygen merges identically named declarations across headers, so documenting them again would leak text into theaux_systickand timing API pages. The group description documents setup instead.Testing
Host: Ubuntu 24.04, Pico SDK 2.3.1,
riscv32-corev-elf-gcc14.1, OpenOCD built from source (cd4873400), Raspberry Pi Debug Probe, Pico 2.cmrxpointing at this branch. It builds withcmake -B build && cmake --build build.target extended-remote/load/runsteps, usinggdb-multiarch. The LED blinks at about 0.5 s, andblinkprints on UART.runprompt.timing_provider_*symbols.Doxyfile(Doxygen 1.9.8).master.aux_systickand timing API group pages is unchanged.Generated with Claude Code