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

drivers: rtc: rtc_ll_stm32: replace k_mutex with k_spinlock #85943

Merged
merged 2 commits into from
Mar 21, 2025

Conversation

jeppenodgaard
Copy link
Collaborator

This allows using this RTC driver from contexts where k_mutex use is not allowed.

Rework rtc_stm32_set_time to lock just before and just after accessing functions that modifies register values.


LOG_DBG("Setting clock");

k_spinlock_key_t key = k_spin_lock(&data->lock);
Copy link
Collaborator

Choose a reason for hiding this comment

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

To avoid functional changes, the following should be used instead:

Suggested change
k_spinlock_key_t key = k_spin_lock(&data->lock);
k_spinlock_key_t key;
int err = k_spin_trylock(&data->lock, &key);
if (err < 0) {
return err;
}

cc @erwango for whether the functional change is OK or not

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For reference. These set_time functions use k_spin_lock:

  • rtc_sam0_set_time
  • rtc_numaker_set_time
  • rtc_mc146818_set_time
  • ifx_cat1_rtc_set_time
  • ambiq_rtc_set_time
  • rtc_rpi_pico_set_time
  • ds1307_set_time

k_spin_trylock is not used by any rtc driver atm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@erwango any chance you got time to give this a look?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think there's a good response here.
I agree you @mathieuchopstm, you're changing the dynamic here, but drivers behaves today differently from the other drivers indeed, so we can't argue about we'll fail on the API contract.
I'm fine with keeping this change and if some applications have trouble with that, let's say that we're moving to the general API consensus.

if (err) {
return err;
}
k_spinlock_key_t key = k_spin_lock(&data->lock);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same remark here

erwango
erwango previously approved these changes Mar 20, 2025
@erwango
Copy link
Member

erwango commented Mar 20, 2025

@jeppenodgaard Rebase required

@jeppenodgaard jeppenodgaard force-pushed the stm32-rtc-rework-lock branch 2 times, most recently from 71c679d to 29adf2f Compare March 20, 2025 11:52
Jeppe Odgaard added 2 commits March 20, 2025 12:57
This allows using this RTC driver from contexts where `k_mutex` use is not
allowed.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
Lock just before and just after accessing functions that modifies register
values.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
@jeppenodgaard jeppenodgaard force-pushed the stm32-rtc-rework-lock branch from 29adf2f to e073fa9 Compare March 20, 2025 12:00
@kartben kartben merged commit 62e1d4b into zephyrproject-rtos:main Mar 21, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: RTC Real Time Clock platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants