• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

PWM on Beaglebone

Phishfry

Daemon

Thanks: 578
Messages: 2,054

#1
I am looking to use PWM on the GPIO pins. FreeBSD 10.x seems to offer sysctl settings for usage.
What is the mechanism for usage on FreeBSD 11.x ?
I am looking to drive an R/C servo.
Here are the BBB 10.4 settings:
Code:
root@beaglebone:~ # sysctl dev.am335x_pwm
dev.am335x_pwm.2.dutyB: 0
dev.am335x_pwm.2.dutyA: 0
dev.am335x_pwm.2.period: 1000
dev.am335x_pwm.2.freq: 100000
dev.am335x_pwm.2.clkdiv: 1
dev.am335x_pwm.2.%parent: simplebus0
dev.am335x_pwm.2.%pnpinfo: name=pwm@48304000 compat=ti,am335x-pwm
dev.am335x_pwm.2.%location:
dev.am335x_pwm.2.%driver: am335x_pwm
dev.am335x_pwm.2.%desc: AM335x PWM
dev.am335x_pwm.1.dutyB: 0
dev.am335x_pwm.1.dutyA: 0
dev.am335x_pwm.1.period: 1000
dev.am335x_pwm.1.freq: 100000
dev.am335x_pwm.1.clkdiv: 1
dev.am335x_pwm.1.%parent: simplebus0
dev.am335x_pwm.1.%pnpinfo: name=pwm@48302000 compat=ti,am335x-pwm
dev.am335x_pwm.1.%location:
dev.am335x_pwm.1.%driver: am335x_pwm
dev.am335x_pwm.1.%desc: AM335x PWM
dev.am335x_pwm.0.dutyB: 0
dev.am335x_pwm.0.dutyA: 0
dev.am335x_pwm.0.period: 1000
dev.am335x_pwm.0.freq: 100000
dev.am335x_pwm.0.clkdiv: 1
dev.am335x_pwm.0.%parent: simplebus0
dev.am335x_pwm.0.%pnpinfo: name=pwm@48300000 compat=ti,am335x-pwm
dev.am335x_pwm.0.%location:
dev.am335x_pwm.0.%driver: am335x_pwm
dev.am335x_pwm.0.%desc: AM335x PWM
dev.am335x_pwm.%parent:
 

Phishfry

Daemon

Thanks: 578
Messages: 2,054

#3
Looking thru those overlays settings they look similar to settings I see from ofwdump on FreeBSD11.1 . I will have to go through them.

Do you know if the overlay method works on FreeBSD 11.x BBB or do I need to use -CURRENT ?
 

aragats

Aspiring Daemon

Thanks: 287
Messages: 768

#4
Unfortunately, I don't know.

I'm still hoping that the latest main stream u-boot can be used for FreeBSD, and it perfectly handles dtb(o)'s by itself.
I built u-boot 2018.01, but never had a chance to test it with FreeBSD.

Also, you can manually add the content of those overlays to the main dtb that you load, and recompile it. Of course, make sure that you don't use macros which are defined in that overlays project tree.
 

Phishfry

Daemon

Thanks: 578
Messages: 2,054

