cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 RTC ISSUE WHEN COINCELL [VBAT] IS REMOVED

Dhanoosh
Associate II

Hi community,

I'm having a STM32F407VET6 PCB board where VBAT is connected to a 10 uF decoupling capacitor [Instead of recommended 100 nF capacitor].
in order to achieve some backup time when both the coin cell and 3.3V are not connected.

My RTC is working fine when a coin-cell or 3.3V supply is available in VBAT. But when I remove the coin cell while performing a power cycle, I'm facing some issues, as listed below.

[Note: RTC is initialized properly with the time 2023-11-07T08:31:20Z [YYYY-MM-DDTHH:MM:SSZ]]

[Note: Coin cell is removed from the board]

 

CasePower cycle durationVoltage level in VBAT Decoupling CapacitorResult Observation

1

7 Seconds3.16V to 0.86VWorking fineRTC Accumulated entire power cycle duration properly
28 Seconds3.15V to 0.77VRTC Init failed - goes to error handler modeRTC Accumulated entire power cycle duration properly
330 Seconds3.16V to 0.46VRTC Init failed - goes to error handler modeRTC Accumulated only first 12 Seconds of the power cycle
45 minutes3.16V to 0.15VRTC Init failed - goes to error handler modeRTC Accumulated only first 12 Seconds of the power cycle
56 minutes3.16V to 0.10VRTC de-initializedRTC de-initialized doesn't goes to error handler mode


The issue is RTC is working fine till 7 seconds with the backup of decoupling capacitor, after that it goes to error handler mode but still accumulating time for first 12 seconds of power cycle [8 Seconds to 5 minutes].

After 6 minutes it de-initialized RTC and doesn't goes to error handler mode. I wanted to de-initialize RTC after the RTC accumulates the first 12 seconds of power cycle in order to avoid error handler mode.

Anyone please explain does the decoupling capacitor affects this behavior in hardware perspective or should I need to use any register to tackle this issue in software perspective.

9 REPLIES 9
LCE
Principal

10 µF just isn't a real battery, as you can see from your own tests.

Try at least 100 µF (6V3) if you want to keep standard caps, otherwise try a supercap.

Hi LCE,

Thanks for the response. I also wanted to know why the RTC goes to error handler mode after a particular power cycle duration [7 seconds]. Does increasing the capacitance fix the error handling issue?

LCE
Principal

I don't know. What does the datasheet say about the minimum required voltage? 0.86 V is quite low.

The datasheet describes the voltage level in Vbat as ranging from 1.65 to 3.6 volts. Let me change the capacitor as suggested and update the findings.

You are probably hitting VBAT brownout, ie. incomplete/faulty reset.

Software ends up in error handler probably due to bug in software, which does not anticipate this state. If you are using Cube or similar "library", you may want to avoid it and write your own.

JW

Gotcha, Thanks Evangelist!

LCE
Principal

Vbat as ranging from 1.65 to 3.6 V

Well, looks like 0.86 V is much too low.

I guess even the 100 µF will not be enough for more than a few seconds.

Hi JW

I am using the STM32 Cube IDE to generate code. In that RTC goes into error state based on the above circumstances at RTC_EnterInitMode. I will write the generated function below 

 

 

HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc)
{
  uint32_t tickstart = 0U;
  HAL_StatusTypeDef status = HAL_OK;
  LOG_DEBUG("Entered RTC Init mode - Line Number %s->%s:%d\n", __FILE__, __FUNCTION__, __LINE__);

  /* Check that Initialization mode is not already set */
  if (READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U)
  {
    /* Set INIT bit to enter Initialization mode */
    SET_BIT(hrtc->Instance->ISR, RTC_ISR_INIT);

    /* Get tick */
    tickstart = HAL_GetTick();

    /* Wait till RTC is in INIT state and if timeout is reached exit */
    while ((READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U) && (status != HAL_ERROR))
    {
      if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
      {
        /* Set RTC state */
        LOG_DEBUG("RTC goes to error state IN RTC_ENTER_INIT_MODE - Line Number %s->%s:%d\n", __FILE__, __FUNCTION__, __LINE__);
       
        hrtc->State = HAL_RTC_STATE_ERROR;
        status = HAL_ERROR;
      }
    }
  }

  return status;
}

 

 
RTC gets timed-out and goes to error state, please let me know if I need to change any to resolve this issue.

This is probably just a consequence, and you need to devise a check for the brownout and reset backup domain explicitly before attempting to set anything in it, including LSE clock.

I don't use Cube/HAL, and I don't use a capacitor on VBAT, so don't have personal experience with this particular issue.

JW