espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.45k stars 7.25k forks source link

ULP source fails to compile when including both GPIO and I2C headers (IDFGH-13547) #14437

Open sidwarkd opened 1 month ago

sidwarkd commented 1 month ago

Answers checklist.

IDF version.

v5.1.1

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

What is the expected behavior?

I expect the main.c file for a ULP project to compile when including ulp_riscv_i2c.h and ulp_riscv_gpio.h.

What is the actual behavior?

Many redefinition errors around various typedefs.

Steps to reproduce.

I've included a repo using VSCode and devcontainers for easy reproduction of this issue. Pull the repo and checkout the redefinition_bug branch.

  1. Launch the project in VSCode
  2. Reopen project in container development
  3. Run idf.py build from the command line in VSCode

Build or installation Logs.

ections -MD -MT CMakeFiles/ulp_main.dir/workspaces/rtc_i2c_bugs/main/ulp/main.c.obj -MF CMakeFiles/ulp_main.dir/workspaces/rtc_i2c_bugs/main/ulp/main.c.obj.d -o CMakeFiles/ulp_main.dir/workspaces/rtc_i2c_bugs/main/ulp/main.c.obj -c /workspaces/rtc_i2c_bugs/main/ulp/main.c
In file included from /workspaces/rtc_i2c_bugs/main/ulp/main.c:7:
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:18:5: error: redeclaration of enumerator 'GPIO_NUM_0'
   18 |     GPIO_NUM_0 = 0,     /*!< GPIO0, input and output */
      |     ^~~~~~~~~~
In file included from /home/dev/esp/idf/components/ulp/ulp_riscv/include/ulp_riscv_i2c.h:15,
                 from /workspaces/rtc_i2c_bugs/main/ulp/main.c:6:
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:169:5: note: previous definition of 'GPIO_NUM_0' with type 'enum <anonymous>'
  169 |     GPIO_NUM_0 = 0,     /*!< GPIO0, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:19:5: error: redeclaration of enumerator 'GPIO_NUM_1'
   19 |     GPIO_NUM_1 = 1,     /*!< GPIO1, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:170:5: note: previous definition of 'GPIO_NUM_1' with type 'enum <anonymous>'
  170 |     GPIO_NUM_1 = 1,     /*!< GPIO1, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:20:5: error: redeclaration of enumerator 'GPIO_NUM_2'
   20 |     GPIO_NUM_2 = 2,     /*!< GPIO2, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:171:5: note: previous definition of 'GPIO_NUM_2' with type 'enum <anonymous>'
  171 |     GPIO_NUM_2 = 2,     /*!< GPIO2, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:21:5: error: redeclaration of enumerator 'GPIO_NUM_3'
   21 |     GPIO_NUM_3 = 3,     /*!< GPIO3, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:172:5: note: previous definition of 'GPIO_NUM_3' with type 'enum <anonymous>'
  172 |     GPIO_NUM_3 = 3,     /*!< GPIO3, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:22:5: error: redeclaration of enumerator 'GPIO_NUM_4'
   22 |     GPIO_NUM_4 = 4,     /*!< GPIO4, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:173:5: note: previous definition of 'GPIO_NUM_4' with type 'enum <anonymous>'
  173 |     GPIO_NUM_4 = 4,     /*!< GPIO4, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:23:5: error: redeclaration of enumerator 'GPIO_NUM_5'
   23 |     GPIO_NUM_5 = 5,     /*!< GPIO5, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:174:5: note: previous definition of 'GPIO_NUM_5' with type 'enum <anonymous>'
  174 |     GPIO_NUM_5 = 5,     /*!< GPIO5, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:24:5: error: redeclaration of enumerator 'GPIO_NUM_6'
   24 |     GPIO_NUM_6 = 6,     /*!< GPIO6, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:175:5: note: previous definition of 'GPIO_NUM_6' with type 'enum <anonymous>'
  175 |     GPIO_NUM_6 = 6,     /*!< GPIO6, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:25:5: error: redeclaration of enumerator 'GPIO_NUM_7'
   25 |     GPIO_NUM_7 = 7,     /*!< GPIO7, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:176:5: note: previous definition of 'GPIO_NUM_7' with type 'enum <anonymous>'
  176 |     GPIO_NUM_7 = 7,     /*!< GPIO7, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:26:5: error: redeclaration of enumerator 'GPIO_NUM_8'
   26 |     GPIO_NUM_8 = 8,     /*!< GPIO8, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:177:5: note: previous definition of 'GPIO_NUM_8' with type 'enum <anonymous>'
  177 |     GPIO_NUM_8 = 8,     /*!< GPIO8, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:27:5: error: redeclaration of enumerator 'GPIO_NUM_9'
   27 |     GPIO_NUM_9 = 9,     /*!< GPIO9, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:178:5: note: previous definition of 'GPIO_NUM_9' with type 'enum <anonymous>'
  178 |     GPIO_NUM_9 = 9,     /*!< GPIO9, input and output */
      |     ^~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:28:5: error: redeclaration of enumerator 'GPIO_NUM_10'
   28 |     GPIO_NUM_10 = 10,   /*!< GPIO10, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:179:5: note: previous definition of 'GPIO_NUM_10' with type 'enum <anonymous>'
  179 |     GPIO_NUM_10 = 10,   /*!< GPIO10, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:29:5: error: redeclaration of enumerator 'GPIO_NUM_11'
   29 |     GPIO_NUM_11 = 11,   /*!< GPIO11, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:180:5: note: previous definition of 'GPIO_NUM_11' with type 'enum <anonymous>'
  180 |     GPIO_NUM_11 = 11,   /*!< GPIO11, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:30:5: error: redeclaration of enumerator 'GPIO_NUM_12'
   30 |     GPIO_NUM_12 = 12,   /*!< GPIO12, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:181:5: note: previous definition of 'GPIO_NUM_12' with type 'enum <anonymous>'
  181 |     GPIO_NUM_12 = 12,   /*!< GPIO12, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:31:5: error: redeclaration of enumerator 'GPIO_NUM_13'
   31 |     GPIO_NUM_13 = 13,   /*!< GPIO13, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:182:5: note: previous definition of 'GPIO_NUM_13' with type 'enum <anonymous>'
  182 |     GPIO_NUM_13 = 13,   /*!< GPIO13, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:32:5: error: redeclaration of enumerator 'GPIO_NUM_14'
   32 |     GPIO_NUM_14 = 14,   /*!< GPIO14, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:183:5: note: previous definition of 'GPIO_NUM_14' with type 'enum <anonymous>'
  183 |     GPIO_NUM_14 = 14,   /*!< GPIO14, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:33:5: error: redeclaration of enumerator 'GPIO_NUM_15'
   33 |     GPIO_NUM_15 = 15,   /*!< GPIO15, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:184:5: note: previous definition of 'GPIO_NUM_15' with type 'enum <anonymous>'
  184 |     GPIO_NUM_15 = 15,   /*!< GPIO15, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:34:5: error: redeclaration of enumerator 'GPIO_NUM_16'
   34 |     GPIO_NUM_16 = 16,   /*!< GPIO16, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:185:5: note: previous definition of 'GPIO_NUM_16' with type 'enum <anonymous>'
  185 |     GPIO_NUM_16 = 16,   /*!< GPIO16, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:35:5: error: redeclaration of enumerator 'GPIO_NUM_17'
   35 |     GPIO_NUM_17 = 17,   /*!< GPIO17, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:186:5: note: previous definition of 'GPIO_NUM_17' with type 'enum <anonymous>'
  186 |     GPIO_NUM_17 = 17,   /*!< GPIO17, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:36:5: error: redeclaration of enumerator 'GPIO_NUM_18'
   36 |     GPIO_NUM_18 = 18,   /*!< GPIO18, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:187:5: note: previous definition of 'GPIO_NUM_18' with type 'enum <anonymous>'
  187 |     GPIO_NUM_18 = 18,   /*!< GPIO18, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:37:5: error: redeclaration of enumerator 'GPIO_NUM_19'
   37 |     GPIO_NUM_19 = 19,   /*!< GPIO19, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:188:5: note: previous definition of 'GPIO_NUM_19' with type 'enum <anonymous>'
  188 |     GPIO_NUM_19 = 19,   /*!< GPIO19, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:38:5: error: redeclaration of enumerator 'GPIO_NUM_20'
   38 |     GPIO_NUM_20 = 20,
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:189:5: note: previous definition of 'GPIO_NUM_20' with type 'enum <anonymous>'
  189 |     GPIO_NUM_20 = 20,   /*!< GPIO20, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:39:5: error: redeclaration of enumerator 'GPIO_NUM_21'
   39 |     GPIO_NUM_21 = 21,   /*!< GPIO21, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:190:5: note: previous definition of 'GPIO_NUM_21' with type 'enum <anonymous>'
  190 |     GPIO_NUM_21 = 21,   /*!< GPIO21, input and output */
      |     ^~~~~~~~~~~
/home/dev/esp/idf/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h:40:3: error: conflicting types for 'gpio_num_t'; have 'enum <anonymous>'
   40 | } gpio_num_t;
      |   ^~~~~~~~~~
/home/dev/esp/idf/components/hal/include/hal/gpio_types.h:216:3: note: previous declaration of 'gpio_num_t' with type 'gpio_num_t'
  216 | } gpio_num_t;

More Information.

To get the project to successfully build, simply remove the i2c references in the main.c ulp file which includes commenting out the include of the header file as well as the I2C Operations section of main.c

I also tried this in the v5.3 branch of IDF with the same results.

louielauanu commented 1 month ago

fix.patch.txt Hi @sidwarkd,

Thanks for reporting this bug and provide the helpful reproduction repo. Our fix will be deleting the redundant gpio_num_t enum in ulp_core/include/ulp_riscv_gpio.h and unify it with the definition in "hal/gpio_types.h". This fix will come soon on IDF v5.3, but may not be backported to IDF v5.1.1. If you need to run IDF v5.1.1, please try the attached patch that deletes the whole definition of gpio_num_t in "components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h" and include "hal/gpio_types.h" in this header file.

Thanks, Xiaoyu

AxelLin commented 1 month ago

This fix will come soon on IDF v5.3, but may not be backported to IDF v5.1.1.

@louielauanu I'm surprised you don't backport compile fix for v5.1 branch? (Isn't v5.1 brnach still in maintenance period?)

louielauanu commented 1 month ago

This fix will come soon on IDF v5.3, but may not be backported to IDF v5.1.1.

@louielauanu I'm surprised you don't backport compile fix for v5.1 branch? (Isn't v5.1 brnach still in maintenance period?)

This fix will be ported to v5.1, but may not on v5.1.1, because it's code freeze. To obtain it, user have to fetch the next v5.1 release version, i.e. v5.1.5.

sidwarkd commented 1 month ago

@louielauanu Thanks for the info. I understand about it being in a bugfix release of 5.1.x. That makes sense. :+1: