Skip to main content
avenk.1
Associate
Mar 8, 2023 6:56 AM UTC
Question

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

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 */

}

This topic has been closed for replies.

3 replies

Johannes
Senior
May 26, 2023 10:47 AM UTC

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

Tesla DeLorean
Guru
May 26, 2023 11:24 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Pavel A.
May 26, 2023 1:59 PM UTC

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.