cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431KBU SPI Clock limited to 40MHz by CubeMX?

Jhon
Associate II

Hi Community, I'm using CubeMX 5.5.0 to setup my STM32G431KBU application, with these parameters:

  SYSCLK = 100MHz

  APB2 peripheral clock = 100MHz

  SPI1 mode = Full-Duplex Master

  Clock Parameters -> Prescaler (for Baud Rate) = 2

then I receive an "Parameter Error" message box:

  With this Prescaler value and APB2 Clock Frequency (100.0MHz), Baud Rate is more than: 40.0 MBits/s. Please set Prescaler more than 4.

And with Prescaler=4, I get the Baud Rate=25.0 MBits/s

But according to the manual, the max SPI clock frequency is 75MHz for Master mode, and 50MHz for Master transmitter mode. I want to set Prescaler = 2, to get a 50MHz SPI clock frequency.

Is this a bug of CubeMX?

6 REPLIES 6
S.Ma
Principal

G4 max frequency is 170MHz which is the datasheet assumed reference.

https://www.st.com/en/microcontrollers-microprocessors/stm32g4-series.html

Usually, SPI master limit is SYSCLK/2 and Slave limit is SYSCLK/4 (unless SPI IP is newer than what I know).

So if you run at 100MHz, 50MHz for master and 25MHz for slave makes sense.

And if SYSCLK is 75MHz, SPI Master max clock will be 36.5MHz...

Make sense?

Jhon
Associate II

Thanks for your reply. Yes my SYSCLK is 100MHz, but I can't set Prescaler=2 to get 50M SPI clock.

While in a STM32F4 project, Prescaler=2 is accepeted by CubeMX.

0690X00000BxoqiQAB.png

I know I can modify the code in main.c generated by CubeMX:

hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;

to

hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

this may work for me, but I've not test yet.

Jhon
Associate II

Any suggestions?

Drop the non-working bloatware generator! :)

TDK
Guru

Seems like a cube bug. Change it in code or try to get ST to fix it. Those are your options.

If you feel a post has answered your question, please click "Accept as Solution".
S.Ma
Principal

Just hack it, let the tool setup at lower frequency, and in the generated SPI.C hack in the user code space to flip up the prescaler whiile the SPI is idle.

Then check the SCK frequency on the oscilloscope and you are future cube version proof.