STM32F103 STM32F407 引脚配置 方法对比

来源:互联网 发布:现在学java前景怎么样 编辑:程序博客网 时间:2024/05/21 15:51

先说STM32F407引脚的配置方法

1. 首先以 UART4 为例,先把引脚配置成 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;  

2. 就是 Alternate function功能

3. 把 UATR4 映射到对应的引脚,看下图,UART4 属于AF8,代码是 GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_UART4);

4. 看下面的代码,其实 GPIO_AF_UART4 就是 AF8,从 M4 开始,意法半导体把外围模块分成了AF0-AF15,其实是一个多路复用器。

/**
  * @brief   AF 7 selection 
  */
#define GPIO_AF_USART1        ((uint8_t)0x07)  /* USART1 Alternate Function mapping */
#define GPIO_AF_USART2        ((uint8_t)0x07)  /* USART2 Alternate Function mapping */
#define GPIO_AF_USART3        ((uint8_t)0x07)  /* USART3 Alternate Function mapping */
#define GPIO_AF_I2S3ext       ((uint8_t)0x07)  /* I2S3ext Alternate Function mapping */

/**
  * @brief   AF 8 selection 
  */
#define GPIO_AF_UART4         ((uint8_t)0x08)  /* UART4 Alternate Function mapping */
#define GPIO_AF_UART5         ((uint8_t)0x08)  /* UART5 Alternate Function mapping */
#define GPIO_AF_USART6        ((uint8_t)0x08)  /* USART6 Alternate Function mapping */

5. M3 的下次在写吧,哈哈

0 0
原创粉丝点击