寄存器开发优点
直接操作寄存器,运行效率高。
寄存器开发缺点
1、开发难度大,开发周期长
2、代码可阅读性差,可移植差
3、后期维护难度高
库函数开发优点
1、开发难度较小,开发周期短
2、代码可阅读性强,可移植高
3、后期维护难度低
库函数开发缺点
相对于寄存器开发,运行效率略低
注意:库函数其实是ST公司对寄存器的进一步封装。
库函数开发LED要添加的库函数文件:stm32f4xx_gpio.c


1、理解led灯原理图
LED0连接在PF9
PF9输出低电平(0),灯亮;PF9输出高电平(0),灯灭;

2、打开GPIOF组时钟
在STM32芯片中,所有的外设时钟是不打开,为了降低功耗
//打开GPIOF组时钟 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
3、设置PF9灯为输出模式 输出推挽 上拉 速度(50MHZ)
// stm32f4xx_gpio.htypedef struct{
uint32_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured. This parameter can be any value of @ref GPIO_pins_define */ GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins. This parameter can be a value of @ref GPIOMode_TypeDef */ GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins. This parameter can be a value of @ref GPIOSpeed_TypeDef */ GPIOOType_TypeDef GPIO_OType; /*!< Specifies the operating output type for the selected pins. This parameter can be a value of @ref GPIOOType_TypeDef */ GPIOPuPd_TypeDef GPIO_PuPd; /*!< Specifies the operating Pull-up/Pull down for the selected pins. This parameter can be a value of @ref GPIOPuPd_TypeDef */}GPIO_InitTypeDef;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9; //引脚GP