当前页面为 开发中 版本,查看特定版本的文档,请在页面左下角的下拉菜单中进行选择。

Driver: DMA M2P&P2M

1 功能概述

dma_m2p2m sampleMemory to UARTUART to Memory 传输为例,演示了 Zephyr DMA Memory-to-Peripheral 和 Peripheral-to-Memory 的使用方法。

2 环境准备

  • PAN1080 EVB 一块

  • USB-TypeC 线一条(用于供电和查看串口打印 Log)

  • 硬件接线:

    • 使用USB线,将 PC USB 与 EVB USB-TypeC(USB->UART)相连

    • 根据 EVB 核心板芯片的封装不同,使用杜邦线将 EVB 底板上的:

      • TX0 与 P00 相连, RX0 与 P01 相连,UART1 自身的 TX (P06) 与 RX (P07) 相连(若 EVB 板芯片为 QFN32 或 LQFP64 封装)

      • TX0 与 P30 相连, RX0 与 P31 相连,UART1 自身的 TX (P14) 与 RX (P15) 相连(若 EVB 板芯片为 QFN48 封装)

  • PC 软件: 串口调试助手(UartAssist)或终端工具(SecureCRT),波特率921600

3 编译和烧录

例程位置:zephyr\samples_panchip\drivers\dma_m2p2m

使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍

4 演示说明

本例程中,同时配置了2个 DMA 通道,其中:

  1. 一个通道配置成 Memory-to-Peripheral 的方式,用于将一个字符串从 Flash 搬移到 UART1 Tx FIFO

  2. 另一个通道配置成 Peripheral-to-Memory 的方式,用于将 UART1 Rx FIFO 接收到的内容搬移到 SRAM

本例程涉及如下的 DMA Driver APIs:

  • dma_request_channel()

  • dma_release_channel()

  • dma_config()

  • dma_start()

  • dma_get_status()

例程执行成功的 Log 如下所示:

*** Booting Zephyr OS build zephyr-v2.7.0 ***
[00:00:00.000,000] <inf> dma_dw: Device DMA_0 initialized
[00:00:00.000,000] <inf> app: DMA M2P2M (Memory to Peripheral to Memory) demo start..
[00:00:00.001,000] <inf> app: Configure and start DMA transfer procedure, chan_id=0
[00:00:00.001,000] <inf> app: Configure and start DMA transfer procedure, chan_id=1
[00:00:00.001,000] <inf> app: DMA m2p status: direction=1, pending_length=19, busy=1
[00:00:00.001,000] <inf> app: DMA p2m status: direction=2, pending_length=43, busy=1
[00:00:00.002,000] <inf> app: DMA m2p status: direction=1, pending_length=3, busy=1
[00:00:00.002,000] <inf> app: DMA p2m status: direction=2, pending_length=35, busy=1
[00:00:00.004,000] <inf> app: dma_m2p_transfer_cb: DMA m2p transfer done
[00:00:00.004,000] <inf> app: DMA m2p status: direction=1, pending_length=0, busy=0
[00:00:00.004,000] <inf> app: DMA p2m status: direction=2, pending_length=11, busy=1
[00:00:00.005,000] <inf> app: dma_p2m_transfer_cb: DMA p2m transfer done
[00:00:00.005,000] <inf> app: DMA m2p status: direction=1, pending_length=0, busy=0
[00:00:00.005,000] <inf> app: DMA p2m status: direction=2, pending_length=0, busy=0
[00:00:00.006,000] <inf> app: Source string for transfer from Memory to Peripheral (UART_0):
[00:00:00.006,000] <inf> app:   - The quick brown fox jumps over the lazy dog
[00:00:00.006,000] <inf> app: String received from UART_0 with DMA Peripheral-to-Memory procudure:
[00:00:00.006,000] <inf> app:   - The quick brown fox jumps over the lazy dog
[00:00:00.006,000] <inf> app: DMA Data transfer OK, and channel 0 and channel 1 are now ready again for later use.
[00:00:00.006,000] <inf> app: DMA M2P2M (Memory to Peripheral to Memory) demo end.

注意:此例程执行前,请确保已经使用杜邦线将 UART1 自身的 TX 与 RX 接在一起。

5 开发者说明

  1. 本例程中使用到了 UART1 外设,但 App 代码中并没做对应的初始化配置,这是因为我们已经通过 DTS 的方式使能并初始化了 UART1:

    • Kconfig 中默认使能了 Zephyr UART Driver (CONFIG_SERIAL=y);

    • 板级 Devicetree 文件(如 pan108xxa1_evb.dts)中默认配置了 UART1 外设,但未使能:

      &uart1 {
         current-speed = <115200>;
         pinctrl-0 = <&p0_6_uart1_tx &p0_7_uart1_rx>;
         status = "disabled";
      };
      
    • App 级 Devicetree Overlay 文件(dma.overlay)中使能了 UART1:

      &uart1 {
         status = "okay";
      };
      
  2. 在涉及到 Peripheral 的 DMA 配置过程中,需要注意某些外设在使用 DMA 之前,要先开启自己模块内部的 DMA 传输使能开关;而另一些外设可能无需做此操作。对于 PAN1080 SoC 来说:

    • 需要另外配置方可使用 DMA 的外设有:SPI、I2C、ADC

    • 无需额外配置即可使用 DMA 的外设有:UART、I2S

  3. 更多技术细节请参考 Driver: DMA M2M 中的相关说明。

6 RAM/Flash资源使用情况

Memory region         Used Size  Region Size  %age Used
FLASH:       27548 B       384 KB      7.01%
SRAM:        7776 B        64 KB     11.87%