Skip to content

rtc driver for the stm32u5xx and instantiation on the nucleo_u545re_q board. - #4950

Open
K-Nicolas-10 wants to merge 7 commits into
tock:masterfrom
WyliodrinEmbeddedIoT:add-rtc
Open

rtc driver for the stm32u5xx and instantiation on the nucleo_u545re_q board.#4950
K-Nicolas-10 wants to merge 7 commits into
tock:masterfrom
WyliodrinEmbeddedIoT:add-rtc

Conversation

@K-Nicolas-10

@K-Nicolas-10 K-Nicolas-10 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Pull Request Overview

This pull request adds RTC driver for stm32u5xx and instantiates it in boards/nucleo_u545re_q.

Testing Strategy

This pull request was tested by uploading tock on the Nucleo U545RE-Q board and running a userspace RTC application. The application can be found in libtock-c/examples/tests/rtc.

TODO or Help Wanted

N/A

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

AI Use

  • The PR description details my use of AI in the production of the
    code in this PR, if any, and I have manually checked and
    personally certify the entire contents of this PR.

My AI use: Although AI didn't write any lines of code in this PR, I have used Gemini for asking questions about the RTC driver for the F429ZI to understand it better and to have the same approach for my driver.

@github-actions github-actions Bot added the stm32 label Jul 15, 2026
Comment thread chips/stm32u5xx/src/chip.rs Outdated
usart1: &'a usart::Usart<'a>,
exti: &'a exti::Exti<'a>,
dma1: &'a Dma,
rtc: &'a rtc::Rtc<'a>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be created here rather than passed in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it in 5ee4e4e.
I had to borrow RCC in order for the DefaultPeripherals to own RTC. Can I ask why this might be a better solution? I thought about the fact that if someone comes along to have multiple RCC initializations, like let rcc = rcc::Rcc::new(rcc::RCC_BASE); , it can cause synchronization issues and borrowing rcc thus being the better approach, is there more to it than this?

Comment thread chips/stm32u5xx/src/rtc.rs Outdated
Comment on lines +479 to +486
register_structs! {
pub PwrRegisters {
(0x00 => _padding),
/// PWR disable backup domain register
(0x28 => pwr_dbpr: ReadWrite<u32, PWR_DBPR::Register>),
(0x2C => @END),
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in its own file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #4940

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9906399.

Comment thread chips/stm32u5xx/src/rtc.rs Outdated
// 5. After the LSI Oscillator stabilizes we select it as the RTC clock source. There can be
// a situation where the oscillator doesn't stabilize, in that case my approach is to not hang the kernel
// and just timeout.
let rcc = rcc::Rcc::new(rcc::RCC_BASE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pass a reference in instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 0235c14.

Comment thread boards/nucleo_u545re_q/src/main.rs Outdated
Comment on lines +173 to +183
// Turn on the RTC clock and unlock the backup domain.
// We handle errors here such that a failure doesn't halt the kernel.
if let Err(e) = rtc.initialize_clock() {
debug!("{:?}", e)
}

// Set up the RTC mode. (configure prescalers, 24h format, default date/time)
// This requires the previous step, the clock and bckup domain to have been sucessfully initialized.
if let Err(e) = rtc.init_mode() {
debug!("{:?}", e)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this all be handled by the default peripheral init function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. af450ee

… board

Signed-off-by: K-Nicolas-10 <alinicolas006@gmail.com>
Signed-off-by: K-Nicolas-10 <alinicolas006@gmail.com>
…t instead of in board

Signed-off-by: K-Nicolas-10 <alinicolas006@gmail.com>
Comment thread boards/nucleo_u545re_q/src/main.rs Outdated
Comment on lines 213 to 216
// Register the RTC to the deferred call client
periphs.rtc.register();

// Board specific wiring

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can move to the def peripherals init function as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 70d5141 .

Signed-off-by: K-Nicolas-10 <alinicolas006@gmail.com>
Signed-off-by: K-Nicolas-10 <alinicolas006@gmail.com>
@bradjc

bradjc commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Please work with the rest of the stm32u5xx team to determine how you all want the chip to handle RCC. Most peripheral drivers seem to initialize everything in the default peripherals init function. It could be handled like this PR. But having multiple patterns makes it hard to use this chip.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants