EmbDev.net

Forum: ARM programming with GCC/GNU tools [ANN] AT91SAM7S-128 USB MSD Example


von Michael W. (mictronics)


Rate this post
useful
not useful
How to implement a USB Mass Storage Device (MSD class) with SD card on
Atmels AT91SAM7S-128?
An example source code and basic schematic can be found at
http://www.mictronics.de

von Martin T. (mthomas) (Moderator)


Rate this post
useful
not useful
Michael Wolf wrote:
> How to implement a USB Mass Storage Device (MSD class) with SD card on
> Atmels AT91SAM7S-128?
> An example source code and basic schematic can be found at
> http://www.mictronics.de

Interesting project. Thanks for the announcement. Did you think about
using the BSD-license or the ecos license instead of GPL?

von Adam S. (adamusx)


Rate this post
useful
not useful
Michael Wolf wrote:
> How to implement a USB Mass Storage Device (MSD class) with SD card on
> Atmels AT91SAM7S-128?
> An example source code and basic schematic can be found at
> http://www.mictronics.de
Hello
I'am trying to use this code (i have ported it to AT91SAM7S256) with
256MB SanDisk card. I compile this in WInARM witchout  error and
warning. When i connect the USB to PC  Windows detect new disk. I try to
format this disk in FAT, but at the end of formating i get message "
..windows can't finish fotmat..." or something like that. and TRACE send
message "MSD_ProcessCommand: Command failed "
I have no idea what is wrong.

This is info from TRACE:

SD:

Init SD card
go idle resp: 1
Not a 2.0 card
Sending CMD55
Sending ACMD41
response = 01
Sending CMD55
Sending ACMD41
response = 00
SDCARD: CID read
Manufacturer ID    : 11
OEM/Application ID : 4a43
Product Name       : SDMMC

Product Revision   : 00
Serial Number      : 0005a100 (368896)
Manuf. Date Code   : 3b
SDCARD: CSD read
C_SIZE = 077e
C_SIZE_MULT = 06
mult = 256
blockno = 491264
card size = 251527168 / (239 MByte)

FAT:

Init SD card OK
FAT init
read sector 00000000
Filesystem is a Unkown
read sector 00000027
data_sectors = 0
num_clusters = 0
Bytes per sector= 512
FirstSector     = 39
Sectors/Cluster = 1
FirstFATSector  = 39
FirstDataSector = 39
FirstDirSector  = 39
root_dir_cluster  = 0
UDP enabled
           SDCARD: CID read
Manufacturer ID    : 11
OEM/Application ID : 4a43
Product Name       : SDMMC

Product Revision   : 00
Serial Number      : 0005a100 (368896)
Manuf. Date Code   : 3b
SDCARD: CSD read
C_SIZE = 077e
C_SIZE_MULT = 06
mult = 256
blockno = 491264
card size = 251527168 / (239 MByte)

BOT:
...
Cbk Cplt SendCSW Cbk okCbk -
Cbk Cplt SendCSW Cbk okCbk -
Cbk Cbk Cplt SendCSW Cbk okCbk -
MSD_ProcessCommand: Command failed
Cbk Cplt SendCSW Cbk okCbk -
Cbk Cbk Cplt SendCSW Cbk okCbk -
Cbk Cbk Cplt SendCSW Cbk okCbk -
Cbk Cplt SendCSW Cbk okCbk -
Cbk Cplt SendCSW Cbk okCbk -
Cbk Cbk Cplt SendCSW Cbk okCbk -
MSD_ProcessCommand: Command failed
...

von Michael W. (mictronics)


Rate this post
useful
not useful
The problem seems to be processing of a SCSI block command in function
sbc_process_command.

Reduce your trace output to TRACE_SBC and TRACE_BOT.

Before "MSD_ProcessCommand: Command failed" there must be a command
executed from sbc_process_command.
I need to know which one to track down the problem.

So far I never had such problems since the code is running.

What OS do you use?

von Adam S. (adamusx)


Rate this post
useful
not useful
I'am using Windows XP. I can format the SDcard in my SD card reader (FAT
format) in notebook,but  when i put formated card into my ARMboard and
connect it to PC windows cant't recognize the file system on the SD
card.

There is a TRACE_SBC and TRACE_BOT log:

after connect USB to PC:

MSD init
MSDReset   BotReq   BotReq   BotReq   BotReq   BotReq   BotReq
 BotReq   BotReq   BotReq   BotReq   BotReq   BotReq   BotReq
BotReq   BotReq   BotReq   BotReq   BotReq   BotReq   BotReq   B
otReq   gMaxLun   Cbk -
Inquiry   SendingCbk    Inquiry   Sent   Cplt Cbk SendCSW okCbk
-
BOT_ProcessCommand: Unknown command 0x23
StaIN Cplt BotReq   ClrFeat   Hlt SendCSW Cbk okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
BOT_ProcessCommand: Unknown command 0x23
StaIN Cplt BotReq   ClrFeat   Hlt SendCSW Cbk okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
BOT_ProcessCommand: Unknown command 0x23
StaIN Cplt BotReq   ClrFeat   Hlt SendCSW Cbk okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
SBC_GetCommandInformation: Page code not supported (0x1C)
ModeSense(6) Cbk ModeSense(6) Wait Cplt Cbk SendCSW okCbk -
BOT_PreProcessCommand: Case 5
ModeSense(6) Cbk ModeSense(6) Wait Cplt StallIn BotReq   ClrFeat
   Hlt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(1Cbk 0) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
