Skip to content

drivers: sensors: Add official ST library for vl53l5cx#23

Open
faxe1008 wants to merge 1 commit into
zephyrproject-rtos:masterfrom
faxe1008:vl53l5cx
Open

drivers: sensors: Add official ST library for vl53l5cx#23
faxe1008 wants to merge 1 commit into
zephyrproject-rtos:masterfrom
faxe1008:vl53l5cx

Conversation

@faxe1008
Copy link
Copy Markdown

@faxe1008 faxe1008 commented Nov 6, 2024

Adds the official ST library for the vl53l5cx tof sensor.

Will open the corresponding zephyr driver PR soonish.

@faxe1008 faxe1008 force-pushed the vl53l5cx branch 2 times, most recently from 409a684 to 8fdc319 Compare November 14, 2024 09:17
@erwango erwango requested review from avisconti and erwango November 19, 2024 07:44
@erwango
Copy link
Copy Markdown
Member

erwango commented Nov 19, 2024

Will open the corresponding zephyr driver PR soonish.

Thanks. Please ping us once it's ready for review

@erwango
Copy link
Copy Markdown
Member

erwango commented Mar 3, 2025

@faxe1008 Is this PR still in your plans ?

@faxe1008
Copy link
Copy Markdown
Author

faxe1008 commented Mar 3, 2025

Hey @erwango,

yeah so I did some work on the zephyr side for this:
faxe1008/zephyr@caf5525

But for some reason part of the initialization fails:
8fdc319#diff-909a8a275d4d87c7f05a575c52f45e54f5319a6babbf41300bcec44590ffa712R363

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.
Besides that I wonder if the upload of the firmware does need to be part of init sequence, would hiding this behind a Kconfig flag be an accetable addition to cut down on flash usage?

So yeah, I'd love to continue on this one gotta find some time and a lead to fix up the init sequencing though.

@avolmat-st
Copy link
Copy Markdown

Hey @erwango,

yeah so I did some work on the zephyr side for this: faxe1008/zephyr@caf5525

But for some reason part of the initialization fails: 8fdc319#diff-909a8a275d4d87c7f05a575c52f45e54f5319a6babbf41300bcec44590ffa712R363

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. Besides that I wonder if the upload of the firmware does need to be part of init sequence, would hiding this behind a Kconfig flag be an accetable addition to cut down on flash usage?

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 ?
If no, I propose to rebase this PR and open a PR on the Zephyr side to work on the Zephyr driver, starting from your commits of course and adding some more bits to add ability to capture and report data.

@faxe1008
Copy link
Copy Markdown
Author

faxe1008 commented Mar 5, 2026

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...

@avolmat-st
Copy link
Copy Markdown

@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 ?
This is simply to avoid having to open another PR since I don't think I have the right to update this PR branch myself.
If you prefer I do this on my side, let me know.

@faxe1008
Copy link
Copy Markdown
Author

@avolmat-st sure, rebased and resolved the conflict.

@avolmat-st
Copy link
Copy Markdown

Thanks a lot @faxe1008 !!

Comment thread sensor/vl53l5cx/README Outdated
https://www.st.com/en/embedded-software/stsw-img007.html

Status:
version 1.0.7
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing v2.4.5 version on the st webpage. Can you x-check ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, my bad the issue is the st webpage provided. It should be:
https://www.st.com/en/embedded-software/stsw-img023.html.

Btw, it could be worth updating to the latest version (v2.0.1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @erwango for spotting the update. Indeed, having rapidly done the comparison, indeed there are changes to be applied.
@faxe1008, how do you wish to proceed ? Do you want to handle this on your side or do you want me to do the update ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do so tomorrow-ish

Comment thread sensor/vl53l5cx/README

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* include vl53l5cx_api.h and vl53l1_platform.h in the driver .h
* include vl53l5cx_api.h and vl53l5_platform.h in the driver .h

Comment thread sensor/vl53l5cx/README Outdated
https://www.st.com/en/embedded-software/stsw-img007.html

Status:
version 1.0.7
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, my bad the issue is the st webpage provided. It should be:
https://www.st.com/en/embedded-software/stsw-img023.html.

Btw, it could be worth updating to the latest version (v2.0.1)

Adds the official ST library for the vl53l5cx tof sensor.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
@faxe1008
Copy link
Copy Markdown
Author

@avolmat-st @erwango updated the pr with the latest version from sts page.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants