GL-MT300N-V2 GPIO pins 4 5 45 46 - solved

How do I change system control registers in OpenWRT?

I'm unable to work with the GPIO pins 4, 5, 45, 46. They always measure 3.3v 3.3v 3.3v 0.0v.

According to the MT7621 datasheet those GPIO pins have a register that toggles different modes on those pins. Right now it is in UART mode and the register needs to be switched to GPIO mode.

Register 1E000060 (32bit)
zero based: bit 2 I2C_MODE needs to be toggled to fix GPIO4 and GPIO5
I2C_MODE: 0=I2c 1=GPIO
zero based: bit 1 UART1_MODE needs to be toggled to fix GPIO45 and GPIO46
URART1_MODE: 0=UART1 1=GPIO

There is no /dev/mem so the io program can't flip the bit.

https://docs.gl-inet.com/en/2/hardware/mt300n-v2/

https://openwrt.org/toh/gl.inet/gl.inet_gl-mt300n_v2

Either export the GPIO in the usual Linux fashion, or I have very vague memories of a UCI command which I believe does something similar, but also links it UCI and possibly ubus.

If they're tied by the DT to a UART, you might need to change the DTS.

Including the /dev/mem driver is a kernel configuration option. Kernel could be rebuilt to include it. In a default build there is no /dev/mem.

1 Like

Bahhh...
Recompiled kernel with /dev/mem however the Register address 0x1e000060 is wrong... Now trying to find a datasheet/programmer guide for the MT7628 registers.

I received a solution from GL-Inet Form. Namely compile from source with the following change.

  • edit target/linux/ramips/dts/GL-MT300N-V2.dts

  • find the pinctrl0 around line 82 and add: "i2c", "uart1"

    &pinctrl {
      state_default: pinctrl0 {
                  gpio {
                          ralink,group = "wdt", "gpio", "wled_an", "p0led_an", "p1led_an", "i2s", "i2c", "uart1";
                          ralink,function = "gpio";
                  };
          };
    };
    

After make and install the gpio pins are now manageable through /sys/class/gpio/.

However the new problem I'm now having is that even though I compiled the 1-wire modues as "M" in make menuconfig. The modules are not available inside my sysupgrade.bin. I also can not install the kmod-w1* packages because they conflict with the kernel.

root@OpenWrt:/etc# opkg install kmod-w1 kmod-w1-master-gpio kmod-w1-gpio-custom
Installing kmod-w1 (4.14.103-1) to root...
Downloading http://downloads.openwrt.org/releases/18.06-SNAPSHOT/targets/ramips/mt76x8/packages/kmod-w1_4.14.103-1_mipsel_24kc.ipk
Installing kmod-w1-master-gpio (4.14.103-1) to root...
Downloading http://downloads.openwrt.org/releases/18.06-SNAPSHOT/targets/ramips/mt76x8/packages/kmod-w1-master-gpio_4.14.103-1_mipsel_24kc.ipk
Installing kmod-w1-gpio-custom (4.14.103-3) to root...
Downloading http://downloads.openwrt.org/releases/18.06-SNAPSHOT/targets/ramips/mt76x8/packages/kmod-w1-gpio-custom_4.14.103-3_mipsel_24kc.ipk
Collected errors:
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-w1:
 * 	kernel (= 4.14.103-1-6b7f4bb0e839f1545297907a37980184)
 * opkg_install_cmd: Cannot install package kmod-w1.
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-w1-master-gpio:
 * 	kernel (= 4.14.103-1-6b7f4bb0e839f1545297907a37980184)
 * opkg_install_cmd: Cannot install package kmod-w1-master-gpio.
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-w1-gpio-custom:
 * 	kernel (= 4.14.103-1-6b7f4bb0e839f1545297907a37980184)
 * opkg_install_cmd: Cannot install package kmod-w1-gpio-custom.

How do I get kernel modules into my sysupgrade.bin?

1 Like

Found packes in /openwrt/openwrt/bin/targets/ramips/mt76x8/packages - manually scp them to /tmp for install. I would still like to know how to include them as part of the sysupgrade.bin.

With this level of customization, you're past what the image builder can do.

I'd recommend the full build system.

How familiar are you with git and the like?

Edit: Seeing that it looks like you've successfully built the modules, I'd personally tackle it with:

  • Create a git branch of your own off master or openwrt-18.06 (as 19 isn't quite branched yet)
  • Make your modifications to the DTS
  • Run make menuconfig and select the packages you need/want
  • make, flash, and enjoy

This way you can rebase your changes on a later point in development, or another branch.

I'm comfortable with git. Should I put in a git pull request to modify the GL-MT300N-V2.dts? The above noted change makes unused gpio pins 4 5 45 46 available for dev.

/sys/class/gpio works for pins 4 5 45 46. I can toggle 3.3v and 0.0v on all 4 pins.

After commenting out the default mirror and adding my own based on compiled packages I can now get 1-wire bus working.

opkg update
opkg install kmod-w1 kmod-w1-master-gpio kmod-w1-gpio-custom
insmod w1-gpio-custom bus0=0,4,0
opkg install kmod-w1-slave-therm
cat /sys/devices/w1_bus_master1/28*/w1_slave
5e 01 4b 46 7f ff 0c 10 51 : crc=51 YES
5e 01 4b 46 7f ff 0c 10 51 t=21875

That's a win: 21.875C

# dmesg
[  713.465074] Driver for 1-wire Dallas network protocol.
[  713.474398] kmodloader: done loading kernel modules from /etc/modules.d/*
[  752.284902] Custom GPIO-based W1 driver version 0.1.1
[  762.781993] w1_master_driver w1_bus_master1: Attaching one wire slave 28.041621a09cff crc 6f
[  762.818252] w1_master_driver w1_bus_master1: Family 28 for 28.041621a09cff.6f is not registered.
[  814.737967] kmodloader: loading kernel modules from /etc/modules.d/*
[  814.748228] w1_master_driver w1_bus_master1: Attaching one wire slave 28.041621a09cff crc 6f

gpio pins & 1-Wire bus works. I've installed ds18b20 temperature module on pin4 with a 4k7 pull-up resistor on the data pin.

That all depends on how fire-proof you feel :wink:

I've looked at the MT300N v2 for use with a timing GPS and NTP, so I'd want serial for two pins, and a GPIO input for the PPS. If I were a gatekeeper, I'd probably ask that they could be configured independently. (To be clear, I'm not a gatekeeper and I decided not to pursue that project so I didn't look into how the serial on those lines was implemented, such as bit-bang vs. UART hardware, vs. I2C hardware.)

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.