cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F479II wakes up immediately from first standby if RTC time was set.

awiernie
Senior II

The STM32F479II is set to standby mode and activated by PWR_WAKEUP_PIN1. This all works. But there is one situation where it wakes up immediately. The next standby works however.

How to reproduce:

Power Cycle -> RTC has no battery thus date and time is reset -> call HAL_RTC_SetTime -> set to standby -> the application is started again (but not the bootloader)

It does not wake up, if is sent to standby the second time.

It does also not wake up if only HAL_RTC_SetDate is called.

I does also wake up if the stlink is connected to the uart and the usb is connected to power

EDIT:

The problem does not occur, if i comment out this in the HAL_RTC_SetTime (see mur_disablethefollowing below):

 /* Configure the RTC_CR register (Deprecated. Use HAL_RTC_DST_*** functions instead) */

  hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);

HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
{
  uint32_t tmpreg = 0U;
  HAL_StatusTypeDef status;
 
  /* Check the parameters */
  assert_param(IS_RTC_FORMAT(Format));
  assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving));
  assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation));
 
  /* Process Locked */
  __HAL_LOCK(hrtc);
 
  hrtc->State = HAL_RTC_STATE_BUSY;
 
  if (Format == RTC_FORMAT_BIN)
  {
    if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U)
    {
      assert_param(IS_RTC_HOUR12(sTime->Hours));
      assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
    }
    else
    {
      sTime->TimeFormat = 0x00U;
      assert_param(IS_RTC_HOUR24(sTime->Hours));
    }
    assert_param(IS_RTC_MINUTES(sTime->Minutes));
    assert_param(IS_RTC_SECONDS(sTime->Seconds));
 
    tmpreg = (uint32_t)(( (uint32_t)RTC_ByteToBcd2(sTime->Hours)   << RTC_TR_HU_Pos)  | \
                        ( (uint32_t)RTC_ByteToBcd2(sTime->Minutes) << RTC_TR_MNU_Pos) | \
                        ( (uint32_t)RTC_ByteToBcd2(sTime->Seconds))                   | \
                        (((uint32_t)sTime->TimeFormat)             << RTC_TR_PM_Pos));
  }
  else
  {
    if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U)
    {
      assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sTime->Hours)));
      assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
    }
    else
    {
      sTime->TimeFormat = 0x00U;
      assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours)));
    }
    assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes)));
    assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds)));
    tmpreg = (((uint32_t)(sTime->Hours)      << RTC_TR_HU_Pos)  | \
              ((uint32_t)(sTime->Minutes)    << RTC_TR_MNU_Pos) | \
              ((uint32_t) sTime->Seconds)                       | \
              ((uint32_t)(sTime->TimeFormat) << RTC_TR_PM_Pos));
  }
 
  /* Disable the write protection for RTC registers */
  __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
 
  /* Enter Initialization mode */
  status = RTC_EnterInitMode(hrtc);
 
  if (status == HAL_OK)
  {
 
    /* Set the RTC_TR register */
    hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
 
    /* Clear the bits to be configured (Deprecated. Use HAL_RTC_DST_*** functions instead) */
    hrtc->Instance->CR &= (uint32_t)~RTC_CR_BKP;
 
#define mur_disablethefollowing
#ifndef mur_disablethefollowing
    /* Configure the RTC_CR register (Deprecated. Use HAL_RTC_DST_*** functions instead) */
    hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);
#endif
    /* Exit Initialization mode */
    status = RTC_ExitInitMode(hrtc);
  }
 
  if (status == HAL_OK)
  {
    hrtc->State = HAL_RTC_STATE_READY;
  }
 
  /* Enable the write protection for RTC registers */
  __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
 
  /* Process Unlocked */
  __HAL_UNLOCK(hrtc);
 
  return status;
}

power_off:

void power_off()
{
	(void) HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
	HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
	__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
	HAL_PWR_EnterSTANDBYMode();
}

6 REPLIES 6
awiernie
Senior II

There are similar symptoms described for STM32L4. I tried the solution there but it made no difference. However I have a different MCU and use HAL drivers.

awiernie
Senior II

How can I check which event or interrupt caused the wakeup?

awiernie
Senior II

I have edited the original question above. The problem does not occur, if I remove the follwing from HAL_RTC_SetTime in file stm32f4xx_hal_rtc.c:

 /* Configure the RTC_CR register (Deprecated. Use HAL_RTC_DST_*** functions instead) */

  hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);

There is already a warning in the source code. Shouldn't it be modified?

This does not apply to my problem. I even don't use the wakeup timer. Your link suggests to read back the wakeup timer flag in a while loop and call reset it until it is reset. I have tried it though, but as expected it did not solve the problem.

ST should modify their code, as they already write that it is deprecated.