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

RTC2 overwrite confiugration

I want to use the RTC Tick Event as my system tick. But on both the RTC0 and RTC1 my programm freezes after about 8min.

It looks like the Tick interrupt is still served (I toggled a pin on the interrupt) but the programm execution is stopped, due it does not leave the __WFI() insturction.

When I use the RTC2, the prescaler value I use is ignored (still 0).

I have the secure bootloader for usb programmed with the softdevice s140. Following my initialization of the RTC:

static void rtc_init()
{
  NRF_RTCx->TASKS_STOP = 1;
 
  NRF_CLOCK->EVENTS_LFCLKSTARTED  = 0;
  NRF_CLOCK->TASKS_LFCLKSTART     = 1;
  while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {}

  NRF_RTC1->EVENTS_TICK = 0;

  NVIC_ClearPendingIRQ(RTCx_IRQn);
  NVIC_EnableIRQ(RTCx_IRQn);
 
  NRF_RTCx->PRESCALER = TICK_PRESCALER; // = 31
  NRF_RTCx->EVTENSET = RTC_EVTEN_TICK_Msk || RTC_EVTEN_OVRFLW_Msk;
  NRF_RTCx->INTENSET = RTC_INTENSET_TICK_Msk || RTC_INTENSET_OVRFLW_Msk;

  NRF_RTCx->TASKS_START = 1;
}

and my irq handler:

void RTC1_IRQHandler(void)
{
  NRF_RTC1->EVENTS_TICK = 0;
  ms_tick++;
  flags.sys_tick = SET;  
}

I use a custom board with the NRF52840

EDIT

I now figured out, that the reason for the freezing is an unhandled interrupt form the RTC2. In my application code I never initialize the RTC2 but it is running with interrupt for overflow enabled. This explains, why the use of RTC0/RTC1 freeze after 512 seconds (=> unhandled overflow interrupt from RTC2).

But I still don't know why and where RTC2 is configured? Even if I configure the RTC2 on my own, the values are overwritten (as already written above). This only happens if I use my code with the secure bootloader (usb) and softdevice programmed (but not used yet).

Parents
  • It turned out, that the RTC2 is still configured and runnig from the bootloader. Should it not be deactivated at the end of the bootloader?

    I coulnd't confiugre the prescaler of the RTC2 because it was still running (to less time between NRF_RTC2->TASKS_STOP = 1 and write to the Prescaler register). Is there a proper way for waiting for the RTC2 has stopped? Now im doing it with:

    while(NRF_RTC2->PRESCALER != TICK_PRESCALER){
        NRF_RTC2->PRESCALER = TICK_PRESCALER;
      }

Reply
  • It turned out, that the RTC2 is still configured and runnig from the bootloader. Should it not be deactivated at the end of the bootloader?

    I coulnd't confiugre the prescaler of the RTC2 because it was still running (to less time between NRF_RTC2->TASKS_STOP = 1 and write to the Prescaler register). Is there a proper way for waiting for the RTC2 has stopped? Now im doing it with:

    while(NRF_RTC2->PRESCALER != TICK_PRESCALER){
        NRF_RTC2->PRESCALER = TICK_PRESCALER;
      }

Children
Related