SPI NOR FLASH with FatFS in nRF52832

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:

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.

Parents
  • Hi

    Is there a specific reason you're using FatFS instead of the standard SPI driver for the device you're using as an external flash? The FatFS module is rather old and contain a few bugs that are hard to do something about, and it will likely be much easier to use the SPI "as intended" instead of forcing a FatFS onto it. Is this a requirement for your project? If not I think it would save you a lot of sweat and tears to drop it.

    Best regards,

    Simon

  • Hi Simon! 

    We have an android application, where we create files and then send them via BLE from a GATT server (APP) to a GATT client (nRF52832).

    Our GATT Client is the nRF52832 chip, once the data is received by the GATT Client (Files), the nRF52832 has to store them in FLASH in the form of a file, since we need to be able to read, write and delete files.

    Is this a requirement for your project? 

    Yes, we need a filesystem that mounts to NOR FLASH properly, and FatFS seems like the best alternative. The fastest solution would be to use SD, but we want to optimize costs, and we are not going to use a lot of storage capacity (Not for now), we intend to use a NOR FLASH of 4MB and a maximum of 8MB.

    We have projects with USB and FATFS mounted on SPI NOR FLASH working properly with Microchip's PIC32MX family using the Harmony V3 framework, I tried migrating the code to nRF52832 but was unsuccessful, it doesn't work properly.

    What do you recommend? Thanks for your time.

    Best regards,

    Fernando

Reply
  • Hi Simon! 

    We have an android application, where we create files and then send them via BLE from a GATT server (APP) to a GATT client (nRF52832).

    Our GATT Client is the nRF52832 chip, once the data is received by the GATT Client (Files), the nRF52832 has to store them in FLASH in the form of a file, since we need to be able to read, write and delete files.

    Is this a requirement for your project? 

    Yes, we need a filesystem that mounts to NOR FLASH properly, and FatFS seems like the best alternative. The fastest solution would be to use SD, but we want to optimize costs, and we are not going to use a lot of storage capacity (Not for now), we intend to use a NOR FLASH of 4MB and a maximum of 8MB.

    We have projects with USB and FATFS mounted on SPI NOR FLASH working properly with Microchip's PIC32MX family using the Harmony V3 framework, I tried migrating the code to nRF52832 but was unsuccessful, it doesn't work properly.

    What do you recommend? Thanks for your time.

    Best regards,

    Fernando

Children
No Data
Related