../Src/stm32l4xx_hal_msp.c(446): error: #20: identifier “USART4“ is undefined错误解决

本文解析了STM32F1xx HAL库中关于USART4与UART4的区别与配置问题。详细解释了stm32f1xx_hal_conf.h文件中对头文件的使能及注释状态导致的UART4无法执行的原因。

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

一个是因为stm32f1xx_hal_conf.h的头文件中对一些头文件做了使能,另一部分头文件是处于注释状态,无法执行。但其实是因为没有usart4,只有uart4

 

 

*** 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
*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'E:\Keil5\ARM\ARMCC\Bin' Build target 'OLED' compiling stm32f4xx_ll_adc.c... compiling stm32f4xx_hal_pwr.c... assembling startup_stm32f411xe.s... compiling oled.c... ..\Core\Src\oled.c(23): error: #20: identifier "OLED_DC_GPIO_Port" is undefined LED_DC_Set();//命令/数据标志位置为1,则表示传送的是命令字节 ..\Core\Src\oled.c(23): error: #20: identifier "OLED_DC_Pin" is undefined LED_DC_Set();//命令/数据标志位置为1,则表示传送的是命令字节 ..\Core\Src\oled.c(26): error: #20: identifier "OLED_DC_GPIO_Port" is undefined LED_DC_Clr();//命令/数据标志位置为0,则表示传送的是数据字节 ..\Core\Src\oled.c(26): error: #20: identifier "OLED_DC_Pin" is undefined LED_DC_Clr();//命令/数据标志位置为0,则表示传送的是数据字节 ..\Core\Src\oled.c(27): error: #20: identifier "OLED_CS_GPIO_Port" is undefined LED_CS_Clr();//片选信号为低,表示选中OLED ..\Core\Src\oled.c(27): error: #20: identifier "OLED_CS_Pin" is undefined LED_CS_Clr();//片选信号为低,表示选中OLED ..\Core\Src\oled.c(30): error: #20: identifier "OLED_DC_GPIO_Port" is undefined LED_DC_Set(); ..\Core\Src\oled.c(30): error: #20: identifier "OLED_DC_Pin" is undefined LED_DC_Set(); ..\Core\Src\oled.c(243): error: #20: identifier "OLED_RST_GPIO_Port" is undefined LED_RST_Clr(); ..\Core\Src\oled.c(243): error: #20: identifier "OLED_RST_Pin" is undefined LED_RST_Clr(); ..\Core\Src\oled.c: 0 warnings, 10 errors compiling gpio.c... ../Core/Src/gpio.c(96): error: #20: identifier "OLED_CS_GPIO_Port" is undefined HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_RESET); ../Core/Src/gpio.c(96): error: #20: identifier "OLED_CS_Pin" is undefined HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_RESET); ../Core/Src/gpio.c(99): error: #20: identifier "OLED_RST_Pin" is undefined HAL_GPIO_WritePin( PIOB, OLED_RST_Pin|OLED_DC_Pin, GPIO_PIN_RESET); ../Core/Src/gpio.c(99): error: #20: identifier "OLED_DC_Pin" is undefined HAL_GPIO_WritePin( PIOB, OLED_RST_Pin|OLED_DC_Pin, GPIO_PIN_RESET); ../Core/Src/gpio.c: 0 warnings, 4 errors compiling i2c.c... ../Core/Inc/i2c.h(34): error: #20: identifier "I2C_HandleTypeDef" is undefined extern I2C_HandleTypeDef hi2c1; i2c.c(27): error: #20: identifier "I2C_HandleTypeDef" is undefined I2C_HandleTypeDef hi2c1; i2c.c(35): error: #20: identifier "I2C_DUTYCYCLE_2" is undefined hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; i2c.c(37): error: #20: identifier "I2C_ADDRESSINGMODE_7BIT" is undefined hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; i2c.c(38): error: #20: identifier "I2C_DUALADDRESS_DISABLE" is undefined hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; i2c.c(40): error: #20: identifier "I2C_GENERALCALL_DISABLE" is undefined hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; i2c.c(41): error: #20: identifier "I2C_NOSTRETCH_DISABLE" is undefined hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; i2c.c(42): warning: #223-D: function "HAL_I2C_Init" declared implicitly if (HAL_I2C_Init(&hi2c1) != HAL_OK) i2c.c(49): error: #20: identifier "I2C_HandleTypeDef" is undefined void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) i2c.c(79): error: #20: identifier "I2C_HandleTypeDef" is undefined void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle) i2c.c(108): warning: #1-D: last line of file ends without a newline /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ i2c.c: 2 warnings, 9 errors compiling stm32f4xx_hal_rtc_ex.c... compiling stm32f4xx_hal_cortex.c... compiling stm32f4xx_hal_spi.c... compiling stm32f4xx_hal_flash_ramfunc.c... compiling stm32f4xx_hal.c... compiling stm32f4xx_hal_adc.c... compiling tim.c... compiling stm32f4xx_hal_dma_ex.c... compiling usart.c... compiling stm32f4xx_hal_flash.c... compiling stm32f4xx_hal_rcc.c... compiling adc.c... compiling stm32f4xx_hal_exti.c... compiling main.c... ../Core/Src/main.c(289): warning: #177-D: variable "i" was declared but never referenced int i,j; ../Core/Src/main.c(371): warning: #1035-D: single-precision operand implicitly converted to double-precision Res_1 = ( ( (float)adc_values[1] ) / ( (float)adc_values[0] )-1.0)*708; ../Core/Src/main.c(375): warning: #1035-D: single-precision operand implicitly converted to double-precision Res_2 = (int)(( ( (float)adc_values[1] ) / ( (float)adc_values[0] )-1.0)*475000); ../Core/Src/main.c(503): warning: #1035-D: single-precision operand implicitly converted to double-precision Esr = ( ( (float)adc_values[1] ) / ( (float)adc_values[0] )-1.0)*708; ../Core/Src/main.c(489): warning: #550-D: variable "adcget1" was set but never used uint32_t adcget1, adcget2, adc_values[2]; ../Core/Src/main.c(489): warning: #550-D: variable "adcget2" was set but never used uint32_t adcget1, adcget2, adc_values[2]; ../Core/Src/main.c(490): warning: #177-D: variable "Res" was declared but never referenced float Res,Esr; ../Core/Src/main.c: 7 warnings, 0 errors compiling spi.c... compiling stm32f4xx_it.c... compiling stm32f4xx_hal_dma.c... compiling stm32f4xx_hal_pwr_ex.c... compiling stm32f4xx_hal_rtc.c... compiling stm32f4xx_hal_gpio.c... compiling stm32f4xx_hal_rcc_ex.c... compiling stm32f4xx_hal_flash_ex.c... compiling stm32f4xx_hal_adc_ex.c... compiling stm32f4xx_hal_msp.c... compiling rtc.c... compiling stm32f4xx_hal_tim_ex.c... compiling stm32f4xx_hal_tim.c... compiling stm32f4xx_hal_uart.c... compiling system_stm32f4xx.c... "OLED\OLED.axf" - 23 Error(s), 9 Warning(s). Target not created. Build Time Elapsed: 00:02:10
最新发布
07-21
*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin' Build target 'APP' 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 dma.c... ../Core/Src/dma.c(40): error: #169: expected a declaration { ../Core/Src/dma.c: 0 warnings, 1 error compiling gpio.c... compiling main.c... ../Core/Src/main.c(113): warning: #223-D: function "task_run" declared implicitly task_run(); ../Core/Src/main.c: 1 warning, 0 errors compiling stm32f1xx_it.c... compiling stm32f1xx_hal_msp.c... compiling tim.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 periph.c... compiling logic.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 system.c... "APP\APP.axf" - 9 Error(s), 3 Warning(s). Target not created. Build Time Elapsed: 00:00:07
07-20
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值