📄 stm32f103-s.h
字号:
// TIM3EN:定时器3时钟使能
#define RCC_TIM3EN ((u32)0x1<<1)
// TIM2EN:定时器2时钟使能
#define RCC_TIM2EN ((u32)0x1<<0)
//--------------------------------------------------------------------
//备份域控制寄存器 (RCC_BDCR)
//--------------------------------------------------------------------
struct RCC_BDCR_BITS {
unsigned LSEON :1; // 0 LSEON:外部低速振荡器使能 1:外部32kHz振荡器开启
unsigned LSERDY :1; // 1 LSERDY:外部低速LSE就绪
unsigned LSEBYP :1; // 2 LSEBYP:外部低速时钟振荡器旁路 1:LSE时钟被旁路 0:LSE时钟未被旁路
unsigned Reserved2 :5; // 7:3
unsigned RTCSEL :2; // 9:8 RTCSEL[1:0]:RTC时钟源选择
unsigned Reserved1 :5; // 14:10
unsigned RTCEN :1; // 15 RTCEN:RTC时钟使能
unsigned BDRST :1; // 16 BDRST:备份域软件复位
unsigned Reserved0 :15; // 31:17
};
union RCC_BDCR_REG {
Uint32 all;
struct RCC_BDCR_BITS bit;
};
//BDRST:备份域软件复位 1:复位整个备份域
#define RCC_BDRST ((u32)0x1<<16)
// RTCEN:RTC时钟使能
#define RCC_RTCEN ((u32)0x1<<15)
// RTCSEL[1:0]:RTC时钟源选择
// 00:无时钟
// 01:LSE振荡器作为RTC时钟
// 10:LSI振荡器作为RTC时钟
// 11:HSE振荡器在128分频后作为RTC时钟
#define RCC_RTCSEL_NONE ((u32)0x0<<8)
#define RCC_RTCSEL_LSE ((u32)0x1<<8)
#define RCC_RTCSEL_LSI ((u32)0x2<<8)
#define RCC_RTCSEL_HSE_DIV128 ((u32)0x3<<8)
#define RCC_RTCCLK_NONE 0x0
#define RCC_RTCCLK_LSE 0x1
#define RCC_RTCCLK_LSI 0x2
#define RCC_RTCCLK_HSE_DIV128 0x3
// LSEBYP:外部低速时钟振荡器旁路
#define RCC_LSEBYP ((u32)0x1<<2)
// LSERDY:外部低速LSE就绪
#define RCC_LSERDY ((u32)0x1<<1)
// LSEON:外部低速振荡器使能
#define RCC_LSEON ((u32)0x1<<0)
//--------------------------------------------------------------------
// 控制/状态寄存器 (RCC_CSR)
//--------------------------------------------------------------------
struct RCC_CSR_BITS {
unsigned LSION :1; // 0
unsigned LSIRDY :1; // 1
unsigned Reserved1 :22; // 23:2
unsigned RMVF :1; // 24
unsigned Reserved0 :1; // 25
unsigned PINRSTF :1; // 26
unsigned PORRSTF :1; // 27
unsigned SFTRSTF :1; // 28
unsigned IWDGRSTF :1; // 29
unsigned WWDGRSTF :1; // 30
unsigned LPWRRSTF :1; // 31
};
// 位31 LPWRRSTF:低功耗复位标志
// 位30 WWDGRSTF:窗口看门狗复位标志
// 位29 IWDGRSTF:独立看门狗复位标志
// 位28 SFTRSTF:软件复位标志
// 位27 PORRSTF:上电/掉电复位标志
// 位26 PINRSTF:NRST管脚复位标志
// 位24 RMVF 清除复位标志
// 位1 LSIRDY:内部低速时钟就绪
// 位0 LSION:内部低速振荡器使能 0:内部40kHz RC振荡器关闭
union RCC_CSR_REG {
Uint32 all;
struct RCC_BDCR_BITS bit;
};
#define RCC_LSION ((u32)0x1<<0)
typedef struct {
union RCC_CR_REG cr ; // 时钟控制寄存器 (RCC_CR)
union RCC_CFGR_REG cfgr ; // 时钟配置寄存器 (RCC_CFGR)
union RCC_CIR_REG cir ; // 时钟中断寄存器 (RCC_CIR)
union RCC_APB2RSTR_REG apb2rstr; // APB2 外设复位寄存器 (RCC_APB2RSTR)
union RCC_APB1RSTR_REG apb1rstr; // APB1 外设复位寄存器 (RCC_APB1RSTR)
union RCC_AHBENR_REG ahbenr; // AHB外设时钟使能寄存器 (RCC_AHBENR)
union RCC_APB2ENR_REG apb2enr; // APB2 外设时钟使能寄存器 (RCC_APB2ENR)
union RCC_APB1ENR_REG apb1enr; // APB1 外设时钟使能寄存器 (RCC_APB1ENR)
union RCC_BDCR_REG bdcr; // 备份域控制寄存器 (RCC_BDCR)
union RCC_CSR_REG csr; // 控制/状态寄存器 (RCC_CSR)
}RCC_REGS;
// *******************************************************************************************************
// 5 通用和复用功能I/O(GPIO和AFIO) REMAP 重映射
// *******************************************************************************************************
#define Analog_Input 0
#define Input_floating 1
#define Input_pull_up 2
#define Input_pull_down 2
#define Output_push_pull 0
#define Output_open_drain 1
#define Output_Af_push_pull 2
// 11:复用功能开漏输出模式
#define Output_Af_open_drain 3
// MODE[]
#define Input_Mode 0
#define Output_Mode_10mhz 1
#define Output_Mode_2mhz 2
// 11:输出模式,最大速度50MHz
#define Output_Mode_50mhz 3
// OFFSET=0X00 32 BIT
struct GPIO_CRL_BITS {
Uint32 MODE0 :2; // 1:0 这两位 配置 引脚 0
Uint32 CNF0 :2; // 3:2
Uint32 MODE1 :2; // 5:4 这两位 配置 引脚 1
Uint32 CNF1 :2; // 7:6
Uint32 MODE2 :2; // 9:8
Uint32 CNF2 :2; // 11:10
Uint32 MODE3 :2; // 13:12
Uint32 CNF3 :2; // 15:14
Uint32 MODE4 :2; // 17:16
Uint32 CNF4 :2; // 19:18
Uint32 MODE5 :2; // 21:20
Uint32 CNF5 :2; // 23:22
Uint32 MODE6 :2; // 25:24
Uint32 CNF6 :2; // 27:26
Uint32 MODE7 :2; // 29:28 这两位 配置 引脚 7
Uint32 CNF7 :2; // 31:30
};
union GPIO_CRL_REG {
Uint32 all;
struct GPIO_CRL_BITS bit;
};
//--------------------------------------------------------------------
// 端口配置寄存器(GPIOx_CRH) (x=A..E)
//--------------------------------------------------------------------
struct GPIO_CRH_BITS {
Uint32 MODE8 :2; // 1:0; 这两位 配置 引脚 8
Uint32 CNF8 :2; // 3:2
Uint32 MODE9 :2; // 5:4
Uint32 CNF9 :2; // 7:6
Uint32 MODE10 :2; // 9:8
Uint32 CNF10 :2; // 11:10
Uint32 MODE11 :2; // 13:12
Uint32 CNF11 :2; // 15:14
Uint32 MODE12 :2; // 17:16
Uint32 CNF12 :2; // 19:18
Uint32 MODE13 :2; // 21:20
Uint32 CNF13 :2; // 23:22
Uint32 MODE14 :2; // 25:24
Uint32 CNF14 :2; // 27:26
Uint32 MODE15 :2; // 29:28
Uint32 CNF15 :2; // 31:30
};
union GPIO_CRH_REG {
Uint32 all;
struct GPIO_CRH_BITS bit;
};
//--------------------------------------------------------------------
// 5.2.3 端口输入数据寄存器(GPIOx_IDR) (x=A..E)
//--------------------------------------------------------------------
struct GPIO_IDR_BITS {
Uint32 IDR0 :1; // 0
Uint32 IDR1 :1; // 1
Uint32 IDR2 :1; // 2
Uint32 IDR3 :1; // 3
Uint32 IDR4 :1; // 4
Uint32 IDR5 :1; // 5
Uint32 IDR6 :1; // 6
Uint32 IDR7 :1; // 7
Uint32 IDR8 :1; // 8
Uint32 IDR9 :1; // 9
Uint32 IDR10 :1; // 10
Uint32 IDR11 :1; // 11
Uint32 IDR12 :1; // 12
Uint32 IDR13 :1; // 13
Uint32 IDR14 :1; // 14
Uint32 IDR15 :1; // 15
Uint32 Reserved0 :16; // 31:16 端口输入数据(y = 0…15) 这些位为只读并只能以字(16位)的形式读出。读出的值为对应I/O口的状态。
};
union GPIO_IDR_REG {
Uint32 all;
struct GPIO_IDR_BITS bit;
};
//--------------------------------------------------------------------
// 5.2.4 端口输出数据寄存器(GPIOx_ODR) (x=A..E)
//--------------------------------------------------------------------
struct GPIO_ODR_BITS {
Uint32 ODR0 :1; // 0
Uint32 ODR1 :1; // 1
Uint32 ODR2 :1; // 2
Uint32 ODR3 :1; // 3
Uint32 ODR4 :1; // 4
Uint32 ODR5 :1; // 5
Uint32 ODR6 :1; // 6
Uint32 ODR7 :1; // 7
Uint32 ODR8 :1; // 8
Uint32 ODR9 :1; // 9
Uint32 ODR10 :1; // 10
Uint32 ODR11 :1; // 11
Uint32 ODR12 :1; // 12
Uint32 ODR13 :1; // 13
Uint32 ODR14 :1; // 14
Uint32 ODR15 :1; // 15
Uint32 Reserved0 :16; // 31:16 端口输出数据(y = 0…15) 这些位可读可写并只能以字(16位)的形式操作。
};
union GPIO_ODR_REG {
Uint32 all;
struct GPIO_ODR_BITS bit;
};
//--------------------------------------------------------------------
// 5.2.5 端口位设置/复位寄存器(GPIOx_BSRR) (x=A..E)
//--------------------------------------------------------------------
struct GPIO_BSRR_BITS {
Uint32 BS0 :1; // 0
Uint32 BS1 :1; // 1
Uint32 BS2 :1; // 2
Uint32 BS3 :1; // 3
Uint32 BS4 :1; // 4
Uint32 BS5 :1; // 5
Uint32 BS6 :1; // 6
Uint32 BS7 :1; // 7
Uint32 BS8 :1; // 8
Uint32 BS9 :1; // 9
Uint32 BS10 :1; // 10
Uint32 BS11 :1; // 11
Uint32 BS12 :1; // 12
Uint32 BS13 :1; // 13
Uint32 BS14 :1; // 14
Uint32 BS15 :1; // 15
Uint32 BR0 :1; // 16
Uint32 BR1 :1; // 17
Uint32 BR2 :1; // 18
Uint32 BR3 :1; // 19
Uint32 BR4 :1; // 20
Uint32 BR5 :1; // 21
Uint32 BR6 :1; // 22
Uint32 BR7 :1; // 23
Uint32 BR8 :1; // 24
Uint32 BR9 :1; // 25
Uint32 BR10 :1; // 26
Uint32 BR11 :1; // 27
Uint32 BR12 :1; // 28
Uint32 BR13 :1; // 29
Uint32 BR14 :1; // 30
Uint32 BR15 :1; // 31
};
union GPIO_BSRR_REG {
Uint32 all;
struct GPIO_BSRR_BITS bit;
};
//--------------------------------------------------------------------
// 5.2.6 端口位复位寄存器(GPIOx_BRR) (x=A..E)
//--------------------------------------------------------------------
struct GPIO_BRR_BITS {
Uint32 BR0 :1; // 0
Uint32 BR1 :1; // 1
Uint32 BR2 :1; // 2
Uint32 BR3 :1; // 3
Uint32 BR4 :1; // 4
Uint32 BR5 :1; // 5
Uint32 BR6 :1; // 6
Uint32 BR7 :1; // 7
Uint32 BR8 :1; // 8
Uint32 BR9 :1; // 9
Uint32 BR10 :1; // 10
Uint32 BR11 :1; // 11
Uint32 BR12 :1; // 12
Uint32 BR13 :1; // 13
Uint32 BR14 :1; // 14
Uint32 BR15 :1; // 15
Uint32 Reserved :16; // 31:16
};
union GPIO_BRR_REG {
Uint32 all;
struct GPIO_BRR_BITS bit;
};
//--------------------------------------------------------------------
// 5.2.7 端口配置锁定寄存器(GPIOx_LCKR) (x=A..E)
//--------------------------------------------------------------------
// 1:锁定端口的配置
struct GPIO_LCKR_BITS {
Uint32 LCK0 :1; // 0
Uint32 LCK1 :1; // 1
Uint32 LCK2 :1; // 2
Uint32 LCK3 :1; // 3
Uint32 LCK4 :1; // 4
Uint32 LCK5 :1; // 5
Uint32 LCK6 :1; // 6
Uint32 LCK7 :1; // 7
Uint32 LCK8 :1; // 8
Uint32 LCK9 :1; // 9
Uint32 LCK10 :1; // 10
Uint32 LCK11 :1; // 11
Uint32 LCK12 :1; // 12
Uint32 LCK13 :1; // 13
Uint32 LCK14 :1; // 14
Uint32 LCK15 :1; // 15
Uint32 LCKK :1; // 16
Uint32 Reserved :15; // 31:17
};
union GPIO_LCKR_REG {
Uint32 all;
struct GPIO_LCKR_BITS bit;
};
struct GPIO_REGS {
union GPIO_CRL_REG crl ; // 端口配置低寄存器 (GPIOx_CRL) (x=A..E)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -