Apr 21, 2013

D-LINK DIR-300 SD module and Serial Port

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

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)
  5. Reset Button (Pressed=01)
  6. 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):

This is the picture of the back side of the pcb after soldering:

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

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

Via tinyhack


Way cool! Some very valid points! I appreciate you writing this write-up plus the rest of the website
is extremely good.

my page - affordable teeth whitening

Post a Comment