2
votes

There is very little information how to configure the Beaglebone for PWM on newer versions of the kernel. Past instructions for interfacing with PWM through the slots file are obsolete, as the slots file and bone_capemgr are disabled in v4.14 of the kernel.

How do I configure PWM for BeagleBone Black with the new kernel? I am using a TI AM335x BeagleBone Black Wireless running kernel version 4.14.37-ti-r46.

2

2 Answers

3
votes

As mentioned in the question, the slots file and bone_capemgr are disabled in v4.14 of the kernel in favor of U-Boot overlays.

As explained in a response by the BeagleBone kernel developer, U-Boot now handles the overlays and automatically enables the equivalent of cape_enable=bone_capemgr.enable_partno=univ-all,BB-ADC,BB-PWM0,BB-PWM1,BB-PWM2:

All 5 of those are enabled out of the box with the images now shipping under:

https://beagleboard.org/latest-images

For the pwm's make sure to reference https://github.com/beagleboard/bb.org-overlays/blob/master/examples/cape-unversal-pwm.txt and the config-pin pwm <pin#>..

Therefore, the PWM interface is already configured! Now just export and use the PWM. For example to access pwm0:

root@beaglebone:~# cd /sys/class/pwm/pwmchip0
root@beaglebone:/sys/class/pwm/pwmchip0# ls
device  export  npwm  power  subsystem  uevent  unexport

root@beaglebone:/sys/class/pwm/pwmchip0# echo 0 > export
root@beaglebone:/sys/class/pwm/pwmchip0# ls
device  export  npwm  power  pwm-0:0  subsystem  uevent  unexport

root@beaglebone:/sys/class/pwm/pwmchip0# ls pwm-0:0
capture  device  duty_cycle  enable  period  polarity  power  subsystem  uevent

Note: you might need to disable HDMI with disable_uboot_overlay_video=1 in /boot/uEnv.txt if the pins are already in use.

To determine the pin mapping for the PWM interfaces, see my follow-up post PWM chip to pin mapping on BeagleBone Black (v4.14).

1
votes

The last image (Debian 10.3 buster) of debian for the BeagleBone give us the next pin mapping for the pwm outputs:

P8.13 corresponds to folder: /sys/class/pwm/pwm-6:1
P8.19 corresponds to folder: /sys/class/pwm/pwm-6:0
P9.14 corresponds to folder: /sys/class/pwm/pwm-3:0
P9.16 corresponds to folder: /sys/class/pwm/pwm-3:1
P9.21 corresponds to folder: /sys/class/pwm/pwm-1:1
P9.22 corresponds to folder: /sys/class/pwm/pwm-1:0

The default period for P8.13, P8:19, P9.14, and P9.16 is 500000. On the other hand, the default period for P9.21 and P9.22 is 20000.

The key to work with the PWM is the next instruction, which is mentioned in the link posted in the last post about the pin mapping for the PWM interfaces:

config-pin P8.13 pwm
config-pin P8.19 pwm
config-pin P9.14 pwm
config-pin P9.16 pwm
config-pin P9.21 pwm
config-pin P9.22 pwm

After doing that, make this for all desired PWM outputs:

debian@beaglebone:~$ cd /sys/class/pwm/pwm-6:1
debian@beaglebone:~$ echo 250000 > duty_cycle
debian@beaglebone:~$ echo 1 > enable