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

nrf Timer with Zephyr

Hello,  i have configured the Timer1 as follows

ISR_DIRECT_DECLARE(timer_handler){

if (NRF_TIMER1->EVENTS_COMPARE[0]){
    NRF_TIMER1->EVENTS_COMPARE[0] = 0;
    gpio_pin_toggle(dev_GPIO1, DT_GPIO_LEDS_LED1_GREEN_GPIOS_PIN);
}
ISR_DIRECT_PM();
return 1;
}
void timer_init(void)
{
    IRQ_DIRECT_CONNECT(TIMER1_IRQn, 7, timer_handler, 0);
    irq_enable(TIMER1_IRQn);
    NRF_TIMER1->PRESCALER = 8; // 16Mhz / 2^8 = 62500
    NRF_TIMER1->CC[0] = 62500; // -> 1s
    NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos;
    NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
    NRF_TIMER1->TASKS_START = 1;
}

My expectations is that my LED toggles every second. But it does not do this. If I set a brakepoint in the line gpio_pin_toggle(dev_GPIO1, DT_GPIO_LEDS_LED1_GREEN_GPIOS_PIN); and switch on manually, the LED is toggling.

After a few investigations i get an MPU Fault:
[00:00:06.396,759] <err> os: ***** MPU FAULT *****
[00:00:06.396,789] <err> os: Instruction Access Violation
[00:00:06.396,789] <err> os: r0/a1: 0x00000000 r1/a2: 0x00000000 r2/a3: 0x00000001
[00:00:06.396,820] <err> os: r3/a4: 0x406100f4 r12/ip: 0x00003e80 r14/lr: 0x000050e1
[00:00:06.396,820] <err> os: xpsr: 0x60000000
[00:00:06.396,820] <err> os: Faulting instruction address (r15/pc): 0x406100f4
[00:00:06.396,850] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
[00:00:06.396,850] <err> os: Current thread: 0x20000380 (thread_fsm_id)
[00:00:07.070,800] <err> os: Halting system

What could be the problem? Is there a Sample for configuring the nrf timer with zephyr interrupt handling in a correct way? 
Related