第一步:新建文件夹,复制文件。
解压后的HAL库包文件夹为STM32Cube_FW_F4_V1.28.0,下文用Pack代替 。
TEMPLATE
CMSIS
Include
Pack\Drivers\CMSIS
Include
Pack\Drivers\CMSIS\Device\ST\STM32F4xx\
Include
Source
Pack\Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates
"system_stm32f4xx.c"
Pack\Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\arm
all
HW
Inc
Pack\Projects\STM32F4-Discovery\Templates\Inc
"stm32f4xx_it.h"
Src
Pack\Projects\STM32F4-Discovery\Templates\Src
"stm32f4xx_it.c"
LIB
Inc
Pack\Drivers\STM32F4xx_HAL_Driver
Inc
Src
Pack\Drivers\STM32F4xx_HAL_Driver
Src
USER
stm32f4xx_hal_conf_template.h 需去掉_template
第二步:KEIL新建工程,添加需要的文件。
CMSIS
"startup_stm32f407xx.s"
"system_stm32f4xx.c"
HW
"stm32f4xx_it.c"
LIB
"stm32f4xx_hal.c"
"stm32f4xx_hal_cortex.c"
"stm32f4xx_hal_rcc.c"
"stm32f4xx_hal_rcc_ex.c"
"stm32f4xx_hal_gpio.c"
USER
"main.c"
main.c
#include "stm32f4xx_hal.h"
int main(void)
{
}
stm32f4xx_it.c
把#include "main.h"
替换为#include "stm32f4xx_hal.h"
第三步:配置工程相关
KEIL > options for Target > Target > ARM Compiler > Use version 5
> enable "Use MicroLIB"
> Output > enable "Create HEX File"
> disable "Browse Information"
> C/C++ > Define > STM32F407xx, USE_HAL_DRIVER, USE_FULL_LL_DRIVER
> enable "C99 Mode"
> Include Paths > "add Include Paths"
参考资料:超子说物联网、安富莱。