Keil MDK 嵌入式开发问题:Error: L6218E: Undefined symbol HAL_TIM_PWM_ConfigChannel
- 在 Keil MDK 中,编译项目时,报如下错误
*** Using Compiler 'V5.06 update 1 (build 61)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin'
Rebuild target 'Target 1'
assembling startup_stm32f103xe.s...
compiling system_stm32f1xx.c...
compiling stm32f1xx_hal_cortex.c...
compiling delay.c...
compiling stm32f1xx_hal_gpio.c...
compiling stm32f1xx_hal_gpio_ex.c...
compiling stm32f1xx_hal.c...
compiling main.c...
compiling stm32f1xx_hal_rcc.c...
compiling stm32f1xx_it.c...
compiling stm32f1xx_hal_rcc_ex.c...
compiling sys.c...
compiling usart.c...
compiling stm32f1xx_hal_dma.c...
compiling stm32f1xx_hal_uart.c...
compiling stm32f1xx_hal_usart.c...
compiling gtim.c...
linking...
..\..\hal_led_breathe.axf: Error: L6218E: Undefined symbol HAL_TIM_PWM_ConfigChannel (referred from gtim.o).
..\..\hal_led_breathe.axf: Error: L6218E: Undefined symbol HAL_TIM_PWM_Init (referred from gtim.o).
..\..\hal_led_breathe.axf: Error: L6218E: Undefined symbol HAL_TIM_PWM_Start (referred from gtim.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 3 error messages.
"..\..\hal_led_breathe.axf" - 3 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:07
# 关键错误..\..\hal_led_breathe.axf: Error: L6218E: Undefined symbol HAL_TIM_PWM_ConfigChannel (referred from gtim.o).
..\..\hal_led_breathe.axf: Error: L6218E: Undefined symbol HAL_TIM_PWM_Init (referred from gtim.o).
..\..\hal_led_breathe.axf: Error: L6218E: Undefined symbol HAL_TIM_PWM_Start (referred from gtim.o).
问题原因
-
这个错误表示主要涉及 PWM 相关 HAL 库函数的未定义,即链接器找不到它们的实现
-
工程配置遗漏或未正确包含 PWM 相关的 HAL 库文件
处理策略
- 在 Keil MDK 工程中,确保以下 HAL 库文件被包含
-
stm32f1xx_hal_tim.c
:基础定时器驱动 -
stm32f1xx_hal_tim_ex.c
:高级定时器驱动,PWM 需要