keil编译STM32工程时 #error directive: "Please select first the target STM32F10x device used in your appli...

AI助手已提取文章相关产品:

我们可以双击错误,然后会自动定位到文件 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。

您可能感兴趣的与本文相关内容

*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Rebuild target 'Target 1' assembling startup_stm32f10x_md.s... compiling system_stm32f10x.c... start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" start\system_stm32f10x.c: 0 warnings, 1 error compiling misc.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\misc.c: 0 warnings, 1 error compiling stm32f10x_adc.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_adc.c: 0 warnings, 1 error compiling stm32f10x_bkp.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_bkp.c: 0 warnings, 1 error compiling stm32f10x_can.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_can.c: 0 warnings, 1 error compiling stm32f10x_cec.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_cec.c: 0 warnings, 1 error compiling stm32f10x_crc.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_crc.c: 0 warnings, 1 error compiling stm32f10x_dac.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_dac.c: 0 warnings, 1 error compiling stm32f10x_dbgmcu.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_dbgmcu.c: 0 warnings, 1 error compiling stm32f10x_dma.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_dma.c: 0 warnings, 1 error compiling stm32f10x_exti.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_exti.c: 0 warnings, 1 error compiling stm32f10x_flash.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_flash.c: 0 warnings, 1 error compiling stm32f10x_fsmc.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_fsmc.c: 0 warnings, 1 error compiling stm32f10x_gpio.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_gpio.c: 0 warnings, 1 error compiling stm32f10x_i2c.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_i2c.c: 0 warnings, 1 error compiling stm32f10x_iwdg.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_iwdg.c: 0 warnings, 1 error compiling stm32f10x_pwr.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_pwr.c: 0 warnings, 1 error compiling stm32f10x_rcc.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_rcc.c: 0 warnings, 1 error compiling stm32f10x_rtc.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_rtc.c: 0 warnings, 1 error compiling stm32f10x_sdio.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_sdio.c: 0 warnings, 1 error compiling stm32f10x_spi.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_spi.c: 0 warnings, 1 error compiling stm32f10x_tim.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_tim.c: 0 warnings, 1 error compiling stm32f10x_usart.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_usart.c: 0 warnings, 1 error compiling stm32f10x_wwdg.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" library\stm32f10x_wwdg.c: 0 warnings, 1 error assembling cr4_fft_256_stm32.s... compiling OLED.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" Hardware\OLED.c: 0 warnings, 1 error compiling OLED_Data.c... compiling main.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" user\main.c: 0 warnings, 1 error compiling stm32f10x_it.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" user\stm32f10x_it.c: 0 warnings, 1 error compiling ADC.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" user\ADC.c: 0 warnings, 1 error compiling mydelay.c... compiling myTIM.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" user\myTIM.c: 0 warnings, 1 error compiling Sound_Sensor_Init.c... .\start\stm32f10x.h(97): error: #35: #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" #error "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)" user\Sound_Sensor_Init.c: 0 warnings, 1 error ".\Objects\project.axf" - 30 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:05
最新发布
07-20
Keil编译STM32F10x项目,如果遇到错误提示: ``` #error "Please select first the target STM32F10x device used in your application" ``` 这通常是因为编译器无法确定目标设备型号,需要手动配置以选择正确的STM32F10x系列芯片型号。 ### 错误原因 在 `stm32f10x.h` 文件中,编译器通过预处理器宏定义来判断所使用的具体MCU型号。如果没有定义任何目标设备宏(如 `STM32F10X_MD`、`STM32F10X_HD` 等),则会触发该错误[^2]。 ### 解决方案 #### 方法一:通过Keil配置定义宏 1. 打开Keil µVision项目。 2. 点击工具栏上的 **"Options for Target"**(魔术棒图标)。 3. 在弹出的窗口中切换到 **"C/C++"** 选项卡。 4. 在 **"Define"** 输入框中添加以下宏定义(根据实际MCU型号选择): - `USE_STDPERIPH_DRIVER`(如果使用标准外设库) - `STM32F10X_MD`(适用于中等容量芯片,如STM32F103C8) - `STM32F10X_LD`(适用于低容量芯片) - `STM32F10X_HD`(适用于高容量芯片) - `STM32F10X_XL`(适用于超大容量芯片) 示例(以STM32F103C8为例): ``` USE_STDPERIPH_DRIVER,STM32F10X_MD ``` 5. 点击 **"OK"** 并重新编译项目[^3]。 #### 方法二:修改 `stm32f10x.h` 文件 如果不希望通过Keil定义宏,也可以直接在 `stm32f10x.h` 文件中手动定义目标设备型号。找到以下代码段: ```c #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 ``` 在该段代码前添加所需的宏定义,例如: ```c #define STM32F10X_MD #define USE_STDPERIPH_DRIVER ``` 这样也可以避免编译错误[^1]。 ### 附加建议 - 确保使用的标准外设库版本与芯片型号兼容。 - 如果使用CubeMX生成的代码,检查是否已正确配置并生成了对应的头文件。 - 确保工程中包含正确的启动文件(如 `startup_stm32f10x_md.s`)。 ---
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值