Hi,
I am saving data in flash memory but when I read after restarting the device it shows FF.
How can I read from flash after restarting the device? and how can I check that there is already data?
Thanks
Hi,
I am saving data in flash memory but when I read after restarting the device it shows FF.
How can I read from flash after restarting the device? and how can I check that there is already data?
Thanks
My initial guess is that you are not waiting for the read finished callback before you print what you have read. Can you share some code showing how you read the data? What are you using to read? Fstorage? FDS? I suggest you check out the examples flash_fstorage or flash_fds, depending on which one you use.
Best regards,
Edvin
Hi Edvin
I have written these 2 functions to read and write data in flash memory.
void write_in_flash(uint8_t place)
{
ret_code_t rc;
place=place*16;
sd_flash_page_erase(0x47);
rc = nrf_fstorage_write(&fstorage, flash_start_address+place, save_data, sizeof(save_data), NULL);
APP_ERROR_CHECK(rc);
wait_for_flash_ready(&fstorage);
NRF_LOG_INFO("Done.");
}
void read_in_flash(uint8_t place)
{
ret_code_t rc;
place=place*16;
rc = nrf_fstorage_read(&fstorage, flash_start_address+place, read_data, sizeof(save_data));
APP_ERROR_CHECK(rc);
NRF_LOG_INFO("Reading from flash hex:");
for(uint8_t i=0; i<sizeof(read_data); i++)
{
NRF_LOG_RAW_INFO("%02x:", read_data[i]);
}
NRF_LOG_RAW_INFO("\r\n");
NRF_LOG_INFO("done");
}void Charcteristics_10(uint8_t test)
{
NRF_LOG_INFO("Function Called");
save_data[0]=0x55;
save_data[1]=0x55;
write_in_flash(2);
read_in_flash(2);
if(test==10)
{
save_data[0]=0x55;
save_data[1]=0x55;
write_in_flash(2);
read_in_flash(2);
}
if(test==20)
{
read_in_flash(2);
}
}
Does any suggestion please?
Hi Edvin
I have written these 2 functions to read and write data in flash memory.
void write_in_flash(uint8_t place)
{
ret_code_t rc;
place=place*16;
sd_flash_page_erase(0x47);
rc = nrf_fstorage_write(&fstorage, flash_start_address+place, save_data, sizeof(save_data), NULL);
APP_ERROR_CHECK(rc);
wait_for_flash_ready(&fstorage);
NRF_LOG_INFO("Done.");
}
void read_in_flash(uint8_t place)
{
ret_code_t rc;
place=place*16;
rc = nrf_fstorage_read(&fstorage, flash_start_address+place, read_data, sizeof(save_data));
APP_ERROR_CHECK(rc);
NRF_LOG_INFO("Reading from flash hex:");
for(uint8_t i=0; i<sizeof(read_data); i++)
{
NRF_LOG_RAW_INFO("%02x:", read_data[i]);
}
NRF_LOG_RAW_INFO("\r\n");
NRF_LOG_INFO("done");
}void Charcteristics_10(uint8_t test)
{
NRF_LOG_INFO("Function Called");
save_data[0]=0x55;
save_data[1]=0x55;
write_in_flash(2);
read_in_flash(2);
if(test==10)
{
save_data[0]=0x55;
save_data[1]=0x55;
write_in_flash(2);
read_in_flash(2);
}
if(test==20)
{
read_in_flash(2);
}
}
Does any suggestion please?
So what do you observe? Have you tried to add a "wait_for_flash_ready(&fstorage);" in read_in_flash as well? What address do you use (flash_start_address)?
Wha do you write, and what do you read? Did you try to use "nrfjprog --memrd <addr>" to check what the flash actually reads after you have written to it?
So what do you observe? Have you tried to add a "wait_for_flash_ready(&fstorage);" in read_in_flash as well?
After connecting the device read/write didn't give any response.
What address do you use (flash_start_address)?
const uint32_t flash_start_address=0x47000;
const uint32_t flash_end_address=0x4ffff;
static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt);
NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
/* Set a handler for fstorage events. */
.evt_handler = fstorage_evt_handler,
/* These below are the boundaries of the flash space assigned to this instance of fstorage.
* You must set these manually, even at runtime, before nrf_fstorage_init() is called.
* The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
* last page of flash available to write data. */
.start_addr = flash_start_address,
.end_addr = flash_end_address,
};
Wha do you write, and what do you read?
I am trying to write this.
save_data[0]=0x55;
save_data[1]=0x55;
write_in_flash(2);
read_in_flash(2);
What I meant was what does NRF_LOG_RAW_INFO("%02x:", read_data[i]); print?
Did you try the nrfjprog --memrd 0x<the address you are writing to>.
Note that you change the address inside write_in_flash(). plac2 = 2*16 = 32, flash_start_address = 0x47000, actual address = 0x47032.
nrfjprog --memrd 0x047032 0x047020
what does that print?
Hi Edvin
Here is the output. When I call the same function before connection it saves and read data from memory BUT when I call the same function after connecting the device it not work.
How many bytes are you writing? And what values do you write? Remember that I don't know anything apart from what you have written here. How am I supposed to know what your log is supposed to write?
According to your snippets so far, the save_data[] array is two bytes long (but it doesn't say). And the values are {0x55, 0x55}.
This is what you read, but the save_data[] array looks like it is 8 bytes long.
Muqarrab said:BUT when I call the same function after connecting the device it not work.
So what do you read then? It seems you forgot to mention that in the log? Or do you not call the function after you have connected?