Using CompactFlash Cards in Your Embedded Linux System
When designing embedded systems, the designer has many choices to make. If you sell thousands of units, you spend lots of time designing around the most inexpensive parts you can find. You design custom circuit boards and search high and low for the best components that you can get for the cheapest price.
If you build only one or two units, the time and cost needed to design the perfect circuit board and find the best parts can eat up the entire budget for your product. In this case, off-the-shelf parts are the best choice.
Most of my projects are for one or two units, so I'm always looking for inexpensive items I can use. The 25¢ MP3 playing chip that can only be bought in lots of 10,000 doesn't help me at all. If there was a $25 chip that I could get in single quantities, I might be interested.
I am an amateur radio operator and a member of the Tucson Amateur Packet Radio organization (TAPR). This organization is dedicated to the support and advancement of amateur radio digital communications by providing publications, meetings and electronic kits. I recently purchased a couple of IDE CompactFlash adapters from them (see Figure 1). This product is a circuit board that allows you to use standard CompactFlash memory cards as an IDE device in a PC.
If you have a digital camera or a portable MP3 player, you might have seen a CompactFlash card (see Figure 2). My Nikon digital camera uses these cards to store images. The cards contain between 2MB and 192MB of Flash memory. Flash memory is read/write memory that does not lose its contents when the power is disconnected.
When building an embedded system based on the Linux operating system, the first problem to solve is how to boot the operating system. It might be possible to purchase an ISA or PCI card that has ROM on it and place your code in these ROMs. I haven't tried this because I haven't found affordable boards to do this.
You could use a floppy drive or hard drive in your embedded device, but I've found that anytime you can reduce the number of moving parts, you increase reliability. These drives also draw a lot of current and generate heat, so they could cause other problems.
Using the TAPR CompactFlash adapter would let you boot the operating system off of a CompactFlash card. These cards aren't terribly expensive, and they are very small. They have no moving parts, so they could be a good solution for embedded projects.
For this article, I show how to build a Linux system on the CompactFlash card. When you boot this system, it starts up a web server. Of course, I have bigger plans for the future, but there just isn't enough room in this article.
The CompactFlash adapter has three connectors and one jumper. It has an IDE connector, a CompactFlash card connector and a power connector. The jumper is used to make this device the master or slave IDE device. It is very easy to install in a system. I used a development system to build the software and a target system to test and run the software. I installed the CompactFlash adapter on the secondary IDE connector of my development box. It is configured as the master device on this controller, so Linux will see the CompactFlash adapter as /dev/hdc on my development box. My development box has a hard drive for the /dev/hda device that has Mandrake Linux 7.2 on it. Almost any Linux distribution should work, though. I also have an IDE CD-ROM on my development system that is the /dev/hdb device on the primary IDE controller.
I am using a 32MB CompactFlash card for my device, but if you want to duplicate my results from this article, an 8MB card will work. The CompactFlash will be used when the target system boots, so it would need to be device /dev/hda on the target. It should be connected to the primary IDE controller and configured as a master device. In this application, it is the only IDE device in the target system. You could connect other needed devices.
If your BIOS supports autodetection of drive parameters, it should detect the card. If it doesn't, you'll have to enter parameters for the cylinders, heads and sectors. Check the TAPR web site for some example parameters you can use. Make sure that you do not install or remove a CompactFlash card while the system is powered on. This could cause data corruption. At the very least, it will confuse the operating system if a device disappears or appears with no warning.
My target system will have an NE2000-compatible Ethernet card in it. Make sure you have the proper drivers for the network card you have in your target system. If you installed the driver as a module, you'll need to modify the /etc/init.d/rcS file also.
- Django Models and Migrations
- Hacking a Safe with Bash
- Secure Server Deployments in Hostile Territory, Part II
- Home Automation with Raspberry Pi
- The Controversy Behind Canonical's Intellectual Property Policy
- Huge Package Overhaul for Debian and Ubuntu
- Shashlik - a Tasty New Android Simulator
- Embed Linux in Monitoring and Control Systems
- KDE Reveals Plasma Mobile
- diff -u: What's New in Kernel Development