Skip to content

Allow overriding the spi clock speed for icm42688 #13346

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

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

JBKingdon
Copy link
Contributor

@JBKingdon JBKingdon commented Feb 4, 2024

There was a report of glitches on the raw gyro output of an icm42688 which were resolved by reducing the the SPI clock speed. I don't think a single report justifies changing the default speed or even adding a CLI command to make it configurable, but it's relatively low impact to allow the speed to be set at compile time by passing the value via EXTRA_FLAGS and this will make it easier to see if changing the speed solves any future cases that might turn up.
(The first attempt at this PR used the existing macro name ICM426XX_MAX_SPI_CLK_HZ to set the override value, however this can't be passed to the cloud build via the configurator, so the PR was changed to introduce a new, simpler name to provide the override value, ICM426XX_CLOCK)

When passing a value for a macro through EXTRA_FLAGS we need to use single quotes, e.g. to set 12MHz we could use

-D'ICM426XX_CLOCK=12000000'

When using the configurator to start a cloud build the value can be placed in the "Custom Defines" text box as

ICM426XX_CLOCK=12000000

(or whatever value is desired)

Thread discussing (in part) the problem:
https://discord.com/channels/868013470023548938/1202941174177079336

Image showing a glitch:
https://cdn.discordapp.com/attachments/1202941174177079336/1203147744370495558/image.png?ex=65d009a7&is=65bd94a7&hm=12c936b068c6d6852e1239107d7b827a487461c25f2fdd35ccd159cd437d6e6e&

Copy link

github-actions bot commented Feb 4, 2024

Do you want to test this code? You can flash it directly from Betaflight Configurator:

  • Simply put #13346 (this pull request number) in the Select commit field of the Configurator firmware flasher tab (you need to Enable expert mode, Show release candidates and Development).

WARNING: It may be unstable. Use only for testing!

@haslinghuis haslinghuis added this to the 4.5 milestone Feb 4, 2024
There was a report of glitches on the raw gyro output of an icm42688
which were resolved by reducing the the SPI clock speed. I don't think
a single report justifies changing the default speed or even adding a
CLI command to make it configurable, but it's relatively low impact to
allow the speed to be set at compile time by passing the value via
EXTRA_FLAGS and this will make it easier to see if changing the speed
solves any future cases that might turn up. Passing the original macro
name caused the cloud builds to fail, so this PR introduces a new, shorter
macro for setting the override value; ICM426XX_CLOCK

When passing a value for a macro through EXTRA_FLAGS for a manual compile
we need to use single quotes, e.g. to set 12MHz we could use

-D'ICM426XX_CLOCK=12000000'

When using the configurator to start a cloud build the value can be placed
in the "Custom Defines" text box as

ICM426XX_CLOCK=12000000

(or whatever value is desired)
@haslinghuis haslinghuis requested a review from blckmn February 4, 2024 23:10
@ctzsnooze
Copy link
Member

Thanks, James.
The original issue was random spikes that occurred primarily in-flight on only pitch and roll axes, not yaw axis.
Should we wait to see if other people benefit from lowering the SPI speed of this gyro?
This PR can be used by anyone experiencing a problem of that kind, to see if it fixes their issue.

@JBKingdon
Copy link
Contributor Author

Hi Chris,
I think it's something of a 50 50 call. We only have the one report so far that fits this problem, so that would argue for not making any code changes. On the other hand using a #define doesn't add any runtime overhead and only minimal complexity. Merging it will make it a lot easier to test if the next report is a year or two down the line.
I have no strong feelings either way.

@nerdCopter
Copy link
Member

approving for it's simplicity and non-effect strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: COMPLETED
Development

Successfully merging this pull request may close these issues.

6 participants