cancel
Showing results for 
Search instead for 
Did you mean: 

SD card formatting using fileX

frogrammer
Associate II

Hi, It works, apparently a different microSd card works.

however, it is strange that, DATALOG2 could write into the card.

May i know how shall i perform sd card format function or what to fill up in the function?

 

Follow-up of the the topic below:

Solved: Re: Standalone FileX SDIO SD Card Initializing err... - STMicroelectronics Community

 

6 REPLIES 6
Saket_Om
ST Employee

Hello @frogrammer 

To format your SD card you can use f_mkfs(). Please refer to the article below:

How to create a file system on a SD card using STM... - STMicroelectronics Community 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

thats using fatfs, not FileX

 

@frogrammer 

For FileX it is fx_media_format(). Pledase refer to the implementation on the example below:

STM32CubeWBA/Projects/NUCLEO-WBA65RI/Applications/FileX/Fx_File_Edit_Standalone/FileX/App/app_filex.c at main · STMicroelectronics/STM32CubeWBA · GitHub

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
AScha.3
Super User

Usually every new SD card is formatted,

at the optimum for this card.

So you just could do it worse by format the card.

And always first do only read tests, with existing file on card, then read and write tests. Format should be never needed, bzw bigger cards are exfat formatted and need this enabled in fat drivers.

If you feel a post has answered your question, please click "Accept as Solution".

Hello @frogrammer 

Did you manage to format your SD card using FileX API? 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
MFARH.1
ST Employee

Hello @frogrammer,

How to Format an SD Card with FileX
To format an SD card, the main steps are as follows:

Initialize the File System
Before any operation, you need to initialize the file system using the fx_system_initialize() function. This prepares the FileX environment to manage storage media.

Use the fx_media_format() Formatting Function
This function formats the card with a file system (FAT32). It requires several important parameters:

UINT _fx_media_format(FX_MEDIA *media_ptr,
                                       VOID (*driver)(FX_MEDIA *media),
                                       VOID *driver_info_ptr,
                                       UCHAR *memory_ptr,
                                       UINT memory_size,
                                       CHAR *volume_name,
                                       UINT number_of_fats,
                                       UINT directory_entries,
                                       UINT hidden_sectors,
                                       ULONG total_sectors,
                                       UINT bytes_per_sector,
                                       UINT sectors_per_cluster,
                                       UINT heads,
                                       UINT sectors_per_track);

Parameter Descriptions

  • media_ptr:
    Pointer to the media control block. This structure manages the media and does not need to be opened before calling this function.

  • driver:
    Pointer to the FileX driver function. This driver must be able to handle requests before the media is opened.

  • driver_info_ptr:
    Optional pointer to driver-specific information or context.

  • memory_ptr:
    Pointer to a memory buffer used by FileX during formatting. This buffer must be at least 512 bytes plus one sector size.

  • memory_size:
    Size of the memory buffer pointed to by memory_ptr.

  • volume_name:
    Name of the volume (label) to assign to the formatted media.

  • number_of_fats:
    Number of FAT copies to create (usually 2 for redundancy).

  • directory_entries:
    Number of root directory entries.

  • hidden_sectors:
    Number of hidden sectors before the start of the volume.

  • total_sectors:
    Total number of sectors on the media.

  • bytes_per_sector:
    Number of bytes per sector (commonly 512 bytes for SD cards).

  • sectors_per_cluster:
    Number of sectors per cluster, which defines the allocation unit size.

  • heads:
    Number of heads (used to simulate disk geometry; usually 1 for removable media).

  • sectors_per_track:
    Number of sectors per track (used for disk geometry simulation).

 

Regards,

Maher