У меня тоже не тактируется от HSE/128. Часы стоят на месте. От LSI часы идут.
Началось все с того что у меня перестал генерить часовой кварц. Несколько недель работал, потом перестал.
Похоже для STM это огромная проблема с RTC. Очень много постов с проблемами RTC.
Уже попробовал 3 вида кварцев, правда они все китайские нонеймы.
Пробовал без кондеров и с кондерами от 5 до 22 пФ.
Ставил резистор на 5 МОм.
Все без толку.
Код
/* Enable PWR and BKP clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* LSI clock stabilization time */
//for(i=0;i<5000;i++) {; }
if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) {
/* Backup data register value is not correct or not yet programmed (when
the first time the program is executed) */
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Reset Backup Domain */
BKP_DeInit();
/* Enable LSE */
RCC_LSEConfig(RCC_LSE_ON);
// enable LSI
RCC_LSICmd(ENABLE);
/* Wait till LSE is ready */
os_dly_wait(10*SEC);
// while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
// {
//
// }
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
// LSE is not ready
// select HSE/128 as RTC clock source
#warning dont' forget
//RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div128);
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Enable RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 1sec */
//RTC_SetPrescaler((HSE_VALUE/128)-1);
RTC_SetPrescaler(62499);
printf("RTC clock source is HSE/128\r\n");
}
else
{
/* Select LSE as RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 1sec */
RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
printf("RTC clock source is LSE\r\n");
}
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Set initial value */
RTC_SetCounter( (uint32_t)((11*60+55)*60) ); // here: 1st January 2000 11:55:00
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
/* Lock access to BKP Domain */
PWR_BackupAccessCmd(DISABLE);
} else {
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
}