#error “Please select first the target STM32F4xx device used in your application (in stm32f4xx.h

本文介绍了如何解决在使用STM32F4xx微控制器时遇到的错误,问题出在没有正确选择应用中的目标设备。解决方案是根据STM32的存储器映射在stm32f4xx.h文件中定义寄存器地址,通过修改该头文件内容来修复Bug。
摘要由CSDN通过智能技术生成

一、Bug背景

在使用寄存器方式点亮LED时遇到的Bug

在这里插入图片描述
解决方案:
根据STM32的存储器映射先定义好各个寄存器的地址,并把这些地址定义都写在stm32f4xx.h中。
stm32f4xx.h文件里的全部内容如下:


/*片上外设基地址  */
#define PERIPH_BASE           ((unsigned int)0x40000000)                          

/*总线基地址 */
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)	

/*GPIO外设基地址*/
#define GPIOA_BASE            (AHB1PERIPH_BASE + 0x0000)


/* GPIOA寄存器地址,强制转换成指针 */
#define GPIOA_MODER				*(unsigned int*)(GPIOA_BASE+0x00)
#define GPIOA_OTYPER			*(unsigned int*)(GPIOA_BASE+0x04)
#define GPIOA_OSPEEDR			*(unsigned int*)(GPIOA_BASE+0x08)
#define GPIOA_PUPDR				*(unsigned int*)(GPIOA_BASE+0x0C)
#define GPIOA_IDR					*(unsigned int*)(GPIOA_BASE+0x10)
#define GPIOA_ODR					*(unsigned int*)(GPIOA_BASE+0x14)
#define GPIOA_BSRR					*(unsigned int*)(GPIOA_BASE+0x18)
#define GPIOA_LCKR					*(unsigned int*)(GPIOA_BASE+0x1C)
#define GPIOA_AFRL					*(unsigned int*)(GPIOA_BASE+0x20)
#define GPIOA_AFRH					*(unsigned int*)(GPIOA_BASE+0x24)

/*RCC外设基地址*/
#define RCC_BASE              (AHB1PERIPH_BASE + 0x3800)

/*RCC的AHB1时钟使能寄存器地址,强制转换成指针*/
#define RCC_AHB1ENR				*(unsigned int*)(RCC_BASE+0x30)
	

以上代码是stm32f4xx.h文件的内容
定义好各个寄存器地址后,再次编译程序,Bug就解决了。

出现Bug时stm32f4xx.h文件的内容如下: (修改前)

/**
  ******************************************************************************
  * @file    stm32f4xx.h
  * @author  MCD Application Team
  * @brief   CMSIS STM32F4xx Device Peripheral Access Layer Header File.
  *            
  *          The file is the unique include file that the application programmer
  *          is using in the C source code, usually in main.c. This file contains:
  *           - Configuration section that allows to select:
  *              - The STM32F4xx device used in the target application
  *              - To use or not the peripheral抯 drivers in application code(i.e. 
  *                code will be based on direct access to peripher
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Version: 2.15.0 (2020-09-28) Keil.STM32F4xx_DFP.2.15.0.pack Download Updated Pack to STM32Cube_FW_F4 Firmware Package version V1.25.1 using HAL Drivers V1.7.9. STM32CubeMX integration (Version 6.0.1): Added support for Timebase Source TIMx (FrameworkCubeMX_gpdsc.ftl). Removed non-existent include path. CMSIS Flash Algorithm: Corrected STM32F42xxx_43xxx_OPT Algorithm. CMSIS SVD: Updated STM32F42*.svd, STM32F43*.svd files. CMSIS-Driver: I2C: Corrected 2 byte reception in master mode. MCI: Replaced empty delay loops with _NOP(). SPI: Corrected PowerControl function (to return error if Initialize was not called, to abort active transfer if power off was requested). Updated GetDataCount function to give accurate count in DMA mode. Corrected Control function (abort in DMA mode, software controlled slave select in slave mode, TI Frame Format selection, ignore bus speed for slave mode). Corrected Uninitialize function (to power off the peripheral if it is powered). Corrected SPI3_SCK pin configuration. Corrected DMA MemDataAlignment configuration. USART: Corrected DMA MemDataAlignment configuration. USBD_HS/USBH_HS: OTG_HS ULPI clock disabled in low power if internal PHY is used to enable proper operation of OTG_HS port in FS mode during CPU sleep. CAN/EMAC/USBD/USBH: Removed macros already provided by cmsis_compiler.h. Updated Boards Examples: Migrated CubeMX projects to V6.0.1 and updated config files. Changed variant selection to "MDK-Plus" where possible. Updated all USB Host/Device examples with user templates from MDK-Middleware v7.11.1. Terminating app_main thread with osThreadExit() to avoid endless loop Updated MS Windows UBS driver files.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值