This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Application keep restarting after scheduler is not firing more queue events

Hi there devs,

### I UPDATED and reformulate the whole question after some finds ####

I am having an issue with my application which is really hard to replicate it could happens after 12 hours, 8 days, 1 month, 30s... 

My software Diagram:

After some time when the unknown issues happens, the queue get filled then my module resets because the scheduler is out of memory to queue more events

The symtom looks like app_sched_execute() is not being called in the main loop, it makes me believe my code gets stuck on a loop somewhere.

I was digging on my code looking for loops, then I have only 2 loops

1) I made a low Power Delay where I use a loop and sd_app_evt_wait() 

devzone.nordicsemi.com/.../creating-my-own-low-power-delay-using-app_timer

//source FILE

bool LowPowerDelay::delay;

LowPowerDelay::LowPowerDelay()
{
	app_timer_create(&LPDelay, APP_TIMER_MODE_SINGLE_SHOT, &LowPowerDelay::DelayCb);
}

void LowPowerDelay::DelayCb(void *p_context){	
	LowPowerDelay::delay = true;
}

void LowPowerDelay::Delay(uint32_t ms)
{
	LowPowerDelay::delay = false;
	app_timer_start(LPDelay, APP_TIMER_TICKS(ms), NULL);
	
	while (!LowPowerDelay::delay){
			APP_ERROR_CHECK(sd_app_evt_wait());
	}
}


//HEADER

ifndef _LOWPOWERDELAY
#define _LOWPOWERDELAY
#include "Headers.h"
#include "Timer.h"

APP_TIMER_DEF(LPDelay);

class LowPowerDelay
{
	public:
	LowPowerDelay();
	
		static LowPowerDelay * Instance()
		{
			static LowPowerDelay instance;
			return &instance;
		}	
	
	static void DelayCb(void *p_context);
	void Delay(uint32_t ms);
		
	static bool delay;
};
#endif

I used J-Scope to verified my code exits from this delay loop after I used RTT as well, then the issue is not here.

2) When perform TWI Write and Reads I have another loop where I wait for the transfer ends

void Twi::WaitForTransfer()
{
	while (Twi::GetInstance()->transferComplete)
	{	
	if(NRF_LOG_PROCESS() == false){     
			APP_ERROR_CHECK(sd_app_evt_wait());
		}
	}
}

now I am aiming the root of my issue could be the TWI loop, but I cant no replicate it, because randomly happens, for example after my device working after 26 hours it is ok at the moment

3) when the issue happens and the queue gets totally filled it  generate an error out of memory, app_error_fault_handler is called then calling  NVIC_SystemReset() after this software reset, the module restarts then the queue gets filled since the beginning generating another software reset and keep resetting because the queue get filled again, and again (please look my RTT log below in the replies)

software reset wont solves it

hardware reset solves it temporally until this unknown behavior happens again, and again

When the issue happens, the neither BLE or TWI sensor works because both depend on the scheduler for my application

Possible causes:

a) TWI hangs and wont fire a handler event with TX or RX (TWI IRQs disabled because the frequency initialization/uninitialization?)

b) External Module unresponsive (?)

Details:

Queue Size 80

SCHED_MAX_EVENT_DATA_SIZE = BLE_STACK_EVT_MSG_BUF_SIZE + 247 (MTU)

SDK 13, nRF52832

Regards,

Meli

Related