This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF Mesh persistent data storage. Mesh config entry only?

Good day!

I need to save sensor configs in persistent storage. What is better to use for this purpose: flash manager from nRF Mesh SDK or fstorage from nRF SDK?

I tried flash manager:

Initialization:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static uint8_t bsec_state[FLASH_MANAGER_ENTRY_MAX_SIZE] = {0};
static uint32_t bsec_state_len;
#define FLASH_CUSTOM_DATA_GROUP_ELEMENT 0x1500 // A number in the range 0x0000 - 0x7EFF (flash_manager.h)
#define CUSTOM_DATA_FLASH_PAGE_COUNT (1)
static flash_manager_t m_custom_data_flash_manager;
static fm_entry_t *p_entry;
static bool bsec_mem_allocated = false;
static bool bsec_persistent_flash_init(void)
{
flash_manager_config_t custom_data_manager_config;
custom_data_manager_config.write_complete_cb = NULL;
custom_data_manager_config.invalidate_complete_cb = NULL;
custom_data_manager_config.remove_complete_cb = NULL;
custom_data_manager_config.min_available_space = WORD_SIZE;
// The new instance of flash manager should use an unused region of flash
mesh_config_backend_flash_usage_t tmp_f_usage;
mesh_config_backend_flash_usage_get(&tmp_f_usage);
//custom_data_manager_config.p_area = (const flash_manager_page_t *)((const uint8_t *)flash_manager_recovery_page_get() - (ACCESS_FLASH_PAGE_COUNT * PAGE_SIZE) - (DSM_FLASH_PAGE_COUNT * PAGE_SIZE));
//custom_data_manager_config.p_area = (const flash_manager_page_t *)flash_manager_recovery_page_get();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

As you can see commented lines 21 and 22 I tried different variants of initialization. Line 21 didn't work at all. Other lines starts fine and crashes while provisioning.

The questions are:

  1. What is better to use for this purpose: flash manager from nRF Mesh SDK or fstorage from nRF SDK?
  2. If Flash manager is prefered how to initialize it?
  3. How to check at startup that data was already stored?

nRF SDK for Mesh v 4.0, nRF SDK 16, nRF52840 (Linux, SeS)

UPD 24/04/20:

I've tried FDS solution. Fail.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static uint8_t bsec_state[FLASH_MANAGER_ENTRY_MAX_SIZE] = {0};
static uint32_t bsec_state_len = sizeof(bsec_state);
#define FLASH_CUSTOM_DATA_GROUP_ELEMENT 0x1500 // A number in the range 0x0000 - 0x7EFF (flash_manager.h)
#define CUSTOM_DATA_FLASH_PAGE_COUNT (1)
//static flash_manager_t m_custom_data_flash_manager;
//static fm_entry_t *p_entry;
static bool bsec_mem_allocated = false;
static uint8_t write_flag = 0;
static void my_fds_evt_handler(fds_evt_t const * const p_fds_evt)
{
switch (p_fds_evt->id)
{
case FDS_EVT_INIT:
if (p_fds_evt->result != NRF_SUCCESS)
{
// Initialization failed.
}
break;
case FDS_EVT_WRITE:
if (p_fds_evt->result == NRF_SUCCESS)
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

UPD 24/04/20

I increased this value in sdk_config.h #define FDS_VIRTUAL_PAGES 8 and application started... and crashed after about 15 minutes.

So question is still opened

UPD 25/05/20

Solution based on Mesh config entry is working! That's great! But now I have new question:

what is the proper way to store kind of blob, 512bytes for example represented as array?

My solution:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*** Save \ load state functions ***/
static uint32_t state_setter(mesh_config_entry_id_t id, const void * p_entry);
static void state_getter(mesh_config_entry_id_t id, void * p_entry);
#define LIB_STATE_FILE_ID 0x0220
MESH_CONFIG_FILE(m_state_file, LIB_STATE_FILE_ID, MESH_CONFIG_STRATEGY_CONTINUOUS);
enum
{
LIB_STATE_RECORD_1 = 0x0001,
LIB_STATE_RECORD_2,
LIB_STATE_RECORD_3,
LIB_STATE_RECORD_4,
LIB_STATE_RECORD_5,
LIB_STATE_RECORD_6,
LIB_STATE_RECORD_7,
LIB_STATE_RECORD_END
};
#define LIB_STATE_C1_ENTRY_ID MESH_CONFIG_ENTRY_ID(LIB_STATE_FILE_ID, LIB_STATE_RECORD_1)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX