Hello,
I am trying to use the flash API of fstorage in my code. I have called below function at the start of my code. I want to save some integer values every 1 min interval.
Flash reading is working fine, but when writing was tried my whole code gets problem. When write api called debug messaged also doesn’t get print. I have included my c code for flash below. Kindly suggest what should be done.
Thank You.
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_ADDR, // 0x70ff0
.end_addr = FLASH_END_ADDR, // 0x80000
};
void Flash_init(void)
{
uint32_t data_1=5;
ret_code_t rc;
#ifdef FLASH_12
nrf_fstorage_api_t * p_fs_api;
/* Initialize an fstorage instance using the nrf_fstorage_sd backend.
* nrf_fstorage_sd uses the SoftDevice to write to flash. This implementation can safely be
* used whenever there is a SoftDevice, regardless of its status (enabled/disabled). */
p_fs_api = &nrf_fstorage_sd;
rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
APP_ERROR_CHECK(rc);
/* It is possible to set the start and end addresses of an fstorage instance at runtime.
* They can be set multiple times, should it be needed. The helper function below can
* be used to determine the last address on the last page of flash memory available to
* store data. */
// (void) nrf5_flash_end_addr_get();
// print_flash_info(&fstorage);
#ifdef UART_Flash
printf("Flash Init=%d\n",rc);
#endif
//
wait_for_flash_ready(&fstorage);
#endif
}
void Flash_Operation(void)
{
ret_code_t rc;
uint32_t local_var=0, data=5;
uint8_t len=0;
/***********************************Flash Read *****************************************/
#ifdef FLASH_12
wait_for_flash_ready(&fstorage);
// printf("Done.");
rc = nrf_fstorage_read(&fstorage, FLASH_START_ADDR, &local_var, sizeof(local_var));
APP_ERROR_CHECK(rc);
wait_for_flash_ready(&fstorage);
#ifdef UART_Flash
printf("local_var=%x , RC=%x \n",local_var,rc);
printf("Flash read Done.\n");
#endif
#endif
/***********************************Flash read end *****************************************/
/***********************************Flash write *****************************************/
rc = nrf_fstorage_erase(&fstorage, FLASH_START_ADDR , 1, NULL);
APP_ERROR_CHECK(rc);
wait_for_flash_ready(&fstorage);
rc = nrf_fstorage_write(&fstorage, FLASH_START_ADDR , &data, sizeof(data), NULL);
APP_ERROR_CHECK(rc);
wait_for_flash_ready(&fstorage);
#ifdef UART_Flash
printf("ERR code=%d,Flash write %x\n",rc,data);
#endif
/***********************************Flash write end *****************************************/
}