STM32MP157系列教程连载-Cortex-M4开发篇2:STM32MP1微控制器之GPIO编程
第 1 章 Cortex-M4 GPIO编程
实验目的
熟悉STM32CubeIDE工具软件的使用。
掌握STM32CubeIDE软件的基本设计流程和设计步骤,能够使用工具进行设计、编程、仿真调试。
学习GPIO口的使用方法,掌握如何利用STM32MP157A芯片的I/O口控制LED。
实验环境
FS_MP1A开发平台
ST-Link仿真器
STM32CubeIDE开发软件
PC机 XP、Window7/10 (32/64bit)
实验原理
只要是对硬件操作,就要首先查看原理图。查看外设是和模块的MCU的哪个引脚相连。FS_MP1A开发平台上的LED的亮灭状态,与芯片上的引脚I/O输出电平有关。
FS_MP1A开发平台上LED的I/O:
IO操作重要结构体:GPIO_InitTypeDef
/**
* @brief GPIO Init structure definition
*/
typedef struct
{
uint32_t Pin; /*!< Specifies the GPIO pins to be configured.
This parameter can be any value of @ref GPIO_pins_define */
uint32_t Mode; /*!< Specifies the operating mode for the selected pins.
This parameter can be a value of @ref GPIO_mode_define */
uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
This parameter can be a value of @ref GPIO_pull_define */
uint32_t Speed; /*!< Specifies the speed for the selected pins.
This parameter can be a value of @ref GPIO_speed_define */
uint32_t Alternate; /*!< Peripheral to be connected to the selected pins.
This parameter can be a value of @ref GPIO_Alternate_function_selection */
}GPIO_InitTypeDef;
第一个成员变量Pin是所操作的管脚,第二个Mode是模式选择,第三个Pull是上拉下拉,或者都不加,第四个Speed是速度选择,第五个是管脚复用功能。一般我们只操作前四个。
IO口可以由软件配置成4种模式,其实操作的是GPIO的端口模式寄存器:
- 输入(复位状态)/input(reset state)
- 通用输出模式 / general purpose output mode
- 复用功能模式 / alternate function mode
- 模拟模式 / analog mode
#