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

embassy-nrf: Timer HAL broken for extended timers (TIMER3/TIMER4) #2951

Open
peter9477 opened this issue May 16, 2024 · 2 comments
Open

embassy-nrf: Timer HAL broken for extended timers (TIMER3/TIMER4) #2951

peter9477 opened this issue May 16, 2024 · 2 comments

Comments

@peter9477
Copy link
Contributor

The embassy-nrf timer.rs implementation has an impl_timer! macro that allows defining "extended" timers (which is used for TIMER3 and TIMER4 on chips where those are supported). This creates a constant CCS equal to 4 or 6, which is used in the Timer::new() to initialize the CC registers. This will panic at run time when TIMER3 or TIMER4 are used to create a Timer, because the impl_timer! macro involves only pac::timer0, which has only 4 CC registers.

As noted in the discussion below https://matrix.to/#/!YoLPkieCYHGzdjUhOK:matrix.org/$dC6N7X1MOSACQwlS0GI9wZsCKI1HS-yGsHlTPTAAEt8?via=matrix.org&via=tchncs.de&via=grusbv.com this will need to reference pac::timer3, possibly via a regs_ext() implementation in the trait (as suggested by @Dirbaio).

peter9477 added a commit to peter9477/embassy that referenced this issue May 17, 2024
peter9477 added a commit to peter9477/embassy that referenced this issue May 17, 2024
@peter9477
Copy link
Contributor Author

peter9477 commented May 17, 2024

We looked at this and couldn't see an obvious and simple way to make the impl_timer macro somehow handle both pac::timer0 and pac::timer3. It looked like by using a few traits and trait bounds it would be feasible, but we've tried something much simpler which appears to work.

aceeedd

This is done only for 52840 for the moment, as a proof of concept. Basically since the timer3 register block is a pure superset of the timer0 register block, and since the Timer type is generic on the CCS count so it knows how many compare registers it can access, by always using timer3 when it's defined for a given chip it appears this can resolve the problem. (We tested and it avoids the panic.)

Is this an acceptable solution? If so we can apply the changes for the other chips and PR this.

(That one changeset isn't complete as we messed up the macro scoping but subsequent commits resolved that.)

@Dirbaio
Copy link
Member

Dirbaio commented May 17, 2024

yes, it is acceptable! it's not elegant but there's no better solutions I can think of. The STM32 HAL does similar things in some places.

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

2 participants