MSC command to Format USB flash memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MSC command to Format USB flash memory

750 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alessandro on Mon Sep 10 08:33:57 MST 2012
Dear developpers,
I am a new member in this usefull forum and I am programming LPC1343 microcontroller for the first time.
I would know if there is a method to intercept a format command which arrived from the O.S. (Windows 7) when I try to format the device (LPC1343 USB with MSC).
At the moment I know this because the O.S. write at the offset zero (BootAddress of FAT12) and so I clean my flash memory and restore the DiskImage, [U][B]but the  the format operation of the O.S. fails.[/B][/U]
Somebody of you know this problem and could help me?
Thanks a lot.
Regards
Alessandro
0 Kudos
6 Replies

632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alessandro on Mon Sep 17 23:26:06 MST 2012
Of course, I know this problem and I switch from RAM to Flash continuously. But this flash is the one that I have. The project is not to perform a USB pen but update a microcontroller renesas on our board via an other connector. The USB is only to load and carry firmwares files. I have tried to work only to the RAM for testing format OS command but  the result was the same. The problem is the size of my cluster? Or the presence of only one Fat table? At the moment I am stopped because an other project is imminent....
Excuse my English...
Thanks a lot Tsuneo.

Alessandro
0 Kudos

632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Mon Sep 17 06:36:26 MST 2012

Quote:
Oh Yes, my flash is 2MB. It has 64KB sector size and so I prefer to have 64KB per cluster: 512*128 sector.


Are you making the mass storage on a 2M bytes FLASH of 64K bytes page?
The FLASH page size isn't good for a writable disk. Select smaller page size, 512, 1024, 2048 or 4096.

The FAT management regions, BPB, FAT and root directory, are assigned in the unit of sector. The sector size is limited to 512, 1024, 2048 or 4096. On a writable disk, FAT and root directory regions are often rewritten. If the FLASH page size is greater than these sector size, you have to repeat this process to rewrite the target region, which is a part of the page.

1) copy the target FLASH page into RAM
2) modify target region on the copied page
3) erase the FLASH page
4) write back the copy into the FLASH page

Tsuneo
0 Kudos

632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alessandro on Sun Sep 16 23:21:10 MST 2012
Oh Yes, my flash is 2MB. It has 64KB sector size and so I prefer to have 64KB per cluster: 512*128 sector. One of these for boot, fat (only one and FAT12) and root space and the others 31 sectors for data...
There is an other better solution?
Thanks Tsuneo.

Alessandro
0 Kudos

632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Thu Sep 13 22:01:20 MST 2012
Does your "disk" has capacity of 40 sectors (at 512 bytes/sector) or more?
40 sectors are the minimum capacity in which "format" succeeds on Windows.

Tsuneo
0 Kudos

632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alessandro on Tue Sep 11 23:34:16 MST 2012
Thanks Tsuneo,
so you say that the problem is the capacity of the volume? I will try Standard FAT12 format with 2 FAT tables, 4 sectors per cluster and 512 entries on root...
I'll say you if the problem will persist.
Regards
Alessandro




Quote: Tsuneo
There is no specific "format" command for Mass-Storage Class. It's because "format" depends on file system (FAT,EXT,HFS, etc). OS writes media sectors using WRITE10 SCSI command. It verifies the result using READ10. Just the sequences of WRITE10/READ10 make up "format" on your disk.


Don't do more than OS requests.

The major reason why OS format fails on USB MSC examples lies in the capacity of the "disk". Too small capacity can't hold "standard format" OS expects.
Such a disk runs on "reduced format". Read/Write of such a disk work without problem, but "Format" fails.

"Standard" FAT12/16 format
- Sectors per cluster: 4
- Number of FAT: 2
- Number of entries on root directory: 512

"Reduced" FAT12/16 format
- Sectors per cluster: 1
- Number of FAT: 1
- Number of entries on root directory: 16

Tsuneo

0 Kudos

632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Mon Sep 10 21:45:55 MST 2012

Quote:
I would know if there is a method to intercept a format command which arrived from the O.S.


There is no specific "format" command for Mass-Storage Class. It's because "format" depends on file system (FAT,EXT,HFS, etc). OS writes media sectors using WRITE10 SCSI command. It verifies the result using READ10. Just the sequences of WRITE10/READ10 make up "format" on your disk.


Quote:
At the moment I know this because the O.S. write at the offset zero (BootAddress of FAT12) and so I clean my flash memory and restore the DiskImage,


Don't do more than OS requests.

The major reason why OS format fails on USB MSC examples lies in the capacity of the "disk". Too small capacity can't hold "standard format" OS expects.
Such a disk runs on "reduced format". Read/Write of such a disk work without problem, but "Format" fails.

"Standard" FAT12/16 format
- Sectors per cluster: 4
- Number of FAT: 2
- Number of entries on root directory: 512

"Reduced" FAT12/16 format
- Sectors per cluster: 1
- Number of FAT: 1
- Number of entries on root directory: 16

Tsuneo
0 Kudos