Search code examples
microcontrollerstm32build-error

Build error, "undeclared (first use in function)" error but it has been declared


I'm very new to STM32 MCU programming and I started a SPI project on TrueStudio. I needed an LCD library as well and hence I adapted an existing library to be used with mine and added those files under Inc and Src.

When I try to compile, I get an error saying that a previously undeclared define is being used for the first time in the function, however, they've been defined in the respective header file and that header file has been included in the C file. What am I missing? All my errors seem to be in the 'HD44780.c' file. I should also mention that I used the CubeMX software to generate the pin definition source code. A zip of the project is available here.

Any help would be appreciated! EDIT: Exact error messages are listed here:

Description                         Resource    Path            Location    Type
'HD44780_D4_GPIO_PORT' undeclared (first use in this function)  HD44780.c   /STM32F103C6T8_SPI/Src  line 242    C/C++ Problem
'HD44780_D5_GPIO_PORT' undeclared (first use in this function)  HD44780.c   /STM32F103C6T8_SPI/Src  line 241    C/C++ Problem
'HD44780_D6_GPIO_PORT' undeclared (first use in this function)  HD44780.c   /STM32F103C6T8_SPI/Src  line 240    C/C++ Problem
'HD44780_D7_GPIO_PORT' undeclared (first use in this function)  HD44780.c   /STM32F103C6T8_SPI/Src  line 239    C/C++ Problem
'HD44780_E_GPIO_PORT' undeclared (first use in this function)   HD44780.c   /STM32F103C6T8_SPI/Src  line 39     C/C++ Problem
'HD44780_RS_GPIO_PORT' undeclared (first use in this function)  HD44780.c   /STM32F103C6T8_SPI/Src  line 36     C/C++ Problem
'HD44780_RS_GPIO_PORT' undeclared (first use in this function)  HD44780.c   /STM32F103C6T8_SPI/Src  line 37     C/C++ Problem

Warnings
implicit declaration of function 'DELAY_Init' [-Wimplicit-function-declaration] HD44780.c   /STM32F103C6T8_SPI/Src  line 81 C/C++ Problem

Info
each undeclared identifier is reported only once for each function it appears in    HD44780.c   /STM32F103C6T8_SPI/Src  line 36 C/C++ Problem
in expansion of macro 'HD44780_E_BLINK' HD44780.c   /STM32F103C6T8_SPI/Src  line 243    C/C++ Problem
in expansion of macro 'HD44780_E_HIGH'  HD44780.c   /STM32F103C6T8_SPI/Src  line 41 C/C++ Problem
in expansion of macro 'HD44780_RS_HIGH' HD44780.c   /STM32F103C6T8_SPI/Src  line 229    C/C++ Problem
in expansion of macro 'HD44780_RS_LOW'  HD44780.c   /STM32F103C6T8_SPI/Src  line 219    C/C++ Problem

Solution

  • In main.h, you are defining HD44780_*_GPIO_Port instead of HD44780_*_GPIO_PORT. Notice the all-uppercase PORT.