其他分享
首页 > 其他分享> > 【stm32_STD_lib学习】学习标准库的搭建(GPIO)

【stm32_STD_lib学习】学习标准库的搭建(GPIO)

作者:互联网

目标:从官网标准库包中搭建一个能使用GPIO的工程环境
过程:知道实际需要用到的头文件、被调用了的头文件、编译器需要做什么该怎么配置
结果:GPIO工程结构、构建思路
先以上次自己写GPIO库的经验导入如图所示的几个文件,main、startup、核外外设基地址头文件f10x.h、GPIO操作函数封装文件f10x_gpio.c和f10x_gpio.h
结果如下图,官方的f10x.h里还引用了别的h文件

把内核设备h文件和系统时钟、存储配置h文件复制到工程目录下,并且加入工程后,结果如下图:

官方的f10x_gpio.c里是引用了RCC外设h文件的,复制到工程目录下,结果如下图:

两个错误,把RCC加入到工程后再试试:

剩下一个错误,

在编译器里加宏定义(在h文件也行,但不想改动h文件)

编译:

加入文件:
把外设注释,只用gpio、rcc

/* Includes ------------------------------------------------------------------*/
/* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */
//#include "stm32f10x_adc.h"
//#include "stm32f10x_bkp.h"
//#include "stm32f10x_can.h"
//#include "stm32f10x_cec.h"
//#include "stm32f10x_crc.h"
//#include "stm32f10x_dac.h"
//#include "stm32f10x_dbgmcu.h"
//#include "stm32f10x_dma.h"
//#include "stm32f10x_exti.h"
//#include "stm32f10x_flash.h"
//#include "stm32f10x_fsmc.h"
#include "stm32f10x_gpio.h"
//#include "stm32f10x_i2c.h"
//#include "stm32f10x_iwdg.h"
//#include "stm32f10x_pwr.h"
#include "stm32f10x_rcc.h"
//#include "stm32f10x_rtc.h"
//#include "stm32f10x_sdio.h"
//#include "stm32f10x_spi.h"
//#include "stm32f10x_tim.h"
//#include "stm32f10x_usart.h"
//#include "stm32f10x_wwdg.h"
//#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */

主函数还要定义一个系统初始化函数

void SystemInit(void)
{
}

程序成功运行,至此,工程目录下的代码有:

尝试把整个外设库拷贝进工程目录,通过编译器的配置来完成h文件的导入


显示没有启动文件,导入

分隔符************
最后发现工程最简单是这样的:




可以发现这三个c文件几乎都引用了同一部分h文件:

标签:STD,文件,lib,stm32f10x,f10x,stm32,gpio,GPIO,include
来源: https://www.cnblogs.com/xianyucaicaizi/p/16210186.html