<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Flash update</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/73343/flash-update</link><description>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: &amp;quot;&amp;lt;info</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 21 Apr 2021 09:03:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/73343/flash-update" /><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/306023?ContentTypeID=1</link><pubDate>Wed, 21 Apr 2021 09:03:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0dbffd6-ceb3-4fd1-bc04-e7994bca545a</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I am not familiar with the phone side of this, but I assume this line is from your mobile application, right?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So if you remove this, then you don&amp;#39;t get any notifications? But you have enabled notifications at one point, right? The first time you connected to it? And you didn&amp;#39;t remove the bonding information since then?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Just to be clear. The central needs to enable notifications at one point, but you don&amp;#39;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.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;When &amp;quot;my phone can&amp;#39;t read incoming data&amp;quot;, what does it say on the nRF when you try to send the notificaiton? What does the sd_ble_gatts_hvx() return?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/305990?ContentTypeID=1</link><pubDate>Wed, 21 Apr 2021 07:05:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07e35b93-20f8-40a3-8f87-09601d0ab497</guid><dc:creator>DimitrisP</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;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&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;java code then there is no writing in flash but my phone can&amp;#39;t read incoming data&lt;/p&gt;
&lt;p&gt;Dimitris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/305082?ContentTypeID=1</link><pubDate>Thu, 15 Apr 2021 11:58:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2d1f765-83c9-448d-9574-6bb1f60c3f63</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;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&amp;#39;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?&lt;/p&gt;
&lt;p&gt;Have you tried to send notifications without enabling them when connecting to a bonded device? Does the phone receive the notifications?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;br /&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/304116?ContentTypeID=1</link><pubDate>Sat, 10 Apr 2021 06:14:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0a12b9e-0bef-46e3-b603-a607344fcc41</guid><dc:creator>DimitrisP</dc:creator><description>&lt;p&gt;Hello &lt;/p&gt;
&lt;p&gt;You are right the update comes from&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        case BLE_GATTS_EVT_WRITE:
        {
            /* Skip local db update if new CCCD setting is identical to the previous one */
            if (cccd_written(&amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write) &amp;amp;&amp;amp;
               (local_db_needs_update(conn_handle))) 
            {
                local_db_update(conn_handle, true);
                update_pending_flags_check();
            }
            break;
        }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have comment out as you suggested the call to the&amp;nbsp;update_pending_flags_check(); and no flash updates anymore. I guess this is not the solution&lt;/p&gt;
