cancel
Showing results for 
Search instead for 
Did you mean: 

Storage access on an STM32 microcontroller

VVarg.1
Associate II

Hi All,

I have noticed that when connecting both of my boards [b-g474e-dpow1, stm32g474ret6u] and [NUCLEO-F429ZI, stm32f429zi] they are recognized as a storage device on windows per the picture below for the b-g474e-dpow1 board.

0693W00000KbSwCQAV.pngMy question is, these 1.51MB are part of the memory of the onboard microcontroller [stm32g474ret6u] or the STlink debugger or both?

We have an application that requires reading data points from a .txt file and place these values sequentially on a port. The user will (somehow) upload the .txt [approx 8kB] file to the microcontroller memory and when done, it will send all these points to a port when commanded.

Any recommendations for an efficient implementation for this problem?

The NUCLEO-F429ZI can provide a USB-OTG PHY. Is it possible to configure it so it behaves as a USB flash drive so the user can upload this .txt file?

Regards

9 REPLIES 9
KnarfB
Principal III

> My question is, these 1.51MB are part of the memory of the onboard microcontroller [stm32g474ret6u]

No. It's all done in the ST-LINK. The ST-LINK will flash the firmware, so in the end the .bin file will sit in MCUs flash.

Yes, you can implement a USB MSC device (=flash drive) in the MCU. There are other ways like attaching a micro-SD card or using the serial connection as long as you have the ST-LINK attached.

hth

KnarfB

Can probably port an MSC Device example to the NUCLEO

STM32Cube_FW_F4_V1.25.0\Projects\STM324x9I_EVAL\Applications\USB_Device\MSC_Standalone

There's probably also RAMDISK examples, many years back I posted a MSC example for the STM32F429I-DISCO using the SDRAM

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

Hi KnarfB

Thanks for your reply. Understood with the memory.

Can you educate me on what's inside the .bin file? Is it the compiled code to download to the flash?

Hi @Community member​ , Thanks for your reply.

I'll search for the examples you mentioned and hope to bring them up.

By RAMDISK, you refer to an implementation using MSC? Or is it different

Thanks

A .bin file is a 1:1 flash image of all machine code and (initialized) data.

hth

KnarfB

A MSC USB Device, looking to the PC like a MSC, with the data stored on the STM32 side SDRAM. ie read/write map to sectors stored in SDRAM. Initial formatting could be done via FATFS MKFS, or PC could format.

ST has some equivalent examples of this in other STM32 Cube/HAL repositories.

Other examples of MSC USB Host, where the STM32 mounts a USB Flash Drive, as I recall this is called FWUpgrade on STM32F4-DISCO and STM3F429I-DISCO

Normally the MSC USB Device implementations map to the SDIO/SDMMC interface to allow read/write-thru onto a MicroSD card or eMMC chip.

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

Hi @Community member​ , thanks for your response.

I have successfully created and downloaded a project that will bring up an MSC drive within the STM32F429ZI memory (SDRAM). Each time I power-cycle the board, windows will always request the unit to be formated. Is there a way this MSC drive can be pre-formatted or a workaround you can suggest?

In the case of using a MicroSD card or an external USB stick (USB as a host), which routines can help me read each line of a .txt file stored in either a MicroSD or a USB stick?

Thanks

Thanks @KnarfB​ !

You could "format" with a handful of blocks, basically a BPB, a couple of FAT sectors, and a blank root directory. If you're not familiar with block storage devices or file systems, you could use FATFS's f_mkfs() create one using DISKIO functions that read/write the memory blocks.

FATFS isn't particularly function rich, you'd need to code a simple parser using f_read() to pull in blocks of data, and extract lines, which terminate with \r\n or \n characters.

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