uanr.com - Up All Night Robotics presents: (Russian)

SD/MMC card fits in floppy edge-connector

You can attach an SD camera memory card to any homebrew DIY project that has a few I/O pins, using ordinary connectors you probably have right now.
SD cards are very popular for this purpose, because they only need a few pins (using SPI mode), and can be driven with simple "bit-bashed" SPI serial communications protocol, using free device drivers readily available on the Internet. Until now, the big holdup for using an SD card in many homebrew projects has been the fact that SD sockets are not available at your local store, are not cheap (especially after shipping), and require ordering and waiting for them to arrive. But wait no longer! You can do it now! If not just laying around, or inside an old unused computer, you may have a spare connector inside the computer you are reading this with right now. ;-)

My computer has an unused 5.25 floppy drive card edge connector just hanging off the end of the floppy drive cable, ready to snip off with a pair of scissors (with the computer unplugged, of course). If you don't have one, one of your friends may be able to part with one of theirs. ;-)


Table of Contents:

Introduction
How To
FAQ - Frequently Asked Questions
References
Statistics
Donations

"How To":

The following images show how to put one of these connectors on a WRT54G(v4). This step-by-step procedure will work just as well for other devices that support mmc device drivers. Other websites show how to connect the wires to I/O pins in this and other devices (see References section below).

After much feedback from visitors to this web site, this webpage has grown to include a lot of text. If you do not care for detailed technical information, please feel free to just look at the photos and descriptive filenames below them, and refer to the text to answer any questions you may have.


01_floppy_cable.jpg

Here is the standard PC floppy cable we will use for this hardware hack, with an SD card waiting patiently to mate with the connector. ;-)



02_5.25in_floppy_connector.jpg

Here is a closeup of the 5.25 1.2 MB floppy edge connector. If you look closely, you can see the pin numbers in this photo. We use the even pins for this hack.



03_good_pin_alignment.jpg

I tried a lot of different connectors I had laying around to find one that could be used as an SD card socket. Here a floppy edge connector is being tested for SD card fit and alignment. You can see how well the (partially inserted) SD card pins align in the floppy connector. You can see the upper connector pins reflecting from the SD card pin pads.

Also, you can see that the ridge on the edge of the SD card slides firmly into the groove in the connector plastic pin separator, which aids card alignment (when the card is inserted using the connector even pins).

It causes no harm to insert the SD card backward, because the odd pins are not used in this application.



04_fully_inserted.jpg

Here is a front view of the SD card, fully inserted into the floppy edge-connector. Be sure to firmly insert the card until it is all the way in.



05_new_sd_cable.jpg

Here is a photo of the ribbon cable already soldered into the wireless router, with the wires spread and pressed partially into the backs of the connector pins.

For more details on where to connect the wires inside your wireless router, detailed links are provided at the bottom of this page.

A closeup of the connector at this point can be seen in the next photo.



06_wire_even_pins.jpg

Here is a closeup of a strip of ribbon cable I "peeled off" from a scrapped 25-pin serial cable. You can use part of the floppy cable if you wish. When I salvage strips of ribbon cable like this, I run a red magic marker down the "pin 1" side of the cable.

You can see that I have carefully removed the back of the connector (by lifting the spring-loaded side clips with a small screwdriver), and pulled off the old ribbon cable. If you accidentally bend any of the connector pins, straighten them with a small needle-nose pliers before continuing.

Spread the wires back enough to fit the connector, then push them down between the odd-numbered pins, and push them slightly into the sharp slots in the even numbered pins (as shown in the photo) using a small needle-nose pliers or screwdriver. When inserting the wires, note that the pins on the small side of the plastic connector edge guide separator are not used in this application. You do not need to push the wires all the way in, because that will be done when the connector back is squeezed on later.



07_squeeze_together.jpg

Now we snap the connector back onto the connector. Then we squeeze the connector on firmly with a vise, C-clamp, vise-grips(TM), or whatever. I have even carefully used a hammer to gently tap the connector backs into place, but I much prefer a tool that applies firm even pressure, as I did for this photo. Squeezing the connector like this forces the wires down into the sharp slots in the backs of the pins, cutting through the plastic insulation and making firm electrical contacts between the wires and the pins. When the back is pressed on fully, the side clips snap securely back into place.



08_label_and_guide_shim.jpg

Here is the completed SD floppy connector, with label attached showing which way to insert the SD card, and with a guide shim (cut from a plastic soda pop bottle) folded over and inserted to help guide the SD card into the proper pins.

It works!


FAQ - Frequently Asked Questions:

(All questions and comments were cut-and-pasted from various online discussions about this web page.)

1. "Wow! a bunch of pictures than mean nothing!"

Although the photos and their filenames are quite self-descriptive, I have since added detailed descriptions, which I hope will aid vision-impaired people (or people who do not like photo essays). Other replies:

A picture is worth a thousand words! .. -klang, 9/13/06

2. "it doesn't even show where to connect it inside the WRT.."

This web page is meant to solve the problem of connecting an SD card to any device with spare I/O pins without having to special-order an expensive SD socket. I do not intend to duplicate the efforts of other web pages that already give great "How To" instructions (with photos) on how to connect to the I/O pins of specific devices. That is why this web page has always said "to find out exactly where to connect to the I/O pins inside your router, please refer to these web pages:" followed by links to web pages that provide those details. I show photos of a WRT54G(v4) only as an example. Please refer to the links in the References section for details.

3. "Thats a good hack, if your board already has a MMC interface onboard you can solder on to."

Your "board" does not need an MMC interface. All you need are a couple of GPIO (General Purpose I/O) pins, and you can "bit-bang" ("bit-bash") the SPI protocol used by the SD card in MMC mode. You need a clock output, a data output, and an (optional) data input. Instead of using a separate SPI data input GPIO pin, you can wire it through a current-limiting resistor to the SPI data output line, then switch I/O directions between SD/MMC reads and writes. This technique is common in the PIC microcontroller world. We can use it in Linux-based routers and other hackable embedded devices as well.

4. "To be really useful for anything except embedded work (though it is pretty schweet for that) you are going to need to come up with a way to auto align the pins. It should be pretty simple to cut down or otherwise modify the connector to do this. It looks like all it would require is a pair of rails to force proper alignment."

You don't need to modify the connector (other than insert a plastic alignment guide). You do not need rails to force pin alignment. The outer edges of the SD card contain grooves that catch in the floppy socket, and the card aligns nicely against the edge of the floppy connector alignment key ... (see above description for more details).

5. "The main limitation on the WRT54G is the 8 megs of RAM (4 meg on some of the newer models). This doesn't help that at all. It is useful for storage, but it won't help you run more softare."

A swapfile simulates RAM using a storage device, and let's you run software that otherwise won't fit in limited RAM. I use a swapfile on my SD card. Recently, I installed a separate swap partition on a larger SD card. Although a swapfile can be slow, it is faster using my new MMC drivers. I sometimes mount a swapfile over a wired network connection for even more speed. I have a FairuzaWrt firmware image file on my SD card, and I mount the embedded filesystem as a loopback device. I run the FairuzaWrt menu and applications (like nmap pingsweep) on my WRT54G(v4) with only 8 MB RAM with no problems. FairuzaWrt applications normally do not fit on a router with less than 16 MB RAM. I also have a DD-WRT firmware image that I mount as well. I use the DD-WRT busybox application (renamed as busybox-ddwrt) with symlinks to the functions that are missing from the OpenWrt busybox. I have a busybox-batbox file too... ;-)

6. "and... this is useful for the linksys wrtg54g for what?"

There were several good answers posted for this one:

DDWRT (replacement firmware) is a good place to start. People are running E-mail, Web Servers, and pretty much anything else you can run under linux on the WRT54G. -violentvinyl, 9/13/06

For those that do not have a WRT54g or any of the similar models, the firmware that runs this particular router is a *nix-based system ... You are limited to what kind of daemons that you can have running by what you can put into the limited firmware memory. If you can expand that memory, you greatly expand the possibilities for what the router can do. -cogit0, 9/13/06

It allows more space for your linux apps to run on modified firmware (DD-WRT, OpenWRT, etc..). Can also store large logs locally instead of dumping them to a server. -deacont23, 9/13/06

