你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】STM32 GPIO相关函数和类型

[复制链接]
STMCU小助手 发布时间:2022-4-3 15:00
01. GPIO固件库概述stm32f4xx_gpio.h GPIO相关函数和类型的声明stm32f4xx_gpio.c GPIO相关函数具体实现。02. GPIO相关类型GPIO相关的类型几乎都在stm32f4xx_gpio.h文件中。GPIO的模式
  1. /**
  2.   * @brief  GPIO Configuration Mode enumeration
  3.   */   
  4. typedef enum
  5. {
  6.   GPIO_Mode_IN   = 0x00, /*!< GPIO Input Mode */
  7.   GPIO_Mode_OUT  = 0x01, /*!< GPIO Output Mode */
  8.   GPIO_Mode_AF   = 0x02, /*!< GPIO Alternate function Mode */
  9.   GPIO_Mode_AN   = 0x03  /*!< GPIO Analog Mode */
  10. }GPIOMode_TypeDef;
  11. #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)  || ((MODE) == GPIO_Mode_OUT) || \
  12.                             ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
复制代码
GPIO输出类型
  1. /**
  2.   * @brief  GPIO Output type enumeration
  3.   */  
  4. typedef enum
  5. {
  6.   GPIO_OType_PP = 0x00,
  7.   GPIO_OType_OD = 0x01
  8. }GPIOOType_TypeDef;
  9. #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
复制代码
GPIO输出速度
  1. /**
  2.   * @brief  GPIO Output Maximum frequency enumeration
  3.   */  
  4. typedef enum
  5. {
  6.   GPIO_Low_Speed     = 0x00, /*!< Low speed    */
  7.   GPIO_Medium_Speed  = 0x01, /*!< Medium speed */
  8.   GPIO_Fast_Speed    = 0x02, /*!< Fast speed   */
  9.   GPIO_High_Speed    = 0x03  /*!< High speed   */
  10. }GPIOSpeed_TypeDef;
  11. /* Add legacy definition */
  12. #define  GPIO_Speed_2MHz    GPIO_Low_Speed   
  13. #define  GPIO_Speed_25MHz   GPIO_Medium_Speed
  14. #define  GPIO_Speed_50MHz   GPIO_Fast_Speed
  15. #define  GPIO_Speed_100MHz  GPIO_High_Speed  
  16. #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Low_Speed) || ((SPEED) == GPIO_Medium_Speed) || \
  17.                               ((SPEED) == GPIO_Fast_Speed)||  ((SPEED) == GPIO_High_Speed))
复制代码
GPIO上下拉
  1. /**
  2.   * @brief  GPIO Configuration PullUp PullDown enumeration
  3.   */
  4. typedef enum
  5. {
  6.   GPIO_PuPd_NOPULL = 0x00,
  7.   GPIO_PuPd_UP     = 0x01,
  8.   GPIO_PuPd_DOWN   = 0x02
  9. }GPIOPuPd_TypeDef;
  10. #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
  11.                             ((PUPD) == GPIO_PuPd_DOWN))
复制代码
GPIO置位和复位
  1. /**
  2.   * @brief  GPIO Bit SET and Bit RESET enumeration
  3.   */
  4. typedef enum
  5. {
  6.   Bit_RESET = 0,
  7.   Bit_SET
  8. }BitAction;
  9. #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
复制代码
GPIO初始化结构体类型声明
  1. /**
  2.   * @brief   GPIO Init structure definition  
  3.   */
  4. typedef struct
  5. {
  6.   uint32_t GPIO_Pin;              /*!< Specifies the GPIO pins to be configured.
  7.                                        This parameter can be any value of @ref GPIO_pins_define */
  8.   GPIOMode_TypeDef GPIO_Mode;     /*!< Specifies the operating mode for the selected pins.
  9.                                        This parameter can be a value of @ref GPIOMode_TypeDef */
  10.   GPIOSpeed_TypeDef GPIO_Speed;   /*!< Specifies the speed for the selected pins.
  11.                                        This parameter can be a value of @ref GPIOSpeed_TypeDef */
  12.   GPIOOType_TypeDef GPIO_OType;   /*!< Specifies the operating output type for the selected pins.
  13.                                        This parameter can be a value of @ref GPIOOType_TypeDef */
  14.   GPIOPuPd_TypeDef GPIO_PuPd;     /*!< Specifies the operating Pull-up/Pull down for the selected pins.
  15.                                        This parameter can be a value of @ref GPIOPuPd_TypeDef */
  16. }GPIO_InitTypeDef;
复制代码
03. GPIO相关宏判断是否为合法的GPIO外设
  1. #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
  2.                                     ((PERIPH) == GPIOB) || \
  3.                                     ((PERIPH) == GPIOC) || \
  4.                                     ((PERIPH) == GPIOD) || \
  5.                                     ((PERIPH) == GPIOE) || \
  6.                                     ((PERIPH) == GPIOF) || \
  7.                                     ((PERIPH) == GPIOG) || \
  8.                                     ((PERIPH) == GPIOH) || \
  9.                                     ((PERIPH) == GPIOI) || \
  10.                                     ((PERIPH) == GPIOJ) || \
  11.                                     ((PERIPH) == GPIOK))
复制代码
GPIO合法的引脚
  1. /** @defgroup GPIO_pins_define
  2.   * @{
  3.   */
  4. #define GPIO_Pin_0                 ((uint16_t)0x0001)  /* Pin 0 selected */
  5. #define GPIO_Pin_1                 ((uint16_t)0x0002)  /* Pin 1 selected */
  6. #define GPIO_Pin_2                 ((uint16_t)0x0004)  /* Pin 2 selected */
  7. #define GPIO_Pin_3                 ((uint16_t)0x0008)  /* Pin 3 selected */
  8. #define GPIO_Pin_4                 ((uint16_t)0x0010)  /* Pin 4 selected */
  9. #define GPIO_Pin_5                 ((uint16_t)0x0020)  /* Pin 5 selected */
  10. #define GPIO_Pin_6                 ((uint16_t)0x0040)  /* Pin 6 selected */
  11. #define GPIO_Pin_7                 ((uint16_t)0x0080)  /* Pin 7 selected */
  12. #define GPIO_Pin_8                 ((uint16_t)0x0100)  /* Pin 8 selected */
  13. #define GPIO_Pin_9                 ((uint16_t)0x0200)  /* Pin 9 selected */
  14. #define GPIO_Pin_10                ((uint16_t)0x0400)  /* Pin 10 selected */
  15. #define GPIO_Pin_11                ((uint16_t)0x0800)  /* Pin 11 selected */
  16. #define GPIO_Pin_12                ((uint16_t)0x1000)  /* Pin 12 selected */
  17. #define GPIO_Pin_13                ((uint16_t)0x2000)  /* Pin 13 selected */
  18. #define GPIO_Pin_14                ((uint16_t)0x4000)  /* Pin 14 selected */
  19. #define GPIO_Pin_15                ((uint16_t)0x8000)  /* Pin 15 selected */
  20. #define GPIO_Pin_All               ((uint16_t)0xFFFF)  /* All pins selected */
  21. #define GPIO_PIN_MASK              ((uint32_t)0x0000FFFF) /* PIN mask for assert test */
  22. #define IS_GPIO_PIN(PIN)           (((PIN) & GPIO_PIN_MASK ) != (uint32_t)0x00)
  23. #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
  24.                               ((PIN) == GPIO_Pin_1) || \
  25.                               ((PIN) == GPIO_Pin_2) || \
  26.                               ((PIN) == GPIO_Pin_3) || \
  27.                               ((PIN) == GPIO_Pin_4) || \
  28.                               ((PIN) == GPIO_Pin_5) || \
  29.                               ((PIN) == GPIO_Pin_6) || \
  30.                               ((PIN) == GPIO_Pin_7) || \
  31.                               ((PIN) == GPIO_Pin_8) || \
  32.                               ((PIN) == GPIO_Pin_9) || \
  33.                               ((PIN) == GPIO_Pin_10) || \
  34.                               ((PIN) == GPIO_Pin_11) || \
  35.                               ((PIN) == GPIO_Pin_12) || \
  36.                               ((PIN) == GPIO_Pin_13) || \
  37.                               ((PIN) == GPIO_Pin_14) || \
  38.                               ((PIN) == GPIO_Pin_15))
复制代码
GPIO合法的引脚源
  1. /** @defgroup GPIO_Pin_sources
  2.   * @{
  3.   */
  4. #define GPIO_PinSource0            ((uint8_t)0x00)
  5. #define GPIO_PinSource1            ((uint8_t)0x01)
  6. #define GPIO_PinSource2            ((uint8_t)0x02)
  7. #define GPIO_PinSource3            ((uint8_t)0x03)
  8. #define GPIO_PinSource4            ((uint8_t)0x04)
  9. #define GPIO_PinSource5            ((uint8_t)0x05)
  10. #define GPIO_PinSource6            ((uint8_t)0x06)
  11. #define GPIO_PinSource7            ((uint8_t)0x07)
  12. #define GPIO_PinSource8            ((uint8_t)0x08)
  13. #define GPIO_PinSource9            ((uint8_t)0x09)
  14. #define GPIO_PinSource10           ((uint8_t)0x0A)
  15. #define GPIO_PinSource11           ((uint8_t)0x0B)
  16. #define GPIO_PinSource12           ((uint8_t)0x0C)
  17. #define GPIO_PinSource13           ((uint8_t)0x0D)
  18. #define GPIO_PinSource14           ((uint8_t)0x0E)
  19. #define GPIO_PinSource15           ((uint8_t)0x0F)
  20. #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
  21.                                        ((PINSOURCE) == GPIO_PinSource1) || \
  22.                                        ((PINSOURCE) == GPIO_PinSource2) || \
  23.                                        ((PINSOURCE) == GPIO_PinSource3) || \
  24.                                        ((PINSOURCE) == GPIO_PinSource4) || \
  25.                                        ((PINSOURCE) == GPIO_PinSource5) || \
  26.                                        ((PINSOURCE) == GPIO_PinSource6) || \
  27.                                        ((PINSOURCE) == GPIO_PinSource7) || \
  28.                                        ((PINSOURCE) == GPIO_PinSource8) || \
  29.                                        ((PINSOURCE) == GPIO_PinSource9) || \
  30.                                        ((PINSOURCE) == GPIO_PinSource10) || \
  31.                                        ((PINSOURCE) == GPIO_PinSource11) || \
  32.                                        ((PINSOURCE) == GPIO_PinSource12) || \
  33.                                        ((PINSOURCE) == GPIO_PinSource13) || \
  34.                                        ((PINSOURCE) == GPIO_PinSource14) || \
  35.                                        ((PINSOURCE) == GPIO_PinSource15))
