<?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>FIFO uart stops sending when inside app_error_handler (flush doesnt do it)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10140/fifo-uart-stops-sending-when-inside-app_error_handler-flush-doesnt-do-it</link><description>i&amp;#39;m using uart for debugging, works fine and dandy except when in app_error_handler.
There only the first character is being printed before we go into an infinite loop. Inside the error handler, i2c and spi work fine, just not uart... odd. 
 void app_error_handler</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 22 Jun 2018 08:47:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10140/fifo-uart-stops-sending-when-inside-app_error_handler-flush-doesnt-do-it" /><item><title>RE: FIFO uart stops sending when inside app_error_handler (flush doesnt do it)</title><link>https://devzone.nordicsemi.com/thread/137218?ContentTypeID=1</link><pubDate>Fri, 22 Jun 2018 08:47:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0903ed1e-77fa-4e2f-83fd-9d8c62206083</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Unless the SoftDevice is set up to use the app_scheduler module the nus_data_handler(..) will run in interrupt context.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try to run the code from main context instead and see if it solves the issue?&lt;/p&gt;
&lt;p&gt;To test this simply create a flag that you set inside the nus_data_handler, and check the status of this flag in the main loop:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;static volatile bool update_motor = false;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;{&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; printf(&amp;quot;%s\r\n&amp;quot;, p_data);&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp; if (p_data[0] == &amp;#39;1&amp;#39;)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; {&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; update_motor = true;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; }&lt;/code&gt;&lt;br /&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;// In main loop...&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;if(update_motor)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;{&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; update_motor = false;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp; run_motor(0, 5000);&lt;/code&gt;&lt;br /&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FIFO uart stops sending when inside app_error_handler (flush doesnt do it)</title><link>https://devzone.nordicsemi.com/thread/137138?ContentTypeID=1</link><pubDate>Thu, 21 Jun 2018 14:45:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d1c9f7b-3462-4d6a-99c2-e465a0ced98a</guid><dc:creator>4ward3D</dc:creator><description>&lt;p&gt;Thanks for the help ovrebekk. I am not using printf in the interrupt. I am simply calling ble_nus_string_send after printf. Here&amp;#39;s some example code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
	printf(&amp;quot;%s\r\n&amp;quot;, p_data);

if (p_data[0] == &amp;#39;1&amp;#39;){
run_motor(0, 5000);
}

void run_motor(int direction, int nosteps){
	printf(&amp;quot;%s&amp;quot;, &amp;quot;got here\r\n&amp;quot;);
    unsigned char string_tosend[]= {&amp;quot;Motor Running&amp;quot;};
// remove the following line and printf to terminal sends all charators
// with following line in, the first charactor is sent (from nus_data_handler)
// and the program stops
	while(ble_nus_string_send(&amp;amp;m_nus, string_tosend, strlen((char*)string_tosend)) != NRF_SUCCESS);  
    motor_steps = nosteps;	
    current_steps = nosteps;
    motor_direction = direction;
    uint32_t err_code;
    err_code = app_timer_start(motor_step_timer_id, APP_TIMER_TICKS(MOTOR_TICKS, APP2_TIMER_PRESCALER), NULL);      APP_ERROR_CHECK(err_code);
	err_code = app_timer_start(motor_run_timer_id , APP_TIMER_TICKS(nosteps, APP2_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;ble_nus_string_send is clobbering the printf for some reason. Could I check and wait for printf to send all characters before calling it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FIFO uart stops sending when inside app_error_handler (flush doesnt do it)</title><link>https://devzone.nordicsemi.com/thread/137086?ContentTypeID=1</link><pubDate>Thu, 21 Jun 2018 11:56:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2df7ffa-bcd7-4c78-8d53-2fac3735dabd</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The issue where you can&amp;#39;t use an interrupt based driver from a high priority interrupt is not changed. The only solution to this&amp;nbsp;issue is to use a non interrupt based driver.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Where are you calling the code from?&lt;br /&gt;In general calling functions like ble_nus_string_send in a loop is a bit risky, especially if you do it in an interrupt (like an event handler). It is wiser to&amp;nbsp;set a flag if the BLE buffers are full, and try to send the packet again once the TX complete event occurs.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FIFO uart stops sending when inside app_error_handler (flush doesnt do it)</title><link>https://devzone.nordicsemi.com/thread/136972?ContentTypeID=1</link><pubDate>Thu, 21 Jun 2018 01:32:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c25b6d83-080c-4e66-9996-dc5e0812a575</guid><dc:creator>4ward3D</dc:creator><description>&lt;p&gt;I know this is an old thread but has anyone solved this issue? I am using UART for debugging with printf() and it is working fine in most of the code. If I do a while(ble_nus_string_send(...)!=NRF_SUCCESS),&amp;nbsp;after my printf, the terminal shows only one character and program locks. Can anyone help?&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FIFO uart stops sending when inside app_error_handler (flush doesnt do it)</title><link>https://devzone.nordicsemi.com/thread/37605?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2015 14:45:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1a2a65a-1d21-4bf6-a9bc-6de48e3ca8c7</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;This could be an interrupt issue, where the UART interrupts are blocked because the app_error_handler is running in a higher (or the same) interrupt context.&lt;/p&gt;
&lt;p&gt;Could you please try using the simple_uart driver instead?
It doesn&amp;#39;t use interrupts, and should work fine from any interrupt priority.&lt;/p&gt;
&lt;p&gt;I have attached the driver &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/simple_5F00_uart.zip"&gt;here&lt;/a&gt; for your convenience:&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;
Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>