【无标题】

keil添加了SPI1_hard.h ,SPI1_hard.c 文件后,Rebuild报错: started: Project: GD32F407 *** Using Compiler 'V6.21', folder: 'C:\software\c51keil\ARM\ARMCLANG\Bin' Rebuild target 'Target 1' compiling systick.c... compiling App_debug.c... compiling bsp_voltage.c... compiling gd32f4xx_it.c... compiling Task.c... compiling main.c... compiling bsp_led188.c... compiling bsp_adkey.c... compiling bsp_current.c... compiling bsp_ec12.c... compiling TIMER.c... compiling USART0.c... compiling ADC0.c... compiling EXTI.c... compiling SPI1_hard.c... compiling bsp_ws2812.c... compiling gd32f4xx_exti.c... compiling gd32f4xx_gpio.c... compiling gd32f4xx_misc.c... compiling gd32f4xx_dma.c... compiling gd32f4xx_pmu.c... compiling gd32f4xx_syscfg.c... compiling gd32f4xx_adc.c... compiling gd32f4xx_rcu.c... assembling startup_gd32f407_427.s... compiling system_gd32f4xx.c... compiling gd32f4xx_usart.c... compiling gd32f4xx_timer.c... linking... .\Objects\GD32F407.axf: Error: L6218E: Undefined symbol spi_i2s_deinit (referred from spi1_hard.o). .\Objects\GD32F407.axf: Error: L6218E: Undefined symbol spi_struct_para_init (referred from spi1_hard.o). .\Objects\GD32F407.axf: Error: L6218E: Undefined symbol spi_init (referred from spi1_hard.o). .\Objects\GD32F407.axf: Error: L6218E: Undefined symbol spi_dma_enable (referred from spi1_hard.o). .\Objects\GD32F407.axf: Error: L6218E: Undefined symbol spi_enable (referred from spi1_hard.o). .\Objects\GD32F407.axf: Error: L6218E: Undefined symbol spi_i2s_flag_get (referred from spi1_hard.o). .\Objects\GD32F407.axf: Error: L6218E: Undefined symbol spi_i2s_data_transmit (referred from spi1_hard.o). .\Objects\GD32F407.axf: Error: L6218E: Undefined symbol spi_i2s_data_receive (referred from spi1_hard.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 8 error messages. ".\Objects\GD32F407.axf" - 8 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:02

解决方案:

L6218E: Undefined symbol xxx (referred from spi1_hard.o) 这个错误的意思是:编译器在编译 SPI1_hard.c 时通过了,但在最后链接生成 .axf 可执行文件时,找不到 spi_i2s_deinitspi_init 等函数的实际代码实现(即 .c 文件)

这通常是因为工程中没有包含 GD32 官方的 SPI 外设驱动源文件。

如果用的是传统的编译环境,到项目的Firmware目录双击,选择STM32F4xx_StdPeriph_Driver/src/... 选择需要的外设驱动源文件添加到项目中。

我用的是RTE(Run-Time Environment)环境,点击keil魔法棒右边第四个按钮

选择Device

点击展开后,会出现很多外设库的选项,添加需要的外设库到项目中,并点击ok就能解决了。

我还在缺失的是spi外设库,所以点击SPI_I2S后面的√就可以了。

这样重新编译就不会报错了。