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

[复制链接]
841|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不经过外设的内存直接访问单元吧?
 楼主| 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 */

单收单发可以,同时收发数据出错
jlyuan 发表于 2022-3-2 21:24 | 显示全部楼层
这部分代码里没有啊
chuxh 发表于 2022-3-2 21:27 | 显示全部楼层
接收数据代码没有啊
renyaq 发表于 2022-3-2 21:29 | 显示全部楼层
没用过dma  dma需要接收中断吗
chuxh 发表于 2022-3-2 22:03 | 显示全部楼层
没有用过dma啊
 楼主| jiajs 发表于 2022-3-2 22:06 | 显示全部楼层

嗯,我再好好缕一缕吧,有了好消息及时通知大家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

940

主题

11975

帖子

6

粉丝
快速回复 在线客服 返回列表 返回顶部