hi nordic Have a code project sample shows the typical use Flash applications in data storage? I see
[code](infocenter.nordicsemi.com/index.jsp.
my code
`
#define FILE_ID 0x1111
#define REC_KEY 0x2222
static void fds_evt_handler(ret_code_t result,
fds_cmd_id_t cmd,
fds_record_id_t record_id,
fds_record_key_t record_key)
{
// Handle events here
}
ret_code_t module_fds_register(void)
{
ret_code_t retval = fds_register(fds_evt_handler);
if(retval != NRF_SUCCESS)
{
// Registering of callback handler failed.
return retval;
}
retval = fds_init();
if (retval != NRF_SUCCESS)
{
// Error.
return retval;
}
return retval;
}
ret_code_t module_fds_write(uint32_t *p_data)
{
ret_code_t retval;
fds_record_key_t key;
fds_record_chunk_t chunk;
fds_record_desc_t descriptor;
// Fill in the record keys.
key.type = REC_KEY;
key.instance = FILE_ID;
// Initialize the record chunk, pointing it to the data to be stored.
chunk.p_data = p_data;
chunk.length_words = 1;
// Write the record to flash.
retval = fds_write(&descriptor,
key,
1 , /*number of chunks*/
&chunk);
if (retval != NRF_SUCCESS)
{
// Error.
}
return retval;
// The command was queued. Wait for a callback signalling its completion.
}
ret_code_t module_fds_read(uint32_t p_data ,fds_length_t length_words)
{
fds_type_id_t type;
fds_instance_id_t inst;
fds_find_token_t tok;
fds_record_desc_t descriptor;
fds_record_t record;
// Set the record keys.
type = REC_KEY;
inst = FILE_ID;
//SEGGER_RTT_printf(0, " module_fds_read\n");
// Loop until all records with the given key pair has been found.
if(fds_find(type, inst, &descriptor, &tok) == NRF_SUCCESS)
{
// A record was found. Open the record to check its contents.
fds_open(&descriptor, &record);
// Cast the data.
*p_data = (uint32_t)(*record.p_data);
// When you are done, close the record using its descriptor.
fds_close(&descriptor);
}
}
`
Writing down a record and Retrieving data is no SOME_VALUE.