Atmel ARM Codes

Example AT91SAM7S-128 (64-256) USB Mass Storage Device (MSD) with SD or SDHC card

This example code implements an USB mass storage device on Atmel AT91SAM7-128 (or 64-256). Storage medium is an SD card connected via SPI interface.
The basic hardware example to run the code is show in the schematic which is included in the archive file. Of course some additional work is needed to implement the code in own projects,
especially code related to the power button needs to be changed for your requirements.
The code is well commented and there exist a Doxygen generated documentation.

All USB functions are based on Atmels USB MSD framework. But since the framework is increadible bloated and hard to understand, I reworked it completely and now it is
reduced to a minimum requirment to save resources and make the code more readable.
Transfer rates are not very fast, bottleneck here is the bulk endpoint size of only
64 byte in AT91SAM7 – 1.3MBits/s.

Code uses 23108 bytes program memory and 4312 bytes RAM.
Debugging output for all parts of the code can be configured in file trace.h
Debugging unit is used with parameters 115200 Baud 8N1.

Additional the code uses some peripheral features which may work as it’s own example as well, like:

  • setup and use of interrupts with AIC
  • setup and use of hardware timer for delays
  • setup and use of UDP peripheral
  • setup and use of SPI
  • configurable printf function, from tiny up to floating point output
  • setup of abort handlers
  • FAT32 library
  • SD card library with support for SDHC cards
  • setup and use of debug unit, DBGU
  • configurable trace library

This example code was successfully tested with Mandriva Linux, Windows XP SP2 and Windows Vista.

Example AT91SAM7S-128 (64-256) USB Mass Storage Device (MSD) with SD or SDHC card
1.1 MB

10 thoughts on “Atmel ARM Codes

  1. Thank you for sharing such a well written project. I had not used Eclipse and the GNU tool-chain, but this was a good excuse to try it. I adjusted your project for our hardware, which uses the Atmel SAM7S64 microcontroller and and SD card, and it works perfectly! PS. I thought your Microkopter project was cool – but so sorry they are so money hungry.

  2. Hi, I am trying to compile your code in Keil uVision. I am working on an university project for my bachelor’s degree. I am unfamiliar with GNU tools or Eclipse, and my mentor wants me to finish the project in Keil uVision. When trying to compile your code I get enormous number of errors, probably because of difference between GNU tools and Keil uVision. Do you perhaps know of any tool that could help me in conversion? Any advice will be appreciated…

    With regards, Marko.

    • Don’t know any kind of tool to perform such conversion. Usually you need to port code by hand from one compiler to another. Shouldn’t be a big deal.

  3. Thank you for your previous reply, but now I have another question 😀

    I installed a GNU tool-chain and Eclipse. I am running win7 x64 OS and trying to compile your code, using Eclipse. While building the project I get the following error:

    cc1: error: unrecognized command line option “-fgnu89-inline”
    make: *** [abort.o] Error 1

    I tried to goggle that error, but didn’t get very far. Would you be kind and suggest possible reasons for this error, and perhaps an idea how to fix it?

    With regards, Marko

  4. Michael,

    Thanks for providing this package, it’s exactly what I need for my project; However, when I try to compile it using arm-none-eabi toolchain it fails with _sbrk error.

    arm-none-eabi/lib/thumb2\libc.a(lib_a-sbrkr.o): In function `_sbrk_r’:
    sbrkr.c:(.text+0xc): undefined reference to `_sbrk’

    After googling for the error, I realized I need arm-uclinux-eabi; but it’s also failing with

    CodeSourcery/Sourcery_G++_Lite/arm-uclinuxeabi/bin/ld.real: main.elf.gdb: hidden symbol `__fini_array_end’ isn’t defined

    my question is which toolchain are you using? I’m on Linux Ubuntu system.



  5. Hi Micheal,

    Thanks for the source code. I am facing few problems in order to understand the code.
    1- How exactly are you using the power button. If the device is a USB powered device, then its getting the power from the host on the VBUS. How exactly you are using the VBUS line on the Schematics. The PIN_POWER_ON is connected to AT91C_PIO_PA29. I mean the schematic doesn’t explain the pio 29.
    2- How can i use the safely removal of the device. The USB 2.0 specification says that every 3ms the device goes to the suspended state (via USB_IRQ). In your code if the device goes to the suspended mode will ever come to the configured state?

    Your advice and answer will be highly appreciated.


    • A bit confusing indeed but it’s just an example. The schematic is taken from the yamppPod project where also the MSD code is used. The full schematic can be found in the yamppPod reference guide, see

      Can’t answer your second question instantly. I’m out of the code and USB programming for quite some time, 2-3years? Need to read into this when I have some time…

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments will be moderated! Spam deleted immediately!
Before you submit form:
Human test by Not Captcha