-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix G4 SPI clock being double what it should be #14207
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
Conversation
Do you want to test this code? You can flash it directly from Betaflight Configurator:
WARNING: It may be unstable. Use only for testing! |
ad7def0
to
9bb0e0f
Compare
I can confirm that my prototype FC now has expected SCK frequency: |
@ledvinap @blckmn @nerdCopter we still have the git submodule present. https://superuser.com/questions/1301581/get-git-commit-a-to-ignore-submodules |
562c640
to
6264ca6
Compare
I noticed src/config was being included which seems like a bad thing, so I've removed it here, but I'll obviously align to the consensus on what should be happening. |
Not sure what's going on with src/config, but this PR now only includes the desired delta from master. |
On a related topic, as a check, I've confirmed the I2C clock speed to be correct. It's configured to be 800kHz, as per
And an access to the baro shows this to be so. |
uint32_t spiClk = SystemCoreClock / 2; | ||
#elif defined(STM32H7) | ||
uint32_t spiClk = 100000000; | ||
#elif defined(STM32G4) | ||
uint32_t spiClk = SystemCoreClock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, this should be HAL_RCC_GetPCLK1Freq
or similar driver function. It will probably work for other processors too (checked F7), but it may be slightly complicated by SPI using both APB1 and APB2 (and thus PCLK1 / PCLK2), but that can be resolved using peripheral address. This is already implemented for timer clocks.
This special-casing will work, but it is mixing a lot of assumptions. But the simplicity may be worth it.
It is possible this is based on a master that does not include the dirty check on submodules. |
@SteveCEvans you could try: |
@SteveCEvans this needs a back port ? |
Yes, will do. Spent the evening making cables to debug GPS issues. |
G4 SPI clock was observed to be double what it should be.
Using a check for a number of frequencies using this temporary patch to the BMI270 driver:
We get the following expected frequencies, but we actually see double that.
As can be seen below:
After this fix, we see the following:
Previously the divisor values were half of what they should be, and the frequency was consequently double.
For FC's using the BMI270 gyro the consequence had been that the gyro was being clocked at 10.5MHz (one 8th of 84MHz), only just above its max permissible value of 10MHz. A consequence of this PR is that the frequency is now correctly set below 10MHz, to 5.25MHz, thus, but it's still plenty fast enough: