cape_universal and how to start up PWM

54 views
Skip to first unread message

Ken Shirriff

unread,
Jan 1, 2019, 8:02:43 PM1/1/19
to BeagleBoard
I'm trying to enable PWM and some GPIOs on the Beaglebone and I'm running into various problems.

Originally I tried to start PWM using the /sys/class/pwm/pwmchip1/export interface, but ran into a bunch of race conditions. I then tried using the Adafruit_BBIO.PWM library, which works around most of the race conditions (but still sometimes fails nonrepeatably). (I also tried writing the PWM registers directly, but there are a lot of them and I couldn't find documentation on which ones are needed, so I figure I'm better off using the device drivers.)

But the Adafruit_BBIO library depends on using cape_universal, which configures some pins in ways that conflict with what I want in my dts file.

So my questions are:
a) Is there a simple, reliable way of enabling PWM?
b) Is there a way of overriding some cape_universal pin assignments? Or getting cape_universal to assign them the way I want? Or configuring the ocp:Px_xx_pinmux/state files that the Adafruit library needs without using cape_universal?

I can post my dts files and so forth, but I suspect that I need to change my approach entirely.

Thanks,
Ken

P.S. By "race conditions", I mean that if I write to /sys/class/pwm/pwmchip1/export, and then try to write to /sys/class/pwm/pwm-1:0, sometimes the latter file isn't there and I need to wait. But even sleeping a bit isn't always enough. The Adafruit library has code to deal with this as well as various other situations, but even that code fails randomly about 20% of the time.



Robert Nelson

unread,
Jan 1, 2019, 8:40:44 PM1/1/19
to Beagle Board, Ken Shirriff
There was a recent change in the "bb-customizations" package to change
the udev rule to automatically export the channels on bootup:

https://github.com/rcn-ee/repos/commit/5e66a1f215c41157072b989f03004b661f50ab40

Might be something useful in that to borrow. ;)

Regards,

--
Robert Nelson
https://rcn-ee.com/

TJF

unread,
Jan 2, 2019, 10:46:00 AM1/2/19
to BeagleBoard
Hi Ken!


Am Mittwoch, 2. Januar 2019 02:02:43 UTC+1 schrieb Ken Shirriff:
So my questions are:
a) Is there a simple, reliable way of enabling PWM?
b) Is there a way of overriding some cape_universal pin assignments? Or getting cape_universal to assign them the way I want? Or configuring the ocp:Px_xx_pinmux/state files that the Adafruit library needs without using cape_universal?

The answers are:

a) The simple and reliable way to enable PWM is using libpruio.
b) With libpruio you won't need cape_universal at all (Adafruit library is also needless). But if you want to use cape_universal by any reason, then libpruio can override all its configurations in order to get you what you need.

P.S. By "race conditions", I mean that if I write to /sys/class/pwm/pwmchip1/export, and then try to write to /sys/class/pwm/pwm-1:0, sometimes the latter file isn't there and I need to wait. But even sleeping a bit isn't always enough. The Adafruit library has code to deal with this as well as various other situations, but even that code fails randomly about 20% of the time.

libpruio can configure the PWM subsystems while the output is stopped, and afterwards start all subsystems synchronously by a single function call. It's also possible to chain up (synchronize) the PWM output between multiple PWM subsystems.

... but I suspect that I need to change my approach entirely.

A good, but late brainchild. I proposed libpruio before you started your approach.

Regards
Reply all
Reply to author
Forward
0 new messages