<?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>MPU FAULT</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86630/mpu-fault</link><description>I am getting this fault when i try to run a observer handler where i have implemented semaphores. 
 
 And i cant figure out what this error code means 
 
 Thanks in advance</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 06 Apr 2022 09:27:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86630/mpu-fault" /><item><title>RE: MPU FAULT</title><link>https://devzone.nordicsemi.com/thread/362017?ContentTypeID=1</link><pubDate>Wed, 06 Apr 2022 09:27:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:264245da-2efc-47be-b494-7ff9ae0b8ec1</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Have you confirmed that it crashes&amp;nbsp;before it is able to return to main?&lt;/p&gt;
&lt;p&gt;If not, could you place similar prints before and after the k_sem_take call, and in your while loop, to get a better idea of exactly how far your program reaches?&lt;/p&gt;
&lt;p&gt;Looking at similar cases, it seems like this could be related to running out of space in your stack, but I&amp;#39;m not sure what in your program would cause this.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not able to easily see how you&amp;#39;ve set up your data processing stuff, is it running in its own thread that&amp;#39;s started by initiate_modules()?&lt;/p&gt;
&lt;p&gt;In that case, could it be that some thread keeps adding data to some queue that ends up overflowing?&lt;/p&gt;
&lt;p&gt;-Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MPU FAULT</title><link>https://devzone.nordicsemi.com/thread/361972?ContentTypeID=1</link><pubDate>Wed, 06 Apr 2022 07:40:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b9aaf5a-6af8-4f8f-86f0-121245d87472</guid><dc:creator>Khuong Huynh</dc:creator><description>&lt;p&gt;Here is a picture of the nRF terminal of the code running&lt;/p&gt;
&lt;p&gt;&lt;img height="351" src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1649230802222v1.png" width="281" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;As you can see the code runs according to my expectations until the &amp;quot;search&amp;quot; is done and then crashes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MPU FAULT</title><link>https://devzone.nordicsemi.com/thread/361891?ContentTypeID=1</link><pubDate>Tue, 05 Apr 2022 14:26:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d564dcd2-110a-4ea8-9f93-1f46f33185b1</guid><dc:creator>Khuong Huynh</dc:creator><description>&lt;p&gt;The code crashes when after the LOG_INF(&amp;quot;Asimuth search done&amp;quot;); in search.c line 36. When it tries to return to the main.c.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MPU FAULT</title><link>https://devzone.nordicsemi.com/thread/361886?ContentTypeID=1</link><pubDate>Tue, 05 Apr 2022 14:10:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:059fa0fe-2960-4a89-9888-40867fee71ca</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Thank you for explaining.&lt;/p&gt;
&lt;p&gt;Do you know exactly what line of code your program crashes on?&lt;/p&gt;
&lt;p&gt;-Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MPU FAULT</title><link>https://devzone.nordicsemi.com/thread/361876?ContentTypeID=1</link><pubDate>Tue, 05 Apr 2022 13:55:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40eae9b6-69d5-40ec-af23-ecdf59103972</guid><dc:creator>Khuong Huynh</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;I am trying to create an algorithm that uses an observer with an accept list to get the rssi value of an beacon(another NRF52DK). We are using an antenna switch that are giving us the possibility to measure the rssi value of two antennas.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The algorithm are supposed to activate the observer which&amp;nbsp;send the rssi values to a data processor, alternating between the antennas. Here I have used an semaphore to wait until the observer have processed x numbers of rssi values. After the observer have processed the rssi values it releases the semaphore which lets our algorithm &amp;quot;get&amp;quot; the values from the data processor. The algorithm does this x-amount of times before it ends.&lt;/p&gt;
&lt;p&gt;The error occurs after the algorithm are done, which makes the system to restart.&lt;/p&gt;
&lt;p&gt;When running the code, i get the correct values from the Logging i have implemented in the code.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Main c

#include &amp;quot;initiater.h&amp;quot;
#include &amp;quot;search.h&amp;quot;


#define LOG_MODULE_NAME app

K_SEM_DEFINE(my_sem,0,1);
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

