<?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>Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/83689/bluetooth-and-threading-with-zephyr</link><description>Hey, I&amp;#39;m trying to integrate BT + DFU functionality into my application, i&amp;#39;m following this example: Add DFU support to your application - Software - nRF Connect SDK guides - Nordic DevZone (nordicsemi.com) 
 
 Everything is working fine, I can see device</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 10 Feb 2023 02:37:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/83689/bluetooth-and-threading-with-zephyr" /><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/409256?ContentTypeID=1</link><pubDate>Fri, 10 Feb 2023 02:37:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfe42297-05f2-4caa-92c3-0ed15619abf3</guid><dc:creator>ALAV</dc:creator><description>&lt;p&gt;Hey Hung, We figured out that it was thread priority. The HCI_RPMSG_RX thread was set to priority 8, We had to change the main thread priority from 0 to 8.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/408850?ContentTypeID=1</link><pubDate>Wed, 08 Feb 2023 12:13:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50ebca85-d022-4c77-b7c8-21d4407d9594</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Alav,&amp;nbsp;&lt;br /&gt;Please create a new case for your question.&amp;nbsp;&lt;br /&gt;Please be aware that in zephyr if thread has the same priority it will not preempt each other. You need to put the thread to sleep to yield for other thread.&amp;nbsp; If you have a look&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.0/zephyr/kernel/services/scheduling/index.html#preemptive-time-slicing"&gt; here&lt;/a&gt;, you can find that when time slicing is not used (which is the default case) preemptive thread with the same priority will not yield to each other.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/407674?ContentTypeID=1</link><pubDate>Thu, 02 Feb 2023 05:07:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6da3e00-216d-4e52-9b1d-21f85506610b</guid><dc:creator>ALAV</dc:creator><description>&lt;p&gt;Can confirm having a similar issue on the NRF5340&amp;nbsp;as well. The BT HCI core initializes fine and advertisements also work like a charm. But, soon as the code enters a while loop on main, connections timeout. I&amp;#39;m testing the connection over LightBlue. The connection only proceeds if the main loop is slowed down.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/390859?ContentTypeID=1</link><pubDate>Fri, 14 Oct 2022 23:07:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ef08bfc-349b-4b3f-aa7d-845e475853b1</guid><dc:creator>ACook</dc:creator><description>&lt;p&gt;I found this thread while trying to debug some similar issues with the Bluetooth stack and multithreading on my nRF52810. I don&amp;#39;t know if this will be helpful for your situation, but I figured I would share since this post is still &amp;quot;not answered&amp;quot;.&lt;/p&gt;
