Hi everyone!
I am working on a project where I have to store files inside a FLASH coming from a GATT server, and be able to manage them through FAT in a GATT client. The part of sending and receiving data through BLE works correctly.
I am using the following Software/Hardware tools:
- nRF5_SDK_17.1.0
- nRF52832
- SPI NOR FLASH 32Mbit (4MB)- AT25DF041B
- Segger V5.70
- FatFS - http://elm-chan.org/fsw/ff/doc/getfree.html
- Windows 10 64 bits
Looking through the examples provided by the SDK, I find the following example:
...\nRF5_SDK_17.1.0\examples\peripheral\fatfs
This example incorporates the FAT but with an SD card. For my project I need to format the FAT on my SERIAL NOR FLASH and mount the volume.
Reading ChaN's FatFS documentation I need to make my own low level disk I/O layer, and make the connection to the FatFS module. Having said the above, I have already done my low-level disk I/O layer and the connection with the FatFS module but I am not getting the expected results. Before I continue, I'd like to check a few things in my project settings to make sure it's set up correctly.
AT25DF041B can be erased in sizes of 256B, 4KB, 32KB and 64KB. Reviewing the ffconfig.h file I find that:
#define FF_MIN_SS 4096 #define FF_MAX_SS 4096 /* This set of options configures the range of sector size to be supported. (512, / 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and / harddisk. But a larger value may be required for on-board flash memory and some / type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured / for variable sector size mode and disk_ioctl() function needs to implement / GET_SECTOR_SIZE command. */
1 .- Set the sector size to 4096 for FAT because it fits the erase sector in FLASH which is also 4096, is this setting correct?
In my code I mount the volume with f_mount, and in case of returning FR_NO_FILESYSTEM I proceed to format the FLASH WITH f_mkfs. Everything is going perfect up to that point, but when I get the free sectors with f_getfree or I want to write a file larger than 230KB the problems start.This means that the FLASH is not being formatted or mounted correctly.
2.- What I would expect from f_getfree would be the free clusters on the volume, in my case there is one sector per cluster (4096*1). So I would expect to get (1024 clusters - VBR) * 4096 bytes and this would result in a value close to 4,194,304 = 4 MB, is this true? FATFS *fs;
DWORD fre_clust, fre_sect, tot_sect;
/* Get volume information and free clusters of drive 1 */
res = f_getfree("1:", &fre_clust, &fs);
if (res) die(res);
/* Get total sectors and free sectors */
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
/* Print the free space (assuming 512 bytes/sector) */
printf("%10lu KiB total drive space.\n%10lu KiB available.\n", tot_sect / 2, fre_sect / 2);
If you have sample code that you can provide with SPI NOR FLASH and FATFS using nRF52832 I would greatly appreciate it.