Where do I find PWM device address mappings?

Hi all,

I’m trying to use the PWM outputs on my beaglebone and have a question about working out which pwmchip device a pin maps to.

After figuring out the steps to get the PWM overlays working with u-boot (as most tutorials are still referring to cape manager), I was struggling with getting a PWM output working using standard shell commands (echoing values to duty_cycle, period, enabled etc.) I came across this nugget of information on a blog post:

“EHRPWM1 is under PWMSS1 which has address 0x48302000 and can be seen under pwmchip0.”

When I list the contents of my /sys/class/pwm directory I get the following:

root@beaglebone:/sys/class/pwm# ls -la
total 0
drwxrwxr-x 2 root pwm 0 Jan 1 2000 .
drwxr-xr-x 59 root root 0 Jan 1 2000 …
lrwxrwxrwx 1 root pwm 0 Nov 3 2016 pwmchip0 → …/…/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0
lrwxrwxrwx 1 root pwm 0 Nov 3 2016 pwmchip1 → …/…/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip1
lrwxrwxrwx 1 root pwm 0 Nov 3 2016 pwmchip3 → …/…/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip3
lrwxrwxrwx 1 root pwm 0 Nov 3 2016 pwmchip5 → …/…/devices/platform/ocp/48304000.epwmss/48304100.ecap/pwm/pwmchip5
lrwxrwxrwx 1 root pwm 0 Nov 3 2016 pwmchip6 → …/…/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip6

Note that in my system the device that maps to 0x48302000 is actually pwmchip3, not pwmchip0 as in the blog post. Once I established that I got things working.

My question is - where do I find the information that tells me that EHRPWM1 is under PWMSS1 which has address 0x48302000? I’ve had a hunt through the am3358 datasheet and can’t see it there. Can anyone point me in the right direction please?

Many thanks,
James Fitzsimons

Here you go:

https://github.com/beagleboard/bb.org-overlays/blob/master/examples/cape-unversal-pwm.txt#L13-L18

Regards,

Hi Robert,

Thanks so much for your speedy response!

Just to confirm then - I understand from the comment at the top of that file “#PWM’s change on every bootup:” that my C++ driver code is going to have to list the contents of each of the epwmss device directories (e.g. /sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/) to get the pwmchipXX mapping to use on each boot?

Cheers,
James Fitzsimons

Actually you don't have to fall back to "/sys/class/pwm/pwmchipX" just
keep moving down the path:
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip*/<here>"

PS, borrow what you can from this project, it's a python project with
c files doing the low level.

https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/source/c_pwm.c

and just watch out for the

pwmchip0/pwm1 -> pwmchip0/pwm-0:1

that occurs in all our v4.11.x+ kernels and some of the newest
"v4.9.x" based kernels.. (it was done so udev would work on giving
the normal user permissions)..

Regards,