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.