zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.92k stars 6.65k forks source link

Sensing subsystem: SPI timeout when reading data from sensor #78169

Open mimok opened 2 months ago

mimok commented 2 months ago

Describe the bug

I'm using a Thingy91 board (nrf9160) and I want to read samples from the on-board ADXL362 acceleremoter using the new sensing subsystem. I updated my dts overlay accordingly.

Every time, the subsystem tries to read a sample from the sensor, there is a communication timeout on the SPI bus.

To Reproduce

I believe this behavior can be reproduced with any real board (not the native simulator) and any real accelerometer.

Expected behavior

Data should be read from the sensor.

Impact

Sensing subsystem is not working properly on my device and i cannot use it.

Origin of the bug

By digging into the code, i can see that the function phy_3d_sensor_submit() is a blocking function while it should be a non blocking function as explained in the documentation . Indeed, it calls the blocking sensor_sample_fetch_chan() function.

In addition, there is a TODO comment in the file sensor_mgmt.c showing that the problem is actually known (or at least expected).

I did a quick test by putting the call to sensor_read() in a work executed by the system work queue and it works. That shows that the problem actually comes from calling a blocking function from the ISR handler sensing_sensor_polling_timer().

I know this part of the code has been updated between v3.6.0 (that i'm using) and v3.7.0 but i believe the problem is still there.

Environment (please complete the following information):

I'm using a Thingy91 board (nrf9160) with sensor ADXL362. I'm using Nordic SDK v2.7.0 based on Zephyr OS v3.6.0

mmahadevan108 commented 2 months ago

@mimok, can you reproduce this issue with the latest Zephyr upstream main branch

mimok commented 2 months ago

@mmahadevan108, I did the test by using the thingy91 BSP from the nordic' SDK with the lastest commit from the main branch of the vanilla Zephyr and the problem is stille there.

I was expecting this behavior given that phy_3d_sensor_submit() still call the blocking function sensor_sample_fetch_chan().

github-actions[bot] commented 1 week ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.