OpenWrt Forum Archive

Topic: (TL-WR703n / GPIO / Misc) AR9331 pinouts?

The content of this topic has been archived between 7 Oct 2014 and 7 May 2018. Unfortunately there are posts – most likely complete pages – missing.

yumbrad wrote:
v8rush wrote:

On a more general note, how does the AR9331 handle PIO muxing - is the GPIO_FUNCTION register a centralised pin-function register, or are they spread over the subsystems (eg ethernet, RF...). If the former, then I guess there's the possibility of freeing up even more GPIOs quite easily.

Check out
http://gpl.back2roots.org/source/fritzb … 240/gpio.c
http://gpl.back2roots.org/source/fritzb … 0/ar7240.h
http://gpl.back2roots.org/source/fritzb … 0/ar933x.h
... some of these german gateway devices (Fritzbox) seems to have utilized more of the ar71xx functionality, and their GPL release has some stuff I haven't seen in other places.

You can grab the whole kernel too: http://gpl.back2roots.org/source/fritzb … nel.tar.gz

There seems to be one register at GPIO_BASE (0x18040000) that selects a pin as input or output, then several function select/mux registers that are rather complicated at GPIO_BASE + 0x28 - 0x40. Some examples of how certain functions get set up are in the above gpio.c file within ar7240_gpio_setup_pin_mode. This could be useful for enabling more GPIOs, but also for using some of the other functions (JTAG, I2S, SPI)

Thanks for the links!

(Last edited by Squonk on 16 Aug 2012, 08:07)

v8rush wrote:

Next thing to do is try modifying the startup code to see if we can free up more GPIOs (I'm guessing this is what imperfect did) by removing them from 'special function' duties. Top of the list to try is the 4 "ethernet switch" LEDs, and if that boots (edit: it did), it's multimeter time to find them...

So, I had a prod around with the 'meter. In the list below the suffix is the compass direction of the component end to wire to. North is the top of the board when the silkscreened TP-LINK is the right way up, ie the edge with the ethernet jack. Why one is a pull-up, I don't know...

13 - R3S (it's a 10K pull-up)
14 - R11N
15 - R12N
16 - R13N
17 - R14N

Note that imperfect thought GPIO 2 was on R14 - I couldn't replicate that, or find GPIO2 anywhere else. I also had a poke around for 10K resistors (on the assumption that pullers would be that value), and found only two that aren't covered by any of the GPIOs in this thread - R53 and R58.

Below is the kernel change - I suspect those new GPIOs are the LEDn_EN bits alone, but releasing the others does no harm.

Index: target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr703n.c
===================================================================
--- target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr703n.c  (revision 33186)
+++ target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr703n.c  (working copy)
@@ -8,11 +8,12 @@
  *  under the terms of the GNU General Public License version 2 as published
  *  by the Free Software Foundation.
  */
-
 #include <linux/gpio.h>

 #include <asm/mach-ath79/ath79.h>
+#include <asm/mach-ath79/ar71xx_regs.h>

+#include "common.h"
 #include "dev-eth.h"
 #include "dev-gpio-buttons.h"
 #include "dev-leds-gpio.h"
@@ -62,6 +63,20 @@
        u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
        u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);

+        /* Turn off support for Ethernet LEDs and RTS/CTS. This should give us more GPIOs */
+       ath79_gpio_function_disable(
+                                   AR933X_GPIO_FUNC_ETH_SWITCH_LED_DUPL|
+                                   AR933X_GPIO_FUNC_ETH_SWITCH_LED_COLL|
+                                   AR933X_GPIO_FUNC_ETH_SWITCH_LED_ACT |
+                                   AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
+                                   AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
+                                   AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
+                                   AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
+                                   AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN |
+                                   AR933X_GPIO_FUNC_UART_RTS_CTS_EN
+                                  );
+
+
        ath79_register_m25p80(&tl_wr703n_flash_data);
        ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr703n_leds_gpio),
                                 tl_wr703n_leds_gpio);

(Last edited by v8rush on 16 Aug 2012, 11:25)

