From e5c6cea199c28c0b461ae6c879ca8018b3f6c897 Mon Sep 17 00:00:00 2001 From: Igor Kolesnikov <29857897+IgorKolesnikov@users.noreply.github.com> Date: Sun, 12 Jul 2026 16:17:33 +0200 Subject: [PATCH] fix(drivers/bmi270): correct FIFO watermark byte calculation FIFO_WTM was computed as samples * sizeof(FIFO::Data), sizing the threshold from a single sensor's 6-byte frame instead of the actual 13-byte combined accel+gyro frame (1 header + 6 gyro + 6 accel) the FIFO actually stores. This made the watermark interrupt fire at the wrong byte count, so the published gyro_fifo rate and sample count no longer matched IMU_GYRO_RATEMAX. E.g. with IMU_GYRO_RATEMAX = 400 (expected: 4 samples per FIFO batch at 1600 Hz ODR -> 400 Hz publish), the driver instead published gyro_fifo at 600 Hz with 3 samples per batch. --- src/drivers/imu/bosch/bmi270/BMI270.cpp | 3 ++- src/drivers/imu/bosch/bmi270/Bosch_BMI270_registers.hpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/drivers/imu/bosch/bmi270/BMI270.cpp b/src/drivers/imu/bosch/bmi270/BMI270.cpp index 34e4b3d31f0e..3bb6abeea22c 100644 --- a/src/drivers/imu/bosch/bmi270/BMI270.cpp +++ b/src/drivers/imu/bosch/bmi270/BMI270.cpp @@ -530,7 +530,8 @@ void BMI270::ConfigureFIFOWatermark(uint8_t samples) { // FIFO_WTM: 13 bit FIFO watermark level value // unit of the fifo watermark is one byte - const uint16_t fifo_watermark_threshold = samples * sizeof(FIFO::Data); + // each combined accel+gyro frame is 1 header byte + 6 gyro bytes + 6 accel bytes + const uint16_t fifo_watermark_threshold = samples * (2 * sizeof(FIFO::Data) + FIFO::HEADER_SIZE); for (auto &r : _register_cfg) { if (r.reg == Register::FIFO_WTM_0) { diff --git a/src/drivers/imu/bosch/bmi270/Bosch_BMI270_registers.hpp b/src/drivers/imu/bosch/bmi270/Bosch_BMI270_registers.hpp index 29e008b62777..305543805ef1 100644 --- a/src/drivers/imu/bosch/bmi270/Bosch_BMI270_registers.hpp +++ b/src/drivers/imu/bosch/bmi270/Bosch_BMI270_registers.hpp @@ -181,6 +181,7 @@ enum ACC_PWR_CTRL_BIT : uint8_t { namespace FIFO { static constexpr size_t SIZE = 1024; +static constexpr size_t HEADER_SIZE = 1; // one header byte precedes each accel+gyro frame struct Data { uint8_t x_lsb;