<?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>Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/92582/fast-notifications-with-nrf5340-and-nrf-connect-sdk</link><description>Board: nRF5340dk 
 SDK version: v2.1.0 
 
 My goal is to transmit 240 bytes of data every 5 ms using GATT notifications and 1 Mb PHY. 
 In the attached sample, I have my dev kit set up to notify on a characteristic every 5 ms. The connection interval</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 30 Nov 2022 23:43:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/92582/fast-notifications-with-nrf5340-and-nrf-connect-sdk" /><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/398422?ContentTypeID=1</link><pubDate>Wed, 30 Nov 2022 23:43:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e80e388-5583-4987-a8bb-cc9bfbdaaa12</guid><dc:creator>Dumam</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;I&amp;#39;ve got the same problem as you, but with bt_gatt_write_without_response[_cb]()&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/94053/nrf5340-is-unable-to-trigger-rpmsg-ipc-transfer"&gt;nrf5340 is unable to trigger rpmsg(ipc) transfer&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Could you tell me how did you changed this call&lt;/p&gt;
&lt;p&gt;&lt;code&gt;return k_fifo_get(&amp;amp;free_tx, K_FOREVER);&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;So it stopped blocking?&lt;/p&gt;
&lt;div id="gtx-trans" style="left:239px;position:absolute;top:66px;"&gt;
&lt;div class="gtx-trans-icon"&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/397326?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2022 08:36:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76649225-74dd-4f92-a5ee-7fe242a2fbfd</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Actually, it points to the same place. I just navigated using VS Code, and there it pointed to&amp;nbsp;&lt;span&gt;ncs\nrf\subsys\bluetooth\rpc\client\bt_rpc_gatt_client.c. I should have checked the .map file.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I believe the reason I couldn&amp;#39;t reproduce it was that I just tried to call bt_nus_send() (bt_gatt_notify_cb()) directly from my main() function. I discussed this with a colleague, who recently had a similar case, which I think you should check out:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/93785/bt_gatt_notify-can-block-when-running-on-zephyr-workqueue"&gt;bt_gatt_notify() can block when running on Zephyr workqueue.&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It turns out that it is the workqueue itself locking up. SInce the bt_gatt_notify_cb() is queued by the workqueue, but the workqueue is also required to actually process your BLE queue, you can end up in a deadlock. I guess the takeaway is that you should call bt_gatt_notify from another thread, so where you actually are calling bt_gatt_notify_cb() from now, you should rather trigger a task in another thread, (either the main thread, or a completely separate thread), so that it doesn&amp;#39;t end up in a deadlock.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As it is now, this is currently a limitation in the Zephyr Bluetooth Host stack.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/397209?ContentTypeID=1</link><pubDate>Wed, 23 Nov 2022 14:42:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b62973f-2220-43b9-a606-7012c467da90</guid><dc:creator>Benno Trutmann</dc:creator><description>&lt;p&gt;Hi Edvin.&lt;/p&gt;
&lt;p&gt;In this case your stack configuration should be the same as mine. But then it is unclear to my why your code calls the bt_gatt_notify_cb() from bt_rpc_gatt_client.c and not from gatt.c.&lt;/p&gt;
&lt;p&gt;Can you verify in zephyr.map from where bt_gatt_notify_cb() is really linked?&lt;/p&gt;
&lt;p&gt;In my zephyr.map I see:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;.text.bt_gatt_notify_cb&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&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; 0x000478d0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0xe8 zephyr/subsys/bluetooth/host/libsubsys__bluetooth__host.a(gatt.c.obj)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&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; 0x000478d0&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; bt_gatt_notify_cb&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/396130?ContentTypeID=1</link><pubDate>Thu, 17 Nov 2022 08:29:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2f90afe-7a60-41a9-aa5c-9e0b9138ae10</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;For testing, I used the peripheral_uart sample found in ncs\nrf\samples\bluetooth\peripheral_uart.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;According to my build folders, CONFIG_BT_RPC is not set. I didn&amp;#39;t find any mentions of it in the autoconf.h, but searching for it in my build folder, these were all the hits:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1668673745652v1.png" alt=" " /&gt;&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: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/395335?ContentTypeID=1</link><pubDate>Fri, 11 Nov 2022 13:23:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ac2afa1-6837-4515-a9f5-8472a73b72e0</guid><dc:creator>Benno Trutmann</dc:creator><description>&lt;p&gt;Is it possible that you build your test code with CONFIG_BT_RPC=y &amp;quot;Bluetooth over RPC [EXPERIMENTAL]&amp;quot;?&lt;/p&gt;
&lt;p&gt;In this case I see inclusion of code from the &amp;quot;ncs\nrf\subsys\bluetooth\rpc&amp;#39; directory. My project does not set CONFIG_BT_RPC!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/395331?ContentTypeID=1</link><pubDate>Fri, 11 Nov 2022 13:07:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40e39fb6-372a-438f-9aa7-ac9fab50a772</guid><dc:creator>Benno Trutmann</dc:creator><description>&lt;p&gt;Hi Edvin.&lt;/p&gt;
&lt;p&gt;To quote the nRF Connect SDK documentation:&lt;/p&gt;
&lt;p&gt;&amp;quot;The SoftDevice Controller is implemented by Nordic Semiconductor. The Zephyr Bluetooth LE Controller is an open source Link Layer developed in &lt;a class="reference external" href="https://zephyrproject.org/"&gt;Zephyr&lt;/a&gt;, to which Nordic Semiconductor is a contributor.&lt;/p&gt;
&lt;p&gt;Both Link Layers integrate with the Zephyr Bluetooth Host, which completes the full Bluetooth LE protocol stack solution in the nRF Connect SDK. It is possible to select either Bluetooth LE Controller for application development. See &lt;a class="reference internal" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.1/nrf/ug_ble_controller.html#usage-in-samples"&gt;Usage in samples&lt;/a&gt; for more information.&amp;quot;&lt;/p&gt;
&lt;p&gt;So with both controllers the Zephyr Bluetooth Host is used, the code for this host is contained in the &amp;#39;zephyr-ncs\subsys\bluetooth\host&amp;#39; directory. And there bt_gatt_notify_cb() is implemented in gatt.c and calls indirectly conn_tx_alloc() from conn.c in the same directory.&lt;/p&gt;
&lt;p&gt;For me it is unclear why you cannot see this call stack in your tests. You mention the function bt_gatt_notify_cb() from &amp;quot;ncs\nrf\subsys\bluetooth\rpc\client\bt_rpc_gatt_client.c&amp;quot;, but I don&amp;#39;t think this is part of the Zephyr Bluetooth Host.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Benno&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/395267?ContentTypeID=1</link><pubDate>Fri, 11 Nov 2022 09:45:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a77c653-145d-49a2-9cf8-8349b6ae1e0b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Benno,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you please explain what you mean by &amp;quot;configuration with the Zephyr Host and the Softdevice Controller&amp;quot;? How do you set the Zephyr Host when you are using the SoftDevice Controller?&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: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394912?ContentTypeID=1</link><pubDate>Wed, 09 Nov 2022 12:50:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e79fe2b0-4510-411c-9c0d-472692b8d31b</guid><dc:creator>Benno Trutmann</dc:creator><description>&lt;p&gt;Hi Edvin.&lt;/p&gt;
&lt;p&gt;I have no sample code at hand to demonstrate the blocking behavior. At the moment I also have no time to build one.&lt;/p&gt;
&lt;p&gt;Are your tests based on a configuration with the Zephyr Host and the Softdevice Controller as in my case?&lt;/p&gt;
&lt;p&gt;By the way: I use the version 2.1.1 of the Connect SDK.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Benno&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394384?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2022 11:23:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e742e037-51c2-4a39-aac4-8516052e39c4</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Benno,&lt;/p&gt;
&lt;p&gt;I am still struggling to get the same behavior as you do. Can you please send me a project with the configuration you are using that I can use to reproduce the issue? Are you able to reproduce it e.g. with something based on the peripheral_uart sample?&amp;nbsp;&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: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/393632?ContentTypeID=1</link><pubDate>Wed, 02 Nov 2022 12:02:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be61d8c0-8d0a-4f2b-9463-3261483b4dc5</guid><dc:creator>Benno Trutmann</dc:creator><description>&lt;p&gt;The controller part was not configured by me, so I do not really know what I am talking about. But I was under the impression that I use the Softdevice controller, but via &amp;quot;HCI using RPMsg&amp;quot; (CONFIG_BT_RPMSG=y).&lt;/p&gt;
&lt;p&gt;When I look into the .config file in the app build directory I see no definition of CONFIG_BT_LL_SPLIT nor CONFIG_BT_LL_SOFTDEVICE.&lt;/p&gt;
&lt;p&gt;In the .config file of the hci_rpmsg build directory I see&lt;/p&gt;
&lt;p&gt;# CONFIG_BT_LL_SW_SPLIT is not set&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;CONFIG_BT_LL_SOFTDEVICE=y&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Benno&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/393625?ContentTypeID=1</link><pubDate>Wed, 02 Nov 2022 11:36:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45052a09-eaa7-405f-b8f0-940c287866e6</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Thank you very much Benno.&lt;/p&gt;
&lt;p&gt;Are you using the Zephyr Bluetooth Low Energy controller?&lt;/p&gt;
&lt;p&gt;Did you set CONFIG_BT_LL_SPLIT=y in your prj.conf (or any other .conf file that is included in your application)?&lt;/p&gt;
&lt;p&gt;I believe the reason I struggled to find it is that if you use the Nordic Bluetooth Low Energy controller (SoftDevice controller), which is either set by default, or if you use CONFIG_BT_LL_SOFTDEVICE=y, then the implementation of&amp;nbsp;bt_gatt_notify_cb() that will be used is found in bt_rpc_gatt_client.c (ncs\nrf\subsys\bluetooth\rpc\client\bt_rpc_gatt_client.c), and it looks like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int bt_gatt_notify_cb(struct bt_conn *conn,
		      struct bt_gatt_notify_params *params)
{
	struct nrf_rpc_cbor_ctx ctx;
	int result;
	size_t scratchpad_size = 0;
	size_t buffer_size_max = 8;

