STMF103C8T6宏定义
时间: 2025-05-28 17:34:59 浏览: 20
### STM32F103C8T6 宏定义列表及其用途
#### 设备配置宏定义
设备特定的宏定义通常位于头文件 `stm32f1xx.h` 中,这些宏用于指定芯片的具体型号和其他硬件特性。
```c
#define STM32F10X_LD /*!< Connect to STM32F10X_LD Device */
#define STM32F10X_LD_VL /*!< Connect to STM32F10X_LD_VL Device */
#define STM32F10X_MD /*!< Connect to STM32F10X_MD Device */
#define STM32F10X_MD_VL /*!< Connect to STM32F10X_MD_VL Device */
#define STM32F10X_HD /*!< Connect to STM32F10X_HD Device */
#define STM32F10X_XL /*!< Connect to STM32F10X_XL Device */
#define STM32F10X_CL /*!< Connect to STM32F10X_CL Device */
```
对于 STM32F103C8T6 芯片而言,应使用如下宏来指明目标器件[^1]:
```c
#define USE_STDPERIPH_DRIVER /*!< Use Standard Peripheral Driver Library */
#define STM32F10X_LD /*!< Selects the STM32F103 Low-density device */
```
#### 外设使能/失能控制宏定义
外设功能的开启与关闭通过 RCC (Reset and Clock Control) 寄存器中的位操作完成。为了简化这一过程,在标准库中提供了相应的宏定义以便于管理各个外设模块的工作状态。
```c
/* Enable or disable the AHB peripheral clock */
#define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
__IO uint32_t tmpreg; \
SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOAEN);\
/* Delay after an RCC peripheral clock enabling */\
tmpreg = READ_BIT(RCC->AHBENR,RCC_AHBENR_GPIOAEN);\
UNUSED(tmpreg); \
} while(0)
#define __HAL_RCC_GPIOA_CLK_DISABLE() CLEAR_BIT(RCC->AHBENR, RCC_AHBENR_GPIOAEN)
...
// 类似地还有其他GPIO端口以及更多外设的使能和禁用宏定义
```
上述代码片段展示了如何启用或停用 GPIOA 的时钟信号[^5]。
#### 输入输出模式设置宏定义
针对不同的应用场景需求,可以利用预处理器指令快速设定 I/O 口的工作方式,比如推挽输出、开漏输出等。
```c
/* Configure the GPIO pin Output Type */
#define GPIO_MODE_OUTPUT_PP ((uint32_t)0x0008U) /*!< Push Pull output */
#define GPIO_MODE_OUTPUT_OD ((uint32_t)0x0010U) /*!< Open Drain output */
/* Configure the speed of IO port */
#define GPIO_SPEED_FREQ_LOW ((uint32_t)0x0001U) /*!< Low Speed */
#define GPIO_SPEED_FREQ_MEDIUM ((uint32_t)0x0002U) /*!< Medium Speed */
#define GPIO_SPEED_FREQ_HIGH ((uint32_t)0x0004U) /*!< High Speed */
#define GPIO_SPEED_FREQ_VERY_HIGH ((uint32_t)0x000AU) /*!< Very high Speed */
```
以上列举了一些常用的输入输出配置选项。
#### 中断优先级分组宏定义
当涉及到多中断源的应用场景下,合理安排各中断请求之间的相对重要性和响应顺序至关重要。为此,NVIC 提供了一套灵活可调的抢占式优先级机制,并配套有便于编程人员使用的辅助工具——即一系列专门用来调整该属性值大小关系的宏命令。
```c
/* NVIC Priority Group Configuration */
#define NVIC_PRIORITYGROUP_0 ((uint32_t)0x700UL << 8) /*!< 0 Bits for pre-emption priority,
4 bits for subpriority */
#define NVIC_PRIORITYGROUP_1 ((uint32_t)0x600UL << 8) /*!< 1 Bit for pre-emption priority,
3 bits for subpriority */
#define NVIC_PRIORITYGROUP_2 ((uint32_t)0x500UL << 8) /*!< 2 Bits for pre-emption priority,
2 bits for subpriority */
#define NVIC_PRIORITYGROUP_3 ((uint32_t)0x400UL << 8) /*!< 3 Bits for pre-emption priority,
1 bit for subpriority */
#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x300UL << 8) /*!< 4 Bits for pre-emption priority,
0 bit for subpriority */
```
此部分宏允许开发者根据实际项目的复杂度自由选择合适的中断调度策略[^4]。
阅读全文
相关推荐


















