cancel
Showing results for 
Search instead for 
Did you mean: 

Flash drive in Nucleo-F446RE

xisco
Associate III

Hello,

When I plug this board to my computer, appears a removable disk of 1,6 MB capacity.

Is this disk accessible from the MCU? For store small data, or make a datalogger

Where the filesystem is stored? Neither the STM32F446RE nor STM32F103CB of the STlink have enough capacity

 

1 ACCEPTED SOLUTION

Accepted Solutions

It's a faux MSC device to allow for drag-n-drop of binary files to flash onto the STM32F446. A bit like the UF2 loader used on Arduino/RPi Pico type boards.

The STM32F1 used for the ST-LINK provides a CDC/VCP and MSC class device, and emulates a FAT Volume for the purpose of writing into the FLASH of the Target

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

View solution in original post

9 REPLIES 9

It's a faux MSC device to allow for drag-n-drop of binary files to flash onto the STM32F446. A bit like the UF2 loader used on Arduino/RPi Pico type boards.

The STM32F1 used for the ST-LINK provides a CDC/VCP and MSC class device, and emulates a FAT Volume for the purpose of writing into the FLASH of the Target

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

Sorry. Can't understand. Which specific board are you using? The appearance of a removable disk of 1.6MB capacity when you plug a board into your computer typically indicates that the board has a USB Mass Storage interface.

If you can't read and understand the question, don't answer it. The board is explicitly stated by the OP

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

Hello Tesla DeLorean

i 'm able to make an MSC class device using USBX connected to a volume emulated in RAM using FileX

but i'm only able to do a volume of 64K that have a real capacity of 64K (actually is less but i think its because part of the space is the FAT)

did you know how ST is able to "FAke" the 6mb of space?

i think i can use the number i want on the ULONG USBD_STORAGE_GetMediaLastLba(VOID) function but only this don't help.

I want to drag and drop a config file on to the microcontroller and i dont need to have  the real file at the finished operation of copy (like ST do with the bin file) but to have access on the file to store value on a eeprom 

thank you

 

 

The MSC reports via SCSI commands, there's a READ CAPACITY command that reports a number of sectors. The file system has it's own MBR or BPB describing the volume, and assorted structure sizes.

To write a "FILE" you have to basically emulate and understand the file system, not just a block storage device. You'd have to watch how it writes to the clusters and writes to the FAT tables, and writes the directory entry.

ST doesn't make that much space available everywhere, it just pretends enough for the OS to accept it, and allow for size/space checking for the file being written/copied.

 

Making a block storage device that just maps to SDRAM or QSPI NOR Flash would be a simpler mapping.

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

Hello Tesla

thank you for your response!

i understand that the ST don't make that much space ,but pretend to the OS that there is much capacity, i think is using a "unreal number" in this function:

ULONG USBD_STORAGE_GetMediaLastLba(VOID)
{
  ULONG LastLba = 0U;

  /* USER CODE BEGIN USBD_STORAGE_GetMediaLastLba */
  LastLba = (FX_SRAM_DISK_SIZE / FX_SRAM_SECTOR_SIZE) - 1;
  /* USER CODE END USBD_STORAGE_GetMediaLastLba */

  return LastLba;
}

BUT my question is how to manage the read and write , we have to fill this two function:

UINT USBD_STORAGE_Read(VOID *storage_instance, ULONG lun, UCHAR *data_pointer,
                       ULONG number_blocks, ULONG lba, ULONG *media_status)
{
  UINT status = UX_SUCCESS;

  /* USER CODE BEGIN USBD_STORAGE_Read */
  UX_PARAMETER_NOT_USED(storage_instance);
  UX_PARAMETER_NOT_USED(lun);
  UX_PARAMETER_NOT_USED(media_status);

  while(number_blocks--)
  {
    status =  fx_media_read(&sram_disk,lba,data_pointer);
    data_pointer+=512;
    lba++;
  }

  /* USER CODE END USBD_STORAGE_Read */

  return status;
}

UINT USBD_STORAGE_Write(VOID *storage_instance, ULONG lun, UCHAR *data_pointer,
                        ULONG number_blocks, ULONG lba, ULONG *media_status)
{
  UINT status = UX_SUCCESS;

  /* USER CODE BEGIN USBD_STORAGE_Write */
  UX_PARAMETER_NOT_USED(storage_instance);
  UX_PARAMETER_NOT_USED(lun);
  UX_PARAMETER_NOT_USED(media_status);

  while(number_blocks--)
  {
    status =  fx_media_write(&sram_disk,lba,data_pointer);
    data_pointer+=512;
    lba++;
  }

  /* USER CODE END USBD_STORAGE_Write */

  return status;
}

here i have a working write and read BUT i need the real space to work

did you have an example like ST manage this two function to fake space?

i think ST is using the information on the file while the file is written and "forgot" the previous write byte

i also have another 2 question:

1)

if i add or delete a file this function is called:

UINT USBD_STORAGE_Flush(VOID *storage_instance, ULONG lun, ULONG number_blocks,
                        ULONG lba, ULONG *media_status)
{
  UINT status = UX_SUCCESS;

  /* USER CODE BEGIN USBD_STORAGE_Flush */
  UX_PARAMETER_NOT_USED(storage_instance);
  UX_PARAMETER_NOT_USED(lun);
  UX_PARAMETER_NOT_USED(number_blocks);
  UX_PARAMETER_NOT_USED(lba);
  UX_PARAMETER_NOT_USED(media_status);

  fx_media_flush(&sram_disk);
  /* USER CODE END USBD_STORAGE_Flush */

  return status;
}

so i know there is a diferent number of file in the disk,

BUT if i only modify i file from PC on the disk the flush function is not called, how can i know there is a difference to manage ? like i have to re-parse the file to change someting in my application

2)

i want to use the disk from PC side to change/read file and from the STM32 to parse/change the file, how to achive that? i have to use a mutex?

i know i can make the disk disappear on PC side changing the status to "media not present" 0x00003A02

in this function:

UINT USBD_STORAGE_Status(VOID *storage_instance, ULONG lun, ULONG media_id,
                         ULONG *media_status)
{
  UINT status = UX_SUCCESS;

  /* USER CODE BEGIN USBD_STORAGE_Status */
  UX_PARAMETER_NOT_USED(storage_instance);
  UX_PARAMETER_NOT_USED(lun);
  UX_PARAMETER_NOT_USED(media_id);
  
  *media_status=0;
  /* USER CODE END USBD_STORAGE_Status */

  return status;
}

and PC can't read or write the disk, but how to know if the PC is reading or writing before put the media to not present? 

thank you in advance for your responce 

 

 

thank you Pavel for this usefull information!

so if i understand correct this is a type of file to flash another firmware on the micro, like ST do on the nucleo

But ST don't use a "normal" .bin file to do that?

also i'm interested to apload a file that have some custom configuration on it

 

thank you

@ABasi.2 If I understand correctly, UF2 is a hack for small devices that do not have enough memory or "brain" for a normal FAT filesystem. ST boards with mbed support are on the upper end of such devices, at least they can handle plain .bin files and simulate the FAT metadata. With UF2 you only need to simulate enough of storage device to let the host "stream" the file, block by block, until you receive the whole file. Hopefully, user on the PC side won't do "copy  /v" to verify the copy ))

also i'm interested to apload a file that have some custom configuration on

Of course. The UF2 format has provision for this (see the flags description).