代码如下
#ifndef __BSP_SPI_H
#define __BSP_SPI_H
#include "bsp.h"
#ifdef HARD_SPI
//#define USE_SPI1
//#define USE_SPI2
#define USE_SPI3
#ifdef USE_SPI1
#define SPI_HARD SPI1
/* ¶¨ÒåSPI×ÜÏßµÄ GPIO¶Ë¿Ú */
#define RCC_SCK RCC_APB2Periph_GPIOA
#define PORT_SCK GPIOA
#define PIN_SCK GPIO_Pin_5
#define RCC_MISO RCC_APB2Periph_GPIOA
#define PORT_MISO GPIOA
#define PIN_MISO GPIO_Pin_6
#define RCC_MOSI RCC_APB2Periph_GPIOA
#define PORT_MOSI GPIOA
#define PIN_MOSI GPIO_Pin_7
#endif
#ifdef USE_SPI2
#define SPI_HARD SPI2
/* ¶¨ÒåSPI×ÜÏßµÄ GPIO¶Ë¿Ú */
#define RCC_SCK RCC_APB2Periph_GPIOB
#define PORT_SCK GPIOB
#define PIN_SCK GPIO_Pin_13
#define RCC_MISO RCC_APB2Periph_GPIOB
#define PORT_MISO GPIOB
#define PIN_MISO GPIO_Pin_14
#define RCC_MOSI RCC_APB2Periph_GPIOB
#define PORT_MOSI GPIOB
#define PIN_MOSI GPIO_Pin_15
#endif
#ifdef USE_SPI3
#define SPI_HARD SPI3
/* ¶¨ÒåSPI×ÜÏßµÄ GPIO¶Ë¿Ú */
#define RCC_SCK RCC_APB2Periph_GPIOB
#define PORT_SCK GPIOB
#define PIN_SCK GPIO_Pin_3
#define RCC_MISO RCC_APB2Periph_GPIOB
#define PORT_MISO GPIOB
#define PIN_MISO GPIO_Pin_4
#define RCC_MOSI RCC_APB2Periph_GPIOB
#define PORT_MOSI GPIOB
#define PIN_MOSI GPIO_Pin_5
#endif
/* SPI or I2S mode selection masks */
#define SPI_Mode_Select ((uint16_t)0xF7FF)
#define I2S_Mode_Select ((uint16_t)0x0800)
/* SPI registers Masks */
#define CR1_CLEAR_Mask ((uint16_t)0x3040)
#define I2SCFGR_CLEAR_Mask ((uint16_t)0xF040)
/* SPI SPE mask */
#define CR1_SPE_Set ((uint16_t)0x0040)
#define CR1_SPE_Reset ((uint16_t)0xFFBF)
void bsp_InitSPIBus(void);
void bsp_spiWrite(uint8_t _ucByte);
uint8_t bsp_spiRead(void);
void bsp_SPI_Init(uint16_t _cr1);
#endif
#endif
然后编译器就是一大堆警告,
*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin'
Rebuild target 'Glacier'
compiling user_command.c...
compiling user_lib.c...
compiling main.c...
compiling pca9554a.c...
compiling app.c...
compiling pca9698.c...
compiling 24cxx.c...
compiling cat9555.c...
compiling spi_flash.c...
..\SoftRef\App\app_src\spi_flash.c(23): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_DISWR); /* 发送禁止写入的命令,即使能软件写保护 */
..\SoftRef\App\app_src\spi_flash.c(46): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_SE); /* 发送擦除命令 */
..\SoftRef\App\app_src\spi_flash.c(69): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_BE); /* 发送整片擦除命令 */
..\SoftRef\App\app_src\spi_flash.c(100): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_AAI); /* 发送AAI命令(地址自动增加编程) */
..\SoftRef\App\app_src\spi_flash.c(136): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(0x02); /* 发送AAI命令(地址自动增加编程) */
..\SoftRef\App\app_src\spi_flash.c(155): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_DISWR);
..\SoftRef\App\app_src\spi_flash.c(182): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_READ); /* 发送读命令 */
..\SoftRef\App\app_src\spi_flash.c(188): warning: #223-D: function "bsp_spiRead" declared implicitly
*_pBuf++ = bsp_spiRead(); /* 读一个字节并存储到pBuf,读完后指针自加1 */
..\SoftRef\App\app_src\spi_flash.c(219): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_READ); /* 发送读命令 */
..\SoftRef\App\app_src\spi_flash.c(226): warning: #223-D: function "bsp_spiRead" declared implicitly
ucValue = bsp_spiRead();
..\SoftRef\App\app_src\spi_flash.c(511): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_RDID); /* 发送读ID命令 */
..\SoftRef\App\app_src\spi_flash.c(512): warning: #223-D: function "bsp_spiRead" declared implicitly
id1 = bsp_spiRead(); /* 读ID的第1个字节 */
..\SoftRef\App\app_src\spi_flash.c(583): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_WREN); /* 发送命令 */
..\SoftRef\App\app_src\spi_flash.c(602): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_EWRSR); /* 发送命令, 允许写状态寄存器 */
..\SoftRef\App\app_src\spi_flash.c(614): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_WRSR); /* 发送命令, 写状态寄存器 */
..\SoftRef\App\app_src\spi_flash.c(631): warning: #223-D: function "bsp_spiWrite" declared implicitly
bsp_spiWrite(CMD_RDSR); /* 发送命令, 读状态寄存器 */
..\SoftRef\App\app_src\spi_flash.c(632): warning: #223-D: function "bsp_spiRead" declared implicitly
while((bsp_spiRead() & WIP_FLAG) == SET); /* 判断状态寄存器的忙标志位 */
..\SoftRef\App\app_src\spi_flash.c: 17 warnings, 0 errors
compiling bsp_led.c...
compiling bsp.c...
compiling bsp_key.c...
compiling bsp_timer.c...
compiling bsp_usart.c...
compiling bsp_iic_gpio.c...
compiling bsp_spi_cs.c...
..\Bsp\bsp_src\bsp_spi_cs.c(36): warning: #223-D: function "bsp_SPI_Init" declared implicitly
bsp_SPI_Init(SPI_Direction_2Lines_FullDuplex | SPI_Mode_Master | SPI_DataSize_8b
..\Bsp\bsp_src\bsp_spi_cs.c: 1 warning, 0 errors
compiling bsp_spi_gpio.c...
compiling bsp_spi.c...
compiling stm32f10x_dma.c...
compiling misc.c...
compiling stm32f10x_exti.c...
compiling stm32f10x_gpio.c...
compiling stm32f10x_spi.c...
compiling stm32f10x_rcc.c...
compiling stm32f10x_usart.c...
compiling stm32f10x_fsmc.c...
compiling stm32f10x_tim.c...
compiling core_cm3.c...
compiling system_stm32f10x.c...
assembling startup_stm32f10x_md.s...
compiling stm32f10x_it.c...
linking...
Program Size: Code=5232 RO-data=268 RW-data=4228 ZI-data=1204
FromELF: creating hex file...
".\Objects\STM32F103.axf" - 0 Error(s), 18 Warning(s).
Build Time Elapsed: 00:00:09
问题在哪里呢,declared implicitly,查阅一下就知道这个是隐式定义的意思,而网上很多的解释是函数没申明,然后我就被误导了
后来实际查阅它的意思,发现问题,就是我给这个头文件整个加了一个条件编译:#ifdef HARD_SPI
而它的定义是在其他的文件,这样编译器就不能接受了,,解决办法有两种,一种是条件编译的范围不要包含函数原型,另一种就是把定义放在一个文件里面。
至于原因嘛,不懂编译器原理,没法给出解释。。。
第一次写,仅为记录,不喜勿喷,欢迎指导,谢谢~///(^v^)\\~