首页 > 解决方案 > Stm Cube IDE ERROR:函数比较错误

问题描述

我正在通过 STMBUBEIDE 程序试验 STM32f407vg 板。

首先,我准备自己的库文件,并在中断部分进行设置。

如果我无法摆脱这个错误的原因怎么办?

首先,我的 src 文件有一个 griodriver.c 文件。我在其中的定义:

  uint8_t portcode = GPIO_BASE_ADDR_TO_CODE (pGPIOHandle-> pGPIOx);

然后我写我的函数,这样它就回来了。

 uint16_t GPIO_BASE_ADDR_TO_CODE(*x)
    {
        if(x==GPIOA)        { return 0; }
        else if(x==GPIOB)   { return 1; }
        else if(x==GPIOC)   { return 2; }
        else if(x==GPIOD)   { return 3; }
        else if(x==GPIOE)   { return 4; }
        else if(x==GPIOF)   { return 5; }
        else if(x==GPIOG)   { return 6; }

    }

如果我删除循环内的指针,我会得到指针和整数错误之间的比较。

每当我编译时,都会出现错误。

我的错误说明了该功能:这是警告错误。

     Description    Resource    Path    Location    Type
     implicit declaration of function 'GPIO_BASE_ADDR_TO_CODE'; did you mean 'GPIOJ_BASEADDR'? 
      [- Wimplicit-function-declaration]    stm32f407xx_gpio_driver.c   /stm32f407xx/drivers/Src     
      line 253  C/C++ Problem

但是我还有另外两个错误是错误的。 在此处输入图像描述

在此处输入图像描述

第一的:

          1. ERROR:  Description    Resource    Path    Location    Type
          make: *** [drivers/Src/subdir.mk:18: drivers/Src/stm32f407xx_gpio_driver.o]            
         Error 1    stm32f407xx         C/C++ Problem

第二:

               Description  Resource    Path    Location    Type
              expected declaration specifiers or '...' before '*' token stm32f407xx_gpio_driver.c    
              /stm32f407xx/drivers/Src  line 168    C/C++ Problem

错误屏幕:

在此处输入图像描述

标签: functionarmreturncomparison

解决方案


我没有在函数中调用它,而是将其定义为 #define for

          GPIO_BASEADDR_TO_CODE

if else 条件也被删除。我使用了 C 第三个条件。

3天后现在没有错误:))

你可以在下面的图片中看到我做了什么。

  #define GPIO_BASEADDR_TO_CODE(x)  ((x == GPIOA)?0 :\
                                    (x == GPIOB)?1 :\
                                    (x == GPIOA)? :\
                                    (x == GPIOA)?3 :\
                                    (x == GPIOA)?4 :\
                                    (x == GPIOA)?5 :\
                                    (x == GPIOA)?6 :\
                                    (x == GPIOA)?7 :0 )

在此处输入图像描述


推荐阅读