Getting SPI on a router

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.

Comments

  1. Hack Man says:

    http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=60979

    What is the maximium reliable transmission length for 4 wire SPI?

  2. Json says:

    Why not just program this box to do what you want?

    • evolotion says:

      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.

  3. rasz says:

    this is using gpio bitbanging = weaksauce
    router has full hardware SPI that can be used after unloading spi flash driver

    • Chris C. says:

      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?

  4. Joost says:

    For the price there is nothing that can compete with the 703N. Most of the you don’t even need a microcontroller

    • Mike Szczys says:

      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).

  5. vonskippy says:

    Mentioning SPI with a router usually means Stateful Packet Inspection.

  6. Mark says:

    How can you use the hardware SPI? If there is one on board, why would one want a software SPI? Thanks!

    • Drone says:

      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.

  7. 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 openwrt.org .
    The file should orginally look like this :
    ::sysinit:/etc/init.d/rcS
    ::shutdown:/sbin/halt
    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 :
    ::sysinit:/etc/init.d/rcS
    ::shutdown:/sbin/halt
    # 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 92,317 other followers