cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H5 RTC count through power cycles

jreina
Associate III

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:

  • VDD = 3.3V from external supply
  • VBAT = 220mF supercap attached
  • RTC is enabled & counting, system is stable
  • LSE oscillation is active on the PC14/15 lines

Action:

  1. VDD = 0V for 1-2 sec (unplugged PSU)
  2. VDD = 3.3V restored (reconnected PSU)

Expected Behavior Through Power-Cycle:

  • RTC count maintains operation & counting (count increases)
  • LSE signal is oscillating at PC14/15 lines

Observed:

  • RTC count freezes when power is removed & resumes counting when power is restored

 

Is this expected? Is it possible to keep the RTC counter active & counting through power cycles?

 

1 ACCEPTED SOLUTION

Accepted Solutions

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 - 

Clock Update Example.png

 

Thank you guys!

View solution in original post

11 REPLIES 11
STOne-32
ST Employee

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

Thank you for the quick response STOne-32!

back shortly

jreina
Associate III

Hi STOne-32, here is our problem in further detail. - 

 

Target:

  • RTC for continuous operation & counts through Vdd power cycles

 

Circuit:

RTC Debug.png

 

 

 

 

 

 

 

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:

  1. Power is applied (Vdd=3.3V) and the system stabilizes
  2. Power is removed (Vdd=0V) for 1 second
  3. Power is applied (Vdd=3.3V)

Results:

  1. RTC signal is visible for steps #1-3 above
  2. RTC count starts at #1, halts unexpectedly for #2 and resumes at #3

 

Why is the RTC time count halting for #2 for us here? This is not expected

Dear @jreina 

thanks for the details . Just wanted to understand what means :

  1. RTC signal is visible for steps #1-3 above ?

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

Interesting! Back tomorrow, thank you

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).

 

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.

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!

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:

  1. RTC signal is visible for steps #1-3 above
    1. Yes it is visible for #1-#3, on PC14/15
    2. #2?
  2. PC13 is not exposed for this board.
    1. I do have a NUCLEO-H563ZI I can test LSE on PC13 with if useful
    2. There are other GPIO pins exposed for debug if useful
  3. Firmware VBAT charging
    1. I am not sure what configuration my teammate is using; it will take some time for review to uncover
  4. Test VBAT charging
    1. Now I am manually charging VBAT; see Procedure.StepOne of attached
  5. VBAT voltage at pin: 3.28V (see Figure 2 of attached)

 

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

 

How do you output the LSE or RTC clock to PC13? Do you have any recommendations?

 

RTC.OUT2?

  • Is RTC_OR.OUT2_RMP a consideration for RTC clock routing to PB2? I can rework a jumper to the chip pin directly if useful

 

Question:

  • How do you observe one of these clocks exposed to a pin?