USB Mass Storage device STM32

The updated app is in the trunk/apps/troubleshooting/sdcard_tools directory of svn.

If you don’t have the build environment setup, please let me know and I will send you the hex file.

It uses the MIOS_Studio 2.0 console to send simple commands to sdcard_tools which allow dir, cd, mkdir, rename and format. Please be aware that the format doesn’t currently ask for ANY confirmation, it just does it!

I am working on the file copy routine at the moment, it should be completed later todaym :slight_smile:

Cheers

Phil

TK, thanks for sorting my posts. I didn’t remember this was a separate thread… :blink:

Phil, is this a separate MIOS application? I don’t have the build tool chain ready. Even though I should get it up, I’d rather spend my time learning MB SEQ V4 at the moment. I just got it working with four IIC MIDI modules. :slight_smile: It you want me to try the application, please provide a hex. Otherwise I could format the SD card in Windows.

Here is a .hex file to try, all functions should work except copy. TK: could you look at the copy code if you get a chance? It is just hanging on f_open and I can’t work out why???

Cheers

Phil

[project.hex](< base_url >/applications/core/interface/file/attachment.php?id=7357)

Copy fails because the FIL structure is created locally (accordingly it will allocate stack memory)

Stack is reduced to 1024 bytes, but each FIL allocates more than 512 bytes, therefore the function doesn’t work deterministic anymore (or just crashes)

Solution: declare the FIL structures outside the function (“static FIL fsrc, fdst:”)

Best Regards, Thorsten.

Solution: declare the FIL structures outside the function (“static FIL fsrc, fdst:”)

Thanks, I knew it would be something stupid that I had done… I even remember you mentioning that in the FatFS thread but I just didn’t notice… I also had to declare the tmp_buffer outside the fuction for the same reason :slight_smile:

Performance isn’t bad considering the amount of work it has to do :slight_smile:

[3041271.692] Mounting SD Card...

[3041271.696] SUCCESS: SD Card mounted!

[3041277.446] dir

[3041277.449] Volume in Drive 0 

[3041277.449] Directory of 0:/

[3041277.449] [......a] 03/04/10 11:11:30 AM 13094673 HP-3D.zip

[3041277.449] 3967488 KB total disk space.

[3041277.450] 3967056 KB available on the disk.

[3041288.163] copy hp-3d.zip test.zip

[3041366.618] Copying /hp-3d.zip to /test.zip

[3041366.619] Copied 13094673 bytes in 78 seconds (163 KB/s)!

I got some interesting results copying the same 12MB file with some different cards.

A standard Lexar 128MB card was the slowest at 122KB/s, then a 4GB Sandisk Ultra II SDHC was 202 KB/s, the surprising thing was a Dane-elec MMC+ 1GB card managed 365KB/s, nearly twice as fast as the SDHC :slight_smile:

Cheers

Phil

Indeed an interesting result!

Could you please add a “benchmark” command (*) ? :slight_smile:

Best Regards, Thorsten.

(*) e.g. generate a 1 MB file. Measure the time how long it takes to write and to read the file. Thereafter copy the file and measure the time again. At the end we will know the read and write performance + the handling performance on copy operations

Here is the same MMC+ card using the new “benchmark” function, the copy overhead isn’t much at all really..

[3101294.650] benchmark

[3101300.205] benchmark: Starting

[3101300.205] Write: 1048576 bytes in 1.375 seconds (762 KB/s)

[3101300.205] Read: 1048576 bytes in 1.364 seconds (768 KB/s)

[3101300.205] Copy: 1048576 bytes in 2.814 seconds (372 KB/s)

I ran the program on the FAT12 card. This is what I got.

[12277.248] format

[12277.250] Formatting SDCARD…

[12277.250] [GET_SECTOR_COUNT] Count is 1020

[12277.250] Drive Format Aborted!

That is strange, can you try running this version (I have enabled debugging)

Phil

[project.hex](< base_url >/applications/core/interface/file/attachment.php?id=7358)

That is strange, can you try running this version (I have enabled debugging)

Phil

[15701.245] ====================

[15701.245] SD Card Tools

[15701.245] ====================

[15701.247]

[15701.256] SD Card has been connected!

[15701.276] Mounting SD Card…

[15701.276] [disk_init] size = 4294967295

[15701.276] [disk_read] sector 0 (#1/1)

[15701.276] [disk_read] sector 1 (#1/1)

[15701.276] Failed to open directory / - error status: 13

[15701.276] ERROR while mounting SD Card!

[15719.729] format

[15719.731] Please type “format yes” to format sd/mmc card

[15728.233] format yes

[15728.236] Formatting SDCARD…

[15728.236] [disk_init] size = 4294967295

[15728.236] [GET_SECTOR_COUNT] Count is 1020

[15728.239] Drive Format Aborted!

I know this really isn’t helping you to get a working sd card but it gives me some really interesting debug info :slight_smile:

It looks like your card doesn’t confirm to the SD spec fully.

All of the SD/MMC cards that I have tested, all report csd->RdBlockLen of 9 whereas looking at your previous posts, yours reports 0.

The format routine needs to know how many 512byte sectors can be written at a time and this uses RdBlockLen.

Attached is a quick hack which forces rdblocklen to 9 if it is returned as 0…

Cheers

Phil

[project.hex](< base_url >/applications/core/interface/file/attachment.php?id=7359)

I know this really isn’t helping you to get a working sd card but it gives me some really interesting debug info :slight_smile:

It looks like your card doesn’t confirm to the SD spec fully.

All of the SD/MMC cards that I have tested, all report csd->RdBlockLen of 9 whereas looking at your previous posts, yours reports 0.

The format routine needs to know how many 512byte sectors can be written at a time and this uses RdBlockLen.

Attached is a quick hack which forces rdblocklen to 9 if it is returned as 0…

Cheers

Phil

This one did the trick!

But now OS X cant read it… I will format it in Windows now…

That’s great.

Since I started looking at SDHC/MMC support some months ago, I have discovered that all cards were not created equal :slight_smile:

I will see if I can find a better solution (as that was a very quick hack).

Cheers

Phil

But now OS X cant read it… I will format it in Windows now…

before you format it in windows, could you just run the “filesys” command please?

Cheers

Phil

before you format it in windows, could you just run the “filesys” command please?

Cheers

Phil

I am really sorry… Have already formatted in Windows. It now works perfect in all systems.

If it is of any interest, here is the sdcard response for the card after format in windows:

[271.359] SD Card Informations

[271.359] ====================

[271.359] --------------------

[271.359] CID:

[271.361] - ManufacturerID:

[271.361] - OEM AppliID:

[271.361] - ProdName: D016W

[271.361] - ProdRev: 32

[271.363] - ProdSN: 0x097a1a00

[271.363] - Reserved1: 182

[271.363] - ManufactDate: 415

[271.365] - msd_CRC: 0x18

[271.365] - Reserved2: 1

[271.387] --------------------

[271.387] --------------------

[271.387] - CSDStruct: 0

[271.387] - SysSpecVersion: 9

[271.387] - Reserved1: 2

[271.387] - TAAC: 0

[271.387] - NSAC: 50

[271.387] - MaxBusClkFrec: 31

[271.387] - CardComdClasses: 1432

[271.387] - RdBlockLen: 0

[271.387] - PartBlockRead: 1

[271.387] - WrBlockMisalign: 1

[271.387] - RdBlockMisalign: 1

[271.387] - DSRImpl: 0

[271.387] - Reserved2: 0

[271.387] - DeviceSize: 1019

[271.387] - MaxRdCurrentVDDMin: 7

[271.387] - MaxRdCurrentVDDMax: 1

[271.387] - MaxWrCurrentVDDMin: 6

[271.387] - MaxWrCurrentVDDMax: 3

[271.387] - DeviceSizeMul: 7

[271.387] - EraseGrSize: 31

[271.387] - EraseGrMul: 28

[271.387] - WrProtectGrSize: 18

[271.387] - WrProtectGrEnable: 0

[271.387] - ManDeflECC: 2

[271.387] - WrSpeedFact: 0

[271.387] - MaxWrBlockLen: 0

[271.387] - WriteBlockPaPartial: 0

[271.387] - Reserved3: 0

[271.387] - ContentProtectAppli: 0

[271.387] - FileFormatGrouop: 1

[271.387] - CopyFlag: 1

[271.387] - PermWrProtect: 1

[271.387] - TempWrProtect: 0

[271.387] - FileFormat: 3

[271.387] - ECC: 3

[271.387] - msd_CRC: 0x6d

[271.387] - Reserved4: 1

[271.389] --------------------

[271.389] Content of root directory:

[271.389] MBSEQ_HW.V4

[271.391]

[271.391] Checking SD Card at application layer

[271.391] =====================================

[271.393] Retrieving SD Card informations - please wait!

[271.393] SD Card: ‘TODO’: 4294 of 0 MB free

[271.395] File MBSEQ_B1.V4: doesn’t exist

[271.395] File MBSEQ_B2.V4: doesn’t exist

[271.397] File MBSEQ_B3.V4: doesn’t exist

[271.397] File MBSEQ_B4.V4: doesn’t exist

[271.399] File MBSEQ_M.V4: doesn’t exist

[271.399] File MBSEQ_S.V4: doesn’t exist

[271.399] File MBSEQ_G.V4: doesn’t exist

[271.401] File MBSEQ_C.V4: doesn’t exist

[271.401] File MBSEQ_HW.V4: valid

[271.403] done.

hi,

still not able to format my 4gb,

the sd formatter chnaged it from 128kb to 96kb!

phil, your tool reports the following:

[520691.203] format yes

[520691.203] Formatting SDCARD…

[520691.203] Drive has no work area

[520827.359] filesys

[520827.359] Failed to open directory - error status: 12

i’m gonna borrow a card reader soon but till then i wonder if this card is trashed?

s.

i’m gonna borrow a card reader soon but till then i wonder if this card is trashed?

It is possible that the card is faulty but it is also possible that the size detection algorythm that I am using is wrong :slight_smile:

I have made various changes to the detection code as it uses the cards CSD (Card Specific Data) to find the size etc of the card. Unfortunately, when I wrote the SDHC (V2.0) detection code I didn’t realise that the CSD format had also changed. This is why csd->DeviceSize was reported as 0 in your earlier post.

The CSD should now be correctly reported so could you try the CSD command on mios32_tools now please and post the results?

The problem is that there are at least 3 distinct types of card, SD SDHC and MMC, each one requires special handling and although I do have one of each (which are working fine), different manufacturers seem to interpret the spec differently. Most of mine are SanDisk cards and because they wrote the SD/SDHC spec, hopefully they are the most compliant :slight_smile:

Cheers

Phil

hi phil, thanks for the ongoing help with this one!

heres what i get from CSD with tools from svn:

[1001626.341] ====================

[1001626.341] SD Card Tools

[1001626.341] ====================

[1001626.341]

[1001626.431] SD Card has been connected!

[1001626.435] Mounting SD Card…

[1001626.437] SUCCESS: SD Card mounted!

[1001632.796] csd

[1001632.791] --------------------

[1001632.791] - CSDStruct: 1

[1001632.791] - SysSpecVersion: 0

[1001632.791] - Reserved1: 0

[1001632.791] - TAAC: 14

[1001632.791] - NSAC: 0

[1001632.791] - MaxBusClkFrec: 50

[1001632.791] - CardComdClasses: 1461

[1001632.791] - RdBlockLen: 9

[1001632.791] - PartBlockRead: 0

[1001632.791] - WrBlockMisalign: 0

[1001632.791] - RdBlockMisalign: 0

[1001632.791] - DSRImpl: 0

[1001632.791] - Reserved2: 0

[1001632.791] - DeviceSize: 0

[1001632.791] - MaxRdCurrentVDDMin: 3

[1001632.792] - MaxRdCurrentVDDMax: 5

[1001632.792] - MaxWrCurrentVDDMin: 4

[1001632.792] - MaxWrCurrentVDDMax: 1

[1001632.792] - DeviceSizeMul: 6

[1001632.792] - EraseGrSize: 31

[1001632.792] - EraseGrMul: 28

[1001632.792] - WrProtectGrSize: 0

[1001632.792] - WrProtectGrEnable: 0

[1001632.794] - ManDeflECC: 0

[1001632.794] - WrSpeedFact: 2

[1001632.794] - MaxWrBlockLen: 9

[1001632.794] - WriteBlockPaPartial: 0

[1001632.794] - Reserved3: 0

[1001632.794] - ContentProtectAppli: 0

[1001632.794] - FileFormatGrouop: 0

[1001632.794] - CopyFlag: 0

[1001632.794] - PermWrProtect: 0

[1001632.794] - TempWrProtect: 0

[1001632.794] - FileFormat: 0

[1001632.794] - ECC: 0

[1001632.794] - msd_CRC: 0x28

[1001632.794] - Reserved4: 1

[1001632.794] --------------------

[1001672.203] format yes

[1001672.199] Formatting SDCARD…

[1001672.199] [GET_SECTOR_COUNT] Count is 1024

[1001672.199] Drive Format Aborted!

:shocked:

i’ve noticed i still have DeviceSize: 0 ?!

oh, mine is toshiba brand if that’s any help? :blink:

s.

i’ve noticed i still have DeviceSize: 0 ?!

It looks like I never committed my latest changes to mios32_sdcard.c (oops!)

Can you download the latest svn and try again please?

Cheers

Phil