1. 程式人生 > >IDE之KEIL declared implicitly 警告問題

IDE之KEIL declared implicitly 警告問題

程式碼如下

#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^)\\~