USB Mass Storage Class framework implements bulk-only-transfer (BOT) with SCSI protocol. USB packets from the host eventually converted SCSI transport commands by the middleware, in which data is exchanged (read / write) in the unit of logical block, typically 512 bytes.
This SCSI commands works well with SD card system where a dedicated controller does the job of managing the actual memory elements. If you want to use a FLASH chip as a memory unit instead, you need to handle read / write operation directly.
Fortunately, most of flash memory support 4KB block erase. This makes the 4096 bytes as a natural choice for the size of the logical block in the file usbd_storage_if.c. In this case, 8Mbit Flash memory was used.
During initial enumeration, this information is registered to the host. The middleware maintains one logical block size of buffer and handles USB transaction where each payload is only 64 bytes. It then calls SCSI requests to store / retrieve data to / from physical memory device in this case a flash memory. Thus the buffer size should be increased by the same amount in the file usbd_conf.h
Necessary task is to simply convert SCSI block read/write commands into Flash memory sector read/write operations.
Here the logical unit number(lun) is always zero. This is because there is only one LUN is defind. And the number of logical blocks (blk_len) is always one. This is because the internal buffer size is equal to the size of local block. See MSC_MEDIA_PACKET definition above.
When it is first plugged in, it appears as a raw disk with no FAT. So no logical drive will appear. Thus it is necessary to create a FAT. To minimize the overhead space, choose FAT16 <32M option in the fdisk (or cfdisk) utility.
Then format the drive
sudo mkfs.vfat -F 16 /dev/sdb1
At this point the host system may recognize the device as a formatted disk drive. Otherwise plug it out and in again. In the picture below, Nucleo32-L432KC (at the center) and Adesto AT25SF081 (bottom left) are used in this project.
<< source code >>
This SCSI commands works well with SD card system where a dedicated controller does the job of managing the actual memory elements. If you want to use a FLASH chip as a memory unit instead, you need to handle read / write operation directly.
Fortunately, most of flash memory support 4KB block erase. This makes the 4096 bytes as a natural choice for the size of the logical block in the file usbd_storage_if.c. In this case, 8Mbit Flash memory was used.
During initial enumeration, this information is registered to the host. The middleware maintains one logical block size of buffer and handles USB transaction where each payload is only 64 bytes. It then calls SCSI requests to store / retrieve data to / from physical memory device in this case a flash memory. Thus the buffer size should be increased by the same amount in the file usbd_conf.h
Necessary task is to simply convert SCSI block read/write commands into Flash memory sector read/write operations.
Here the logical unit number(lun) is always zero. This is because there is only one LUN is defind. And the number of logical blocks (blk_len) is always one. This is because the internal buffer size is equal to the size of local block. See MSC_MEDIA_PACKET definition above.
When it is first plugged in, it appears as a raw disk with no FAT. So no logical drive will appear. Thus it is necessary to create a FAT. To minimize the overhead space, choose FAT16 <32M option in the fdisk (or cfdisk) utility.
Then format the drive
sudo mkfs.vfat -F 16 /dev/sdb1
At this point the host system may recognize the device as a formatted disk drive. Otherwise plug it out and in again. In the picture below, Nucleo32-L432KC (at the center) and Adesto AT25SF081 (bottom left) are used in this project.
<< source code >>
Comments
Post a Comment