USB Flash and FAT32 on the K70 SOM Using uClinux Print


This application note explains how to use USB Flash disks and FAT32 on the K70 SOM running uClinux.

Hardware Configuration

Set up your system with the K70 SOM as follows:

  • Plug in the K70 SOM into the TWR-SOM-BSB baseboard. If you have obtained the K70 SOM Starter Kit from Emcraft Systems, the K70 SOM comes plugged into the TWR-SOM-BSB so in all likelihood this step is not needed.
  • Connect a mini-USB cable between the P1 connector of the TWR-SOM-BSB and a USB port of your PC. This connection serves two purposes. First, it provides a serial console interface to the K70 and, second, it supplies the USB power for the K70 SOM. (Please refer to the additional considerations on the power supply below).
  • Insert a USB Flash disk into the P13 connector of TWR-SOM-BSB. It is a mini-USB port, so you may need a miniUSB-to-USB adapter to insert you USB Flash disk.

Please note that the USB power supplied to the K70 SOM over the mini-USB cable is limited to 500mA. As long as you stick to the use scenarios that involve only USB Flash as described below, this should be enough. However, if you access the USB Flash simultaneously with performing some other I/O operations, the 500mA power supplied by the USB link may be not sufficient. Should this happen to you, you could set up the K70 SOM and the Freescale Tower System with an external 5V power supply as described below:

  • Turn the SW1 switch on the Primary Elevator module to the middle position to disconnect all external power sources from the Tower System.
  • Connect a 5V power supply to the J10 connector of the TWR Primary Elevator board (observe the polarity). The maximum power consumption of the whole system in this configuration is around 800mA.
  • To power the system from the external 5V source, turn the SW1 switch on the Primary Elevator module to the position TB.

Software Configuration

The following kernel options are necessary to get the USB High Speed interface configured for the host-mode operation:


Additional kernel configuration options are required to enable support for the USB Flash and the FAT32 file system. Also, appropriate device node files must be created in the target root filesystem.

The usbflash.tgz tarball contains a uClinux sample configuration (a uClinux project) that configures the kernel, busybox and root filesystems for operations with the USB Flash disk over the USB High-Speed interface of the K70. Contact Emcraft to obtain the bootable image and project source files.

This project can be installed and built within the uClinux K70 software development environment using the following step-wise procedure:

  1. From the top of the uClinux development tree, go to the projects directory:

    cd projects/

  2. Unpack the project tarball:
  3. tar xvfz usbflash.tgz

  4. Go to the project's directory and build the uClinux bootable image:
  5. cd projects/usbflash/

This will produce a uClinux bootable image for the newly installed project (usbflash.uImage). That image can booted on the K70 SOM from either a TFTP host or the on-module NAND Flash.

Storing Files on USB Flash Disk in FAT32 Filesystem

The most typical use of a USB Flash disk in embedded applications is storing data in a FAT32 file system. This allows easy transfer of data collected on the embedded system to a PC host.

Linux supports many file systems, including FAT32 with support for long file names (VFAT). As soon as a USB Flash disk formatted as FAT32 has been connected to the K70, it can be immediately mounted and accessed using standard Linux tools and interfaces.

For example:

~ # mount /dev/sda1 /mnt/
~ # mkdir /mnt/folder
~ # echo "Hello, world!" > /mnt/folder/file.txt
~ # cat /mnt/folder/file.txt
Hello, world!
~ # umount /mnt/
~ #

The newly created file (file.txt in the folder directory) can now be opened on this USB Flash disk on a PC in almost any operating system, including Windows, Mac OS X and Linux.

USB Flash Disk Partitioning

On some USB storage devices, a FAT32 file system may have been created in a partition, not on the whole disk. Linux supports the MBR partitioning, allowing access to specific partitions on a disk. The disk partitioning support is seamless - all you need to do is change the pathname to the storage volume, sda being the whole disk, sda1 - the first partition, etc.

For example, this command will mount a first partition of the USB Flash disk, rather than the entire disk.

~ # mount /dev/sda1 /mnt/
~ #

Note further that the MBR partition table can be created or modified directly on the K70 target. This is done using the fdisk utility implemented as part of the busybox multi-entry tool.

The sample session below shows how fdisk can be used to create a primary partition on the USB Flash disk:

~ # fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 1999 MB, 1999634432 bytes
62 heads, 62 sectors/track, 1016 cylinders
Units = cylinders of 3844 * 512 = 1968128 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-1016, default 1): Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1016, default 1016): Using
default value 1016

Command (m for help): p

Disk /dev/sda: 1999 MB, 1999634432 bytes
62 heads, 62 sectors/track, 1016 cylinders
Units = cylinders of 3844 * 512 = 1968128 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 1016 1952721 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table
sd 0:0:0:0: [sda] Assuming drive cache: write through
~ #

Formatting FAT32 File System on the Target

Although typically a USB Flash disk would be formatted as FAT32 on a PC host, it is possible to do the formatting on the K70 target as well.

The following command shows how format the entire USB Flash disk:

~ # mkfs.vfat /dev/sda -v -n "MYDISK"
Device '/dev/sda':
heads:62, sectors/track:62, bytes/sector:512
media descriptor:f8
total sectors:3905536, clusters:487239, sectors/cluster:8
FATs:2, sectors/FAT:3807
volumeID:00000145, label:'MYDISK'
~ #

The newly formatted FAT32 file system is now ready for mounting.