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);
}
}