[STM32F7] STM32CubeIDE 报错

[复制链接]
30|5
jerry尧 发表于 2026-2-4 09:30 | 显示全部楼层 |阅读模式

在 NUCLEO-H723 开发板做中,此前对 SPI 外设的编程开发一直都很正常,但当我添加 USART 串口功能、想在串口终端上显示文本时,却突然出现了下述报错。


arm-none-eabi-gcc "../Core/Src/gpio.c" -mcpu=cortex-m7 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32H723xx -c -I../Core/Inc -I../Drivers/STM32H7xx_HAL_Driver/Inc -I../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32H7xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/gpio.d" -MT"Core/Src/gpio.o" --specs=nano.specs -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -o "Core/Src/gpio.o"


arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m7 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32H723xx -c -I../Core/Inc -I../Drivers/STM32H7xx_HAL_Driver/Inc -I../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32H7xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -o "Core/Src/main.o"


arm-none-eabi-gcc -o "SPI_PWRSTP01_USART.elf" @"objects.list" -mcpu=cortex-m7 -T"C:\Users\goh\STM32CubeIDE\workspace_1.13.1\proj_USART-v1\proj_USART\STM32H723ZGTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="proj_USART.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group




C:/ST/STM32CubeIDE_1.13.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.0.202601231506/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/usart.o:C:/Users/goh/STM32CubeIDE/workspace_1.13.1/SPI_PWRSTP01_USART-v1/SPI_PWRSTP01/Debug/../Core/Src/usart.c:27: multiple definition of `huart3'; ./Core/Src/main.o:C:/Users/goh/STM32CubeIDE/workspace_1.13.1/SPI_PWRSTP01_USART-v1/SPI_PWRSTP01/Debug/../Core/Src/main.c:53: first defined here


collect2.exe: error: ld returned 1 exit status


heisexingqisi 发表于 2026-2-6 16:26 | 显示全部楼层
只声明了函数 / 变量,但没有实现对应的代码;
classroom 发表于 2026-2-6 16:37 | 显示全部楼层
检查是否在头文件错误使用#define定义变量
cr315 发表于 2026-2-6 16:39 | 显示全部楼层
错误提示明确显示huart3在main.c和usart.c中均有定义表明两个源文件都包含了对huart3的全局定义。
elephant00 发表于 2026-2-6 16:40 | 显示全部楼层
在多个编译单元中定义了相同的全局变量,违反C语言单定义规则。通过将变量定义收敛到单一源文件,配合extern声明跨模块引用即可解决。
duo点 发表于 2026-2-6 18:39 | 显示全部楼层
在usart.c中定义huart3,在usart.h中声明extern UART_HandleTypeDef huart3;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

99

主题

123

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部
0