drivers: sensors: Add official ST library for vl53l5cx#23
Conversation
409a684 to
8fdc319
Compare
Thanks. Please ping us once it's ready for review |
|
@faxe1008 Is this PR still in your plans ? |
|
Hey @erwango, yeah so I did some work on the zephyr side for this: But for some reason part of the initialization fails: The plattform abstraction for the I2C seems to be working - I can read the sensor ID and the other operations prior to reading the NVM data in the init method seem to work. It's not really evident to me why this happens. Need to see if I can use a working refrence implementation and see what is happening there. So yeah, I'd love to continue on this one gotta find some time and a lead to fix up the init sequencing though. |
Hi @faxe1008, I gave a try with this PR and the related Zephyr commit you pointed as well from your repo. I also faced the same NVM data init, but it turns out that that the issue is in the WrMulti function in which there is a typo. diff --git a/drivers/sensor/st/vl53l5cx/vl53l5cx_platform.c b/drivers/sensor/st/vl53l5cx/vl53l5cx_platform.c
index e5ceeddb8f9..e5fec09993e 100644
--- a/drivers/sensor/st/vl53l5cx/vl53l5cx_platform.c
+++ b/drivers/sensor/st/vl53l5cx/vl53l5cx_platform.c
@@ -33,7 +33,7 @@ uint8_t WrMulti(VL53L5CX_Platform *p_platform, uint16_t RegisterAdress, uint8_t
{.buf = p_values, .len = size, .flags = I2C_MSG_WRITE | I2C_MSG_STOP},
};
- if (i2c_transfer_dt(&p_platform->i2c, msg, size) < 0) {
+ if (i2c_transfer_dt(&p_platform->i2c, msg, 2) < 0) {
return VL53L5CX_STATUS_ERROR;
}I am using this on the STM32N6570_DK board. Since there is quite a large amount of registers to set during the init, leading to having quite long (in time) i2c transaction. Depending on the I2C bus speed, this can take a little while, leading to timeout of the I2C STM32 driver which has a default limit in time. To overcome it it is thus necessary to change the default timeout value and increase it via the Kconfig CONFIG_I2C_STM32_TRANSFER_TIMEOUT_MSEC. With that done, I am able to get the initialization working fine and also getting result_data which do not seem too wrong. So, idea now is thus to add more stuff in the driver and expose the captured value via the sensor interface. After this PR have you been able to improve / debug also this issue in which case do you have already a more recent version of the code ? |
|
I have not put much more effort into this, happy if this gave you anplace to start though. Feel free to pick it up 😀 Maybe the firmware upload needs to be guarded by a kconfig as this is also quite hefty in regards to flash... |
|
@faxe1008 I have improved the Zephyr part for this TOF and will push the updates enabling this TOF on Zephyr. I will make the west.yaml point to this hal_st update. Currently this is outdated so would you be able to simply rebase this PR on top of the head of hal_st ? |
|
@avolmat-st sure, rebased and resolved the conflict. |
|
Thanks a lot @faxe1008 !! |
|
|
||
| In order to use this library, you have to: | ||
| * define CONFIG_HAS_STLIB and CONFIG_VL53L5CX | ||
| * include vl53l5cx_api.h and vl53l1_platform.h in the driver .h |
There was a problem hiding this comment.
| * include vl53l5cx_api.h and vl53l1_platform.h in the driver .h | |
| * include vl53l5cx_api.h and vl53l5_platform.h in the driver .h |
There was a problem hiding this comment.
To be updated and doesn't seem to be inline with changes done in https://github.com/zephyrproject-rtos/zephyr/pull/105238/changes
9c1a2b4 to
e3ed50f
Compare
|
@avolmat-st @erwango updated the pr with the latest version from sts page. |
|
Thanks @faxe1008. I just gave it a try. I had to perform few updates in the PR to have it work. diff --git a/CMakeLists.txt b/CMakeLists.txt
index eceb3f95..683d8fc9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,8 @@ zephyr_include_directories(audio/microphone)
zephyr_library_sources(audio/microphone/OpenPDMFilter.c)
endif()
+endif()
+
# STMEMSC - Hardware Abstraction Layer for ST sensor
add_subdirectory_ifdef(CONFIG_HAS_STMEMSC sensor/stmemsc)
diff --git a/sensor/vl53l5cx/api/inc/vl53l5cx_api.h b/sensor/vl53l5cx/api/inc/vl53l5cx_api.h
index 0e870ac0..40c32c68 100644
--- a/sensor/vl53l5cx/api/inc/vl53l5cx_api.h
+++ b/sensor/vl53l5cx/api/inc/vl53l5cx_api.h
@@ -19,7 +19,7 @@
-#include "platform.h"
+#include "vl53l5cx_platform.h"^M
/**
* @brief Current driver version.
diff --git a/sensor/vl53l5cx/api/inc/vl53l5cx_buffers.h b/sensor/vl53l5cx/api/inc/vl53l5cx_buffers.h
index 35eaff8b..8cc3007f 100644
--- a/sensor/vl53l5cx/api/inc/vl53l5cx_buffers.h
+++ b/sensor/vl53l5cx/api/inc/vl53l5cx_buffers.h
@@ -15,7 +15,7 @@
#ifndef VL53L5CX_BUFFERS_H_
#define VL53L5CX_BUFFERS_H_
-#include "platform.h"
+#include "vl53l5cx_platform.h"
/**
* @brief Inner internal number of targets.
An endif is missing in the CMakeLists.txt. I am cleaning up the Zephyr PR to use that new version of the HAL driver as well as expose all distance values. |
Adds the official ST library for the vl53l5cx tof sensor. Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
|
I updated the PR :^) |
avolmat-st
left a comment
There was a problem hiding this comment.
LGTM. Tested with PR zephyrproject-rtos/zephyr#105238
|
Aside from @erwango comment: I had something like this: To allow Zephyr to place firmware or xtalk buffers into a specific DMAble memory region. IIRC (this was a year or so ago at this point) I did that to help with I2C transfer speed. Any thoughts @avolmat-st ? |
|
@faxe1008 indeed, maybe that's good to test. Since it takes a little while to upload via I2C I had to increase the i2c timeout to allow properly booting. |
|
@faxe1008 I performed some more test using I2C / DMA and I was able to use it without having to place the data into a specific buffer. I didn't have to put the code into a specific area for that purpose (at least on the which is the platform I am using now) |
Adds the official ST library for the vl53l5cx tof sensor.
Will open the corresponding zephyr driver PR soonish.