2020-02-02 03:29 AM
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?
2020-02-02 05:16 AM
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?
2020-02-02 07:22 PM
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.
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.
2020-02-08 05:52 AM
Any suggestions?
2020-02-08 06:39 AM
Drop the non-working bloatware generator! :)
2020-02-08 09:52 AM
Seems like a cube bug. Change it in code or try to get ST to fix it. Those are your options.
2020-02-09 12:20 AM
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.