Skip to content
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

Disable ICM426XX AFSR feature to prevent stalls #13132

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/drivers/accgyro/accgyro_spi_icm426xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
#define ICM426XX_BANK_SELECT3 0x03
#define ICM426XX_BANK_SELECT4 0x04

// Fix for stalls in gyro output. See https://github.com/ArduPilot/ardupilot/pull/25332
#define ICM426XX_INTF_CONFIG1 0x4D
#define ICM426XX_INTF_CONFIG1_AFSR_MASK 0xC0
#define ICM426XX_INTF_CONFIG1_AFSR_DISABLE 0x40

#define ICM426XX_RA_PWR_MGMT0 0x4E // User Bank 0
#define ICM426XX_PWR_MGMT0_ACCEL_MODE_LN (3 << 0)
#define ICM426XX_PWR_MGMT0_GYRO_MODE_LN (3 << 2)
Expand Down Expand Up @@ -274,6 +279,13 @@ void icm426xxGyroInit(gyroDev_t *gyro)

spiWriteReg(dev, ICM426XX_RA_INT_CONFIG1, intConfig1Value);

// Disable AFSR to prevent stalls in gyro output
uint8_t intfConfig1Value = spiReadRegMsk(dev, ICM426XX_INTF_CONFIG1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment about ICM426XX_INTF_CONFIG1 location in user bank 0
Also, is is really necessary use 3 lines for mask-and-set operation, which is idiomatic in low level programming ?

spiWriteReg(dev, ICM426XX_INTF_CONFIG1, (intfConfig1 & ~ICM426XX_INTF_CONFIG1_AFSR_MASK) | ICM426XX_INTF_CONFIG1_AFSR_DISABLE);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I simply followed the style of the adjacent code. I tend to try to follow the style of any code being maintained to avoid a confusing mix. Happy to make the obvious enhancement in which case I’d do the same for the other initialisation.

Copy link
Contributor

@ledvinap ledvinap Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. This is just minor case, and maybe only my personal preference.
The code style will slowly spread as new drivers are written based on old ones. Maybe mixing both is not that dangerous - with little luck, someone will use better one when creating new driver.

The comment is more important. It can lead to bugs when modification of other register is added.

intfConfig1Value &= ~ICM426XX_INTF_CONFIG1_AFSR_MASK;
intfConfig1Value |= ICM426XX_INTF_CONFIG1_AFSR_DISABLE;
spiWriteReg(dev, ICM426XX_INTF_CONFIG1, intfConfig1Value);


// Turn on gyro and acc on again so ODR and FSR can be configured
turnGyroAccOn(dev);

Expand Down