&lt;p&gt;My sentral is a phone with a custom NUS service for receive and sending data, so I assume that it must enable notifications&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As I told you before all these are happening When&lt;/p&gt;
&lt;p&gt;PM_SERVICE_CHANGED_ENABLED 1 and&lt;/p&gt;
&lt;p&gt;NRF_SDH_BLE_SERVICE_CHANGED 1&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Dimitris&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/303209?ContentTypeID=1</link><pubDate>Tue, 06 Apr 2021 14:01:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:392800e8-b356-473a-9158-50e7412567c5</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;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&amp;nbsp;update_pending_flags_check() just to see how it behaves and if this is the one causing the updates.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What is your central? Is it a mobile phone, or a custom nRF central?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="DimitrisP"]I have not implemented yet DFU neither I add or remove services[/quote]
&lt;p&gt;&amp;nbsp;Do you see this in your sdk_config.h:&lt;/p&gt;
&lt;p&gt;#define PM_SERVICE_CHANGED_ENABLED&lt;/p&gt;
&lt;p&gt;What is it set to?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/302835?ContentTypeID=1</link><pubDate>Thu, 01 Apr 2021 07:44:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a50a7cf8-b1e7-4730-b94a-e709a2eeb1f8</guid><dc:creator>DimitrisP</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;I mean that it is difficult for me to understand all the stack from your excellent project&lt;/p&gt;
&lt;p&gt;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&amp;#39;t figure out what is triggering the write.&lt;/p&gt;
&lt;p&gt;I also noticed that in the&amp;nbsp;PM_EVT_PEER_DATA_UPDATE_SUCCEEDED event ,p_evt-&amp;gt;params.peer_data_update_succeeded.data_id = PM_PEER_DATA_ID_GATT_LOCAL with action PM_PEER_DATA_OP_UPDATE.&lt;/p&gt;
&lt;p&gt;Regarding your questions&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Yes every time&lt;/li&gt;
&lt;li&gt;I have not implemented yet DFU neither I add or remove services&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;From the peer side I have not emplemented yet a change service characteristic. Do you think that might cause the issue?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Dimitris&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/FlashWrite.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;After further investigation the flash write is triggered here&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        case BLE_GATTS_EVT_WRITE:
        {
            /* Skip local db update if new CCCD setting is identical to the previous one */
            if (cccd_written(&amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write) &amp;amp;&amp;amp;
               (local_db_needs_update(conn_handle))) 
            {
                local_db_update(conn_handle, true);
                update_pending_flags_check();
            }
            break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in the gatt_cashe_manager.c file where the peer&amp;#39;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&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/302730?ContentTypeID=1</link><pubDate>Wed, 31 Mar 2021 12:24:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:337203cb-9c22-4e88-ac0d-eab2009047fb</guid><dc:creator>Edvin</dc:creator><description>[quote user="DimitrisP"]Sorry but this is as far as I can go[/quote]
&lt;p&gt;&amp;nbsp;What do you mean?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Try to set a breakpoint inside nrf_fstorage_write() to check the call stack to see where it is written from.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;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.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My guess is that it updates whether or not it has notifyed the service changed service on each peer. Let me know:&lt;/p&gt;
&lt;p&gt;1: Is it every time you connect to a central? Or only if you connect to another central in between connects?&lt;/p&gt;
&lt;p&gt;2: Is it all the time, or only after you update your services (DFU or adding/removing services in your application development)?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/302637?ContentTypeID=1</link><pubDate>Tue, 30 Mar 2021 15:56:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:269c7986-a1a7-4171-9a09-6207dda6aece</guid><dc:creator>DimitrisP</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;In gatt_cache_manager.c and if PM_SERVICE_CHANGED_ENABLED == 1 the function service_changed_needed(p_event-&amp;gt;conn_handle) is called. There if the gscm_service_changed_ind_needed function returns true update in flash is triggered.&lt;/p&gt;
&lt;p&gt;bool gscm_service_changed_ind_needed(uint16_t conn_handle)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret_code_t&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; err_code;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; service_changed_state;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pm_peer_data_flash_t peer_data;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; peer_data.p_service_changed_pending = &amp;amp;service_changed_state;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pm_peer_id_t peer_id = im_peer_id_get_by_conn_handle(conn_handle);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; err_code = pdb_peer_data_ptr_get(peer_id, PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING, &amp;amp;peer_data);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (err_code != NRF_SUCCESS)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return *peer_data.p_service_changed_pending;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Above is the code for the gscm_service_changed_ind_needed. That function return false if&amp;nbsp;pdb_peer_data_ptr_get (....) !=&amp;nbsp; NRF_SUCCESS. or if *peer_data.p_service_changed_pending == false&lt;/p&gt;
&lt;p&gt;Sorry but this is as far as I can go&lt;/p&gt;
&lt;p&gt;Dimitris&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/302605?ContentTypeID=1</link><pubDate>Tue, 30 Mar 2021 13:39:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df065772-47b5-41c4-a016-f32f366ea84e</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Try looking into the&amp;nbsp;PM_EVT_BONDED_PEER_CONNECTED event, and see if you can figure out where it queues the FDS writes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;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()?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/302454?ContentTypeID=1</link><pubDate>Mon, 29 Mar 2021 17:29:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42c26494-b83e-40a3-a8ca-e561ee2614e7</guid><dc:creator>DimitrisP</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;I am not using &amp;quot;ranking&amp;quot; so I think that it has nothing to do with &amp;quot;device most recently connected&amp;quot;&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Dimitris&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash update</title><link>https://devzone.nordicsemi.com/thread/302378?ContentTypeID=1</link><pubDate>Mon, 29 Mar 2021 13:22:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:221bd7cc-cc1a-4e62-8e63-bbbd477f57fe</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;First, the FDS will make sure that the flash has an even &amp;quot;wear and tear&amp;quot;. 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&amp;#39;t need to do an erase before &amp;quot;all pages - 1&amp;quot; are full. When &amp;quot;all pages - 1&amp;quot; are full, it will do an erase, and that together will have spent one write erase cycle. So your flash is probably fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am not completely sure, but I believe what the peer manager does is updating what device that was connected most recently.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>