&lt;p&gt;The app I have runs a simple control API over UART in a loop in main to setup Bluetooth GATT services. I had main running at priority 0, and I noticed that pairing would never work unless I explicitly did a sleep in my loop. I saw that the BT RX and TX threads were running at negative priority, but when I dug a little deeper I noticed that the &amp;quot;BT CTLR ECDH&amp;quot; thread was running at priority 10. So I think that thread could never pre-empt main and pairing could never be initiated.&lt;/p&gt;
&lt;p&gt;That thread gets created in the NRF Bluetooth controller (not Zephyr), so if this is not desired behavior then maybe a bug ticket needs to be created for Nordic. I also noticed that the module could crash randomly if I had main running at a higher priority than the BT CTLR ECDH, so maybe there&amp;#39;s a crash that can happen in there if it gets pre-empted.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/350926?ContentTypeID=1</link><pubDate>Wed, 02 Feb 2022 15:10:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:288fe4a5-ee0b-4dfe-b74a-7e60415d6191</guid><dc:creator>Dymek117</dc:creator><description>&lt;p&gt;I tried with example app from nordic and it works with assertion turned off.&lt;br /&gt;I will try to collect more logs or maybe we will rise private tickets.&lt;/p&gt;
&lt;p&gt;But I also have new idea now - is it possible that&amp;nbsp;cause of BT working not properly is that we &lt;strong&gt;totally removed zephyr console&lt;/strong&gt; from our project?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/350334?ContentTypeID=1</link><pubDate>Sun, 30 Jan 2022 16:38:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9b7b64d-8dac-48d2-8931-fb1cbc4ce1c3</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;If your code is confidential, I can make this ticket private, so only the support engineers here at Nordic has access to the content.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try to enable some more logging? Set these and reproduce the failing state&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_LOG=y
CONFIG_BT_DEBUG_HCI_CORE=y
CONFIG_BT_DEBUG_HCI_DRIVER=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and see if you get any information about why it fails.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/349042?ContentTypeID=1</link><pubDate>Sat, 22 Jan 2022 00:48:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e829a82f-7b1c-4b6b-a5d1-00afbf397a35</guid><dc:creator>Dymek117</dc:creator><description>&lt;p&gt;Unfortunatelly I&amp;#39;m not able to share my code :( Maybe i can create some sample next week.&lt;/p&gt;
&lt;p&gt;But to make long story short - everything works fine with one thread (even without assert), but when two threads are running CONFIG_ASSSERT=y is necessary - otherwise bluetooth will be working fine, only until next thread will be started.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/348948?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 13:50:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5cd22c38-93b3-43f9-a553-8e38769c2419</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Hmm.. It is hard to say why enabling asserts makes the issue go away. It would be much easier for me to investigate this if I get the sample, run it on an nRF52832 DK and reproduce it myself. Would it be possible to upload the sample here on DevZone (or a simplified sample that demonstrates the issue)?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/348910?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 12:16:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78488256-efc2-485b-ad36-a5460d37ffa1</guid><dc:creator>Dymek117</dc:creator><description>&lt;div&gt;&lt;span&gt;It may be helpful to look info my prj.conf. This one is without asserts (so it is not working)&lt;br /&gt;&lt;br /&gt;CONFIG_SIZE_OPTIMIZATIONS&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_GPIO&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_PWM&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_ADC&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_NRFX_TIMER0&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_FLASH&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_SMP&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_PERIPHERAL&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_DEVICE_NAME&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;quot;Nordic_LBS&amp;quot;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;# Enable mcumgr.&lt;/p&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;# Enable most core commands.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR_CMD_IMG_MGMT&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR_CMD_OS_MGMT&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;# Ensure an MCUboot-compatible binary is generated.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BOOTLOADER_MCUBOOT&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;# Enable the Bluetooth (unauthenticated) and shell mcumgr transports.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR_SMP_BT&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR_SMP_BT_AUTHEN&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;# Some command handlers require a large stack.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE&lt;/span&gt;&lt;span&gt;=4096&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;# Disable Bluetooth features not needed&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_DEBUG_NONE&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_ASSERT&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_DATA_LEN_UPDATE&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_PHY_UPDATE&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_GATT_CACHING&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_HCI_VS_EXT&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_CTLR_PRIVACY&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;# Reduce Bluetooth buffers&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT&lt;/span&gt;&lt;span&gt;=1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_BUF_EVT_RX_COUNT&lt;/span&gt;&lt;span&gt;=2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_L2CAP_TX_BUF_COUNT&lt;/span&gt;&lt;span&gt;=2&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MULTITHREADING&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/348847?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 07:23:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2913caf-d0eb-4162-9112-d335e9dea274</guid><dc:creator>Dymek117</dc:creator><description>&lt;p&gt;I had to return to this problem, here is my current position:&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;With&amp;nbsp;CONFIG_ASSERT=n:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;main() starts&lt;/span&gt;&lt;br /&gt;&lt;span&gt;enable BT and mcumgr OTA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - &lt;strong&gt;Bluetooth fully responsible&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;delay 3s&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;- &lt;strong&gt;Bluetooth fully responsible&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;run my thread (priority set to 18)&amp;nbsp; &amp;nbsp; - &lt;strong&gt;Bluetooth&amp;nbsp;not responsible at all&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;With&amp;nbsp;CONFIG_ASSERT=y:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;main() starts&lt;/span&gt;&lt;br /&gt;&lt;span&gt;enable BT and mcumgr OTA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;nbsp;&lt;strong&gt;Bluetooth fully responsible&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;delay 3s&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;-&amp;nbsp;&lt;strong&gt;Bluetooth fully responsible&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;run my thread (priority set to 18)&amp;nbsp; &amp;nbsp;&amp;nbsp;-&amp;nbsp;&lt;strong&gt;Bluetooth fully responsible&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My question is - &lt;strong&gt;why does enabling assertion globally solves this problem?&amp;nbsp;&lt;/strong&gt;&lt;br /&gt;I would rather not includ asserts in my code, as BT appliacation with asserts weights a lot,&lt;br /&gt;and i would better keep space for 2 program slots in my 512kB of flash.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It&amp;#39;s worth adding, that my thread is not influencing bluetooth or ota features, it&amp;#39;s simple gpio, uart operations.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/348019?ContentTypeID=1</link><pubDate>Mon, 17 Jan 2022 12:14:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32bd68ef-9b73-4f56-8c6e-6b0a519980e9</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m glad you found a partial solution. However, I&amp;#39;m not exactly sure what could cause this issue. Could you share a simple sample that demonstrates the issue?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth and threading with Zephyr</title><link>https://devzone.nordicsemi.com/thread/347917?ContentTypeID=1</link><pubDate>Mon, 17 Jan 2022 07:40:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af14ed3b-dec1-4c43-b272-5eef3d3778b7</guid><dc:creator>Dymek117</dc:creator><description>&lt;p&gt;Ok, I partially solved my problem. Solution was running all BT and DFU init&amp;nbsp;functions in main loop (or separate thread) and setting my code&amp;#39;s thread priority down to 18 value .&lt;br /&gt;Running my code and BT inside one thread is apparently not a good idea.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>