#define RCC_FLAG_HSIRDY ((uint8_t)0x21) #define RCC_FLAG_HSERDY ((uint8_t)0x31) #define RCC_FLAG_PLLRDY ((uint8_t)0x39) #define RCC_FLAG_LSERDY ((uint8_t)0x41) #define RCC_FLAG_LSIRDY ((uint8_t)0x61) #define RCC_FLAG_PINRST ((uint8_t)0x7A) #define RCC_FLAG_PORRST ((uint8_t)0x7B) #define RCC_FLAG_SFTRST ((uint8_t)0x7C) #define RCC_FLAG_IWDGRST ((uint8_t)0x7D) #define RCC_FLAG_WWDGRST ((uint8_t)0x7E) #define RCC_FLAG_LPWRRST ((uint8_t)0x7F) //以上这些都是根据什么来设置的? #ifndef STM32F10X_CL #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \ ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \ ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_PINRST) || \ ((FLAG) == RCC_FLAG_PORRST) || ((FLAG) == RCC_FLAG_SFTRST) || \ ((FLAG) == RCC_FLAG_IWDGRST)|| ((FLAG) == RCC_FLAG_WWDGRST)|| \ ((FLAG) == RCC_FLAG_LPWRRST)) #else #define RCC_FLAG_PLL2RDY ((uint8_t)0x3B) #define RCC_FLAG_PLL3RDY ((uint8_t)0x3D) #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \ ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \ ((FLAG) == RCC_FLAG_PLL2RDY) || ((FLAG) == RCC_FLAG_PLL3RDY) || \ ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_PINRST) || \ ((FLAG) == RCC_FLAG_PORRST) || ((FLAG) == RCC_FLAG_SFTRST) || \ ((FLAG) == RCC_FLAG_IWDGRST)|| ((FLAG) == RCC_FLAG_WWDGRST)|| \ ((FLAG) == RCC_FLAG_LPWRRST)) #endif /* STM32F10X_CL */ /*以下是搞用上面设置的库函数,关键来了,看到这里就蒙了*/ FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG) { uint32_t tmp = 0; uint32_t statusreg = 0; FlagStatus bitstatus = RESET; /* Check the parameters */ assert_param(IS_RCC_FLAG(RCC_FLAG)); /* Get the RCC register index */ tmp = RCC_FLAG >> 5;//上面的解释应该是说通过左移5来取得寄存器的下标,发现都左移后和下面对应的寄存器不太对应啊 if (tmp == 1) /* The flag to check is in CR register */ { statusreg = RCC->CR; } else if (tmp == 2) /* The flag to check is in BDCR register */ { statusreg = RCC->BDCR; } else /* The flag to check is in CSR register */ { statusreg = RCC->CSR; } <span style="font-size: medium"> /* Get the flag position */ tmp = RCC_FLAG & FLAG_Mask; if ((statusreg & ((uint32_t)1 |
RE:请高手看下这是怎么来的?stm32f10x_rcc.h
RE:请高手看下这是怎么来的?stm32f10x_rcc.h
RE:请高手看下这是怎么来的?stm32f10x_rcc.h
通过宏定义 来 表示的,后面的是 十六进制的数。
回复:请高手看下这是怎么来的?stm32f10x_rcc.h
define RCC_FLAG_WWDGRST 是根据这个标志位在寄存器中的位置计算的。这个标志位为0,其他标志位为1而得出的结果。
#define RCC_FLAG_IWDGRST ((uint8_t)0x7D)
FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
{
/* Check the parameters */
assert_param(IS_RCC_FLAG(RCC_FLAG));
/* Get the RCC register index */
tmp = RCC_FLAG >> 5;// 假如RCC_FLAG是RCC_FLAG_IWDGRST,右移5位RCC_FLAG_IWDGRST后变成了0x3了,而IWDGRST所在的位:RCC_CSR寄存器的位29,算一下感觉不对了,请问上面的楼主能解释一下,这里为什么要右移5位吗?
if (tmp == 1) /* The flag to check is in CR register */
{
statusreg = RCC->CR;
}
else if (tmp == 2) /* The flag to check is in BDCR register */
{
statusreg = RCC->BDCR;
}
else /* The flag to check is in CSR register */
{
statusreg = RCC->CSR;
}
回复:请高手看下这是怎么来的?stm32f10x_rcc.h
define RCC_FLAG_WWDGRST 是根据这个标志位在寄存器中的位置计算的。这个标志位为0,其他标志位为1而得出的结果。
#define RCC_FLAG_IWDGRST ((uint8_t)0x7D)
FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
{
/* Check the parameters */
assert_param(IS_RCC_FLAG(RCC_FLAG));
/* Get the RCC register index */
tmp = RCC_FLAG >> 5;// 假如RCC_FLAG是RCC_FLAG_IWDGRST,右移5位RCC_FLAG_IWDGRST后变成了0x3了,而IWDGRST所在的位:RCC_CSR寄存器的位29,算一下感觉不对了,请问上面的楼主能解释一下,这里为什么要右移5位吗?
if (tmp == 1) /* The flag to check is in CR register */
{
statusreg = RCC->CR;
}
else if (tmp == 2) /* The flag to check is in BDCR register */
{
statusreg = RCC->BDCR;
}
else /* The flag to check is in CSR register */
{
statusreg = RCC->CSR;
}
RE:请高手看下这是怎么来的?stm32f10x_rcc.h