NVS, SECURE FAULT

I am running into a secure fault when I set the NVS_SECTOR_COUNT to >= 7, 
not sure how to proceed.

it fails at nvs_mount(&fs)

#define MAX_RECORDS     400U
#define NVS_SECTOR_SIZE 4096U
#define NVS_SECTOR_COUNT 8U
#define NVS_TOTAL_SIZE NVS_SECTOR_SIZE*NVS_SECTOR_COUNT

/* NVS instance */
static struct nvs_fs fs;

/* Write and read pointers */
static size_t next_record_index = 1;
static size_t current_record_index = 0;

/* Temporary buffer for reads */
static record_t temp_record;

/* Mount NVS and recover next_record_index */
void record_buffer_init(void)
{
    fs.flash_device = FIXED_PARTITION_DEVICE(storage);
    fs.offset = FIXED_PARTITION_OFFSET(storage);
    fs.sector_size = NVS_SECTOR_SIZE;
    fs.sector_count = NVS_SECTOR_COUNT;

    int rc = nvs_mount(&fs);
    if (rc) {
        LOG_ERR("NVS mount failed: %d", rc);
        next_record_index = 1;
        return;
    }

    LOG_INF("NVS mounted at offset 0x%x, size %u bytes",fs.offset, fs.sector_size * fs.sector_count);
    LOG_INF("Max allowable record = %d", (NVS_TOTAL_SIZE/sizeof(record_t))-1);
    if (sizeof(record_t)*MAX_RECORDS > NVS_TOTAL_SIZE)
    {
        LOG_ERR("Max record %d > allowable record %d", MAX_RECORDS, (NVS_TOTAL_SIZE/sizeof(record_t) - 1));
    }

    /* Recover next_record_index */
    size_t highest = 0;
    record_t dummy;
    for (size_t key = 1; key <= MAX_RECORDS; key++) {
        rc = nvs_read(&fs, key, &dummy, sizeof(dummy));
        if (rc > 0) {
            highest = key;
        }
    }

    if (highest == 0) {
        next_record_index = 1;
    } else {
        next_record_index = (highest % MAX_RECORDS) + 1;
    }

    LOG_INF("Recovered next_record_index: %u", next_record_index);
}

I have added a nvs_storage partitation in pm_static.yml

# Reserve for NVS storage
nvs_storage:
   address: 0xE8000
   size: 0x18000        # Last 96 KB of 

memory map shows no overlap

Related