cancel
Showing results for 
Search instead for 
Did you mean: 

Hi , I have a stm32 Nucleo L073rz custom board, have tested the usb memory device example ,it is working fine and getting detected in the pc .

svii
Associate III

Can i transfer files from my pc to stm board memory using this config of usb memory device , else i should configure it as a host please let me know this. thanks in advance.

5 REPLIES 5

So if working fine, PC should be able to format and read/write files to MSC​

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

Hi thanks for the reply , the usb memory device is only been detected as a removable disk .I am not able to format it no disk present , the size of the disk is also not available showing unknown capacity. Below is the code i have used (usb , 1Mbyte spi flash).

/////////////////////////////////usbd_storage_if.c/////////////////////////////////////////////////

#define STORAGE_LUN_NBR         1

#define STORAGE_BLK_NBR         0x100

#define STORAGE_BLK_SIZ         0x1000

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

{

 /* USER CODE BEGIN 6 */

  for(int i =0 ;i<blk_len;i++)

 {

SST80B_ReadSector(buf,0,(blk_addr*STORAGE_BLK_SIZ),STORAGE_BLK_SIZ);

 buf +=STORAGE_BLK_SIZ;

}

 return (USBD_OK);

 /* USER CODE END 6 */

}

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

{

  

for(int i =0; i<blk_len;i++)

{

chipsector_erase_call((blk_addr*STORAGE_BLK_SIZ));

}

  for(int j =0; j<blk_len;j++)

  {  

  SST25Write((blk_addr*STORAGE_BLK_SIZ),(uint8_t *)buf,STORAGE_BLK_SIZ);

buf +=STORAGE_BLK_SIZ;  

  }

}

I have configured the STORAGE_BLK_SIZ  to 4096 bytes ,since the min erase of the spi flash is 4096 sector erase,

will this cause any problems.Kindly let me know .

You need to test your code outside of the MSC.

Both read and write routines here move data to the same block, you need to advance the block count in the loop.

Perhaps test logic on a PC C compiler where you print values. On the STM32 you could also instrument to code via a USART or SWV connection.​

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

Hi thanks for the reply, i have tested the spi flash code outside msc and it is working fine , i have implemented spi flash byte read/write and sector (multi byte ) write/read as well,

uart is also added as suggested ,i am able to capture the data in the terminal while reading and writing

data into flash.

I have couple of doubts here :

STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)

STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)

in the above function read and write ,i found the blk_len to be 1 , which corresponds to only one byte

why is storage read and storage write using only 1 byte transfer.

Another problem noticed here is when i configure with below :

#define STORAGE_LUN_NBR         1

#define STORAGE_BLK_NBR         0xff      

#define STORAGE_BLK_SIZ          0x1000

i am not able to format , should i keep STORAGE_BLK_SIZ          0x200 .using an 1MB spi flash with

4096 byte min erase creating problems.

any inputs will be helpful,thaks in advance.

svii
Associate III

Hi, i was able to solve this problem, it works at 4096 block configuration.