cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 sdhc 4GB problem

klaus-dieter
Associate
Posted on June 15, 2015 at 16:27

hi,

I'm using fatfs R0.11 on a stm32f4 for logging files on a SDhc card (sdio 4 bit): 32GB (16k cluster size).

Log files about 1MB/file.

Until a amount of 4GB of data (about 4600 files) all works perfect.

Now, if the recorded data past the 4GB limit and the SFN entry is the last entry of the last sector in the fat-table (see TF004606TXT), the fatfs stack wants to allocate a next chain of 32 sectors to continue the fat-table.

If this address for the next table is above 4GB, we don't get any more entries in the fat table for the next files.

I can see that the next files are physicaly recorded on the card (see TF004608.txt), but these files are not registered in the fat table. So they are invisible for the pc.

is there a limit for the table address at 4GB? A uint32 somewhere?

can someone help me with this issue?

#stm32f4 #fatfs #sdio
2 REPLIES 2
Posted on June 15, 2015 at 16:34

Not sure what the graphic is telling me.

A lot of the ST SDIO implementation use uint32_t BYTE Addressing, uint64_t on later iterations. The cards really need BLOCK Addressing, and that it's done throughly.

You'd need to look at the coding in DISKIO.C and however you've implemented your SDIO drivers below that.

Can't say I've played with how FatFs expands a FAT32 root directory.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
klaus-dieter
Associate
Posted on June 16, 2015 at 10:53

I found it out yesterday. 🙂 Until now I recorded about 000 files (about 18GB data).

The problem is in the ff.c

Let me explain short the attached graph:

I opened the volume with a hex-editor to see the content of the SD card.

The fatfs always reserves 32 sectors for the SFN entries.

In the graph you can see the last 32 sectors of the fat table below 4GB (sectors 8157504 - 8157536). This contains the SFN entries for the files TF004txt – TF0046txt. After this 32 sectors, the fatfs starts with the content of this 32*16 files. The size for this content depends on the size of all this files.

Because the SFN for the file TF0046txt is the last entry in the 32th sector, the system must expand the fat-table and reserve new 32 sectors for the next SFN entries. The place for this new sectors will be on the beginning of the next free sector (or cluster?). In the graph you can see that the fat table is continued at sector 9173344 for the next files (starts with file TF406txt).

And exactly here is the problem:

In the ff.c there is a function called: dir_next() with a parameter ''stretch''.

Each time this function is called, this parameter is always set to ''0'' = do not stretch table. In this case the complete fat-table can be located just in sectors below 4GB. If you read now the directory via fatfs, the last file will be TF0046txt (which is the last entry in the last sector).

To be able to expand the fat table above the 4GB limit, you must set the parameter to

1: Stretch table if needed

________________

Attachments :

forum.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0uR&d=%2Fa%2F0X0000000bfl%2FngppcnG9u.FoGpQMFHeYp1NFDhbq5rn7U.6u8Gm9QHQ&asPdf=false