Skip to content

lsm6dso sensor driver not working on nRF5340 #33440

@richardbarlow

Description

@richardbarlow

Describe the bug
The LSM6DSO sensor driver does not function on the nRF5340 SoC. This appears to be the exact same problem as outlined in #11612, which was fixed for the LIS2DH in #19901 and issue #20154 was created as a 'marker' issue to reference when implementing the workaround.

The issue is that on the nRF51, nRF52 and nRF53 it is impossible to correctly implement the i2c_burst_write() API, which means that it is not cross-platform. What should be executed as a single I2C transaction ends up split with a repeated start. #17801 indicates that using the TWI, rather than TWIM peripheral may fix this, but the nRF53 only has TWIM.

Having applied the workaround noted in #20154 (comment) to drivers/sensor/lsm6dso/lsm6dso_i2c.c the sensor functions correctly.

I could submit a pull-required that adds this workaround into the LSM6DSO driver, however I feel that will be doing the world a disservice. The i2c_burst_write() API is used all over the place and I would prefer to prevent others like myself from falling into the same trap (and wasting a day tracking down the issue) when using any of the sensor drivers.

The LSM6DSO driver, uses the stmemsc library (https://github.com/zephyrproject-rtos/hal_st/tree/master/sensor/stmemsc). I haven't checked exhaustively, but I'm guessing that all of the other ST MEMS sensors drivers do the same. This library requires a read and write function to be provided to perform the actual read/write operations over the relevant hardware interface. Each Zephyr sensor driver that uses the stmemsc appears to have its own identical implementation of the read/write functions. Currently these functions are relatively simple and, in the case of the I2C write implementation, all buggy. One way of fixing the issue that I am encountering would be to apply the workaround to each of the write functions, but I think it would be better to factor these functions out somehow. Unfortunately this is at the limits of my experience with Zephyr and its architecture and I would appreciate some advice on how I might go about doing this. In particular the stmemsc library passes an opaque pointer through to the read/write functions and each sensor driver uses its own _data object. If the read/write functions were generalised then a similarly generalised type would need for the handle.

It is also of note that the fix made in #19901 for the LIS2DH was undone by 1ebb708, which presumably means it's broken again when using it with an nRF51/2/3 SoC.

Environment (please complete the following information):

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions