flash FDS writing operation is not happening

Hi team,

I am using NRF52833 DK with PCA10100 on it and s140 soft device version..

While writing data into the flash, it is not updating.

Here I am attaching my fds code:

/* File ID and Key used for the configuration record. */

#define CONFIG_FILE (0x8010)
#define CONFIG_REC_KEY (0x7010)

* A dummy structure to save in flash. */
typedef struct
{
uint32_t boot_count;
uint8_t device_name[16];
bool config1_on;
bool config2_on;
} configuration_t;

static char const * fds_evt_str[] =
{
"FDS_EVT_INIT",
"FDS_EVT_WRITE",
"FDS_EVT_UPDATE",
"FDS_EVT_DEL_RECORD",
"FDS_EVT_DEL_FILE",
"FDS_EVT_GC",
};

/* Dummy configuration data. */
static configuration_t m_dummy_cfg =
{
.config1_on = false,
.config2_on = true,
.boot_count = 0x0,
/*.device_name = "dummy",*/
};

/* A record containing dummy configuration data. */
static fds_record_t const m_dummy_record =
{
.file_id = CONFIG_FILE,
.key = CONFIG_REC_KEY,
.data.p_data = &m_dummy_cfg,
/* The length of a record is always expressed in 4-byte units (words). */
.data.length_words = (sizeof(m_dummy_cfg) + 3) / sizeof(uint32_t),
};

/* Keep track of the progress of a delete_all operation. */
static struct
{
bool delete_next; //!< Delete next record.
bool pending; //!< Waiting for an fds FDS_EVT_DEL_RECORD event, to delete the next record.
} m_delete_all;

/* Flag to check fds initialization. */
static bool volatile m_fds_initialized;


const char *fds_err_str(ret_code_t ret)
{
/* Array to map FDS return values to strings. */
static char const * err_str[] =
{
"FDS_ERR_OPERATION_TIMEOUT",
"FDS_ERR_NOT_INITIALIZED",
"FDS_ERR_UNALIGNED_ADDR",
"FDS_ERR_INVALID_ARG",
"FDS_ERR_NULL_ARG",
"FDS_ERR_NO_OPEN_RECORDS",
"FDS_ERR_NO_SPACE_IN_FLASH",
"FDS_ERR_NO_SPACE_IN_QUEUES",
"FDS_ERR_RECORD_TOO_LARGE",
"FDS_ERR_NOT_FOUND",
"FDS_ERR_NO_PAGES",
"FDS_ERR_USER_LIMIT_REACHED",
"FDS_ERR_CRC_CHECK_FAILED",
"FDS_ERR_BUSY",
"FDS_ERR_INTERNAL",
};

return err_str[ret - NRF_ERROR_FDS_ERR_BASE];
}

void fds_Init()
{
rc = fds_init();
APP_ERROR_CHECK(rc);

/* Wait for fds to initialize. */
// wait_for_fds_ready();

nrf_delay_ms(100);

//fds_stat_t stat = {0};

//rc = fds_stat(&stat);
//APP_ERROR_CHECK(rc);

//NRF_LOG_INFO("Found %d valid records.", stat.valid_records);
//NRF_LOG_INFO("Found %d dirty records (ready to be garbage collected).", stat.dirty_records);

}

uint8_t nus[16] = {0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}; /**< Used vendor specific UUID. */

void fds_Read()
{
rc = fds_init();
APP_ERROR_CHECK(rc);

/* Wait for fds to initialize. */
// wait_for_fds_ready();

nrf_delay_ms(100);

fds_stat_t stat = {0};

rc = fds_stat(&stat);
APP_ERROR_CHECK(rc);

NRF_LOG_INFO("Found %d valid records.", stat.valid_records);
NRF_LOG_INFO("Found %d dirty records (ready to be garbage collected).", stat.dirty_records);

NRF_LOG_INFO("Found %d pages avaiable", stat.pages_available);

fds_record_desc_t desc = {0};
fds_find_token_t tok = {0};

rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);

if (rc == NRF_SUCCESS)
{
/* A config file is in flash. Let's update it. */
fds_flash_record_t config = {0};

/* Open the record and read its contents. */
rc = fds_record_open(&desc, &config);
APP_ERROR_CHECK(rc);

/* Copy the configuration from flash into m_dummy_cfg. */
memcpy(&m_dummy_cfg, config.p_data, sizeof(configuration_t));


/* Close the record when done reading. */
rc = fds_record_close(&desc);
APP_ERROR_CHECK(rc);

if(m_dummy_cfg.device_name[0] == 0)
{
/*
m_dummy_cfg.device_name[0] = 0x9E;
m_dummy_cfg.device_name[1] = 0xCA;
m_dummy_cfg.device_name[2] = 0xDC;
m_dummy_cfg.device_name[3] = 0x24;
m_dummy_cfg.device_name[4] = 0x0E;
m_dummy_cfg.device_name[5] = 0xE5;
m_dummy_cfg.device_name[6] = 0xA9;
m_dummy_cfg.device_name[7] = 0xE0;
m_dummy_cfg.device_name[8] = 0x93;
m_dummy_cfg.device_name[9] = 0xF3;
m_dummy_cfg.device_name[10] = 0xA3;
m_dummy_cfg.device_name[11] = 0xB5;
m_dummy_cfg.device_name[12] = 0x00;
m_dummy_cfg.device_name[13] = 0x00;
m_dummy_cfg.device_name[14] = 0x40;
m_dummy_cfg.device_name[15] = 0x6E; */

/* m_dummy_cfg.device_name[0] = {0x9E,0xCA,0xDC,0x24};
m_dummy_cfg.device_name[1] = nus[1];
m_dummy_cfg.device_name[2] = nus[2];
m_dummy_cfg.device_name[3] = nus[3];

m_dummy_cfg.device_name[4] = nus[4];
m_dummy_cfg.device_name[5] = nus[5];
m_dummy_cfg.device_name[6] = nus[6];
m_dummy_cfg.device_name[7] = nus[7];
m_dummy_cfg.device_name[8] = nus[8];
m_dummy_cfg.device_name[9] = nus[9];
m_dummy_cfg.device_name[10] = nus[10];
m_dummy_cfg.device_name[11] = nus[11];
m_dummy_cfg.device_name[12] = nus[12];
m_dummy_cfg.device_name[13] = nus[13];
m_dummy_cfg.device_name[14] = nus[14];
m_dummy_cfg.device_name[15] = nus[15]; */

// strncpy(m_dummy_cfg.device_name, nus,16);

// memcpy(&m_dummy_cfg.device_name,nus,16);

for(uint8_t i = 0; i<16; i++)
{
m_dummy_cfg.device_name[i] = nus[i];

}

rc = fds_record_update(&desc, &m_dummy_record);
if ((rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH))
{
NRF_LOG_INFO("No space in flash, delete some records to update the config file.");
}
else
{
APP_ERROR_CHECK(rc);
}

//for(uint8_t i = 0; i<16; i++)
// {
// buff[i] = m_dummy_cfg.device_name[i];

// }

}


NRF_LOG_INFO("Config file found, updating boot count to %d.", m_dummy_cfg.boot_count);
}
/* Update boot count. */
//m_dummy_cfg.boot_count++;

// ntwid_flag = 1;

/* Close the record when done reading. */
// rc = fds_record_close(&desc);
// APP_ERROR_CHECK(rc);


//rc = fds_file_delete(CONFIG_FILE);
//APP_ERROR_CHECK(rc);

}

Please check and let me know if anything required.

Thanks and Regards,

Hareesh Gorle

Parents
  • Hi,

    How do you check that it is not updating? Do you get any error codes?

    FDS writes are asynchronous, meaning that the write is not necessarily completed when the write/update function returns. You need to implement the event handler and wait for the events indicating operation success before reading back the record. When using a Softdevice, the flash operations will be scheduled between BLE events and other Softdevice tasks.

    Best regards,
    Jørgen

Reply
  • Hi,

    How do you check that it is not updating? Do you get any error codes?

    FDS writes are asynchronous, meaning that the write is not necessarily completed when the write/update function returns. You need to implement the event handler and wait for the events indicating operation success before reading back the record. When using a Softdevice, the flash operations will be scheduled between BLE events and other Softdevice tasks.

    Best regards,
    Jørgen

Children
Related