<?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>Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112689/trying-to-figure-out-a-bus-fault-error-zephyr-nrf52840</link><description>Hey all, 
 I&amp;#39;m looking for a bit of guidance here to nail a bus fault that happens about 30 minutes into the program. 
 The message is the following: 
 
 Reading through previous threads I found some information: 
 
 That tells me that the error seems</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Jul 2024 13:31:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112689/trying-to-figure-out-a-bus-fault-error-zephyr-nrf52840" /><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492286?ContentTypeID=1</link><pubDate>Thu, 04 Jul 2024 13:31:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bec85817-c6b6-42d6-b990-4d6844eaec14</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Alberto,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m&amp;nbsp;happy to hear you found the problem! Thank you for the update.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492283?ContentTypeID=1</link><pubDate>Thu, 04 Jul 2024 13:28:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1003af44-b412-4859-a150-fb3a6162c732</guid><dc:creator>Albert_0</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;The overflow was on the buffer because the index was getting bigger than it should have.&lt;/p&gt;
&lt;p&gt;I ran some tests for the last four and a half hours and it all seems to work well. Some issues were also due to some checksum errors, and I added additional checks to prevent accessing buffers out of boundaries.&lt;/p&gt;
&lt;p&gt;Thanks you very much for the help, I&amp;#39;m happy how this is working now and I think all is solved.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Alberto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492281?ContentTypeID=1</link><pubDate>Thu, 04 Jul 2024 13:22:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a162263-c69a-4340-b2cf-9785feb1b678</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi Alberto,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Maybe the&amp;nbsp;overflow could be in the &amp;#39;controller_receive_buf&amp;#39; or the &amp;#39;controller_data_buf&amp;#39; buffer. They are pretty close to the &amp;#39;adc_filt_idx&amp;#39; in RAM.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1720099308977v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492165?ContentTypeID=1</link><pubDate>Thu, 04 Jul 2024 05:50:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02c39fdd-4d2a-47f5-9819-18bef802c129</guid><dc:creator>Albert_0</dc:creator><description>&lt;p&gt;Hey Vidar,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks, sure, I can upload the map file.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5141.zephyr.map"&gt;devzone.nordicsemi.com/.../5141.zephyr.map&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I had some progress. I noticed one pipe where the error was happening had a different buffer size than defined originally, it was larger, so that was overwriting the other pipe I believe. That issue has been solved.&lt;/p&gt;
&lt;p&gt;The test ran now for over 3 hours, unfortunately, there was another bus crash somewhere else which I need to look at now... baby steps.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1720072132516v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1720072197364v2.png" /&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll try to find out where the error happened now.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Alberto&lt;/p&gt;
&lt;p&gt;Edit:&lt;/p&gt;
&lt;p&gt;Looks like another overflow somewhere else...&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1720072354151v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1720072369050v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;That value does not look right...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492160?ContentTypeID=1</link><pubDate>Thu, 04 Jul 2024 05:36:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a538fa91-0a30-461f-8b09-a490ac38695f</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Alberto,&lt;/p&gt;
&lt;p&gt;Thanks for the update. It does look like there is a buffer overrun that is overwriting more than just the thread object. Maybe you can post the zephyr.map file here. It might provide some clues even though we haven&amp;#39;t seen the source code.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492145?ContentTypeID=1</link><pubDate>Thu, 04 Jul 2024 01:10:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e1ce2e0-cb81-46ef-bd52-7ac1256886a1</guid><dc:creator>Albert_0</dc:creator><description>&lt;p&gt;I was able to attach the debugger and it stopped at the fault. I&amp;#39;m also able to look at the variables and the call stack, and the fault is close to where I expected it to be.&lt;/p&gt;
&lt;p&gt;I also noticed that one of the k_pipes I&amp;#39;m using for data buffering seems to be corrupt. This is a normal pipe with OK values (not sure what &amp;quot;buffer&amp;quot; refers to):&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1720055326487v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;The one causing the issue looks like:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1720055366855v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sure I must be corrupting it somewhere.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll see what else I can find. Thanks for your input so far.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Alberto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492037?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 10:58:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7671d131-a0b0-40cf-8284-a5dc74c0ef2e</guid><dc:creator>Albert_0</dc:creator><description>&lt;p&gt;I ran a test increasing the stack for that thread to double the size. In the end that didn&amp;#39;t help. It may have lasted a few minutes longer, but I&amp;#39;m not sure, in the end it felt it failed in the same position.&lt;/p&gt;
&lt;p&gt;I will try with the debugger connected tomorrow and disable the reset on hard fault. I will also look at the variables in the map file. Unfortunately the problem seems to happen on a Zephyr file, and I don&amp;#39;t have so much experience with Zephyr OS other than as user.&lt;/p&gt;
&lt;p&gt;Thanks for confirming the&amp;nbsp;0x80bf68b4 is rubbish, and I have a few places I can look at.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll keep you posted.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Alberto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492031?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 10:17:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab1204fe-574e-4974-93cb-c1f8228b4f6a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thank you&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/turboj"&gt;Turbo J&lt;/a&gt;&amp;nbsp;.&lt;/p&gt;
&lt;p&gt;Alberto, to avoid the hardfault reset during, you may temporalily disable the&amp;nbsp;CONFIG_RESET_ON_FATAL_ERROR setting in your release build. This will cause the program enter an infinte loop in the fault handler.&amp;nbsp;You can then&amp;nbsp;use Segger Ozone or nrfjprog to inspect the memory. Remember to select &amp;quot;attach to running target&amp;quot; if using Ozone so the chip does not reset.&lt;/p&gt;
[quote userid="18935" url="~/f/nordic-q-a/112689/trying-to-figure-out-a-bus-fault-error-zephyr-nrf52840/492006"]Its usually simpler to check the map file what sturctures and varables are &amp;quot;close to&amp;quot; the k_thread structure thats getting trashed and check code that touches these for BO.[/quote]
&lt;p&gt;This is a good suggestion. You can check the name of the &amp;#39;struct k_thread&amp;#39; variable(s) you have declared in your application and then look up their addresses in the build/zephyr/zephyr.map file.&lt;/p&gt;
&lt;p&gt;Reading memory with nrfjprog&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;$ nrfjprog --memrd &amp;lt;insert RAM address here&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492006?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 08:46:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93f8199b-e5e9-4bc9-bba3-30426d3f3e00</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;You would have to catch the crash with a connected debugger - a&amp;nbsp; hard fault reset will likely just overwrite that structure in RAM.&lt;/p&gt;
&lt;p&gt;Won&amp;#39;t help you much in buffer overflow cases - the cow has already turned into hamburger at this point in time.&lt;/p&gt;
&lt;p&gt;Its usually simpler to check the map file what sturctures and varables are &amp;quot;close to&amp;quot; the k_thread structure thats getting trashed and check code that touches these for BO.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/492001?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 08:38:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08e1ebc1-41e1-471f-807b-50c83b91d614</guid><dc:creator>Albert_0</dc:creator><description>&lt;p&gt;Hey Vidar, Turbo J,&lt;/p&gt;
&lt;p&gt;I will try by increasing the stack size, that is my first suspicion, everything else seems to work well.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/vibe"&gt;Vidar Berg&lt;/a&gt;&amp;nbsp;I&amp;#39;m not sure how to check the &amp;#39;struct k_thread&amp;#39; variables after the crash... I don&amp;#39;t have the debugger connected or running. The firmware is compiled in release mode, I have access to J-Link, but it would take me some time to figure out how to check the variables using Ozone. And of course, after the crash, the unit resets... but I&amp;#39;ll look into it.&lt;/p&gt;
&lt;p&gt;Any other way I can check the k_thread variables after the crash?&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Alberto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/491970?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 07:08:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cca25ff6-76d9-49d6-9b1d-ce13df5b85db</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello Alberto,&lt;/p&gt;
&lt;p&gt;It looks like the bus fault is&amp;nbsp;caused by &amp;#39;thread&amp;#39; pointer passed as the first argument to pipe_walk_op() being corrupted. &amp;#39;&lt;span&gt;0x80bf68b4&amp;#39; and &amp;#39;0x80bf68c8&amp;#39; does not map to any valid memory on the device, and the fault&amp;nbsp;is triggered&amp;nbsp;as soon as the function tries to assign the &amp;#39;pipe descriptor&amp;#39; from the corrupt thread struct pointer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;t&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1719985763576v1.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I suspect the thread struct is being overwritten elsewhere in your appliction, maybe by a buffer overrun. A stack overflow should normally&amp;nbsp;have been caught by the stack guard. Though, increasing the stack sizes are worth a try.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Are you able to check&amp;nbsp;the&amp;nbsp;&amp;#39;&lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;k_thread&amp;#39; variables&amp;nbsp;&lt;/span&gt;&lt;span&gt;in your application after the crash to see if they have been overwritten?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trying to figure out a bus fault error (Zephyr + NRF52840)</title><link>https://devzone.nordicsemi.com/thread/491961?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2024 06:12:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:472dcfb5-5c66-41ac-9d8d-9935768cda73</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;You are looking at a stack overflow that has overwritten important thread information that the scheduler uses when switching between threads.&lt;/p&gt;
&lt;p&gt;Can happen when you increase (or tun on) logging levels. Try a bigger stack for that thread.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>