cancel
Showing results for 
Search instead for 
Did you mean: 

how to transfer files from stm32 board as mass storage class in device mode to pc.

avenk.1
Associate II

hello,

I able to see the stm32 RAM as storage in pc. I want to transfer the files and buffer data to pc from stm32 RAM as storage.

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

{

 /* USER CODE BEGIN 6 */

memcpy(buf,&buffer1[blk_addr*STORAGE_BLK_SIZ],blk_len*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)

{

 /* USER CODE BEGIN 7 */

memcpy(&buffer1[blk_addr*STORAGE_BLK_SIZ],buf,blk_len*STORAGE_BLK_SIZ);

 return (USBD_OK);

 /* USER CODE END 7 */

}

3 REPLIES 3
Johannes
Senior

So you want to create a RAM-Disk?

Your STM32 should appear as a drive on windows via USB?

If you just add RAM to your USB storage, it appears as "unformated" in windows.

you need to format your ramdisk with a file system like fatfs or azure RTOS FileX and then you can write files to your ram disk

There's been examples of an SDRAM-DISK MSC on several of the DISCO boards over the years.

As @Johannes​ points out you'll need to format with f_mkfs(),perhaps preload with other files for Windows / Linux to find it immediately usable. Can't really auto-run things at this point due to the threat vector that represents, but the OS can read and copy files at user direction.

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

You may also want to use MTP protocol instead of plain mass storage. MTP capable devices are aware of the "files" exchanged between the device and host.