// At first, define a function named Init;
//结构体GPIO_INITSTRUCT
void LED_Init(void)
{
//step 1
/*********定义一个GPIO_InitTypeDef 类型的结构体**********/
GPIO_InitTypeDef GPIO_InitStruct;
//step 2 Assign values to the GPIO_InitStruct
//Set three Values to the InitStuct;
/*********选择要控制的GPIOx的引脚**********/
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_4;
/*********设置引脚速率为50MHZ**********/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
/*********设置引脚模式为通用推完输出**********/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
//step 3 open RCC of GPIOx
/*打开LED使用的GPIO的时钟使能*/
RCC_APB2PeriphClockCmd(RCC__APB2Periph_GPIOA, ENABLE);
//STEP 4 Init GPIOx
//
/*初始化相应的GPIO*/
GPIO_Init(GPIOA, &GPIO_InitStruct); //初始化GPIO_LED
}
//Content of GPIO_InitTypeDef
typedef struct
{
uint16_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
This parameter can be any value of @ref GPIO_pins_define */
GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
This parameter can be a value of @ref GPIOSpeed_TypeDef */
GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
This parameter can be a value of @ref GPIOMode_TypeDef */
}GPIO_InitTypeDef;
//Content of GPIO_Init(GPIOx, &InitStruct);
// Because GPIOx IS a Address InitStruct is a variable, Should Add & sign before InitStuct;
//
/*定义GPIOA-H 寄存器结构体指针*/
#define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
#define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
#define GPIOC ((GPIO_TypeDef *) GPIOC_BASE)
#define GPIOD ((GPIO_TypeDef *) GPIOD_BASE)
#define GPIOE ((GPIO_TypeDef *) GPIOE_BASE)
#define GPIOF ((GPIO_TypeDef *) GPIOF_BASE)
#define GPIOG ((GPIO_TypeDef *) GPIOG_BASE)
#define GPIOH ((GPIO_TypeDef *) GPIOH_BASE)
//void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
// Content of GPIO_Init( )
//Content of GPIO_TypeDef;
typedef struct
{
__IO uint32_t CRL;
__IO uint32_t CRH;
__IO uint32_t IDR;
__IO uint32_t ODR;
__IO uint32_t BSRR;
__IO uint32_t BRR;
__IO uint32_t LCKR;
} GPIO_TypeDef;