2024-05-03 6:08 AM - edited 2024-05-03 6:52 AM
What is the expected RTC peripheral behavior through power cycles on VDD? We have a 3.3V system design with the STM32H562VGT6 right now.
Setup:
Action:
Expected Behavior Through Power-Cycle:
Observed:
Is this expected? Is it possible to keep the RTC counter active & counting through power cycles?
Solved! Go to Solution.
2024-05-29 6:15 AM - edited 2024-05-29 10:13 AM
Thank you for the detail and patience @STOne-32 & @unsigned_char_array, we were able to resolve the situation! Our project was using the LSI within the MSP -
Solution:
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  if(hrtc->Instance==RTC)
  {
    /** Initializes the peripherals clock
    */
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
    PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;  // <- Originally 'RCC_RTCCLKSOURCE_LSI'
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
    {
      Error_Handler();
    }
    /* Peripheral clock enable */
    __HAL_RCC_RTC_ENABLE();
    __HAL_RCC_RTCAPB_CLK_ENABLE();
  }
}
Our IOC file wasn't in-sync with our project; is it supposed to be? Here was the update to apply with the IOC -
Thank you guys!
2024-05-04 2:56 AM
Dear @jreina ,
This is not expected and is strange behavior , VBAT mode is used exactly for such use cases where we loose main VDD and keep the RTC counting and LSE Oscillation stable . To debug this case, we need to see schematics of power supplies including VBAT , try to monitor the PC13 output of the LSE/Div and see what happens using an oscilloscope probes while probing the VDD supply and PC13 output. As well as the Firmware sequence.
Hope it helps you .
STOne-32
2024-05-05 6:37 AM
Thank you for the quick response STOne-32!
back shortly
2024-05-07 12:56 PM - edited 2024-05-07 12:58 PM
Hi STOne-32, here is our problem in further detail. -
Target:
Circuit:
Source:
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
	...
	
	HAL_Init();
	...
	
	SystemClock_Config();
	
	...
	
	MX_RTC_Init();
	... 
	
	os/freertos init & start
	
	...
	
	for(;;);
}
	
/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  /** Configure the main internal regulator output voltage
  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  /** Configure LSE Drive Capability
  */
  HAL_PWR_EnableBkUpAccess();
  //__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
  __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI
									|RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV2;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
	Error_Handler();
  }
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
							  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
							  |RCC_CLOCKTYPE_PCLK3;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
	Error_Handler();
  }
}
/**
  * @brief RTC Initialization Function
  *  None
  * @retval None
  */
