2019-03-07 06:04 AM
Hello,
On STM32F429, I'm using RTC. It is clocked by the 32KHz LSI.
I set async prescaler register to 127 and Sync prescaler register to 249.
The total prescaling factor will be 250*128 = 32 000.
Exactly what I need to provide 1Hz to RTC.
After testing, it appears that RTC is faster that true time about 17s after runing 5 minutes, more or less 5.6%.
What can happen?
I don't think there's a impact but I'm using freeRTOS.
void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/**Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 72;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 3;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
Error_Handler();
}
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
Error_Handler();
}
}
<....>
RTC_HandleTypeDef hrtc;
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 249;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK) {
Error_Handler();
}
Thanks
Julien
2019-03-07 06:31 AM
Isn't the F2/F4 running closer to 37KHz?
Your options here are to feed LSI out of MCO (or wherever) and scope it, or use the TIM it can be attached too and measure the periodicity wrt HSE
2019-03-07 06:57 AM
How about reading a datasheet?
https://www.st.com/resource/en/datasheet/stm32f429ve.pdf
I think section 6.3.10 is clear enough...
2019-03-07 09:39 AM
Sorry fell off my chair, hadn't looked at that in a while, thing's got a span of 30 KHz.... HMOF
2019-03-07 09:44 AM
2019-03-07 10:33 AM
Ah ! ah ! Clive. I did the same !..
Thanks for your answers. They helped a lot.
I should have put a quartz on the board but I've already ordered the pcbs.
So what I did : I computed the prescaler by comparing the RTC to a quartz driven timer.
Of course, it's not super accurate but far better than no computation at all and enough for my needs.
Thanks both for your help.
Julien