Hello
I use nrf52832 SDK14.2 for development, I copy the flash_fstorage example code to my project.
I write the data to flash doesn't have any error, and can read flash data successfully. But if I reboot and read the flash again the data is wrong.
Below is my code :
static void cmd_flash_write(nrf_cli_t const * p_cli, size_t argc, char **argv)
{
if (argc != 3 )
{
NRF_LOG_RAW_INFO("Invalid flash_write command\r\n");
return;
}
ret_code_t rc;
NRF_LOG_INFO("fstorage example started!");
nrf_fstorage_api_t * p_fs_api;
p_fs_api = &nrf_fstorage_sd;
rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
APP_ERROR_CHECK(rc);
print_flash_info(&fstorage);
uint32_t address_check = nrf5_flash_end_addr_get();
NRF_LOG_RAW_INFO("nrf5_flash_end_addr_get() = %d\r\n",address_check);
uint32_t reg[2];
reg[0] = strtol(argv[1], NULL, 16); //the flash address you want to write
reg[1] = strtol(argv[2], NULL, 16);//the data you want write
rc = nrf_fstorage_erase(&fstorage,reg[0],1,NULL);
APP_ERROR_CHECK(rc);
NRF_LOG_INFO("Writing \"%x\" to flash.", reg[1]);
rc = nrf_fstorage_write(&fstorage, reg[0], ®[1], sizeof(reg[1]), NULL);
APP_ERROR_CHECK(rc);
wait_for_flash_ready(&fstorage);
NRF_LOG_INFO("Done.");
}
NRF_CLI_CMD_REGISTER(flash_write, NULL, "flash_write Command.", cmd_flash_write);
static void cmd_flash_read(nrf_cli_t const * p_cli, size_t argc, char **argv)
{
if (argc != 2 )
{
NRF_LOG_RAW_INFO("Invalid flash_read command\r\n");
return;
}
uint32_t reg[1];
uint32_t m_data2;
reg[0] = strtol(argv[1], NULL, 16);
nrf_fstorage_read(&fstorage, reg[0],&m_data2,sizeof(m_data2));
NRF_LOG_INFO("Read \"%x\" to flash.\r\n", m_data2);
}
NRF_CLI_CMD_REGISTER(flash_read, NULL, "flash_read Command.", cmd_flash_read);
Write 0x11223344 to flash address 0x5e000 doesn't show error, and can read successful

But if I reboot, and read again. The data in flash address 0x5e000 is 0.

Anyone know why ?