mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
fix(drivers/imu/st/lsm6dsv): reset before telling the 16X from the 32X (#28823)
CTRL8 bit2 identifies the 32X only at its reset value, and probe() read it before any reset. After a warm restart from firmware that cleared the bit (drivers without 32X support write the 16X CTRL8 encoding), a 32X was detected as a 16X and its accel ran at ±32 g while scaled as ±16 g. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
1 parent
bb4e77b00c
commit
a7646e2d6d
1 file changed
+19
-1
@@ -215,7 +215,25 @@ int LSM6DSV::probe()
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
// 16X vs 32X: read CTRL8 bit2 (hardware-reserved, differs per variant)
|
||||
// 16X vs 32X: CTRL8 bit2 is must-be-0 on the 16X and must-be-1 on the 32X, so it identifies the part
|
||||
// only at its reset value. A warm restart keeps whatever the previous firmware wrote there (drivers
|
||||
// without 32X support write the 16X encoding), so reset first, powered down per ST's reset procedure.
|
||||
RegisterSetAndClearBits(Register::CTRL1, 0, CTRL1_BIT::ODR_XL_MASK);
|
||||
RegisterSetAndClearBits(Register::CTRL2, 0, CTRL2_BIT::ODR_G_MASK);
|
||||
RegisterWrite(Register::CTRL3, CTRL3_BIT::SW_RESET);
|
||||
|
||||
bool reset_complete = false;
|
||||
|
||||
for (int attempt = 0; attempt < 10 && !reset_complete; attempt++) {
|
||||
px4_usleep(1000);
|
||||
reset_complete = (RegisterRead(Register::CTRL3) & CTRL3_BIT::SW_RESET) == 0;
|
||||
}
|
||||
|
||||
if (!reset_complete) {
|
||||
DEVICE_DEBUG("software reset timed out");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
const uint8_t ctrl8 = RegisterRead(Register::CTRL8);
|
||||
_device_variant = (ctrl8 & Bit2) ? DeviceVariant::LSM6DSV32X : DeviceVariant::LSM6DSV16X;
|
||||
|
||||
|
||||
Reference in new issue
Block a user