cancel
Showing results for 
Search instead for 
Did you mean: 

FATFs f_opendir is not showing ??

antonius
Senior
Posted on April 10, 2017 at 05:13

Everyone,

I tried to count all the directories on the root but only got 2 directories,

What do I missed here ?

I started with :

f_opendir(&dir, ''),

It returns only 2 directories, suppose to be more than 2,

Anyone has the same experience ?

Thanks

#fatfs #count #directory
9 REPLIES 9
Posted on April 10, 2017 at 08:50

Show the whole code loop where you iterate through the file attributes returned.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 10, 2017 at 08:54

It can change directory but can not read file properly yet ??

====

for(;;) //first for begin

{

if (Cdir >= ndirs) Cdir = 0;

if (Cdir <= ndirs) {Cdir++;Ctrk=1;};

ntrks = get_tracks(AlbumTbl[Cdir], 1); /* Get tracks of

current album */

printf('Curent directory : %d \n',Cdir);

if (strk == 2) {

Ctrk = ntrks - 1;

} else if (strk == 1 || Ctrk >= ntrks) {

Ctrk = 0;

}

strk = 1;

for (;;)

{ //loop the directory until ends, second for begins

strcpy(fname, AlbumTbl[Cdir]); /* Play a track */

strcat(fname, '/');

strcat(fname, TrackTbl[Ctrk]);

printf(fname);printf('\n \n');

//check if directory finish begin

if (++Ctrk >= ntrks )

{

printf('Track finished.. \n');

//Cdir++;//next directory

break;

}//end if

//check if directory finish end

HAL_Delay(250);

}//second for ends

} //first for ends

Posted on April 10, 2017 at 11:14

with this code, it's only entering the first directory, it can see the

next directory but never enter it...I have no idea yet where do I miss ?

I can show you the function if you don't mind..

====

ndirs = get_albums(); /* Get albums and generate card status ID */

for(;;) //first for begin

{

if (Cdir >= ndirs) Cdir = 0;

ntrks = get_tracks(AlbumTbl[Cdir], 1); /* Get

tracks of current album */

printf('Curent directory : %d \n',Cdir);

for (;;)

{ //loop the directory until ends, second for begins

strcpy(fname, AlbumTbl[Cdir]); /* Play a

track */

strcat(fname, '/');

strcat(fname, TrackTbl[Ctrk]);

printf(fname);printf('\n \n');

//check if directory finish begin

if (++Ctrk >= ntrks )

{

printf('Track finished.. \n');

if (Cdir <= ndirs) Cdir++;

break;

}//end if

//check if directory finish end

HAL_Delay(250);

}//second for ends

} //first for ends

=======================

Monitor result :

==============

Get albums 1 ndir

CLK

Get albums 2 ndir

MUSIC3

Get albums 3 ndir

MUSIC32

Get albums 4 ndir

MUSIC33

Get albums 5 ndir

MUSIC34

Get albums 6 ndir

MUSIC35

Get albums 7 ndir

CUBEMX

Get albums 8 ndir

PHOTOV~1

Curent directory : 0

CLK/1OCLOC~1.MP3

CLK/1.MP3

CLK/10.MP3

CLK/10OCLOCK.MP3

CLK/11.MP3

CLK/11OCLOCK.MP3

CLK/12.MP3

CLK/12OCLOCK.MP3

CLK/13.MP3

CLK/14.MP3

CLK/15.MP3

CLK/16.MP3

CLK/17.MP3

CLK/18.MP3

CLK/19.MP3

CLK/1OCLOCK.MP3

CLK/2OCLOC~1.MP3

CLK/2.MP3

CLK/20.MP3

CLK/2OCLOCK.MP3

CLK/3.MP3

CLK/30MIN.MP3

CLK/30MINU~1.MP3

CLK/3OCLOCK.MP3

CLK/4.MP3

CLK/4OCLOCK.MP3

CLK/5.MP3

CLK/5OCLOCK.MP3

CLK/6.MP3

CLK/6OCLOCK.MP3

CLK/7.MP3

CLK/7OCLOCK.MP3

CLK/8.MP3

CLK/8OCLOCK.MP3

CLK/9.MP3

CLK/9OCLOCK.MP3

CLK/ASK.MP3

CLK/BEDROOM1.MP3

CLK/DOOR1.MP3

CLK/DOOR2.MP3

CLK/GREET1.MP3

CLK/GREET2.MP3

