3
\$\begingroup\$

I am trying to run a simple tutorial (external interrupt example) on my NUCLEO-F746ZG board. I use STM32CubeMx software version 5.2.0 and Keil software version 5.28.0.0 as compiler. I get the following error:

EXTI_callback\EXTI_callback.axf: Error: L6218E: Undefined symbol ex0 (referred from stm32f7xx_it.o). Not enough information to list image symbols. Not enough information to list load addresses in the image map. Finished: 2 information, 0 warning and 1 error messages. Target not created.

where ex0 is a variable that is defined in main.c as

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

char ext0;

/* USER CODE END PV */

and it is used as the external variable inside the stm32f7xx_it.c as follows :

/* External variables --------------------------------------------------------*/


/* USER CODE BEGIN EV */

extern char ex0;

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
    if ( GPIO_Pin == GPIO_PIN_13 ) {
        ex0 = 1;
    }
}

/* USER CODE END EV */

by using the HAL_GPIO_EXTI_Callback function I want to assign the value of 1 to the ex0 variable, whenever the blue push button (GPIO_PIN_13) is pressed on the NUCLEO-F746ZG board.

It seems the code can not find the reference to ex0 variable, while it is defined in the main.c file. I don't understand what is cause of this problem. Should I add some .h / .c files to the my project? In addition, many users have also complained about the "Error: L6218E: Undefined symbol VAR_NAME" when they have tried to compile their code with Keil Software. I have read some of them, but I didn't find the main reason behind this error. I appreciate those of you who can share their experience on how to solve this error.

\$\endgroup\$
6
\$\begingroup\$

Well you define ext0 but try to use ex0. No wonder linking fails.

\$\endgroup\$
3
\$\begingroup\$

Some remarks:

  1. About your problem: You made a typo, you use ex0 while you mean ext0.
  2. It is always good practice to initialize variables.
  3. Besides that, you only set the variable, but you do not use it (maybe you did not show that code).
  4. Externally declared variables are best to put in the dedicated protected region at the beginning of the file.

So your code can simply be:

/* USER CODE BEGIN PV */

char ext0 = '\0';

/* USER CODE END PV */

Other file, somewhere at the start in the correct protected region:

extern char ext0;

And in your code where you use it:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
    if ( GPIO_Pin == GPIO_PIN_13 ) {
        ext0 = 1;
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.