Skip to content

drivers: sensor: lsm6dsv16x: fix ODR handling in FIFO streaming setup - #126834

Open
MaureenHelm wants to merge 4 commits into
zephyrproject-rtos:mainfrom
MaureenHelm:lsm6dsv16x-streaming-fixes
Open

MaureenHelm wants to merge 4 commits into
zephyrproject-rtos:mainfrom
MaureenHelm:lsm6dsv16x-streaming-fixes

Conversation

@MaureenHelm

Copy link
Copy Markdown
Member

lsm6dsv16x_config_fifo() temporarily switches accel and gyro to the SFLP ODR so that the SFLP gbias takes effect, then restores the previous ODRs. This PR fixes two problems with that switch.

  • The restore wrote back the SFLP ODR instead of the configured one. lsm6dsv16x_accel_set_odr_raw() and lsm6dsv16x_gyro_set_odr_raw() update data->accel_freq and data->gyro_freq, so by the time of the restore they already held the SFLP ODR. Any accel-odr above the SFLP ODR was ignored when streaming. The configured ODRs are now saved before the switch.
  • The switch ran on every FIFO configuration. Changing the ODR right before the FIFO starts puts a settling sample at the head of the stream. The switch and the gbias write are now skipped unless SFLP data is batched.

Found while testing analogdevicesinc/libiio#1631 with an x_nucleo_iks4a1 shield

lsm6dsv16x_config_fifo() moves accel and gyro to the SFLP ODR to apply
the gbias, then restores data->accel_freq and data->gyro_freq. But
lsm6dsv16x_accel_set_odr_raw() updates those fields, so the restore
writes back the SFLP ODR and any accel-odr above it is ignored when
streaming. Save the configured ODRs before the switch.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
Changing the accel ODR right before the FIFO starts puts a settling
sample at the head of every stream. The switch is only needed to apply
the SFLP gbias, so skip it unless SFLP data is batched.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
@zephyrbot zephyrbot added area: Sensors Sensors size: L A PR changing between 50 and 499 lines of code labels Nov 23, 2026

@TheArkadiuszGrzelka TheArkadiuszGrzelka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixes the SFLP gbias ODR switch in lsm6dsv16x_config_fifo(): the restore wrote back the SFLP ODR because *_set_odr_raw() overwrites accel_freq and gyro_freq, and the switch now runs only when SFLP data is batched. Both changes make sense and belong in this driver.

Read both commits against lsm6dsv16x.c (*_set_odr_raw() updates the cached fields at lines 169 and 198, so saving accel_odr and gyro_odr first is right) and the callers of lsm6dsv16x_config_fifo(). sflp_fifo is only set inside the trigger branch, so the new guard also skips the switch when the FIFO is being turned off. Nothing to raise. I did not build or run it.

avisconti
avisconti previously approved these changes Nov 27, 2026

@avisconti avisconti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks

lsm6dsv16x_decoder_get_frame_count() counted the words of each FIFO tag
in uint8_t, while the FIFO holds up to 511 words. A capture of 256
accelerometer words reported zero frames, and a client streaming
through libiio failed with -ENODATA.

Count in uint16_t, the type the frame count is returned in.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
The FIFO is reconfigured, and so flushed, only when the requested FIFO
triggers change. After a stream is cancelled the FIFO keeps batching,
so the next stream with the same triggers starts with stale samples.
If the FIFO is past its watermark, the interrupt line is already
asserted when the edge interrupt is armed, and the stream never
triggers.

Clear the cached FIFO trigger setup when completing a cancelled
request, so the next stream reconfigures and flushes the FIFO.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Sensors Sensors size: L A PR changing between 50 and 499 lines of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants