This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

data appending flash storage

Hello everyone,

I have trying to store my serial data in nrf52832 SDK15.2 fs flash storage i need to appending data one by one in same file. i have using fds_record_update() concet to appending data finaly i read file data using fds_record_open() this function only getting last updated data other data missing...???

How do i get all appending data get in single read function. please suggest any example code for appending one by one in nrf52 flash

Parents Reply Children
  • Hello,

    If you use fds_record_update() it will replace the old record with the new one, so either you need to read, append and write a new record with all the data that you wish to store, or alternatively write a new record, instead of updating the old one.

  • I already try this function fds_record_update().  Record ID increase every appending but  i was read overall data using this function fds_record_open(). I got last appending mac id only. other mac id missing. How can i get writing all mac id...???

    This is my example function

    struct {
      uint8_t value[1000];
    } __ALIGN(4) FS_data;
    
    bool Fs_write(const uint8_t *data, uint16_t len, uint16_t recordKey) {
    	fds_record_desc_t record_desc;
    	fds_find_token_t ftok = {0};
    	ret_code_t rc;
    
    	memcpy(&FS_data.value, data, len);
    	
    	if (fds_record_find(FILE_ID, recordKey, &record_desc, &ftok) == FDS_SUCCESS) {
            fds_record_t const rec = {
                .file_id           = DATA_STORE_FILE_ID,
                .key               = recordKey,
                .data.p_data       = &FS_data,
                .data.length_words = (len + sizeof(uint32_t)-1) / sizeof(uint32_t)
            };
    		rc = fds_record_update(&record_desc, &rec);
    		return (rc == FDS_SUCCESS);
    	}
    	else {
            fds_record_t const rec = {
                .file_id           = DATA_STORE_FILE_ID,
                .key               = recordKey,
                .data.p_data       = &FS_data,
                .data.length_words = (len + sizeof(uint32_t)-1) / sizeof(uint32_t)
            };
    		rc = fds_record_write(&record_desc, &rec);
    		return (rc == FDS_SUCCESS);
    	}
    }
    
    
    bool FS_read(uint16_t recordKey, fds_flash_record_t *flash_record) {
        fds_record_desc_t   record_desc = {0};
        fds_find_token_t    ftok = {0};
    
        memset(&ftok, 0x00, sizeof(fds_find_token_t));
    
        if (fds_record_find(FILE_ID, recordKey, &record_desc, &ftok) == FDS_SUCCESS) {
            if (fds_record_open(&record_desc, flash_record) == FDS_SUCCESS) {
                fds_record_close(&record_desc);
                return true;
            }
        }
    
        return false;
    }

  • Edvin said:
    If you use fds_record_update() it will replace the old record with the new one

     Yes. That is how it is intended to work. You have to use fds_record_write with a new record ID in order to add new data and keep the old one.

Related