This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

please review my flash write function

Dear Nordic guy,I'm developing with nrf51822 (6.0 stack binary and 5.0 SDK). I recently updated the code and stack binary(6.0 stack binary and 5.0 SDK). My function is not working well.I can't read and write. Please inspect my code.My developing environment is worse,so I can't debugging using debugger.


original hrs profile

// Module initialization routine to be called once by the application. uint32_t pstorage_init(void) { cmd_queue_init(); m_next_app_instance = 0; m_next_page_addr = PSTORAGE_DATA_START_ADDR; m_module_initialized = true;

for(unsigned int index = 0; index < PSTORAGE_MAX_APPLICATIONS; index++)
{
    m_app_table[index].cb = NULL;
    m_app_table[index].block_size = 0;
    m_app_table[index].no_of_pages = 0;
    m_app_table[index].block_count = 0;
}

#ifdef PSTORAGE_RAW_MODE_ENABLE m_raw_app_table.cb = NULL; m_raw_app_table.no_of_pages = 0; #endif //PSTORAGE_RAW_MODE_ENABLE return NRF_SUCCESS; }

bond_manager_init(){ ........... pstorage_init(); ...........

#if 1//add by me nv_init(); #endif }

add by me

#define MAX_DB_IN_WEEK 40

typedef struct { uint8_t medication_id[MAX_DB_IN_WEEK]; uint16_t year[MAX_DB_IN_WEEK]; uint8_t month[MAX_DB_IN_WEEK]; uint8_t day[MAX_DB_IN_WEEK]; uint8_t hours[MAX_DB_IN_WEEK]; uint8_t minutes[MAX_DB_IN_WEEK]; uint8_t taken_num[MAX_DB_IN_WEEK];//for the future } nv_info_data_t;

static void ans_pstorage_callback(pstorage_handle_t * handle, uint8_t op_code, uint32_t reason, uint8_t * p_data, uint32_t param_len) { }

uint32_t nv_init(void) {

uint32_t                err_code;
pstorage_module_param_t param;

param.block_size  = sizeof (nv_info_data_t) + sizeof (uint32_t);
param.block_count = 1;
param.cb          = ans_pstorage_callback;

// Register with storage module.
err_code = pstorage_register(&param, &m_nv_handle);

return err_code;

}

uint32_t nv_page_write(nv_info_data_t * p_message) { uint32_t err_code;

err_code = pstorage_store(&m_nv_handle,
                          (uint8_t *) p_message,
                         sizeof (nv_info_data_t),
                          0);
return err_code;

}

uint32_t nv_page_read(nv_info_data_t * p_message) {

uint32_t err_code;


err_code = pstorage_load((uint8_t *)p_message,
                         &m_nv_handle,
                         sizeof (nv_info_data_t),
                         0);

return err_code;

}

uint32_t nv_page_delete(void) { return pstorage_clear(&m_nv_handle, 0); }

Related