AnsweredAssumed Answered

STM32F334 and RTC Setup

Question asked by Manu Abraham on Mar 28, 2017
Latest reply on Mar 28, 2017 by Lekkerkerker.Peter



I have a STM32F334 with a cylindrical watch 32.768kHz xtal connected as a LSE oscillator. LSE now works. Folks on the forum, were kind enough to point out to me about possible PCB related issues.Originally, I've had a EPSON SMD crystal in there.


Found a multitude of problems in there after digging into the issue, the first problem was a dead 32.768kHz crystal. Many trials later, tried the same crystal connected to a HEF4060 on a veroboard to test the crystal, which verified that the crystal was dead. Tried a cylindrical watch crystal with the HEF4060 and it worked. Tried the same cylindrical crystal in the same position, which did not work at all. The PCB design issue came to my mind, eventually stuck the crystal on top of the F334 and soldered the pins directly on to the F334.


Unfortunately, this also did not help. After pulling out some hair, I found that for the LSE to be turned ON, the RTC domain had to be reset, which allowed the LSE to be turned ON.


This now works, I can turn ON the LSE, can see the MCO output as well as the RTC_CALIB_OUT.


This but raises yet another concern. Everytime, I reset the CPU, the LSE is turned OFF/ON, as a result the RTC setting gets messed up. I am wondering how to avoid the RTC getting messed up.


Any thoughts/suggestions ?




void rtc_setup(void)
    RTC_InitTypeDef rtc;


    __PWR_CLK_ENABLE();                /* Enable the PWR clock */


     * After reset, the Backup Domain Registers (RCC BDCR Register,
     * RTC registers and RTC backup registers) are protected against
     * possible stray write accesses.
     * To access the Backup domain, it must be explicitly enabled
     * The change takes effect, only at RESET and hence must be
     * RESET cycled.
    __RTC_DOMAIN_WR_ENABLE();            /* Allow access to RTC */
    __RTC_DOMAIN_RST_ENABLE();            /* Reset RTC Domain */


    __RTC_LSEBYPASS_DISABLE();            /* disable LSE bypass    */
    __LSE_ON();                    /* and switch LSE on    */
    while (!__LSE_RDY());                /* Wait until LSE is ready */


    __RTC_CLKSRC_LSE();                /* Select the RTC Clock Source */
    __RTC_CLK_ENABLE();                /* Clock enable        */
    RTC_WaitForSynchro();                /* Wait for RTC APB registers synchronisation */


    RCC_MCOConfig(RCC_MCOSource_LSE, RCC_MCOPrescaler_128);    /* Configure MCO clock source */


    /* Configure the RTC data register and RTC prescaler */
    rtc.RTC_AsynchPrediv = 0x7F;
    rtc.RTC_SynchPrediv  = 0xFF;
    rtc.RTC_HourFormat   = RTC_HourFormat_24;


    __RTC_CALIBOUT_512Hz();                /* RTC_CALIB Selection (1Hz or 512Hz)*/
    __RTC_CALIBOUT_ENA();                /* RTC clock output */


int main(void)
    RTC_TimeTypeDef t;

    SysTick_Config(SystemCoreClock / 1000);        /* SysTick event @1ms        */


    putstr(USART1, "\r\n========================\r");
    putstr(USART1, "   RTC Debug\r");
    putstr(USART1, "========================\r\n");





    while (1) {
            RTC_GetTime(RTC_Format_BIN, &t);