STM32 library function port initialization description

Publisher:EnchantedMagicLatest update time:2018-08-12 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The following only describes the operation ports of these two MCU library functions.

1. Port function description
STM32F0 series
typedef struct
{
  uint32_t GPIO_Pin; //Pin configuration
  
  GPIOMode_TypeDef GPIO_Mode; //Port mode
  GPIOSpeed_TypeDef GPIO_Speed; //Pin speed
  GPIOOType_TypeDef GPIO_OType; //Output setting
  GPIOPuPd_TypeDef GPIO_PuPd; //Pin setting
}GPIO_InitTypeDef;


typedef enum
{
  GPIO_Mode_IN = 0x00, //Input
  GPIO_Mode_OUT = 0x01, //Output
  GPIO_Mode_AF = 0x02, //Floating input 
  GPIO_Mode_AN = 0x03 //Analog input

}GPIOMode_TypeDef;


typedef enum
{
  GPIO_OType_PP = 0x00, //Push-pull
  GPIO_OType_OD = 0x01 //Open drain
}GPIOOType_TypeDef;


typedef enum
{
  GPIO_Speed_Level_1 = 0x01, //Medium speed
  GPIO_Speed_Level_2 = 0x02, //Low speed
  GPIO_Speed_Level_3 = 0x03 //High speed
}GPIOSpeed_TypeDef;


typedef enum
{
  GPIO_PuPd_NOPULL = 0x00, //No pull-up and pull-down
  GPIO_PuPd_UP = 0x01, //Pu-up
  GPIO_PuPd_DOWN = 0x02 //Pu-down
}GPIOPuPd_TypeDef;
------------------------------------------------------------

STM32F1 series


typedef struct
{
  uint16_t GPIO_Pin; //Pin configuration
  
  GPIOSpeed_TypeDef GPIO_Speed; //Pin speed
  GPIOMode_TypeDef GPIO_Mode; //Port mode
}GPIO_InitTypeDef;


typedef enum
{ GPIO_Mode_AIN = 0x0, //Analog input
  GPIO_Mode_IN_FLOATING = 0x04, //Floating input
  GPIO_Mode_IPD = 0x28, //Pull-down input
  GPIO_Mode_IPU = 0x48, //Pull-up input
  GPIO_Mode_Out_OD = 0x14, //Open drain output
  GPIO_Mode_Out_PP = 0x10, //Push-pull output
  GPIO_Mode_AF_OD = 0x1C, //Open drain multiplexing
  GPIO_Mode_AF_PP = 0x18 //Push-pull multiplexing
}GPIOMode_TypeDef;


typedef enum

  GPIO_Speed_10MHz = 1, //10MHz
  GPIO_Speed_2MHz, //2MHz
  GPIO_Speed_50MHz //50MHz
}GPIOSpeed_TypeDef;


2. Initialization function body


STM32F0 series
void Myport_Init(void)
{
/*Define a structure of type GPIO_InitTypeDef*/
GPIO_InitTypeDef GPIO_InitStruct; 
/*Turn on the peripheral clock of GPIOA*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/*Set the controlled GPIOA pin*/
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
/*Set the port mode of the controlled GPIOA pin*/
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
/*Set the pin setting of the controlled GPIOA pin*/
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
/*Set the pin rate to high speed*/
GPIO_InitStruct.GPIO_Speed ​​=GPIO_Speed_Level_3;
/*Call library function to initialize GPIOA*/
GPIO_Init(GPIOA, &GPIO_InitStruct);
}


STM32F1 series
void Myport_Init(void)
{
/*Define a structure of type GPIO_InitTypeDef*/
GPIO_InitTypeDef GPIO_InitStructure;
/*Turn on the peripheral clock of GPIOC*/
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE); 
/*Select the GPIOC pin to be controlled*/   
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; 
/*Set the pin mode to general push-pull output*/
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   
/*Set the pin rate to 50MHz */   
  GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz; 
/*Call library function to initialize GPIOC*/
  GPIO_Init(GPIOC, &GPIO_InitStructure);  
}


Keywords:STM32 Reference address:STM32 library function port initialization description

Previous article:STM32F051C8T6 control LED
Next article:STM32 GPIO brief introduction and initialization configuration (library function)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号