<?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>No preemption in application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/36825/no-preemption-in-application</link><description>Hi, 
 I use the peripheral ble_app_uart with nRF52832 (Murata module). The nRF52832 is connected to another MCU, STM32L476, via UART. 
 I develop using IAR, with SDK V15.0.0 
 My problem is that the uart_event_handle is not preempted by ble_nus_on_ble_evt</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Jul 2018 11:53:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/36825/no-preemption-in-application" /><item><title>RE: No preemption in application</title><link>https://devzone.nordicsemi.com/thread/141892?ContentTypeID=1</link><pubDate>Mon, 30 Jul 2018 11:53:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7964420-eb19-40b4-8acd-1a5c95066c42</guid><dc:creator>Clonimmus74</dc:creator><description>&lt;p&gt;I was mistaken, I moved the function from main to SWI, and there&amp;#39;s no preemption.&lt;br /&gt;&lt;br /&gt;I changed in&amp;nbsp;ble_stack_init the line to force priority = 2:&lt;/p&gt;
&lt;p&gt;NRF_SDH_BLE_OBSERVER(m_ble_observer, 2, ble_evt_handler, NULL);&lt;/p&gt;
&lt;p&gt;and I set SWI:&lt;/p&gt;
&lt;p&gt;nrf_drv_swi_alloc(&amp;amp;ble_uart_swi, ble_tx_swi_event_handler, APP_IRQ_PRIORITY_LOWEST);&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The SWI waits in a loop for a flag set in&amp;nbsp;&lt;span&gt;ble_evt_handler, but it never reaches it. the SWI executes&amp;nbsp;ble_nus_data_send, then I expect the event&amp;nbsp;BLE_GATTS_EVT_HVN_TX_COMPLETE to be triggered, but the program never reaches it since there&amp;#39;s no preemption.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I move the function from SWI (and disable SWI) to main all functions properly.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No preemption in application</title><link>https://devzone.nordicsemi.com/thread/141786?ContentTypeID=1</link><pubDate>Sun, 29 Jul 2018 07:09:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ad3c2b1-e1e0-4f2c-b6b5-1b5b8d9111ef</guid><dc:creator>Clonimmus74</dc:creator><description>&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;Actually, from what I&amp;#39;ve seen, they don&amp;#39;t have the same priority,and as I said I tried&amp;nbsp;forcing different priorities.&lt;/p&gt;
&lt;p&gt;I found the problem though,&amp;nbsp;f_ble_tx_complete was initialized with 0 instead of 1, so the first transmission didn&amp;#39;t occur. Regardless I moved the UART part to main.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No preemption in application</title><link>https://devzone.nordicsemi.com/thread/141681?ContentTypeID=1</link><pubDate>Fri, 27 Jul 2018 12:37:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97c74148-6fc1-4f7e-8a84-702fa96fc0d2</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Both these handlers are executed in the NVIC interrupt priority 7, which is why your while-loop will never exit. I&amp;#39;d recommend that you schedule the ble_nus_data_send logic to main context instead.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The define&amp;nbsp;BLE_NUS_BLE_OBSERVER_PRIO will set the priority on which order each hook/callback will be called when polling the event from the softdevice_handler, but they all are still executed in handler context.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>