cancel
Showing results for 
Search instead for 
Did you mean: 

The best sequency to initialize RCT in STM32f37x

zdravko
Associate II
Posted on March 10, 2016 at 13:30

I've tried to access the document in the , but the result is 404 server error. 

What I'm trying to do is initialize a RCT clocked from HSE 12 MHz quarz. It's initializing after I restart it from the debugger several times, otherwise it's unable to initialize. Absolute mystery... Here is the code:

void RTC_Config(struct tm* ptm) {  RTC_InitTypeDef RTC_InitStructure;   RTC_TimeTypeDef  RTC_TimeStruct;  RTC_DateTypeDef RTC_DateStruct;   /* Enable the PWR clock */   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);   /* Allow access to RTC */   PWR_BackupAccessCmd(ENABLE);   /* For HSE no need of clock domain reset!!! */ //  RCC_BackupResetCmd(ENABLE); // RCC_BackupResetCmd(DISABLE);   /* Select the RTC Clock Source */ // RCC_HSEConfig(RCC_HSE_ON);  RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div32);   /* Configure the RTC data register and RTC prescaler */   RTC_InitStructure.RTC_AsynchPrediv = 0x7C;   RTC_InitStructure.RTC_SynchPrediv  = 0xBB7;   RTC_InitStructure.RTC_HourFormat   = RTC_HourFormat_24;   while(RTC_Init(&RTC_InitStructure)!=SUCCESS) {  /* Enable the RTC Clock */  RCC_BackupResetCmd(ENABLE);  RCC_BackupResetCmd(DISABLE);  RCC_RTCCLKCmd(ENABLE);  RTC_Init(&RTC_InitStructure);  RCC_RTCCLKCmd(DISABLE);  }   /* Set the time to 00h 00mn 00s AM */   RTC_TimeStruct.RTC_H12     = RTC_H12_AM;   RTC_TimeStruct.RTC_Hours   = ptm->tm_hour;   RTC_TimeStruct.RTC_Minutes = ptm->tm_min;   RTC_TimeStruct.RTC_Seconds = ptm->tm_sec;      RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);    RTC_DateStruct.RTC_Year = ptm->tm_year;  RTC_DateStruct.RTC_Month = ptm->tm_mon;  RTC_DateStruct.RTC_Date = ptm->tm_mday;  RTC_DateStruct.RTC_WeekDay = ptm->tm_wday;  RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);      /* Wait for RTC APB registers synchronisation */  RCC_RTCCLKCmd(ENABLE);   RTC_WaitForSynchro();  RTC_AlarmConfig(); }

2 REPLIES 2
Amel NASRI
ST Employee
Posted on March 14, 2016 at 15:36

Hi georgiev.zdravko,

The document you are looking for is

http://www.st.com/web/en/resource/technical/document/application_note/CD00248402.pdf

, but I don't that this is really what you need.

However, I suggest you have a look to the examples that you may find in standard peripheral library package under STM32F37x_DSP_StdPeriph_Lib_V1.0.0\Project\STM32F37x_StdPeriph_Examples\RTC.

You may start with one of the 5 examples available there to adapt it on your need.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

zdravko
Associate II
Posted on March 15, 2016 at 09:41

Mayla,

thank you for your answer. The first thing I've done is to try exactly the examples from the STM library. Actually the code I've shared is a modified version of one of those examples. The problem is that as far as I read all of those examples are based on LSE external low frequency oscillator which in my PCB is not available. Therefore I'm trying to use the HSE oscillator through the 32 frequency divider (

RCC_RTCCLKSource_HSE_Div32), but the problem is that the INITF flag comes not always or comes never after cold reset. Thus I'm asking for an algorithm  to initialize the RCT when using the HSE clock source.