<?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>FreeRTOS + UART receive blocks everything</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/13238/freertos-uart-receive-blocks-everything</link><description>Hi, 
 Using the nRF5 11.0.0 release SDK, I&amp;#39;m trying to set up one task to transmit to and one task to receive data from the UART. Nothing special. 
 The configuration block in nrf_drv_config.h looks like: 
 /* UART */
#define UART0_ENABLED 1

#if</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 17 Apr 2016 12:02:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/13238/freertos-uart-receive-blocks-everything" /><item><title>RE: FreeRTOS + UART receive blocks everything</title><link>https://devzone.nordicsemi.com/thread/50482?ContentTypeID=1</link><pubDate>Sun, 17 Apr 2016 12:02:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bdb856e-27c8-4628-be98-094649b18ac5</guid><dc:creator>maxv</dc:creator><description>&lt;p&gt;I haven&amp;#39;t got stack overflow checking on.&lt;/p&gt;
&lt;p&gt;However, I was wondering if it&amp;#39;s common to implement an indepedent task to check on all the other tasks&amp;#39; high water mark, using &lt;code&gt;uxTaskGetStackHighWaterMark&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;I&amp;#39;m thinking about printing this information out at runtime.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 1:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;After doing some more digging, it does look like the legacy UART driver is not compatible with FreeRTOS. This is likely a problem on the Nordic side. It&amp;#39;s not a stack size issue. It&amp;#39;s probably fixable by using the UARTE non-blocking Rx/Tx, and I&amp;#39;ll be trying that path next.&lt;/p&gt;
&lt;p&gt;When I trace the problem with &lt;code&gt;gdb&lt;/code&gt;, it tells me that the &lt;code&gt;nrf_drv_uart_rx_for_uart&lt;/code&gt; gets stuck in a while loop, but the OS should have at some point preempted this, and allowed my other tasks to run:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Program received signal SIGTRAP, Trace/breakpoint trap.
nrf_drv_uart_rx_for_uart (p_data=&amp;lt;optimized out&amp;gt;, length=&amp;lt;optimized out&amp;gt;, second_buffer=&amp;lt;optimized out&amp;gt;) at /home/max/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/uart/nrf_drv_uart.c:421
421	            } while ((!rxrdy) &amp;amp;&amp;amp; (!rxto) &amp;amp;&amp;amp; (!error));
(gdb) bt
#0  nrf_drv_uart_rx_for_uart (p_data=&amp;lt;optimized out&amp;gt;, length=&amp;lt;optimized out&amp;gt;, second_buffer=&amp;lt;optimized out&amp;gt;) at /home/max/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/uart/nrf_drv_uart.c:421
#1  nrf_drv_uart_rx (p_data=p_data@entry=0x20003314 &amp;lt;ucHeap+2524&amp;gt; &amp;quot;&amp;quot;, length=length@entry=8 &amp;#39;\b&amp;#39;) at /home/max/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/uart/nrf_drv_uart.c:570
#2  0x0002191e in uart_input_task (arg=&amp;lt;optimized out&amp;gt;) at /home/max/nRF5_SDK_11.0.0_89a8197/examples/ble_peripheral/ble_app_hrs_freertos/main.c:911
#3  0x0001d684 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My task creation in &lt;code&gt;main()&lt;/code&gt; looks like this, and the code is getting stuck immediately at the launch of &lt;code&gt;uart_input_task&lt;/code&gt;, it never runs the tasks specified in the other &lt;code&gt;xTaskCreate&lt;/code&gt; calls:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if (pdPASS != xTaskCreate(uart_input_task, &amp;quot;UART Rx&amp;quot;, 256, NULL, 1, &amp;amp;m_uart_input_thread))
{
    printf(&amp;quot;Out of memory.&amp;quot;);
    APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}

if (pdPASS != xTaskCreate(uart_output_task, &amp;quot;UART Tx&amp;quot;, 256, NULL, 1, &amp;amp;m_uart_output_thread))
{
    printf(&amp;quot;Out of memory.&amp;quot;);
    APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}

if (pdPASS != xTaskCreate(uart_test_task, &amp;quot;Test UART Task&amp;quot;, 256, NULL, 1, &amp;amp;m_uart_test_task))
{
    printf(&amp;quot;Out of memory.&amp;quot;);
    APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Update 2&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;Yes, using the UARTE non-blocking TX/RX seems to work. The UART event handler passed to &lt;code&gt;nrf_drv_uart_init()&lt;/code&gt; uses a semaphore to notify the RX task that data has been received, and the RX task sets up another receive using &lt;code&gt;nrf_drv_uart_rx()&lt;/code&gt;, then the RX task waits on the semaphore again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS + UART receive blocks everything</title><link>https://devzone.nordicsemi.com/thread/50481?ContentTypeID=1</link><pubDate>Fri, 15 Apr 2016 17:33:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b2049db-be9b-42ab-af1c-5ae4e96d4990</guid><dc:creator>www.FreeRTOS.org</dc:creator><description>&lt;p&gt;See my reply &lt;a href="https://devzone.nordicsemi.com/question/75930/freertos-queues-seem-broken/"&gt;to this thread&lt;/a&gt;, my reply to this one would be very similar.&lt;/p&gt;
&lt;p&gt;Your stack looks relatively small - do you have &lt;a href="http://www.freertos.org/Stacks-and-stack-overflow-checking.html"&gt;stack overflow checking on&lt;/a&gt;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>