-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
STM32H7 SPI123 incorrect clock source used for prescaler calculation #41650
Comments
Thanks for raising this @heinwessels. I'm currently looking at supporting multiple/alternate peripheral clock source by STM32 clock_control driver. I still need to give it more thoughts before sharing more details but it looks like the case you mention would be a good starting point. Btw, and this is a different topic but I see that the sample you're using is
|
@erwango I do believe this not at all a framing issue, and therefore not related to the issue you mentioned. It's also not limited to the
Do you think I should still do an temporary fix for this SPI case in the mean time? A more comprehensive clock driver is the better solution, but it might still be some while off. There might be users running at different SPI frequencies without knowing it until then. |
Ok. I didn't want to say this was the root cause of the clock issue you've identified, as it seems to be a well established issue.
One idea would be to push it as a PR and not getting it merged, so it is available to people that may face the issue. |
I don't think that's the case :) I made really sure that it's indeed a bug, because it's been giving me quite a few headaches.
I understand completely. Then it will be lower priority for me to create a temporary fix. In our implementation I will simply change the |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
Add 2 clocks tests around device clock configuration on stm32h7. For now, 'spi1_pllq_2_d1ppre_4' test variant is failed, which illustrates issue reported in zephyrproject-rtos#41650. Signed-off-by: Erwan Gouriou <[email protected]>
Add support for an alternate clock. If available, alternate clock is enabled and used to get the device clock rate. Fixes zephyrproject-rtos#41650 Signed-off-by: Erwan Gouriou <[email protected]>
Add 2 clocks tests around device clock configuration on stm32h7. For now, 'spi1_pllq_2_d1ppre_4' test variant is failed, which illustrates issue reported in #41650. Signed-off-by: Erwan Gouriou <[email protected]>
Add support for an alternate clock. If available, alternate clock is enabled and used to get the device clock rate. Fixes #41650 Signed-off-by: Erwan Gouriou <[email protected]>
Add 2 clocks tests around device clock configuration on stm32h7. For now, 'spi1_pllq_2_d1ppre_4' test variant is failed, which illustrates issue reported in zephyrproject-rtos#41650. Signed-off-by: Erwan Gouriou <[email protected]>
Add support for an alternate clock. If available, alternate clock is enabled and used to get the device clock rate. Fixes zephyrproject-rtos#41650 Signed-off-by: Erwan Gouriou <[email protected]>
Describe the bug
In the STM32H7 series the assumed clock source is incorrect when using SPI1, 2 or 3. This incorrect clock source is then used to calculate the clock prescaler (
SPI_CFG:MBR
), which can then potentially be calculated incorrectly. More specifically, it assumes the SCK clock source is, for exampleAPB2
, while it's by actually by defaultPLL1Q
. This resulted that our custom STM32H743 implementation is outputting an incorrect SPI clock frequency.This is because for the H7 series the SPI1, 2, and 3 has a seperate clock domain that governs the SCK speed. See the following snippet from RM0433 Figure 609.
Here
spi_ker_ck
is theSCLK
source, notPCLK
(f.i.APB2
). The value of thespi_ker_ck
is set byRCC_D2CCIP1R : SPI123SEL
, which ispll1_q_ck
by default.To Reproduce
We can slightly adjust the
nucleo_h743zi
DTS and abuse theled_ws2812
app to easily see this behaviour.e2588d6a42
a. Checking out this branch
b. Applying the patch
nucleo-configuration-patch
supplied below.print-clocks-output
patch to print out debugging clock informationwest build -p auto -b nucleo_h743zi samples/drivers/led_ws2812/
west flash
onto anucleo_h743zi
CN7:10
(D13
orSPI_A_SCK
orSPI_1_SCK
) with an oscilloscopeSCK
frequency incorrectly being 6MHz instead of the desired and calculated 3MHz.It will also output the following with the optional logging patch
Expected behavior
Expect the prescaler calculation to use the correct clock source to output the desired frequency.
Impact
Hard to notice issues with incorrect SPI frequencies meaning devices run slower/faster than designed for.
Environment (please complete the following information):
e2588d6a42
Additional Context
I created #40998 to attempt to fix this issue, but ABOSTM found a showstopping flaw in my implementation. We then proposed a new sollution would be to:
spi_ker_ck
value, since it's not possible to set two clocks the DTS. This means SCK source will always bePLL1Q
.PPL1Q
is enabled and#error
if not.I will try to create a fix for this implementation soon. However, I'm not sure yet what would be the best way to calculate the
PLL1Q
frequency, and would like some thoughts on that. The way I did it in the patch below is quite ugly.It's coincidance that this has gone unnoticed during previous SPI driver testing. If I understand correctly then the Nucleo H743zi is popular for STM32H7 testing, and the
PLL1 Q
divider usually sets the clock up by chance thatPLL1Q == APB2
. Therefore I had to change the dts in the patch below to changepll1_q
divisor from4
to1
to highlight this issue.Patches
nucleo-configuration-patch
print-clocks-output
The text was updated successfully, but these errors were encountered: