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

pstorage_handle_t is lost in BLE NUS data event

why m_storageHandle_DeviceName became to 0xFFFFFFFF, its value was init by pstorage_register when app startup, but here it lost value. Can anybody help me ?

// event on receiving data from ble uart service
static void on_nus_data_evt(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
    uint32_t err_code = 0;
    if (p_data != NULL && length > 0)
    {
        err = pstorage_clear( & m_storageHandle_DeviceName, 
                                       DEVICE_NAME_LENGTH*4);
	APP_ERROR_CHECK(err);
    }
}
  • code.txt

    // main.c

    static ble_nus_t m_nus; static ble_nus_init_t m_nus_init; static pstorage_handle_t m_storageHandle_DeviceName;

    static void on_nus_data_evt(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) { uint32_t err_code = 0;

    if (p_data != NULL && length > 0)
    {
        pstorage_handle_t blockHandle;
    err_code = pstorage_block_identifier_get(&m_storageHandle_DeviceName, 0, &blockHandle);
    APP_ERROR_CHECK(err_code);
    }
    

    }

    static void bond_manager_init(void) { uint32_t err_code; ble_bondmngr_init_t bond_init_data; bool bonds_delete;

    err_code = pstorage_init();
    APP_ERROR_CHECK(err_code);
    
    err_code = app_button_is_pushed(SIGNAL_ALERT_BUTTON, &bonds_delete);
    APP_ERROR_CHECK(err_code);
    
    bond_init_data.flash_page_num_bond     = FLASH_PAGE_BOND;
    bond_init_data.flash_page_num_sys_attr = FLASH_PAGE_SYS_ATTR;
    bond_init_data.evt_handler             = NULL;
    bond_init_data.error_handler           = bond_manager_error_handler;
    bond_init_data.bonds_delete            = bonds_delete;
    err_code = ble_bondmngr_init(&bond_init_data);
    APP_ERROR_CHECK(err_code);
    

    }

    static void gap_params_init(void) { uint32_t err_code; ble_gap_conn_params_t gap_conn_params; ble_gap_conn_sec_mode_t sec_mode;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
    	
    pstorage_module_param_t param;
    param.block_count = 1;
    param.block_size = 8*4;
    param.cb = on_pstorage_deviceName_evtHandler;
    err_code = pstorage_register(&param, &m_storageHandle_DeviceName);
    APP_ERROR_CHECK(err_code);
    
    	
    static uint8_t devName[DEVICE_NAME_LENGTH]__attribute__((aligned(4))) = {0};	
    GET_DEVICE_NAME(devName);	
    err_code = sd_ble_gap_device_name_set(&sec_mode, (uint8_t *)devName, DEVICE_NAME_LENGTH);
    APP_ERROR_CHECK(err_code);
    
    
    err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_KEYRING);
    APP_ERROR_CHECK(err_code);
    
    memset(&gap_conn_params, 0, sizeof(gap_conn_params));
    
    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
    gap_conn_params.slave_latency     = SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;
    
    
    err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
    APP_ERROR_CHECK(err_code);
    
    
    err_code = sd_ble_gap_tx_power_set(TX_POWER_LEVEL);
    APP_ERROR_CHECK(err_code);
    

    }

    static void nus_init(void) { uint32_t err_code;

    memset(&m_nus_init, 0, sizeof(m_nus_init));
    m_nus_init.data_handler = on_nus_data_evt;
    
    err_code = ble_nus_init(&m_nus, &m_nus_init);
    APP_ERROR_CHECK(err_code);
    

    }

    int main(void) { ble_stack_init();

    bond_manager_init();
    gap_params_init();
    advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE);
    	
    nus_init();
    
    conn_params_init();
    sec_params_init();
    
    advertising_start();
    	
    for (;;)
    {
        uint32_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
    }
    

    }

  • It's 0xFFFFFFFF before calling pstorage_clear().

  • So after

    err_code = pstorage_register(&param, &m_storageHandle_DeviceName);
    

    It's not 0xFFFFFFFF and in on_nus_data_evt() callback it's 0xFFFFFFFF?

    Then try to follow your code and check m_storageHandle_DeviceName value in your code to identify where does it corrupt:

    if (m_storageHandle_DeviceName == 0xFFFFFFFF) {led_on(); while(1);}
    

    First place if after:

    err_code = pstorage_register(&param, &m_storageHandle_DeviceName);
    

    then after:

    gap_params_init();
    

    and etc.

  • thanks, i am trying.

  • I find that the m_storageHandle_DeviceName currupt after pstorage_load().

    static uint8_t devName[DEVICE_NAME_LENGTH]attribute((aligned(4))) = {0}; pstorage_handle_t blockHandle; pstorage_block_identifier_get(&m_storageHandle_DeviceName, 0, &blockHandle); pstorage_load(devName, &blockHandle, DEVICE_NAME_LENGTH*4, 0);

Related