CLK/GREET3.MP3

CLK/MAILBOX.MP3

CLK/OPEN.MP3

Track finished..

Curent directory : 1

CUBEMX/

Track finished..

Curent directory : 2

MUSIC3/

Track finished..

Curent directory : 3

MUSIC32/

Track finished..

Curent directory : 4

MUSIC33/

Track finished..

Curent directory : 5

MUSIC34/

Track finished..

Curent directory : 6

MUSIC35/

Track finished..

Curent directory : 7

PHOTOV~1/

=====================

Posted on April 10, 2017 at 15:39

Neither of these two posts show you calling FatFs API functions, or indications from you where this deviates from the content you expect on the media.

Useful information would help you debug

  printf('Curent directory : %d \n',Cdir); // Also print out ntrks so you understand what is expected to be enumerated

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 10, 2017 at 16:30

I have 8 directories and I want to display the content of the

directories, first directory ==> list the track until finish, going to

the second directory ==> list directory...until the 8th directory,

return to the first,

I've made :

printf('Total track : %d \n',ntrks);

from your inspiration, so far it can display only two of the first

directory, but from directory 0 jump to directory 2, I have no idea yet

why ?

Posted on April 10, 2017 at 16:35

Looks like the track is not reset to 1 everytime it's changing

directory, that's probably my puzzle ?

Please have a look on the serial monitor :

=================

Get albums 1 ndir

CLK

Get albums 2 ndir

MUSIC3

Get albums 3 ndir

MUSIC32

Get albums 4 ndir

MUSIC33

Get albums 5 ndir

MUSIC34

Get albums 6 ndir

MUSIC35

Get albums 7 ndir

CUBEMX

Get albums 8 ndir

PHOTOV~1

Total directory : 8

Curent directory : 0

Total track : 45

Curent track : 0

CLK/1OCLOC~1.MP3

Curent track : 1

CLK/1.MP3

Curent track : 2

CLK/10.MP3

Curent track : 3

CLK/10OCLOCK.MP3

Curent track : 4

CLK/11.MP3

Curent track : 5

CLK/11OCLOCK.MP3

Curent track : 6

CLK/12.MP3

Curent track : 7

CLK/12OCLOCK.MP3

Curent track : 8

CLK/13.MP3

Curent track : 9

CLK/14.MP3

Curent track : 10

CLK/15.MP3

Curent track : 11

CLK/16.MP3

Curent track : 12

CLK/17.MP3

Curent track : 13

CLK/18.MP3

Curent track : 14

CLK/19.MP3

Curent track : 15

CLK/1OCLOCK.MP3

Curent track : 16

CLK/2OCLOC~1.MP3

Curent track : 17

CLK/2.MP3

Curent track : 18

CLK/20.MP3

Curent track : 19

CLK/2OCLOCK.MP3

Curent track : 20

CLK/3.MP3

Curent track : 21

CLK/30MIN.MP3

Curent track : 22

CLK/30MINU~1.MP3

Curent track : 23

CLK/3OCLOCK.MP3

Curent track : 24

CLK/4.MP3

Curent track : 25

CLK/4OCLOCK.MP3

Curent track : 26

CLK/5.MP3

Curent track : 27

CLK/5OCLOCK.MP3

Curent track : 28

CLK/6.MP3

Curent track : 29

CLK/6OCLOCK.MP3

Curent track : 30

CLK/7.MP3

Curent track : 31

CLK/7OCLOCK.MP3

Curent track : 32

CLK/8.MP3

Curent track : 33

CLK/8OCLOCK.MP3

Curent track : 34

CLK/9.MP3

Curent track : 35

CLK/9OCLOCK.MP3

Curent track : 36

CLK/ASK.MP3

Curent track : 37

CLK/BEDROOM1.MP3

Curent track : 38

CLK/DOOR1.MP3

Curent track : 39

CLK/DOOR2.MP3

Curent track : 40

CLK/GREET1.MP3

Curent track : 41

CLK/GREET2.MP3

Curent track : 42

CLK/GREET3.MP3

Curent track : 43

CLK/MAILBOX.MP3

Curent track : 44

CLK/OPEN.MP3

Track finished..

Total directory : 8

Curent directory : 2

Total track : 104

Curent track : 45

MUSIC3/YINWEI~1.MP3

Curent track : 46

MUSIC3/YONGGA~1.MP3

Curent track : 47

