#2 USB mass-storage with Atmel AT91

This is a Mass-Storage Device (MSD) support to eCos, slave side only ( eCos does not currently support USB host side ). The mass-storage driver is tested with an AT91SAM7X128 evaluation kit using an external power supply. The AT91SAM7X128 evaluation kit is usually self powered from the USB port, some hardware modifications are therefore required to use an external power source. To do so, the 5 Volts pin of the USB connector is disconnected from the PCB. Instead, an external 5 Volts power supply is inserted.

I. Steps to generate the ROM application binary file

$ ecosconfig new at91sam7xek default
$ ecosconfig import packages/hal/arm/at91/at91sam7xek/current/misc/default_usbs_msd.ecm
$ ecosconfig remove CYGPKG_LIBC_SETJMP
$ ecosconfig remove CYGPKG_LIBC_SIGNALS
$ ecosconfig remove CYGPKG_LIBC_STARTUP
$ ecosconfig remove CYGPKG_LIBC_TIME
$ ecosconfig remove CYGPKG_LIBM
$ ecosconfig remove CYGPKG_LIBC
$ ecosconfig remove CYGPKG_DEVS_ETH_PHY
$ ecosconfig remove CYGPKG_DEVS_ETH_ARM_AT91
$ ecosconfig tree
$ make

Next step is to compile the supplied "RAM disk" test. This test application creates a tiny ram disk of around 32 sectors of 512 bytes formatted using FAT12. The 16KB RAM disk space is statically defined. The disk devtab entry is "/dev/ramdisk0". The first partition is accessible from "/dev/ramdisk0/1". The test application is located here:
-/io/usb/msd/slave/current/tests/usbs_test_ramdisk.c

II. Mass-Storage Device template configuration

The template ( default_usbs_msd.ecm ) contains the required configuration to run the RAM disk test on the AT91SAM7X128 board. The following packages are added to include disk and filesystem support:
CYGPKG_IO_DISK
CYGPKG_IO_USB_SLAVE_MSD
CYGPKG_BLOCK_LIB
CYGPKG_LINUX_COMPAT
CYGPKG_FS_FAT
CYGPKG_IO_FILEIO

The following options are set: EP4 is used has TX endpoint. EP4 size is set to 256 bytes. The RX endpoint remains the default endpoint ( EP2 ). The null lenght termination packet is disable and stalling is enable.

Parameters Value
CYGHWR_HAL_ARM_AT91SAM7 at91sam7x128
CYGSEM_DEVS_USB_AT91_ZERO_LENGHT_PACKET_TERMINATION 0
CYGDAT_IO_USB_SLAVE_MSD0_TX_EP "usbs_at91_ep4"
CYGNUM_IO_USB_SLAVE_MSD0_TX_EP_NUM 4
CYGNUM_IO_USB_SLAVE_MSD0_TX_EP_MAX_PACKET_SIZE 256
CYGSEM_IO_USB_SLAVE_MSD_STALL_ENABLE 1
CYGDAT_IO_USB_SLAVE_MSD0_LUN0_NAME "\"/dev/ramdisk0/1\""
CYGBLD_IO_USB_SLAVE_MSD_DEBUG 1

Some packages are removed from the default template to reduce the application size.

III. Testing the MSD driver

Burn the resulting binary file to the target FLASH at @0x00100000. Restart the target and plug the USB cable to the host machine. The host machine should detect a USB MSD drive under the eCos-3.0 name as shown in the following screenshot:

The USB MSD package is further documented in the updated eCos documentation here . Here is the output of lsusb under a linux based host machine:

List of file changed / added (diff from ecos public repository) :

The USB MSD package is now part of eCos public repository at:
$ cvs -z3 -d :pserver:anoncvs@ecos.sourceware.org:/cvs/ecos co -P ecos

  • /hal/arm/at91/at91sam7xek/current/misc/default_usbs_msd.ecm