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

About TIMER1_IRQHandler()

Hi, I want to start TIMER1 by a GPIO_TE. When the program enter the TIMER1_IRQHandler(), I want to disable the ppi. And when the program leave the TIMER1_IRQHandler(), I want to enable the ppi again. But I found once I disable the ppi, the program run to HardFault_Handler immediatly. It sames that I can't modefy ppi any more after program initial. It's the program(my sd is 6.0.0 and sdk is 5.2.0):

int main(void)
{
    ble_stack_init();
    gpiote_init();
    ppi_init();
    init_timer1();
    while(1){}
}

static void gpiote_init(void)
{
	APP_GPIOTE_INIT(1);
	nrf_gpiote_event_config(MF_GPIOTE_CHANNEL_NUMBER, KEY_START, GPIOTE_CONFIG_POLARITY_HiToLo);
}

static void ppi_init(void)
{
	sd_ppi_channel_assign(0, &NRF_GPIOTE->EVENTS_IN[MF_GPIOTE_CHANNEL_NUMBER], &NRF_TIMER1->TASKS_START);
	sd_ppi_channel_enable_set(1 << 0);
}

void init_timer1()
{
    NRF_TIMER1->PRESCALER = 1;
    NRF_TIMER1->TASKS_CLEAR = 1;
    NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
    NRF_TIMER1->CC[0] = 10;				

    NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
    NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk;

    NRF_TIMER1->EVENTS_COMPARE[0] = 0; 
    NRF_TIMER1->EVENTS_COMPARE[1] = 0;
    NRF_TIMER1->EVENTS_COMPARE[2] = 0;
    NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
    sd_nvic_SetPriority(TIMER1_IRQn, 1);
    sd_nvic_EnableIRQ(TIMER1_IRQn);
}

void TIMER1_IRQHandler()
{
    sd_ppi_channel_enable_clr(1 << 0);
    clear_timer1_event_compare();
    NRF_TIMER1->TASKS_STOP = 1;
    ......
    sd_ppi_channel_enable_set(1 << 0);
}
  • Hi,

    You are setting the priority of TIMER1 to 1 (NRF_APP_PRIORITY_HIGH), which has higher priority than the SVC handler that handles calls to sd_* functions. This would lead to a deadlock, so it produces a HardFault for you instead of endlessly consuming power.

    So currently you will have to leave out calls to sd_ functions within APP_HIGH IRQs. The low application priority (3) is lower than SVC, and would allow you to do what you try to do.

    Please also have a look at the answer to this question: devzone.nordicsemi.com/.../

Related