Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
内核学习营
新人求助:按照官方教程做的编译出错
发布于 2019-04-17 02:22:38 浏览:5372
订阅该版
新人求助: 我按照如下两个教程 1、[https://www.rt-thread.org/document/site/tutorial/nano/cube/nano-mx5/](https://www.rt-thread.org/document/site/tutorial/nano/cube/nano-mx5/) 2、[https://www.rt-thread.org/document/site/tutorial/nano/nano_finsh/nano-finsh/](https://www.rt-thread.org/document/site/tutorial/nano/nano_finsh/nano-finsh/) 一步一步照着做,只是芯片换成103RB(创建nano工程都没问题),到第二个帖子修改头文件那个步骤后出现编译错误。(我本想上传图片,结果还是上传不了;想上传我的问题工程,结果附件也无法上传。。。。上传结果提示:SERVER(IO)ERROR) 编译提示如下错误:(要崩溃了,想用3.1.2版本的nano-msh怎么就那么难呢?纠结这个问题快一个月了,我一直是用标准库的,为了用nano-msh,今天照着教程现学hal库。。。) ../Inc/drv_usart.h(51): error: #20: identifier "UART_HandleTypeDef" is undefined UART_HandleTypeDef handle; ..\Src\drv_usart.c(93): error: #20: identifier "UART_HWCONTROL_NONE" is undefined uart->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; ..\Src\drv_usart.c(94): error: #20: identifier "UART_MODE_TX_RX" is undefined uart->handle.Init.Mode = UART_MODE_TX_RX; ..\Src\drv_usart.c(95): error: #20: identifier "UART_OVERSAMPLING_16" is undefined uart->handle.Init.OverSampling = UART_OVERSAMPLING_16; ..\Src\drv_usart.c(99): error: #20: identifier "UART_WORDLENGTH_8B" is undefined uart->handle.Init.WordLength = UART_WORDLENGTH_8B; ..\Src\drv_usart.c(102): error: #20: identifier "UART_WORDLENGTH_9B" is undefined uart->handle.Init.WordLength = UART_WORDLENGTH_9B; ..\Src\drv_usart.c(111): error: #20: identifier "UART_STOPBITS_1" is undefined uart->handle.Init.StopBits = UART_STOPBITS_1; ..\Src\drv_usart.c(114): error: #20: identifier "UART_STOPBITS_2" is undefined uart->handle.Init.StopBits = UART_STOPBITS_2; ..\Src\drv_usart.c(123): error: #20: identifier "UART_PARITY_NONE" is undefined uart->handle.Init.Parity = UART_PARITY_NONE; ..\Src\drv_usart.c(126): error: #20: identifier "UART_PARITY_ODD" is undefined uart->handle.Init.Parity = UART_PARITY_ODD; ..\Src\drv_usart.c(129): error: #20: identifier "UART_PARITY_EVEN" is undefined uart->handle.Init.Parity = UART_PARITY_EVEN; ..\Src\drv_usart.c(136): warning: #223-D: function "HAL_UART_Init" declared implicitly if (HAL_UART_Init(&uart->handle) != HAL_OK) ..\Src\drv_usart.c(162): warning: #223-D: function "__HAL_UART_DISABLE_IT" declared implicitly __HAL_UART_DISABLE_IT(&(uart->handle), UART_IT_RXNE); ..\Src\drv_usart.c(162): error: #20: identifier "UART_IT_RXNE" is undefined __HAL_UART_DISABLE_IT(&(uart->handle), UART_IT_RXNE); ..\Src\drv_usart.c(169): warning: #223-D: function "__HAL_UART_ENABLE_IT" declared implicitly __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_RXNE); ..\Src\drv_usart.c(190): warning: #223-D: function "__HAL_UART_CLEAR_FLAG" declared implicitly UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC); ..\Src\drv_usart.c(190): error: #20: identifier "UART_FLAG_TC" is undefined UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC); ..\Src\drv_usart.c(197): warning: #223-D: function "__HAL_UART_GET_FLAG" declared implicitly while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET); ..\Src\drv_usart.c(210): warning: #223-D: function "__HAL_UART_GET_FLAG" declared implicitly if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) ..\Src\drv_usart.c(210): error: #20: identifier "UART_FLAG_RXNE" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) ..\Src\drv_usart.c(249): warning: #223-D: function "__HAL_UART_GET_FLAG" declared implicitly if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) && ..\Src\drv_usart.c(249): error: #20: identifier "UART_FLAG_RXNE" is undefined if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) && ..\Src\drv_usart.c(250): warning: #223-D: function "__HAL_UART_GET_IT_SOURCE" declared implicitly (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_RXNE) != RESET)) ..\Src\drv_usart.c(250): error: #20: identifier "UART_IT_RXNE" is undefined (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_RXNE) != RESET)) ..\Src\drv_usart.c(273): error: #20: identifier "UART_FLAG_ORE" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_ORE) != RESET) ..\Src\drv_usart.c(275): warning: #223-D: function "__HAL_UART_CLEAR_OREFLAG" declared implicitly __HAL_UART_CLEAR_OREFLAG(&uart->handle); ..\Src\drv_usart.c(277): error: #20: identifier "UART_FLAG_NE" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_NE) != RESET) ..\Src\drv_usart.c(279): warning: #223-D: function "__HAL_UART_CLEAR_NEFLAG" declared implicitly __HAL_UART_CLEAR_NEFLAG(&uart->handle); ..\Src\drv_usart.c(281): error: #20: identifier "UART_FLAG_FE" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_FE) != RESET) ..\Src\drv_usart.c(283): warning: #223-D: function "__HAL_UART_CLEAR_FEFLAG" declared implicitly __HAL_UART_CLEAR_FEFLAG(&uart->handle); ..\Src\drv_usart.c(285): error: #20: identifier "UART_FLAG_PE" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_PE) != RESET) ..\Src\drv_usart.c(287): warning: #223-D: function "__HAL_UART_CLEAR_PEFLAG" declared implicitly __HAL_UART_CLEAR_PEFLAG(&uart->handle); ..\Src\drv_usart.c(291): error: #20: identifier "UART_FLAG_LBD" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_LBD) != RESET) ..\Src\drv_usart.c(293): warning: #223-D: function "__HAL_UART_CLEAR_FLAG" declared implicitly UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_LBD); ..\Src\drv_usart.c(296): error: #20: identifier "UART_FLAG_CTS" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_CTS) != RESET) ..\Src\drv_usart.c(298): warning: #223-D: function "__HAL_UART_CLEAR_FLAG" declared implicitly UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_CTS); ..\Src\drv_usart.c(300): error: #20: identifier "UART_FLAG_TXE" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TXE) != RESET) ..\Src\drv_usart.c(302): warning: #223-D: function "__HAL_UART_CLEAR_FLAG" declared implicitly UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TXE); ..\Src\drv_usart.c(304): error: #20: identifier "UART_FLAG_TC" is undefined if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) != RESET) ..\Src\drv_usart.c(306): warning: #223-D: function "__HAL_UART_CLEAR_FLAG" declared implicitly UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC); ..\Src\drv_usart.c(310): warning: #223-D: function "__HAL_UART_CLEAR_FLAG" declared implicitly UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_RXNE); ..\Src\drv_usart.c: 17 warnings, 24 errors
查看更多
15
个回答
默认排序
按发布时间排序
Ernest
2019-04-17
这家伙很懒,什么也没写!
[attach]8250[/attach] 例程展示stm32l475,不是例程的平台,根据此仿照流程。上图表示,猜测可能出现的问题,你看看驱动里面的宏定义是什么,据此类似修改
Ernest
2019-04-17
这家伙很懒,什么也没写!
[attach]8251[/attach]使用驱动如上图所示,相关文件地址、名称
Ernest
2019-04-17
这家伙很懒,什么也没写!
[https://www.rt-thread.org/qa/thread-10348-1-1.html](https://www.rt-thread.org/qa/thread-10348-1-1.html) 老的bsp驱动可以参考这个更改
Tiv
2019-04-17
这家伙很懒,什么也没写!
>例程展示stm32l475,不是例程的平台,根据此仿照流程。上图表示,猜测可能出现的问题,你看看驱动里面的宏 ... --- 这里已安装F1的修改过了
Tiv
2019-04-17
这家伙很懒,什么也没写!
>使用驱动如上图所示,相关文件地址、名称 --- 这里也是用的F1的
Tiv
2019-04-17
这家伙很懒,什么也没写!
马上我帖出文件内容
Ernest
2019-04-17
这家伙很懒,什么也没写!
>这里也是用的F1的 --- 完全没有问题:F1的有,参照改改,一步步来
Tiv
2019-04-17
这家伙很懒,什么也没写!
rtconfig.h ``` /* RT-Thread config file */ #ifndef __RTTHREAD_CFG_H__ #define __RTTHREAD_CFG_H__ #include "RTE_Components.h" // <<< Use Configuration Wizard in Context Menu >>> //
Basic Configuration //
Maximal level of thread priority <8-256> //
Default: 32 #define RT_THREAD_PRIORITY_MAX 32 //
OS tick per second //
Default: 1000 (1ms) #define RT_TICK_PER_SECOND 1000 //
Alignment size for CPU architecture data access //
Default: 4 #define RT_ALIGN_SIZE 4 //
the max length of object name<2-16> //
Default: 8 #define RT_NAME_MAX 8 //
Using RT-Thread components initialization //
Using RT-Thread components initialization #define RT_USING_COMPONENTS_INIT // //
Using user main //
Using user main #define RT_USING_USER_MAIN // //
the size of main thread<1-4086> //
Default: 512 #define RT_MAIN_THREAD_STACK_SIZE 1024 //
using tiny size of memory //
using tiny size of memory //#define RT_USING_TINY_SIZE // //
//
Debug Configuration //
enable kernel debug configuration //
Default: enable kernel debug configuration //#define RT_DEBUG // //
enable components initialization debug configuration<0-1> //
Default: 0 //#define RT_DEBUG_INIT //
thread stack over flow detect //
Diable Thread stack over flow detect //#define RT_USING_OVERFLOW_CHECK // //
//
Hook Configuration //
using hook //
using hook //#define RT_USING_HOOK // //
using idle hook //
using idle hook //#define RT_USING_IDLE_HOOK // //
//
Software timers Configuration //
Enables user timers //#define RT_USING_TIMER_SOFT //
The priority level of timer thread <0-31> //
Default: 4 #define RT_TIMER_THREAD_PRIO 4 //
The stack size of timer thread <0-8192> //
Default: 512 #define RT_TIMER_THREAD_STACK_SIZE 512 //
The soft-timer tick per second <0-1000> //
Default: 100 #define RT_TIMER_TICK_PER_SECOND 100 //
//
IPC(Inter-process communication) Configuration //
Using Semaphore //
Using Semaphore #define RT_USING_SEMAPHORE // //
Using Mutex //
Using Mutex //#define RT_USING_MUTEX // //
Using Event //
Using Event //#define RT_USING_EVENT // //
Using MailBox //
Using MailBox //#define RT_USING_MAILBOX // //
Using Message Queue //
Using Message Queue //#define RT_USING_MESSAGEQUEUE // //
//
Memory Management Configuration //
Using Memory Pool Management //
Using Memory Pool Management //#define RT_USING_MEMPOOL // //
Dynamic Heap Management //
Dynamic Heap Management #define RT_USING_HEAP // //
using small memory //
using small memory #define RT_USING_SMALL_MEM // //
//
Console Configuration //
Using console //
Using console #define RT_USING_CONSOLE // //
the buffer size of console <1-1024> //
the buffer size of console //
Default: 128 (128Byte) #define RT_CONSOLEBUF_SIZE 128 //
The device name for console //
The device name for console //
Default: uart0 #define RT_CONSOLE_DEVICE_NAME "uart2" //
#if defined(RTE_USING_DEVICE) #define RT_USING_DEVICE #define RT_USING_SERIAL #define BSP_USING_UART2 #endif #if defined(RTE_USING_FINSH) //
Finsh Configuration //
Using FinSh Shell //
Using FinSh Shell #define RT_USING_FINSH // //
Using Msh Shell //
Using Msh Shell #define FINSH_USING_MSH // //
Only using Msh Shell //
Only using Msh Shell #define FINSH_USING_MSH_ONLY // //
the priority of finsh thread <1-7> //
the priority of finsh thread //
Default: 6 #define __FINSH_THREAD_PRIORITY 1 #define FINSH_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 8 * __FINSH_THREAD_PRIORITY + 1) //
the stack of finsh thread <1-4096> //
the stack of finsh thread //
Default: 4096 (4096Byte) #define FINSH_THREAD_STACK_SIZE 2048 //
the history lines of finsh thread <1-32> //
the history lines of finsh thread //
Default: 5 #define FINSH_HISTORY_LINES 5 //
Using symbol table in finsh shell //
Using symbol table in finsh shell #define FINSH_USING_SYMTAB // //
#endif //RTE_USING_FINSH #define SOC_SERIES_STM32F1 // <<< end of configuration section >>> #endif ``` drv_usart.h ``` /* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018.10.30 SummerGift first version * 2019.03.05 whj4674672 add stm32h7 */ #ifndef __DRV_USART_H__ #define __DRV_USART_H__ #include
#include "rtdevice.h" #include
//#include
//#include "drv_dma.h" #include "uart_config.h" #include "stm32f1xx_hal.h" int rt_hw_usart_init(void); #if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) \ || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) #define DMA_INSTANCE_TYPE DMA_Channel_TypeDef #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32H7) #define DMA_INSTANCE_TYPE DMA_Stream_TypeDef #endif /* defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) */ #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F4) \ || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) #define UART_INSTANCE_CLEAR_FUNCTION __HAL_UART_CLEAR_FLAG #elif defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32H7) #define UART_INSTANCE_CLEAR_FUNCTION __HAL_UART_CLEAR_IT #endif /* stm32 config class */ struct stm32_uart_config { const char *name; USART_TypeDef *Instance; IRQn_Type irq_type; struct dma_config *dma_rx; }; /* stm32 uart dirver class */ struct stm32_uart { UART_HandleTypeDef handle; struct stm32_uart_config *config; #ifdef RT_SERIAL_USING_DMA struct { DMA_HandleTypeDef handle; rt_size_t last_index; } dma; #endif rt_uint8_t uart_dma_flag; struct rt_serial_device serial; }; #endif /* __DRV_USART_H__ */ ``` drv_usart.c ``` /* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-10-30 SummerGift first version */ //#include "board.h" #include "drv_usart.h" //#include "drv_config.h" #ifdef RT_USING_SERIAL //#define DRV_DEBUG #define LOG_TAG "drv.usart" //#include
#if !defined(BSP_USING_UART1) && !defined(BSP_USING_UART2) && !defined(BSP_USING_UART3) \ && !defined(BSP_USING_UART4) && !defined(BSP_USING_UART5) && !defined(BSP_USING_LPUART1) #error "Please define at least one BSP_USING_UARTx" /* this driver can be disabled at menuconfig ? RT-Thread Components ? Device Drivers */ #endif #ifdef RT_SERIAL_USING_DMA static void stm32_dma_config(struct rt_serial_device *serial); #endif enum { #ifdef BSP_USING_UART1 UART1_INDEX, #endif #ifdef BSP_USING_UART2 UART2_INDEX, #endif #ifdef BSP_USING_UART3 UART3_INDEX, #endif #ifdef BSP_USING_UART4 UART4_INDEX, #endif #ifdef BSP_USING_UART5 UART5_INDEX, #endif #ifdef BSP_USING_UART6 UART6_INDEX, #endif #ifdef BSP_USING_LPUART1 LPUART1_INDEX, #endif }; static struct stm32_uart_config uart_config[] = { #ifdef BSP_USING_UART1 UART1_CONFIG, #endif #ifdef BSP_USING_UART2 UART2_CONFIG, #endif #ifdef BSP_USING_UART3 UART3_CONFIG, #endif #ifdef BSP_USING_UART4 UART4_CONFIG, #endif #ifdef BSP_USING_UART5 UART5_CONFIG, #endif #ifdef BSP_USING_UART6 UART6_CONFIG, #endif #ifdef BSP_USING_LPUART1 LPUART1_CONFIG, #endif }; static struct stm32_uart uart_obj[sizeof(uart_config) / sizeof(uart_config[0])] = {0}; static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_configure *cfg) { struct stm32_uart *uart; RT_ASSERT(serial != RT_NULL); RT_ASSERT(cfg != RT_NULL); uart = (struct stm32_uart *)serial->parent.user_data; RT_ASSERT(uart != RT_NULL); uart->handle.Instance = uart->config->Instance; uart->handle.Init.BaudRate = cfg->baud_rate; uart->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; uart->handle.Init.Mode = UART_MODE_TX_RX; uart->handle.Init.OverSampling = UART_OVERSAMPLING_16; switch (cfg->data_bits) { case DATA_BITS_8: uart->handle.Init.WordLength = UART_WORDLENGTH_8B; break; case DATA_BITS_9: uart->handle.Init.WordLength = UART_WORDLENGTH_9B; break; default: uart->handle.Init.WordLength = UART_WORDLENGTH_8B; break; } switch (cfg->stop_bits) { case STOP_BITS_1: uart->handle.Init.StopBits = UART_STOPBITS_1; break; case STOP_BITS_2: uart->handle.Init.StopBits = UART_STOPBITS_2; break; default: uart->handle.Init.StopBits = UART_STOPBITS_1; break; } switch (cfg->parity) { case PARITY_NONE: uart->handle.Init.Parity = UART_PARITY_NONE; break; case PARITY_ODD: uart->handle.Init.Parity = UART_PARITY_ODD; break; case PARITY_EVEN: uart->handle.Init.Parity = UART_PARITY_EVEN; break; default: uart->handle.Init.Parity = UART_PARITY_NONE; break; } if (HAL_UART_Init(&uart->handle) != HAL_OK) { return -RT_ERROR; } return RT_EOK; } static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *arg) { struct stm32_uart *uart; #ifdef RT_SERIAL_USING_DMA rt_ubase_t ctrl_arg = (rt_ubase_t)arg; #endif RT_ASSERT(serial != RT_NULL); uart = (struct stm32_uart *)serial->parent.user_data; RT_ASSERT(uart != RT_NULL); switch (cmd) { /* disable interrupt */ case RT_DEVICE_CTRL_CLR_INT: /* disable rx irq */ NVIC_DisableIRQ(uart->config->irq_type); /* disable interrupt */ __HAL_UART_DISABLE_IT(&(uart->handle), UART_IT_RXNE); break; /* enable interrupt */ case RT_DEVICE_CTRL_SET_INT: /* enable rx irq */ NVIC_EnableIRQ(uart->config->irq_type); /* enable interrupt */ __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_RXNE); break; #ifdef RT_SERIAL_USING_DMA case RT_DEVICE_CTRL_CONFIG: if (ctrl_arg == RT_DEVICE_FLAG_DMA_RX) { stm32_dma_config(serial); } break; #endif } return RT_EOK; } static int stm32_putc(struct rt_serial_device *serial, char c) { struct stm32_uart *uart; RT_ASSERT(serial != RT_NULL); uart = (struct stm32_uart *)serial->parent.user_data; UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC); #if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) \ || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) uart->handle.Instance->TDR = c; #else uart->handle.Instance->DR = c; #endif while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET); return 1; } static int stm32_getc(struct rt_serial_device *serial) { int ch; struct stm32_uart *uart; RT_ASSERT(serial != RT_NULL); uart = (struct stm32_uart *)serial->parent.user_data; RT_ASSERT(uart != RT_NULL); ch = -1; if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) { #if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) \ || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) ch = uart->handle.Instance->RDR & 0xff; #else ch = uart->handle.Instance->DR & 0xff; #endif } return ch; } static const struct rt_uart_ops stm32_uart_ops = { .configure = stm32_configure, .control = stm32_control, .putc = stm32_putc, .getc = stm32_getc, }; /** * Uart common interrupt process. This need add to uart ISR. * * @param serial serial device */ static void uart_isr(struct rt_serial_device *serial) { struct stm32_uart *uart; #ifdef RT_SERIAL_USING_DMA rt_size_t recv_total_index, recv_len; rt_base_t level; #endif RT_ASSERT(serial != RT_NULL); uart = (struct stm32_uart *) serial->parent.user_data; RT_ASSERT(uart != RT_NULL); /* UART in mode Receiver -------------------------------------------------*/ if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) && (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_RXNE) != RESET)) { rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); } #ifdef RT_SERIAL_USING_DMA else if ((uart->uart_dma_flag) && (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_IDLE) != RESET) && (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_IDLE) != RESET)) { level = rt_hw_interrupt_disable(); recv_total_index = serial->config.bufsz - __HAL_DMA_GET_COUNTER(&(uart->dma.handle)); recv_len = recv_total_index - uart->dma.last_index; uart->dma.last_index = recv_total_index; rt_hw_interrupt_enable(level); if (recv_len) { rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8)); } __HAL_UART_CLEAR_IDLEFLAG(&uart->handle); } #endif else { if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_ORE) != RESET) { __HAL_UART_CLEAR_OREFLAG(&uart->handle); } if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_NE) != RESET) { __HAL_UART_CLEAR_NEFLAG(&uart->handle); } if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_FE) != RESET) { __HAL_UART_CLEAR_FEFLAG(&uart->handle); } if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_PE) != RESET) { __HAL_UART_CLEAR_PEFLAG(&uart->handle); } #if !defined(SOC_SERIES_STM32L4) && !defined(SOC_SERIES_STM32F7) && !defined(SOC_SERIES_STM32F0) \ && !defined(SOC_SERIES_STM32L0) && !defined(SOC_SERIES_STM32G0) && !defined(SOC_SERIES_STM32H7) if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_LBD) != RESET) { UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_LBD); } #endif if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_CTS) != RESET) { UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_CTS); } if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TXE) != RESET) { UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TXE); } if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) != RESET) { UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC); } if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) { UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_RXNE); } } } #if defined(BSP_USING_UART1) void USART1_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&(uart_obj[UART1_INDEX].serial)); /* leave interrupt */ rt_interrupt_leave(); } #if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART1_RX_USING_DMA) void UART1_DMA_RX_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); HAL_DMA_IRQHandler(&uart_obj[UART1_INDEX].dma.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART1_RX_USING_DMA) */ #endif /* BSP_USING_UART1 */ #if defined(BSP_USING_UART2) void USART2_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&(uart_obj[UART2_INDEX].serial)); /* leave interrupt */ rt_interrupt_leave(); } #if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART2_RX_USING_DMA) void UART2_DMA_RX_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); HAL_DMA_IRQHandler(&uart_obj[UART2_INDEX].dma.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART2_RX_USING_DMA) */ #endif /* BSP_USING_UART2 */ #if defined(BSP_USING_UART3) void USART3_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&(uart_obj[UART3_INDEX].serial)); /* leave interrupt */ rt_interrupt_leave(); } #if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART3_RX_USING_DMA) void UART3_DMA_RX_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); HAL_DMA_IRQHandler(&uart_obj[UART3_INDEX].dma.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(BSP_UART_USING_DMA_RX) && defined(BSP_UART3_RX_USING_DMA) */ #endif /* BSP_USING_UART3*/ #if defined(BSP_USING_UART4) void UART4_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&(uart_obj[UART4_INDEX].serial)); /* leave interrupt */ rt_interrupt_leave(); } #if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART4_RX_USING_DMA) void UART4_DMA_RX_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); HAL_DMA_IRQHandler(&uart_obj[UART4_INDEX].dma.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(BSP_UART_USING_DMA_RX) && defined(BSP_UART4_RX_USING_DMA) */ #endif /* BSP_USING_UART4*/ #if defined(BSP_USING_UART5) void UART5_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&(uart_obj[UART5_INDEX].serial)); /* leave interrupt */ rt_interrupt_leave(); } #if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART5_RX_USING_DMA) void UART5_DMA_RX_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); HAL_DMA_IRQHandler(&uart_obj[UART5_INDEX].dma.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART5_RX_USING_DMA) */ #endif /* BSP_USING_UART5*/ #if defined(BSP_USING_UART6) void USART6_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&(uart_obj[UART6_INDEX].serial)); /* leave interrupt */ rt_interrupt_leave(); } #if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART6_RX_USING_DMA) void UART6_DMA_RX_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); HAL_DMA_IRQHandler(&uart_obj[UART6_INDEX].dma.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART6_RX_USING_DMA) */ #endif /* BSP_USING_UART6*/ #if defined(BSP_USING_LPUART1) void LPUART1_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&(uart_obj[LPUART1_INDEX].serial)); /* leave interrupt */ rt_interrupt_leave(); } #if defined(RT_SERIAL_USING_DMA) && defined(BSP_LPUART1_RX_USING_DMA) void LPUART1_DMA_RX_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); HAL_DMA_IRQHandler(&uart_obj[LPUART1_INDEX].dma.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_LPUART1_RX_USING_DMA) */ #endif /* BSP_USING_LPUART1*/ #ifdef RT_SERIAL_USING_DMA static void stm32_dma_config(struct rt_serial_device *serial) { RT_ASSERT(serial != RT_NULL); struct stm32_uart *uart = (struct stm32_uart *)serial->parent.user_data; RT_ASSERT(uart != RT_NULL); struct rt_serial_rx_fifo *rx_fifo; LOG_D("%s dma config start", uart->config->name); { rt_uint32_t tmpreg= 0x00U; #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) \ || defined(SOC_SERIES_STM32L0) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ SET_BIT(RCC->AHBENR, uart->config->dma_rx->dma_rcc); tmpreg = READ_BIT(RCC->AHBENR, uart->config->dma_rx->dma_rcc); #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ SET_BIT(RCC->AHB1ENR, uart->config->dma_rx->dma_rcc); tmpreg = READ_BIT(RCC->AHB1ENR, uart->config->dma_rx->dma_rcc); #endif UNUSED(tmpreg); /* To avoid compiler warnings */ } __HAL_LINKDMA(&(uart->handle), hdmarx, uart->dma.handle); #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L0) uart->dma.handle.Instance = uart->config->dma_rx->Instance; #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) uart->dma.handle.Instance = uart->config->dma_rx->Instance; uart->dma.handle.Init.Channel = uart->config->dma_rx->channel; #elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0) uart->dma.handle.Instance = uart->config->dma_rx->Instance; uart->dma.handle.Init.Request = uart->config->dma_rx->request; #endif uart->dma.handle.Init.Direction = DMA_PERIPH_TO_MEMORY; uart->dma.handle.Init.PeriphInc = DMA_PINC_DISABLE; uart->dma.handle.Init.MemInc = DMA_MINC_ENABLE; uart->dma.handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; uart->dma.handle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; uart->dma.handle.Init.Mode = DMA_CIRCULAR; uart->dma.handle.Init.Priority = DMA_PRIORITY_MEDIUM; #if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) uart->dma.handle.Init.FIFOMode = DMA_FIFOMODE_DISABLE; #endif if (HAL_DMA_DeInit(&(uart->dma.handle)) != HAL_OK) { RT_ASSERT(0); } if (HAL_DMA_Init(&(uart->dma.handle)) != HAL_OK) { RT_ASSERT(0); } rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; /* Start DMA transfer */ if (HAL_UART_Receive_DMA(&(uart->handle), rx_fifo->buffer, serial->config.bufsz) != HAL_OK) { /* Transfer error in reception process */ RT_ASSERT(0); } /* enable interrupt */ __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_IDLE); /* enable rx irq */ HAL_NVIC_SetPriority(uart->config->dma_rx->dma_irq, 0, 0); HAL_NVIC_EnableIRQ(uart->config->dma_rx->dma_irq); HAL_NVIC_SetPriority(uart->config->irq_type, 1, 0); HAL_NVIC_EnableIRQ(uart->config->irq_type); LOG_D("%s dma RX instance: %x", uart->config->name, uart->dma.handle.Instance); LOG_D("%s dma config done", uart->config->name); } /** * @brief UART error callbacks * @param huart: UART handle * @note This example shows a simple way to report transfer error, and you can * add your own implementation. * @retval None */ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) { RT_ASSERT(huart != NULL); struct stm32_uart *uart = (struct stm32_uart *)huart; LOG_D("%s: %s %d\n", __FUNCTION__, uart->config->name, huart->ErrorCode); UNUSED(uart); } /** * @brief Rx Transfer completed callback * @param huart: UART handle * @note This example shows a simple way to report end of DMA Rx transfer, and * you can add your own implementation. * @retval None */ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { struct rt_serial_device *serial; struct stm32_uart *uart; rt_size_t recv_len; rt_base_t level; RT_ASSERT(huart != NULL); uart = (struct stm32_uart *)huart; serial = &uart->serial; level = rt_hw_interrupt_disable(); recv_len = serial->config.bufsz - uart->dma.last_index; uart->dma.last_index = 0; rt_hw_interrupt_enable(level); if (recv_len) { rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8)); } } #endif /* RT_SERIAL_USING_DMA */ static void stm32_uart_get_dma_config(void) { #ifdef BSP_UART1_RX_USING_DMA uart_obj[UART1_INDEX].uart_dma_flag = 1; static struct dma_config uart1_dma_rx = UART1_DMA_CONFIG; uart_config[UART1_INDEX].dma_rx = &uart1_dma_rx; #endif #ifdef BSP_UART2_RX_USING_DMA uart_obj[UART2_INDEX].uart_dma_flag = 1; static struct dma_config uart2_dma_rx = UART2_DMA_CONFIG; uart_config[UART2_INDEX].dma_rx = &uart2_dma_rx; #endif #ifdef BSP_UART3_RX_USING_DMA uart_obj[UART3_INDEX].uart_dma_flag = 1; static struct dma_config uart3_dma_rx = UART3_DMA_CONFIG; uart_config[UART3_INDEX].dma_rx = &uart3_dma_rx; #endif #ifdef BSP_UART4_RX_USING_DMA uart_obj[UART4_INDEX].uart_dma_flag = 1; static struct dma_config uart4_dma_rx = UART4_DMA_CONFIG; uart_config[UART4_INDEX].dma_rx = &uart4_dma_rx; #endif #ifdef BSP_UART5_RX_USING_DMA uart_obj[UART5_INDEX].uart_dma_flag = 1; static struct dma_config uart5_dma_rx = UART5_DMA_CONFIG; uart_config[UART5_INDEX].dma_rx = &uart5_dma_rx; #endif #ifdef BSP_UART6_RX_USING_DMA uart_obj[UART6_INDEX].uart_dma_flag = 1; static struct dma_config uart6_dma_rx = UART6_DMA_CONFIG; uart_config[UART6_INDEX].dma_rx = &uart6_dma_rx; #endif #ifdef BSP_LPUART1_RX_USING_DMA uart_obj[LPUART1_INDEX].uart_dma_flag = 1; static struct dma_config lpuart1_dma_rx = LPUART1_DMA_CONFIG; uart_config[LPUART1_INDEX].dma_rx = &lpuart1_dma_rx; #endif } int rt_hw_usart_init(void) { rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct stm32_uart); struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; rt_err_t result = 0; stm32_uart_get_dma_config(); for (int i = 0; i < obj_num; i++) { uart_obj[i].config = &uart_config[i]; uart_obj[i].serial.ops = &stm32_uart_ops; uart_obj[i].serial.config = config; #if defined(RT_SERIAL_USING_DMA) if(uart_obj[i].uart_dma_flag) { /* register UART device */ result = rt_hw_serial_register(&uart_obj[i].serial,uart_obj[i].config->name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX| RT_DEVICE_FLAG_DMA_RX ,&uart_obj[i]); } else #endif { /* register UART device */ result = rt_hw_serial_register(&uart_obj[i].serial,uart_obj[i].config->name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,&uart_obj[i]); } RT_ASSERT(result == RT_EOK); } return result; } #endif /* RT_USING_SERIAL */ ```
Tiv
2019-04-17
这家伙很懒,什么也没写!
差37积分才能发消息,不好意思,回不了你们消息:'(
Tiv
2019-04-17
这家伙很懒,什么也没写!
我QQ 390763144 微信 dream_daiblo
撰写答案
登录
注册新账号
关注者
0
被浏览
5.4k
关于作者
Tiv
这家伙很懒,什么也没写!
提问
14
回答
41
被采纳
0
关注TA
发私信
相关问题
1
【内核学习】rtthread内核移植记录-STM32F103ZET6-HAL库
2
《内核学习营》+水一方+自用STM32F103VC 板RT-Thread内核移植分享
3
《内核学习营》+水一方+项目中创建标准的 RT-Thread工程
4
内核学习营+坦然+探索者stm32f407板子RT-thread循环点亮led灯
5
<内核学习营>+坦然+探索者stm32f407板子RT-thread串口字符点灯
6
<内核学习营>+坦然+探索者stm32f407板子RT-thread的pwm点灯实验
7
<内核学习营>+坦然+探索者stm32f407板子RT-thread串口实验
8
<内核学习营>+坦然+野火stm32f103板子RT-thread读写SD卡实验
9
<内核学习营>+坦然+探索者stm32f407板子RT-thread的RTC闹钟实验
10
【内核学习营】+王秀峰+led_rgb
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用RC522软件包驱动FM1722
2
常量数据类型和表达式陷阱分享
3
进行i2c驱动移植的经验总结
4
在VSCode中使用clang-format
5
我该如何使用这个微雪的WIFI400 WIFI-LPB-100在rtt里或者我该怎样为它开发驱动
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
UART
WIZnet_W5500
ota在线升级
freemodbus
PWM
flash
cubemx
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
编译报错
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
踩姑娘的小蘑菇
4
个答案
1
次被采纳
红枫
4
个答案
1
次被采纳
张世争
4
个答案
1
次被采纳
Ryan_CW
4
个答案
1
次被采纳
xiaorui
1
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
qq1078249029
2
篇文章
2
次点赞
xnosky
2
篇文章
1
次点赞
Woshizhapuren
1
篇文章
5
次点赞
YZRD
1
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部