Would it be possible to connect a 315/433 MHz receiver directly to a GPIO pin on the TL-WR703N? I have a sender/receiver pair like this: http://www.seeedstudio.com/depot/315mhz … th=139_140
And I would like to trigger a script when a PIR motion detector connected directly to the transmitter detects motion. I know it could be done with a microcontroller at both sides, but I don't need the PIR sensor to send any other information. Here shouldn't be other 315MHz devices around, so it should work without any sort of identification. The Pir sensor is one like this: http://www.ebay.com/itm/Mini-Portable-P … 4163fb5414

Should I just connect GND to GND and VCC to 5V on the TL-WR703N, and the data pin on the receiver to a GPIO pin on the TL-WR703N? Or do I need some kind of circuit between them?

(Last edited by monotube on 16 Aug 2012, 16:11)

monotube wrote:

Would it be possible to connect a 315/433 MHz receiver directly to a GPIO pin on the TL-WR703N? I have a sender/receiver pair like this: http://www.seeedstudio.com/depot/315mhz … th=139_140
And I would like to trigger a script when a PIR motion detector connected directly to the transmitter detects motion. I know it could be done with a microcontroller at both sides, but I don't need the PIR sensor to send any other information. Here shouldn't be other 315MHz devices around, so it should work without any sort of identification. The Pir sensor is one like this: http://www.ebay.com/itm/Mini-Portable-P … 4163fb5414

Should I just connect GND to GND and VCC to 5V on the TL-WR703N, and the data pin on the receiver to a GPIO pin on the TL-WR703N? Or do I need some kind of circuit between them?

Ouch, don't do that: all these seem to be 5V TTL I/Os and AR9331 GPIOs are only 3.3 V (don't know if they are 5V tolerant since I don't have the datasheet, but I seriously doubt)... This could kill the GPIO or worse, fry the whole chip altogether!

You might have to use some level-translator or a cheap ATmega32U4 board from eBay as an interface. This will double the cost, though.

Oh yes, didn't think about that. But would it work if I put a 74HCT08 as a 5V -> 3.3V level shifter between them? I have used one between an Arduino and a 3.3v enc28j60 ethernet shield and it worked fine.

My question should then maybe be, can I trigger a script by supplying 3.3V to a GPIO pin? How should I configure the  pin (for example GPIO7) to run a script when I feed 3.3v to it? I'm currently using kmod-w1 with a DS18B20 on GPIO29.


EDIT: or would it be better to drive a relay with the 315MHz receiver (through a transistor), and the relay would connect the GPIO29 pin to ground? That could be even easier. Or can I drive a transistor with the 315MHz receiver data pin, which would connect GPIO29 to ground?

(Last edited by monotube on 16 Aug 2012, 21:09)

Since you just need to adjust the voltage into one direction, it should be sufficient to use a voltage divider contained of two resistors.
(receiver)--(1k resistor)--(GPIO)--(2k resistor)--(GND)

Thanks, that looks like an easy and nice solution.

I found some information about how to run a script when I feed 3.3v to the GPIO pin: http://www.instructables.com/files/orig … AZRJY5.txt and https://forum.openwrt.org/viewtopic.php?id=28193

So I guess I need at least kmod-input-gpio-keys-polled and then something like this:

echo 29 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio29/direction
cat /sys/devices/virtual/gpio/gpio0/value

But how do I monitor the /sys/devices/virtual/gpio/gpio0/value continuously? Is it possible to monitor it without screen, as my flash is quite full?

#! /bin/bash

while [cat /sys/devices/virtual/gpio/gpio0/value != "1" ]

do
// nothing

done
// cat is now = 1

// do your stuff here

exit 0

Hello all,

I've been a lurker here for a while, but have recently bitten the bullet and taken the soldering iron to the TL-WR703N. I followed the previous discussion and chose GPIO pins 7 and 29 to create an I2C bus. Installing OpenWRT drivers was not too hard (although there was an issue with the kmod-i2c-algo-bit dependencies) and it works to flash LEDs on a PCF8574 IO expander. The linux kernel's drivers for the PCF8574 also work, allowing individual control of each IO pin of the PCF8574 from the filesystem.

I wrote the process up in my blog, for those who are interested:
http://pragti.ch/kippycam/Adding%20an%2 … R703N.html

Please let me know any mistakes or if there should be any clarifications.

Thanks go to imperfect and MBS for documenting their learning and inspiring me to do this.

