cancel
Showing results for 
Search instead for 
Did you mean: 

How to write multiple file in sd card sdio using fatfs

pankaj4
Associate

Hi,

 

1.I want to save multiple files but only 50 or 55 files savings.

and how to save files next to next file.

I want to fo fill data files up to to 32 GB.

 

 

2. how to reuse same memory for multi file creation

int main(void)

{

 

/* USER CODE BEGIN 1 */

 

 

/* USER CODE END 1 */

 

/* MCU Configuration--------------------------------------------------------*/

 

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

 

/* USER CODE BEGIN Init */

 

/* USER CODE END Init */

 

/* Configure the system clock */

SystemClock_Config();

 

/* USER CODE BEGIN SysInit */

 

/* USER CODE END SysInit */

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_SDIO_SD_Init();

/* USER CODE BEGIN 2 */

#if 1

/*##-1- Link the SD disk I/O driver ########################################*/

static uint8_t buffer[_MAX_SS]; /* a work buffer for the f_mkfs() */

 

 

// HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);

/*##-1- Link the SD disk I/O driver ########################################*/

if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)

{

/*##-2- Register the file system object to the FatFs module ##############*/

if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK)

{

/* FatFs Initialization Error */

Error_Handler();

}

else

{

/*##-3- Create a FAT file system (format) on the logical drive #########*/

if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, buffer, sizeof(buffer)) != FR_OK)

{

HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);

Error_Handler();

}

else

{

 

for(k=0;k<10000;k++)

{

sprintf(f_name,"Test%u.csv",k);

newFileName(f_name);

//HAL_Delay(200);

 

}

 

}

}

}

 

/*##-11- Unlink the SD disk I/O driver ####################################*/

FATFS_UnLinkDriver(SDPath);

 

 

I also changed Stack size and heap size

_Min_Heap_Size = 0x2000; /* required amount of heap */

_Min_Stack_Size = 0x4000; /* required amount of stack */

 

Please help me.

Thanks

Pankaj

 

3 REPLIES 3
SofLit
ST Employee

Hello,

You are not following our recommendations on thread posting.

Please read this: https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

Thank you for your understanding.

 

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.

I wouldn't use f_mkfs() unless the card is blank or gets corrupted. Cards from the factory are optimally formatted, reformatting is usually less than ideal with respect to the alignment of clusters, structures, and erase blocks.

FAT typically limits the number of files in the top level. Would recommend creating a subdirectory, and filling THAT with the files, as it will expand to accommodate them.

Individual files you'd likely want to keep below 4GB to be manageable.

You can fill a card using multiple files. Filling a 400GB card can take a while on the STM32

The function writing the file might be illustrative.

Use 8.3 names, they'll consume less resources in the root directory.

Use the code pasting tool </> so formatting is retained, and there's not a wall-of-text

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

As @SofLit said, please pay attention to the posting tips - particularly for posting source code!

 


@pankaj4 wrote:

 

1.I want to save multiple files but only 50 or 55 files savings.

Not sure what you mean by, "only 50 or 55 files savings" ?

 


@pankaj4 wrote:

and how to save files next to next file.


Surely, that's just a case of closing the previous file, and opening the next ?

The FatFs documentation is here: http://elm-chan.org/fsw/ff/

Specifically, for opening a file: http://elm-chan.org/fsw/ff/doc/open.html

You can see that f_open() has the option to create a file if it doesn't already exist.