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

pstorage_clear or dm_device_delete_all is not working?

  • Custom Board with MCU NordicSemi nRF51822-QFAA

  • Softdevice S110 7.1

  • IAR for ARM 7.1

  • SDK 7.2 using a merged service (HID keyboard example + NUS example + HRS example)

  • Testing with iPhone 5S, 6 and iPad air (iOS 8.1.3)

/ Nexus 5 and Galaxy Note 3 (Android 4.4.2).

/****************************************************************************/

I added codes in device_manager_peripheral.c

void dm_ble_evt_handler(ble_evt_t * p_ble_evt){ //skipping to the changed part

   case BLE_GAP_EVT_AUTH_STATUS:
      if (p_ble_evt->evt.gap_evt.params.auth_status.auth_status != BLE_GAP_SEC_STATUS_SUCCESS){
            event_result = p_ble_evt->evt.gap_evt.params.auth_status.auth_status;
      }

      else{
 
         if ((m_connection_table[index].state & STATE_LINK_ENCRYPTED) ==
                STATE_LINK_ENCRYPTED)
            {
                m_connection_table[index].state |= STATE_BONDED;

                if (m_connection_table[index].bonded_dev_id == DM_INVALID_ID)
                {
                    //Assign a peer index as a new bond or update existing bonds.
                    err_code = device_instance_allocate((uint8_t *)&device_index,
                                                        &m_connection_table[index].peer_addr);
                    //Allocation successful.
                    if (err_code == NRF_SUCCESS)
                    { /*...*/}

                    else
                    {
                        event_result = err_code;

                        // my added part
                        if(err_code == DM_DEVICE_CONTEXT_FULL){
                            err_code = pstorage_clear(&m_storage_handle,
                                                      (ALL_CONTEXT_SIZE * DEVICE_MANAGER_MAX_BONDS));
                            //err_code = dm_device_delete_all(m_handle_pointer);
                            //m_handle_pointer is an extern variable pointing m_app_handle in main.c
                            
                        }
                    }
                }

The code's content is if the number of bonds reaches DEVICE_MANAGER_MAX_BONDS,

it will delete every bond infos.

Although the example code is implemented to erase all bonds when

BOND_DELETE_BUTTON_ID is pressed before initializing variables, I want to erase all bonds

automatically regardless of the button press.

I tried both pstorage_clear and dm_device_delete_all.

Even though both returned err_code 0 (NRF_SUCCESS),

it seems that the flash hasn't been cleared.

After the number of bonds reaches DEVICE_MANAGER_MAX_BONDS and calls these functions,

nothing happens.

Is there something that I'm missing?

Does these functions returning NRF_SUCCESS has relations with

DM_EVT_DEVICE_CONTEXT_DELETED (or other MACROS) or the scheduler?

Edited : About callback

I'm debugging with J-link.

image description

I set a break point here. After I call pstorage_clear, however, it doesn't

call dm_pstorage_cb_handler.

What could be the problem? Or did I misunderstand about "getting the callback from pstorage"?

-Regards, Mango922

Parents Reply Children
No Data
Related