Closed heinwessels closed 2 years ago
Thanks for raising this @heinwessels.
I'm currently looking at supporting multiple/alternate peripheral clock source by STM32 clock_control driver. One of the advantage would be to centralize most of the work in one common driver, rather than splitting it in multiple peripheral drivers (which would also have to support similar problem for multiple series)
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 led_strip: ws2812
.
This is worrying me a little since we have identified a different issue with this driver, along with a different solution.
Would you mind having a look to following points ?
Btw, and this is a different topic but I see that the sample you're using is
led_strip: ws2812
. This is worrying me a little since we have identified a different issue with this driver, along with a different solution. Would you mind having a look to following points ?
@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 ws2812
at all. I picked up this issue when using the SPI for normal communiation (controlling a ili9341
LCD display). I simply used ws2812
sample as it seemed like the fastest way to get a dummy SPI peripheral running as minimal working example.
I'm currently looking at supporting multiple/alternate peripheral clock source by STM32 clock_control driver. One of the advantage would be to centralize most of the work in one common driver, rather than splitting it in multiple peripheral drivers (which would also have to support similar problem for multiple series)
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.
@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 ws2812 at all. I picked up this issue when using the SPI for normal communiation (controlling a ili9341 LCD display). I simply used ws2812 sample as it seemed like the fastest way to get a dummy SPI peripheral running as minimal working example.
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. I just wanted to be sure we're not colliding 2 different issues here by picking up an already broken example. And if not the case then I wonder if #40860 is required if you're able to get the sample working w/o it. Though, anyway as mentioned, this is a totally different topic.
Do you think I should still do an temporary fix for this SPI case in the mean time?
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. It may also be a good comparison point to the upcoming clock_control driver enhancement. I'm reluctant to merge this code if we already know it has to be removed rather soon, but in case of known delay, it is still an option.
I just wanted to be sure we're not colliding 2 different issues here by picking up an already broken example.
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'm reluctant to merge this code if we already know it has to be removed rather soon, but in case of known delay, it is still an option.
I understand completely. Then it will be lower priority for me to create a temporary fix. In our implementation I will simply change the PLL Q
divisor so that it matches the expected clock source frequency for now, since it's not used for anything else. Hacky, but should suffice until your refactoring at some point.
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.
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
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