pragtich

@pragtich: Welcome and thank you for sharing your experience!

(Last edited by Squonk on 22 Aug 2012, 23:37)

@pragtich: nice guide. but you should consider using a standard pinout for the i2c-bus, like found here: http://www.rn-wissen.de/index.php/RN-De … us_Stecker
in case you want to grow your project and merge with other available products/solutions.

MBS wrote:

@pragtich: nice guide. but you should consider using a standard pinout for the i2c-bus, like found here: http://www.rn-wissen.de/index.php/RN-De … us_Stecker
in case you want to grow your project and merge with other available products/solutions.

A quick Google shows there are about as many 'standard' I2C connectors as there are vendors...

v8rush wrote:
MBS wrote:

@pragtich: nice guide. but you should consider using a standard pinout for the i2c-bus, like found here: http://www.rn-wissen.de/index.php/RN-De … us_Stecker
in case you want to grow your project and merge with other available products/solutions.

A quick Google shows there are about as many 'standard' I2C connectors as there are vendors...

Agreed, if you want to use a "standard" socket from your fav vendor, then presumably you know how to solder.
Let's not run before we can walk.
We are getting 1-wire and I2C, but is there a full bit bang module? I haven't got that far.
But at this point we have maybe 6-8 GPIOs, now the kernel code needs addressing.
Anyone up for a challenge?
RTB

As a tribute to all of you hackers/makers, dealing with the fantastic TL-WR703N/TL-MR3020 pocket routers, here is the AR9331 pinout:



http://wiki.openwrt.org/_media/toh/tp-link/ar9331.pinout.bg.png


More on this in the corresponding Wiki page!

Enjoy wink

Alleluia! Awesome work, Squonk, thank you. smile

(Last edited by Bombyx on 27 Aug 2012, 00:17)

Thank you!

As a convenience, I added a GPIO table on the TL-WR703N main Wiki page.

Absolutely amazing work squonk!! Thank you.

Squonk wrote:

Thank you!

As a convenience, I added a GPIO table on the TL-WR703N main Wiki page.

Excellent work, thanks!

Just to contribute some info we worked out while testing my expander board with these routers regarding U6.

The chip labelled U6 on the router is not an LDO, but rather it appears to be a power distribution switch for the "3G" USB port.  It appears to be something similar to TI's TPS2051B - pin-out makes sense, but probably from another vendor based on the marking.  This is presumably in place to allow software power control of a plugged in 3G USB modem.

The enable signal appears to be controlled by GPIO8.  There is also a connection to the over-current sense, which I believe is on GPIO6.
It can be bypassed by putting a blob of solder across the empty pads labelled R113, which I've found useful to power the router from my expander board, rather than vice-versa.

Also from what I can tell, C107/C108 are for decoupling of the 5V input on the microUSB connector prior to the U5 switching reg, and not connected to the shields as mentioned in the above summary.  Similarly I think C113/C115 are decoupling the 5V at the 3G USB connector.  It looks to me that the 3 connectors have all their shields connected together, and are bypassed to GND via C37 and C114.

Hope this is of help, and I hope to contribute more when I get a spare moment back in the lab to desolder the chips on one of my units and analyse the PCB further.

Kean

Thanks Kean,

Your guess for U6 makes sense!

I wasn't aware of the availability of such chips, I learned something. Yes, GPIO8 is for active-high "USB_POWER" control, as this can be observed into the kernel source file "arch/mips/ath79/mach-tl-wr703n.c":

#define TL_WR703N_GPIO_USB_POWER    8

...

static void __init tl_wr703n_setup(void)
{
    u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
    u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);

    ath79_register_m25p80(&tl_wr703n_flash_data);
    ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr703n_leds_gpio),
                 tl_wr703n_leds_gpio);
    ath79_register_gpio_keys_polled(-1, TL_WR703N_KEYS_POLL_INTERVAL,
                    ARRAY_SIZE(tl_wr703n_gpio_keys),
                    tl_wr703n_gpio_keys);

    ath79_set_usb_power_gpio(TL_WR703N_GPIO_USB_POWER, GPIOF_OUT_INIT_HIGH, <=== HERE
                "USB power");
    ath79_register_usb();

    ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);

    ath79_register_mdio(0, 0x0);
    ath79_register_eth(0);

    ath79_register_wmac(ee, mac);
}

