<?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>Recover from NRF_UARTE_EVENT_ERROR when UART RX pin pulled low</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/23834/recover-from-nrf_uarte_event_error-when-uart-rx-pin-pulled-low</link><description>Greetings, 
 In my application I have another device (STM32) communicating to a NRF52 via UART. When the STM32 needs to be reset, the NRF52&amp;#39;s RX pin is pulled low. When the RX pin is pulled low, a NRF_UARTE_EVENT_ERROR error is triggered in the uarte_irq_handler</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Aug 2017 03:21:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/23834/recover-from-nrf_uarte_event_error-when-uart-rx-pin-pulled-low" /><item><title>RE: Recover from NRF_UARTE_EVENT_ERROR when UART RX pin pulled low</title><link>https://devzone.nordicsemi.com/thread/93773?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 03:21:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6e1233b-e28e-4b36-807a-f7477f997f71</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve managed to fix this problem (with the help of Nordic Semi!). It turned out that I needed to clear the errors before restarting the UART driver.&lt;/p&gt;
&lt;p&gt;In case anyone else has a similar problem with the serial DFU, the modifications I made to nrf_serial_dfu.c are just in the uart_event_handler. When/if a framing error occurs (such as if RX goes low for longer than a character), it clears all errors and attempts to restart the UART interface.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void uart_event_handler(nrf_drv_uart_event_t * p_event, void * p_context)
{
    switch (p_event-&amp;gt;type)
    {
        case NRF_DRV_UART_EVT_TX_DONE:
            nrf_dfu_req_handler_reset_if_dfu_complete();
            break;

        case NRF_DRV_UART_EVT_RX_DONE:
            on_rx_complete((serial_dfu_t*)p_context, p_event-&amp;gt;data.rxtx.p_data, p_event-&amp;gt;data.rxtx.bytes);
            break;

        case NRF_DRV_UART_EVT_ERROR:
        {
            uint32_t err_code;
        
            /* Clear all events */
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_TXDRDY);
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_RXDRDY);
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_RXTO);
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_ERROR);
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_CTS);
            nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_NCTS);
            
            /* Restart UART */
            err_code = serial_dfu_transport_close();
            if(err_code != NRF_SUCCESS)
            {
                APP_ERROR_HANDLER(err_code);
            }
            err_code = serial_dfu_transport_init();
            if(err_code != NRF_SUCCESS)
            {
                APP_ERROR_HANDLER(err_code);
            }
        } break;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I recommend that Nordic Semi considers adding this to the next SDK release of nrf_serial_dfu.c or any drivers that use the UART driver!&lt;/p&gt;
