<?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>BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108341/bus-fault-when-working-with-async-uart</link><description>Good Day. 
 When working with the UART in asynchronous mode, I occasionally get this error: 
 
 Please tell me what this is related to and how to fix it. 
 Thank you.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 17 Feb 2024 06:03:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108341/bus-fault-when-working-with-async-uart" /><item><title>RE: BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/thread/469337?ContentTypeID=1</link><pubDate>Sat, 17 Feb 2024 06:03:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:592a3b5c-a0ed-4cb0-81a0-5c9a869ca5d2</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Yes, the error was related to the &amp;quot;i&amp;quot; index. I could not determine the cause of the error on my own.&lt;/p&gt;
&lt;p&gt;Thank you very much for your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/thread/469154?ContentTypeID=1</link><pubDate>Fri, 16 Feb 2024 07:43:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:925b8feb-2c73-46ad-94c8-39df112fc6fe</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thanks for the additional information. I don&amp;#39;t see anything that would prevent &amp;#39;rx_buf&amp;#39; from overrunning in cases where the &amp;#39;$&amp;#39; might not be found. The &amp;#39;i&amp;#39;&amp;nbsp;index will just keep incrementing until it triggers a fault.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/thread/469125?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2024 17:50:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:412e9e2d-48f7-4586-859c-04d31ac182e1</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* Receive buffer */
static uint8_t rx_buf[512] = {0};
/* Buffer for NMEA sentence*/
volatile static uint8_t sentence[82] = {0};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The algorithm of the program is as follows:&lt;/p&gt;
&lt;p&gt;I receive data from GNSS until the buffer is completely filled.&amp;nbsp;In the UART_RX_BUF_RELEASED event, I run the getStrFromRxBuffer() function which finds the $GNRMC string in the rx_buf receive buffer. Then I run the work to parsing the found string - k_work_submit&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;case UART_RX_BUF_RELEASED:
	getStrFromRxBuffer();
	k_work_submit(&amp;amp;gnss_work);
	break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Function getStrFromRxBuffer():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;char * getStrFromRxBuffer(void){
	volatile bool waitingForStrBegin = true;
	volatile bool waitingReadySentence = false;
	volatile static int index = 0; /* index inside sentence buffer */
	volatile static int i = 0; /* index inside rx_buf */

while(!waitingReadySentence){

	while(waitingForStrBegin){
		if(rx_buf[i] == &amp;#39;$&amp;#39;){    // is line 65 in the original program code
			index = 0;
			sentence[index++] = rx_buf[i++];
			waitingForStrBegin = false;
		}
		else{
			i++;
		}
	}

	while(rx_buf[i] != &amp;#39;\n&amp;#39;){
		sentence[index++] = rx_buf[i++];
	}

	sentence[index] = &amp;#39;\0&amp;#39;;

	const char * prefix = &amp;quot;$GNRMC&amp;quot;;
	if(strncmp(sentence, prefix, strlen(prefix)) == 0){
		waitingReadySentence = true;
		return sentence;
		}
		else {
		memset(sentence, 0, sizeof(sentence));
		index = 0;
		waitingForStrBegin = true;
		}
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Inside the work function, I clear the sentence and rx_buf buffers and then turn on the UART receiver and everything repeats again.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void gnss_work_cb (struct k_work *work){

struct minmea_sentence_rmc frame;
if(minmea_parse_rmc(&amp;amp;frame, sentence)){
                LOG_DBG(&amp;quot;\n Latitude: %f\n Longitude: %f\n Speed: %f\n&amp;quot;,
                        minmea_tocoord(&amp;amp;frame.latitude),
                        minmea_tocoord(&amp;amp;frame.longitude),
                        minmea_tofloat(&amp;amp;frame.speed));
            }
            else {
                 LOG_DBG(INDENT_SPACES &amp;quot;$GNRMC sentence is not parsed\n&amp;quot;);
            }
	memset(sentence, 0, sizeof(sentence));
	memset(rx_buf, 0, sizeof(rx_buf));
	uart_rx_enable(uart, rx_buf, sizeof(rx_buf), RECEIVE_TIMEOUT);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/thread/469110?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2024 16:18:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e342d3e-5834-4536-976e-92715cb12103</guid><dc:creator>Vidar Berg</dc:creator><description>[quote userid="112712" url="~/f/nordic-q-a/108341/bus-fault-when-working-with-async-uart/469105"]If I understand correctly, it points to an error in line 65?[/quote]
&lt;p&gt;Yes, correct. Could you post the code surrounding this line as well? Based on this and the&amp;nbsp;BFAR address, it appears that the rx_buf is pointing to an invalid memory address (RAM ends at 0x20040000).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/thread/469105?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2024 16:06:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e105ebe3-e3d0-447f-8b73-51039af8fcda</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Thanks. After entering the command I get the following response:&lt;/p&gt;
&lt;p&gt;C:\nordic\myapps\customblinky\build/../src/main.c:65&lt;/p&gt;
&lt;p&gt;If I understand correctly, it points to an error in line 65?&lt;/p&gt;
&lt;p&gt;In the program code at line 65 I check the condition if(rx_buf[i] == &amp;#39;$&amp;#39;) and look for the beginning of the line in the NMEA packet received from GNSS.&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t understand why this error occurs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/thread/469103?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2024 15:55:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ef32b68-9ac5-4f28-a78c-cbb6b10731bf</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please remove the &amp;#39;$&amp;#39; character at the beginning of the command.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/thread/469080?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2024 15:04:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98366d18-22fe-4838-b91b-1ce8bbfd4bcb</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Hi Vidar&lt;/p&gt;
&lt;p&gt;After entering a command, I get this error:&lt;/p&gt;
&lt;p&gt;$ : The name &amp;quot;$&amp;quot; is not recognized........&lt;/p&gt;
&lt;p&gt;+ $ arm-zephyr-eabi-addr2line -e build/zephyr/zephyr.elf 0x9e0&lt;br /&gt;+ ~&lt;br /&gt; + CategoryInfo : ObjectNotFound: ($:String) [], CommandNotFoundException&lt;br /&gt; + FullyQualifiedErrorId : CommandNotFoundException&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BUS FAULT when working with ASYNC UART</title><link>https://devzone.nordicsemi.com/thread/469065?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2024 14:40:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10509fee-ccae-49af-92b8-53ae42353885</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The bus fault occurs during the UARTE0 interrupt, likely within the callback. Please use addr2line on the &amp;#39;Faulting instruction address&amp;#39; to determine the corresponding code line.&lt;/p&gt;
&lt;p&gt;You can do this from the terminal in vs code. In vs code, press&amp;nbsp;&lt;b&gt;Ctrl+Shift+P&amp;nbsp;&lt;/b&gt;and select &amp;#39;nRF Connect: Open Toolchain Terminal Profile&amp;#39;. Then from the terminal, navigate to your project source directory and run the command below.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;$ arm-zephyr-eabi-addr2line -e build/zephyr/zephyr.elf  0x9e0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>