STM32关于UART4_IRQn未定义的解决方法(identifier "UART4_IRQn" is undefined)

本文解决了一个从STM32F103C8T6移植到ZET6过程中遇到的UART4中断问题。主要原因是目标设备缺乏UART4。解决步骤包括确认设备类型、检查define设置并替换启动文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这种问题一般出现在中容量(或小容量)向大容量移植程序的时候,出现原因也很简单,因为中容量设备里没有UART4自然也就没有这个中断了。我是由STM32F103C8T6向ZET6移植程序时出现的。
解决方法是:
1.确认你的设备是大容量设备(确认有UART4)
2.确认C/C++中define的是“STM32F10X_HD”而不是“STM32F10X_MD”
3.确认替换了启动文件(“startup_stm32f10x_md.s”->“startup_stm32f10x_hd.s”)

*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin' Build target 'APP' assembling startup_stm32f103xb.s... compiling stm32f1xx_it.c... ../Core/Src/stm32f1xx_it.c(247): error: #20: identifier "UART_CLEAR_NEF" is undefined _HAL_UART_CLEAR_FLAG(&huart1, UART_CLEAR_NEF); // 清除中断标志[^1] ../Core/Src/stm32f1xx_it.c: 0 warnings, 1 error compiling main.c... ../Core/Src/main.c(98): error: #20: identifier "hdma_usart1_tx" is undefined NABLE_DMA(); // 启用自定义DMA配置 ../Core/Src/main.c(111): warning: #223-D: function "task_run" declared implicitly task_run(); ../Core/Src/main.c: 1 warning, 1 error compiling dma.c... ../Core/Src/dma.c(42): error: #65: expected a ";" void Custom_DMA_Config(DMA_HandleTypeDef *hdma) { ../Core/Src/dma.c(56): warning: #12-D: parsing restarts here after previous syntax error HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0); ../Core/Src/dma.c: 1 warning, 1 error compiling usart.c... ../Core/Src/usart.c(27): error: #148: variable "rx_flag" has already been initialized volatile uint8_t rx_flag = 0; ../Core/Src/usart.c(31): error: #148: variable "rx_length" has already been initialized uint16_t rx_length = 0; ../Core/Src/usart.c(32): error: #147: declaration is incompatible with "uint8_t rx_buffer[256]" (declared at line 32 of "../APP/bsp.h") extern uint8_t rx_buffer[128]; ../Core/Src/usart.c(63): error: #18: expected a ")" HAL_UART_Receive_IT(&huart1,uart_rx_buffer,1 sizeof(rx_buffer)); ../Core/Src/usart.c: 0 warnings, 4 errors compiling stm32f1xx_hal_msp.c... compiling gpio.c... compiling tim.c... compiling stm32f1xx_hal_gpio_ex.c... compiling stm32f1xx_hal_rcc_ex.c... compiling stm32f1xx_hal_rcc.c... compiling stm32f1xx_hal.c... compiling stm32f1xx_hal_gpio.c... compiling stm32f1xx_hal_tim_ex.c... compiling stm32f1xx_hal_tim.c... compiling stm32f1xx_hal_dma.c... compiling stm32f1xx_hal_cortex.c... compiling stm32f1xx_hal_pwr.c... compiling stm32f1xx_hal_exti.c... compiling stm32f1xx_hal_flash.c... compiling stm32f1xx_hal_flash_ex.c... compiling stm32f1xx_hal_uart.c... compiling periph.c... compiling uart_app.c... ..\APP\uart_app.c(3): error: #20: identifier "UART_HandLeTypeDef" is undefined void HAL_UART_TxCpLtCallback(UART_HandLeTypeDef *huart) ..\APP\uart_app.c(15): error: #7: unrecognized token if(uart_rx_index == 0)return; ..\APP\uart_app.c(15): error: #125: expected a "(" if(uart_rx_index == 0)return; ..\APP\uart_app.c(15): error: #7: unrecognized token if(uart_rx_index == 0)return; ..\APP\uart_app.c(25): warning: #1-D: last line of file ends without a newline } ..\APP\uart_app.c: 1 warning, 4 errors compiling system_stm32f1xx.c... compiling system.c... compiling schedule.c... ..\APP\schedule.c(64): warning: #1-D: last line of file ends without a newline ..\APP\schedule.c: 1 warning, 0 errors compiling logic.c... "APP\APP.axf" - 11 Error(s), 4 Warning(s). Target not created. Build Time Elapsed: 00:00:17
最新发布
07-20
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值