The Application of struct In the Firmware Library.
The definition and reference method of the general struct are introduced last time. Next we will briefly describe how to use the struct in the official Firmware Library.
The reference method of struct pointer member variables is implemented through the "→" symbol. For example, to access the name of the member variable pointed to by student1 struct pointer, the method is:
stuednt1—>name;
For example, the port usage mode struct in the official STM32 Firmware Library is defined as follows:
Typedef enum {GPIO_Mode_AIN = 0x0, // simulate input mode GPIO_Mode_IN_FLOATING = 0x04, // float input mode GPIO_Mode_IPD = 0x28, // pull-down output mode GPIO_Mode_IPU = 0x48, // pull-up output mode GPIO_Mode_Out_OD = 0x14, // export mode GPIO_Mode_Out_PP = 0x10, // general push-pull output mode GPIO_Mode_AF_OD = 0x1C, // output GPIO_Mode_AF_PP = 0x18 // output of the reuse function} GPIOMode_TypeDef;
Typedef enum // port transmission 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 port settings in the official library. The specific reference is as follows:
# Include "stm32f10"
Void Delay (u32 count)
{
U32 I = 0;
For (; I <count; I ++ );
}
Int main (void)
{
GPIO-InitTypeDef GPIO-InitStructure; // defines the struct type
RCC-APB2PeriphClockCmd (RCC-APB2Peruph-GPIO, ENABLE); // ENABLE peripheral clock APB2
GPIO-InitStructure.GPIO-Pin = GPIO-Pin-5; // configure PB.5 Port
GPIO-InitStructure.GPIO-Mode = GPIO-Mode-Out-PP; // push-pull output
GPIO-InitStructure.GPIO-Speed-50MHz; // IO port speed is 50 MHz
GPIO-Init (GPIOB, GPIO-Pin-5); // PB.5 port Initialization
While (1)
{
GPIO-ResetBits (GPIOB, GPIO-Pin-5); // PB.5B low output
Delay (3000000); // latency
GPIO-SetBits (GPIOB, GPIO-Pin-5); // PB.5 output height
Delay (3000000 );
}
}
This program is PB.5 port for LED light shining program.
Therefore, you must configure the corresponding port before using the STM32 program.