RTC interrupt problems

Hi,

I have a problem getting interrupts by the rtc component working. I am using the nrf58211 chip, nRF Connect SDK v. 1.9, uBlox BMD360-eval development board.

My code looks like this:

static nrfx_rtc_t powerdown_rtc = NRFX_RTC_INSTANCE(0);

static void powerdown_rtc_handler(nrfx_rtc_int_type_t int_type){
    nrfx_rtc_counter_clear(&powerdown_rtc);
}

void init_rtc(){
    IRQ_CONNECT(DT_IRQN(DT_NODELABEL(rtc0)),
                DT_IRQ(DT_NODELABEL(rtc0), priority),
                nrfx_isr, nrfx_rtc_0_irq_handler, 0);

    nrfx_rtc_config_t config = NRFX_RTC_DEFAULT_CONFIG;
    config.prescaler = RTC_FREQ_TO_PRESCALER(1); // set to 1 HZ
    nrfx_rtc_init(&powerdown_rtc, &config, powerdown_rtc_handler);
    nrfx_rtc_tick_disable(&powerdown_rtc);
    nrfx_rtc_counter_clear(&powerdown_rtc);

    nrfx_rtc_cc_set(&powerdown_rtc, 0, 5, true);
    nrfx_rtc_int_enable(&powerdown_rtc, NRF_RTC_INT_COMPARE0_MASK);
    nrfx_rtc_enable(&powerdown_rtc);
}

I want: An Interrupt to be triggered 5s after initialization.

What actually happens is: The board resets after 5s

The prj.conf contains

CONFIG_NRFX_RTC=y
CONFIG_NRFX_RTC0=y

Thank you for any hints and suggestions beforehand.

Kind Regards Tim

  • Hi Tim,

    Did you include the header file nrfx_rtc.h? If no, add

    #include "nrfx_rtc.h"

    If this was not your issue, then I'm going to need more information. Do you get any warnings/errors when building/flashing or running the code? I was not able to recreate any errors myself when testing your configuration.

    Edit: Add a print statement to your callback function to see if it works as intended. The following sample does what it is written to do without resetting the board

    #include <zephyr.h>
    #include <sys/printk.h>
    
    #include "nrfx_rtc.h"
    
    static nrfx_rtc_t powerdown_rtc = NRFX_RTC_INSTANCE(0);
    
    static void powerdown_rtc_handler(nrfx_rtc_int_type_t int_type){
        nrfx_rtc_counter_clear(&powerdown_rtc);
        printk("Inside callback\n");
    }
    
    void init_rtc(){
            printk("Initializing rtc\n");
        IRQ_CONNECT(DT_IRQN(DT_NODELABEL(rtc0)),
                    DT_IRQ(DT_NODELABEL(rtc0), priority),
                    nrfx_isr, nrfx_rtc_0_irq_handler, 0);
    
        nrfx_rtc_config_t config = NRFX_RTC_DEFAULT_CONFIG;
        config.prescaler = RTC_FREQ_TO_PRESCALER(1); // set to 1 HZ
        nrfx_rtc_init(&powerdown_rtc, &config, powerdown_rtc_handler);
        nrfx_rtc_tick_disable(&powerdown_rtc);
        nrfx_rtc_counter_clear(&powerdown_rtc);
    
        nrfx_rtc_cc_set(&powerdown_rtc, 0, 5, true);
        nrfx_rtc_int_enable(&powerdown_rtc, NRF_RTC_INT_COMPARE0_MASK);
        nrfx_rtc_enable(&powerdown_rtc);
    }
    
    void main(void){
    
            init_rtc();
            k_msleep(5000);
            printk("Hello World! %s\n", CONFIG_BOARD);
            // while(1){
            //         printk("Hello World! %s\n", CONFIG_BOARD);
    
            //         k_msleep(5000);
            // }
    
    }


    Kind regards,
    Andreas

  • Hello Andreas,

    thank you for your quick response. I must admit, i did not give you the full story. My code also uses the SoftDevice and TIMER1 and this seems to have issues (i persume soft device uses rtc0 in some sort).

    So if I use RTC0 the board crashes with the following printed at COM0

    If I use RTC1 i get a compile error

    I don't have that much time at the moment so I could not do a deeper analysis. Anyways, I am looking forward to receiving any suggestions.

    Best Regards

    Tim

  • Hi Tim

    TimK said:
    If I use RTC1 i get a compile error

    I was able to recreate the same error with RTC1. As far as I can see from this somewhat similar ticket for nRF5340, RTC1 is reserved for the Zephyr RTOS kernel timer which might cause the invocation of "Has IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times". I will keep on investigating if this is the same for a nRF52811 which you're working with, but in the meanwhile you may try to base your sample on the same zip-sample in that ticket (also added here).

    Regarding the first issue, did you get it by running both the same sample I posted in my previous reply as well as the full code you posted in your initial post?

     
    For investigating this you can check the function addresses that return causes the kernel oops by running the following lines in a cmd, but it will only work if you added GNUARMEMB to path, which you can verify by running the line in 1) in cmd.

    1) "where arm-none-eabi-addr2line"

    It should return something like this: "C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2015q3\bin\arm-none-eabi-addr2line.exe". 

    If it returns something that indicates that it is not on the path, you may try to follow this step in a manual installation guide.

    Then run the two following lines separately where you replace "<path to build\zephyr\zephyr.elf>" with the actual path

    2) "arm-none-eabi-addr2line -e <path to build\zephyr\zephyr.elf> 0x00010d06" for r15/pc

    and "arm-none-eabi-addr2line -e <path to build\zephyr\zephyr.elf> 0x0000c3cf" for r14/lr

    If 1) returns the path, then 2) should return the lines in which functions that causes the issue and might give us a clue about the issue.

    Let me know if any of this helps and your progress with the debugging. 

    Kind regards,
    Andreas

    4810.nrfx_rtc.zip

  • Hi Andreas,

    thank you very much for this detailed answer and general debugging help.

    The project you provided works for me as well but when I enable bluetooth (CONFIG_BT=y in prj.conf) the interrupts are not triggered anymore. My code works as well, when the SoftDevice is turned off.

    The reason for this is: SoftDevice uses RTC0 (like mentioned in this ticket https://devzone.nordicsemi.com/f/nordic-q-a/13264/using-rtc-driver-with-softdevice)

    If RTC1 is used by zephyr this only leaves me with RTC2, but I dont think my chip is equipped with a third RTC peripheral.

    Anyways my goal is to put my application into a powersaving mode for a few minutes and then send a bluetooth advertisement. I think I need to go with either a Zephyr or SoftDevice API to archieve this.

    Because my initial questioned is answered, I will close the ticket.

    Best regards

    Tim

    TLDR: Zephyr uses RTC1, SoftDevice RTC0 so they can't be used for your application

Related