Open taltenbach opened 1 month ago
Thanks for raising this issue.
This description is correct but some notes should be added:
Expected behavior The peripheral P is properly clock after
clock_control_on
has returned and the access to the register R succeeds.
Not exactly. API clock_control_on
specifies: " On success, the clock is enabled and ready when this function returns.".
hence that the clock is enabled and nothing else. Nothing is specified on the requesting peripheral.
Coming to the way to fix this, the most simple would be performing systematic dummy read in each peripheral driver following return from clock_control_on
.
We can also think of alternatives like getting the requesting peripheral to provide a reg address where the dummy read should be performed in the opaque clock_control_subsys_t
structure provided as argument to clock_control_on
and have the clock_control driver performing the read.
Both have pro's and cons but I'd prefer the first one.
Describe the bug According to RM0433, section 8.5.10, the following sequence must be used on STM32H7 MCUs when enabling a peripheral's clock to guarantee the peripheral is properly clocked before accessing its registers:
(Note that this sequence assumes the domain in which the peripheral is located is in DRun mode. Otherwise, additional steps are required.)
However, the current implementation of
clock_control_on
on STM32H7 devices currently only performs step 1 and 2 (see here).This means an access to a register of the enabled peripheral just after the call to
clock_control_on
might silently fail, leading to hard to investigate issues. This is probably especially true for peripherals having a low clock frequency, in comparison to the CPU clock.I suspect this issue to also impact other STM32 series. For example, RM0481, section 11.4.16, suggests that a similar sequence should be followed on STM32H5 MCUs.
Relates to https://github.com/zephyrproject-rtos/zephyr/issues/73580.
To Reproduce In theory, it the following sequence could fail on an STM32 MCU:
clock_control_on
to enable the clock of a given peripheral P.clock_control_on
has returned, immeditaly access a register R of the peripheral P.Expected behavior The peripheral P is properly clock after
clock_control_on
has returned and the access to the register R succeeds.Impact According to the reference manual, the peripheral P might not be properly clocked when
clock_control_on
returns, which means the access to the register R might silently fail.Logs and console output N/A
Environment
Additional context Relevant quotes from the RM0433 8.5.10: