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.
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?
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 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.