cancel
Showing results for 
Search instead for 
Did you mean: 

Baud rate calculation for STM32WLE SPI2 in STM32CubeMX appears to be in error

DWalk.3
Associate III

When I configure SPI2 in STM32CubeMX, I see the following:

0693W00000NrLNxQAN.pngHere, I'm set up as a full-duplex SPI master, the prescaler is set to 8 and underneath the prescaler specification, it computes the baud rate to be 2 MBits/s. I've also observed that this value does not change with processor clock frequency so the tool must be assuming that the input clock is from the SPI2S2 clock multiplexor. This is consistent with what I see in STM32CubeMX because if I vary this clock with the PLL, the baud rate tracks this frequency. SPI1 works as expected

I ran some code that performs SPI transactions and observed the following on the logic analyzer:

0693W00000NrLR6QAN.pngClearly, the SPI baud rate is 4 MBits/s and not the 2 MBits/s as computed by the tool.

From this, I conclude that the clock source for SPI is actually PCLK1 and not the output of the SPI2S2 clock multiplexor. I think that that clock is only used in I2S mode (which I've never used) which is suggested by the reference manual in section 7.4.29 for bits 9:8:

"This bit is set and cleared by software to select the SPI2S2 I2S clock source."

Is this a bug in STM32CubeMX or is there something fundamental that I'm missing?

1 ACCEPTED SOLUTION

Accepted Solutions
Louis AUDOLY
ST Employee

Hello, @Community member​  and all,

Sorry for the very long delay.

It appear there was a lack of precision in the reference manual, that have an impact on CubeMx.

We cannot choose the input clock for the SPI2, we can only choose it for the I2S.

So for the SPI2, the input clock is SYSCLK. The baud rate in CubeMx is not good and will need to be change.

Regards

View solution in original post

4 REPLIES 4
Louis AUDOLY
ST Employee

Hello @Community member​ ,

It seems there is an issue here, I will go up the problem to the team and I will keep you inform when we have more information.

Thank you for pointing this.

Regards

Louis AUDOLY
ST Employee

Hello, @Community member​  and all,

Sorry for the very long delay.

It appear there was a lack of precision in the reference manual, that have an impact on CubeMx.

We cannot choose the input clock for the SPI2, we can only choose it for the I2S.

So for the SPI2, the input clock is SYSCLK. The baud rate in CubeMx is not good and will need to be change.

Regards

DWalk.3
Associate III

So the input clock in SPI mode is SYSCLK and not PCLK1?

Louis AUDOLY
ST Employee

Yes it is PCLK1, sorry I did a mistake