AnsweredAssumed Answered

STM32L1xx SPL 1.2.0: Bug with IS_RCC_FLAG

Question asked by Phil Pemberton on Jul 3, 2014
Latest reply on Jul 3, 2014 by Montassar BEN ROMDHANE
Scenario:
Our product displays the Last Reset Reason (from the RCC) when it powers up. This allows us to determine if the last reset was intentional or caused by e.g. a power brownout or software failure.

Problem:
When USE_FULL_ASSERT is defined, RCC_GetFlagStatus() uses the IS_RCC_FLAG macro to determine whether the passed value is a valid RCC flag.
Attempting to check the state of the RCC_FLAG_OBLRST RCC flag causes an assertion failure.

Cause:
The IS_RCC_FLAG() macro (stm32lxx_rcc.h) is incorrectly defined.
RCC_FLAG_WWDGRST is checked twice, and RCC_FLAG_OBLRST is not checked at all:
1.#define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
2.                           ((FLAG) == RCC_FLAG_MSIRDY) || ((FLAG) == RCC_FLAG_PLLRDY) || \
3.                           ((FLAG) == RCC_FLAG_LSERDY) || ((FLAG) == RCC_FLAG_LSIRDY) || \
4.                           ((FLAG) == RCC_FLAG_PINRST) || ((FLAG) == RCC_FLAG_PORRST) || \
5.                           ((FLAG) == RCC_FLAG_SFTRST) || ((FLAG) == RCC_FLAG_IWDGRST)|| \
6.                           ((FLAG) == RCC_FLAG_WWDGRST)|| ((FLAG) == RCC_FLAG_LPWRRST)|| \
7.                           ((FLAG) == RCC_FLAG_WWDGRST)|| ((FLAG) == RCC_FLAG_LSECSS))

Fix:
The last line should be changed to:
1.((FLAG) == RCC_FLAG_OBLRST) || ((FLAG) == RCC_FLAG_LSECSS))

This allows RCC_FLAG_OBLRST to be passsed as an RCC flag, and have its status checked without causing an assertion failure.

Outcomes