Quick Reference for SD Cards and Binary Data

SD Card: Non-volatile, No writes, No random read access, Gigabytes of storage
SD-RAM: Volatile, Random reads & writes permitted, 8MB storage
General idea: Copy needed data from SD Card to SD-RAM when initializing program.

For details regarding the SD Card controller, see the Lab 7 page for the SD Card controller.

Creating binary data - Audio

Convert .mp3 to .wav

If you have an mp3 file you want to convert to a wav file, you can use the following command in a terminal.

ffmpeg -i in.mp3 out.wav

Convert .wav to .raw

You can convert a wav file to a RAW binary file using the Sound eXchange program, sox. This program can do much more, if you are interested to learn more, check out its manual by typing man sox in a terminal.

To convert the wav file in.wav to a RAW binary file, out.raw, usable by the E100, you can do the following in a terminal:

sox in.wav -w -s -c 1 -r 8000 out.raw

Creating binary data - Images

For detailed information regarding how to create bitmapped images for the E100, see this page.

The MATLAB function color100 can be used to convert an image to both .e and .bin files, and the .bin file can be written to a SD card. Right-click and save this file somewhere in your AFS home directory.

To use this function, start MATLAB by typing matlab into a terminal. When MATLAB starts, you should see a Command Window and a Current Folder. Browse to the folder where you saved the color100.m in the Command Window. Then you can type

color100 filename.jpg

in the Command Window and hit enter. After this completes, you should see that a filename.jpg.e and a filename.jpg.bin were created.

Creating header information for binary data

You may need to add information that helps you identify which file you are reading. One simple way to do this is to add a unique numerical identifier for each file, and some information that tells you how many 16-bit samples are stored in this file. addheader is a simple C program that you may use to do this. To compile addheader in a terminal, type gcc addheader.c -o addheader. To run addheader in a terminal, type ./addheader input.bin NUM, where input.bin is the binary file you wish to create a header for, and NUM is a unique numerical identifier from 1-32767. (Remember to only use one number per file.)

E.g. After running ./addheader test.bin 2, the file 2_test_header.bin will be created.

You can examine the output header binary file using khexedit, and you will see that it has stored 3 16-bit words of data. As seen in the table below, the first is the identifer you provided, and the next two can be used to calculate the number of 16-bit samples are stored in the file.

Address Contents
0x00 ID
0x02 Samples_hi
0x04 Samples_lo

Since the E100 uses signed 16-bit numbers, the maximum positive number you can represent is 32767. Often, you may have more than 32767 samples in your binary files, so you can represent numbers greater than this by using two values, Samples_lo and Samples_hi. You can calculate the total number of samples by doing the following:

total_samples = (Samples_hi * 32767) + Samples_lo

Combining binary files

The Unix utility cat can concatenate multiple files into a single file. E.g., to concatenate three files 1_file1_header.bin, 1_file1.bin, 2_file2_header.bin, and 2_file2.bin into a single, combined file all.bin, run the following command:

cat 1_file1_header.bin 1_file1.bin 2_file2_header.bin 2_file2.bin > all.bin

Writing binary data to SD card

To initialize the contents of an SD card, create a file with the desired contents, then carry out the following steps at a computer in 2331 or 2431 EECS:

  1. Login to the computer.
  2. Remove all removable media (e.g., USB drives) from the computer.
  3. If you're in 2331 EECS, use the built-in multi-card writer on the front panel of the computer. If you're in 2431 EECS, plug an SD card writer (SanDisk ImageMate or SanDisk MobileMate) into the computer.
  4. Insert the SD card into the SD writer. If the operating system mounts any partitions from the SD card, unmount them before continuing.
  5. Wait at least 15 seconds. During this time, the operating system detects the SD card writer and changes permissions on the device file.
  6. Run the following command:
    dd if=FILE of=DEVICE
    
    Replace FILE with the name of the file that has the contents you want to write to the SD card (E.g. all.bin). Replace DEVICE with the device name from the following table (depending on which room you're in and which SD card writer you're using):

    2331 EECS 2431 EECS
    Built-in multi-card writer /dev/sde
    SanDisk ImageMate /dev/sdh /dev/sdd
    SanDisk MobileMate /dev/sdf /dev/sdb
  7. Wait for the dd command to finish and the SD card writer light to stop flashing.

ase100 simulates the SD card controller accurately enough for you to test your device driver and to run assembly-language programs. ase100 simulates the SD card by reading data from a file, which you select when your program runs.

More info is available on the handout on manipulating binary data files for how to create binary files using MATLAB or C/C++.