AnsweredAssumed Answered

mass storage class and usbd_storage.c

Question asked by de.ab on Sep 8, 2014
Latest reply on Sep 8, 2014 by Clive One
I try to make mass storage device with stm32f4 and I don't use SD card. So i take usb device example and change usbd_storage.c

#define STORAGE_LUN_NBR                  1  
#define STORAGE_BLK_NBR                  2048  
#define STORAGE_BLK_SIZ                  1
uint8_t Memory[2048];

.
.
.
.
.
.
.

int8_t STORAGE_Init(uint8_t lun)
{
   int i = 0;
   for (i = 0 ; i < 2048 ; i++)
   {
      Memory[i] = 0;
  }
  return 0;
}

int8_t STORAGE_IsReady(uint8_t lun)
{
   return 0;
}

int8_t STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
   int i;   
   for (i = 0; i < blk_len; i++)
   {
      buf[i] = Memory[i+blk_addr];
   }
  return 0;
}

int8_t STORAGE_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{   
   int i;   
   for (i = 0; i < blk_len; i++)
   {
      Memory[i+blk_addr] = buf[i];
   }
  return 0;
}

I download program to STM32, connect it to PC, new disk appears in Windows Ecplorer and I can't access it, so it doesn't work as mass storage device. I know, that with global array Memory[] it will be erase after power off, but I thought that when it connected to PC, it should work fine.
So what is wrong?
I also don't understand what STORAGE_BLK_NBR and STORAGE_BLK_SIZ should be exactly?

Outcomes