cancel
Showing results for 
Search instead for 
Did you mean: 

"Undefined reference to custom function" but header is part of the includes path.

KMew
Senior III

I am writing firmware that was automatically generated by the TouchGFX 4.20.0 and then opened the .ioc file to enable an ADC, Timer, Binary Semaphore and add a Task. When I generated that code, it compiled without any issue.

My purpose for enabling these features is to measure the value on an ADC and display it on the LCD screen.

Part of my work was to develop a custom .c and .h file that initialized the ADC, the timer and do a callback to send the ADC value to the screen via a Binary Semaphore.

I added two files:

  • "PollingRoutines.c"
  • "PollingRoutines.h"

PollingRoutines.c is below:

#include "main.h"
#include "PollingRoutines.h"
#include "cmsis_os.h"
 
extern ADC_HandleTypeDef hadc1;
extern TIM_HandleTypeDef htim1;
extern osSemaphoreId_t binarySemAnalogHandle;
 
uint16_t uhADCxConvertedValue[10] = {0};
 
void PollingInit(){
	HAL_ADC_Start_DMA(&hadc1,&uhADCxConvertedValue,10);
	HAL_TIM_Base_Start_IT(&htim1);
}
 
void PollingRoutine(){
 
}
 
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc){
	osSemaphoreRelease(binarySemAnalogHandle);
}

PollingRoutines.h is below:

#ifndef INC_POLLINGROUTINES_H_
#define INC_POLLINGROUTINES_H_
 
void PollingInit();
void PollingRoutine();
 
#endif /*INC_POLLINGROUTINES_H_ */

In my main.c, I include the polling routines as below:

/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
#include "app_touchgfx.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "PollingRoutines.h"
/* USER CODE END Includes */

When I compile, I get an error of "undefined reference to PollingInit() & PollingRoutine()"

The PollingRoutines.h header file is in the project's includes path. Specifically, in the one highlighted:

0693W00000Unq7HQAR.png 

I'm unsure what's causing this error, since PollingInit are defined in PollingRoutines.h, which is in the project's included paths. Did I miss something?

1 ACCEPTED SOLUTION

Accepted Solutions
KMew
Senior III

Resolved the issue.

Despite the Core/Src folder's PollingRoutine.c, you ALSO have to include it in the Applications/User/Core folder, or the project compiler does not recognize it. When I added it, the error went away.

View solution in original post

1 REPLY 1
KMew
Senior III

Resolved the issue.

Despite the Core/Src folder's PollingRoutine.c, you ALSO have to include it in the Applications/User/Core folder, or the project compiler does not recognize it. When I added it, the error went away.