GPIO not working with RT patch

fvllml
fvllml New Member Posts: 12

I'm trying to use GPIO pins on up2.

My kernel is

Linux up 5.4.65-rt38+ #1 SMP PREEMPT_RT Mon Feb 28 13:42:31 CET 2022 x86_64 x86_64 x86_64 GNU/Linux

I compiled this up linux repository with the RT patch for the right kernel version and the following options:

  SYSTEM_REVOCATION_KEYS: no
  SYSTEM_TRUSTED_KEYS: no

  HZ_PERIODIC: yes
  NO_HZ_IDLE: no
  CONFIG_NTP_PPS: no
  HIGH_RES_TIMERS: yes
  CONFIG_HZ_1000: yes
  CONFIG_HZ: 1000
  CONFIG_OF: no
  CONFIG_AUFS_FS: no

  CONFIG_PREEMPT_RT: yes
  PREEMPT: yes
  PREEMPT_RT_FULL: yes
  PREEMPT_COUNT: yes
  PREEMPTION: yes
  DEBUG_PREEMPT: yes 

  CPU_IDLE: no
  INTEL_IDLE: no
  CPU_FREQ_DEFAULT_GOV_PERFORMANCE: yes

Then I installed the upboard-extras package

# Install extras
sudo add-apt-repository ppa:aaeon-cm/5.4-upboard
sudo apt update
sudo apt install upboard-extras

# Add groups
for group in gpio leds spi i2c; do
    if ! getent group $group >/dev/null; then
        addgroup --system $group
    fi
done

# Add User
sudo usermod -a -G gpio ${USER}
sudo usermod -a -G leds ${USER}
sudo usermod -a -G spi ${USER}
sudo usermod -a -G i2c ${USER}
sudo usermod -a -G dialout ${USER}

sudo reboot

I am able to communicate with a chip using spi so I think the permissions are right.

I tried the following code without success

echo 432 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio432/direction
echo 1 > /sys/class/gpio/gpio432/value

I measure with a multimeter on pin 432 (pin 13 from this wiki and I get 0.1V.

Am I missing something?
PS: I cannot see anything when ls /sys/class/leds/, why?

Best Answer

  • fvllml
    fvllml New Member Posts: 12
    Answer ✓

    My problem was that I was compiling the kernel with a generic ubuntu configuration and not the up-board configuration.

    I instealled Ubuntu 20 again, then used the procedure in the wiki to patch the kernel with the up-board kernel. Then I copied back the config at /boot/ and used it to compile the kernel again with RT.

    After that, I installed again Ubuntu 20 on the Up squared and installed the debian packages of my previously compiled RT-upboard-patched kernel and now it works. I can control the GPIO and the leds.

Answers

  • fvllml
    fvllml New Member Posts: 12
    edited April 2022

    I am trying now the kernel proposed by the wiki.

    up@up:~$ uname -a
    Linux up 5.4.0-1-generic #0~upboard5-Ubuntu SMP Fri Jan 7 11:53:57 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
    

    Now I can see the leds and control the GPIO pins.

    Am I compiling the right kernel or should I use another repository?

  • fvllml
    fvllml New Member Posts: 12
    edited April 2022

    Doing a diff on lsmod for both kernels I got this:

    # Modules lodaded on generic but not in realtime
    snd_sof_intel_hda      20480  1 snd_sof_intel_hda_common
    leds_upboard           16384  0
    pinctrl_upboard        16384  0
    ulpi                   20480  1 dwc3
    upboard_fpga           20480  0
    
    # Modules loaded on realtime but not in generic
    snd_soc_hdac_hda       20480  1 snd_sof_intel_hda_common
    pinctrl_broxton        40960  0
    

    So basically the kernel with the realtime patch is not loading pinctrl_upboard and leds_upboard so I think this is why I cannot control the GPIOs.

    When trying to load them manually:

    up@up:~$ modprobe -v pinctrl_upboard
    modprobe: FATAL: Module pinctrl_upboard not found in directory /lib/modules/5.4.65-rt38+
    up@up:~$ modprobe -v leds_upboard
    modprobe: FATAL: Module leds_upboard not found in directory /lib/modules/5.4.65-rt38+
    

    Any way I could have those modules on a realtime patched kernel?

  • fvllml
    fvllml New Member Posts: 12

    When I do a diff on the output of lsmod from both kernels I get this

    # Modules lodaded on generic but not in realtime
    snd_sof_intel_hda      20480  1 snd_sof_intel_hda_common
    leds_upboard           16384  0
    pinctrl_upboard        16384  0
    ulpi                   20480  1 dwc3
    upboard_fpga           20480  0
    
    # Modules loaded on realtime but not in generic
    snd_soc_hdac_hda       20480  1 snd_sof_intel_hda_common
    pinctrl_broxton        40960  0
    

    Apparently the pinctrl_upboard and the leds_upboard are not being loaded so I think this is why I cannot control the GIPOs on my up squared.

    If I try to load them I get the following error

    up@up:~$ modprobe -v pinctrl_upboard
    modprobe: FATAL: Module pinctrl_upboard not found in directory /lib/modules/5.4.65-rt38+
    up@up:~$ modprobe -v leds_upboard
    modprobe: FATAL: Module leds_upboard not found in directory /lib/modules/5.4.65-rt38+
    

    Also, on the realtime kernel I can find the .ko files for leds and pinctrl at

    up@up:/lib/modules/5.4.0-1-generic$ find . | grep -i leds-upboard
    ./kernel/drivers/leds/leds-upboard.ko
    up@up:/lib/modules/5.4.0-1-generic$ find . | grep -i pinctrl-upboard
    ./kernel/drivers/pinctrl/pinctrl-upboard.ko
    

    with no chances on /lib/modules/5.4.65-rt38+

    Any way I can have an Ubuntu with realtime patched kernel and working GPIOs on Up squared?