Skip to content

RP235x: add selectable Embassy time driver backends (TIMER1, AON/POWMAN, and RISC-V mtime) - #6733

Open
mschnell1 wants to merge 15 commits into
embassy-rs:mainfrom
mschnell1:rp-timer-driver-with-time-driver-timer1-and-time-driver-aot
Open

RP235x: add selectable Embassy time driver backends (TIMER1, AON/POWMAN, and RISC-V mtime)#6733
mschnell1 wants to merge 15 commits into
embassy-rs:mainfrom
mschnell1:rp-timer-driver-with-time-driver-timer1-and-time-driver-aot

Conversation

@mschnell1

@mschnell1 mschnell1 commented Aug 7, 2026

Copy link
Copy Markdown

Summary

This PR extends the RP235x time driver implementation in Embassy RP to support multiple timer backends behind feature flags, while preserving the existing default behavior.

Compared to origin/main, this branch contains 11 commits and updates 2 files:

  • embassy-rp/Cargo.toml
  • embassy-rp/src/time_driver.rs

Motivation

On RP235x, different low-power and execution scenarios benefit from different timer sources. This change enables selecting the time driver backend explicitly, instead of always using TIMER0.

What Changed

  1. Added new feature flags in embassy-rp/Cargo.toml:

    • time-driver-timer1
    • time-driver-aot
    • time-driver-mtime
  2. Refactored backend selection in embassy-rp/src/time_driver.rs:

    • Default RP235x backend remains TIMER0 when no new time-driver-* feature is enabled.
    • Added TIMER1 backend support for RP235x.
    • Added AON/POWMAN backend support for RP235x.
    • Added RISC-V mtime backend support for RP235x.
  3. Implemented backend-specific time read and alarm logic:

    • Dedicated now() implementations for AON and mtime backends.
    • Dedicated set_alarm/check_alarm behavior where backend semantics differ.
  4. Added backend-specific init and interrupt wiring:

    • TIMER1_IRQ_0 for time-driver-timer1.
    • POWMAN_IRQ_TIMER for time-driver-aot.
    • SIO_IRQ_MTIMECMP for time-driver-mtime.
    • Existing TIMER0 IRQ path preserved as default fallback.
  5. Added RP235x AON helper module:

    • POWMAN keyed register writes.
    • AON timer initialization.
    • Embassy tick to LPOSC tick conversion and alarm programming.

Compatibility and Behavior

  • No behavior change for existing RP2040 users.
  • No behavior change for RP235x users who do not enable the new time-driver-* features (still uses TIMER0).
  • New behavior is opt-in through feature flags.

Notes

The Cargo feature declarations are currently added directly in embassy-rp as an interim step to make backend selection possible in this branch.

Testing

  • Verified compile-time feature-gated paths and interrupt routing in the updated driver code.
  • Follow-up validation on hardware is recommended for each backend:
    • time-driver-timer1 (done by dev)
    • time-driver-aot (done by dev)
    • time-driver-mtime (done by dev)

TODO

Decent integration with the existing cargo feature system (see comment below )
Optimal resource use, maybe easiest for the user, just a single additional cargo feature ("low-power-timer") necessary:

  • 2040: use Timer 0 (there is no other) (1µS resolution)
  • 2350:
    default: use the Platform Timer (same 1µS resolution as with 2040) => both TIMER0 and TIMER1 are free for the user project.
    optional: (feature "low-power-timer") use the AON Timer (1mSec resolution) => extreme low power

@embassy-bot

embassy-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

This pull request is a draft, so it isn't in the review queue yet. Mark it as ready for review when you'd like someone to look at it.

@mschnell1
mschnell1 marked this pull request as ready for review August 7, 2026 12:10
@mschnell1

mschnell1 commented Aug 7, 2026

Copy link
Copy Markdown
Author

in embassy-rp/Cargo.toml:


## these settimngs are currently necessary to allow the pipeline build. They should be removed ghere when the features will be (somehow) selectable in the "embassy-executor" or the "embassy-time" section
time-driver-timer1 = []
time-driver-aot = []
time-driver-mtime = []

@mschnell1

mschnell1 commented Aug 7, 2026

Copy link
Copy Markdown
Author

@Dirbaio also see #3847
(May 20, 2024 you suggested a pull request, but then I was not yet enough trained with git, now I got some assistance by @nursude355 )

@leftger leftger added the e-rp Issues for the RP family of chips label Aug 7, 2026
@mschnell1

mschnell1 commented Aug 8, 2026

Copy link
Copy Markdown
Author

From the conversation last year:
I am really convinced that using the "Platform Timer" should be the default with the RP235x and the "AON Timer" should be eligible for low power projects.
Hence I would be inclined to help to make this happen.
Please let me know if this might be planned with the Embassy RP library.


IMHO, the hardware design of the 2350 suggest intended use of the Platform Timer for thread scheduling purpose.

Hence TODO with feature managing:
Optimal resource use, maybe easiest for the user, just a single additional cargo feature ("low-power-timer") necessary:

  • 2040: use Timer 0 (there is no other) (1µS resolution)

  • 2350:
    default: use the Platform Timer (same 1µS resolution as with 2040) => both TIMER0 and TIMER1 are free for the user project.
    optional: (feature "low-power-timer") use the AON Timer (1mSec resolution) => extreme low power

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e-rp Issues for the RP family of chips

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants