朱老师单片机课程学习记录
//specifies the new state of the HSE 指定HSE的状态
// * This parameter can be one of the following values:
// * @arg RCC_HSE_OFF: HSE oscillator OFF
// * @arg RCC_HSE_ON: HSE oscillator ON
// * @arg RCC_HSE_Bypass: HSE oscillator bypassed with external //clock
// * @retval None
void RCC_HSEConfig(uint32_t RCC_HSE)
{
/* Check the parameters */
assert_param(IS_RCC_HSE(RCC_HSE));
/* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/
/* Reset HSEON bit */
RCC->CR &= CR_HSEON_Reset;
/* Reset HSEBYP bit */
RCC->CR &= CR_HSEBYP_Reset;
/* Configure HSE (RCC_HSE_OFF is already covered by the code section above) */
switch(RCC_HSE)
{
case RCC_HSE_ON:
/* Set HSEON bit */
RCC->CR |= CR_HSEON_Set;
break;
case RCC_HSE_Bypass:
/* Set HSEBYP and HSEON bits */
RCC->CR |= CR_HSEBYP_Set | CR_HSEON_Set;
break;
default:
break;
}
}
assert断言,断言机制用的最多的就是:库函数中用断言来检查用户调用该库函数时传参到底对不对。上面那个函数就是stm32中的一个库函数,函数中使用了断言机制,RCC_HSEConfig这个函数接收的参数只能是这三个,分别是
RCC_HSE_OFF,RCC_HSE_ON,RCC_HSE_Bypass,如果不是这三个,就会报错。
//这个函数需要用户自己去定义的
void assert_failed(uint8_t* file, uint32_t line)
{
//用户用自己的方法去报错一个断言错误
}
枚举的定义方式
typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;