MUSIC3/YOUNIZ~1.MP3

Curent track : 48

MUSIC3/BESTMA~1.MP3

Curent track : 49

MUSIC3/THEBES~1.MP3

Curent track : 50

MUSIC3/BESTCH~1.MP3

Curent track : 51

MUSIC3/ZHENAI~1.MP3

Curent track : 52

MUSIC3/YOUXIN~1.MP3

Curent track : 53

MUSIC3/YU-AIM~1.MP3

Curent track : 54

MUSIC3/ZAIWOX~1.MP3

Curent track : 55

MUSIC3/ZENYAN~1.MP3

Curent track : 56

MUSIC3/100FEN~1.MP3

Curent track : 57

MUSIC3/AIBUDA~1.MP3

Curent track : 58

MUSIC3/AIBUZA~1.MP3

Curent track : 59

MUSIC3/AIDEJU~1.MP3

Curent track : 60

MUSIC3/AINIDE~1.MP3

Curent track : 61

MUSIC3/AIQING~1.MP3

Curent track : 62

MUSIC3/AIQING~2.MP3

Curent track : 63

MUSIC3/AIQING~3.MP3

Curent track : 64

MUSIC3/AIQING~4.MP3

Curent track : 65

MUSIC3/AI0741~1.MP3

Curent track : 66

MUSIC3/AIZAIT~1.MP3

Curent track : 67

MUSIC3/BAOQIA~1.MP3

Curent track : 68

MUSIC3/BEIERS~1.MP3

Curent track : 69

MUSIC3/BIANCH~1.MP3

Curent track : 70

MUSIC3/BOLI-C~1.MP3

Curent track : 71

MUSIC3/BUAILE~1.MP3

Curent track : 72

MUSIC3/BUDONG~1.MP3

Curent track : 73

MUSIC3/BUZAIH~1.MP3

Curent track : 74

MUSIC3/CHOPST~1.MP3

Curent track : 75

MUSIC3/DANREN~1.MP3

Curent track : 76

MUSIC3/DENGYI~1.MP3

Curent track : 77

MUSIC3/DINGHU~1.MP3

Curent track : 78

MUSIC3/GENGKU~1.MP3

Curent track : 79

MUSIC3/HAOLES~1.MP3

Curent track : 80

MUSIC3/HAOSHI~1.MP3

Curent track : 81

MUSIC3/HONGCH~1.MP3

Curent track : 82

MUSIC3/HUIDAO~1.MP3

Curent track : 83

MUSIC3/HUIYID~1.MP3

Curent track : 84

MUSIC3/HUOYUA~1.MP3

Curent track : 85

MUSIC3/ILLMAR~1.MP3

Curent track : 86

MUSIC3/JINYUL~1.MP3

Curent track : 87

MUSIC3/KELLY-~1.MP3

Curent track : 88

MUSIC3/KUAILE~1.MP3

Curent track : 89

MUSIC3/LIANRE~1.MP3

Curent track : 90

MUSIC3/MAHANG~1.MP3

Curent track : 91

MUSIC3/MEILIT~1.MP3

Curent track : 92

MUSIC3/MEIYOU~1.MP3

Curent track : 93

MUSIC3/MEIYOU~2.MP3

Curent track : 94

MUSIC3/MERRYC~1.MP3

Curent track : 95

MUSIC3/MERRYC~2.MP3

Curent track : 96

MUSIC3/MYWAY-~1.MP3

Curent track : 97

MUSIC3/NANDAO~1.MP3

Curent track : 98

MUSIC3/NIDEWE~1.MP3

Curent track : 99

MUSIC3/NISHIW~1.MP3

Curent track : 100

MUSIC3/NIZAIW~1.MP3

Curent track : 101

MUSIC3/NIZOUB~1.MP3

Curent track : 102

MUSIC3/NICHOL~1.MP3

Curent track : 103

MUSIC3/ONEFIF~1.MP3

Track finished..

Total directory : 8

Curent directory : 4

Total track : 0

Curent track : 104

MUSIC33/

Track finished..

Total directory : 8

Curent directory : 6

Total track : 0

Curent track : 105

MUSIC35/

Track finished..

Total directory : 8

Curent directory : 8

Total track : 11

Curent track : 106

/

Track finished..

Total directory : 8

Curent directory : 9

Total track : 45

Curent track : 107

CLK/

Track finished..

Total directory : 8

Curent directory : 2

Total track : 104

Curent track : 108

MUSIC3/

Track finished..

Total directory : 8

Curent directory : 4

Total track : 0

Curent track : 109

MUSIC33/

Track finished..

Total directory : 8

Curent directory : 6

Total track : 0

Curent track : 110

MUSIC35/

Track finished..

Total directory : 8

Curent directory : 8

Total track : 11

Curent track : 111

/;

Track finished..

Total directory : 8

Curent directory : 9

Total track : 45

Curent track : 112

CLK/

Track finished..

Total directory : 8

Curent directory : 2

Total track : 104

Curent track : 113

MUSIC3/

Track finished..

Total directory : 8

Curent directory : 4

Total track : 0

Curent track : 114

MUSIC33/8'

Track finished..

Total directory : 8

Curent directory : 6

Total track : 0

Curent track : 115

MUSIC35/9

Track finished..

Total directory : 8

Curent directory : 8

Total track : 11

Curent track : 116

/

=============

Posted on April 11, 2017 at 01:23

It's scanning the album now, but from 0 to 8 albums, it's doing album

0,2,4,6,8 ==>0,2,4,6,8 ....why is does it miss 1,3,5,7 ?? Anything I

missed here ? thanks

Serial monitor output :

=================

Get albums 1 ndir

CLK

Get albums 2 ndir

MUSIC3

Get albums 3 ndir

MUSIC32

Get albums 4 ndir

MUSIC33

Get albums 5 ndir

MUSIC34

Get albums 6 ndir

MUSIC35

Get albums 7 ndir

CUBEMX

Get albums 8 ndir

PHOTOV~1

Total directory : 8

Curent directory : 0

Total track : 45

Curent track : 0

CLK/1OCLOC~1.MP3

Curent track : 1

CLK/1.MP3

Curent track : 2

CLK/10.MP3

Curent track : 3

CLK/10OCLOCK.MP3

Curent track : 4

CLK/11.MP3

Curent track : 5

CLK/11OCLOCK.MP3

Curent track : 6

CLK/12.MP3

Curent track : 7

CLK/12OCLOCK.MP3

Curent track : 8

CLK/13.MP3

Curent track : 9

CLK/14.MP3

Curent track : 10

CLK/15.MP3

Curent track : 11

CLK/16.MP3

Curent track : 12

CLK/17.MP3

Curent track : 13

CLK/18.MP3

Curent track : 35

CLK/9OCLOCK.MP3

Curent track : 36

CLK/ASK.MP3

Curent track : 37

CLK/BEDROOM1.MP3

Curent track : 38

CLK/DOOR1.MP3

Curent track : 39

CLK/DOOR2.MP3

Curent track : 40

CLK/GREET1.MP3

Curent track : 41

CLK/GREET2.MP3

Curent track : 42

CLK/GREET3.MP3

Curent track : 43

CLK/MAILBOX.MP3

Curent track : 44

CLK/OPEN.MP3

Track finished..

Total directory : 8

Curent directory : 2

Total track : 104

Curent track : 1

MUSIC3/PEINIZ~1.MP3

Curent track : 2

MUSIC3/PEIZHE~1.MP3

Curent track : 3

MUSIC3/QISHIZ~1.MP3

Curent track : 4

MUSIC3/QINAID~1.MP3

Curent track : 5

MUSIC3/QINAID~2.MP3

Curent track : 6

MUSIC3/QINGRE~1.MP3

Curent track : 7

MUSIC3/QINGXI~1.MP3

Curent track : 8

MUSIC3/RENBUZ~1.MP3

Curent track : 9

MUSIC3/RUGUOB~1.MP3

Curent track : 10

MUSIC3/RUGUOY~1.MP3

==============

CODE :

Posted on April 11, 2017 at 08:40

Is it possible that I got stack overflow ? I set on 512 bytes per task

and &sharpdefine configTOTAL_HEAP_SIZE ((size_t)8192)

Posted on April 12, 2017 at 03:11

without loop in Cdir, I put Cdir with value, it's working, but it can

not jump to another directory :

Code :

=============

Cdir = 0;

ndirs = get_albums();

printf('Total directory : %d \n',ndirs);

printf('Curent directory : %d \n',Cdir);

ntrks = get_tracks(AlbumTbl[Cdir], 1); /* Get

tracks of current album */

printf('Total track : %d \n',ntrks);

for (;;)

