Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
SPI+DMA
标准版rt_thread中用STM32H563串口空闲中断+DMA接收数据
发布于 2024-11-01 17:45:43 浏览:341
订阅该版
DMA缓冲区,每次只能正确接收4的整数倍字节,并且DMA接收缓冲区大小只能设置在63个字节及以下,求救如何解决问题(裸机跑过没有任何问题)) DMA配置代码 ```c struct rt_serial_rx_fifo *rx_fifo; DMA_HandleTypeDef *DMA_Handle; struct dma_config *dma_config; struct stm32_uart *uart; RT_ASSERT(serial != RT_NULL); RT_ASSERT(flag == RT_DEVICE_FLAG_DMA_TX || flag == RT_DEVICE_FLAG_DMA_RX); uart = rt_container_of(serial, struct stm32_uart, serial); if (RT_DEVICE_FLAG_DMA_RX == flag) { DMA_Handle = &uart->dma_rx.handle; dma_config = uart->config->dma_rx; } else /* RT_DEVICE_FLAG_DMA_TX == flag */ { DMA_Handle = &uart->dma_tx.handle; dma_config = uart->config->dma_tx; } 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)|| defined(SOC_SERIES_STM32F3) || defined(SOC_SERIES_STM32L1) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ SET_BIT(RCC->AHBENR, dma_config->dma_rcc); tmpreg = READ_BIT(RCC->AHBENR, dma_config->dma_rcc); #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WL) \ || defined(SOC_SERIES_STM32G4)|| defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32H5) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ SET_BIT(RCC->AHB1ENR, dma_config->dma_rcc); tmpreg = READ_BIT(RCC->AHB1ENR, dma_config->dma_rcc); #elif defined(SOC_SERIES_STM32MP1) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ SET_BIT(RCC->MP_AHB2ENSETR, dma_config->dma_rcc); tmpreg = READ_BIT(RCC->MP_AHB2ENSETR, dma_config->dma_rcc); #endif #if (defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WL) || defined(SOC_SERIES_STM32G4) || defined(SOC_SERIES_STM32WB)) && defined(DMAMUX1) /* enable DMAMUX clock for L4+ and G4 */ __HAL_RCC_DMAMUX1_CLK_ENABLE(); #elif defined(SOC_SERIES_STM32MP1) __HAL_RCC_DMAMUX_CLK_ENABLE(); #endif UNUSED(tmpreg); /* To avoid compiler warnings */ } if (RT_DEVICE_FLAG_DMA_RX == flag) { __HAL_LINKDMA(&(uart->handle), hdmarx, uart->dma_rx.handle); } else if (RT_DEVICE_FLAG_DMA_TX == flag) { __HAL_LINKDMA(&(uart->handle), hdmatx, uart->dma_tx.handle); } #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L0)|| defined(SOC_SERIES_STM32F3) || defined(SOC_SERIES_STM32L1) || defined(SOC_SERIES_STM32U5) || defined(SOC_SERIES_STM32H5) DMA_Handle->Instance = dma_config->Instance; #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) DMA_Handle->Instance = dma_config->Instance; DMA_Handle->Init.Channel = dma_config->channel; #elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WL) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32G4) || defined(SOC_SERIES_STM32WB)\ || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32MP1) DMA_Handle->Instance = dma_config->Instance; DMA_Handle->Init.Request = dma_config->request; #endif //DMA_Handle->Instance = dma_config->Instance; DMA_Handle->Init.Request = dma_config->request; DMA_Handle->Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST; DMA_Handle->Init.SrcInc = DMA_SINC_FIXED; DMA_Handle->Init.DestInc = DMA_DINC_INCREMENTED; DMA_Handle->Init.SrcDataWidth = DMA_SRC_DATAWIDTH_BYTE; DMA_Handle->Init.DestDataWidth = DMA_DEST_DATAWIDTH_BYTE; DMA_Handle->Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER; // DMA_Handle->Init.SrcBurstLength=1; // DMA_Handle->Init.DestDataWidth=1; DMA_Handle->Init.TransferAllocatedPort=DMA_SRC_ALLOCATED_PORT0|DMA_DEST_ALLOCATED_PORT0; if (RT_DEVICE_FLAG_DMA_RX == flag) { DMA_Handle->Init.Direction = DMA_PERIPH_TO_MEMORY; DMA_Handle->Init.Mode = DMA_NORMAL; } else if (RT_DEVICE_FLAG_DMA_TX == flag) { DMA_Handle->Init.Direction = DMA_MEMORY_TO_PERIPH; DMA_Handle->Init.Mode = DMA_NORMAL; } DMA_Handle->Init.Priority = DMA_HIGH_PRIORITY; #if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32MP1) DMA_Handle->Init.FIFOMode = DMA_FIFOMODE_DISABLE; #endif // if (HAL_DMA_DeInit(DMA_Handle) != HAL_OK) // { // RT_ASSERT(0); // } if (HAL_DMA_Init(DMA_Handle) != HAL_OK) { RT_ASSERT(0); } //__HAL_LINKDMA(&(uart->handle), hdmarx, uart->dma_rx.handle); HAL_DMA_ConfigChannelAttributes(DMA_Handle, DMA_CHANNEL_NPRIV); /* enable interrupt */ if (flag == RT_DEVICE_FLAG_DMA_RX) { 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); } CLEAR_BIT(uart->handle.Instance->CR3, USART_CR3_EIE); __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_IDLE); // __HAL_DMA_ENABLE_IT(DMA_Handle, DMA_IT_TC); } /* DMA irq should set in DMA TX mode, or HAL_UART_TxCpltCallback function will not be called */ // HAL_NVIC_SetPriority(dma_config->dma_irq, 0, 0); // HAL_NVIC_EnableIRQ(dma_config->dma_irq); HAL_NVIC_SetPriority(uart->config->irq_type, 3, 3); HAL_NVIC_EnableIRQ(uart->config->irq_type); ``` 中断处理代码: ```c struct rt_serial_rx_fifo *rx_fifo; rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; uint8_t ucTmp=0; ucTmp = uart->handle.Instance->ISR; ucTmp= uart->handle.Instance->RDR; HAL_UART_DMAStop(&(uart->handle)); rx_fifo->get_index=0; rx_fifo->put_index=0; dma_recv_isr(serial, UART_RX_DMA_IT_IDLE_FLAG); HAL_UART_Receive_DMA(&(uart->handle), rx_fifo->buffer, serial->config.bufsz); //rt_memset(rx_fifo->buffer,0, serial->config.bufsz); //CLEAR_BIT(uart->handle.Instance->CR3, USART_CR3_EIE); __HAL_UART_CLEAR_IDLEFLAG(&uart->handle); ```
查看更多
3
个回答
默认排序
按发布时间排序
用户名由3_15位
2024-11-02
这家伙很懒,什么也没写!
- 用RTT自己的串口驱动看看;uartV2内部也是用DMA+空闲中断的
简卡拉卡
2025-01-13
这家伙很懒,什么也没写!
博主是自己移植的rtt还是借助的开发工具?我也是需要在STM32H563上使用rtt,目前还没找到方便移植的方法
逍遥洒脱邱子风
2025-01-23
这家伙很懒,什么也没写!
我刚刚看官方的教程,我发现默认是接收64字节,但可以自己设置。 ![微信图片_20250123165726.png](https://oss-club.rt-thread.org/uploads/20250123/9377139e04fcc954465fb5a76085ddbb.png.webp) ![微信图片_20250123165801.png](https://oss-club.rt-thread.org/uploads/20250123/52e3bbaad9f54fb376dbd5a261b65fed.png.webp) 官方文档地址https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/uart/uart_v1/uart?id=%e8%ae%bf%e9%97%ae%e4%b8%b2%e5%8f%a3%e8%ae%be%e5%a4%87
撰写答案
登录
注册新账号
关注者
0
被浏览
341
关于作者
RETW_8966
这家伙很懒,什么也没写!
提问
1
回答
0
被采纳
0
关注TA
发私信
相关问题
1
正点原子战舰V3+ENC28J60+SPI,开启SPI DMA后,卡死
2
SPI4设置DMA RX 错误
3
spi DMA 发送数据失败
4
spi dma 中断接收的问题
5
关于spi和dma的问题
6
RT Studio中F407芯片SPI的DMA怎么开启?
7
RT Studio中SPI+DMA如何使用?
8
rt-thread 互斥信号量BUG
9
我现在可以使用SPI正常收发数据了,但是怎样使用SPI的DMA模式进行数据的收发
10
SPI DMA 缓冲区
推荐文章
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
【RT-Thread】【ci】【scons】将ci.attachconfig.yml和scons结合使用
2
Rt-thread中OTA下载后,bootloader不搬程序
3
ulog 日志 LOG_HEX 输出时间改为本地日期时间
4
在RT-Thread Studio中构建前执行python命令
5
研究一了一段时间RTT,直接标准版上手太难,想用nano,但又舍不得组件
热门标签
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
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
cubemx
PWM
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
xusiwei1236
8
个答案
2
次被采纳
踩姑娘的小蘑菇
1
个答案
2
次被采纳
用户名由3_15位
9
个答案
1
次被采纳
bernard
4
个答案
1
次被采纳
RTT_逍遥
3
个答案
1
次被采纳
本月文章贡献
聚散无由
2
篇文章
15
次点赞
catcatbing
2
篇文章
5
次点赞
Wade
2
篇文章
4
次点赞
Ghost_Girls
1
篇文章
7
次点赞
xiaorui
1
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部