Skip to main content
alianvari
Associate III
December 25, 2019
Solved

using LFN feature in sd card with stm32f4

  • December 25, 2019
  • 5 replies
  • 1837 views

Hi,I want to use lfn feature in sd card and i use stm32f4 for this purpose i set _USE_LFN to 1 and _MAX_LFN to 255 . when i create the file , file is created but when i want to return file name , returns wrong.

please guide me, how to return file name when i use lfn feature?

i attache the code.

unsigned char save_file_sd_log(void)

{

rtc_get(NO_CHANGE);

delay_ms(5);

if (INSERT_SD ==0)

{

res=disk_initialize (0);

if (res==FR_OK)

{

rtc_get(NO_CHANGE);

res=f_mount(&SDFatFs,"1:/", 1);

if (res!=FR_OK && res!=FR_EXIST) 

{

sprintf(str,"save log to sd ERROR f_mount:%d",res);

debug(str);

return 0;

}

res=f_mkdir ("1:/LOG");

if (res!=FR_OK && res!=FR_EXIST)

{

sprintf(str,"save log to sd ERROR f_mkdir:%d",res);

debug(str);

return 0;

}

if(AA_SaveOnCycleFile==1)

{

sprintf(name_file_str,"1:/LOG/CYCLE%02d%02d%02d.log",year_shamsi,month_shamsi,day_shamsi);

res = f_open( &SD_File , name_file_str ,FA_OPEN_ALWAYS | FA_READ | FA_WRITE);

}

else

{

sprintf(name_file_str,"1:/LOG/EVENT%02d%02d%02d.log",year_shamsi,month_shamsi,day_shamsi);

res = f_open( &SD_File , name_file_str ,FA_OPEN_ALWAYS | FA_READ | FA_WRITE);

}

if (res!=FR_OK && res!=FR_EXIST) 

{

sprintf(str,"save log to sd ERROR f_open:%d",res);

debug(str);

return 0;

}

res = f_lseek(&SD_File, SD_File.fsize);

if (res!=FR_OK && res!=FR_EXIST) 

{

f_close(&SD_File);

f_closedir(&SD_dir);

sprintf(str,"save log to sd ERROR f_lseek:%d",res);

debug(str);

return 0;

}

f_printf (&SD_File,"%s",log_trigger_sd);

res=f_close(&SD_File);

f_closedir(&SD_dir);

return 1;

}

else

{

debug("disk Not Initialize!");

return 0;

}

}

else

{

debug("NO Insert Card!");

return 0;

}

}

unsigned char find_files_sd(void)

{

if (INSERT_SD ==0)

{

res=disk_initialize (0);

if (res==0)

{

res=f_mount(&SDFatFs,"1:/", 1);

if (res!=FR_OK && res!=FR_EXIST) 

{

sprintf(str,"<ERR*SD NOT Ready:%d*>\r\n",res);

if (start_debug==1) print(DEBUG_PORT,str);

else if (start_debug==2) print(LAN_PORT,str);

return 0;

}

res = f_findfirst(&SD_dir,&fno,"1:/LOG","*.LOG"); /* Start to search for log files */

sprintf(str,"<FFILE*");

if (start_debug==1) print(DEBUG_PORT,str);

else if (start_debug==2) print(LAN_PORT,str);

  while (res == FR_OK && fno.fname[0]) /* Repeat while an item is found */

{     

sprintf(str,"%s*%ld*", fno.lfname,fno.fsize); 

if (start_debug==1) print(DEBUG_PORT,str);

else if (start_debug==2) print(LAN_PORT,str);

 res = f_findnext(&SD_dir, &fno);        /* Search for next item */

 } 

sprintf(str,">\r\n");  

if (start_debug==1) print(DEBUG_PORT,str);

else if (start_debug==2) print(LAN_PORT,str);

  f_closedir(&SD_dir);

}

else

{

sprintf(str,"<ERR*disk Not Initialize!*>\r\n");  

if (start_debug==1) print(DEBUG_PORT,str);

else if (start_debug==2) print(LAN_PORT,str);}

}

else

{

sprintf(str,"<ERR*NO Insert Card!*>\r\n");  

if (start_debug==1) print(DEBUG_PORT,str);

else if (start_debug==2) print(LAN_PORT,str);

return 0;

}

return 1;

}

This topic has been closed for replies.
Best answer by dbgarasiya

I am attaching you one screenshot for that

5 replies

dbgarasiya
Senior
December 28, 2019

you have to update in your .ioc file in Fatfs part

USE_LFN should be enable

alianvari
alianvariAuthor
Associate III
December 30, 2019

I din't notice . Can you explain more?

what is .ioc file?

dbgarasiya
Senior
December 31, 2019

means in hardware configuration file, where you configure hardware pin for sd card

dbgarasiya
dbgarasiyaBest answer
Senior
December 31, 2019

I am attaching you one screenshot for that

alianvari
alianvariAuthor
Associate III
January 5, 2020

thanks