{ //loop the directory until ends, second for begins

//Ctrk++;

strcpy(filename, AlbumTbl[Cdir]); /* Play a

track */

strcat(filename, '/');

strcat(filename, TrackTbl[Ctrk]);

printf('Curent track : %d \n',Ctrk);

printf('Curent directory : %d \n',Cdir);

printf(filename);printf('\n \n');

//check if directory finish begin

if (++Ctrk >= ntrks )

{

printf('Track finished.. \n');

Ctrk=0;

break;

}//end if

//check if directory finish end

HAL_Delay(150);

}//second for loop ends

========

serial monitor:

====

Get albums 1 ndir

CLK

Get albums 2 ndir

MUSIC3

Get albums 3 ndir

MUSIC32

Get albums 4 ndir

MUSIC33

Get albums 5 ndir

MUSIC34

Get albums 6 ndir

MUSIC35

Get albums 7 ndir

CUBEMX

Get albums 8 ndir

PHOTOV~1

Total directory : 8

Curent directory : 0

Total track : 45

Curent track : 0

Curent directory : 0

CLK/1OCLOC~1.MP3

Curent track : 1

Curent directory : 0

CLK/1.MP3

Curent track : 2

Curent directory : 0

CLK/10.MP3

Curent track : 3

Curent directory : 0

CLK/10OCLOCK.MP3

Curent track : 4

Curent directory : 0

CLK/11.MP3

Curent track : 5

Curent directory : 0

CLK/11OCLOCK.MP3

Curent track : 6

Curent directory : 0

CLK/12.MP3

Curent track : 7

Curent directory : 0

CLK/12OCLOCK.MP3

Curent track : 8

Curent directory : 0

CLK/13.MP3

Curent track : 9

Curent directory : 0

CLK/14.MP3

Curent track : 10

Curent directory : 0

CLK/15.MP3

Curent track : 11

Curent directory : 0

CLK/16.MP3

Curent track : 12

Curent directory : 0

CLK/17.MP3

Curent track : 13

Curent directory : 0

CLK/18.MP3

Curent track : 14

Curent directory : 0

CLK/19.MP3

Curent track : 15

Curent directory : 0

CLK/1OCLOCK.MP3

Curent track : 16

Curent directory : 0

CLK/2OCLOC~1.MP3

Curent track : 17

Curent directory : 0

CLK/2.MP3

Curent track : 18

Curent directory : 0

CLK/20.MP3

Curent track : 19

Curent directory : 0

CLK/2OCLOCK.MP3

Curent track : 20

Curent directory : 0

CLK/3.MP3

Curent track : 21

Curent directory : 0

CLK/30MIN.MP3

Curent track : 22

Curent directory : 0

CLK/30MINU~1.MP3

Curent track : 23

Curent directory : 0

CLK/3OCLOCK.MP3

Curent track : 24

Curent directory : 0

CLK/4.MP3

Curent track : 25

Curent directory : 0

CLK/4OCLOCK.MP3

Curent track : 26

Curent directory : 0

CLK/5.MP3

Curent track : 27

Curent directory : 0

CLK/5OCLOCK.MP3

Curent track : 28

Curent directory : 0

CLK/6.MP3

Curent track : 29

Curent directory : 0

CLK/6OCLOCK.MP3

Curent track : 30

Curent directory : 0

CLK/7.MP3

Curent track : 31

Curent directory : 0

CLK/7OCLOCK.MP3

Curent track : 32

Curent directory : 0

CLK/8.MP3

Curent track : 33

Curent directory : 0

CLK/8OCLOCK.MP3

Curent track : 34

Curent directory : 0

CLK/9.MP3

Curent track : 35

Curent directory : 0

CLK/9OCLOCK.MP3

Curent track : 36

Curent directory : 0

CLK/ASK.MP3

Curent track : 37

Curent directory : 0

CLK/BEDROOM1.MP3

Curent track : 38

Curent directory : 0

CLK/DOOR1.MP3

Curent track : 39

Curent directory : 0

CLK/DOOR2.MP3

Curent track : 40

Curent directory : 0

CLK/GREET1.MP3

Curent track : 41

Curent directory : 0

CLK/GREET2.MP3

Curent track : 42

Curent directory : 0

CLK/GREET3.MP3

Curent track : 43

Curent directory : 0

CLK/MAILBOX.MP3

Curent track : 44

Curent directory : 0

CLK/OPEN.MP3

Track finished..