1.简单的c语言
#include "sys.h"
#include "uart1.h"
#include "delay.h"
#define LED_CLK() __HAL_RCC_GPIOB_CLK_ENABLE()
#define LED_GPIO GPIOB
#define LED_PIN GPIO_PIN_8
void led_init(void); /* LED初始化函数声明 */
int main(void)
{
HAL_Init(); /* 初始化HAL库 */
stm32_clock_init(RCC_PLL_MUL9); /* 设置时钟, 72Mhz */
led_init(); /* LED初始化 */
uart1_init(115200);
printf("running...\r\n");
while(1)
{
HAL_GPIO_WritePin(LED_GPIO,LED_PIN,GPIO_PIN_SET);
delay_ms(500);
HAL_GPIO_WritePin(LED_GPIO,LED_PIN,GPIO_PIN_RESET);
delay_ms(500);
}
}
/**
* @brief 初始化LED相关IO口, 并使能时钟
* @param 无
* @retval 无
*/
void led_init(void)
{
GPIO_InitTypeDef gpio_initstruct;
LED_CLK(); /* IO口时钟使能 */
gpio_initstruct.Pin = LED_PIN; /* LED0引脚 */
gpio_initstruct.Mode = GPIO_MODE_OUTPUT_PP; /* 推挽输出 */
gpio_initstruct.Pull = GPIO_PULLUP; /* 上拉 */
gpio_initstruct.Speed = GPIO_SPEED_FREQ_HIGH; /* 高速 */
HAL_GPIO_Init(LED_GPIO, &gpio_initstruct); /* 初始化LED0引脚 */
}
2.HAL_Init(); /* 初始化HAL库 */
f12看看调用了什么库 具体的方法
调用了
C:\Users\Administrator\Desktop\base\00. STM32F103工程模板\STM32F103C8T6_Template\Drivers\STM32F1xx_HAL_Driver\Src
C:\Users\Administrator\Desktop\base\00. STM32F103工程模板\STM32F103C8T6_Template\Drivers\STM32F1xx_HAL_Driver\Src
stm32f1xx_hal.c
具体的详细参考
STM32F1xx HAL库 中文详解 之 综合概述(一)_hal库中文手册-CSDN博客
HAL_StatusTypeDef HAL_Init(void)
{
/* Configure Flash prefetch */
#if (PREFETCH_ENABLE != 0)
#if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || \
defined(STM32F102x6) || defined(STM32F102xB) || \
defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || \
defined(STM32F105xC) || defined(STM32F107xC)
/* Prefetch buffer is not available on value line devices */
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
#endif
#endif /* PREFETCH_ENABLE */
/* Set Interrupt Group Priority */
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
/* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
HAL_InitTick(TICK_INT_PRIORITY);
/* Init the low level hardware */
HAL_MspInit();
/* Return function status */
return HAL_OK;
}