<?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>nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/122378/nrf52840---device-reboots-when-ble-connection-is-terminated</link><description>I&amp;#39;m using a nRF52840 configured as Central and Peripheral, with nRF5_SDK 17.1.0 (I&amp;#39;m Not using Zephyr) for reading the Device Name from the Generic Service of a beacon. I&amp;#39;m already able to connect to the beacon GAP, discover the characteristic I need</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 03 Jul 2025 08:26:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/122378/nrf52840---device-reboots-when-ble-connection-is-terminated" /><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/541287?ContentTypeID=1</link><pubDate>Thu, 03 Jul 2025 08:26:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f84d5db-3168-41df-9916-9a77c5653b0b</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Ricardo,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ignoring critical errors does not seem&amp;nbsp;like a good way to go. If you just remove NVIC_SystemReset() and continue after critical error, we cannot make any guarantees that SoftDevice will work as expected.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Priyanka&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/541179?ContentTypeID=1</link><pubDate>Wed, 02 Jul 2025 13:08:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faebc0cc-57df-40f4-bbd7-98977cd91f70</guid><dc:creator>ricardo.oliveira</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;Thanks for taking time to analyze the code.&lt;/p&gt;
&lt;p&gt;So far what I did was redefine the __WEAK function that reboots the mcu, removing the&amp;nbsp;&lt;span&gt;NVIC_SystemReset().&lt;br /&gt;it works now, and it doesn&amp;#39;t hang or block the normal work of the mcu.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I also used it to print the error code and it has shown me 2 codes: Error 18 and Error 8.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Error 18 seems to be associated with advertising problems. I do use this code with a bigger app as central and peripheral, so it is in fact sending advertisement packets, but I didn&amp;#39;t get what is the conflict it may be happening between disconnecting the Gap and advertisement packets.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;About error 8 I honestly couldn&amp;#39;t understand what may be going on.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/541172?ContentTypeID=1</link><pubDate>Wed, 02 Jul 2025 12:48:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03aa4eb7-2052-44b4-97db-2fcc3b4c2b10</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Ricardo,&lt;/p&gt;
&lt;p&gt;May be removing of APP_ERROR_CHECK is not a good idea to find out what is wrong? It might be helpful to&amp;nbsp;do the opposite: add more error checks to find out why exactly it reboots. Can also replace all NVIC_SystemReset(); in error handling with for(;;){}; so it hangs instead of rebooting and then examine with debugger what exactly happens.&lt;/p&gt;
&lt;p&gt;Not sure what that &amp;quot;GATT queue&amp;quot; is, it&amp;#39;s not part of SoftDevice, probably some SDK module? In general, sd_ble_gap_disconnect() can be called any time and should just work.&lt;/p&gt;
&lt;p&gt;We went through your&amp;nbsp;app, can you make sure you don&amp;#39;t have buffer overflow here?&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;case BLE_GATTC_EVT_READ_RSP:&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;uint8_t lengthDataRead = p_ble_evt-&amp;gt;evt.gattc_evt.params.read_rsp.len;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; memcpy(BufferDataRead, p_ble_evt-&amp;gt;evt.gattc_evt.params.read_rsp.data, lengthDataRead);&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //EVERYTHING GOES FINE UNTIL HERE&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//BUT WHEN I TRY DO DISCONNECT IT, uC REBOOTS&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sd_ble_gap_disconnect(myConnHandle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Some examples set NRF_SDH_BLE_GATT_MAX_MTU_SIZE to high value, that may overflow 30 bytes they reserve in BufferDataRead.&lt;/p&gt;
&lt;p&gt;-Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/541033?ContentTypeID=1</link><pubDate>Tue, 01 Jul 2025 12:32:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0be2c6f-9f3b-461e-a188-f824c20eaa61</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Ricardo,&lt;/p&gt;
&lt;p&gt;I am discussing this internally and will get back to you. Please expect a slight delay as it is the summer holidays here in Norway.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/540038?ContentTypeID=1</link><pubDate>Fri, 20 Jun 2025 13:04:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e4d1276-85fb-48b3-800e-dca355770868</guid><dc:creator>ricardo.oliveira</dc:creator><description>&lt;p&gt;Hi there.&lt;/p&gt;
&lt;p&gt;Could you give an example of how I use the GATT queue? In the SDK examples code, they start the instance like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRF_BLE_GQ_DEF(m_ble_gatt_queue,                                        /**&amp;lt; BLE GATT Queue instance. */
               NRF_SDH_BLE_CENTRAL_LINK_COUNT,
               NRF_BLE_GQ_QUEUE_SIZE);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But I don&amp;#39;t know how to use that in the code, for instance, how can I queue the sd_ble_gattc_read() and sd_ble_gap_disconnect() so they don&amp;#39;t overlap?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/540031?ContentTypeID=1</link><pubDate>Fri, 20 Jun 2025 12:44:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f18cfc3-c3cf-4b85-be43-f4d03b47b6e2</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Ricardo,&lt;/p&gt;
&lt;p&gt;If you have removed all APP_ERROR_CHECK calls and still experience reboots, the cause is likely a hard fault or assert elsewhere, possibly due to improper GATT operation sequencing or missing required initialization (such as the GATT queue). Using the GATT queue&amp;nbsp;taht you mentioned&amp;nbsp;is&amp;nbsp;a good approach.&lt;/p&gt;
&lt;p&gt;In your case, you&amp;#39;re calling &lt;em&gt;sd_ble_gattc_read()&lt;/em&gt; immediately after discovery, and later calling &lt;em&gt;sd_ble_gap_disconnect()&lt;/em&gt;&amp;nbsp;so there is a chance that they&amp;nbsp;might overlap, especially if the beacon ends the connection suddenly. Without the GATT Queue, this can cause undefined behavior.&lt;/p&gt;
&lt;p&gt;-Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/539943?ContentTypeID=1</link><pubDate>Thu, 19 Jun 2025 22:14:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:826544be-f366-45e3-858e-a51bff0b2b12</guid><dc:creator>ricardo.oliveira</dc:creator><description>&lt;p&gt;Also I noticed in an exemple of NUS that they use&amp;nbsp;NRF_BLE_GQ_DEF&amp;nbsp;(BLE GATT Queue instance). Should I use it? If so, how can I do that?&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/539942?ContentTypeID=1</link><pubDate>Thu, 19 Jun 2025 22:09:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eac89e48-aeb1-468e-9883-88122f59ddb2</guid><dc:creator>ricardo.oliveira</dc:creator><description>&lt;p&gt;I removed all APP_ERROR_CHECK of the whole code and still it reboots.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Device Reboots when BLE connection is terminated</title><link>https://devzone.nordicsemi.com/thread/539840?ContentTypeID=1</link><pubDate>Thu, 19 Jun 2025 09:00:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5035ea30-42e4-4792-b1cf-f68cd322a1b8</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;SWD is usually&amp;nbsp;&lt;em&gt;required&lt;/em&gt; for production programming, I don&amp;#39;t see why you can&amp;#39;t use that here...?&lt;/p&gt;
&lt;p&gt;APP_ERROR_CHECK reboots the device by default when there is no debugger connected. I believe you can reconfigure the SDK to skip the checks. There was also a method to print out errors using your own custom function, but that is not 100% reliable in case of stack overflows.&lt;/p&gt;
&lt;p&gt;Probably simpler to port your code onto a DK board for testing the central stuff specifically.&lt;/p&gt;
&lt;p&gt;You also want to learn Zephyr ASAP, there is very little support for the old SDK versions from this point forward.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>