Getting SPI On A Router


Cheap routers such a s the TP-LINK 703n and the TP-LINK MR3020 (seen above) can be used for much more than just connecting your laptop to your cable modem. They’re actually very small Linux boxes and with OpenWRT, you can control every aspect of these tiny pocket-sized computers. It’s frequently been suggested that these routers are awesome substitutes for the usual methods of getting Internet on a microcontroller, but how do you actually do that? The onboard serial port is a great start, but this also dumps output from the Linux console. What you need here is an SPI connection, and [ramcoderdude] has just the solution for you.

Linux already has a few SPI modules, but these are only accessible with kernel drivers. Traditionally, the only way to access SPI is to recompile the kernel, but [coderdude] created a kernel module that allows any device running the Attitude Adjustment OpenWRT image to dynamically allocate SPI busses.

He’s already submitted this patch to the OpenWRT devs, and hopefully it will be included in future updates. Very cool, we think, and something that can open a whole lot of doors for hacking up routers very easily.

13 thoughts on “Getting SPI On A Router

    1. They dont have a lot of gpio, and some tasks are just quicker to throw together of you use the likes of an arduino(gasp) and all its habdy libraries leaving the router to do what it does best with the network side of things.

    1. You don’t need the high speed of hardware SPI to do, for example, a few hundred samples per second from an external DAC. And I’d prefer to use a separate bus when possible, rather than worrying that the additional wire length on the bus might cause higher speed comms with the FLASH to glitch at boot.

      So I like this idea. Is there a similar solution for dynamically allocating I2C channels?

      1. I should probably add to that post that i got more than 1MHz from the SPI over GPIO. It’s near to what you would get with an hardware SPI on a MCU so i think it’s ok for most applications.
        I too prefer to keep things separated (and also i want to keep access to flash).

        For i2c there is already a module called i2c-gpio-custom (in fact i used it as a template):

    1. Not just the price. They’re tiny which means you can throw one in the trunk of your car — never really noticing it’s there — and you’ve always got the equipment for a WiFi AP when you need it (assuming you have an Ethernet connection available).

    1. Even if there is hardware SPI, trying to get the likes of Broadcom or some Chinese ARM Spewer to provide the documentation on how to access it is likely impossible. You can try hacking it, but typically something like native SPI is connected to something like the AMBA bus in the SoC. Good luck getting around that, even if you do, then to get speed out of the native SPI you’re going to need native DMA support – again, no documentation and the chip manufacturers will not talk to you.

  1. You can still use the serial port.
    Have this note on how to turn off the console output
    (don’t have the source, sorry)

    To remove the Console from /dev/tts/0 you have to login in your wrt -box via telnet or ssh
    and edit the file /etc/inittab , how to edit files at yaour router is described anywhere here at .
    The file should orginally look like this :
    tts/0::askfirst:/bin/ash –login
    You have to comment out the last line in this file , after change it , it should look like this :
    # tts/0::askfirst:/bin/ash –login
    in short words : you have to disable the last line , you can do comment it out or delete it
    save the modified inittab -file and reboot your router
    and … after this modification you should not have the console on /dev/tts/0
    this modification disable the console from /dev/tts/0

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.