Linux IIO development
 help / color / mirror / Atom feed
* [BUG] iio: st_lsm6dsx: hw timestamp gain is 0 on ISM330DLC / LSM6DSL
@ 2026-11-09 13:38 Phil Williams
  2026-11-15  0:09 ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Phil Williams @ 2026-11-09 13:38 UTC (permalink / raw)
  To: mario.tesi, mario.tesi; +Cc: jic23, linux-iio

Hey Guys,

I ran into an issue where every FIFO sample from an ISM330DLC came out 
with the same timestamp, so our attitude math froze the pitch. The 
accelerometer and gyroscope values were fine. I've patched it locally, 
so this is just an FYI.

Make what you want of it, but here is an AI generated description of the 
issue:

Commit 8abbf45fcda0 ("iio: st_lsm6dsx: Fixed calibrated timestamp 
calculation") drops the timestamp scale for the older parts in this 
driver. Stable backport 981f3da383ce is what we hit, in 6.6.142.

st_lsm6dsx_init_hw_timer() used to do:

     hw->ts_gain = ST_LSM6DSX_TS_SENSITIVITY; /* 25000 ns/tick */

That commit deletes the constant and reads the gain from the per-chip table:

     hw->ts_gain = ts_settings->ts_sensitivity;

ts_sensitivity is only filled in on the entries that already had 
freq_fine (LSM6DSO / LSM6DSR / LSM6DSV and that generation). The 
untagged-FIFO entries have no freq_fine register, so they were left at 0:

     LSM6DS3
     LSM6DS3H
     LSM6DSL, LSM6DSM, ISM330DLC, LSM6DS3TR-C

st_lsm6dsx_read_fifo() still does:

     ts = data[1] << 16 | data[0] << 8 | data[3];
     ts *= hw->ts_gain;
     iio_push_to_buffers_with_timestamp(..., sensor->ts_ref + ts);

With ts_gain == 0 every sample is published as ts_ref, the 
CLOCK_REALTIME value taken when the buffer was enabled. The accel and 
gyro values are fine. Only the timestamp is stuck. The raw count is 
still checked against 0xff0000 before the multiply, so ts_ref is 
refreshed when the counter gets there. At 25 µs/tick that is about 7 
minutes. The driver comment says 1.638 s, which is 2^16 ticks, but the 
test is 0xff0000.

How we found it: an ISM330DLC on SPI (whoami 0x6a), on a Toradex Verdin 
i.MX8M Plus, after moving onto 6.6.142. Userspace integrates attitude 
from the delta of the IIO buffer timestamp and treats a non-increasing 
timestamp as dt = 0, so pitch, roll and yaw froze at the first sample. A 
strace of the process reading /dev/iio:deviceX showed the xyz int16s 
changing and the 8 timestamp bytes identical across samples. The same 
binary against the previous kernel, which still used the 25000 constant, 
did not do this.

Setting the old scale on those three entries fixes it. freq_fine stays 
unset, so the trim register is not read and the gain stays exactly 
25000, which is what those parts had before:

     .ts_sensitivity = 25000,
     .ts_trim_coeff = 37500,

After booting that kernel the timestamp bytes increment and pitch tracks 
the unit again. The entries that already had ts_sensitivity (25000, or 
21701 on the freq_fine 0x4f part) were left alone.

Fixes: 8abbf45fcda0 ("iio: st_lsm6dsx: Fixed calibrated timestamp 
calculation")

Regards,
Phil Williams
Principal Software Engineer
Advisoft Ltd


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-15  8:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 13:38 [BUG] iio: st_lsm6dsx: hw timestamp gain is 0 on ISM330DLC / LSM6DSL Phil Williams
2026-11-15  0:09 ` Jonathan Cameron
2026-11-15  7:11   ` Francesco Lavra
2026-11-15  8:17     ` [PATCH] iio: imu: st_lsm6dsx: fall back to 25 us/tick without a trim Phil Williams
2026-11-15  8:52       ` Lorenzo Bianconi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox