Omega2S+ can't read GPIO pin 26



  • Product being used : Omega2S+

    Firmware version : 0.3.3 b247

    Description of the issue and context:

    GPIO pin 26 always returns LOW, unlike all other GPIO pins (also including pin 27 also in the
    SD-card reader block of pins).

      # omega2-ctrl gpiomux get
      Group i2c - [i2c] gpio
      Group uart0 - uart [gpio]
      Group uart1 - uart [gpio] pwm01
      Group uart2 - uart [gpio] pwm23
      Group pwm0 - pwm [gpio]
      Group pwm1 - pwm [gpio]
      Group refclk - refclk [gpio]
      Group spi_s - spi_s [gpio] pwm01_uart2
      Group spi_cs1 - spi_cs1 [gpio] refclk
      Group i2s - i2s [gpio] pcm
      Group ephy - ephy [gpio]
      Group wled - wled [gpio]
    
      # gpioctl dirin 26
      Using gpio pin 26.
      # gpioctl dirin 27
      Using gpio pin 27.
      # gpioctl get 26
      Using gpio pin 26.
      Pin 26 is LOW
      # gpioctl get 27
      Using gpio pin 27.
      Pin 27 is HIGH
    

    Expected Behavior

    Pin 26 is wired similar to 27 and should be HIGH.

    Observed Behavior

    Pin 26 is LOW.

    Steps to reproduce the issue

    Connection:

      3.3V --> R100K --> Omega2S+ pin 26
                      |  
       GND --> C10p --/
    

    What kind of help are you looking for?

    I've been searching without luck what I need to do to make sure the software knows to use
    pins 22-29 for the SD-card reader as GPIO pins. Or; what I need to uninstall to make
    sure those pins are never disturbed by SD-card related software/drivers.

    My only guess is that pin 26 reads low because it's somehow used as SD.CLK.

    If you can please help me get pin 26 as a plain GPIO pin, very much appreciated.



  • @magge Thank you for posting your question with all of the required detail.

    I can't test this right now, perhaps someone else can, however my first thought is that the mmc kmods may be messing with the gpio. A quick and easy test is to delete (move) the mmc kmods , then reboot and test again. You could of course use rmmod but that fails so this is a quick and dirty test.

    The kmods are in /lib/modules/4.14.81/ the two files are mmc_block.ko and mmc_core.ko

    If that resolves your issue then you can build your kernel and firmware without mmc support.



  • @crispyoz Thanks!

    Somehow it can still load those modules even when I moved the files into /root/backup and even added .bak on their filename (and rebooted). šŸ˜•

    # lsmod | grep mmc
    mmc_block              21446  0
    mmc_core               88573  2 mmc_block,sdhci
    # ls -l /lib/modules/4.14.81/ | grep mmc
    #
    

    I will try to read up on building a kernel without mmc...



  • @magge The magic of *nix šŸ˜„ Quite bizaare, it/they must be in another location but you can also remove /etc/modules.d/mmc which deals with the loading of those modules. Use the command "which mmc_block.ko" and "which mmc_core.ko" to see where they may be living a clandestine life.



  • @crispyoz

    Was not able to avoid mmc_core and mmd_block loading on boot. I think they are maybe loaded from the read-only /rom, seems it's the only place they are left now...

    # find / | grep mmc_core
    /overlay/upper/root/backup/mmc_core.ko.bak
    /overlay/upper/lib/modules/4.14.81/mmc_core.ko
    /rom/lib/modules/4.14.81/mmc_core.ko
    /root/backup/mmc_core.ko.bak
    

    However I figured out that mmc_core was not possible to rmmod because of dependent modules, but removing all deps first allows also removing mmc_core.
    Still getting pin 26 as low though, so maybe this is not about SD after all... šŸ˜•

    # rmmod sdhci_pltfm
    # rmmod sdhci
    # rmmod mmc_block
    # rmmod mmc_core
    # lsmod | grep mmc
    
    # gpioctl dirin 26
    Using gpio pin 26.
    # gpioctl get 26
    Using gpio pin 26.
    Pin 26 is LOW
    


  • @magge Can I just check your nomenclature, you're referring to "PIN 26" which is GPIO 0 on the Omega2S. GPIO 26 is pin 57.



  • @crispyoz Sorry, yes I am referring to GPIO-26 or SD.CLK. I have been looking at this diagram https://miro.medium.com/max/1100/0*TL9bMpprfW5sp_b_ .
    You are right that it's pin 57, I guess.

    That being said I have found 2 solutions:

    1:
    The mmc_core, mmc_block, sdhci* kmods are the ones causing interference. Building a custom firmware without them fixes the problem!

    2:
    The omega2-ctrl gpiomux could also have fixed this if it was updated for the Omega2S+ (S meaning SD card, right?).
    One of the MT7688 (https://cdn.hackaday.io/files/279051193887520/MT7688_Datasheet_v1_4.pdf) registers that this tool writes (GPIO1_MODE) actually has SD_MODE (bits 11:10) which allows controlling what the pins are used for!

    I have not found a nice way to read the register and bitwise-and/or with the only the bits we want to set, however we can write the whole register as shown below. This sets all modes in GPIO1_MODE to GPIO except for I2C, which is what I need in this particular case, including the invisible SD_MODE...

    # devmem 0x10000060 32 0x55055554
    # omega2-ctrl gpiomux get
    Group i2c - [i2c] gpio
    Group uart0 - uart [gpio]
    Group uart1 - uart [gpio] pwm01
    Group uart2 - uart [gpio] pwm23
    Group pwm0 - pwm [gpio]
    Group pwm1 - pwm [gpio]
    Group refclk - refclk [gpio]
    Group spi_s - spi_s [gpio] pwm01_uart2
    Group spi_cs1 - spi_cs1 [gpio] refclk
    Group i2s - i2s [gpio] pcm
    Group ephy - ephy [gpio]
    Group wled - wled [gpio]
    

    Setting the gpio mux correctly allows it to work even with the standard kmods running.

    # lsmod | grep mmc
    mmc_block              21446  0
    mmc_core               88573  3 mmc_block,sdhci,mtk_sd
    # gpioctl dirin 26
    Using gpio pin 26.
    # gpioctl get 26
    Using gpio pin 26.
    Pin 26 is LOW
    # devmem 0x10000060 32 0x55055554
    # gpioctl get 26
    Using gpio pin 26.
    Pin 26 is HIGH
    


  • @magge It's good you have it working by removing those modules.

    The "S" in Omega2S+ is for Surface Mount, the standard Omega2+ is the socket mounted version.

    The code for omega2-ctrl https://github.com/OnionIoT/omega2-ctrl, look at giomux.c/h you can see how it works by modifying the registers on the SoC.



  • @crispyoz Thanks for all your help!



Looks like your connection to Community was lost, please wait while we try to reconnect.