<?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>NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85493/nrf52833dk-persistent-hard-faults</link><description>I am developing an NRF52833 application that reads from the I2C sensor MLX90641. Below is the code I am using to test. MLX90641_I2C_Driver.c was originally written for Mbed and is meant to be adapted to the target platform. It isn&amp;#39;t important to understand</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Mar 2022 09:08:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85493/nrf52833dk-persistent-hard-faults" /><item><title>RE: NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/thread/357862?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2022 09:08:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e34e047-60db-43a4-a9f8-d33a73567052</guid><dc:creator>Sigurd</dc:creator><description>[quote user="rm_89"]This did the job, 8192 is enough and anything below that crashes. [/quote]
&lt;p&gt;Great!&lt;/p&gt;
[quote user="rm_89"]One last question, if main stack size was the culprit, why did the thread analyzer say that main stack was only at 28% usage when the crashes were happening?[/quote]
&lt;p&gt;I assume that there was a sudden peak in the stack usage, this caused the crash, and that the thread analyzer did not&amp;nbsp;have time to register or report this increase before the crash.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/thread/357786?ContentTypeID=1</link><pubDate>Sat, 12 Mar 2022 20:08:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8934c502-7f42-4b5b-90a0-3b7293357b6e</guid><dc:creator>rm_89</dc:creator><description>[quote userid="15146" url="~/f/nordic-q-a/85493/nrf52833dk-persistent-hard-faults/357573#357573"]CONFIG_MAIN_STACK_SIZE=16384[/quote]
&lt;p&gt;This did the job, 8192 is enough and anything below that crashes. So weird because I tried increasing to 2048 and 4096 initially and both caused the program to crash earlier than with 1024 so I never tried increasing it more.&lt;/p&gt;
&lt;p&gt;One last question, if main stack size was the culprit, why did the thread analyzer say that main stack was only at 28% usage when the crashes were happening?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/thread/357573?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2022 09:19:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3b5c4bd-61c8-46a0-aa8f-acf749edba74</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;1) the function MLX90641_I2CRead() is called from main thread context? correct?&lt;/p&gt;
&lt;p&gt;2) Any difference if you set&amp;nbsp;CONFIG_LOG2_MODE_IMMEDIATE=n ?&lt;/p&gt;
&lt;p&gt;3) Have you tried setting stack and heap to some very high numbers? e.g.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;# Stacks and heaps&lt;br /&gt;CONFIG_MAIN_STACK_SIZE=16384&lt;br /&gt;CONFIG_HEAP_MEM_POOL_SIZE=16384&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/thread/357569?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2022 09:07:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7a93c0c-e711-4f41-94e4-8c96b82e9d79</guid><dc:creator>rm_89</dc:creator><description>&lt;p&gt;Similar crash output, the addresses traceback to random zephyr source files related to timing:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/960x720/__key/communityserver-discussions-components-files/4/nrfcrash10.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;I also just installed NCS v1.9.1 and created a fresh VS Code workspace to recreate the project, pretty much the same errors still.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/thread/357565?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2022 09:01:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4605c608-7a80-48b1-9ea6-207128c5deef</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you try setting these, and see what information you get then.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_DEBUG=y
CONFIG_HW_STACK_PROTECTION=y&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/thread/357548?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2022 08:12:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6949a944-7a54-4b52-a0b0-52bcd6665254</guid><dc:creator>rm_89</dc:creator><description>&lt;p&gt;I&amp;nbsp;randomly added another&amp;nbsp;LOG_INF output outside of the function that crashes, and&amp;nbsp;the crash changed to &amp;quot;Usage Fault&amp;quot; and it seems the function gets slightly further along although the crash happens at a lower memory address as can be seen below.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/960x720/__key/communityserver-discussions-components-files/4/nrfcrash6.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;Instruction addresses traceback to random NRF/Zephyr files.&lt;/p&gt;
&lt;p&gt;And now, even weirder, when I comment out everything below line 24 in main.c, the program does not run at all and crashes with another different message seen below. How is this possible if the crash happens in the first function? I don&amp;#39;t see how removing code after this point should change anything, since it never even runs. It must be&amp;nbsp;some obscure ridiculous memory issue causing these crashes?&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/960x720/__key/communityserver-discussions-components-files/4/nrfcrash7.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;Once again, the faulting instruction addresses in r15 and r14 trace back to random zephyr code (log_output.c and cbprintf_complete.c)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/thread/356712?ContentTypeID=1</link><pubDate>Mon, 07 Mar 2022 19:17:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d74ac0a-5875-419a-b6f8-23477e193840</guid><dc:creator>rm_89</dc:creator><description>&lt;p&gt;I&amp;#39;ve now tried dynamically allocating memory, and I get a bus fault.&lt;/p&gt;
&lt;p&gt;prj.cnf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_I2C=y

