GPIOs on GL-MT300N-V2 changed numbers after update to firmware 4.3.17?

I really need to use the GPIO pins on my beloved GL-MT300N-V2 / Mango.

I was running firmware 3.x.x, and I could see the GPIO pins in Linux, but no matter what value I wrote to them, the voltages didn't change.

So I updated to the latest available firmware version 4.3.17, and now it is even worse? All the GPIO numbers of the pre-defined GPIOs seem to have changed:

root@GL-MT300N-V2:~#  cat /sys/kernel/debug/gpio
gpiochip2: GPIOs 416-447, parent: platform/10000600.gpio, 10000600.gpio-bank2:

gpiochip1: GPIOs 448-479, parent: platform/10000600.gpio, 10000600.gpio-bank1:
 gpio-454 (                    |reset               ) in  hi IRQ ACTIVE LOW
 gpio-458 (                    |green:power         ) out lo ACTIVE LOW
 gpio-459 (                    |green:wan           ) out hi ACTIVE LOW
 gpio-460 (                    |red:wlan            ) out lo ACTIVE LOW

gpiochip0: GPIOs 480-511, parent: platform/10000600.gpio, 10000600.gpio-bank0:
 gpio-480 (                    |switch              ) in  hi IRQ
 gpio-483 (                    |BTN_1               ) in  lo IRQ ACTIVE LOW
 gpio-491 (                    |usb                 ) out hi

Note that the GPIO numbers used to be something like -0, -3, -4 and -11. Now they are > 400 ??

Also, when trying to export one of the unused GPIO pins using the number provided in the official pinouts, I just get an error:

root@GL-MT300N-V2:~#  echo "45" > /sys/class/gpio/export
ash: write error: Invalid argument

I have installed the packages gpioctl-sysfs and gpiod-tools , but that didn't change anything.
Running "gpiodetect" doesn't return anything.

Please help? I really need these GPIOs ASAP.

Edit: I followed the instructions at https://openwrt.org/docs/techref/hardware/port.gpio in order to use the new GPIO numbers. I am testing GPIO46. So I wired cables between GND (upper left pin) and GPIO46 (bottom right pin).
I ran:

root@GL-MT300N-V2:~# cat /sys/class/gpio/gpiochip*/base | head -n1
416

# 416 + 46 = 462

root@GL-MT300N-V2:~# echo "462" > /sys/class/gpio/export
root@GL-MT300N-V2:~# echo "out" > /sys/class/gpio/gpio462/direction
root@GL-MT300N-V2:~# echo "1" > /sys/class/gpio/gpio462/value
root@GL-MT300N-V2:~# echo "0" > /sys/class/gpio/gpio462/value

But my multimeter always just show 0V on that pin.

I reverted to firmware 3.216, and have my normal GPIO numbers back. GPIO 4 and 5 do actually seem to work now, which is great. But I urgently need more GPIOs.

GPIO45 (TX1) and GPIO46 (RX1) still don't work. I am guessing because they are being used as UARTS?

"dmesg |grep tty" show me:

root@GL-MT300N-V2:~# dmesg | grep tty
[    0.000000] Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jffs2
[    0.298728] console [ttyS0] disabled
[    0.302165] 10000c00.uartlite: ttyS0 at MMIO 0x10000c00 (irq = 28, base_baud = 2500000) is a 16550A
[    0.310939] console [ttyS0] enabled
[    0.326701] 10000d00.uart1: ttyS1 at MMIO 0x10000d00 (irq = 29, base_baud = 2500000) is a 16550A

I really don't need ttyS1 (or ttyS0 for that matter, but meh) - can I somehow tell the kernel NOT to use those pins as a serial port? I really need them for GPIO.

I've read on another forum post that one of the gl-inet staff said that firmware version 3.211 does have those pins NOT claimed by UART1, and are hence GPIOs, as advertised.

However, all links to v3.211 don't seem to work anymore. I really don't want to recompile a whole OpenWRT just for that.
Does anyone have a copy of v3.211 ? Because v3.216 definetly does use pins 45 and 46 for UART1.

