/******************************************************************************/
/* */
/* RCC寄存器--复位和时钟控制 */
/* */
/******************************************************************************/
//typedef struct
//{
// __IO uint32_t CR;
// __IO uint32_t CFGR;
// __IO uint32_t CIR;
// __IO uint32_t APB2RSTR;
// __IO uint32_t APB1RSTR;
// __IO uint32_t AHBENR;
// __IO uint32_t APB2ENR;
// __IO uint32_t APB1ENR;
// __IO uint32_t BDCR;
// __IO uint32_t CSR;
//#ifdef STM32F10X_CL
// __IO uint32_t AHBRSTR;
// __IO uint32_t CFGR2;
//#endif /* STM32F10X_CL */
//#if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
// uint32_t RESERVED0;
// __IO uint32_t CFGR2;
//#endif /* STM32F10X_LD_VL || STM32F10X_MD_VL || STM32F10X_HD_VL */
//} RCC_TypeDef;
//RCC_CR--时钟控制寄存器
#define bRCC_CLK_HSION BIT_ADDR(RCC_BASE, 0) //LSI时钟: 0禁用,1开启
#define bRCC_CLK_HSIRDY BIT_ADDR(RCC_BASE, 1) //LSI时钟状态由硬件控制(只读):0不可用,1就绪
#define bRCC_CLK_HSEON BIT_ADDR(RCC_BASE, 16) //HSE时钟: 0禁用,1开启
#define bRCC_CLK_HSERDY BIT_ADDR(RCC_BASE, 17) //HSE时钟状态由硬件控制(只读):0不可用,1就绪
#define bRCC_CLK_HSEBYP BIT_ADDR(RCC_BASE, 18) //外部时钟旁路(调试用)-- 0不旁路 1旁路
#define bRCC_CLK_CSSON BIT_ADDR(RCC_BASE, 19) //系统时钟安全系统使能 0时钟检测禁用 1外部时钟就绪后启动检测
#define bRCC_CLK_PLLON BIT_ADDR(RCC_BASE, 24) //PLL倍频: 0禁用,1开启
#define bRCC_CLK_PLLRDY BIT_ADDR(RCC_BASE, 25) //PLL倍频状态由硬件控制(只读):0不可用,1就绪
//本寄存器还有5BIT的HSITRIM 内部高速时钟调整
// 8BIT的HSICAL 内部高速时钟校准 用于补偿因温度等变化对内部RC振荡器时钟频率的影响.
//RCC_CFGR--时钟配置寄存器
#define bRCC_CONFIG_SW0 BIT_ADDR(RCC_BASE+0x04, 0) //系统时钟选择2BIT-- 00:HSI 01:HSE
#define bRCC_CONFIG_SW1 BIT_ADDR(RCC_BASE+0x04, 1) // 10LL 11: 无效
#define bRCC_CONFIG_SW_PLL BIT_ADDR(RCC_BASE+0x04, 1) //SYSCLK时钟选择位1,置位时为选择PLL作为系统时钟源
#define bRCC_CONFIG_SWS0 BIT_ADDR(RCC_BASE+0x04, 2) //系统时钟源指示,只读: 定义同上
#define bRCC_CONFIG_SWS1 BIT_ADDR(RCC_BASE+0x04, 3) //
#define bRCC_CONFIG_SWS_PLL BIT_ADDR(RCC_BASE+0x04, 3) //SYSCLK时钟指示位1,为1时指示PLL已经为系统时钟源
#define bRCC_CONFIG_PLLSRC BIT_ADDR(RCC_BASE+0x04, 16) //PLL钟源选择, 0: HSI/2 1:HSE(PREDIV1的输出)
#define bRCC_CONFIG_PLLXTPRE BIT_ADDR(RCC_BASE+0x04, 17) //输出至PLL的HSE是否分频 0:不分频 1:二分频
#define bRCC_CONFIG_USBPRE BIT_ADDR(RCC_BASE+0x04, 22) //USB预分频控制 0: PLL/1.5 1: PLL
#define bRCC_CONFIG_ADCPRE0 BIT_ADDR(RCC_BASE+0x04, 14) //ADC(对PLCK2)预分频2BIT控制: 00: 2分频 01: 4分频
#define bRCC_CONFIG_ADCPRE1 BIT_ADDR(RCC_BASE+0x04, 15) // 10: 6分频 11: 8分频
//本寄存器还有4BIT的HPRE控制位: 控制系统时钟SYSCLK分频至AHB
// 3BIT的PPRE1控制位: 控制至APB1的预分频
// 3BIT的PPRE2控制位: 控制至APB2的预分频
// 4BIT的PLLMUL:选择PLL的倍频数,2-16
// 3BIT的MCO控制位: 对MCU输出时钟的选择进行控制
//RCC_CIR--时钟中断寄存器
#define bRCC_INT_LSIRDY** BIT_ADDR(RCC_BASE+0x08, 0) //LSI稳定且对应IE置位时由硬件置位,只读0无效,1可用
#define bRCC_INT_LSERDY** BIT_ADDR(RCC_BASE+0x08, 1) //LSE稳定且对应IE置位时由硬件置位,只读0无效,1可用
#define bRCC_INT_HSIRDY** BIT_ADDR(RCC_BASE+0x08, 2) //HSI稳定且对应IE置位时由硬件置位,只读0无效,1可用
#define bRCC_INT_HSERDY** BIT_ADDR(RCC_BASE+0x08, 3) //HSE稳定且对应IE置位时由硬件置位,只读0无效,1可用
#define bRCC_INT_PLLRDY** BIT_ADDR(RCC_BASE+0x08, 4) //PLL锁定且对应IE置位时由硬件置位,只读0无效,1可用
#define bRCC_INT_CSSF BIT_ADDR(RCC_BASE+0x08, 7) //外部振荡器失效时由硬件置位,只读0:无效,1中断可用
#define bRCC_INT_LSIRDYIE BIT_ADDR(RCC_BASE+0x08, 8) //LSI可用 中断使能, 0禁用 1使能
#define bRCC_INT_LSERDYIE BIT_ADDR(RCC_BASE+0x08, 9) //下同
#define bRCC_INT_HSIRDYIE BIT_ADDR(RCC_BASE+0x08, 10)
#define bRCC_INT_HSERDYIE BIT_ADDR(RCC_BASE+0x08, 11)
#define bRCC_INT_PLLRDYIE BIT_ADDR(RCC_BASE+0x08, 12)
#define bRCC_INT_LSIRDYCLR BIT_ADDR(RCC_BASE+0x08, 16) //写1以清零相应的LSIRDYF,下同
#define bRCC_INT_LSERDYCLR BIT_ADDR(RCC_BASE+0x08, 17)
#define bRCC_INT_HSIRDYCLR BIT_ADDR(RCC_BASE+0x08, 18)
#define bRCC_INT_HSERDYCLR BIT_ADDR(RCC_BASE+0x08, 19)
#define bRCC_INT_PLLRDYCLR BIT_ADDR(RCC_BASE+0x08, 20)
#define bRCC_INT_CSSCLR BIT_ADDR(RCC_BASE+0x08, 23)
//RCC_APB2RSTR寄存器
#define bRCC_RESET_AFIO BIT_ADDR(RCC_BASE+0x0C, 0) //0无效,1复位,下同
#define bRCC_RESET_GPIOA BIT_ADDR(RCC_BASE+0x0C, 2)
#define bRCC_RESET_GPIOB BIT_ADDR(RCC_BASE+0x0C, 3)
#define bRCC_RESET_GPIOC BIT_ADDR(RCC_BASE+0x0C, 4)
#define bRCC_RESET_GPIOD BIT_ADDR(RCC_BASE+0x0C, 5)
#define bRCC_RESET_GPIOE BIT_ADDR(RCC_BASE+0x0C, 6)
#define bRCC_RESET_ADC1 BIT_ADDR(RCC_BASE+0x0C, 9)
#define bRCC_RESET_ADC2 BIT_ADDR(RCC_BASE+0x0C, 10)
#define bRCC_RESET_TIM1 BIT_ADDR(RCC_BASE+0x0C, 11)
#define bRCC_RESET_SPI1 BIT_ADDR(RCC_BASE+0x0C, 12)
#define bRCC_RESET_USART1 BIT_ADDR(RCC_BASE+0x0C, 14)
//RCC_APB1RSTR寄存器
#define bRCC_RESET_TIM2 BIT_ADDR(RCC_BASE+0x10, 0) //0无效,1复位,下同
#define bRCC_RESET_TIM3 BIT_ADDR(RCC_BASE+0x10, 1)
#define bRCC_RESET_TIM4 BIT_ADDR(RCC_BASE+0x10, 2)
#define bRCC_RESET_WWDG BIT_ADDR(RCC_BASE+0x10, 11)
#define bRCC_RESET_SPI2 BIT_ADDR(RCC_BASE+0x10, 14)
#define bRCC_RESET_USART2 BIT_ADDR(RCC_BASE+0x10, 17)
#define bRCC_RESET_USART3 BIT_ADDR(RCC_BASE+0x10, 18)
#define bRCC_RESET_I2C1 BIT_ADDR(RCC_BASE+0x10, 21)
#define bRCC_RESET_I2C2 BIT_ADDR(RCC_BASE+0x10, 22)
#define bRCC_RESET_USB BIT_ADDR(RCC_BASE+0x10, 23)
#define bRCC_RESET_CAN BIT_ADDR(RCC_BASE+0x10, 25)
#define bRCC_RESET_BKP BIT_ADDR(RCC_BASE+0x10, 27)
#define bRCC_RESET_PWR BIT_ADDR(RCC_BASE+0x10, 28)
//RCC_AHBEN寄存器
#define bRCC_ENABLE_DMA BIT_ADDR(RCC_BASE+0x14, 0) //0关闭时钟,1开启时钟,下同
#define bRCC_ENABLE_SRAM BIT_ADDR(RCC_BASE+0x14, 2)
#define bRCC_ENABLE_FLITF BIT_ADDR(RCC_BASE+0x14, 4)
#define bRCC_ENABLE_CRC BIT_ADDR(RCC_BASE+0x14, 6)
//RCC_APB2ENR寄存器
#define bRCC_ENABLE_AFIO BIT_ADDR(RCC_BASE+0x18, 0) //0关闭时钟,1开启时钟,下同
#define bRCC_ENABLE_GPIOA BIT_ADDR(RCC_BASE+0x18, 2)
#define bRCC_ENABLE_GPIOB BIT_ADDR(RCC_BASE+0x18, 3)
#define bRCC_ENABLE_GPIOC BIT_ADDR(RCC_BASE+0x18, 4)
#define bRCC_ENABLE_GPIOD BIT_ADDR(RCC_BASE+0x18, 5)
#define bRCC_ENABLE_GPIOE BIT_ADDR(RCC_BASE+0x18, 6)
#define bRCC_ENABLE_ADC1 BIT_ADDR(RCC_BASE+0x18, 9)
#define bRCC_ENABLE_ADC2 BIT_ADDR(RCC_BASE+0x18, 10)
#define bRCC_ENABLE_TIM1 BIT_ADDR(RCC_BASE+0x18, 11)
#define bRCC_ENABLE_SPI1 BIT_ADDR(RCC_BASE+0x18, 12)
#define bRCC_ENABLE_USART1 BIT_ADDR(RCC_BASE+0x18, 14)
//RCC_APB1ENR寄存器
#define bRCC_ENABLE_TIM2 BIT_ADDR(RCC_BASE+0x1C, 0) //0关闭时钟,1开启时钟,下同
#define bRCC_ENABLE_TIM3 BIT_ADDR(RCC_BASE+0x1C, 1)
#define bRCC_ENABLE_TIM4 BIT_ADDR(RCC_BASE+0x1C, 2)
#define bRCC_ENABLE_WWDG BIT_ADDR(RCC_BASE+0x1C, 11)
#define bRCC_ENABLE_SPI2 BIT_ADDR(RCC_BASE+0x1C, 14)
#define bRCC_ENABLE_USART2 BIT_ADDR(RCC_BASE+0x1C, 17)
#define bRCC_ENABLE_USART3 BIT_ADDR(RCC_BASE+0x1C, 18)
#define bRCC_ENABLE_I2C1 BIT_ADDR(RCC_BASE+0x1C, 21)
#define bRCC_ENABLE_I2C2 BIT_ADDR(RCC_BASE+0x1C, 22)
#define bRCC_ENABLE_USB BIT_ADDR(RCC_BASE+0x1C, 23)
#define bRCC_ENABLE_CAN BIT_ADDR(RCC_BASE+0x1C, 25)
#define bRCC_ENABLE_BKP BIT_ADDR(RCC_BASE+0x1C, 27)
#define bRCC_ENABLE_PWR BIT_ADDR(RCC_BASE+0x1C, 28)
//RCC_BDCR寄存器--备份区域控制
#define bRCC_CLK_LSEON BIT_ADDR(RCC_BASE+0x20, 0) //LSE时钟: 0禁用,1开启
#define bRCC_CLK_LSERDY BIT_ADDR(RCC_BASE+0x20, 1) //LSE时钟状态由硬件控制(只读):0不可用,1就绪
#define bRCC_CLK_RTCSEL0 BIT_ADDR(RCC_BASE+0x20, 24) //RTC时钟源选择两位共同控制: 00:无时钟 01SE
#define bRCC_CLK_RTCSEL1 BIT_ADDR(RCC_BASE+0x20, 26) // 10SI 11: HSE/128
#define bRCC_ENABLE_RTC BIT_ADDR(RCC_BASE+0x20, 27) //0禁用RTC; 1:使能RTC
#define bRCC_RESET_BKUPDOMAIN BIT_ADDR(RCC_BASE+0x20, 28) //备份区域软复位 写1复位 0复位未被激活
//RCC_CSR寄存器--状态与控制
#define bRCC_CLK_LSION BIT_ADDR(RCC_BASE+0x24, 0) //LSI时钟: 0禁用,1开启
#define bRCC_CLK_LSIRDY BIT_ADDR(RCC_BASE+0x24, 1) //LSI时钟状态由硬件控制(只读):0不可用,1就绪
#define bRCC_**_RMVF BIT_ADDR(RCC_BASE+0x24, 24) //清除复位标志 写0复位未激活的复位标志,写1则清复位标志
#define bRCC_**_PINRSTF BIT_ADDR(RCC_BASE+0x24, 26) //引脚复位标志 硬件置1软件写RMVF位清0
#define bRCC_**_PORRSTF BIT_ADDR(RCC_BASE+0x24, 27) //端口复位标志 硬件置1软件写RMVF位清0
#define bRCC_**_SFTRSTF BIT_ADDR(RCC_BASE+0x24, 28) //软件复位标志 硬件置1软件写RMVF位清0
#define bRCC_**_IWDGRSTF BIT_ADDR(RCC_BASE+0x24, 29) //独立看门狗复位标志 硬件置1软件写RMVF位清0
#define bRCC_**_WWDGRSTF BIT_ADDR(RCC_BASE+0x24, 30)//窗口看门狗复位标志 硬件置1软件写RMVF位清0
#define bRCC_**_LPWRRSTF BIT_ADDR(RCC_BASE+0x24, 31)//低功耗管理复位标志 硬件置1软件写RMVF位清0 |