可以给我一个STM32芯片的封装库
时间: 2023-05-25 16:06:47 浏览: 55
以下是一个STM32F103C8T6芯片的封装库:
```
#ifndef _STM32F103C8T6_H_
#define _STM32F103C8T6_H_
#include <stdint.h>
/* Port base addresses */
#define GPIOA_BASE 0x40010800
#define GPIOB_BASE 0x40010C00
#define GPIOC_BASE 0x40011000
#define GPIOD_BASE 0x40011400
#define GPIOE_BASE 0x40011800
#define GPIOF_BASE 0x40011C00
#define GPIOG_BASE 0x40012000
/* Register offsets */
#define GPIO_CRL_OFFSET 0x00
#define GPIO_CRH_OFFSET 0x04
#define GPIO_IDR_OFFSET 0x08
#define GPIO_ODR_OFFSET 0x0C
#define GPIO_BSRR_OFFSET 0x10
/* GPIO port registers */
typedef struct {
volatile uint32_t CRL; /* Port configuration register low */
volatile uint32_t CRH; /* Port configuration register high */
volatile uint32_t IDR; /* Port input data register */
volatile uint32_t ODR; /* Port output data register */
volatile uint32_t BSRR; /* Port bit set/reset register */
} GPIO_TypeDef;
/* Available pins on each port */
#define GPIO_A_PIN_0 0
#define GPIO_A_PIN_1 1
#define GPIO_A_PIN_2 2
#define GPIO_A_PIN_3 3
#define GPIO_A_PIN_4 4
#define GPIO_A_PIN_5 5
#define GPIO_A_PIN_6 6
#define GPIO_A_PIN_7 7
#define GPIO_A_PIN_8 8
#define GPIO_A_PIN_9 9
#define GPIO_A_PIN_10 10
#define GPIO_A_PIN_11 11
#define GPIO_A_PIN_12 12
#define GPIO_A_PIN_13 13
#define GPIO_A_PIN_14 14
#define GPIO_A_PIN_15 15
#define GPIO_B_PIN_0 0
#define GPIO_B_PIN_1 1
#define GPIO_B_PIN_2 2
#define GPIO_B_PIN_3 3
#define GPIO_B_PIN_4 4
#define GPIO_B_PIN_5 5
#define GPIO_B_PIN_6 6
#define GPIO_B_PIN_7 7
#define GPIO_B_PIN_8 8
#define GPIO_B_PIN_9 9
#define GPIO_B_PIN_10 10
#define GPIO_B_PIN_11 11
#define GPIO_B_PIN_12 12
#define GPIO_B_PIN_13 13
#define GPIO_B_PIN_14 14
#define GPIO_B_PIN_15 15
#define GPIO_C_PIN_0 0
#define GPIO_C_PIN_1 1
#define GPIO_C_PIN_2 2
#define GPIO_C_PIN_3 3
#define GPIO_C_PIN_4 4
#define GPIO_C_PIN_5 5
#define GPIO_C_PIN_6 6
#define GPIO_C_PIN_7 7
#define GPIO_C_PIN_8 8
#define GPIO_C_PIN_9 9
#define GPIO_C_PIN_10 10
#define GPIO_C_PIN_11 11
#define GPIO_C_PIN_12 12
#define GPIO_C_PIN_13 13
#define GPIO_C_PIN_14 14
#define GPIO_C_PIN_15 15
#define GPIO_D_PIN_0 0
#define GPIO_D_PIN_1 1
#define GPIO_D_PIN_2 2
#define GPIO_D_PIN_3 3
#define GPIO_D_PIN_4 4
#define GPIO_D_PIN_5 5
#define GPIO_D_PIN_6 6
#define GPIO_D_PIN_7 7
#define GPIO_D_PIN_8 8
#define GPIO_D_PIN_9 9
#define GPIO_D_PIN_10 10
#define GPIO_D_PIN_11 11
#define GPIO_D_PIN_12 12
#define GPIO_D_PIN_13 13
#define GPIO_D_PIN_14 14
#define GPIO_D_PIN_15 15
#define GPIO_E_PIN_0 0
#define GPIO_E_PIN_1 1
#define GPIO_E_PIN_2 2
#define GPIO_E_PIN_3 3
#define GPIO_E_PIN_4 4
#define GPIO_E_PIN_5 5
#define GPIO_E_PIN_6 6
#define GPIO_E_PIN_7 7
#define GPIO_E_PIN_8 8
#define GPIO_E_PIN_9 9
#define GPIO_E_PIN_10 10
#define GPIO_E_PIN_11 11
#define GPIO_E_PIN_12 12
#define GPIO_E_PIN_13 13
#define GPIO_E_PIN_14 14
#define GPIO_E_PIN_15 15
#define GPIO_F_PIN_0 0
#define GPIO_F_PIN_1 1
#define GPIO_F_PIN_2 2
#define GPIO_F_PIN_3 3
#define GPIO_F_PIN_4 4
#define GPIO_F_PIN_5 5
#define GPIO_F_PIN_6 6
#define GPIO_F_PIN_7 7
#define GPIO_F_PIN_8 8
#define GPIO_F_PIN_9 9
#define GPIO_F_PIN_10 10
#define GPIO_F_PIN_11 11
#define GPIO_F_PIN_12 12
#define GPIO_F_PIN_13 13
#define GPIO_F_PIN_14 14
#define GPIO_F_PIN_15 15
#define GPIO_G_PIN_0 0
#define GPIO_G_PIN_1 1
#define GPIO_G_PIN_2 2
#define GPIO_G_PIN_3 3
#define GPIO_G_PIN_4 4
#define GPIO_G_PIN_5 5
#define GPIO_G_PIN_6 6
#define GPIO_G_PIN_7 7
#define GPIO_G_PIN_8 8
#define GPIO_G_PIN_9 9
#define GPIO_G_PIN_10 10
#define GPIO_G_PIN_11 11
#define GPIO_G_PIN_12 12
#define GPIO_G_PIN_13 13
#define GPIO_G_PIN_14 14
#define GPIO_G_PIN_15 15
/* GPIO pin modes */
#define GPIO_MODE_INPUT 0x00
#define GPIO_MODE_OUTPUT_10MHZ 0x01
#define GPIO_MODE_OUTPUT_2MHZ 0x02
#define GPIO_MODE_OUTPUT_50MHZ 0x03
/* GPIO pin configuration */
#define GPIO_CNF_PUSH_PULL 0x00
#define GPIO_CNF_OPEN_DRAIN 0x01
/* Function prototypes */
void gpio_configure_pin(GPIO_TypeDef * port, uint8_t pin, uint8_t mode, uint8_t conf);
void gpio_set_pin(GPIO_TypeDef * port, uint8_t pin);
void gpio_clear_pin(GPIO_TypeDef * port, uint8_t pin);
void gpio_toggle_pin(GPIO_TypeDef * port, uint8_t pin);
#endif /* _STM32F103C8T6_H_ */
```
该封装库实现了对STM32F103C8T6芯片的GPIO控制,包括引脚配置、引脚输出控制。如果需要使用其他的外设,需要按照特定的寄存器映射关系编写代码。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)