AnsweredAssumed Answered

Bug in HAL_PWR_EnableWakeUpPin()

Question asked by Sakurai.Hiroshi on Nov 1, 2016
Latest reply on Nov 2, 2016 by FTITI.Walid
Currently, HAL_PWR_EnableWakeUpPin() enables wakeup-pin before it sets polarity. The calling order should be reversed.

void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)
  /* Enable wake-up pin */
  SET_BIT(PWR->CSR2, (PWR_EWUP_MASK & WakeUpPinPolarity));
  /* Specifies the Wake-Up pin polarity for the event detection
    (rising or falling edge) */
  MODIFY_REG(PWR->CR2, (PWR_EWUP_MASK & WakeUpPinPolarity), (WakeUpPinPolarity >> 0x06));

When I tried to set a wakeup pin as falling edge by calling HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW), wakeup flag was set after MODIFY_REG is called. I think it's because the default polarity is rising edge and changing the polarity while wakeup is enabled sets a wakeup flag.

It should call MODIFY_REG before SET_BIT. 

The version I'm using is:
  * @file    stm32f7xx_hal_pwr.c
  * @author  MCD Application Team
  * @version V1.1.1
  * @date    01-July-2016
  * @brief   PWR HAL module driver.

Workaround is calling __HAL_PWR_CLEAR_WAKEUP_FLAG() after HAL_PWR_EnableWakeUpPin().