So I used the Gl.inet image builder from GitHub - gl-inet/imagebuilder: Warning!Please look at 'GL.iNET Imagebuilder Introduction' section. to build myself a 3.211 version of the firmware, but GPIO 45 and 46 still don't work, and dmesg seems to indicate that they are being used as UART1.

Is there a way to use the imagebuilder and modify te required .dts file? I can't seem to find the .dts file in the build directory.

This is getting quite complicated. All I need is the 4 GPIO pins that are advertised!

I folowwed the instructions at

to modify the file
./imagebuilder/3.8/openwrt-imagebuilder-ramips-mt76x8_3.8/target/linux/ramips/dts/GL-MT300N-V2.dts

and added "uart1" to the relevant line.

I built the image again and installed it, but that didn't work. uart1 is still claiming pins 45 and 46.

Hi,

Found this:

This is over on a fork of the gl-infra-builder that has been pulled from public use, and the build of mt300n-v2 is 3.216, after this, the Mango was moved to 22.03.4 as a base for official GL-inet firmware 4.3.7.

I have two Mangos if you want me to test anything?

Thank you!

Yes, from what I can gather on the forums, I need to add "uart1" to that green line in order to tell the kernel that I want those pins to be available for GPIO. Adding the "i2c" does the same for pins 4 and 5 (which are used for i2c by default).

I followed the instructions on glinet's image builder github and managed to build my own 3.X image with that 'uart1' change, but it also didnt work.

Do you happen to have a .bin file at hand for testing?

Yes, any particular version you are after?
I'm just hunting down the Openwrt release to see if all gpio are available on that.

https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=abbfcc85259a4f6658c61e99dd3d2d3567e3eb3a

https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/ramips/dts/GL-MT300N-V2.dts;h=e40c4cf7dfea9dc5e0772f6b747f3d839fa9586b;hb=abbfcc85259a4f6658c61e99dd3d2d3567e3eb3a

Do you need GL firmware or will vanilla Openwrt do as full instructions are over here on what is needed:

found it as /openwrt/target/linux/ramips/dts$ nano mt7628an_glinet_gl-m t300n-v2.dts

just building Openwrt 23.05.3 for the Mango with the changes to prove it works, back soon.

Here's my build of 23.05.3 for the Mango with UART1 enabled:

Thank you!

Yes, for ease of use, I would prefer the GL firmware. But if that's a hassle, I can make do with Luci.

I tried cross-compiling a whole firmware from scratch, but get weird dnsmasq errors, and can't find the relevant 'make menuconfig' option to disable that. All very sad.

I downloaded your build from MEGA (you say 'UART1 enabled' - is that a typo? I am trying to disable UART1 in order to get access to the GPIO pins), but it's a .zip with two .bin files inside (initramfs and sysupgrade)? I'm sorry, but this confuses me a bit - I'm used to flashing one big .bin file, and am afraid of bricking my poor router. Could you tell me what to do with those?

Thank you so much for your efforts!

Instructions from the git commit are use the sysupgrade .bin without keeping settings.
https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=abbfcc85259a4f6658c61e99dd3d2d3567e3eb3a

@admon is there any support staff that could build/ request this with the included GPIO changes for 4.3.17 so there's an official supported firmware?

I guess @bruce should take a look.

1 Like

gpio45 and gpio46 are used as uart1 by default. I haven't found a way to modify pinctrl at the UserSpace, so you have to modify dts to make it work

--- a/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts
+++ b/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts
@@ -75,7 +75,7 @@
 
 &state_default {
        gpio {
-               groups = "wdt", "gpio", "wled_an", "p0led_an", "p1led_an", "i2s";
+               groups = "wdt", "gpio", "wled_an", "p0led_an", "p1led_an", "i2s", "uart1";
                function = "gpio";
        };
 };
@@ -132,7 +132,7 @@
 };
 
 &uart1 {
-       status = "okay";
+       status = "disabled";
 };
 
 &factory {

3 Likes

@dxf is it possible to have an official 4.3.17 with those changes, or even a 3.2.16?

Pls try this firmware, it is based on 3.216 and changes uart1 to gpio
https://fw.gl-inet.com/firmware/mt300n-v2/temp/openwrt-mt300n-v2-3.216-0725.bin

1 Like