	buffer_size_max += bt_gatt_notify_params_buf_size(params);

	scratchpad_size += bt_gatt_notify_params_sp_size(params);

	NRF_RPC_CBOR_ALLOC(&amp;amp;bt_rpc_grp, ctx, buffer_size_max);
	ser_encode_uint(&amp;amp;ctx, scratchpad_size);

	bt_rpc_encode_bt_conn(&amp;amp;ctx, conn);
	bt_gatt_notify_params_enc(&amp;amp;ctx, params);

	nrf_rpc_cbor_cmd_no_err(&amp;amp;bt_rpc_grp, BT_GATT_NOTIFY_CB_RPC_CMD,
		&amp;amp;ctx, ser_rsp_decode_i32, &amp;amp;result);

	return result;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It doesn&amp;#39;t call gatt_notify(). Do you see the same blocking behavior if you try to set CONFIG_BT_LL_SOFTDEVICE=y in your prj.conf?&lt;/p&gt;
&lt;p&gt;&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: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/393593?ContentTypeID=1</link><pubDate>Wed, 02 Nov 2022 09:36:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3bc0492-a45d-4e9b-a4ae-2af0c0cf2997</guid><dc:creator>Benno Trutmann</dc:creator><description>&lt;p&gt;Hi Edvin.&lt;/p&gt;
&lt;p&gt;Here is the call stack (keep in mind that conn_tx_alloc() is only called when func in struct bt_gatt_notify_params is set to a callback):&lt;/p&gt;
&lt;p&gt;bt_gatt_notify_cb(params-&amp;gt;func!=NULL) -&amp;gt; gatt_notify(params-&amp;gt;func!=NULL) -&amp;gt;&lt;/p&gt;
&lt;p&gt;bt_att_send() -&amp;gt; att_send_process() -&amp;gt; process_queue() -&amp;gt; bt_att_chan_send() -&amp;gt; chan_send() -&amp;gt;&lt;/p&gt;
&lt;p&gt;bt_l2cap_send_cb(cb!=NULL) -&amp;gt;&lt;/p&gt;
&lt;p&gt;bt_conn_send_cb(cb!=NULL) -&amp;gt; conn_tx_alloc() -&amp;gt;&lt;/p&gt;
&lt;p&gt;k_fifo_get(&amp;amp;free_tx, K_FOREVER)&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Benno&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/393586?ContentTypeID=1</link><pubDate>Wed, 02 Nov 2022 09:10:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abb86094-a7f3-45fd-b911-63d06170de05</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello, Sorry to bother you with this, but I struggle to find the call path from bt_nus_send_cb() to conn_tx_allloc().&lt;/p&gt;
&lt;p&gt;I see that conn_tx_alloc() is used from&amp;nbsp;bt_conn_send_cb(), which again is used from either bt_l2cap_send_cb() or&amp;nbsp;bt_iso_chan_send(). Which one is used in your case? And can you please share the entire callstack from bt_gatt_notify_cb() to conn_tx_alloc()? The reason I am asking is that I need to be able to reproduce this before filing it as a bug report/feature request.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/393215?ContentTypeID=1</link><pubDate>Mon, 31 Oct 2022 12:03:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e87be0a7-aec7-42c9-b737-c886b83ef890</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Benno,&lt;/p&gt;
&lt;p&gt;I was not aware that it did that. I agree that it would make sense to have it just return an error instead of waiting for a free buffer. I will report your suggestion (which I agree with) internally.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I guess you can modify the behavior of bt_gatt_notify_cb() if you like, to return -ENOBUFS even if it is not called from System Workqueue context, or you can call it from a different thread that doesn&amp;#39;t do anything other than that (so that it doesn&amp;#39;t matter if it is blocking).&lt;/p&gt;
&lt;p&gt;&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: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/393177?ContentTypeID=1</link><pubDate>Mon, 31 Oct 2022 09:43:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:722605bc-42f6-4397-a423-89f80c013d02</guid><dc:creator>Benno Trutmann</dc:creator><description>&lt;p&gt;Hello Edvin.&lt;/p&gt;
&lt;p&gt;Unfortunately I have no demo code for you to reproduce.&lt;/p&gt;
&lt;p&gt;But I think I found the culprit: At the end of the&amp;nbsp; function conn_tx_alloc() in the module subsys/bluetooth/host/conn.c there is the line&lt;/p&gt;
&lt;p&gt;&lt;code&gt;return k_fifo_get(&amp;amp;free_tx, K_FOREVER);&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;And because of that bt_gatt_notify_cb() blocks as soon as the free_tx queue is empty. There is one exception when bt_gatt_notify_cb()&amp;nbsp; gets called from System Workqueue context (e.g. from the &amp;quot;Notification Value callback&amp;quot;), in this case instead of blocking the error code -ENOBUFS is returned.&lt;/p&gt;
&lt;p&gt;The size of the free_tx queue can be set by the Kconfig option CONFIG_BT_CONN_TX_MAX, in my tests this option was set to 3.&lt;/p&gt;
&lt;p&gt;For many applications this behavior may be the desired one, but for my application a call to bt_gatt_notify_cb() must not block under any circumstances. Therefore I introduced a credit counter in my code, so I can track the fill level of the free_tx queue and only call bt_gatt_notify_cb() if the queue is not empty.&lt;/p&gt;
&lt;p&gt;Unfortunately this credit counter is not the real fill level of the free_tx queue and if some other code parts also call bt_gatt_notify_cb(), without respecting the credit counter, my approach could still block.&lt;/p&gt;
&lt;p&gt;Therefore I propose a change in the host stack: There is already a struct bt_gatt_notify_params passed to bt_gatt_notify_cb(), it should be easy to add a field to this struct to indicate if bt_gatt_notify_cb() is allowed to block or not.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Benno&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/393022?ContentTypeID=1</link><pubDate>Fri, 28 Oct 2022 12:27:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a9bcb6d-a476-493f-ac92-d1a69acc01b2</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Benno,&lt;/p&gt;
&lt;p&gt;Can you please upload a project that I can use to replicate what you are seeing? What are you connected to? Can I reproduce the issue using two DKs of some sort?&lt;/p&gt;
&lt;p&gt;&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: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/392903?ContentTypeID=1</link><pubDate>Thu, 27 Oct 2022 16:30:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:754cc3eb-a15f-43c1-afd5-6ae9061067dd</guid><dc:creator>Caesarn</dc:creator><description>&lt;p&gt;Great to read your ideas. :))&lt;br /&gt;&lt;span style="color:#ffffff;font-size:75%;"&gt;&lt;a style="color:#ffffff;" href="https://stumbleguysonline.io"&gt;stumble guys online&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/392890?ContentTypeID=1</link><pubDate>Thu, 27 Oct 2022 15:02:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6735855a-9837-4eff-9c23-9bbf3889b873</guid><dc:creator>Benno Trutmann</dc:creator><description>&lt;p&gt;Hi all.&lt;/p&gt;
&lt;p&gt;For me bt_gatt_notify_cb() does block as well.&lt;/p&gt;
&lt;p&gt;I try to implement a flow control with the help of the &amp;quot;Notification Value callback&amp;quot; func in struct bt_gatt_notify_params. But for that to work bt_gatt_notify_cb() should&amp;nbsp; return an error code indicating an out of buffer condition. Whereas in my test bt_gatt_notify_cb() only returns 0.&lt;/p&gt;
&lt;p&gt;I use a connection interval of 500ms, the first three calls to bt_gatt_notify_cb() return immediately with return value of 0, but the forth blocks for almost 500ms and then returns also with the value 0.&lt;/p&gt;
&lt;p&gt;I too thought that bt_gatt_notify_cb() is non-blocking but the behavior is blocking!&lt;/p&gt;
&lt;p&gt;Do I miss some Zephyr BLE config option?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Benno&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/389625?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 12:33:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f124e32-3d57-4cfc-b8c6-641cb1311e50</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;So whereabout in the sniffer trace would you say that it starts to slow down?&lt;/p&gt;
&lt;p&gt;If you want to actually monitor whether or not the notifications are sent, you should check the return value from bt_gatt_notify_cb. This will tell you whether or not the packet is actually queued.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I guess the reason you are seeing these &amp;quot;slowing down&amp;quot; (they aren&amp;#39;t really. You still have on average 1 interrupt every 5ms) is that you have this timer set to interrupt at the same rate as your connection interval (every other timer interrupt). Remember that every 10 ms the nRF needs to spin up the radio, and the softdevice controller takes over to handle the communication with the connected device. Due to clock accuracy (or inaccuracy), these connection events (the events that occur every connection interval) can drift a bit. I believe what you are seeing is that it drifted over to hit the timer interrupts, and in the middle of bt_gatt_notify_cb, the SoftDevice Controller (Bluetooth stack) takes control over the CPU to handle Bluetooth stuff, and then gives back the CPU to your application when it is done. At that point it will continue where it left off.&lt;/p&gt;
&lt;p&gt;&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: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/389439?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2022 13:48:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3551d3d-dfc5-4b5a-b2ca-c60d38a0db06</guid><dc:creator>Jason Wright</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Sorry, I should have been a bit clearer on this.&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Please see L199-201 in main.c for the call to bt_gatt_notify_cb surrounded by P0.04 toggle.&lt;/li&gt;
&lt;li&gt;My logic analyzer capture (.sal) and Wireshark capture (.pcapng) are unfortunately not synchronized because I did not have a way of starting them at the same time. When I mentioned 14.5 seconds, I was referring to the logic analyzer capture (see image below).&lt;/li&gt;
&lt;li&gt;In the logic analyzer capture, the first notification is sent at 8.694 seconds. The first notification in the Wireshark capture is no. 9472 at 21.044 seconds.&lt;/li&gt;
&lt;li&gt;The Wireshark capture includes the connection establishment (starting at no. 7518), MTU exchange, connection parameters, data length extension, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I should also mention that my central device is a nRF52840 dongle running the Nordic connectivity firmware, using the nRF Connect Desktop BLE app, and I can see the notifications appear in the app.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1664977611425v1.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Fast notifications with nRF5340 and nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/389321?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2022 07:58:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6be36fb7-e8e4-48f4-a92d-efa569b7812f</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;bt_gatt_notify_cb() is not a blocking call, so it should not be the reason why the P0.04 isn&amp;#39;t toggling.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you sure that bt_gatt_notify_cb() is even called at 14.5 seconds into the trace? The trace doesn&amp;#39;t show any notifications being sent around that time. In fact, it doesn&amp;#39;t look like any notifications are sent at all in the connection starting at packet no. 7517 (12.89 seconds into the sniffer trace).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Are you sure bt_gatt_notify_cb() is called at all? And if it is, what does it return? I assume it doesn&amp;#39;t return 0, since no notifications are actually sent.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&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>