Consistent kernel panics when using timer

I have two i2c modules on the same bus and I plan to have a common timer for both of these. one of these is a sensor and I only want to read the sensor values at a predefined interval. The next module is a LED flash/fade manager. But when I try to implement a common timer for both of these, the system crashes and reboot on its own. I am using NCS V2.0 with nrf52840. This is the log.

ASSERTION FAIL [((arch_is_in_isr() == 0) || ((timeout).ticks == (((k_timeout_t) {0})).ticks))] @ WEST_TOPDIR/zephyr/kernel/sem.c:121\n'
b'\r\t\n'
[1;31m<err> os: r0/a1:  0x00000004  r1/a2:  0x00000079  r2/a3:  0x00000019\x1b[0m\r\n'
[1;31m<err> os: r3/a4:  0x20001ee8 r12/ip:  0x2000864c r14/lr:  0x0002608f\x1b[0m\r\n'
[1;31m<err> os:  xpsr:  0x61000021\x1b[0m\r\n'
[1;31m<err> os: Faulting instruction address (r15/pc): 0x0002c968\x1b[0m\r\n'
[1;31m<err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0\x1b[0m\r\n'
[1;31m<err> os: Fault during interrupt handling\n'
1;31m<err> os: Current thread: 0x20002670 (unknown)\x1b[0m\r\n'
[1;31m<err> fatal_error: Resetting system\x1b[0m\r\xf0\r\n'

has anyone encountered this before ? Or any idea what is going on ? The same problem happens when I use individual timers for both of these i2c modules. Is there something I am doing wrong ? Any help will be appreciated. Additionally, I also have a ble and a uart module apart from all these.

Parents
  • Hi there,

    Can you share a minimal example that reproduces the issue on the development kit?

    regards

    Jared 

  • I think I found out the issue is. But Cannot figure out why this is happening. To reproduce the issue, execute the following steps in order.


    Create a timer and corresponding expiry callback function. At the timer expiry, fetch data from sensors.

    K_TIMER_DEFINE(m_global_timer,timer_expiry_cb,timer_stop_cb);
    k_timer_expiry_t timer_expiry_cb()
    {
        expiry_counter++;
        LedManager_TimerCallback();
        if(expiry_counter%5 == 0)
        {
            PTH_update();
        }
    }
    
    /*<The following function PTH_update() is in another file originally. Moved here for convenience>*/
    void PTH_update()
    {   
    		sensor_sample_fetch(dev);
    		sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
    		sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
    		sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
    }

    The crash happens only when I try to fetch the sensor values. Otherwise, it works fine. So, I believe it has something to do with timer expiry and reading sensor values API.
    Thanks for taking a look at this.

  • Hi,

    Sorry for the late reply.

    If you comment out PTH_update() do you still get the error? I'm not totally sure if it's LedManager_TimerCallback() or PTH_update() that causes the issue, but the error message indicates that you're getting an error because you're trying to grab a semaphore while in a interrupt context. Try putting whatever task that is causing the issue into a workqueue.

    regards

    Jared  

  • Hi,

    I solved the issue couple of days before employing the workqueue for PTH_update(). Thank you for responding though. So sorry that I forgot to close the case.I will mark your answer as solution and close the case right away. Thanks again.

Reply Children
No Data
Related