keil编译STM32工程时 #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)"

时间:2023-03-09 10:00:04
keil编译STM32工程时 #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)"

keil编译STM32工程时 #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)"

我们可以双击错误,然后会自动定位到文件 stm32f10x.h 中出错的地方,可以看到代码:

#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined
(STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD)
&& !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined
(STM32F10X_CL)
#error "Please select first the target STM32F10x device used in your application (in stm32f10x.h
file)"
#endif

这是因为 3.5 版本的库函数在配置和选择外设的时候通过宏定义来选择的,所以我们需要配
置 一 个 全 局 的 宏 定 义 变 量 。 按 照 步 骤 16 , 定 位 到 c/c++ 界 面 , 然 后 copy
“STM32F10X_MD,USE_STDPERIPH_DRIVER”到 Define 里面。
这里解释一下,如果你用的是大容量那么 STM32F10X_MD 修改为 STM32F10X_HD,小容
量修改为 STM32F10X_LD. 然后点击 OK。