static void MX_RTC_Init(void)
{
	RTC_PrivilegeStateTypeDef privilegeState = {0};
	/** Initialize RTC Only
	*/
	hrtc.Instance = RTC;
	hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
	hrtc.Init.AsynchPrediv = 127;
	hrtc.Init.SynchPrediv = 255;
	hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
	hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
	hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
	hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
	hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
	hrtc.Init.BinMode = RTC_BINARY_NONE;
	if (HAL_RTC_Init(&hrtc) != HAL_OK)
	{
		Error_Handler();
	}
	privilegeState.rtcPrivilegeFull = RTC_PRIVILEGE_FULL_NO;
	privilegeState.backupRegisterPrivZone = RTC_PRIVILEGE_BKUP_ZONE_NONE;
	privilegeState.backupRegisterStartZone2 = RTC_BKP_DR0;
	privilegeState.backupRegisterStartZone3 = RTC_BKP_DR0;
	if (HAL_RTCEx_PrivilegeModeSet(&hrtc, &privilegeState) != HAL_OK)
	{
		Error_Handler();
	}
	return;
}
Test:
Results:
Why is the RTC time count halting for #2 for us here? This is not expected
2024-05-07 1:44 PM
Dear @jreina
thanks for the details . Just wanted to understand what means :
is it visible for all steps from 1 to 3 including 2?
if possible to activate the output on PC13 and monitor the LSE clock in continuous way ? As PC13 is powered by backup domain and we should see what happens . Is you can try to change and LSE drive level to low as well to debug further .
ST1
2024-05-07 3:03 PM
Interesting! Back tomorrow, thank you
2024-05-08 5:25 AM - edited 2024-05-08 5:30 AM
I don't see an external charging circuit. Have you enabled internal charging in software?
Reference manual:
VBAT battery charging
When VDD is present, it is possible to charge the external battery on VBAT through an
internal resistance.
The VBAT charging is done either through a 5 or a 1.5 kΩ resistor, depending upon the
VBRS bit value in the PWR_BDCR register.
The battery charging is enabled by setting VBE bit in the PWR_BDCR register. It is
automatically disabled in V BAT mode
If you have enabled charging, what is the voltage on the VBAT pin?
RC-time constant if you use 1500Ohm and 0.22F is 330 seconds. I don't know what voltage the RTC needs so it could be even longer than this. I would use an external charging circuit (a diode with a series resistor should suffice).
2024-05-08 6:49 PM - edited 2024-05-08 6:51 PM
Interesting !! I am helping a teammate, with their solution including PCB & firmware I will check in the morning
Thank you guys. I had response to STOne-32 prepared at my desk, but another conversation carried long over and I did not get it submitted
Back tomorrow!
2024-05-17 6:47 AM - edited 2024-05-17 7:27 AM
I really appreciate your feedback and insight unsigned_char_array, thank you.
With the feedback from you and STOne-32, I was able to gather responses and test again, see attached.
Question Responses:
Code:
/**
  * @brief  The application entry point
  * @retval int
  */
int main(void) {
	///Locals
	//...
	//Init Vars
	//...
	//Init HAL
	HAL_Init();
	SystemClock_Config();
	//Init Periphs
	MX_RTC_Init();
	//...
	//Console Notice
	//...
	//Init OS
	osKernelInitialize();
	MX_FREERTOS_Init();
	//Start OS
	osKernelStart();
	//Loop
	for(;;);
}
/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void) {
  //... provided on request
  return;
}
/**
  * @brief RTC Initialization Function
  *  None
  * @retval None
  */
static void MX_RTC_Init(void) {
  RTC_PrivilegeStateTypeDef privilegeState = {0};
  //Initialize RTC Only
  hrtc.Instance            = RTC;
  hrtc.Init.HourFormat     = RTC_HOURFORMAT_24;
  hrtc.Init.AsynchPrediv   = 127;
  hrtc.Init.SynchPrediv    = 255;
  hrtc.Init.OutPut         = RTC_OUTPUT_DISABLE;
  hrtc.Init.OutPutRemap    = RTC_OUTPUT_REMAP_NONE;
  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  hrtc.Init.OutPutType     = RTC_OUTPUT_TYPE_OPENDRAIN;
  hrtc.Init.OutPutPullUp   = RTC_OUTPUT_PULLUP_NONE;
  hrtc.Init.BinMode        = RTC_BINARY_NONE;
  if(HAL_OK != HAL_RTC_Init(&hrtc)) {
    Error_Handler();
  }
  privilegeState.rtcPrivilegeFull         = RTC_PRIVILEGE_FULL_NO;
  privilegeState.backupRegisterPrivZone   = RTC_PRIVILEGE_BKUP_ZONE_NONE;
  privilegeState.backupRegisterStartZone2 = RTC_BKP_DR0;
  privilegeState.backupRegisterStartZone3 = RTC_BKP_DR0;
  if(HAL_OK != HAL_RTCEx_PrivilegeModeSet(&hrtc, &privilegeState)) {
    Error_Handler();
  }
  return;
}
I did some research into RC charging dynamics with our circuit, and appreciated the feedback there thank you unsigned_char_array
I will try to activate the output on PC13 and monitor the LSE clock in continuous way; posting an updated report next. With the current configuration in code above and results below, if you see any feedback let me know! Back soon, thank you guys
2024-05-23 9:39 AM - edited 2024-05-23 9:41 AM
How do you output the LSE or RTC clock to PC13? Do you have any recommendations?
RTC.OUT2?
Question:
