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);
}
Previous article:STM32F051C8T6 control LED
Next article:STM32 GPIO brief introduction and initialization configuration (library function)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- The brushless drive solution for the 17th Smart Car Competition sponsored by Lingdong is now open source
- Texas Instruments CC1310 Synchronous Transmit and Receive
- [National Technology N32G457 Review] RT_Thread Studio drives CAN and STM32F103VE communication
- 16 Years of Taiwanese New Year
- 【Project Source Code】Digital Signal Processing Learning——Mixer
- Chapter 4: Use of Timers and PWM
- Ask an outrageous question, why do we need to use a resistor to form a discharge path for the capacitor to discharge?
- An annular solar eclipse is coming. Have those in the annular eclipse zone seen it?
- How to set differential traces for high-speed USB positive and negative in AD16 PCB
- 【Infineon XENSIV PAS CO2 sensor】Official data study