The last time we introduced the definition of a general struct and the method of referencing it, the next step is to make a brief description of how the structure is used in the official firmware library.
struct pointer member variable reference method is through the "→ symbol to access the member variable name of the struct that the Student1 struct pointer points to, then the method is:
stuednt1->name;
as in the STM32 official firmware library, the port usage pattern structure is defined as follows:
typedefenum{Gpio_mode_ain=0x0,//Analog input mode gpio_mode_in_floating=0x04,//floating-air input mode GPIO_MODE_IPD=0x28,//drop-down output mode Gpio_mode_ipu=0x48,//pull-up output mode Gpio_mode_out_od=0x14,//open-Drain output mode gpio_mode_out_pp=0x10,//Universal push-Pull output mode Gpio_mode_af_od=0x1C,//Multiplexing function open-drain output gpio_mode_af_pp=0x18 //multiplexing function push-pull output }gpiomode_typedef;
typedef enum//port transfer rate setting
{ Gpio_speed_10mhz = 1,
Gpio-speed-2mhz;
Gpio-speed-50mhz;
}gpiospeed_typedef;
typedef struct
{uint16-t gpio-pin;
Gpiospeed-typedef Gpio-speed;
Gpiomode-typedef Gpio-mode;
}gpio_inittypedef;
The above are some of the ports in the official library settings, the specific reference to the following examples:
#include "stm32f10 "
void Delay (u32 count)
{
u32 i=0;
For (; i<count;i++);
}
int main (void)
{
Gpio-inittypedef gpio-initstructure; defining struct types
Rcc-apb2periphclockcmd (rcc-apb2peruph-gpio,enable); Enable Peripheral Clock APB2
gpio-initstructure.gpio-pin=gpio-pin-5; Configuring the pb.5 Port
GPIO-INITSTRUCTURE.GPIO-MODE=GPIO-MODE-OUT-PP; Push-Pull output
Gpio-initstructure.gpio-speed-50mhz; IO port speed is 50MHz
Gpio-init (gpiob,gpio-pin-5); PB.5 Port Initialization
while (1)
{
Gpio-resetbits (gpiob,gpio-pin-5); pb.5b Output Low
Delay (3000000);//delay
Gpio-setbits (gpiob,gpio-pin-5); pb.5 Output High
Delay (3000000);
}
}
This program is the pb.5 port for the LED light of the flashing program.
thus, in the process of compiling the STM32 , the corresponding port must be configured beforehand before it can be used.
Application of structure in firmware library