...
...

(10) Next Cplt Cbk SendCSW okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
PrevAllowRem Cplt Cbk SendCSW okCbk -
BOT_PreProcessCommand: Case 5
ModeSense(6) Cbk ModeSense(6) Wait Cplt StallIn BotReq   ClrFeat
   Hlt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(1Cbk 0) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(1Cbk 0) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Read(10) Cbk Read(10) Ok Read(10) Sending Read(10Cbk )
 Sent Read(10) Next Read(10) Cbk Read(10) Ok Read(10) Sending Re
ad(Cbk 10) Sent Read(10) Next Read(10) Cbk Read(10) Ok Read(10)
Sending Read(Cbk 10) Sent Read(10) Next Read(10) Cbk Read(10) Ok
 Read(10) Sending Read(Cbk 10) Sent Read(10) Next Read(10) Cbk R
ead(10) Ok Read(10) Sending Read(Cbk 10) Sent Read(10) Next Read
(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read(10)
 Next Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sen
t Read(10) Next Cplt Cbk SendCSW okCbk -
PrevAllowRem Cplt Cbk SendCSW okCbk -
...
...

when i trying to format disk:

Cbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Verify(10) Cplt Cbk SendCSW okCbk -
Verify(10) Cplt Cbk SendCSW okCbk -
Verify(10) Cplt Cbk SendCSW okCbk -
Verify(10) Cplt Cbk SendCSW okCbk -
Verify(10) Cplt Cbk SendCSW okCbk -
Verify(10) Cplt Cbk SendCSW okCbk -
Verify(10) Cplt Cbk SendCSW okCbk -
...
...
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Write(10) Receive Cbk Write(10) Wait Write(10) Cbk Write(10) Wai
t Write(10) Cplt Cbk SendCSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
Write(10) Receive Cbk Write(10) Wait Write(10) Cbk Write(10) Wai
t Write(10) Cplt Cbk SendCSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
Write(10) Receive Cbk Write(10) Wait Write(10) Cbk Write(10) Wai
t Write(10) Write(10) Receive Cbk Write(10) Wait Write(10) Cbk W
rite(10) Wait Write(10) Write(10) Receive Cbk Write(10) Wait Wri
te(10) Cbk Write(10) Wait Write(10) Write(10) Receive Cbk Write(
10) Wait Write(10) Cbk Write(10) Wait Write(10) Write(10) Receiv
e Cbk Write(10) Wait Write(10) Cbk Write(10) Wait Write(10) Writ
e(10) Receive Cbk Write(10) Wait Write(10) Cbk Write(10) Wait Wr
...
...
Wait Write(10)
Cplt Cbk SendCSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
Read(10) Cbk Read(10) Ok
...
...
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(1Cbk 0) Sent Read
(10) Next Cplt Cbk SendCSW okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
PrevAllowRem Cplt Cbk SendCSW okCbk -
BOT_PreProcessCommand: Case 5
ModeSense(6) Cbk ModeSense(6) Wait Cplt StallIn BotReq   ClrFeat
   Hlt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
TstUnitRdy ? MSD_ProcessCommand: Command failed
Cplt Cbk SendCSW okCbk -
ReqSense ReqSensCbk e Cplt SendCSW Cbk okCbk -
RdCapacity(10) SCbk ending   RdCapacity(10) Sent   Cplt Cbk Send
CSW okCbk -
Read(10) Cbk Read(10) Ok Read(10) Sending Read(Cbk 10) Sent Read

...
....

Maby it is a problem with startup file for SAM7S256. I'am using your
startup file with changed stack addres for AT91SAM7S256:

  .equ    Top_Stack,      0x00210000
        .equ    UND_Stack_Size, 0x00000004
        .equ    SVC_Stack_Size, 0x00000100
        .equ    ABT_Stack_Size, 0x00000020     // was 4
        .equ    FIQ_Stack_Size, 0x00000004
        .equ    IRQ_Stack_Size, 0x00000100
        .equ    USR_Stack_Size, 0x00000400

and changed *.ld file
  CODE (rx) : ORIGIN = 0x00100000,  LENGTH = 0x00040000
  DATA (rwx) : ORIGIN = 0x00200000, LENGTH = 0x00010000

Maby you can compile the code for AT91SAM7S256, send me and i will try
it ?
I will be gratefully.

Regards
/Adam S.

von Adam S. (adamusx)


Rate this post
useful
not useful
I have just resolved my problem  It's work wery good.

The problem was with detect the SDcard.

von Michael W. (mictronics)


Rate this post
useful
not useful
Ok, nice work then.

von Michael W. (mictronics)


Rate this post
useful
not useful
The example code includes now support for SDHC cards.
Tested with Sandisk 4GB.

von Kalanyos V. (kalven)


Rate this post
useful
not useful
Yesterday I played with this USB MSD Example.
I had to change some settings ( sam7s-256, pure arm mode, and some hw
pins )
I build it with arm-elf-gcc v.4.2.2 on linux.

The device works well on WinXP-SP3, but not works well on kubuntu gutsy
linux. :(

The other problem is the transfer speed. I change the sd sector
read/write
to dma version, but the speed is 106 kB/s write, 235 kB/ read.
(without DMA this was ~ 65/85 kB/s)


I am not not an USB expert, but i use the sam7s CDC example, and a bulk
transfer speed is about 900 kB/s.

What is the difference

How it would be possible to accelerate the MSD device?
How much should the normal speed be?

thanks
kalven

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.