Skip to content

Latest commit

 

History

History
139 lines (93 loc) · 9.58 KB

DeviceTreeExperiments.md

File metadata and controls

139 lines (93 loc) · 9.58 KB

Device Tree Experiments

I wanted to experiment with the character device API for GPIO, so I installed gpiod on my RPi 3B+/bullseye. I hit a snag with my first command:

$ sudo apt-get install gpiod
# ...
$ gpioinfo
gpiochip0 - 54 lines:
	line   0:      unnamed       unused   input  active-high
	line   1:      unnamed       unused   input  active-high
	line   2:      unnamed       unused   input  active-high
	line   3:      unnamed       unused   input  active-high
...
	line  52:      unnamed       unused   input  active-high
	line  53:      unnamed       unused   input  active-high
gpiochip1 - 8 lines:
	line   0:      unnamed       unused  output  active-high
	line   1:      unnamed       unused  output  active-high
	line   2:      unnamed       "led1"  output   active-low [used]
	line   3:      unnamed       unused  output  active-high
	line   4:      unnamed       unused   input  active-high
	line   5:      unnamed "cam1_regulator" output active-high [used]
	line   6:      unnamed       unused  output  active-high
	line   7:      unnamed       unused   input  active-high

Every line being listed as unnamed didn't look like a promising start. On my RPi 4B however, all the lines had pin names. Some research turned up a discussion on GitHub explaining the cause for this: no updates had been made for older RPi models.

A link was given to a source for the RPi 3B+ dts file, and it was suggested that anyone interested in pin names for an unsupported model was welcome to update the dts file & recompile it with a kernel that would read it properly. This sounded like a fair amount of work for a lazy man, and I wondered if it might be easier to add the pin names with a device tree overlay? I decided to try:

I've been curious about the device tree for a while, but my only experience with it has been limited to adding an occasional overlay specification to /boot/config.txt. Some overlays have piqued my curiosity, and motivated me - briefly - to learn more, but after looking at the overlay source code, that motivation melted - the code struck me as impenetrably arcane. And getting smacked down on the RPi forum didn't help either. But sometimes, disparaging remarks are motivational, and finally - trial and error yielded a result that seems to get the job done - an overlay that adds pin names to the RPi 3b+ :

The following suggests that this overlay seems to work! Copy the source file to your RPi 3B+, and follow these steps to compile, add and test it:

$ dtc -@ -Hepapr -I dts -O dtb -o 3BPpin_nm.dtbo 3BP_pin_name_overlayRev1.dts 
$ sudo cp 3BPpin_nm.dtbo /boot/overlays 

# Add the following line to `boot/config.txt`: 
dtoverlay=3BPpin_nm
#
$ sudo reboot 
... # following the reboot: 
$ gpioinfo
gpiochip0 - 54 lines:
	line   0:     "ID_SDA"       unused   input  active-high
	line   1:     "ID_SCL"       unused   input  active-high
	line   2:       "SDA1"       unused   input  active-high
	line   3:       "SCL1"       unused   input  active-high
...
	line  52: "SD_DATA2_R"       unused   input  active-high
	line  53: "SD_DATA3_R"       unused   input  active-high
gpiochip1 - 8 lines:
	line   0:      "BT_ON"       unused  output  active-high
	line   1:      "WL_ON"       unused  output  active-high
	line   2:  "PWR_LED_R"       "led1"  output   active-low [used]
	line   3:    "LAN_RUN"       unused  output  active-high
	line   4:         "NC"       unused   input  active-high
	line   5:  "CAM_GPIO0" "cam1_regulator" output active-high [used]
	line   6:  "CAM_GPIO1"       unused  output  active-high
	line   7:         "NC"       unused   input  active-high

If you encounter any issues adapting this to your model of RPi, make a comment in the Issues section here. I may or may not be able to help, but promise you won't get a smackdown!


REFERENCES & NOTES:

Nothing particularly useful for others here, but I added this for my benefit since the device tree coding, syntax and resources are not very well documented in the RPi documentation (IMHO).

  1. Device Tree What it Is
  2. Device Tree Reference
  3. Linux and the Devicetree
From an end-to-end review of the Device Tree forum, some items that attracted my attention: