D-LINK DIR-300 Serial Port and SD mod

The latest progress of my freeBSD port for CNS21XX and ThinkLink Hot-e was three weeks ago. The CNS21XX network driver and Hot-e network driver was completed. I haven’t touched anything since then because I had to work on weekends at the office. This weekend, I could have continued coding, but I don’t feel like coding, so I did a hardware project: adding serial port and SD card slot to my D-LINK DIR-300 that I bought April last year.

This is not a difficult project, I already added SD/MMC card to my WRT54GL about 2,5 years ago. The difference is that there isn’t much guide about the hardware part (which GPIO pins to solder), and the software part (how to activate the drivers). So here is a short guide to anyone who needs it. Note that I already installed OpenWRT Kamikaze using the guide from: OpenWRT site.

This is what the front side of PCB looks like:


On the bottom right, you can connect a serial port (note: 3.3V, you will need MAX3232 or use a data cable from phone, don’t connect directly). Many guides are already available for connecting serial port (for example: here, here, here, and here), so I wont write about it. Just note that you will use the 3.3V and GND for the SD card mod.


This is what the PCB looks like from the back:


I found the GPIO pins from this posting by guidoa:

1: SES Button Blue led (Enable=ON)
2: WiFi led
3: SES Button Red led (Enable=ON)
4: SES Button (Pressed=01)
6: Reset Button (Pressed=01)
7: Status led (Enable=ON)

I have confirmed it using voltmeter and gpioctl command line tool. The SES button is the button on the right side of the unit. As far as I know, SES button, and the LEDS (red and blue) are not used by default, the Wifi LED is used to indicate Wifi ON/OFF. So we can use GPIO 1,3,4. We need another one: we can use GPIO 6 or 7. Since The status led is not used, I prefer GPIO 7. You can see the location of the GPIO pins that I used from the above picture.

Now, look at the SD Card Pinout (you can search it in Google, or just look here).
You need to connect SD Pin 4 to to 3.3V (see the serial port above), Pin 3 and 6 to GND. The rest is up to you (we will configure this later in software). This is what I use:

  • Pin 2 (Data In/MOSI) to GPIO 4 (SES Button)
  • Pin 7 (Data Out/MISO) to GPIO 7 (Status LED)
  • Pin 5 in SD Card (CLK) to GPIO 1 (blue LED)
  • Pin 1 in SD Card (Chip Select) to GPIO 3 (red LED)

After you solder them, you need to install these packages using opkg: kmod-mmc, kmod-mmc-over-gpio, kmod-mmc-spi, kmod-spi-bitbang, and kmod-spi-gpio. We need to edit /etc/init.d/mmc_over_gpio. The line that you are looking for is the add_device "default". There are some numbers in the following order DI, DO, CLK, CS and SPI_MODE. You need to fill in the GPIO that you use for each of that pins and just fill in 0 for SPI_MODE. In my case I edit the line to become: add_device "default" 4 7 1 3 0.

Now I can start the SD card using: /etc/init.d/mmc_over_gpio start. You can now mount the card. To remove the card, umount the card and /etc/init.d/mmc_over_gpio stop. The SD card speed is to slow, I will look on to this later, but for now the speed is enough for me.

This is my final result (I am really lousy at soldering):


Doesn’t look too bad from the outside for the SD Card:


But I made a stupid mistake for the RS232 port. I put the port on the wrong place, and I can not drill for the screw on the right side of the port. Fortunately this is not fatal, I just glued the port to the casing.

DLINK DIR-300 Serial Port

Update This is the dmesg log after /etc/init.d/mmc_over_gpio start

gpio-mmc: Failed to request mmc_spi module.
mmc_spi spi32765.0: SD/MMC host mmc0, no DMA, no WP, no poweroff
gpio-mmc: MMC-Card "default" attached to GPIO pins di=4, do=7, clk=1, cs=3
mmc_spi spi32765.0: can't change chip-select polarity
mmc0: new SD card on SPI
mmcblk0: mmc0:0000 SD512 495488KiB
 mmcblk0: p1

Update 9 April 2010 to make it clear, this is the picture of the back side of the pcb after soldering:

back side of DLink DIR-300

42 thoughts on “D-LINK DIR-300 Serial Port and SD mod”

  1. Hi, thanks for your explain. I made this how you explain and have Kamikaze (r18961) (latest firmware) but when i do: /etc/mmc_over_gpio start say this error in log:

    gpio-mmc: Failed to request mmc_spi module.
    mmc_spi spi32764.0: SD/MMC host mmc0, no DMA, no WP, no poweroff
    gpio-mmc: MMC-Card “default” attached to GPIO pins di=4, do=7, clk=1, cs=3
    mmc_spi spi32764.0: can’t change chip-select polarity
    mmc0: error -5 whilst initialising SD card

    Any idea? What version of Openwrt you use?

    Sorry for my english 🙂

    Thanks anyway for this guide!!! 😀

    Greetings from Argentina!

  2. Hi Yak,

    I am using KAMIKAZE (8.09, r14511), I haven’t upgrade since last year.

    I also didn’t get it right the first time, some of the things to check:

    – Cable and soldering
    – Make sure the SD Card supports SPI. I have an old microSD (64mb) card that doesn’t support SPI mode, after using another card that I have, it works.
    – Curently Iam using SD card with small capacity (512 Mb), I don’t know if the driver supports SDHC card or not. So try with SD Card less than 2 Gb.

    I have double checked everyhing when I wrote the guide, but I will check my guide again when I got home, to see if there is something wrong in the stuff that I wrote.

  3. Thanks for answer. I use a 2gb MicroSD (TransFlash) SanDisk card with adapter:

    I solder this today and flash with same firmware version as you uses.

    I update and solder the SD with cables and search for SPI compatibily for this microSD.

    Thanks 😉 Excellent blog 😀

  4. I search in many sites and many people say that MicroSD SanDisk dont support SPI mode :S 🙁 do you have any info about this?

    Thanks 😉

  5. From Wikipedia, it says thatk all SanDisk cards support SPI mode. I have uploaded the back side of the PCB, and it seems I have written everything correctly.

    May be you can post your picture of your work, so I can see/compare?

  6. I was looking for some hacks for the dir 300 and found your side! Awesome hack :D. I will try to do the same with my DIR 300 :).

    Greets from germany!

  7. Hey,

    i tried the hack today. It works really nice, but i have just a 128mb card :(. However still more than before :D.

    To mount the card install:

    And mount the card with:
    mount -t vfat /dev/mmcblk0p1 /mnt/mmc -o rw

    My Firmware: Kamikaze (r16206)

    Greets Pablo.

  8. Hi Yohanes!

    I got that Router, too and will try the mod 🙂
    By the way, could you please upload your latest linux-patch for the agestar nas? It would be really nice 😉 I am going to try out a few things – Thank you a lot!!!

  9. I’m getting this.

    root@OpenWrt:~# /etc/init.d/mmc_over_gpio start
    configfs on /config type configfs (rw)
    mkdir: cannot create directory ‘/config/gpiommc/default’: No such file or directory

    Did I get the soldering wrong or something? Learning how to solder again in one day was quite interesting.

    I am using x-wrt Kamikaze, but I don’t think it matters, as I’ve installed all packages.

  10. @anon you don’t have gpiommc, mmc_spi, mmc_block, and mmc_core kernel modules installed

    here is the first few lines of my lsmod:

    root@OpenWrt:~# lsmod
    Module                  Size  Used by    Tainted: P
    gpiommc                 4160  1
    spi_gpio                3712  1 gpiommc
    spi_bitbang             3360  1 spi_gpio
    mmc_spi                 7296  0
    mmc_block               7344  0
    mmc_core               32768  2 mmc_spi,mmc_block

    May be you need additional package, or may be you need to compile something by yourself. The easiest is just test with openWRT which has all the modules to check your soldering work, and then back to X-WRT if you prefer it more.

  11. Well… I got the same error using normal OpenWRT . Do I have to compile myself to get those additional modules? Packages won’t do? How did you get it right?

    I’ll use dd-wrt just to see if my soldering works, then I’ll go back to openwrt, and try some other things if there’s no easy answer to this.

  12. @anon:

    With openwrt, you need to install these packages using opkg: kmod-mmc, kmod-mmc-over-gpio, kmod-mmc-spi, kmod-spi-bitbang, and kmod-spi-gpio. After you install it, these modules should be loaded automatically on boot.

  13. Just a dumb question: did you use a level converted to install the serial port or not? I couldn’t fine any information on the signal levels of the dir-300.


  14. huh… I’m getting
    mount: mounting /dev/mmcblk0p1 on /mnt/mmc failed: Invalid argument

    all the time… No errors in dmesg, I have no idea what’s the cause. I re-checked soldering three times, I shortened the wires, I even downgraded from 10.03.1rc1 to 8.09.2 to check if it’s working… but no, it isn’t. I can’t mount the card, even though:

    gpio-mmc: Failed to request mmc_spi module.
    mmc_spi spi32766.0: SD/MMC host mmc0, no DMA, no WP, no poweroff
    gpio-mmc: MMC-Card “default” attached to GPIO pins di=4, do=2, clk=1, cs=3
    mmc_spi spi32766.0: can’t change chip-select polarity
    mmc0: new SD card on SPI
    mmcblk0: mmc0:0000 SA02G 1921024KiB
    mmcblk0: p1

    That means soldering is OK and the card is recognized, right?

    fsck results in

    root@OpenWrt:/mnt# e2fsck /dev/mmcblk0p1
    e2fsck 1.40.11 (17-June-2008)
    e2fsck: Superblock invalid, trying backup blocks…
    e2fsck: Bad magic number in super-block while trying to open /dev/mmcblk0p1

    The superblock could not be read or does not describe a correct ext2
    filesystem. If the device is valid and it really contains an ext2
    filesystem (and not swap or ufs or something else), then the superblock
    is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193

    Any help would be appreciated, I’d really like to get this working!
    The only thing I changed, compared to your tutorial, was instead of using GPIO7, I’m using GPIO2 (because for some reason wifi driver blinks with status led instead of wifi one, lol)

  15. I’ve got the same error.
    The problem was that my card had FAT filesystem.
    I installed following packages

    than I had to reboot the router. Only after this my card mounted by the comand

    mount -t vfat /dev/mmcblk0p1 /mnt/card

  16. Yout wrote :
    “The SD card speed is to SLOW, I will look on to this later, but for now the speed is enough for me.”

    So, what was the problem, Is is still SLOW?
    Did you fixed ?
    Is It problem with “Failed to request mmc_spi module.”
    (that you wrote in “Update” ?)

    I’am using Openwrt 10.03.1-rc4 (atheros)
    It will work with this version ?

    Best Regards!

  17. I have a DIR-300 Revision A1 and when I read this article I was interested in this mod, but I have some questions about this.

    First: I Have a 2GB microSD that comes with a Nokia E17 smartphone that I don´t use. I am thinking about use it with an SD adapter. My question is… This microSD is SPI?

    Second: Using this mod… Can I use it like an additional amount of RAM to this device?

    Third: I need to do the other mod to? The terminal? Or they are independent?

    I´m awaiting answers… Sorry about my english…


  18. @aloosek i didn’t do anything with the speed (still slow). It should work with latest openwrt.

    @Thiago: (1) usually microSD supports SPI. (2) You can not use it as extra RAM, but use it as swap space (which is like extra RAM). (3) The serial MOD is not related to the SD mod. You can do the serial only or SD only or both.

  19. Just to share my results…

    Backfire (10.03.1-rc4, r24045):
    GPIO’s have to be configured in /etc/config/mmc_over_gpio

    SD which doesn’t work (for me):
    – Sandisk 2GB
    – PNY 1 GB

    SD which does work:
    – Hama 2 GB

    Speed is really slow. Anyone some suggestions to fix this?

    Anyway… Thank you for this hack! As a software guy, I am always lost in hardware hacks ;-)…

  20. Just did the terminal mod today, did it without MAX232 (had a USB cable), works like a charm except that nobody noted that you have to connect Rx->Tx and Tx->Rx, on all schemes it looks like Tx->Tx and Rx->Rx. But anyway. I HAZ A CONSOLE, YAY! <3 I actually connected it using a 3,5 Jack port – it doesn't take as much space as the serial port and looks better.

    As for the other mod (SD), I've been using it for around a year now. The problem with it is that sometimes an error occurs on GPIO, the memory card gets corrupt ("unclean") and I have to run e2fsck for it to mount again… really troublesome. What's more, I just updated to 10.03.1-rc4. The data transfer speed in 8.09 was incomparably higher than it is in 10.03.1. I wonder why is this happening? I tried "echoing" 0 to the spi_delay file, but it just stays at 1 whatever I do, any ideas? It's really iritating, it was like 20-40kB/s on 8.09 and now it's under 5kB/s… (slower than turtles)

  21. @Alien, about my question above – the solution was to format the card from router, somehow the ext2 partition format I created using ubuntu is different to the one openwrt creates

  22. I’ve just soldered the sd card onto the dir-300 and mounted a ext2 formatted partition. This seems to work nice but the router keeps restarting when i try to install openvpn onto the card … any idea why this happens?

  23. @Florian: Most likely it runs out of memory. Try to add a swap partition on the sd card (use fdisk to create two partitions etc), use mkswap to format it, then swapon to enable it.
    Check if it works using ‘free’ and try to install openvpn again.

  24. I have DIR-600 Rev B2 that in http://www.openwrt.org said that it has the same hardware as DIR-300 has.
    This is my linux version Linux
    root@OpenWrt:~# uname -a
    OpenWrt #3 Thu Sep 15 15:04:32 IRDT 2011 mips GNU/Linux
    I installed gpioctl but there is no /dev/gpio folder.
    (Error whilst opening /dev/gpio)

    root@OpenWrt:~# find / -name gpio*

    Any idea ?!
    Any help will be appritiated

  25. Works like a charm!

    I tried both a FAT and ext2 cards. When a FAT MMC card is used it is important to reboot the router after the relevant modules (listed before by @Pablo) are installed.

    Now I have enough space to install and run OpenVPN server on my DIR-300. Yipee!

    @yohanes thank you for this post

  26. I have no experience with such things, but do you think that adding a usb port to this router is possible? There are two hardware versions of this router. A1 and B1. I have B1. For witch hardware version is the sd mod?

    1. Hi M.M.M I think yes the serial port works, but dependently the use, I mean for example to connect an Arduino yes works very fine.

  27. Hi !! here im trying to get the serial conexion to work …. not success yet.
    Im using the trendnet tu-69 cable.
    Already solded the pinout to db9 female cable.
    Using putty / minicom … but only get garbage output.
    ���”��r-{h�����[(9���M�@��u_g���x��BE�2��,�����”���a]a��� ���-����X=� 
    Mine is a dlink dir300.
    I think … if i get some output there is no pinout problem nor voltege levels…
    so , it should be a setting problem , I have tryed many configs, would you post yours ??

    1. Hi, try select another speed in the Com Communication, You use a MAX232 right?, Personally I use this hack serial mods for used in Arduino projects, using /dev/cua/1 (Serial port) but if I connect the serial port to the computer and then type for example echo “Hello world” > /dev/cua/1 I don’t received the message, I received characters rare, I think this is a TTL problem, because I don’t use MAX232 for the serial connection.

      1. Sorry, I forget say: Aparently I recieved the same garbage in the output Serial port, but The arduino connection works fine, I mean Directly with Serial port Router (No MAX232). I have a WRT54GL and WRT54G v2.2, and this week I will try with this router (airlink AR430W it’s a DIR-300 Clone). Thanks for the info Yohanes this blog is very cool!

Leave a Reply

Your email address will not be published. Required fields are marked *