For those of you who still ask why: many advanced features are available after you install custom firmware (like http://www.dd-wrt.com); such as transmit power boost (up to 250mW), VPN server endpoints, syslog clients, QoS and the ability to install additional packages like a spam filter and a torrent client (if you mount a drive or a network drive) and so on. I use 'em for dedicated LAN bridging at work, and OpenVPN endpoints at home. -CptFuzzy, 9/13/06

7. "Nice to see someone working on it. Can you please figure out how to read the write protect switch and handle hotswapping?"

The write protect switch is a mechanical switch built into a *real* SD socket (that's why they cost *real* money). The easy way to read it is to connect the switch pins across a switch in the router (i.e. reset switch or front panel switch). The script that mounts the mmc device should decide whether to mount it "rw" (read-write) or "ro" (read-only), by checking the input pin connected to the write-protect switch (with the GPIO utility). For hotswapping, as long as you "umount" (unmount) the SD card so Linux does not read or write to it, the SD card is "tri-stated" when not selected, and it is safe to insert or remove it with power applied. During testing I used a software loop that continuously "sniffed" the partition table on the SD card and displayed what it found, while I plugged and unplugged multiple SD cards formatted in various ways. Hotswapping even while accessing the cards did not cause any damage to them or their data, although their filesystems were not mounted at the time. I do not recommend hotswapping a mounted filesystem without unmounting it first.

8. "I have problems to mount my 4GB SD Card, manufactor "extremememory". It works perfekt with a 512 MB SD card."

The original mmc.o driver for OpenWrt does not supports 4 GB SD cards because the byte address sent to the mmc/sd card is 32 bits, and the arithmetic that calculates this from the block address uses a SIGNED number. Therefore, the original mmc.o driver only supports cards whose size is between -2 GB and +2 GB. This is a common problem with most devices that use SD, because the SD specification only goes up to 2 GB, and 4 GB SD cards are outside the spec and are therefore non-standard. The new SD 2.0 (SDHC) standard supports 4 GB and larger cards using sector-addressing rather than byte-addressing. I have made extensive changes to MY copy of mmc.c, and I added support for 4 GB SD cards. I plan to add SDHC support to the mmc.o driver as well...

9. "I understand that Secure Digital is propriatry code, are there any open source read/write drivers that have been written?"

Actually, the (previously expensive) SD specs are now (somewhat) open, and open-source SD-mode drivers HAVE been written, but have not (yet) been ported to OpenWRT. SD protocol requires the extra pins that are provided by a *real* SD socket. However, MMC-mode does not need the SD pins, supports 4-bit data transfers (like SD), and can share the GPIO pins without needing individual SPI-mode chip select pins. Full MMC-mode drivers (with address resolution protocol) are available, and will work using a floppy edge connector for the SD socket, but still need to be ported to the WRT54G platform.

10. "That's awesome. but where can I download the updated mmc driver"

I am reconstructing source code in my "spare" time from various backup copies (Windows ate it and many other files during a bootup disk scan after a system lockup. I lost more code when I did "tar -zcvf" instead of "tar -zxvf" during a late night session. Sometimes sleep is a good thing, despite a boss who often said "there is plenty of time to sleep after you are dead." I do have an mmc.o module that I have been using since 2006-February-18 in one of my routers, and it is quite stable (but has no 4 GB SD card support). I hope to be finished soon (a matter of days).

11. "Would this be possible to hook directly to a computer?"

Yes! My next hack is an "el-cheapo parallel port SD card reader" using only salvaged floppy and printer cables, and some resistors (no circuit board needed). This should even work with old laptop computers that do not have USB ports. When complete (soon), I will submit my "el-cheapo parallel port SD card reader" to hackaday. :-)

12. "Szerzo: vakangyal
Datum: v, 2006-09-17 15:49
haly
esetleg ez? :)
http://uanr.com/sdfloppy/"

Huh?


References:

There are mmc device drivers available for free on the Internet, ready to use with PIC (or other) microcontrollers, wireless routers (running OpenWrt or DD-WRT Linux firmware), and many other embedded appliances. These drivers allow using the SD card just like a miniature hard disk. At this time (2006-September-12) new 1 GigaByte SD cards can be purchased for as little as $16, or "obsolete" smaller ones (like in the photos) may be sitting unused in desk drawers of friends, relatives, neighbors (just ask). ;-)

Because many wireless routers (and other embedded appliances) run the Linux open source Operating System, there are many hundreds of totally free software packages ready to install and run in these devices. There is even a complete native software development toolchain (compiler, linker, etc.) that runs completely inside a WRT54G (with swapfile on SD card). I am currently booting my WRT54G into OpenWrt on a 512 MB SD card, and I have MANY packages installed to their default locations (which is now on the SD card). I have even ported Tom Pittman's TinyBasic, and can run TinyLife.BAS and TinyAdventure.BAS inside my router (while logged into the router with a remote terminal program). ;-)