AFAIK, it is never turned off, at least in the OpenWRT kernel.

And GPIO6 is probably an over-current sense as you guess, as it is connected to the 6 resistors R107-R112 near U6 in a rather strange way

Blobbing R113 is a nice trick yikes

And you are probably right about the role of C113/CC15, as it is unusual to put 2 bypass capacitors in parallel.

I will update the Wiki page accordingly, if you don't mind (unless you want to do it by yourself?).

Please continue to investigate and contribute! The more people are involved, the best chances we have to understand this device in all its details

What still puzzles me is the exact role of the 2 Q1/Q2 transistors: my guess is that they are used for power-related things. Probably 1 is for the Ethernet analog power, the other one is mounted very close to the SDRAM chip on several TP-Link routers, so I don't think this is just a coincidence.

(Last edited by Squonk on 28 Aug 2012, 23:22)

Just a quick note to let you know that YOU ROCK!

I'm waiting for a second unit to arrive and I will then test an Elpida EDD5116ADTA-6B-E RAM chip.

Can't wait to get going with GPIOs after that!

Thank you for all your efforts!

</hijack thread>

About that GPIO8, I guess it explains that you can power the WR703N from an external powered hub , but only when it has actually booted and initialized that pin?

Is this a "good practice" or did I not spend enough on my cheap powered hub? Are they supposed to "back feed" 5v power like that?

Squonk wrote:

Yes, GPIO8 is for active-high "USB_POWER" control, as this can be observed into the kernel source file "arch/mips/ath79/mach-tl-wr703n.c":

Yeah, I got the GPIO numbers from the same place, and another post somewhere.  I then toggled them to verify.

Squonk wrote:

AFAIK, it is never turned off, at least in the OpenWRT kernel.

It is off until some point in the boot process, so power fed back in that port (for example from a cheap hub) won't power the device on.  (but will keep it on once U6 is enabled)

Squonk wrote:

I will update the Wiki page accordingly, if you don't mind (unless you want to do it by yourself?).

I'll leave that to you.  If I have more to contribute, I may do some wiki edits myself.

Squonk wrote:

What still puzzles me is the exact role of the 2 Q1/Q2 transistors: my guess is that they are used for power-related things.

I hadn't taken much notice of Q1 and Q2 before, so I just did some research.  They are marked "HY4C" and googling indicates it is most likely a general purpose PNP (something like MMBT3906).
Doing some circuit tracing, Q1 and Q2 appear to be used as the power transistors for voltage regulators that regulate the 3.3V supply to other required voltages.
The base connections seem to go back to the Atheros chip, so it presumably handles the regulation but needs external transistors depending on power requirements.
Q1 is for the 2V supply into the ethernet magnetics, and mine measures at about 2.12V out.  Q2 is the the RAM power supply, and measures about 2.45V.

Kean

ZotDitzMyo wrote:

About that GPIO8, I guess it explains that you can power the WR703N from an external powered hub , but only when it has actually booted and initialized that pin?

Correct.  As per my previous post, the USB power controller is off until some point in the boot process.  You can short out R113 to get around that (but lose the USB power control function).  This is actually really useful as it saves having to also connect the micro USB connector for power when the router is being used in unintended ways (e.g. on a quadcopter!).

ZotDitzMyo wrote:

Is this a "good practice" or did I not spend enough on my cheap powered hub? Are they supposed to "back feed" 5v power like that?

This is quite common in cheap USB hubs, but I believe it is against the USB standard.  According to a post on the Raspberry Pi forums [1] the standard states "No device shall supply (source) current on VBUS at its upstream facing port at any time".  I haven't checked, but it sounds right to me.  Most hubs don't include the diode, as that would drop between 0.3V and 1.0V (depending on diode type and current draw) when used in bus powered mode.  A FET is needed to reduce that voltage drop, and they just don't bother.  (I didn't bother implementing this properly on the hub in my expander board [2] either)

Kean

[1] http://www.raspberrypi.org/phpBB3/viewt … p;p=160513 and http://www.element14.com/community/thre … 6?tstart=0
[2] http://www.kean.com.au/oshw/WR703N/