int azimuth_reading[20][3];
int nulls_azimuth[1];
int min_encoder_search = 0;
int16_t max_encoder_search = 20;
int increment = 1;

void main(void)
{
	LOG_INF(&amp;quot;Hello World! %s\n&amp;quot;, CONFIG_BOARD);
	initiate_modules();
	k_sem_give(&amp;amp;my_sem);
	sweep_search(0, min_encoder_search, max_encoder_search,increment);
	k_sem_take(&amp;amp;my_sem, K_FOREVER);
	// if(err){
	// 	LOG_ERR(&amp;quot;err:%d&amp;quot;, err);
	// }
	while(1){

	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Search.c

#include &amp;quot;search.h&amp;quot;

#define LOG_MODULE_NAME SEARCHER
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

extern struct k_sem my_sem;

void sweep_search(bool state, int min_encoder_search, int16_t max_encoder_search, int increment){
    LOG_INF(&amp;quot;Starting to search in Azimuth&amp;quot;);
    int16_t readings[][3] = {0};
    int16_t index = 0;
    for (int i = 0; i &amp;lt; 10; i+= 1){
        //move_servo(state, i) bevege servo enten i asimuth til enkoder verdi i (ikke implementert enda)
        int16_t *buffer_data;
        LOG_INF(&amp;quot;started&amp;quot;);
        set_observer(true);
        LOG_INF(&amp;quot;waiting&amp;quot;);
        k_sem_take(&amp;amp;my_sem, K_FOREVER);
        LOG_INF(&amp;quot;next&amp;quot;);
        buffer_data = get_data();
        for (int i = 0; i &amp;lt; 3; i++){
            readings[index][i] = buffer_data[i];
        }
        int16_t encoder = readings[index][0];
        int16_t delta = readings[index][1];
        int16_t zigma = readings[index][2];
        LOG_INF(&amp;quot;Encoder: %d, Delta: %d, Zigma %d, i: %d: &amp;quot;,encoder, delta, zigma, index);
        index+=1;
       

    }

    k_sem_give(&amp;amp;my_sem);
    LOG_INF(&amp;quot;Azimuth search done&amp;quot;);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Observer.c

#include &amp;quot;observer.h&amp;quot;
#define LOG_MODULE_NAME Observer
#define average_counter 5
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

extern struct k_sem my_sem; 
bool send_data_state = true;

int set_observer(bool state){
	int err = 1;
	send_data_state = state;
	LOG_INF(&amp;quot;Observer state changed to %d&amp;quot;, send_data_state);
	return err = 0;

}

void set_switch(int state){
	//set gpio switch to value;
}

static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
			 struct net_buf_simple *ad)
{	
	if(send_data_state){
    	// rssi = KALMAN(rssi);
		static int counter = 0;
		static bool delta_zigma_state = false; // 0 = delta, 1 = zigma, 2 = done
		if(!delta_zigma_state){
			LOG_INF(&amp;quot;counter: %d, rssi: %d, zigma: %d&amp;quot;,counter,rssi,delta_zigma_state);
			send_data_delta(rssi, counter);
			counter +=1;
			if(counter &amp;gt;= average_counter){
				counter = 0;
				delta_zigma_state = true;
				
			}
		}
		else if(delta_zigma_state){
			LOG_INF(&amp;quot;counter: %d, rssi: %d, zigma: %d &amp;quot;,counter,rssi, delta_zigma_state);
			send_data_zigma(rssi, counter);
			counter += 1;
			if(counter &amp;gt;= average_counter){
				delta_zigma_state = false;
				counter = 0;
				set_observer(false);
				k_sem_give(&amp;amp;my_sem);
				LOG_INF(&amp;quot;given&amp;quot;);
				
			}
		}

	}

	else{LOG_INF(&amp;quot;rssi: %d&amp;quot;, rssi);}

	





}


int add_filter_accept_list_from_string(const char *addr_str,const char *type){
    int err;
	bt_addr_le_t addr_le = {.a = BT_ADDR_LE_ANY, .type = BT_ADDR_LE_RANDOM};
	err = bt_addr_le_from_str(addr_str, type, &amp;amp;addr_le);
	if (err){
		LOG_ERR(&amp;quot;error: %d&amp;quot;, err);
	}
	err = bt_le_filter_accept_list_add(&amp;amp;addr_le);
	if (err){
		LOG_ERR(&amp;quot;Could not add to acceptlist (error: %d)&amp;quot;, err);
		return err;
	}
    return err;
}


int init_bluethooth_scan(){

	struct bt_le_scan_param scan_param = {
		.type       = BT_LE_SCAN_TYPE_ACTIVE,
		.options    = BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST,
		.interval   = BT_GAP_SCAN_FAST_INTERVAL,
		.window     = BT_GAP_SCAN_FAST_WINDOW,
	};
	int err;
	LOG_INF(&amp;quot;Starting Observer\n&amp;quot;);
	/* Initialize the Bluetooth Subsystem */
	err = bt_enable(NULL);
	if (err) {
		LOG_ERR(&amp;quot;Bluetooth init failed (err %d)\n&amp;quot;, err);
		return err;
	}
    err = add_filter_accept_list_from_string(&amp;quot;C8:4A:E6:23:F5:13&amp;quot;, &amp;quot;(random)&amp;quot;);
	if (err){
		LOG_ERR(&amp;quot;Could not add to acceptlist (error: %d)&amp;quot;, err);
		return err;
	}    
	LOG_INF(&amp;quot;Bluetooth initialized\n&amp;quot;);

	err = bt_le_scan_start(&amp;amp;scan_param, device_found);
	if (err) {
		LOG_ERR(&amp;quot;Starting scanning failed (err %d)\n&amp;quot;, err);
		return err;
	}
	return err;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Dataprocessor.c

#include &amp;quot;data_processor.h&amp;quot;

#define LOG_MODULE_NAME DATA_PROCESSOR
#define average_counter 5
LOG_MODULE_REGISTER(LOG_MODULE_NAME);


int8_t data_delta[average_counter];
int8_t data_zigma[average_counter];

void send_data_delta(int8_t rssi, int index){
    data_delta[index] = rssi;
}
void send_data_zigma(int8_t rssi, int index){
    data_zigma[index] = rssi;
}

int16_t *get_data(){

    static int16_t buffer_data[3];
    buffer_data[0] = (int16_t) get_encoder();
    buffer_data[1] = (int16_t) get_average(data_delta);
    buffer_data[2] = (int16_t) get_average(data_zigma);

    return buffer_data;

}

int8_t get_average(int8_t *list){
    int16_t average = 0;
    int8_t size = average_counter;
    for(int i = 0; i &amp;lt; size; i++){
        average += list[i];
    }
    average = average/size;
    return (int8_t) average;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;prj.conf

# Configure logger
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=n
CONFIG_LOG_BACKEND_UART=y
CONFIG_LOG_DEFAULT_LEVEL=3

#From observer
CONFIG_BT=y
CONFIG_BT_OBSERVER=y

# Configure buttons and LEDs
CONFIG_GPIO=y
CONFIG_DK_LIBRARY=y

# Enable the BLE modules from NCS
CONFIG_BT_NUS_CLIENT=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_SCAN=y
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_UUID_CNT=1
CONFIG_BT_GATT_DM=y
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_BT_FILTER_ACCEPT_LIST=y
CONFIG_BT_SCAN_NAME_CNT=1

#Servomotors
CONFIG_GPIO=y
CONFIG_DK_LIBRARY=y


# Enable math.h
CONFIG_NEWLIB_LIBC=y

#vet ikke
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Hope this gives a better picture of what I am trying to implement.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks in advance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MPU FAULT</title><link>https://devzone.nordicsemi.com/thread/361866?ContentTypeID=1</link><pubDate>Tue, 05 Apr 2022 13:22:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8adbec34-e0d7-4b72-a81e-e1eb6cf1f8b8</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;It would probably help with a bit more context.&lt;/p&gt;
&lt;p&gt;What are you trying to do?&lt;/p&gt;
&lt;p&gt;Are your semaphores properly defined when you use them?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>