FATS f_getfree 0 clusters

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

FATS f_getfree 0 clusters

Post by fastlink30 »

stm32f4 discovery , chibios 2.6.6, fatfs 0,9 patched, ugfx

installed fatfs, seems all correct, i try the routine cmd_sdiotest() , under \testhal\STM32F4xx\SDC\
all is done successfully until arrive to f_getfree(), here the number of resulting cluster is everytime 0

i have changed the parameter of routine, becouse if i use &fsp as last parameter the returning parameter err is not FR_OK.
to have FR_OK i change to &SDC_FS, and no error.

Code: Select all

err = f_getfree("/", &clusters, &SDC_FS);


what can be? communication is ok, sd card is 8mb, with only 1 partition of 680mb fat16 (tryed also with fat32)
tryed also with another sd card, same results.
tryed to pass parameter for path as "/", "0:", "1:"

one things, when i compile i get this warning:

warning: passing argument 3 of 'f_getfree' from incompatible pointer type [enabled by default]
note: expected 'struct FATFS **' but argument is of type 'struct FATFS *'

what is the correct mode to pass this argument (from static struct FATFS)?

thanks
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: FATS f_getfree 0 clusters

Post by Giovanni »

The warning is definitely meaningful, apparently you have to pass a pointer to a pointer to that structure, it is like the function returns a pointer to a structure allocated internally.

Giovanni
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: FATS f_getfree 0 clusters

Post by fastlink30 »

i try with (like in the demos)

FATFS *fs;

.... , &fs);

but is not ok.

so all the demos are wrong?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: FATS f_getfree 0 clusters

Post by Giovanni »

No, those used to work, there must be something else.

Giovanni
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: FATS f_getfree 0 clusters

Post by fastlink30 »

at the moment i do:

FATFS *fs2;
FATFS **fsp;

.....

fs2=(FATFS *)&SDC_FS;
*fsp=fs2;
chprintf(chp, "Mount filesystem... ");
chThdSleepMilliseconds(100);
err = f_getfree("/", &clusters, fsp);

ok, brutal, but like this seems correct, inside f_getfree() is called check_fs() wich return 2 (record signature not found)=> FR_NO_FILESYSYEM
... ach!
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: FATS f_getfree 0 clusters

Post by fastlink30 »

i forgot to say that i use usart6 and pins are connected like this:

DISCOVERY MMC
C6 D0
D2 CMD
C12 CLK

pins are configurate as alternative 12

if i look the fatfs source, he set the card as 4 bit bus, so i tried also with 4bit configuration

DISCOVERY MMC
C9 D1
C10 D2
C11 D3

like this, the test routine stop on first test, if i switch C6 to C8, can't connect to card.
i'm disoriented, with fatfs MUST be 4 bit bus? if yes, what are the correct pins to use with usart6?
at the moment there are active only usb1/shell, all the other things are disabled
Jeroen3
Posts: 35
Joined: Wed Apr 02, 2014 10:14 am

Re: FATS f_getfree 0 clusters

Post by Jeroen3 »

Code: Select all

FATFS* fs;
f_getfree("0:", &freeClusters, &fs);

Works fine here. But, you'd need to call sdcStart, sdcConnect and f_mount (successfully) before f_getfree works.

You say you have an 8mb card, don't you mean 8 GB? If so, you're doing undefined stuff because the maximum size is 4 GB. Make sure your files stay below that boundary.
Why are you using an uart? Typically you'd use an SDIO or SPI to communicate with an SD card.
You haven't disabled _FS_NOFSINFO in the conf file, did you?
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: FATS f_getfree 0 clusters

Post by fastlink30 »

yes, i write wrong, 8gb is correct, but i have resized partition to 680mb (is the only partition, signed as active, no logical partition, fat32)
i write also usart, but is serial6, mistake, also serial must be defined becouse SDIO need it for functioning.

i not have _FS_NOFSINFO directive, is not included on the ffconf.h with the 0.9 patched shipped with chibios, i think is shipped with uGFX version of fatfs
at the moment i use fatfs from chibios to be sure all is working good, after i change to uGFX fatfs version.

i looked signal with oscilloscope, and i not see signal on d0-d3, but if i put probe on clk line, i can see signal on it, and can see if the sdcard is connected,
if i leave the probe from clk i can't connect to sd-card.
but i not understand, all the signal are with pull-up resistor. can be a problem the lenght of the cable? (sd-card <-> discovery) are only 10cm not much

thank you , you give me some more tips to follow
Jeroen3
Posts: 35
Joined: Wed Apr 02, 2014 10:14 am

Re: FATS f_getfree 0 clusters

Post by Jeroen3 »

I've looked into Chibios used here. (2.6)
But it seems you can only use the fatfs bindings with the SDCDriver, or the MMCDriver. Not Serial, not SPI.

Typically there is no pullup on the clk line. http://i.stack.imgur.com/abV6X.jpg (the transistor is optional, to be able to turn off the card)
Also, the EMI filters in the image above are often just some low ohm resistor arrays.

I doubt you are actually initializing the card properly.
Wat are the return codes of the following init functions?
- sdcStart
- sdcConnect
- f_mount
- f_getfree
- f_open(&fil, "test.txt", FA_CREATE_ALWAYS); followed by an immediate f_close(&fil); Just to make sure you can actually USE the card.

If you want, you can update fatfs to R0.10b without problems. The bindings do not require functional rework, only the type of one of the arguments require a touch. The warnings will tell you.
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: FATS f_getfree 0 clusters

Post by fastlink30 »

maybe i found something, before i have connection problem to sdcard, and many times on first try, fail

Code: Select all

    chprintf(chp, "Trying to connect SDIO... ");
    chThdSleepMilliseconds(100);

    if (!sdcConnect(&SDCD1))
    {
        chprintf(chp, "OK\r\n");
......


so, i decided to put on loop this routine:

Code: Select all

    chprintf(chp, "Trying to connect SDIO... ");
    chThdSleepMilliseconds(100);

    int trycnt=1;
    while (1)
    {
        if (!sdcConnect(&SDCD1))
        {
            chprintf(chp, "OK %d\r\n",trycnt);
            break;
        }
        trycnt++;
    }
[end]


and i get many different values for cnt (from 3 to 9, normally), so i change the code:

Code: Select all

    //chprintf(chp, "Trying to connect SDIO... ");
    chThdSleepMilliseconds(100);

    int trycnt=1;
    while (1)
    {
        if (!sdcConnect(&SDCD1))
        {
            //chprintf(chp, "OK %d\r\n",trycnt);
            break;
        }
        trycnt++;
    }

[end]


and unexpectedly everytime is 1 (correct!), so at this point i can presume that is 'bug' of usb routine (i use CDC) or i not know something to use usb with sdio?
on the examples code is mixed sdio with usb, so i think there are something different to consider.
also on terminal program i not see the string 'OK .....' when card is connected, but breakpoint already arrived to [end] (if the first chprintf is without //)
Post Reply