Bug fix for GPIO under recent Linux kernel versions#1562
Conversation
Using libgpiod
|
Tested on my Raspberry PI / NRF24 gateway and working fine (with around 10 devices). Not tested on any other platform. |
|
Nice work, thanks! Attaching the restyling that the butler requests: Will add further comments shortly. |
mfalkvidd
left a comment
There was a problem hiding this comment.
Adding review comments.
Do you know how long this interface has been available? The reason I'm asking is that we would prefer to not break older gateways (running on older Linux versions) if people upgrade.
| * - RF24_PA_MAX = 0dBm | ||
| */ | ||
| #ifndef MY_RF24_PA_LEVEL | ||
| #define MY_RF24_PA_LEVEL (RF24_PA_HIGH) |
There was a problem hiding this comment.
I'd prefer if we didn't change the default PA level in this PR, since it is not related to the change.
| // FILE *fp = fopen("/sys/class/gpio/unexport", "w"); | ||
| // if (fp == NULL) { | ||
| // logError("Unable to unexport pin %d for interrupt\n", gpioPin); | ||
| // exit(1); | ||
| // } | ||
| // fprintf(fp, "%d", gpioPin); | ||
| // fclose(fp); |
There was a problem hiding this comment.
Would you mind deleting those lines instead of commenting them? We have git for history.
| #include <stdint.h> | ||
|
|
||
| // Ajout RRO | ||
| #include <gpiod.h> |
There was a problem hiding this comment.
Do you know if this is installed by default on Raspberry Pi OS? If it is not, we should probably document how to install the dependency.
There was a problem hiding this comment.
sudo apt-get install libgpiod-dev
Thanks to @zkarolyi in #1562 (comment)
|
Styles and minor updates done. For the documentation, sorry for my question but, how do I do that ? |
|
Excellent, thanks! 6 years should be good enough, imo. The documentation is not under version control unfortunately but I can add it to https://www.mysensors.org/build/raspberry |
|
Thank you to the reviewers. |
|
Hi, |
|
Just tested this on RPi Zero W with Raspbian Bookworm 32-bit kernel. Works great. |
What is the SOC and CPU detected as part of the configure command execution? E.g. update: |
|
like @raks-dev and @ricgyver I also still see the error "Could not open /sys/class/gpio/gpio9/direction". It seems that this pull request is not complete. The error is coming from file "hal/architecture/Linux/drivers/core/GPIO.cpp". |
This solution includes:
Edit: I don't think the GPIO files are used with the changed configuration file (to detect the rpi4). I don't understand it, but at least it works for me. |
| // Wait a bit | ||
| usleep(1000); | ||
| } | ||
|
|
There was a problem hiding this comment.
143-146 are now all unused vars from deleted code (fd, fName, c, count)
| fclose(fd); | ||
| char *chipname = "gpiochip0"; | ||
| unsigned int line_num = gpioPin; | ||
| struct gpiod_line_event event; |
|
After some time I was finally able to get MySensors running on a RPI3B serial gateway with bookworm os. I had to use this gpio_fix version of the library (the current dev branch does not compile). It is working reliably by almost a week with the sensors network I build in previous years. As steted, I had to install the libgpiod-dev library and use the following config lines: ./configure --my-transport=rfm69 --my-rfm69-frequency=433 --my-is-rfm69hw --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyUSB020 --soc=BCM2837 --cpu-flags="-march=armv8-a+crc -mtune=cortex-a53"_ All the other attempts (without the --soc=BCM2837 --cpu-flags="-march=armv8-a+crc -mtune=cortex-a53 instructions) failed. Hope this can push the merge of the fix in the official release of MySensors. |
|
For make this needed: |
|
Just to confirm that I tried base
Considering the relevance of this for RPi 5 user it should be documented somewhere. |
|
For RPi 4 I have these WORKING:
ONLY for IRQ: to: I can not use IQR ( |
Slight update of MySensors using libgpiod instead of all standard sysfs to map interrupts.