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

APP_TIMER and RTC_TIMER_0 at the same time - problems

Good morning,

I have been asked to merge the code developed by two independent teams. Of course, each one of them took their decision on the management of time, and of course they took different ways :) . I am currently working on SDK 15.0.0

So, I have one program which is based on APP_TIMER (which uses RTC1) and the other one which uses RTC0 (as done in the example of SDK, under peripheral --> RTC). I know that RTC0 is used by the softdevice, but it does not matter, since we are using a proprietary protcol without softdevice.

The "master" program which uses some functionality of the other one is based on the RTC0; nonetheless the "slave" program uses several timers, so the APP_TIMER is a must. 

So, I was so far able to merge the softwares, to compile them and to program the NRF52832. The problem I am facing is that if I use only the RTC0 timer, the "master" program runs smoothly.

As soon as I call the app_timer_init() function, the program stops working. I was able to track down the problem to the single instruction

    NVIC_EnableIRQ(SWI_IRQn); 

in app_timer_init.c Without this instruction the "master" program run smoothly. But of course the app_timer does not work properly.

I tried to change the APP_TIMER_CONFIG_SWI_NUMBER defined in sdk_config.h to 1 or to 0, but in both cases I have the same issue.

So, my question is the following: is it possible that the definition of interrupts for RTC0 and RTC1 (app_timer) creates conflicts? 

Do you have any suggestion on how to avoid these issues?


If possible, I would like to avoid using the APP_TIMER for managing all the timers, since this would require quite some work....so essentially I would like to know if RTC0 and APP_TIMER could live and work together happily.....

Thank you!

  • I forgot to mention that the problem seems also related to a communication using the SPI.....If the NVIC_ENABLE_IRQ instruction is commented out everything works fine, otherwise it seems that the firmware is locked in a while cycle waiting for a _spi_xfer_over boolean to become true....is it possible that the app_timer interrupt interferes with the SPI interrupt?

  • Hi,

    There should not be any issues with using these resources together, but it could be that you have some priority issues in your application. Have you started the LFCLK? This is required by the RTC to be running.

    Can you post some code/example project that shows what you are doing and can be used to reproduce the issue?

    Best regards,
    Jørgen

  • Hello,

    sorry for the late reply, but I was on holidays until today.

    The code is pretty complex (and confidential), so I cannot really post pieces of it. Furthermore, I was not able to reproduce the issue on a clean project....if I have a simple project with the 2 timers, it works fine.

    What I can show is exactly where the problem happens, as I mentioned in my second comment.

    We are in the situation where the two timers (RTC0 and RTC1) have already been started, the LFCLK is correctly running and (apparently) everything goes without problems.

    The operation which blocks the system is a configuration of a peripheral using SPI configuration.

    The SPI is configured using the default config given by Nordic, i.e.

    #define NRF_DRV_SPI_DEFAULT_CONFIG                           \
    {                                                            \
        .sck_pin      = NRF_DRV_SPI_PIN_NOT_USED,                \
        .mosi_pin     = NRF_DRV_SPI_PIN_NOT_USED,                \
        .miso_pin     = NRF_DRV_SPI_PIN_NOT_USED,                \
        .ss_pin       = NRF_DRV_SPI_PIN_NOT_USED,                \
        .irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY,         \
        .orc          = 0xFF,                                    \
        .frequency    = NRF_DRV_SPI_FREQ_4M,                     \
        .mode         = NRF_DRV_SPI_MODE_0,                      \
        .bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST,         \
    }

    and the system is stuck at this operation

    	spi_xfer_done = false;
    
    	nrf_drv_spi_transfer(&spi_unit, tx, 1, rx, 1);
    	while (!spi_xfer_done)
    	{
    		__WFE();
    	}

    As mentioned before, if I run the same code but I comment out the instruction 

        NVIC_EnableIRQ(SWI_IRQn); 
    

    in the file app_timer.c , in function app_timer_init(void), the software is able to continue without blocking at the spi transfer.

    As you suggest in your comment, I too suspect that there is some issue with irq priorities, but changing them did not seem to fix the problem. I tried to modify the NRF_DRV_SPI_DEFAULT_CONFIG and to give it a higher priority (2 for example), but this did not seem to help.

    Any other suggestion would be greatly appreciated!

  • Where do you initialize the SPI transfer? Is it in main or interrupt context? How many app timers are you running, and do you start/stop these somewhere in the application?

Related