Hi all,
I want save and read flash in example light switch proxy server .
I add code part of provisioner example into proxy server example
This is my code ;
#include "led_driver.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "nrf_drv_clock.h"
#include "nrf.h"
#include "device_state_manager.h"
#include "flash_manager.h"
#include "log.h"
#define FLASH_CUSTOM_DATA_GROUP_ELEMENT 0x1ABC // A number in the range 0x0000 - 0x7EFF (flash_manager.h)
#define CUSTOM_DATA_FLASH_PAGE_COUNT 1
flash_manager_t data_flash_manager; // flash manager instance
/* This function initialize flash which use when backup led's color */
flash_status initFlashManager(void)
{
uint32_t ret_code;
flash_manager_config_t flash_config;
flash_config.write_complete_cb = NULL;
flash_config.invalidate_complete_cb = NULL;
flash_config.remove_complete_cb = NULL;
flash_config.min_available_space = WORD_SIZE;
// The new instance of flash manager should use an unused region of flash:
flash_config.p_area = (const flash_manager_page_t *) (((const uint8_t *) dsm_flash_area_get()) - (ACCESS_FLASH_PAGE_COUNT * PAGE_SIZE) - (NET_FLASH_PAGE_COUNT * PAGE_SIZE) );
flash_config.page_count = CUSTOM_DATA_FLASH_PAGE_COUNT;
ret_code = flash_manager_add(&data_flash_manager, &flash_config);
if (NRF_SUCCESS != ret_code)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Flash error: no memory\r\n",ret_code);
return ERROR;
}
else
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "initFlashManagerForLed success\r\n",ret_code);
return OK;
}
}
flash_status backupByte(uint8_t byte)
{
// allocate flash
fm_entry_t * p_entry = flash_manager_entry_alloc(&data_flash_manager, FLASH_CUSTOM_DATA_GROUP_ELEMENT, sizeof(data_of_flash_t));
if (p_entry == NULL)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "backupByte() Error\r\n");
return ERROR;
}
data_of_flash_t * p_data = (data_of_flash_t *) p_entry->data;
p_data->data = byte;
// write DRGB to flash
flash_manager_entry_commit(p_entry);
// Wait for flash manager to finish.
flash_manager_wait();
return OK;
}
/* This function restore led's mode from flash */
uint8_t restoreByte(void)
{
const fm_entry_t * p_read_raw = flash_manager_entry_get(&data_flash_manager, FLASH_CUSTOM_DATA_GROUP_ELEMENT);
const data_of_flash_t * p_data = (const data_of_flash_t *) p_read_raw->data;
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "restoreByte() return %d\r\n", p_data->data);
return p_data->data;
}
void app_flash_manager_add(void)
{
flash_manager_config_t manager_config;
manager_config.write_complete_cb = NULL;
manager_config.invalidate_complete_cb = NULL;
manager_config.remove_complete_cb = NULL;
manager_config.min_available_space = WORD_SIZE;
manager_config.p_area = (const flash_manager_page_t *) (((const uint8_t *) dsm_flash_area_get()) - (ACCESS_FLASH_PAGE_COUNT * PAGE_SIZE * 2));
manager_config.page_count = CUSTOM_DATA_FLASH_PAGE_COUNT;
uint32_t status = flash_manager_add(&data_flash_manager, &manager_config);
if (NRF_SUCCESS != status)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_ERROR, "Unable to add flash manager for app data\n");
}
}
And in main. c , I call app_flash_manager_add() , but it appear hardFault in static inline bool metadata_is_valid(const flash_manager_metadata_t * p_metadata)
This is call stack :
Pls , help me , thank !!!