keil报错Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file

本文详细介绍了在使用Keil进行STM32开发时遇到的一个常见问题——设备未定义错误的解决方案。通过修改stm32f1xx.h头文件中的设备定义,并在项目设置中添加相应的宏定义,可以有效解决该问题。

最近一次在使用keil时发现有一个报错是

Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file

报错内容
查看了stm32f1xx.h头文件报错的地方,发现是没有定义具体的设备,解决方法如下:

  1. 在报错的头文件里面找到一段如下的定义代码,然后找到自己型号对应的定义并复制,例如我这里是STM32F103xB
    查找定义代码
  2. 打开魔法棒→C/C++→define,添加信息:
    STM32F103xB,USE_STDPERIPH_DRIVER
    其中第一个文本就是要改成我们第一步查到的定义
    添加define
  3. 点击OK保持,然后运行一下就成功了

我这例子是报错出现在stm32f1xx.h头文件的,其他的头文件也可能会有类似的报错,解决方法同理。

Build started: Project: BC26-Smoker *** Using Compiler 'V5.06 update 6 (build 750)', folder: 'C:\迅雷下载\keil ruanj\ARM\ARMCC\Bin' Build target 'Target 1' compiling stm32f1xx_hal_adc_ex.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_adc_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal_adc.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_adc.c: 0 warnings, 1 error compiling stm32f1xx_hal_rcc_ex.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_rcc_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal_rcc.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_rcc.c: 0 warnings, 1 error compiling stm32f1xx_hal_tim.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_tim.c: 0 warnings, 1 error compiling stm32f1xx_hal_gpio_ex.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_gpio_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal.c: 0 warnings, 1 error compiling misc.c... compiling stm32f1xx_hal_exti.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_exti.c: 0 warnings, 1 error compiling stm32f1xx_hal_dma.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_dma.c: 0 warnings, 1 error compiling stm32f1xx_hal_pwr.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_pwr.c: 0 warnings, 1 error compiling stm32f1xx_hal_cortex.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_cortex.c: 0 warnings, 1 error compiling stm32f1xx_hal_flash.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_flash.c: 0 warnings, 1 error compiling stm32f1xx_hal_flash_ex.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_flash_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal_gpio.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_gpio.c: 0 warnings, 1 error compiling stm32f1xx_hal_tim_ex.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_tim_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal_uart.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\libarary\src\stm32f1xx_hal_uart.c: 0 warnings, 1 error compiling stm32f10x_bkp.c... compiling stm32f10x_adc.c... compiling stm32f10x_cec.c... compiling stm32f10x_can.c... compiling stm32f10x_crc.c... compiling stm32f10x_dac.c... compiling stm32f10x_dbgmcu.c... compiling stm32f10x_dma.c... compiling stm32f10x_exti.c... compiling stm32f10x_flash.c... compiling stm32f10x_fsmc.c... compiling stm32f10x_gpio.c... compiling stm32f10x_iwdg.c... compiling stm32f10x_i2c.c... compiling stm32f10x_pwr.c... compiling stm32f10x_rtc.c... compiling stm32f10x_rcc.c... compiling stm32f10x_spi.c... compiling stm32f10x_sdio.c... compiling gpio.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\system\gpio\gpio.c: 0 warnings, 1 error compiling system.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\system\sys\system.c: 0 warnings, 1 error compiling stm32f10x_usart.c... compiling stm32f10x_tim.c... compiling stm32f10x_wwdg.c... compiling delay1.c... compiling tim.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\system\timer\tim.c: 0 warnings, 1 error compiling usart.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ..\system\usart\usart.c: 0 warnings, 1 error compiling sys.c... compiling adc.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" adc\adc.c: 0 warnings, 1 error compiling timer.c... ..\system\timer\timer.c(2): error: #5: cannot open source input file "led.h": No such file or directory #include "led.h" ..\system\timer\timer.c: 0 warnings, 1 error compiling BC26.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" bc26\BC26.c: 0 warnings, 1 error compiling ds18b20.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" ds18b20\ds18b20.c: 0 warnings, 1 error compiling lcd1602.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" lcd1602\lcd1602.c: 0 warnings, 1 error compiling usart1.c... ..\system\usart\usart1.c(20): warning: #260-D: explicit type is missing ("int" assumed) _sys_exit(int x) ..\system\usart\usart1.c: 1 warning, 0 errors compiling system_stm32f10x.c... compiling main.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" main.c: 0 warnings, 1 error compiling core_cm3.c... compiling wdg.c... compiling adc1.c... compiling stm32f10x_it.c... compiling main1.c... ..\user\stm32f1xx.h(140): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" main1.c: 0 warnings, 1 error ".\Objects\BC26-Smoker.axf" - 27 Error(s), 1 Warning(s). Target not created. Build Time Elapsed: 00:00:03
最新发布
09-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值