&lt;p&gt;EDIT:&lt;/p&gt;
&lt;p&gt;While on the subject of making the nrf_serial_dfu.c more robust, I also had to reset the WDT in the wait_for_event() function in nrf_dfu.c. This is because my app (which uses the WDT) performs a software reset to get into the bootloader in preparation for DFU.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void wait_for_event()
{
    // Transport is waiting for event?
    while(true)
    {
        NRF_WDT-&amp;gt;RR[0] = WDT_RR_RR_Reload; //Reset WDT
        
        // Can&amp;#39;t be emptied like this because of lack of static variables
#ifdef BLE_STACK_SUPPORT_REQD
        (void)sd_app_evt_wait();
#else
        __WFI();
#endif
        app_sched_execute();
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Recover from NRF_UARTE_EVENT_ERROR when UART RX pin pulled low</title><link>https://devzone.nordicsemi.com/thread/93769?ContentTypeID=1</link><pubDate>Wed, 02 Aug 2017 10:46:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39aef1a0-2df0-4e5b-9ff1-f459cd537b0a</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Could you run the chip in debug mode and check the &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fuarte.html&amp;amp;cp=2_1_0_34_9_4&amp;amp;anchor=register.ERRORSRC"&gt;UART--&amp;gt;ERRORSRC&lt;/a&gt; when this error occur? What is the source of the error given in that register?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Recover from NRF_UARTE_EVENT_ERROR when UART RX pin pulled low</title><link>https://devzone.nordicsemi.com/thread/93768?ContentTypeID=1</link><pubDate>Fri, 28 Jul 2017 05:11:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1545373-d08a-4a30-a3d0-e201148084fc</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;I&amp;#39;ve tried two attempts of recovering from this error:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reinitialize the UART driver (&amp;quot;nrf_drv_uart_uninit&amp;quot; then &amp;quot;nrf_drv_uart_init&amp;quot;). Result: uarte_irq_handler triggers after a character is received, but is EVENTS_ERROR is set.&lt;/li&gt;
&lt;li&gt;Call &amp;quot;nrf_drv_uart_rx_abort&amp;quot; by itself, then followed by &amp;quot;nrf_drv_uart_rx_disable&amp;quot; then &amp;quot;nrf_drv_uart_rx_enable&amp;quot;. Result: uarte_irq_handler is not triggered after a character is received. This is despite no change in the interrupt register values from prior to pulling the RX pin low.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Both of these attempts were done in the NRF_DRV_UART_EVT_ERROR case in the &amp;quot;uart_event_handler&amp;quot;.&lt;/p&gt;
&lt;p&gt;Could someone please confirm that there is no way to recover from this error, other than performing a software reset?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Recover from NRF_UARTE_EVENT_ERROR when UART RX pin pulled low</title><link>https://devzone.nordicsemi.com/thread/93772?ContentTypeID=1</link><pubDate>Fri, 28 Jul 2017 02:37:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44d1fdc6-61a5-4913-b99d-2f14a70d7d0a</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;Another &amp;quot;fix&amp;quot; could be enabling the pull up on the NRF52&amp;#39;s RX pin, this will at least get around the issue when the STM32 reboots.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Recover from NRF_UARTE_EVENT_ERROR when UART RX pin pulled low</title><link>https://devzone.nordicsemi.com/thread/93771?ContentTypeID=1</link><pubDate>Fri, 28 Jul 2017 02:21:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7cb3623-fd82-4e09-8c0f-c4f135177a15</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;Kristin,&lt;/p&gt;
&lt;p&gt;Just re-read your reply. I&amp;#39;m not sure whether this scheme would fix the problem. When the error occurs, it enters the &amp;quot;uarte_irq_handler&amp;quot; function in nrf_drv_uart.c which then calls the event handler that was passed into &amp;quot;nrf_drv_uart_init&amp;quot;. In the case of the secure serial bootloader, this is the &amp;quot;uart_event_handler&amp;quot; function. In this function, I&amp;#39;ve commented out the NRF_DRV_UART_EVT_ERROR case so that the error is ignored (and the &amp;quot;uarte_irq_handler&amp;quot; clears the error flag). However, when a valid character is received, it is reported as an error in the &amp;quot;uarte_irq_handler&amp;quot; interrupt routine.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll see whether re-initialising the UART driver is able to fix the problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Recover from NRF_UARTE_EVENT_ERROR when UART RX pin pulled low</title><link>https://devzone.nordicsemi.com/thread/93767?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2017 21:57:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:689b9d44-aa97-4d83-95d3-89da386eaaba</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;Kirstin,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sure I could make a work around on this on the STM32 side and will do so.&lt;/p&gt;
&lt;p&gt;However, I&amp;#39;d also like to make the NRF52 firmware able to recover from this state. Any idea why the NRF52&amp;#39;s UART sets the EVENTS_ERROR flag when a valid character is received after one EVENTS_ERROR is received from pulling the RX line low? This is despite the EVENTS_ERROR being cleared after it is first triggered in the uarte_irq_handler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Recover from NRF_UARTE_EVENT_ERROR when UART RX pin pulled low</title><link>https://devzone.nordicsemi.com/thread/93770?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2017 12:13:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2484fc0a-d39c-42af-85b5-1eb9b2da75ff</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Is there a way for STM32 to indicate that it is about to reset? If so, STM32 can tell nRF52 that it is a about to reset. The nRF52 can then set a flag so that the application  knows that it can ignore the error NRF_DRV_UART_EVT_ERROR.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>