打印
[STM32H7]

串口DMA接收,哪里是接收数据存放处?

[复制链接]
251|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jiajs|  楼主 | 2022-3-2 21:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/* Configure the DMA handler for reception process */
  hdma_rx.Instance                 = USARTx_RX_DMA_STREAM;
  hdma_rx.Init.Request             = USARTx_RX_DMA_CHANNEL;
  hdma_rx.Init.Direction           = DMA_PERIPH_TO_MEMORY;
  hdma_rx.Init.PeriphInc           = DMA_PINC_DISABLE;
  hdma_rx.Init.MemInc              = DMA_MINC_ENABLE;
  hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  hdma_rx.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
  hdma_rx.Init.Mode                = DMA_NORMAL;
  hdma_rx.Init.Priority            = DMA_PRIORITY_HIGH;
  hdma_rx.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
  hdma_rx.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
  hdma_rx.Init.MemBurst            = DMA_MBURST_INC4;
  hdma_rx.Init.PeriphBurst         = DMA_PBURST_INC4;

  HAL_DMA_Init(&hdma_rx);

使用特权

评论回复
沙发
heweibig| | 2022-3-2 21:15 | 只看该作者
这只是初始化,还没调用 HAL_UART_Receive_DMA 函数。[em:3:

使用特权

评论回复
板凳
jiajs|  楼主 | 2022-3-2 21:18 | 只看该作者
/* Clean D-cache */
/* Make sure the address is 32-byte aligned and add 32-bytes to length, in case it overlaps cacheline */
SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t)tx_buffer) & ~(uint32_t)0x1F), TX_LENGTH+32);

/* Start DMA transfer */
HAL_UART_Transmit_DMA(&huart1, tx_buffer, TX_LENGTH);
请问 SCB_Clean... 这语句什么意思? 没这条就发不出

使用特权

评论回复
地板
supernan| | 2022-3-2 21:20 | 只看该作者
DMA cpu不经过外设的内存直接访问单元吧?

使用特权

评论回复
5
jiajs|  楼主 | 2022-3-2 21:22 | 只看该作者
Transmitting data:

#define TX_LENGTH  (16)
uint8_t tx_buffer[TX_LENGTH];

/* Write data */
tx_buffer[0] = 0x0;
tx_buffer[1] = 0x1;

/* Clean D-cache */
/* Make sure the address is 32-byte aligned and add 32-bytes to length, in case it overlaps cacheline */
SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t)tx_buffer) & ~(uint32_t)0x1F), TX_LENGTH+32);

/* Start DMA transfer */
HAL_UART_Transmit_DMA(&huart1, tx_buffer, TX_LENGTH);
Receiving data:

#define RX_LENGTH  (16)
uint8_t rx_buffer[RX_LENGTH];

/* Invalidate D-cache before reception */
/* Make sure the address is 32-byte aligned and add 32-bytes to length, in case it overlaps cacheline */
SCB_InvalidateDCache_by_Addr((uint32_t*)(((uint32_t)rx_buffer) & ~(uint32_t)0x1F), RX_LENGTH+32);

/* Start DMA transfer */
HAL_UART_Receive_DMA(&huart1, rx_buffer, RX_LENGTH);
/* No access to rx_buffer should be made before DMA transfer is completed */

单收单发可以,同时收发数据出错

使用特权

评论回复
6
jlyuan| | 2022-3-2 21:24 | 只看该作者
这部分代码里没有啊

使用特权

评论回复
7
chuxh| | 2022-3-2 21:27 | 只看该作者
接收数据代码没有啊

使用特权

评论回复
8
renyaq| | 2022-3-2 21:29 | 只看该作者
没用过dma  dma需要接收中断吗

使用特权

评论回复
9
chuxh| | 2022-3-2 22:03 | 只看该作者
没有用过dma啊

使用特权

评论回复
10
jiajs|  楼主 | 2022-3-2 22:06 | 只看该作者

嗯,我再好好缕一缕吧,有了好消息及时通知大家

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

940

主题

11975

帖子

6

粉丝