AnsweredAssumed Answered

QSPI + FatFS + USB mass storage

Question asked by Lukasz Przenioslo on Mar 21, 2018
Latest reply on Mar 25, 2018 by Lukasz Przenioslo

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: 

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 = {
  (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.