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

LPCOMP in NCS-Zephyr on NRF52

I'm trying to get LPCOMP working on Zephyr - I have used the vanilla NCS sample as a baseline and have set up the event handler and the init function. 

The problem is that this fatal fault occurs:

[00:00:00.006,225] <err> os: >>> ZEPHYR FATAL ERROR 1: Unhandled interrupt on CPU 0

[00:00:00.006,225] <err> os: Current thread: 0x200039f0 (unknown)

[00:00:00.322,540] <err> fatal_error: Resetting system

After speaking to some of the guys on the Zephyr Slack, apparently this is happening because I need to use IRQ_CONNECT() in order to register the callback/handler. This information is obviously not in the NCS sample. I looked at the Zephyr NRFX sample for using IRQ with GPIOTE and it doesn't use IRQ_ENABLE(), which the documentation says you should use, so I'm very confused.

Could you please help by telling me how I should call this and with what arguments? I just want a simple LPCOMP interrupt on Zephyr

Below is my init and handler:

static void lpcomp_event_handler(nrf_lpcomp_event_t event)

{

    if (event == NRF_LPCOMP_EVENT_DOWN)

    {

        //bsp_board_led_invert(BSP_BOARD_LED_0); // just change state of first LED

        led1_on(false);

        voltage_falls_detected++;

        //voltage_falls_total++;

    }

}

static void lpcomp_init(void)

{

    printk("Starting lpcomp setup\n");

    uint32_t                err_code;

    nrfx_lpcomp_config_t config = NRFX_LPCOMP_DEFAULT_CONFIG(NRF_LPCOMP_INPUT_2);

    // initialize LPCOMP driver, from this point LPCOMP will be active and provided

    // event handler will be executed when defined action is detected

    err_code = nrfx_lpcomp_init(&config, lpcomp_event_handler);

    printk("error code was %i\n", err_code);

    nrfx_lpcomp_enable();

    printk("finished lpcomp setup\n");

}

The handler is not called before the fatal crash/reboot.

Parents Reply
  • Thanks for your help Kenneth,

    I decided which parameters to use just from looking at the documentation; it might have been incorrect. I tried to use IRQ_DIRECT_CONNECT(COMP_LPCOMP_IRQn,..). as you say, but it seems that simply adding this stops the program from starting at all for some reason. I have set CONFIG_NRFX_LPCOMP=y in prj.conf already, and I've looked at that article but I don't really understand it much because their interrupt handler nrfx_spim_1_irq_handler isn't defined in the same C file so one would assume they're using a default interrupt handler... either way I have tried what they suggested to no avail.

    Is it possible for you to setup a simple LPCOMP sample in Zephyr? This doesn't exist yet, and would be VERY useful for myself and the community to understand how to get it working as there's nothing like it at the moment

Children
Related