|
NRF52832使用SDK12.3,使用库中的FDS功能,参照SDK15.0官方FDS例程,出现以下问题,百思不得其解...
首先定义record_chunk.length_words = 30,即打算写入30个字节到FLASH,其次设m_data_record.data.num_chunks = 1;然后使用fds_record_write函数写入30个数据,回调函数观察到写入成功,此时使设备进入睡眠状态,一会后再唤醒,然后用fds_record_find找到记录,再用fds_record_open打开并读取,这时读回来的前14个是正常数据,后16个全为0,请问这应该从哪几方面入手确认?
写函数:
ret_code_t data_write(uint32_t index,uint32_t file_id,uint32_t record_id,int16_t *data,uint32_t length_words)
{
ret_code_t rc;
fds_record_chunk_t record_chunk;
if(index > 3){
return FDS_ERR_INVALID_ARG;
}
if(length_words > 3000){
return FDS_ERR_INVALID_ARG;
}
if(data == NULL){
return FDS_ERR_INVALID_ARG;
}
record_chunk.p_data = data;
record_chunk.length_words = length_words;
m_data_record.file_id = file_id;
m_data_record.key = record_id;
m_data_record.data.p_chunks = &record_chunk;
m_data_record.data.num_chunks = 1;
rc = fds_record_write(NULL, &m_data_record);//D′¼Ç¼oíêy¾Y
APP_ERROR_CHECK(rc);
return rc;
}
读函数:
ret_code_t data_read(uint32_t index,uint32_t file_id,uint32_t record_id,int16_t *data,uint32_t *len)
{
ret_code_t rc;
fds_flash_record_t flash_record = {0};
//fds_record_desc_t record_desc;
//fds_find_token_t ftok;
if(data == NULL)return FDS_ERR_INVALID_ARG;
if(len == NULL)return FDS_ERR_INVALID_ARG;
if(index > 3)return FDS_ERR_INVALID_ARG;
memset(&tok, 0x00, sizeof(fds_find_token_t));
// Loop until all records with the given key and file ID have been found.
rc = fds_record_find(file_id, record_id, &desc, &tok);// == FDS_SUCCESS
if(rc == FDS_SUCCESS){
rc = fds_record_open(&desc, &flash_record);
APP_ERROR_CHECK(rc);
//data = (int16_t *)flash_record.p_data;
*len = flash_record.p_header->tl.length_words;
memcpy(data, (int16_t *)flash_record.p_data, flash_record.p_header->tl.length_words);
// Access the record through the flash_record structure.
// Close the record when done.
rc = fds_record_close(&desc);// != FDS_SUCCESS)
APP_ERROR_CHECK(rc);
// Handle error.
}else {
/* System config not found; write a new one. */
// rc = fds_record_write(&desc, &m_dummy_record);//ÖØDÂD′¼Ç¼
// APP_ERROR_CHECK(rc);
}
return rc;
}
|
|