A walkthrough of debugging a TSL2591 light sensor driver initialization failure on an STM32L4 Discovery IoT node running Zephyr RTOS. Using `west debug` and GDB, the author traces the failure from the sensor init function down through Zephyr's I2C subsystem into the STM32 I2C controller driver. Disabling compiler optimizations (`CONFIG_NO_OPTIMIZATIONS=y`) makes stepping reliable. Inspecting the `data` struct reveals `is_nack=1` after a software reset write — the device doesn't ACK immediately after reset. The fix treats the post-reset NACK as non-fatal by ignoring the return code, consistent with Adafruit's Arduino driver and the Linux kernel driver. The fix was submitted as a PR and accepted upstream into the Zephyr project.

10m read timeFrom embeddedrelated.com
Post cover image
Table of contents
IntroductionReproducing The ErrorUsing GDB
3 Impressions