VL53L4CD ULD – CalibrateXtalk() wraps negative crosstalk to ~65k, invalidating all subsequent ranging
Hi,
We found an issue in VL53L4CD_CalibrateXtalk() (ULD v2.2.2, as shipped in X-CUBE-TOF1 v3.4.3).
When the measured average distance is slightly greater than the target distance, the computed crosstalk is negative:
c
tmp_xtalk = (float_t)1.0 - (AvgDistance/TargetDistance);
tmp_xtalk *= (AverageSignal/AverageSpadNb);The function only checks the upper bound (tmp_xtalk > 127.0). It then casts the negative float to uint16_t, which is undefined behavior in C. On our platform the value wraps. For example, −3 kcps is returned as 65533 and reported as a successful calibration, and the register is written with 64000, which corresponds to about 125 kcps.
With that value applied, crosstalk compensation removes nearly the entire return signal: 125 kcps/SPAD × 77 SPADs ≈ 9,600 kcps, against a raw signal of about 9,700 kcps. Every subsequent measurement fails with "signal below threshold" (range_status 2, distance 8191 mm).
Setup: offset calibrated at 100 mm, then crosstalk calibration on a white target at 200 mm, 10 samples. The issue is intermittent: a repeated calibration sometimes returns a small positive value and ranging works normally.
We understand that 200 mm on a white target is not the recommended calibration condition. Even so, the function should handle that case safely rather than leave the sensor unusable.
Thanks,
Ondrej Pilat
