Custom Device Tree Overlays
Configure the AM335x Device Tree to enable analogue inputs and PWM outputs on the BeagleBone Black. You will inspect the running tree, create a custom overlay, validate it before enabling it at boot, and verify the exposed hardware interfaces.
Practical Checklist
This chapter shows why and how to use a Device Tree overlay to enable:
- ADC (TSCADC -> IIO)
- EHRPWM1 on P9_14 / P9_16
1. Why overlays?
On AM335x, many header pins are multiplexed (GPIO, UART, I²C, SPI, PWM, …).
The base DTB enables only a safe subset.
Overlays are “patches” you can apply at boot (or at runtime with configfs) to:
- turn blocks on (
status = "okay") - apply pinmux (select a peripheral mode on a pad)
- avoid pin conflicts on your board
This keeps the kernel generic and your board configuration explicit and reproducible.
2. Pinmux math for P9_14 / P9_16
The AM335x control module exposes pad registers starting at 0x44E1_0800.
The pinctrl-single,pins entries use offset = absolute - 0x0800:
- P9_14 =
gpmc_a2, abs =0x0848-> offset0x048 - P9_16 =
gpmc_a3, abs =0x084C-> offset0x04C
For both pins, MODE = 6 selects ehrpwm1A/B.
3. Check for Device Tree compatibility
-
Run the following the command to see what device tree we have, because we don't want to create an overlay with the wrong tree - or we will run into boot errors.
tr '\0' '\n' </proc/device-tree/compatible -
Hopefully you should see:
ti,am335x-bone-black ti,am335x-bone ti,am33xx
4. Checking live.dts
-
Dump the currently running tree in to a file
live.dtswe can viewsudo dtc -I fs -O dts /sys/firmware/devicetree/base > live.dts 2>/dev/null -
You will then see that the compatible boards we found earlier should match those in this
live.dtsconfirming that board type is correct.grep -m1 -w compatible live.dtscompatible = "ti,am335x-bone-black\0ti,am335x-bone\0ti,am33xx";\0is anullterminator which is the separator for each board type
5. Check labels in your live DT
Now you will target well-known labels so the overlay binds on the image.
-
Create a folder in your
homedirectorydtsand within that a file calleddevice-tree.shthat prints the Device Tree symbol labels and the paths they resolve to in the live tree:# List symbols we care about ls /proc/device-tree/__symbols__ | egrep 'am33|epwmss1|ehrpwm1|tscadc' || true # Print each symbol -> its target path for s in am33xx_pinmux epwmss1 ehrpwm1 tscadc; do f="/proc/device-tree/__symbols__/$s" if [ -f "$f" ]; then printf "%-14s -> %s\n" "$s" "$(tr -d '\0' < "$f")" else echo "$s (missing)" fi done -
Run it:
bash dts/device-tree.sham335x_adc am33xx_pinmux ehrpwm1 ehrpwm1_tbclk epwmss1 tscadc am33xx_pinmux -> /ocp/interconnect@44c00000/segment@200000/target-module@10000/scm@0/pinmux@800 epwmss1 -> /ocp/interconnect@48000000/segment@300000/target-module@2000/epwmss@0 ehrpwm1 -> /ocp/interconnect@48000000/segment@300000/target-module@2000/epwmss@0/pwm@200 tscadc -> /ocp/interconnect@44c00000/segment@200000/target-module@d000/tscadc@0
6. Create the overlay (ADC + PWM1)
-
Create the file:
dts/BB-ADC-PWM-00A0.dtsnano dts/BB-ADC-PWM-00A0.dts/dts-v1/; /plugin/; /* Enable AM335x ADC (TSCADC) and EHRPWM1 -> P9_14/P9_16 (MODE 6). */ &{/} { compatible = "ti,am335x-bone-black","ti,am335x-bone", "ti,am33xx"; part-number = "BB-ADC-PWM"; version = "00A0"; }; /* Pinmux controller (am33xx_pinmux). * Pad offsets are (absolute - 0x0800): * P9_14: gpmc_a2 abs 0x0848 -> off 0x048 -> MODE=6 (ehrpwm1A) * P9_16: gpmc_a3 abs 0x084C -> off 0x04C -> MODE=6 (ehrpwm1B) */ &am33xx_pinmux { bb_pwm1_pins: pinmux_bb_pwm1_pins { pinctrl-single,pins = < 0x048 0x06 /* P9_14 -> ehrpwm1A */ 0x04C 0x06 /* P9_16 -> ehrpwm1B */ >; }; }; /* Ensure the PWMSS1 subsystem and its TBCLK are enabled */ &epwmss1 { status = "okay"; }; &ehrpwm1_tbclk { status = "okay"; }; /* Bind the pins to EHRPWM1 */ &ehrpwm1 { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&bb_pwm1_pins>; }; /* Enable ADC (tscadc) and expose AIN0..AIN6 */ &tscadc { status = "okay"; adc { ti,adc-channels = <0 1 2 3 4 5 6>; }; };Explanation of the dts file...
- Header:
- Declares this file as a Device Tree Source (v1) and marks it as a plugin (overlay) rather than a full base tree.
/dts-v1/;— required for all modern DTS files./plugin/;— instructs the compiler to include symbol references (__symbols__) so this file can patch an existing live tree./dts-v1/; /plugin/;
- Root Node Overlay:
- This fragment doesn’t modify hardware; it adds metadata used by the kernel and bootloader.
compatible— ensures the overlay only applies to matching boards (BeagleBone Black and related AM335x variants).part-number— used by the cape manager /configfssystem to identify the overlay.version— overlay revision (helps in debugging and upgrade control).
- Effectively this section declares “this overlay is safe to load on a BeagleBone Black.”
/* Enable AM335x ADC (TSCADC) and EHRPWM1 -> P9_14/P9_16 (MODE 6). */ &{/} { compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx"; part-number = "BB-ADC-PWM"; version = "00A0"; }; - This fragment doesn’t modify hardware; it adds metadata used by the kernel and bootloader.
-
Pinmux Configuration
-
Each AM335x pad can serve multiple functions (GPIO, UART, PWM, etc.).
-
&am33xx_pinmux— references the global pinmux controller node. -
pinmux_bb_pwm1_pins— a custom pin group we define here. -
pinctrl-single,pins— a list of pad offsets and mode values.
Pad Physical Pin Offset Mode Function Description gpmc_a2P9_14 0x048 6 ehrpwm1APWM channel A gpmc_a3P9_16 0x04C 6 ehrpwm1BPWM channel B - Mode 6 selects the PWM peripheral function for those pads.
/* * Pinmux controller (am33xx_pinmux) * Pad offsets are (absolute - 0x0800): * P9_14: gpmc_a2 abs 0x0848 -> off 0x048 -> MODE=6 (ehrpwm1A) * P9_16: gpmc_a3 abs 0x084C -> off 0x04C -> MODE=6 (ehrpwm1B) */ &am33xx_pinmux { bb_pwm1_pins: pinmux_bb_pwm1_pins { pinctrl-single,pins = < 0x048 0x06 /* P9_14 -> ehrpwm1A */ 0x04C 0x06 /* P9_16 -> ehrpwm1B */ >; }; }; -
-
PWM Subsystem Enablement
-
The
AM335xhas three PWM Subsystems (PWMSS0–2), each containing anEHRPWM,ECAP, andEQEPblock. -
&epwmss1— enables the PWM Subsystem 1 (normally disabled by default). -
&ehrpwm1_tbclk— ensures the Time Base Clock forPWM1is active.- Without this clock, the PWM registers can’t be written or toggled.
-
Setting
status = "okay";tells the kernel to probe and register these devices.
/* Ensure the PWMSS1 subsystem and its TBCLK are enabled */ &epwmss1 { status = "okay"; }; &ehrpwm1_tbclk { status = "okay"; }; -
-
PWM Node Binding
-
This connects the pinmux group defined earlier (
bb_pwm1_pins) to the actual PWM driver node. -
&ehrpwm1— symbolic label for thePWM1peripheral insideepwmss1. -
pinctrl-names/pinctrl-0— standard Linux convention for naming and linking pin control states. -
status = "okay";— ensures this PWM channel appears under/sys/class/pwm/.
/* Bind the pins to EHRPWM1 */ &ehrpwm1 { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&bb_pwm1_pins>; }; -
-
ADC (TSCADC) Enablement
-
The TSCADC (Touchscreen Controller + ADC) block on the AM335x provides up to 8 analog channels (AIN0–AIN7).
-
&tscadc— symbolic label for the ADC node in the base tree. -
status = "okay";— powers up and registers the IIO ADC driver. -
adc { ti,adc-channels = <0 … 6>; }— exposes seven analog inputs (AIN0–AIN6).- AIN7 is typically reserved for the on-chip temperature sensor.
/* Enable ADC (tscadc) and expose AIN0..AIN6 */ &tscadc { status = "okay"; adc { ti,adc-channels = <0 1 2 3 4 5 6>; }; }; -
- Header:
7. Compile to .dtbo
-
Run the following command:
sudo dtc -@ -I dts -O dtb -o /boot/dtbs/$(uname -r)/overlays/BB-ADC-PWM-00A0.dtbo dts/BB-ADC-PWM-00A0.dts
8. Validate the overlay
-
Run a merge test without rebooting:
sudo fdtoverlay -i /boot/dtbs/$(uname -r)/am335x-boneblack.dtb -o /tmp/merged.dtb -v /boot/dtbs/$(uname -r)/overlays/BB-ADC-PWM-00A0.dtboecho "rc=$?"; ls -lh /tmp/merged.dtbrc=0 -rw-r--r-- 1 root root 98K May 28 11:10 /tmp/merged.dtb- If
rc=0and/tmp/merged.dtbhas a size > 100 kB, the overlay merged cleanly.
- If
-
Inspect key nodes:
sudo dtc -I dtb -O dts -o /tmp/merged.dts /tmp/merged.dtbgrep -n 'status = "okay"' /tmp/merged.dts | head1093: status = "okay"; 1122: status = "okay"; 1143: status = "okay"; 1149: status = "okay"; 1286: status = "okay"; 1563: status = "okay"; 1881: status = "okay"; 2106: status = "okay"; 2247: status = "okay"; 2566: status = "okay";epwmss1,ehrpwm1_tbclk,ehrpwm1, andtscadcmarked"okay"
9. Enabling for next boot
-
Run the following commands to have the overlay persistent on boot
echo 'enable_uboot_overlays=1' | sudo tee -a /boot/uEnv.txtecho 'uboot_overlay_addr4=/boot/dtbs/6.12.28-bone25/overlays/BB-ADC-PWM-00A0.dtbo' | sudo tee -a /boot/uEnv.txt -
Now you can reboot
sudo reboot
10. Verify it worked
-
Once rebooted (this make take a minute before ssh gets a response) and logged in run the following:
ls /sys/bus/iio/devicesiio:device0 -
Then run this command to see
adcdevicegrep -H . /sys/bus/iio/devices/iio:*/name/sys/bus/iio/devices/iio:device0/name:TI-am335x-adc.0.auto -
PWM should also appear under
/sys/class/pwm/tree -d /sys/class/pwm/**- /sys/class/pwm/pwmchip0/
- device -> ../../../48302200.pwm
- power
- pwm0
- power
- pwm1
- power
- subsystem -> ../../../../../../../../../../class/pwm
- /sys/class/pwm/pwmchip0/