Skip to content

Conversation

anthony289478
Copy link
Contributor

When running the icm45686 on current main for several hours, occasionally I hit this assert,

__ASSERT(!(fdata->header & FIFO_HEADER_EXT_HEADER_EN(true)) &&
(fdata->header & FIFO_HEADER_ACCEL_EN(true)) &&
(fdata->header & FIFO_HEADER_GYRO_EN(true)) &&
(fdata->header & FIFO_HEADER_HIRES_EN(true)),
"Unsupported FIFO packet format");

When inspecting the value of the header, it is 0xff which is invalid and lead me to this comment in the official TDK HAL driver.
zephyrproject-rtos/hal_tdk/icm456xx/imu/inv_imu_driver_advanced.c

Since the current icm45686 driver implementation reads the fixed watermark threshold number of frames, and in cases where the watermark is equal to 1, the workaround is the watermark threshold set to M + 1 frames and M frames are read out on each threshold trigger.

When an unsupported fifo packet triggers an assert, it is
helpful to see the packet as a hex value to help when debugging.

Signed-off-by: Anthony Williams <[email protected]>
@anthony289478 anthony289478 changed the title Icm45686 an000364 fifo fix Icm45686 AN-000364 fifo fix Oct 16, 2025
@anthony289478 anthony289478 changed the title Icm45686 AN-000364 fifo fix ICM45686 AN-000364 FIFO Fix Oct 16, 2025
@zephyrbot zephyrbot added the area: Sensors Sensors label Oct 16, 2025
@anthony289478 anthony289478 force-pushed the icm45686-an000364-fifo-fix branch from 1216db8 to a79a687 Compare October 16, 2025 20:07
When operating in streaming mode, a FIFO empty event, which
is caused by host reading the last byte of the last FIFO frame,
can cause FIFO data corruption.

During subsequent reads to the FIFO, the first  frame that arrives
after the empty condition will be corrupted. Once the issue occurs,
the internal state cannot recover and the FIFO must be flushed in
bypass mode to clear the corrupted state.

The current workaround from TDK is to read M-1 frames when M frames
are reported by fifo_count. Since M is fixed by the fifo_watermark
DT parameter, and in cases where fifo_watermark == 1, the watermark
trigger threshold is set to M + 1 frames and M frames are read out
during a watermark threshold event.

Signed-off-by: Anthony Williams <[email protected]>
@anthony289478 anthony289478 force-pushed the icm45686-an000364-fifo-fix branch from a79a687 to 02b06bc Compare October 16, 2025 20:29
MaureenHelm
MaureenHelm previously approved these changes Oct 17, 2025
Change the __ASSERT on unsupported fifo packet header to
CHECKIF so the user can choose how to handle the invalid
packet.

Signed-off-by: Anthony Williams <[email protected]>
ubieda
ubieda previously approved these changes Oct 17, 2025
The size of icm45686_encoded_data fifo_payload is guaranteed
to span the full number of frames read as it was allocated during
icm45686_event_handler() buf_len_required size.

This update suppresses the static analysis warning of
out of bounds memory access at index 1 by explicitly declaring
fifo_payload to be a VLA at the end of icm45686_encoded_data.

Signed-off-by: Anthony Williams <[email protected]>
@anthony289478
Copy link
Contributor Author

dceeaef fixes the sonarqubecloud error

Access of the field 'fifo_payload' at index 1, while it holds only a single 'struct icm45686_encoded_fifo_payload' element

@ubieda
Copy link
Member

ubieda commented Oct 17, 2025

I don't mean to veer off the PR topic, but I wonder if we should add a size_t len next to the const uint8_t *buffer on the Decoder Decode API:

struct sensor_decoder_api {

Feels like, even though this is typically encoded in the data, it'd be safer to not entirely rely on the data when deciding how far to go pass the edata address (e.g: a bunch of 0xFF's in a corrupted buffer).

What do you think? @teburd @MaureenHelm @yperess

Copy link

@yperess
Copy link
Contributor

yperess commented Oct 17, 2025

I don't mean to veer off the PR topic, but I wonder if we should add a size_t len next to the const uint8_t *buffer on the Decoder Decode API:

struct sensor_decoder_api {

Feels like, even though this is typically encoded in the data, it'd be safer to not entirely rely on the data when deciding how far to go pass the edata address (e.g: a bunch of 0xFF's in a corrupted buffer).

What do you think? @teburd @MaureenHelm @yperess

I'll need to go back and double check, but I think there was a reason for that. I seem to recall that it was hard or useless to guarantee the size at the decode phase. I'm not opposed to it though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants