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

  • Hello,

    First, the FDS will make sure that the flash has an even "wear and tear". This means it will not use the same address over and over again. You can probably connect hundreds of times before you fill one page in the FDS (I have not tested this), and then depening on how many FDS pages you have, you don't need to do an erase before "all pages - 1" are full. When "all pages - 1" are full, it will do an erase, and that together will have spent one write erase cycle. So your flash is probably fine. 

    I am not completely sure, but I believe what the peer manager does is updating what device that was connected most recently. 

    Best regards,

    Edvin

  • Hello

    Even if you have a point, in my system a peripheral (nRF) will be connected with about 10 centrals (phones) Every central will make at list 40 connections and disconnections per day so that is why I am skeptic about flash writing. Now peer manager uses 7 pages.

    I am not using "ranking" so I think that it has nothing to do with "device most recently connected"

    When I set NRF_SDH_BLE_SERVICE_CHANGED=0 and PM_SERVICE_CHANGED_ENABLED=0 updating stops. My problem is that I find a good idea to use the service change option.

    So is there a workaround to avoid unnecessary writings in flash and in the same time I can use the service change option? (I mean if there is no change in data to be written with the existing)

    Dimitris

  • Try looking into the PM_EVT_BONDED_PEER_CONNECTED event, and see if you can figure out where it queues the FDS writes. 

    But I would try to check about how often you get the garbage collection (how often fds_gc() is called). How many connections/disconnections does it take before one fds_gc()?

  • Hello

    In gatt_cache_manager.c and if PM_SERVICE_CHANGED_ENABLED == 1 the function service_changed_needed(p_event->conn_handle) is called. There if the gscm_service_changed_ind_needed function returns true update in flash is triggered.

    bool gscm_service_changed_ind_needed(uint16_t conn_handle)
    {
        ret_code_t           err_code;
        bool                 service_changed_state;
        pm_peer_data_flash_t peer_data;

        peer_data.p_service_changed_pending = &service_changed_state;
        pm_peer_id_t peer_id = im_peer_id_get_by_conn_handle(conn_handle);

        err_code = pdb_peer_data_ptr_get(peer_id, PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING, &peer_data);

        if (err_code != NRF_SUCCESS)
        {
            return false;
        }

        return *peer_data.p_service_changed_pending;
    }

    Above is the code for the gscm_service_changed_ind_needed. That function return false if pdb_peer_data_ptr_get (....) !=  NRF_SUCCESS. or if *peer_data.p_service_changed_pending == false

    Sorry but this is as far as I can go

    Dimitris

  • 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

Related