nRF5340: FCB(Flash Circular Buffer) on external flash

Hi Support Team,

I want to use an external flash(2M byte) to store the sensor data in a 'circular overwrite' way. I now tried it with the FCB(Flash Circular Buffer) on nRF5340-DK.

On the external flash, I use the first sector as a control block and the other 511 sectors for FCB storage.

Could I ask several questions about it:
1. When init the FCB, the user needs to set fcb.f_sector_cnt and fcb.f_scratch_cnt. The f_scratch_cnt was described as scratch space for garbage collecting when FCB fills up. If my f_sector_cnt is 511, what's the suggested value of f_scratch_cnt? Will this value affect the rotation behavior of FCB? I hope to rotate only when reaching the end of the data sectors(The oldest sector will be overwritten only when there is no free sector, in a strict FIFO way).

2. In struct fcb, both f_sector_cnt and f_scratch_cnt are uint8_t type, so the maximum capacity is 1M byte(255 sectors, 4K byte per sector). I changed the f_sector_cnt from uint8_t to uint16_t to support 511 sectors. By now, the fcb_append works well, but I don't know if the fcb_rotate is also ok.

3. The fcb.f_sectors = fcb_instance_sectors, was defined as a big array and initialized as:

    #define SPI_FLASH_SECTOR_SIZE 4096
    #define FCB_SECTOR_COUNT 510
    #define FCB_SCRATCH_SECTOR_COUNT 10
    
    memset(fcb_instance_sectors, 0, sizeof(fcb_instance_sectors));
    for (int i = 0; i < FCB_SECTOR_COUNT; i++) {
        fcb_instance_sectors[i].fs_off = i * SPI_FLASH_SECTOR_SIZE;
        fcb_instance_sectors[i].fs_size = SPI_FLASH_SECTOR_SIZE;
    }

The big array consumed a lot of stack memory, is there any other better way to define the FCB sectors?

Thank you very much.

Best regards,
Yanpeng Wu

Parents Reply Children
No Data
Related