Edit online

编程指南

3 Mar 2025
Read time: 3 minute(s)
注:
  • 源端与终端地址需要 4Byte 对齐。
  • 外设 WIDTH 设置需与外设模块寄存器位宽对齐。
  • 外设 LENGTH 设置需要与 WIDTH 对齐。
  • SPI Width 说明:DMA_Width=32,则 SPI.src_word_en=1。DMA_Width=8,则 SPI.src_word_en=0。需要配置 spi 模块内部 src_word_en 使用。
  • UART Byte 传输说明:如 UART 需要实现 Byte 功能(即每接收到 1Byte 数据,马上写到内存中),则 Burst=1、Type=io_single、Block_length=1。

dma_flow1

1. DMA 编程指南

外设与外设传输

  • TASK_LENGTH:需要与 max(src_width,dst_width)对齐。
  • 外设模块内部水位:等于 block_length
  • src_type=iob 与 dst_type=iob: block_length=src_width*src_burst=dst_width*dst_burst
  • src_type=iob 与 dst_type=ios: block_length=src_width*src_burst
  • src_type=ios 与 dst_type=iob: block_length=dst_width*dst_burst
以 SPI 为例,源端为 SPI0,终端为 SPI1。SPI 的 width 支持 8 或者 32。SPI 支持 burst 操作。
1. 外设与外设传输编程示例
对象 参数 配置值例 1 配置值例 2 配置值例 3 配置值例 4 配置值例 5 配置值例 6
源端 SPI0

src_spi0

width 8 8 8 8 8 8
burst 1 1 1 1 8 8
type ios ios ios ios iob (或 iof) iob (或 iof)
终端 SPI1 dst_spi1
width 32 8 32 8 32 8
burst 1 1 4 4 4 4
type ios ios iob (或 iof) iob (者 iof) iob (者 iof) iob (或 iof)
要求 length 对齐要求 4Byte 对齐 1Byte 对齐 4Byte 对齐 1Byte 对齐 4Byte 对齐 1Byte 对齐
block_length 4 1 16 4 16 8
src_spi0 与 spi1 模块内部水位 4 1 16 4 16 8

DMA 编程说明

以下是以 SRAM 搬运数据到 SPI (spi0) 为例的 DMA 配置步骤:

  1. 初始化参数。
    2. DMA 编程初始化参数示例
    源端 终端
    SRAM (假设 src _width=32)
    • src_width = 32
    • src_burst = 16
    • src_type = memory
    SPI (spi0, dma_id=8)
    • dst_width = 32
    • dst_burst = 4
    • dst_type = io_burst
  2. 计算 Block_Length。

    由于对象包含外设并且 type=io_burst,则 block_length=32x4/8=16(Bytes)。

  3. 初始化 SPI 进行,并且把 SPI 的水位设置为等于 length。此处设为 16,等于 length。
  4. 使能 DMA 模块时钟、释放 DMA 复位并使能 DMA 中断。
  5. 配置任务链表内容如下:
    3. DMA 任务链表编程示例
    地址 参数描述 备注
    0xa1c8_6688 TASK_LINK_ID TASK_LINK_ID 需要与 SET 一致。
    0x2148_22c0 TASK_CFG_1
    0x0000_0010 BLOCK_LEN
    0x9004_7444 SRC_ADDR 源端地址:sram 首地址
    0x913f_0200 DST_ADDR 终端:SPI0 TX_FIFO 地址
    0x0000_00f4 TASK_LENGTH
    0x55ff_0000 TASK_CFG_2 使用推荐值 0x55ff_0000。
    0xffff_fffc 下一 task 首地址 因为只有一个 task,故为 0xffff_fffc。
  6. 把任务链表首地址(0x900406e0),写到 DMA 所对应通道的 DMA_CH_TASK_ADD_1 寄存器中。
  7. 启动 DMA 传输,等待 DMA 传输完成中断。