STM32:XXX.axf: Error: L6218E: Undefined symbol xxx (referred from xxxx.o).

created at 03-19-2022 views: 13

1 problem statement

Problem Review

When I learned to manually build a STM32HAL library project template file, I found that there were 6 errors, and the types of the 6 errors were the same, and 3 of them were solved by adding hal_rcc.h and hal_gpio.c files . So the other 3 errors caused by the lack of the corresponding .c file I also thought of.

But in the STM32F1xx_HAL_Driver folder, I did not find such iconic symbols as rcc and GPIO. The 3 errors are as follows:

They are HAL_NVIC_SetPriority, HAL_NVIC_SetProtityGrouping and HAL_SYSTICK_Config respectively.

No .c files like NVIC or SYSTICK were found in the STM32F1xx_HAL_Driver folder.

I copied the question and didn't find a suitable answer online because I simply don't know how to describe my problem. After asking a senior, he solved the problem for me in only 5 minutes.

2 Solutions

2.1 Reconsideration issues

…\Output\Template.axf: Error: L6218E: Undefined symbol HAL_NVIC_SetPriority (referred from stm32f1xx_hal.o).

There are two key words in the question, let's look at them one by one

2.1.1 Undefined symbol xxx.c

The meaning is: The symbol xxx.c is not defined

2.1.2 referred from xxxx.o

The meaning is: the above xxx.c file has been called in xxxx.o

What are .o files?

The .o file does not exist in the project, it is generated by the .c file during the compilation process. So we only need to find the .c file in the project, here the corresponding name is xxxx.c

2.2 Solution steps

2.2.1 How to find the location of xxxx.c?

  • step1: Ctrl+F pops up the search box
  • step2: Search for the xxxx.c file in the Find in Files tab

location of .c file

  • step3: The location where the file is found in the entire project file will be returned under keil

find the file

  • step4: You will find it from the left task bar, this xxxx.c file already exists

already find the file

2.2.2 same method for undefined xxx.c symbols

Got the following result:

The .c files and .h files where HAL_NVIC_SetPriority appeared are: * hal_gpio.c * hal.c * cortex.h

2.2.3 Continue the analysis

From the left task bar, we can see that hal_gpio.c and hal.c have been added to the project file

hal_gpio.c and hal.c

Look for the hal_cortex.h file

location of hal_cortex.h

It can be seen that in the hal_cortex.h file, we found the declaration of the corresponding function, but the definition is missing, so we need to add the hal_cortex.c file into the project file.

Add the hal_cortex.c file into the project file

2.2.4 Compile again

compile again

It is found that all errors are resolved, indicating that the declaration and definition of the problem HAL_SYSTICK_Config are also done in cortex.h and cortex.c.

At this point, the problem is solved.

3 A little explanation

3.1 Why global search can find this function also exists in "cortex.h"?

There are two reasons:

  1. Open the magic wand, open the C/C++ tab, follow the steps to open, you will find that we have saved the stored path before

find the stored path

  1. Although we did not put the cortex.c file into the project file, the purpose is to save the compilation time without putting all the hal library files into the project, but in stm32fxx_hal.c calls all the hal library's .h file. So when retrieving, keil can discover and find the function and location of the search

keil can discover and find the function and location of the search

created at:03-19-2022
edited at: 03-19-2022: