-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Probably errant delays in GPIO/PWM #350
Comments
Thanks, this is a good point and worthy of being fixed.
I agree that it seems like the tracking of exported state needs to be improved. I need to think more about that because it has been awhile since I looked at this.
I made a fix for pwm_path in #342 which is also related to the array index. Do you have commit Overall, the current path handling code does seem complicated and brittle but I am hesitant to make changes for fear of regressions. I don't have a good way to test across all the kernel versions that there is logic for.
I have to admit that a lot of this library has built over time to cover many different kernel versions and device tree overlay strategies and there are many brittle parts. Adafruit Blinka has been receiving more focus over the last 2 years. There is support for some of the functionality on the BeagleBone and PocketBeagle. I think there are people that still prefer the semantics of Adafruit_BBIO (which in turn is based on the rather old RPi.GPIO) but I would recommend people first try Adafruit_Blinka for new Python projects on BeagleBone or PocketBeagle before they try Adafruit_BBIO. It might be more productive to improve the Blinka support than try to continue developing Adafruit_BBIO. |
So re: the issue with #342, there's another place the array index needed fixed a few lines above: I'm not sure why mine took a different code path than the original, probably because I was messing around with the various filenames as I flailed while seeking an answer. I looked at Blinka, and I don't think it will work for my application, mainly because the code says that But it seems we've both converged on the term "brittle" to describe this part of the code, and given I've managed to hack my way through something that works for my application, it would probably be a better use of your time to spend it beefing up Blinka than decoding this maze of twisty pathways. I'm grateful for the time you spent helping me. |
With a BeagleBone Green Wireless and the latest everything (Debian Buster 2020-04-06, Python 3.7, Adafruit-BBIO 1.2.0), I'm finding spurious delays in GPIO and PWM signals that don't seem right . Full
version.sh
info at the end.This is an embedded application that uses the GPIO bits for machine control, and PWM to generate speaker beeps to alert an operator of runtime conditions. Some of these errant delays are actually problematic.
I think I've tracked most of these down and will look at creating some pull requests to make them so, though my utter unfamiliarity with udev might make some of them sub-optimal.
GPIO delays
When doing simple GPIO bit flipping, the code seems to add a 200msec delay during pin setup to allow the udev export stuff to settle down even if the pin has already been exported.
At the end of the function
gpio_export()
found inevent_gpio.c
is this bit of code:and this seems reasonable enough if it needs to let things settle, but my proposed fix would exclude this if the pin has already been exported (mostly pseudocode);
Actual code fixing this seems to work, though I think the errant delay is not a huge deal because it's just once per execution. Still, worthy of a fix.
PWM delays
Much more problematic are PWM setup delays, which are repeatable. Generating a beep that's 50 msec at 1 kHz, then 50 msec at 2 kHz, then another 50 msec back at 1 kHz:
The stock library takes around 220 milliseconds between each set of beeps, which feels excessive.
Looking into the code, there is at least one obvious bug that gets one of the udev names wrong, plus I think a second test is wrong as well - this stuff is confusing to me - and after "fixing" it, it looks a lot better:
The
pwm_setup()
function inc_pwm.c
is where I think all the problematic behavior is, and early in the function are character arrays for a raft of different related names.The clear bug is in:
because
pwm_path[67]
is a slash character on my platform. creating a filename like (check out the far right side of the path):Using
pwm_path[66]
gets the last character of thepwmchip#
number, which gets us more in the ballpark:The deeper issue is that the code seems to think it needs to keep exporting the same PWM pin even after it's been exported previously, and this takes more runtime plus has some built-in intentional delays.
The code first tests the
pwm_path
, then thepwm_path_udev
, and I think it should be doing it in the other order.and at the end of the
else
for this test, we copypwm_path_pwm
topwm_path
, and the rest of the code seems to do the right thing.This feels terribly brittle and is unlikely to be right in the general case; I'm not sure how to vet this more broadly.
The text was updated successfully, but these errors were encountered: