2014-09-08 07:25 AM
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?2014-09-08 08:02 AM
Having 2048 bytes (2KB) is not going to be any good for creating a mass storage device.
The block sizes should be 512 bytes, unless you plan on learning a lot more about how this works. You should perhaps try 100 blocks, which would be 50KB, and your read/write routines are not memory/byte addressed, they are block addressed, and each block should be 512 bytes. Suggest using memcpy(). Remember you are making a BLOCK STORAGE DEVICE. I posted examples of using SDRAM on the STM32F429I-DISCO (8MB) as an MSC