Skip to content

Day19 - I2C Sensor Driver

Summary

Implemented a complete I2C sensor driver using:

  • STM32 as I2C slave
  • Raspberry Pi as Linux host

Successfully built a register-based sensor model and exposed it via sysfs.


What I Learned

  • How Linux I2C driver works (probe/remove)
  • Device Tree binding for I2C devices
  • sysfs interface design principles
  • Difference between data plane and control plane
  • Importance of machine-readable kernel interfaces
  • Synchronization using mutex

Key Insights

  • sysfs is an API, not a UI
  • kernel should not format human-readable values
  • register-based design makes driver scalable
  • separating control and data improves clarity

Issues Encountered

1. Device Tree reg warning

  • Cause: missing #address-cells / #size-cells
  • Fix: explicitly define them

2. Overlay memory leak warning

OF: overlay: WARNING: memory leak will occur if overlay removed
  • Cause: modifying existing node properties
  • Impact: harmless for lab use

3. Temperature format mistake

Initially used:

25.29

Corrected to:

25290

Reason:

  • align with Linux hwmon standard
  • ensure machine-readable format

Result

  • Fully working I2C driver
  • Stable sysfs interface
  • Clean architecture

Next

  • Convert driver to hwmon subsystem
  • Learn standard sensor interface