标准库、HAl库和LL库(PC13初始化)
标准库 (Standard Peripheral Library)
c
#include "stm32f10x.h"void GPIO_Init_PC13(void) {GPIO_InitTypeDef GPIO_InitStruct;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽输出GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;GPIO_Init(GPIOC, &GPIO_InitStruct);
}
HAL库 (Hardware Abstraction Layer)
c
#include "stm32f1xx_hal.h"void GPIO_Init_PC13(void) {GPIO_InitTypeDef GPIO_InitStruct = {0};__HAL_RCC_GPIOC_CLK_ENABLE();GPIO_InitStruct.Pin = GPIO_PIN_13;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // 推挽输出GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
LL库 (Low-Layer Library)
c
#include "stm32f1xx_ll_gpio.h"
#include "stm32f1xx_ll_bus.h"void GPIO_Init_PC13(void) {LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);LL_GPIO_SetPinMode(GPIOC, LL_GPIO_PIN_13, LL_GPIO_MODE_OUTPUT);LL_GPIO_SetPinOutputType(GPIOC, LL_GPIO_PIN_13, LL_GPIO_OUTPUT_PUSHPULL);LL_GPIO_SetPinSpeed(GPIOC, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_LOW);
}