RTC time counter doesn't work on K64

Hi guys,

I’m working with a RTC peripheral on K64 with external 32,768Khz clock and the time counter doesn’t seem to work. In other words, the RTC->TSR content stay the same. I verified on the XTAL output and the oscillator is working correctly.

There is my init :

rtc_config_t RTC_config = {
.wakeupSelect = false,
.updateMode = false,
.supervisorAccess = false,
.compensationInterval = 0x0U,
.compensationTime = 0x0U
};

dateTime_st.u16Year = 2021;
dateTime_st.u8Month = 11;
dateTime_st.u8Day = 24;
dateTime_st.u8Hour = 8;
dateTime_st.u8Min = 54;
dateTime_st.u8Sec = 00;

/* RTC initialization */
RTC_Init(RTC, &RTC_config);

/* Select RTC clock source */
RTC_SetClockSource(RTC); // Same as : RTC->CR |= RTC_CR_OSCE_MASK;

/* Stop RTC timer */
RTC_StopTimer(RTC); // Same as : RTC->SR |= ~RTC_SR_TCE_MASK;

/* Date and time initialization */
RTC_SetDatetime(RTC, (rtc_datetime_t *) &dateTime_st);

/* Start RTC timer */
RTC_StartTimer(RTC); // Same as : RTC->SR |= RTC_SR_TCE_MASK;

My clock sources and diagram configuration :

Any idea ?

Thank you by advance.

Best regards.

Mota

This isn’t a FreeRTOS question so you probably won’t get much help here. It looks pretty much like the RTC example and your code works on my K26 board so it seems like it should work. The one part you don’t show is the setup of the oscillator but you said it is working. So I dunno. Have you tried running the RTC example on their FRDM-K64 board?

Hi @maboytim,

Thank you for answered me quickly :slight_smile:.

There is the setup of my oscillator (It’s automaticaly genereted when I setup the clock sources) :

static void CLOCK_CONFIG_SetRtcClock(uint32_t capLoad, uint8_t enableOutPeriph)
{
  /* RTC clock gate enable */
  CLOCK_EnableClock(kCLOCK_Rtc0);
  if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) { /* Only if the Rtc oscillator is not already enabled */
    /* Set the specified capacitor configuration for the RTC oscillator */
    RTC_SetOscCapLoad(RTC, capLoad);
    /* Enable the RTC 32KHz oscillator */
    RTC->CR |= RTC_CR_OSCE_MASK;
  }
  /* Output to other peripherals */
  if (enableOutPeriph) {
    RTC->CR &= ~RTC_CR_CLKO_MASK;
  }
  else {
    RTC->CR |= RTC_CR_CLKO_MASK;
  }
  /* Set the XTAL32/RTC_CLKIN frequency based on board setting. */
  CLOCK_SetXtal32Freq(BOARD_XTAL32K_CLK_HZ);
  /* Set RTC_TSR if there is fault value in RTC */
  if (RTC->SR & RTC_SR_TIF_MASK) {
    RTC -> TSR = RTC -> TSR;
  }
  /* RTC clock gate disable */
  CLOCK_DisableClock(kCLOCK_Rtc0);
}

And it’s call in my main() by :

BOARD_InitBootClocks();

In other hand, I see my 32Khz crystal oscillation on the scope in XTAL. I use VBAT too as shown :

I don’t have FRDM-K64 board to test these kind of examples and I’m working with a MK64FX512xxx12 instead of MK64FN1M0xxx12 :frowning:.

My bad for posting here. Next time I’ll post on the right section.

Thank you.

Regards,

Mota

Hi Mota,

I think it’s okay to post this question here, but it’s not a FreeRTOS question so I’m not sure you will find much help here. I think it is useful to have a standard dev board so that you can run examples and see them work, even if it’s not the exact chip that you are using (the closer the better though). It’s seems a little suspicious that CLOCK_CONFIG_SetRtcClock() would disable the module clock at the end but I assume it’s re-enabled again later otherwise I think you would get a fault accessing the RTC. The K26 stuff looks a little different - I don’t see any RTC clock init in Board_InitBootClocks() it’s all in RTC_Init(). I’m not sure what to suggest.

Matt

To maintain the value of this resource to FreeRTOS users the preference is to keep this forum focused on FreeRTOS only.

Hi Matt,

Effectively, the RTC is re-enable when RTC_Init() is call. I don’t really know what’s going wrong with it. I let you know if I find the answer.

Thank you very much for your time.

Regards,

Mota