<?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>CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95084/cccd-change-not-written-to-flash-after-ble-write-server</link><description>Hello, 
 I am currently developing a firmware where I am acting as a server with nRF52840. 
 The protocol of my use case is: 
 
 Client is connecting to my device (server with bonding) 
 Client sets notification enabled (is written to flash by the server</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 03 Jan 2023 09:44:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95084/cccd-change-not-written-to-flash-after-ble-write-server" /><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/402919?ContentTypeID=1</link><pubDate>Tue, 03 Jan 2023 09:44:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cdcb9b6a-1c98-48ef-a9a5-b3afa63f1ad4</guid><dc:creator>KonstantinK</dc:creator><description>&lt;p&gt;UPDATE: I could solve my issue, I did something wrong with my ram management (start address and size). As well as a mistake with&amp;nbsp;sd_ble_gatts_value_set(). Thanks for your help and I am going to close this thread :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/402842?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 14:24:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80a087cd-aed9-49e7-9c0a-c04c6a8c17c5</guid><dc:creator>KonstantinK</dc:creator><description>&lt;p&gt;I changed the location of the characteristic to&amp;nbsp;&lt;span&gt;BLE_GATTS_VLOC_STACK and can add the 9 characteristics with size 510 bytes each with&amp;nbsp;sd_ble_gatts_characteristic_add and I can successfully read and notify from the characteristics. But as soon as I am writing to them, there is again the issue with bonding. When the size of each characteristic is 201 bytes, everythin works well. Are there any other limitations which I should take care of. Or am I fine with memory when&amp;nbsp;sd_ble_gatts_characteristic_add&amp;nbsp; returns NRF_SUCCESS for each characteristic. Or should I take care of something else, even tho&amp;nbsp;sd_ble_gatts_characteristic_add&amp;nbsp;returns NRF_SUCCESS? Thanks for the support&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/402787?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 10:54:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08027f36-6c18-4d78-aa7b-6438867c3aa0</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thanks. The max. table size is only limited by how much RAM you&amp;nbsp;have to spare.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/402786?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 10:52:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60a003d4-0597-49b2-aa6d-0959d15a59be</guid><dc:creator>KonstantinK</dc:creator><description>&lt;p&gt;Alright, I will try with&amp;nbsp;&lt;span&gt;BLE_GATTS_VLOC_STACK. Me too haha. Is there a maximum value for&amp;nbsp;NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE, except the limitation of the ram?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/402784?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 10:48:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b9654f8-6529-47d5-9718-d843a74a94e6</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Would you mind trying with&amp;nbsp;BLE_GATTS_VLOC_STACK instead?&amp;nbsp; The BLE_GATTS_VLOC_USER option was more relevant before when the attribute table size was not configurable.&amp;nbsp;&lt;/p&gt;
[quote userid="116619" url="~/f/nordic-q-a/95084/cccd-change-not-written-to-flash-after-ble-write-server/402765"]But as soon as I configure them with a size of 202 bytes, it is not working anymore. When I increase the&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE&amp;nbsp;to 1700 bytes for example it is also working with a size of 202 bytes each&lt;/span&gt;[/quote]
&lt;p&gt;I am surprised it helped to increase the&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE, to be honest. I would have expected the table size to remain unchanged since the attribute values are kept in the application memory.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/402765?ContentTypeID=1</link><pubDate>Mon, 02 Jan 2023 09:24:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5375fce-f2e9-4785-ad36-0d02130c71ae</guid><dc:creator>KonstantinK</dc:creator><description>&lt;p&gt;Hello, thanks for your answer. I did some more research and debugging and discovered following:&lt;/p&gt;
&lt;p&gt;I have 9 characteristic with a size of 510 bytes each. I have configured them with&amp;nbsp;BLE_GATTS_VLOC_USER and it is not working (initializing and advertising works but writing to the characteristic causes problems with bonding data). When I configure them with a size of 201 bytes each (with NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1608), everything works fine (initializing, advertising and writing+bonding works). But as soon as I configure them with a size of 202 bytes, it is not working anymore. When I increase the&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE&amp;nbsp;to 1700 bytes for example it is also working with a size of 202 bytes each. So the issue should be somewhere with my memory management and the size of&amp;nbsp;NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE. My question is, when I am using the&amp;nbsp;BLE_GATTS_VLOC_USER&amp;nbsp;flag, why is the size of the characteristic still depending on the softdevice stack? And which&amp;nbsp;NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE should i use for using such long characteristics?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your help&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;best regards&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/402286?ContentTypeID=1</link><pubDate>Tue, 27 Dec 2022 13:14:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:957c9ad3-03fe-405f-8d5e-5e77de23943f</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;It sounds like the bonding data is being erased on disconnect for some reason. It could be because the FDS storage is full as you indicated earlier and that&amp;nbsp;&amp;nbsp;&lt;a title="pm_handler_flash_clean" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__pm__handler.html?cp=8_1_6_2_16_2_2#ga143031c4ec929f76d406f5c7c40dcb8a"&gt;pm_handler_flash_clean&lt;/a&gt;()/&lt;a title="pm_handler_flash_clean_on_return" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__pm__handler.html?cp=8_1_6_2_16_2_3#ga3519c41daa6b593307c294945214e7fb"&gt;pm_handler_flash_clean_on_return&lt;/a&gt;() is called. Or do you see the same if you do a full chip erase before you program your FW?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;FDS usage can be monitored with the&amp;nbsp;&lt;a title="fds_stat" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__fds.html?cp=8_1_6_10_18_31#ga5d3f04e9755408293408be377f7eeaf9"&gt;fds_stat&lt;/a&gt;() function.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/401981?ContentTypeID=1</link><pubDate>Thu, 22 Dec 2022 15:23:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44f38986-add2-4792-ac27-753c9b3a39c8</guid><dc:creator>KonstantinK</dc:creator><description>&lt;p&gt;Edit: After more debugging I discovered following:&lt;/p&gt;
&lt;p&gt;1. First connect (everything works and central and peripheral are bonded)&lt;/p&gt;
&lt;p&gt;2. Writing to a characteristic (&lt;span&gt;BLE_GATTS_EVT_WRITE occurred and value is written to characteristic&lt;/span&gt;)&lt;/p&gt;
&lt;p&gt;3. Disconnecting&lt;/p&gt;
&lt;p&gt;4. Reconnecting (Device is not recognized as peer and is doing rebonding)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Note: If I am doing the steps 1., 3. and 4. Device is recognized as already bonded peer&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any ideas where the issue might be?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/401960?ContentTypeID=1</link><pubDate>Thu, 22 Dec 2022 14:15:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4009e558-251c-47ac-94bd-abb699d34b25</guid><dc:creator>KonstantinK</dc:creator><description>&lt;p&gt;My connection parameters are:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;MIN_CONN_INTERVAL                   MSEC_TO_UNITS(100, UNIT_1_25_MS)
MAX_CONN_INTERVAL                   MSEC_TO_UNITS(200, UNIT_1_25_MS)        
SLAVE_LATENCY                       0                                       
CONN_SUP_TIMEOUT                    MSEC_TO_UNITS(4000, UNIT_10_MS)    &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Are these values good to go or should I use other?&lt;/p&gt;
&lt;p&gt;Yes, the updating of CCCD values is not correct. The new value gets written to the CCCD but the new value is not stored to flash. (when doing a write on a characteristic before). Have you ever experienced something like this before?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/401912?ContentTypeID=1</link><pubDate>Thu, 22 Dec 2022 12:24:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a2cac43-47d4-4ad6-b669-acdb1972b939</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Oh, sorry. I thought you were using NCS, not the nRF5 SDK. Never mind what I said in the previous reply then.&lt;/p&gt;
[quote user="KonstantinK"]But after that, nothing is written to flash and this only after I did a write to characteristic 1 before[/quote]
&lt;p&gt;What connection parameters are you using? Does it work with one of the examples that use bonding by default in the SDK if you test?&lt;/p&gt;
&lt;p&gt;And what exactly is it that is not working? Updating the CCCD value that is stored in flash?&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><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/401896?ContentTypeID=1</link><pubDate>Thu, 22 Dec 2022 11:50:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2beaaba-bcae-4b57-8d56-c117af8b4b8d</guid><dc:creator>KonstantinK</dc:creator><description>&lt;p&gt;Thanks for the reply. After I want to disable notification I am disconnecting from the device. So there is no poweroff or something like that.&lt;/p&gt;
&lt;p&gt;I did some debugging and discovered that when I first write something to characteristic 1, and I want to enable/disable characteristic 2. I get the event that something is written to UUID 0x2902 (as BLE_GATTS_EVT_WRITE indicates) but afterwards there is nothing written to flash. When I am not writting to characteristic 1 in the first place, everything works fine with enabling/disabling notification on characteristic 2. Might there be a problem with memory size somehow? Since characteristic 1 has a size of 510 bytes..? I did some debugging in the peer manager as well and I reach this function in the gatt_cache_manager.c with correct parameters:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;case BLE_GATTS_EVT_WRITE:
            if (cccd_written(&amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write))
            {
                local_db_update(conn_handle, true);
                update_pending_flags_check();
            }
            break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But after that, nothing is written to flash and this only after I did a write to characteristic 1 before. Might there be a chance that I am blocking the fds module somehow when I receive the write event in the first place form characteristic 1?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your help&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CCCD change not written to flash after BLE Write (Server)</title><link>https://devzone.nordicsemi.com/thread/401890?ContentTypeID=1</link><pubDate>Thu, 22 Dec 2022 11:23:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f6c43c3-35b1-45ce-87c5-578801bd3f5e</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I am guessing that you are connecting, bonding, enabling notifications, and turning off the server/peripheral.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;By default, the CCCD values are stored after the disconnect event, but if you disconnect by turning off the power, then obviously, that will not happen.&lt;/p&gt;
&lt;p&gt;You can add this to your prj.conf file:&lt;/p&gt;
&lt;p&gt;CONFIG_BT_SETTINGS_CCC_STORE_ON_WRITE=y&lt;/p&gt;
&lt;p&gt;Which will cause it to store it at once instead. Please see the description of the config BT_SETTINGS_CCC_STORE_ON_WRITE from NCS\zephyr\subsys\bluetooth\host\Kconfig:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;config BT_SETTINGS_CCC_STORE_ON_WRITE
	bool &amp;quot;Store CCC value immediately after it has been written&amp;quot;
	depends on BT_CONN
	default y
	help
	  Store Client Configuration Characteristic value right after it has
	  been updated. If the option is disabled, the CCC is only stored on
	  disconnection.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Try that, and see if it helps.&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>