Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: using another timer but 0 for "time-driver" #3766

Open
mschnell1 opened this issue Jan 13, 2025 · 5 comments
Open

Feature Request: using another timer but 0 for "time-driver" #3766

mschnell1 opened this issue Jan 13, 2025 · 5 comments

Comments

@mschnell1
Copy link

mschnell1 commented Jan 13, 2025

I started a project using an RP2350 chip based on embassy-rp.
I found that when specifying the embassy-rp feature "time-driver" my tests work just fine. Here embassy uses TIMER0 (as defined in rp235x/mod.rs.
Now the RP2350 features multiple timers. In fact I would like to use the "Always on" Timer for this battery powered project.
Feature request : It would be great if in the features a timer hardware could be selected.
For now I dropped the re-used the feature "time-driver" and created my own driver essentially by copying the code from embassy-rp/time_driver_rs. That works fine. Now researching on how to make it use TIMER1 and then the "Always On" timer.
Thanks for listening !

BTW.: Seemingly the AON Timer (denoted as TIMER in the RP2350 documentation seems not top be included in rp235x/mod.rs. ?!? (but POWMAN_IRQ_TIMER = 45 already is defined.) Supposedly the definitions in powman.rs should be used here. but how to decently use pac::POWMAN::inte() or similar for the AON Timer ?

@mschnell1 mschnell1 changed the title Feature Request; using another timer but 0 for "time-driver" Feature Request: using another timer but 0 for "time-driver" Jan 13, 2025
@mschnell1
Copy link
Author

mschnell1 commented Jan 14, 2025

As a first step I tried to use timer 1 instead of timer 0.
I found that the (mostly copied from the embassy sources) code with TIMER0, TIMER0_IORQ_0.enable() andfn TIMER0_IRQ_0() works fine and I can reach a breakpoinht at DRIVER.check_alarm().
I replaced TIMER0, TIMER0_IORQ_0.enable() andfn TIMER0_IRQ_0() by TIMER1, TIMER1_IORQ_0.enable() andfn TIMER1_IRQ_0(). Tist does compile, but now the breakpoint is not hit anymore.
What am I doing wrong ?

@mschnell1
Copy link
Author

mschnell1 commented Jan 14, 2025

edit:
I found that I need to set the source for Timer 1 (while I did not find where embassy-rp sets the source for timer0, which somehow seems to be 1 msec by default). I did

        *TIMER.source().as_ptr() = p_pac::timer::regs::Source(1);

(don't know if that is the correct way. )
Now I get interrupts. But way to fast. ("1" is documented to be the full clock, while "0" is documented to be "default", which does not work.)

@mschnell1
Copy link
Author

mschnell1 commented Jan 14, 2025

edit:
could get it running corrcetly by

    let timer0_freq = pac::TICKS.timer0_cycles().read().0;    
    pac::TICKS.timer1_cycles().write(|w| w.0 = timer0_freq );
    pac::TICKS.timer1_ctrl().write(|w| w.set_enable(true));

but I of course should use the clk_ref_freq defined in embassy/embassy-rp/src/clocks.rs. But I don't find a way to access this value.
Also see #3773

@mschnell1
Copy link
Author

Once done, I may be able contribute an update to time-driver.rs that adheres to a feature defining which timer to use,

@mschnell1
Copy link
Author

proceeding, I did find clocks::clk_ref_freq() :)
using TIMTER1 works and is done as desired. Now trying the AON Timer....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant