cancel
Showing results for 
Search instead for 
Did you mean: 

Every time i getting the same error and i cant fix it . I am trying to write my uart communication as a header file even if i used the extern but it doesnt work , Can somenone help me how to write properly ?

ÖBekt.1
Associate

09:32:54 **** Incremental Build of configuration Debug for project uart_deneme ****

make -j8 all 

arm-none-eabi-gcc "../Core/Src/myHeader.c" -mcpu=cortex-m0 -std=gnu11 -g -DDEBUG -DUSE_HAL_DRIVER -DSTM32F072xB -c -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/CMSIS/Include -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/myHeader.d" -MT"Core/Src/myHeader.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/myHeader.o"

In file included from ../Core/Src/myHeader.c:11:

../Core/Inc/myHeader.h:14:8: error: unknown type name 'I2C_HandleTypeDef'

  14 | extern I2C_HandleTypeDef hi2c1;

   |    ^~~~~~~~~~~~~~~~~

../Core/Src/myHeader.c:32:29: error: conflicting types for 'hi2c1'

  32 |  extern I2C_HandleTypeDef hi2c1;

   |               ^~~~~

In file included from ../Core/Src/myHeader.c:11:

../Core/Inc/myHeader.h:14:26: note: previous declaration of 'hi2c1' was here

  14 | extern I2C_HandleTypeDef hi2c1;

   |             ^~~~~

make: *** [Core/Src/subdir.mk:40: Core/Src/myHeader.o] Error 1

"make -j8 all" terminated with exit code 2. Build might be incomplete.

09:32:55 Build Failed. 3 errors, 0 warnings. (took 654ms)

4 REPLIES 4
Bob S
Principal

The first error tells you all you need to know. Something is "unknown" (i.e. not defined). Find where that is defined (hint: somewhere in a .h file) and make sure that include file is included BEFORE you include "myHeader.h". Or, put that include at the top of "myHeader.h", but that gets in to almost religious arguments about how to organize and use include files.

LCE
Principal

 error: unknown type name 'I2C_HandleTypeDef'

the file does not know that type and thus needs to include the i2c HAL .h file.

Look in your stm32f0xx_hal_conf.h ​file, make sure the I2C module is selected.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

#include is to import multiple text slices in order, then compiler will crunch the glued together source text file.

If the includes are not in the right order, you may use a type defined later, and the compiler will fail because it read beginning to end, no bottom to top sweeping.