Closed RaulTrombin closed 1 year ago
I discovered that there should be a minimum delay of 20 milliseconds between exporting and setting directions. In the case of port 16, it requires a 30-millisecond delay, although the reason for this is unclear.
pin.export().expect("Error: Error during led pins export");
Delay {}.delay_ms(30 as u16);
pin.set_direction(Direction::High)
.expect("Error: Setting led pins as output");
In conclusion, if you run the program with sudo, the delay is not necessary. However, if you run it as a regular user, this delay is required.I guess it's related to the kernel.
Any tips on how to investigate this further? Could it be something related to method export?
@RaulTrombin What SOC are you targeting?
Actually, thinking about this a bit more I strongly suspect that this is a udev-related race condition on export. The kernel exports the device but it is async for udev to change the permissions. If your code gets to it first, then the perms won't be updated yet.
The cdev API wouldn't have this same problem.
@posborne it's the arm7 for raspberry pi 4, cdev is another crate/feature?
@RaulTrombin The GPIO sysfs interface is deprecated. The linux-embedded-hal crate provides both as part of features. To interact with the kernel via the cdev interface you'd use https://docs.rs/linux-embedded-hal/latest/linux_embedded_hal/struct.CdevPin.html (and then the embedded-hal interface once you have a pin).
Hi, I'm using the Pin method for CS1 and CS2, also for 3 leds. Here is how I'm using it:
So, when I do a first run, it fails:
But during the next run it works, basically i have to run it 5 times before to have it working (the 5 first erros for each pin), on each boot of the OS. Running it as sudo works at the fresh first time.