#5
I could not get the overlay working but I used the information in the overlays to merge into a de-compiled am33x-boneblack.dts.
Then I hand applied some of the overlay and compiled it back into the dtb.
So I have ADC overlay and PWM working on FreeBSD 11.1 and with HDMI working. Nice.
I turned on every setting there is for pwm. I have no idea what ecap is.
Time to hit the books. Ti has some good docs.
Code:
root@BBB3:/boot/dtb # sysctl -a | grep pwm
dev.am335x_ehrpwm.2.dutyB: 0
dev.am335x_ehrpwm.2.dutyA: 0
dev.am335x_ehrpwm.2.period: 1000
dev.am335x_ehrpwm.2.freq: 100000
dev.am335x_ehrpwm.2.clkdiv: 1
dev.am335x_ehrpwm.2.%parent: am335x_pwmss2
dev.am335x_ehrpwm.2.%pnpinfo: name=ehrpwm@48304200 compat=ti,am33xx-ehrpwm
dev.am335x_ehrpwm.2.%location:
dev.am335x_ehrpwm.2.%driver: am335x_ehrpwm
dev.am335x_ehrpwm.2.%desc: AM335x EHRPWM
dev.am335x_ehrpwm.1.dutyB: 0
dev.am335x_ehrpwm.1.dutyA: 0
dev.am335x_ehrpwm.1.period: 1000
dev.am335x_ehrpwm.1.freq: 100000
dev.am335x_ehrpwm.1.clkdiv: 1
dev.am335x_ehrpwm.1.%parent: am335x_pwmss1
dev.am335x_ehrpwm.1.%pnpinfo: name=ehrpwm@48302200 compat=ti,am33xx-ehrpwm
dev.am335x_ehrpwm.1.%location:
dev.am335x_ehrpwm.1.%driver: am335x_ehrpwm
dev.am335x_ehrpwm.1.%desc: AM335x EHRPWM
dev.am335x_ehrpwm.0.dutyB: 0
dev.am335x_ehrpwm.0.dutyA: 0
dev.am335x_ehrpwm.0.period: 1000
dev.am335x_ehrpwm.0.freq: 100000
dev.am335x_ehrpwm.0.clkdiv: 1
dev.am335x_ehrpwm.0.%parent: am335x_pwmss0
dev.am335x_ehrpwm.0.%pnpinfo: name=ehrpwm@48300200 compat=ti,am33xx-ehrpwm
dev.am335x_ehrpwm.0.%location:
dev.am335x_ehrpwm.0.%driver: am335x_ehrpwm
dev.am335x_ehrpwm.0.%desc: AM335x EHRPWM
dev.am335x_ehrpwm.%parent:
dev.am335x_ecap.2.%parent: am335x_pwmss2
dev.am335x_ecap.1.%parent: am335x_pwmss1
dev.am335x_ecap.0.%parent: am335x_pwmss0
dev.am335x_pwmss.2.%parent: simplebus0
dev.am335x_pwmss.2.%pnpinfo: name=epwmss@48304000 compat=ti,am33xx-pwmss
dev.am335x_pwmss.2.%location:
dev.am335x_pwmss.2.%driver: am335x_pwmss
dev.am335x_pwmss.2.%desc: AM335x PWM
dev.am335x_pwmss.1.%parent: simplebus0
dev.am335x_pwmss.1.%pnpinfo: name=epwmss@48302000 compat=ti,am33xx-pwmss
dev.am335x_pwmss.1.%location:
dev.am335x_pwmss.1.%driver: am335x_pwmss
dev.am335x_pwmss.1.%desc: AM335x PWM
dev.am335x_pwmss.0.%parent: simplebus0
dev.am335x_pwmss.0.%pnpinfo: name=epwmss@48300000 compat=ti,am33xx-pwmss
dev.am335x_pwmss.0.%location:
dev.am335x_pwmss.0.%driver: am335x_pwmss
dev.am335x_pwmss.0.%desc: AM335x PWM
dev.am335x_pwmss.%parent: simplebus
 

Phishfry

Daemon

Thanks: 578
Messages: 2,054

#7
On Beaglebone there are three PWM nodes {ehrpwm0, ehrpwm1, and ehrpwm2}, but two of them have an A and a B. There are restrictions on how the A and B can be used, such as they have to use the same frequency, but they can each have independent duty cycles.

I can only seem to get pwm1A(P9_14) pwm1B(P9_16) & pwm2A(P8_19) pwm2B(P8_13) working.
So I am going to rework my setup as pwm0 seems absent. 2 pairs of PWN pins to work with.

Getting PWM working takes modifying decompiled dtb settings from 'status=disabled' to 'status=okay'. That part from the overlays work.
It is the pinmux selection that deviates.

I am going to try and write a dtso that will work for FreeBSD to enable PWM1 and PWM2.

https://github.com/beagleboard/bb.org-overlays/tree/master/src/arm

I am pulling from both am33xx-pwm-00A0.dts and the newer overlays with seprate files for each pwmss- BB-PWM1-00A0.dts and BB-PWM2-00A0.dts
 

Snurg

Aspiring Daemon

Thanks: 244
Messages: 700

#9
Yes and i noticed that FreeBSD source contains the C file for it.
/usr/src/sys/arm/ti/am335x/am335x_ecap.c

I noticed there is a GNU overlay for PWM-Timer. Need to do so research on that.
That's good it's already present and doesn't need yet to be imported from Linux.
I am still only reading around and preparing myself for the BBB things.

Will anyway have to wait with starting BBB playing until micro-HDMI->DVI cable, USB->SATA adapter and MAX-232 have arrived some day the coming week.

I found at the university junkyard a very nice and robust quality 5.25" FH external drive case with fan and PS 12V 5A and 5V 5A, providing a sweet cage for the Beagle protecting it from my cats.
And I am happy that I didn't yet carry that old 1280x1024 LCD monitor to the junkyard, as it seems the optimum for Beagle video output. :)

Looking forward to my first Beagle blinky :)
 

Phishfry

Daemon

Thanks: 578
Messages: 2,054

#10
So I disabled ehrpwm0 because none of the pins are broken out. It seems they are special.
When I redid my dts and only enabled ehrpwm1 & 2 and then recompiled dtb and rebooted.
FreeBSD seemed to relabel old ehrpwm1 to ehrpwm0 because that is disabled now.
[This is typical behavior of FreeBSD to give a zero address to the first detected device. vga0 comes to mind on headless units with no VGA connector.]
I didn't like that as the pin locations on the board are well documented as ehrpwm1A&1B and ehrpwm2A&2B.
So I added it back ehrpwm0 to get my names back to norm. I did leave off eCAP as I wont need it for now.

Now I need to verify if the pinmux is needed by checking for output from pins. Wish I had an oscilloscope.