cancel
Showing results for 
Search instead for 
Did you mean: 

I'm trying to use FATFS library with my SPI-Flash. How can I format it in a right way. I'm using 16Mb flash. W25q16. It has 64 Blocks, each Block has 8 sectors. Total 512 sectors, each sector has 16 pages, each page has 256 Byte.

MShafiee
Associate

I traced the code flow and I found that the SPI flash should be formatted.

I used an SD-Card and traced the code while it is mounted and knew that it searches in sector 0 for the record signature and the pointer to the partition sector. Then it reads the partition sector to get all information about the physical memory. My problem is that the SD-card has 512 Bytes per sector and 236 sectors per cluster while SPI-Flash sector size is 4096 Bytes and the block is 32 Kilo Bytes . When I edit the sector data to adequate my SPI-Flash the code calculates the total memory wrong. I want to know how can I edit these data to make the code controls the SPI-Flash successfully.

Also I want to know how to calculate the Root Directory Entry Size.

Thank you!!

2 REPLIES 2
KnarfB
Principal III

There are some remarks about porting FatFS here http://elm-chan.org/fsw/ff/doc/appnote.html#port as a starting point.

A direct mapping from FatFS to SPI flash has the disadvantage, that there is no wear-levelling layer involved. I.e. the first sectors containing the FAT (file allocation tables) etc. will change quite often when you write to a file and wear out the underlying flash cells. This may or may not be a critical point depending on your use case.

Use f_mkfs() to format the media, with the IOCTL in diskio.c setup to provide block counts.

Make the sector size the minimum erase size of the media unless you plan to micro-manage the deblocking yourself in diskio.c

Use of NOR media in this fashion is ill advised and very slow when writing. Chip level data storage is better done with eMMC.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..