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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近一次在使用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头文件的,其他的头文件也可能会有类似的报错,解决方法同理。

是编译过程中报的错Rebuild target 'FreeRTOS' compiling stm32f1xx_hal_cortex.c... ..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h(141): 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)" ..\..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c: 0 warnings, 1 error compiling system_stm32f1xx.c... ..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h(141): 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)" ..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c: 0 warnings, 1 error compiling sys.c... ..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h(141): 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)" ..\..\Drivers\SYSTEM\sys\sys.c: 0 warnings, 1 error compiling stm32f1xx_hal_gpio_ex.c... ..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h(141): 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)" ..\..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c: 0 warnings, 1 error compiling stm32f1xx_hal_pwr.c... ..\..\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h(141): 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 stm32f
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值