复制代码
04. GPIO相关函数
  1. /*  Function used to set the GPIO configuration to the default reset state ****/
  2. //配置GPIO为默认状态
  3. void GPIO_DeInit(GPIO_TypeDef* GPIOx);
  4. /* Initialization and Configuration functions *********************************/
  5. //GPIO初始化
  6. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
  7. //GPIO结构体初始化
  8. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
  9. //GPIO锁配置
  10. void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  11. /* GPIO Read and Write functions **********************************************/
  12. //GPIO读写函数
  13. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  14. uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  15. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  16. uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  17. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  18. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  19. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
  20. void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
  21. void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  22. /* GPIO Alternate functions configuration function ****************************/
  23. void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
复制代码
05. GPIO其它相关stm32f4xx.h文件中通用GPIO结构体封装
  1. typedef struct
  2. {
  3.   __IO uint32_t MODER;    /*!< GPIO port mode register,               Address offset: 0x00      */
  4.   __IO uint32_t OTYPER;   /*!< GPIO port output type register,        Address offset: 0x04      */
  5.   __IO uint32_t OSPEEDR;  /*!< GPIO port output speed register,       Address offset: 0x08      */
  6.   __IO uint32_t PUPDR;    /*!< GPIO port pull-up/pull-down register,  Address offset: 0x0C      */
  7.   __IO uint32_t IDR;      /*!< GPIO port input data register,         Address offset: 0x10      */
  8.   __IO uint32_t ODR;      /*!< GPIO port output data register,        Address offset: 0x14      */
  9.   __IO uint16_t BSRRL;    /*!< GPIO port bit set/reset low register,  Address offset: 0x18      */
  10.   __IO uint16_t BSRRH;    /*!< GPIO port bit set/reset high register, Address offset: 0x1A      */
  11.   __IO uint32_t LCKR;     /*!< GPIO port configuration lock register, Address offset: 0x1C      */
  12.   __IO uint32_t AFR[2];   /*!< GPIO alternate function registers,     Address offset: 0x20-0x24 */
  13. } GPIO_TypeDef;
复制代码
GPIO基地址
  1. /*!< AHB1 peripherals */
  2. #define GPIOA_BASE            (AHB1PERIPH_BASE + 0x0000)
  3. #define GPIOB_BASE            (AHB1PERIPH_BASE + 0x0400)
  4. #define GPIOC_BASE            (AHB1PERIPH_BASE + 0x0800)
  5. #define GPIOD_BASE            (AHB1PERIPH_BASE + 0x0C00)
  6. #define GPIOE_BASE            (AHB1PERIPH_BASE + 0x1000)
  7. #define GPIOF_BASE            (AHB1PERIPH_BASE + 0x1400)
  8. #define GPIOG_BASE            (AHB1PERIPH_BASE + 0x1800)
  9. #define GPIOH_BASE            (AHB1PERIPH_BASE + 0x1C00)
  10. #define GPIOI_BASE            (AHB1PERIPH_BASE + 0x2000)
  11. #define GPIOJ_BASE            (AHB1PERIPH_BASE + 0x2400)
  12. #define GPIOK_BASE            (AHB1PERIPH_BASE + 0x2800)
复制代码
GPIO起始地址
  1. #define GPIOA               ((GPIO_TypeDef *) GPIOA_BASE)
  2. #define GPIOB               ((GPIO_TypeDef *) GPIOB_BASE)
  3. #define GPIOC               ((GPIO_TypeDef *) GPIOC_BASE)
  4. #define GPIOD               ((GPIO_TypeDef *) GPIOD_BASE)
  5. #define GPIOE               ((GPIO_TypeDef *) GPIOE_BASE)
  6. #define GPIOF               ((GPIO_TypeDef *) GPIOF_BASE)
  7. #define GPIOG               ((GPIO_TypeDef *) GPIOG_BASE)
  8. #define GPIOH               ((GPIO_TypeDef *) GPIOH_BASE)
  9. #define GPIOI               ((GPIO_TypeDef *) GPIOI_BASE)
  10. #define GPIOJ               ((GPIO_TypeDef *) GPIOJ_BASE)
  11. #define GPIOK               ((GPIO_TypeDef *) GPIOK_BASE)
复制代码
GPIO寄存器相关位
  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                            General Purpose I/O                             */
  4. /*                                                                            */
  5. /******************************************************************************/
  6. /******************  Bits definition for GPIO_MODER register  *****************/
  7. #define GPIO_MODER_MODER0                    ((uint32_t)0x00000003)
  8. #define GPIO_MODER_MODER0_0                  ((uint32_t)0x00000001)
  9. #define GPIO_MODER_MODER0_1                  ((uint32_t)0x00000002)
  10. #define GPIO_MODER_MODER1                    ((uint32_t)0x0000000C)
  11. #define GPIO_MODER_MODER1_0                  ((uint32_t)0x00000004)
  12. #define GPIO_MODER_MODER1_1                  ((uint32_t)0x00000008)
  13. #define GPIO_MODER_MODER2                    ((uint32_t)0x00000030)
  14. #define GPIO_MODER_MODER2_0                  ((uint32_t)0x00000010)
  15. #define GPIO_MODER_MODER2_1                  ((uint32_t)0x00000020)
  16. #define GPIO_MODER_MODER3                    ((uint32_t)0x000000C0)
  17. #define GPIO_MODER_MODER3_0                  ((uint32_t)0x00000040)
  18. #define GPIO_MODER_MODER3_1                  ((uint32_t)0x00000080)
  19. #define GPIO_MODER_MODER4                    ((uint32_t)0x00000300)
  20. #define GPIO_MODER_MODER4_0                  ((uint32_t)0x00000100)
  21. #define GPIO_MODER_MODER4_1                  ((uint32_t)0x00000200)
  22. #define GPIO_MODER_MODER5                    ((uint32_t)0x00000C00)
  23. #define GPIO_MODER_MODER5_0                  ((uint32_t)0x00000400)
  24. #define GPIO_MODER_MODER5_1                  ((uint32_t)0x00000800)
  25. #define GPIO_MODER_MODER6                    ((uint32_t)0x00003000)
  26. #define GPIO_MODER_MODER6_0                  ((uint32_t)0x00001000)
  27. #define GPIO_MODER_MODER6_1                  ((uint32_t)0x00002000)
  28. #define GPIO_MODER_MODER7                    ((uint32_t)0x0000C000)
  29. #define GPIO_MODER_MODER7_0                  ((uint32_t)0x00004000)
  30. #define GPIO_MODER_MODER7_1                  ((uint32_t)0x00008000)
  31. #define GPIO_MODER_MODER8                    ((uint32_t)0x00030000)
  32. #define GPIO_MODER_MODER8_0                  ((uint32_t)0x00010000)
  33. #define GPIO_MODER_MODER8_1                  ((uint32_t)0x00020000)
  34. #define GPIO_MODER_MODER9                    ((uint32_t)0x000C0000)
  35. #define GPIO_MODER_MODER9_0                  ((uint32_t)0x00040000)
  36. #define GPIO_MODER_MODER9_1                  ((uint32_t)0x00080000)
  37. #define GPIO_MODER_MODER10                   ((uint32_t)0x00300000)
  38. #define GPIO_MODER_MODER10_0                 ((uint32_t)0x00100000)
  39. #define GPIO_MODER_MODER10_1                 ((uint32_t)0x00200000)
  40. #define GPIO_MODER_MODER11                   ((uint32_t)0x00C00000)
  41. #define GPIO_MODER_MODER11_0                 ((uint32_t)0x00400000)
  42. #define GPIO_MODER_MODER11_1                 ((uint32_t)0x00800000)
  43. #define GPIO_MODER_MODER12                   ((uint32_t)0x03000000)
  44. #define GPIO_MODER_MODER12_0                 ((uint32_t)0x01000000)
  45. #define GPIO_MODER_MODER12_1                 ((uint32_t)0x02000000)
  46. #define GPIO_MODER_MODER13                   ((uint32_t)0x0C000000)
  47. #define GPIO_MODER_MODER13_0                 ((uint32_t)0x04000000)
  48. #define GPIO_MODER_MODER13_1                 ((uint32_t)0x08000000)
  49. #define GPIO_MODER_MODER14                   ((uint32_t)0x30000000)
  50. #define GPIO_MODER_MODER14_0                 ((uint32_t)0x10000000)
  51. #define GPIO_MODER_MODER14_1                 ((uint32_t)0x20000000)
  52. #define GPIO_MODER_MODER15                   ((uint32_t)0xC0000000)
  53. #define GPIO_MODER_MODER15_0                 ((uint32_t)0x40000000)
  54. #define GPIO_MODER_MODER15_1                 ((uint32_t)0x80000000)
  55. /******************  Bits definition for GPIO_OTYPER register  ****************/
  56. #define GPIO_OTYPER_OT_0                     ((uint32_t)0x00000001)
  57. #define GPIO_OTYPER_OT_1                     ((uint32_t)0x00000002)
  58. #define GPIO_OTYPER_OT_2                     ((uint32_t)0x00000004)
  59. #define GPIO_OTYPER_OT_3                     ((uint32_t)0x00000008)
  60. #define GPIO_OTYPER_OT_4                     ((uint32_t)0x00000010)
  61. #define GPIO_OTYPER_OT_5                     ((uint32_t)0x00000020)
  62. #define GPIO_OTYPER_OT_6                     ((uint32_t)0x00000040)
  63. #define GPIO_OTYPER_OT_7                     ((uint32_t)0x00000080)
  64. #define GPIO_OTYPER_OT_8                     ((uint32_t)0x00000100)
  65. #define GPIO_OTYPER_OT_9                     ((uint32_t)0x00000200)
  66. #define GPIO_OTYPER_OT_10                    ((uint32_t)0x00000400)
  67. #define GPIO_OTYPER_OT_11                    ((uint32_t)0x00000800)
  68. #define GPIO_OTYPER_OT_12                    ((uint32_t)0x00001000)
  69. #define GPIO_OTYPER_OT_13                    ((uint32_t)0x00002000)
  70. #define GPIO_OTYPER_OT_14                    ((uint32_t)0x00004000)
  71. #define GPIO_OTYPER_OT_15                    ((uint32_t)0x00008000)
  72. /******************  Bits definition for GPIO_OSPEEDR register  ***************/
  73. #define GPIO_OSPEEDER_OSPEEDR0               ((uint32_t)0x00000003)
  74. #define GPIO_OSPEEDER_OSPEEDR0_0             ((uint32_t)0x00000001)
  75. #define GPIO_OSPEEDER_OSPEEDR0_1             ((uint32_t)0x00000002)
  76. #define GPIO_OSPEEDER_OSPEEDR1               ((uint32_t)0x0000000C)
  77. #define GPIO_OSPEEDER_OSPEEDR1_0             ((uint32_t)0x00000004)
  78. #define GPIO_OSPEEDER_OSPEEDR1_1             ((uint32_t)0x00000008)
  79. #define GPIO_OSPEEDER_OSPEEDR2               ((uint32_t)0x00000030)
  80. #define GPIO_OSPEEDER_OSPEEDR2_0             ((uint32_t)0x00000010)
  81. #define GPIO_OSPEEDER_OSPEEDR2_1             ((uint32_t)0x00000020)
  82. #define GPIO_OSPEEDER_OSPEEDR3               ((uint32_t)0x000000C0)
  83. #define GPIO_OSPEEDER_OSPEEDR3_0             ((uint32_t)0x00000040)
  84. #define GPIO_OSPEEDER_OSPEEDR3_1             ((uint32_t)0x00000080)
  85. #define GPIO_OSPEEDER_OSPEEDR4               ((uint32_t)0x00000300)
  86. #define GPIO_OSPEEDER_OSPEEDR4_0             ((uint32_t)0x00000100)
  87. #define GPIO_OSPEEDER_OSPEEDR4_1             ((uint32_t)0x00000200)
  88. #define GPIO_OSPEEDER_OSPEEDR5               ((uint32_t)0x00000C00)
  89. #define GPIO_OSPEEDER_OSPEEDR5_0             ((uint32_t)0x00000400)
  90. #define GPIO_OSPEEDER_OSPEEDR5_1             ((uint32_t)0x00000800)
  91. #define GPIO_OSPEEDER_OSPEEDR6               ((uint32_t)0x00003000)
  92. #define GPIO_OSPEEDER_OSPEEDR6_0             ((uint32_t)0x00001000)
  93. #define GPIO_OSPEEDER_OSPEEDR6_1             ((uint32_t)0x00002000)
  94. #define GPIO_OSPEEDER_OSPEEDR7               ((uint32_t)0x0000C000)
  95. #define GPIO_OSPEEDER_OSPEEDR7_0             ((uint32_t)0x00004000)
  96. #define GPIO_OSPEEDER_OSPEEDR7_1             ((uint32_t)0x00008000)
  97. #define GPIO_OSPEEDER_OSPEEDR8               ((uint32_t)0x00030000)
  98. #define GPIO_OSPEEDER_OSPEEDR8_0             ((uint32_t)0x00010000)
  99. #define GPIO_OSPEEDER_OSPEEDR8_1             ((uint32_t)0x00020000)
  100. #define GPIO_OSPEEDER_OSPEEDR9               ((uint32_t)0x000C0000)
  101. #define GPIO_OSPEEDER_OSPEEDR9_0             ((uint32_t)0x00040000)
  102. #define GPIO_OSPEEDER_OSPEEDR9_1             ((uint32_t)0x00080000)
  103. #define GPIO_OSPEEDER_OSPEEDR10              ((uint32_t)0x00300000)
  104. #define GPIO_OSPEEDER_OSPEEDR10_0            ((uint32_t)0x00100000)
  105. #define GPIO_OSPEEDER_OSPEEDR10_1            ((uint32_t)0x00200000)
  106. #define GPIO_OSPEEDER_OSPEEDR11              ((uint32_t)0x00C00000)
  107. #define GPIO_OSPEEDER_OSPEEDR11_0            ((uint32_t)0x00400000)
  108. #define GPIO_OSPEEDER_OSPEEDR11_1            ((uint32_t)0x00800000)
  109. #define GPIO_OSPEEDER_OSPEEDR12              ((uint32_t)0x03000000)
  110. #define GPIO_OSPEEDER_OSPEEDR12_0            ((uint32_t)0x01000000)
  111. #define GPIO_OSPEEDER_OSPEEDR12_1            ((uint32_t)0x02000000)
  112. #define GPIO_OSPEEDER_OSPEEDR13              ((uint32_t)0x0C000000)
  113. #define GPIO_OSPEEDER_OSPEEDR13_0            ((uint32_t)0x04000000)
  114. #define GPIO_OSPEEDER_OSPEEDR13_1            ((uint32_t)0x08000000)
  115. #define GPIO_OSPEEDER_OSPEEDR14              ((uint32_t)0x30000000)
  116. #define GPIO_OSPEEDER_OSPEEDR14_0            ((uint32_t)0x10000000)
  117. #define GPIO_OSPEEDER_OSPEEDR14_1            ((uint32_t)0x20000000)
  118. #define GPIO_OSPEEDER_OSPEEDR15              ((uint32_t)0xC0000000)
  119. #define GPIO_OSPEEDER_OSPEEDR15_0            ((uint32_t)0x40000000)
  120. #define GPIO_OSPEEDER_OSPEEDR15_1            ((uint32_t)0x80000000)
  121. /******************  Bits definition for GPIO_PUPDR register  *****************/
  122. #define GPIO_PUPDR_PUPDR0                    ((uint32_t)0x00000003)
  123. #define GPIO_PUPDR_PUPDR0_0                  ((uint32_t)0x00000001)
  124. #define GPIO_PUPDR_PUPDR0_1                  ((uint32_t)0x00000002)
  125. #define GPIO_PUPDR_PUPDR1                    ((uint32_t)0x0000000C)
  126. #define GPIO_PUPDR_PUPDR1_0                  ((uint32_t)0x00000004)
  127. #define GPIO_PUPDR_PUPDR1_1                  ((uint32_t)0x00000008)
  128. #define GPIO_PUPDR_PUPDR2                    ((uint32_t)0x00000030)
  129. #define GPIO_PUPDR_PUPDR2_0                  ((uint32_t)0x00000010)
  130. #define GPIO_PUPDR_PUPDR2_1                  ((uint32_t)0x00000020)
  131. #define GPIO_PUPDR_PUPDR3                    ((uint32_t)0x000000C0)
  132. #define GPIO_PUPDR_PUPDR3_0                  ((uint32_t)0x00000040)
  133. #define GPIO_PUPDR_PUPDR3_1                  ((uint32_t)0x00000080)
  134. #define GPIO_PUPDR_PUPDR4                    ((uint32_t)0x00000300)
  135. #define GPIO_PUPDR_PUPDR4_0                  ((uint32_t)0x00000100)
  136. #define GPIO_PUPDR_PUPDR4_1                  ((uint32_t)0x00000200)
  137. #define GPIO_PUPDR_PUPDR5                    ((uint32_t)0x00000C00)
  138. #define GPIO_PUPDR_PUPDR5_0                  ((uint32_t)0x00000400)
  139. #define GPIO_PUPDR_PUPDR5_1                  ((uint32_t)0x00000800)
  140. #define GPIO_PUPDR_PUPDR6                    ((uint32_t)0x00003000)
  141. #define GPIO_PUPDR_PUPDR6_0                  ((uint32_t)0x00001000)
  142. #define GPIO_PUPDR_PUPDR6_1                  ((uint32_t)0x00002000)
  143. #define GPIO_PUPDR_PUPDR7                    ((uint32_t)0x0000C000)
  144. #define GPIO_PUPDR_PUPDR7_0                  ((uint32_t)0x00004000)
  145. #define GPIO_PUPDR_PUPDR7_1                  ((uint32_t)0x00008000)
  146. #define GPIO_PUPDR_PUPDR8                    ((uint32_t)0x00030000)
  147. #define GPIO_PUPDR_PUPDR8_0                  ((uint32_t)0x00010000)
  148. #define GPIO_PUPDR_PUPDR8_1                  ((uint32_t)0x00020000)
  149. #define GPIO_PUPDR_PUPDR9                    ((uint32_t)0x000C0000)
  150. #define GPIO_PUPDR_PUPDR9_0                  ((uint32_t)0x00040000)
  151. #define GPIO_PUPDR_PUPDR9_1                  ((uint32_t)0x00080000)
  152. #define GPIO_PUPDR_PUPDR10                   ((uint32_t)0x00300000)
  153. #define GPIO_PUPDR_PUPDR10_0                 ((uint32_t)0x00100000)
  154. #define GPIO_PUPDR_PUPDR10_1                 ((uint32_t)0x00200000)
  155. #define GPIO_PUPDR_PUPDR11                   ((uint32_t)0x00C00000)
  156. #define GPIO_PUPDR_PUPDR11_0                 ((uint32_t)0x00400000)
  157. #define GPIO_PUPDR_PUPDR11_1                 ((uint32_t)0x00800000)
  158. #define GPIO_PUPDR_PUPDR12                   ((uint32_t)0x03000000)
  159. #define GPIO_PUPDR_PUPDR12_0                 ((uint32_t)0x01000000)
  160. #define GPIO_PUPDR_PUPDR12_1                 ((uint32_t)0x02000000)
  161. #define GPIO_PUPDR_PUPDR13                   ((uint32_t)0x0C000000)
  162. #define GPIO_PUPDR_PUPDR13_0                 ((uint32_t)0x04000000)
  163. #define GPIO_PUPDR_PUPDR13_1                 ((uint32_t)0x08000000)
  164. #define GPIO_PUPDR_PUPDR14                   ((uint32_t)0x30000000)
  165. #define GPIO_PUPDR_PUPDR14_0                 ((uint32_t)0x10000000)
  166. #define GPIO_PUPDR_PUPDR14_1                 ((uint32_t)0x20000000)
  167. #define GPIO_PUPDR_PUPDR15                   ((uint32_t)0xC0000000)
  168. #define GPIO_PUPDR_PUPDR15_0                 ((uint32_t)0x40000000)
  169. #define GPIO_PUPDR_PUPDR15_1                 ((uint32_t)0x80000000)
  170. /******************  Bits definition for GPIO_IDR register  *******************/
  171. #define GPIO_IDR_IDR_0                       ((uint32_t)0x00000001)
  172. #define GPIO_IDR_IDR_1                       ((uint32_t)0x00000002)
  173. #define GPIO_IDR_IDR_2                       ((uint32_t)0x00000004)
  174. #define GPIO_IDR_IDR_3                       ((uint32_t)0x00000008)
  175. #define GPIO_IDR_IDR_4                       ((uint32_t)0x00000010)
  176. #define GPIO_IDR_IDR_5                       ((uint32_t)0x00000020)
  177. #define GPIO_IDR_IDR_6                       ((uint32_t)0x00000040)
  178. #define GPIO_IDR_IDR_7                       ((uint32_t)0x00000080)
  179. #define GPIO_IDR_IDR_8                       ((uint32_t)0x00000100)
  180. #define GPIO_IDR_IDR_9                       ((uint32_t)0x00000200)
  181. #define GPIO_IDR_IDR_10                      ((uint32_t)0x00000400)
  182. #define GPIO_IDR_IDR_11                      ((uint32_t)0x00000800)
  183. #define GPIO_IDR_IDR_12                      ((uint32_t)0x00001000)
  184. #define GPIO_IDR_IDR_13                      ((uint32_t)0x00002000)
  185. #define GPIO_IDR_IDR_14                      ((uint32_t)0x00004000)
  186. #define GPIO_IDR_IDR_15                      ((uint32_t)0x00008000)
  187. /* Old GPIO_IDR register bits definition, maintained for legacy purpose */
  188. #define GPIO_OTYPER_IDR_0                    GPIO_IDR_IDR_0
  189. #define GPIO_OTYPER_IDR_1                    GPIO_IDR_IDR_1
  190. #define GPIO_OTYPER_IDR_2                    GPIO_IDR_IDR_2
  191. #define GPIO_OTYPER_IDR_3                    GPIO_IDR_IDR_3
  192. #define GPIO_OTYPER_IDR_4                    GPIO_IDR_IDR_4
  193. #define GPIO_OTYPER_IDR_5                    GPIO_IDR_IDR_5
  194. #define GPIO_OTYPER_IDR_6                    GPIO_IDR_IDR_6
  195. #define GPIO_OTYPER_IDR_7                    GPIO_IDR_IDR_7
  196. #define GPIO_OTYPER_IDR_8                    GPIO_IDR_IDR_8
  197. #define GPIO_OTYPER_IDR_9                    GPIO_IDR_IDR_9
  198. #define GPIO_OTYPER_IDR_10                   GPIO_IDR_IDR_10
  199. #define GPIO_OTYPER_IDR_11                   GPIO_IDR_IDR_11
  200. #define GPIO_OTYPER_IDR_12                   GPIO_IDR_IDR_12
  201. #define GPIO_OTYPER_IDR_13                   GPIO_IDR_IDR_13
  202. #define GPIO_OTYPER_IDR_14                   GPIO_IDR_IDR_14
  203. #define GPIO_OTYPER_IDR_15                   GPIO_IDR_IDR_15
  204. /******************  Bits definition for GPIO_ODR register  *******************/
  205. #define GPIO_ODR_ODR_0                       ((uint32_t)0x00000001)
  206. #define GPIO_ODR_ODR_1                       ((uint32_t)0x00000002)
  207. #define GPIO_ODR_ODR_2                       ((uint32_t)0x00000004)
  208. #define GPIO_ODR_ODR_3                       ((uint32_t)0x00000008)
  209. #define GPIO_ODR_ODR_4                       ((uint32_t)0x00000010)
  210. #define GPIO_ODR_ODR_5                       ((uint32_t)0x00000020)
  211. #define GPIO_ODR_ODR_6                       ((uint32_t)0x00000040)
  212. #define GPIO_ODR_ODR_7                       ((uint32_t)0x00000080)
  213. #define GPIO_ODR_ODR_8                       ((uint32_t)0x00000100)
  214. #define GPIO_ODR_ODR_9                       ((uint32_t)0x00000200)
  215. #define GPIO_ODR_ODR_10                      ((uint32_t)0x00000400)
  216. #define GPIO_ODR_ODR_11                      ((uint32_t)0x00000800)
  217. #define GPIO_ODR_ODR_12                      ((uint32_t)0x00001000)
  218. #define GPIO_ODR_ODR_13                      ((uint32_t)0x00002000)
  219. #define GPIO_ODR_ODR_14                      ((uint32_t)0x00004000)
  220. #define GPIO_ODR_ODR_15                      ((uint32_t)0x00008000)
  221. /* Old GPIO_ODR register bits definition, maintained for legacy purpose */
  222. #define GPIO_OTYPER_ODR_0                    GPIO_ODR_ODR_0
  223. #define GPIO_OTYPER_ODR_1                    GPIO_ODR_ODR_1
  224. #define GPIO_OTYPER_ODR_2                    GPIO_ODR_ODR_2
  225. #define GPIO_OTYPER_ODR_3                    GPIO_ODR_ODR_3
  226. #define GPIO_OTYPER_ODR_4                    GPIO_ODR_ODR_4
  227. #define GPIO_OTYPER_ODR_5                    GPIO_ODR_ODR_5
  228. #define GPIO_OTYPER_ODR_6                    GPIO_ODR_ODR_6
  229. #define GPIO_OTYPER_ODR_7                    GPIO_ODR_ODR_7
  230. #define GPIO_OTYPER_ODR_8                    GPIO_ODR_ODR_8
  231. #define GPIO_OTYPER_ODR_9                    GPIO_ODR_ODR_9
  232. #define GPIO_OTYPER_ODR_10                   GPIO_ODR_ODR_10
  233. #define GPIO_OTYPER_ODR_11                   GPIO_ODR_ODR_11
  234. #define GPIO_OTYPER_ODR_12                   GPIO_ODR_ODR_12
  235. #define GPIO_OTYPER_ODR_13                   GPIO_ODR_ODR_13
  236. #define GPIO_OTYPER_ODR_14                   GPIO_ODR_ODR_14
  237. #define GPIO_OTYPER_ODR_15                   GPIO_ODR_ODR_15
  238. /******************  Bits definition for GPIO_BSRR register  ******************/
  239. #define GPIO_BSRR_BS_0                       ((uint32_t)0x00000001)
  240. #define GPIO_BSRR_BS_1                       ((uint32_t)0x00000002)
  241. #define GPIO_BSRR_BS_2                       ((uint32_t)0x00000004)
  242. #define GPIO_BSRR_BS_3                       ((uint32_t)0x00000008)
  243. #define GPIO_BSRR_BS_4                       ((uint32_t)0x00000010)
  244. #define GPIO_BSRR_BS_5                       ((uint32_t)0x00000020)
  245. #define GPIO_BSRR_BS_6                       ((uint32_t)0x00000040)
  246. #define GPIO_BSRR_BS_7                       ((uint32_t)0x00000080)
  247. #define GPIO_BSRR_BS_8                       ((uint32_t)0x00000100)
  248. #define GPIO_BSRR_BS_9                       ((uint32_t)0x00000200)
  249. #define GPIO_BSRR_BS_10                      ((uint32_t)0x00000400)
  250. #define GPIO_BSRR_BS_11                      ((uint32_t)0x00000800)
  251. #define GPIO_BSRR_BS_12                      ((uint32_t)0x00001000)
  252. #define GPIO_BSRR_BS_13                      ((uint32_t)0x00002000)
  253. #define GPIO_BSRR_BS_14                      ((uint32_t)0x00004000)
  254. #define GPIO_BSRR_BS_15                      ((uint32_t)0x00008000)
  255. #define GPIO_BSRR_BR_0                       ((uint32_t)0x00010000)
  256. #define GPIO_BSRR_BR_1                       ((uint32_t)0x00020000)
  257. #define GPIO_BSRR_BR_2                       ((uint32_t)0x00040000)
  258. #define GPIO_BSRR_BR_3                       ((uint32_t)0x00080000)
  259. #define GPIO_BSRR_BR_4                       ((uint32_t)0x00100000)
  260. #define GPIO_BSRR_BR_5                       ((uint32_t)0x00200000)
  261. #define GPIO_BSRR_BR_6                       ((uint32_t)0x00400000)
  262. #define GPIO_BSRR_BR_7                       ((uint32_t)0x00800000)
  263. #define GPIO_BSRR_BR_8                       ((uint32_t)0x01000000)
  264. #define GPIO_BSRR_BR_9                       ((uint32_t)0x02000000)
  265. #define GPIO_BSRR_BR_10                      ((uint32_t)0x04000000)
  266. #define GPIO_BSRR_BR_11                      ((uint32_t)0x08000000)
  267. #define GPIO_BSRR_BR_12                      ((uint32_t)0x10000000)
  268. #define GPIO_BSRR_BR_13                      ((uint32_t)0x20000000)
  269. #define GPIO_BSRR_BR_14                      ((uint32_t)0x40000000)
  270. #define GPIO_BSRR_BR_15                      ((uint32_t)0x80000000)
复制代码
GPIO全部挂载AHB1总线上
  1. /********************  Bit definition for RCC_AHB1ENR register  ***************/
  2. #define  RCC_AHB1ENR_GPIOAEN                 ((uint32_t)0x00000001)
  3. #define  RCC_AHB1ENR_GPIOBEN                 ((uint32_t)0x00000002)
  4. #define  RCC_AHB1ENR_GPIOCEN                 ((uint32_t)0x00000004)
  5. #define  RCC_AHB1ENR_GPIODEN                 ((uint32_t)0x00000008)
  6. #define  RCC_AHB1ENR_GPIOEEN                 ((uint32_t)0x00000010)
  7. #define  RCC_AHB1ENR_GPIOFEN                 ((uint32_t)0x00000020)
  8. #define  RCC_AHB1ENR_GPIOGEN                 ((uint32_t)0x00000040)
  9. #define  RCC_AHB1ENR_GPIOHEN                 ((uint32_t)0x00000080)
  10. #define  RCC_AHB1ENR_GPIOIEN                 ((uint32_t)0x00000100)
  11. #define  RCC_AHB1ENR_GPIOJEN                 ((uint32_t)0x00000200)
  12. #define  RCC_AHB1ENR_GPIOKEN                 ((uint32_t)0x00000400)
复制代码
收藏 评论0 发布时间:2022-4-3 15:00

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版