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

Flash update

Hello

SDK ver 17

DK nRF52 DK

DK is a peripheral connected to many centrals. Every time I connect to a phone I get the messages attached in the picture.. My question: Is flash actually written every time a connection is established? message: "<info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update" I also use a workaround from nordic that checks if there is no change in CCCD and skips writing again. Message "Local db is up to date". I have also noticed with debug that there is a call in "nrf_fstorage_write(....) function. If flash is written over and over again when connected I am afraid it will be destoyed

Dimitris

Parents
  • DimitrisP said:
    Sorry but this is as far as I can go

     What do you mean?

    Try to set a breakpoint inside nrf_fstorage_write() to check the call stack to see where it is written from.

    I don't see any decision made by gscm_service_changed_ind_needed() that will trigger a flash directly, but it may be something using these flags (ble_conn_state_user_flag_set) to determine whether or not it needs to write to flash.

    My guess is that it updates whether or not it has notifyed the service changed service on each peer. Let me know:

    1: Is it every time you connect to a central? Or only if you connect to another central in between connects?

    2: Is it all the time, or only after you update your services (DFU or adding/removing services in your application development)?

    BR,

    Edvin

  • Hello

    I mean that it is difficult for me to understand all the stack from your excellent project

    Anyway you are right. The gscm_service_changed_ind_needed() does not trigger a flash write. If I set a breakpoint in nrf_fstorage_write() in the picture you can see the call stack. I still can't figure out what is triggering the write.

    I also noticed that in the PM_EVT_PEER_DATA_UPDATE_SUCCEEDED event ,p_evt->params.peer_data_update_succeeded.data_id = PM_PEER_DATA_ID_GATT_LOCAL with action PM_PEER_DATA_OP_UPDATE.

    Regarding your questions

    1. Yes every time
    2. I have not implemented yet DFU neither I add or remove services

    From the peer side I have not emplemented yet a change service characteristic. Do you think that might cause the issue?

    Dimitris

    After further investigation the flash write is triggered here

            case BLE_GATTS_EVT_WRITE:
            {
                /* Skip local db update if new CCCD setting is identical to the previous one */
                if (cccd_written(&p_ble_evt->evt.gatts_evt.params.write) &&
                   (local_db_needs_update(conn_handle))) 
                {
                    local_db_update(conn_handle, true);
                    update_pending_flags_check();
                }
                break;

    in the gatt_cashe_manager.c file where the peer's data are different from locals data base. So I guess the stack works as expected. Now why peer data are not the same is something else. I use a custom nus service with tx and Rx characteristics to send receive data to/from peer

  • Ok, so it is the pds_peer_data_store() that stores the data in flash, and in your case it is called from write_buf_store() called from gscm_local_db_chache_update() (I am just reading this from your call stack), called from db_update_pending_handle(), and so on. This all comes from the gcm_ble_evt_handler() in gatt_chache_manager() which calls update_pending_flags_check(). Try setting a breakpoint to determine whether or not it comes from the BLE_GATTS_EVT_WRITE event. If so, is this event caused by the central enabling notifications on one of the services? Have you tried commenting out this call to update_pending_flags_check() just to see how it behaves and if this is the one causing the updates.

    What is your central? Is it a mobile phone, or a custom nRF central?

     

    DimitrisP said:
    I have not implemented yet DFU neither I add or remove services

     Do you see this in your sdk_config.h:

    #define PM_SERVICE_CHANGED_ENABLED

    What is it set to?

  • Hello

    You are right the update comes from

            case BLE_GATTS_EVT_WRITE:
            {
                /* Skip local db update if new CCCD setting is identical to the previous one */
                if (cccd_written(&p_ble_evt->evt.gatts_evt.params.write) &&
                   (local_db_needs_update(conn_handle))) 
                {
                    local_db_update(conn_handle, true);
                    update_pending_flags_check();
                }
                break;
            }

    I have comment out as you suggested the call to the update_pending_flags_check(); and no flash updates anymore. I guess this is not the solution

    My sentral is a phone with a custom NUS service for receive and sending data, so I assume that it must enable notifications

    As I told you before all these are happening When

    PM_SERVICE_CHANGED_ENABLED 1 and

    NRF_SDH_BLE_SERVICE_CHANGED 1

    Ok my central (Phone) enables notifiations in order to exchange data. What I can not get is why every time after connection flash is updated? Am I missing something?

    Dimitris

  • Because the flash manager stores the state of the notifications. If the phone is bonded, then the notification status is stored, so that it doesn't need to enable notifications every time. Are you sure you need to enable the notifications when the devices are already bonded? What is your central? I know it is a phone, but are you using nRF Connect for Android/iOS, or is it a custom application?

    Have you tried to send notifications without enabling them when connecting to a bonded device? Does the phone receive the notifications?

    BR,
    Edvin

  • Hello

    My sentral is a custom NUS. If I use the UART app in nRF tool box the same hapens. If I only connect with nRF connect then there is no flash update but there is no data exchange. If I remove from phone app the

    mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);

    java code then there is no writing in flash but my phone can't read incoming data

    Dimitris

  • I am not familiar with the phone side of this, but I assume this line is from your mobile application, right?

    So if you remove this, then you don't get any notifications? But you have enabled notifications at one point, right? The first time you connected to it? And you didn't remove the bonding information since then?

    Just to be clear. The central needs to enable notifications at one point, but you don't need to do it every time you connect. The state of the notification (whether it is enabled or not) is stored in the bonding data.

    When "my phone can't read incoming data", what does it say on the nRF when you try to send the notificaiton? What does the sd_ble_gatts_hvx() return?

    BR,

    Edvin

Reply
  • I am not familiar with the phone side of this, but I assume this line is from your mobile application, right?

    So if you remove this, then you don't get any notifications? But you have enabled notifications at one point, right? The first time you connected to it? And you didn't remove the bonding information since then?

    Just to be clear. The central needs to enable notifications at one point, but you don't need to do it every time you connect. The state of the notification (whether it is enabled or not) is stored in the bonding data.

    When "my phone can't read incoming data", what does it say on the nRF when you try to send the notificaiton? What does the sd_ble_gatts_hvx() return?

    BR,

    Edvin

Children
No Data
Related