Skip to main content
Javier1
Principal
April 28, 2022
Solved

Using FatFs , i am unable to get long filenames, but i get the short filenames

  • April 28, 2022
  • 1 reply
  • 2677 views

I am able to read the fixed length fname.

But the pointer to the long filename is always 0.

0693W00000LzKvXQAV.png 

this is how im reading trough the list of files

FRESULT detect_binariesFolder(){
	fresult=f_opendir(&dir, "lu");
	fresult=f_readdir(&dir, &filinfo);
	fresult=f_findfirst(&dir, &filinfo, "lu", "*.bin");//http://elm-chan.org/fsw/ff/doc/findfirst.html
 
	 while (fresult == FR_OK && filinfo.fname[0]) { /* Repeat while an item is found */
			fresult=f_findnext (&dir, &filinfo);
	 }
 
	fresult=f_closedir(&dir);
	return fresult;
}

I tried the three different cubeMx options for long filenames :

  • static buffer on the BSS
  • dynamic buffer on heap
  • dynamic buffer on stack

None of them works.

0693W00000LzKtSQAV.png 

My setup:

  • stm32f105RBt6 custom board.
  • SD Card trough SPI2, sandisk ultra 16GB.
  • CubeMx version 6.4.0, STM32Cube_FW_F1_V1.8.4 package which uses FatFs version R0.10c, Nov 09, 2014.
  • CubeIDE Version: 1.8.0
This topic has been closed for replies.
Best answer by Javier1

Okay that wasnt so hard, i just needed to find up to date documentation.

(C:\Users\**your user**\STM32Cube\Repository\STM32Cube_FW_F1_V1.8.4\Middlewares\Third_Party\FatFs\doc)

0693W00000LzL6pQAF.png 

Apparently the pointer needs to be initialiced by you first.

adding this three lines fixes the code:

FRESULT detect_binariesFolder(){
 char lfn[_MAX_LFN + 1];
 filinfo.lfname = lfn;
 filinfo.lfsize = sizeof lfn;
 
 	fresult=f_opendir(&dir, "lu");
 	fresult=f_readdir(&dir, &filinfo);
 	fresult=f_findfirst(&dir, &filinfo, "lu", "*.bin");//http://elm-chan.org/fsw/ff/doc/findfirst.html
 
 	 while (fresult == FR_OK && filinfo.fname[0]) { /* Repeat while an item is found */
 			fresult=f_findnext (&dir, &filinfo);
 	 }
 
 	fresult=f_closedir(&dir);
 	return fresult;
 }

0693W00000LzL6BQAV.png

1 reply

Javier1
Javier1AuthorBest answer
Principal
April 28, 2022

Okay that wasnt so hard, i just needed to find up to date documentation.

(C:\Users\**your user**\STM32Cube\Repository\STM32Cube_FW_F1_V1.8.4\Middlewares\Third_Party\FatFs\doc)

0693W00000LzL6pQAF.png 

Apparently the pointer needs to be initialiced by you first.

adding this three lines fixes the code:

FRESULT detect_binariesFolder(){
 char lfn[_MAX_LFN + 1];
 filinfo.lfname = lfn;
 filinfo.lfsize = sizeof lfn;
 
 	fresult=f_opendir(&dir, "lu");
 	fresult=f_readdir(&dir, &filinfo);
 	fresult=f_findfirst(&dir, &filinfo, "lu", "*.bin");//http://elm-chan.org/fsw/ff/doc/findfirst.html
 
 	 while (fresult == FR_OK && filinfo.fname[0]) { /* Repeat while an item is found */
 			fresult=f_findnext (&dir, &filinfo);
 	 }
 
 	fresult=f_closedir(&dir);
 	return fresult;
 }

0693W00000LzL6BQAV.png

hit me up in https://www.linkedin.com/in/javiermuñoz/