For more details on upgrading a wireless router with OpenWrt or DD-WRT firmware, or to find out exactly where to connect to the I/O pins inside your router, please refer to these web pages:

OpenWrt Wireless Freedom
DD-WRT Control Panel
Adding an MMC/SD Card (hardware)
beakmyn's WRT modding page (with mmc drivers)
WRT54GS or WRT54GL wireless router for $5 plus $8 shipping (preloaded with DD-WRT).


MMC Device Driver Project Status:

My mmc driver has been optimized to leave interrupts ON where appropriate, so other sessions are not bogged down during lengthy SD card I/O (such as using dd to copy a partition on the SD card). I also rewrote the SPI bitbang routines to use separate input-only and output-only subroutines, and to use word-based rather than bit-based I/O, so I can output the clock and data at the same time (only 2 GPIO outputs per data bit). Input from the SD card requires 2 outputs plus an input, so it is a little slower.

I also output to both GPIO2 and GPIO5, so my driver works fine with either router wiring version. It does not take any extra time to output a clock bit plus 2 outputs to the sd card, when outputting an entire word in parallel to the GPIO port. My GPIO outputs are 32 bits, because testing showed this to be faster than 8-bit outputs to these ports.

There seems to be a hardware wait-state generated during GPIO output, because writing to the port is far slower than writing to RAM. Also, timing analysis shows that the SD card itself takes extra time during sequential reads or writes when it crosses an erase-block boundary. Diffierent SD cards have different timing boundaries.

Although I have not done it yet, I plan to also support using DI and DO sharing a single GPIO bit, as is commonly done using PIC microcontrollers, by tying the SD card output pin to its input pin via a resistor. My code changes will need to change the data direction on the shared GPIO pin between reads and writes to the SD card.

I turn off the WRT54G front panel amber LED before exiting from the mmc driver, so the LED doubles as a "disk access" light. I have made numerous other small corrections to the code as well.

I am booting (pivotroot) from my SD card ext3 partition, and I also have a second partition formatted as JFFS2. In theory, the effective throughput should be faster sending COMPRESSED data over the slow bit-bang SPI bus. Because JFFS2 always does an integrity check during mount, it takes several minutes to mount, so my /etc/init.d startup script launches the mount in the background so booting can continue. The JFFS2 partition mount point is empty for several minutes after booting, until the background mount completes.

I have updated the mmc.o driver from the OpenWrt package to run much faster and to place much less load on the router. I will post the updated driver soon. Later, I want to incorporate features from other mmc device drivers available from a number of sources, for various embedded devices. OpenWrt and DD-WRT either have an mmc device driver built-in, or as an installable package. There is a much more complete mmc device driver available from HP, and another from Yong-Il Joh that has some additional features that would be nice to have. There are also drivers for PIC microcontrollers and other devices designed to use minimal resources. I want to incorporate features from all of these into my final mmc device driver.

To bypass booting (pivotroot) my WRT54G from the ext3 partition on my SD card, I can press the RESET button within one second of when the front panel amber LED first comes on. Startup scripts launch mounting the SD card JFFS2 partition in the background so booting can continue. The JFFS2 mount point is empty for several minutes after booting, while complete JFFS2 integrity testing is done, until the mount completes. Because the filesystem root is on my SD card, I have installed MANY OpenWRT software packages without having to reconfigure them for non-default installs. :-)

SD floppy details here:
http://uanr.com/sdfloppy/

My OpenWrt mmc driver status:
http://uanr.com/mmc/

My 802.11b/g Wifi Spectrum Scans:
http://uanr.com/wifiscans/

UANR.com Home
http://uanr.com


Statistics

I have multiple hit counters for testing purposes. All these counters agreed with each other after setting them up, but soon started deviating. Apparently they lose counts, so the real value is greater than what is seen here:

Hits since site posted to hack a day:


Donations

To see more cool stuff, please support this website.
Digg this page
Bookmark this page on Google
Submit this page to Reddit
Stumble Upon this page
This page is del.icio.us!
Fave this page on Technorati
Bookmark this page on Yahoo

- Rob Wentworth
- (uanr<at>RobWentworth<dot>com)
- This web page created 2006-Sept-12, latest update 2007-Mar-26.