MPU FAULT occurs when creating a new thread

Good Day.

I get an MPU FAULT when creating a new thread where I want to display the RSSI value.

Looking at similar requests in the community, there were recommendations to increase CONFIG_MAIN_STACK_SIZE, I increased this parameter to 2048, but it didn't help. 

I have one thread (Priority = 7) in my program now (taken from the BLE example), it sends data over bluetooth. 

void send_data_thread(void)
{
	while (1) {
		/* Simulate data */
		simulate_data();
		/* Send notification, the function sends notifications only if a client is subscribed */
		my_lbs_send_sensor_notify(app_sensor_value);
		k_sleep(K_MSEC(NOTIFY_INTERVAL));
	}
}

K_THREAD_DEFINE(send_data_thread_id, 2048, send_data_thread, NULL, NULL, NULL, 7, 0, 0);

When adding a second thread (Priority = 8) that should read RSSI, an error occurs.

void rssi_thread(void)
{
	int8_t rssi = 0xFF;
	while(1){
		read_conn_rssi(default_conn_handle, &rssi);
		LOG_INF("RSSI level = %d\n", rssi);
		k_msleep(1000);
	}
}

K_THREAD_DEFINE(rssi_thread_id, 2048, rssi_thread, NULL, NULL, NULL, 8, 0, 0);

If I move all the code from rssi_thread() to main(), everything works without errors.

Can you please tell me what could be the reason?

Thanks.

Parents
  • Hi 

    I can't immediately spot why this would work from the main thread but not from your own thread. I assume something happens in the read_conn_rssi(..) function that doesn't play well with the second thread.

    Can you confirm that everything runs fine if you comment out the read_conn_rssi(..) function call, but keep everything else? 

    Best regards
    Torbjørn

  • Hi Torbjørn, thank you for your response.

    If I comment out the read_conn_rssi line in my thread, the thread starts and I see the message "RSSI level = -1". 

    So apparently the problem is really in the read_conn_rssi function call. Perhaps I need to pass some additional parameters to my thread - void rssi_thread(...........)? But I don't know which ones, because the read_conn_rssi function works normally without passing additional parameters to the main() thread.

Reply
  • Hi Torbjørn, thank you for your response.

    If I comment out the read_conn_rssi line in my thread, the thread starts and I see the message "RSSI level = -1". 

    So apparently the problem is really in the read_conn_rssi function call. Perhaps I need to pass some additional parameters to my thread - void rssi_thread(...........)? But I don't know which ones, because the read_conn_rssi function works normally without passing additional parameters to the main() thread.

Children
Related