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

Critical region called in handlers freeze app

I am trying to enable a critical section in handler. I need to update a sensitive global variable when a button event occurs, and the fact to enable/disable the interrupt freeze the app.

My code in the button event handler, the first APP_ERROR_CHECK is never reached and the app is freezed. For this test, I disabled all other places where I enable/disable interrupts :

static void gpiote_event_watch_button_1_toggle(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
	if(nrf_drv_gpiote_in_is_set(pin))
	{
		//Event was triggered on low-to-high signal
	
		uint32_t err_code;
		uint8_t is_nested_critical_region;
	
		//Disable interrupt
		err_code = sd_nvic_critical_region_enter(&is_nested_critical_region);
        //Following lines are never reached
		APP_ERROR_CHECK(err_code);      
	
		m_signal |= SIGNAL_REL_1;   // setting the requested bit
	
		//Enable interrupt
		err_code = sd_nvic_critical_region_exit(is_nested_critical_region);
		APP_ERROR_CHECK(err_code);
	}
}
Parents
  • Usual problem - calling softdevice functions from an interrupt context with higher priority than the SVC call. I'll assume that your GPIOTE IRQ priority is APP_PRIORITY_HIGH, if you want to call softdevice functions from it, it needs to be LOW, or you need to use the scheduler.

    And the app isn't "freezed", it's in the hardfault handler, hitting break in the debugger should show you that.

Reply
  • Usual problem - calling softdevice functions from an interrupt context with higher priority than the SVC call. I'll assume that your GPIOTE IRQ priority is APP_PRIORITY_HIGH, if you want to call softdevice functions from it, it needs to be LOW, or you need to use the scheduler.

    And the app isn't "freezed", it's in the hardfault handler, hitting break in the debugger should show you that.

Children
Related