cancel
Showing results for 
Search instead for 
Did you mean: 

QSPI + FatFS + USB mass storage

Posted on March 21, 2018 at 15:12

Hello there,

I am trying to connect 3 sub-systems:

  • qspi flash memory
  • FatFS
  • USB mass storage device

I have successfully written low level drivers for qspi and have connected it with FatFS middleware. I can read and write file and all- this is working.

Now I need to connect the FatFS layer with USB mass storage layer. I am working with the examples found in CubeMx as well as this:

https://community.st.com/thread/44445-using-fatfs-to-access-sd-card-and-usb-mass-storage-device#comments

My problem is that I quite do not understand how the usb mass storage part reaches for files in the FatFs. I thought at the beginning, that the function pointer for USB mass storage lib would be something like: list files, open file, read file, get file time stamp etc... Now I see that there are function pointers for reading and writing some kind of blocks, which have nothing to do with files in my opinion (at least I see no connection yet):

int8_t STORAGE_Init(uint8_t lun);

int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size);

int8_t STORAGE_IsReady(uint8_t lun);

int8_t STORAGE_IsWriteProtected(uint8_t lun);

int8_t STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);

int8_t STORAGE_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);

int8_t STORAGE_GetMaxLun(void);

USBD_StorageTypeDef USBD_DISK_fops = {

STORAGE_Init,

STORAGE_GetCapacity,

STORAGE_IsReady,

STORAGE_IsWriteProtected,

STORAGE_Read,

STORAGE_Write,

STORAGE_GetMaxLun,

(int8_t *)STORAGE_Inquirydata,

};

How to translate data from files like language that FatFS is speaking to the language that USB mass storage API will understand? How are FatFs sectors related to USB mass storage blocks?

I would appreciate all help.

#qspi #usb-mass-storage #fatfs

Note: this post was migrated and contained many threaded conversations, some content may be missing.
11 REPLIES 11
Posted on March 23, 2018 at 18:45

Thanks for the info. I will have to deal with this as well eventually but I need to make the USB mass storage work first.

Posted on March 23, 2018 at 19:17

The SCSI/ATAPI commands coming across the interface (MSC/USBSTOR) are typically for BLOCKs of 512 Byte size (CD/DVD would be 2048 byte, as I recall). The GET CAPACITY should give block size, and block count.

The DISKIO layer of FatFS talks in BLOCKs (nominally 512 bytes, and might request 64 of them if is is acting on a 32KB cluster), the cluster stuff is managed internally by the file system software (FatFS in this case) and described in the BPB (Boot/BIOS Parameter Block) on the media. The media needs to be formatted to have a FAT File System on it. ie FORMAT or MKFS has been used. Blank media/flash will need to be formatted to contain required structures for the file system.

1024 / 512 = 2

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..