CONFIG_TINYCBOR=y
CONFIG_CBOR_FLOATING_POINT=y

CONFIG_LOG=y
CONFIG_LOG2_MODE_IMMEDIATE=y

CONFIG_HEAP_MEM_POOL_SIZE=4096&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;main.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;

#include &amp;lt;kernel.h&amp;gt;

#include &amp;lt;logging/log.h&amp;gt;
LOG_MODULE_REGISTER(TTPMS);

#include &amp;quot;MLX90641_API.h&amp;quot;
#include &amp;quot;MLX90641_I2C_Driver.h&amp;quot;

#define TA_SHIFT 8 //Default shift for MLX90641 in open air

static float mlx90641To[768];
paramsMLX90641 mlx90641;

void main(void)
{
	LOG_INF(&amp;quot;Running sensor_testing on %s&amp;quot;, CONFIG_BOARD);

	MLX90641_I2CInit();

	int status;
    //uint16_t eeMLX90641[832];
	uint16_t *eeMLX90641;
	eeMLX90641 = k_malloc(832*sizeof(uint16_t));
	if (eeMLX90641 != NULL) {
		memset(eeMLX90641, 0, 832*sizeof(uint16_t));
		LOG_INF(&amp;quot;Memory allocation succeeded&amp;quot;);
	} else {
		LOG_INF(&amp;quot;Memory allocation failed&amp;quot;);
	}
    status = MLX90641_DumpEE(MLX90641_ADDR, eeMLX90641);
    if (status != 0) {
        printk(&amp;quot;Failed to load system parameters\n&amp;quot;);
    }
	
    status = MLX90641_ExtractParameters(eeMLX90641, &amp;amp;mlx90641);
    if (status != 0) {
        printk(&amp;quot;Parameter extraction failed\n&amp;quot;);
    }
	k_free(eeMLX90641);

	while(1) {
		for (uint8_t x = 0 ; x &amp;lt; 2 ; x++) { //Read both subpages
			uint16_t mlx90641Frame[834];
			int status = MLX90641_GetFrameData(MLX90641_ADDR, mlx90641Frame);
			if (status &amp;lt; 0) {
				printk(&amp;quot;GetFrame Error: %d\n&amp;quot;, status);
			}

			float vdd = MLX90641_GetVdd(mlx90641Frame, &amp;amp;mlx90641);
			float Ta = MLX90641_GetTa(mlx90641Frame, &amp;amp;mlx90641);

			float tr = Ta - TA_SHIFT; //Reflected temperature based on the sensor ambient temperature
			float emissivity = 0.95;

			MLX90641_CalculateTo(mlx90641Frame, &amp;amp;mlx90641, emissivity, tr, mlx90641To);
    	}

		for (int x = 0 ; x &amp;lt; 10 ; x++) {
			printk(&amp;quot;Pixel %d: %fC\n&amp;quot;, x, mlx90641To[x]);
		}

		k_sleep(K_SECONDS(1));
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Log output:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/nrfcrash5.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;addr2line on r14/lr: 0x00008047 goes to SEGGER_RTT.c line 948&lt;/p&gt;
&lt;p&gt;Interesting to note that the crash happens before the program even gets to&amp;nbsp;LOG_INF on the first line of MLX90641_I2CRead&lt;/p&gt;
&lt;p&gt;UPDATE: If I include string.h in main.c, the crash turns into an MPU_FAULT but happens at the same address traced back to SEGGER_RTT.c&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52833DK Persistent Hard Faults</title><link>https://devzone.nordicsemi.com/thread/356465?ContentTypeID=1</link><pubDate>Mon, 07 Mar 2022 06:01:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fd44da8-72ea-4b9c-9857-b78746939024</guid><dc:creator>rm_89</dc:creator><description>&lt;p&gt;As stated in the original post, increasing CONFIG_MAIN_STACK_SIZE causes an immediate bus fault crash and the program does not even start. I just tried reducing the CONFIG_MAIN_STACK_SIZE to 512 (default is 1024) and now the program got further along (cnt: 575) but it crashed at the exact same memory address, 0x20001b60. I am now almost certain this is an issue with Zephyr/NRF52833 memory regions rather than faulty code. Sidenote: I&amp;#39;m now using LOG_INF with LOG2_MODE_IMMEDIATE instead of printk.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/nrfcrash4.jpg" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>