Skip to main content
AShel.1
Associate III
August 27, 2020
Question

sector allignments in FATfs on external flash with STM32F767

I'm using FATfs file system on external flash (16MB) using STM32F767, I'm able to create/ read/ write/ close files.

I've created 4 files: sequence of handing files and sector no assigned to them are as,

Created/ Write File1 - sector 8

Created/ Write File2 - sector 9

Created/ Write File3 - sector 10

unlink File2

Created/ Write File4 - sector 11

before creating File 4 I've deleted File 2 using f_unlink("0:/FILE2.TXT"); function, now I expect if I create File4 then sector no 9 should be assigned to this file as it is free sector after File2 is deleted. Is there any way to reused the free sector after deleting files.

if(f_open(&MyFile, "0:/FILE1.TXT", FA_READ | FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)//FA_CREATE_ALWAYS | FA_WRITE
	 {
	 /* 'STM32.TXT' file Open for write Error */
	 Error_Handler();
	 }
	 else
	 {
	 /* Write data to the text file */
	 res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
 
	 if((byteswritten == 0) || (res != FR_OK))
	 {
	 /* 'STM32.TXT' file Write or EOF Error */
	 Error_Handler();
	 }
	 else
	 {
	 		if(f_open(&MyFile2, "0:/FILE2.TXT", FA_READ | FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)//FA_CREATE_ALWAYS | FA_WRITE
	 	 {
	 	 /* 'STM32.TXT' file Open for write Error */
	 	 Error_Handler();
	 	 }
	 
	 else
	 {
	 	res = f_write(&MyFile2, wtext2, sizeof(wtext2), (void *)&byteswritten);
 
	 		 if((byteswritten == 0) || (res != FR_OK))
	 		 {
	 		 /* 'STM32.TXT' file Write or EOF Error */
	 		 Error_Handler();
	 		 }
	 		 
	 /* Read data from the text file */
	 		 if(f_open(&MyFile3, "0:/FILE3.TXT", FA_READ | FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)//FA_CREATE_ALWAYS | FA_WRITE
	 		 	 {
	 		 	 /* 'STM32.TXT' file Open for write Error */
	 		 	 Error_Handler();
	 		 	 }
	 		 	 else
	 		 	 {
	 		 	 /* Write data to the text file */
	 		 	 res = f_write(&MyFile3, wtext, sizeof(wtext), (void *)&byteswritten);
 
	 		 	 if((byteswritten == 0) || (res != FR_OK))
	 		 	 {
	 		 	 /* 'STM32.TXT' file Write or EOF Error */
	 		 	 Error_Handler();
	 		 	 }
	 		 	 else
	 		 	 {
 
	 		 	 }
	 		 	 }
	 		 f_unlink("0:/FILE2.TXT");	 		 
	 		 
	 		 if(f_open(&MyFile4, "0:/FILE4.TXT", FA_READ | FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)//FA_CREATE_ALWAYS | FA_WRITE
	 		 	 		 	 {
	 		 	 		 	 /* 'STM32.TXT' file Open for write Error */
	 		 	 		 	 Error_Handler();
	 		 	 		 	 }
	 		 	 		 	 else
	 		 	 		 	 {
	 		 	 		 	 /* Write data to the text file */
	 		 	 		 	 res = f_write(&MyFile4, wtext, sizeof(wtext), (void *)&byteswritten);
 
	 		 	 		 	 if((byteswritten == 0) || (res != FR_OK))
	 		 	 		 	 {
	 		 	 		 	 /* 'STM32.TXT' file Write or EOF Error */
	 		 	 		 	 Error_Handler();
	 		 	 		 	 }
	 		 	 		 	 else
	 		 	 		 	 {
 
	 		 	 		 	 }
	 		 	 		 	 }

This topic has been closed for replies.

2 replies

AShel.1
AShel.1Author
Associate III
November 8, 2020
AShel.1
AShel.1Author
Associate III
March 7, 2024