void fs_evt_handler(nrf_fstorage_evt_t * p_evt) { printf("fs_evt_handler\r\n"); } NRF_FSTORAGE_DEF(nrf_fstorage_t m_instance) = { .evt_handler = fs_evt_handler, .start_addr = 0xFD000, .end_addr = 0xFFFFF, }; #define FLASH_ADDR 0xFC000 /* This is the data to write in flash. Because the fstorage interface is asynchrounous, the data must be kept in memory. */ void write_test(void) { static uint32_t number = 123; ret_code_t rc = nrf_fstorage_write( &m_instance, /* The instance to use. */ FLASH_ADDR, /* The address in flash where to store the data. */ &number, /* A pointer to the data. */ sizeof(number), /* Lenght of the data, in bytes. */ NULL /* Optional parameter, backend-dependent. */ ); if (rc == NRF_SUCCESS) { printf("write OK\r\n"); } else { printf("write fail\r\n"); } } void read_test(void) { /* This is the data to write in flash. Because the fstorage interface is asynchrounous, the data must be kept in memory. */ static uint32_t number = 0; ret_code_t rc = nrf_fstorage_read( &m_instance, /* The instance to use. */ FLASH_ADDR, /* The address in flash where to read data from. */ &number, /* A buffer to copy the data into. */ sizeof(number) /* Lenght of the data, in bytes. */ ); if (rc == NRF_SUCCESS) { printf("number=%d\r\n",number); } else { printf("read fail\r\n"); } } void erase_flash(void) { static uint32_t pages_to_erase = 1; ret_code_t rc = nrf_fstorage_erase( &m_instance, /* The instance to use. */ FLASH_ADDR, /* The address of the flash pages to erase. */ pages_to_erase, /* The number of pages to erase. */ NULL /* Optional parameter, backend-dependent. */ ); if (rc == NRF_SUCCESS) { printf("OK\r\n"); } else { printf("Erase fail\r\n"); } } int main() { timers_init(); uart_init(); ble_stack_init(); nrf_fstorage_init( &m_instance, /* You fstorage instance, previously defined. */ &nrf_fstorage_sd, /* Name of the backend. */ NULL /* Optional parameter, backend-dependant. */ ); erase_flash(); read_test(); write_test(); read_test(); }