DMA:Data Memory Access,直接存储器访问。数据从一个地方搬运到另外一个地方,不占用CPU。
STM32有两个DMA,其中DMA2只存在大容量和互联型产品。
DMA1有7个通道,DMA2有5个通道。
DMA三种使用方式:
DMA框架可以分为三部分:DMA请求,DMA通道,DMA仲裁器。
DMA请求
来自外设设备。
通道
DMA1有7条通道,DMA2有5道通道。
DMA1请求映像:
DMA2请求映像:
仲裁器
typedef struct
{uint32_t DMA_PeripheralBaseAddr; /*!< Specifies the peripheral base address for DMAy Channelx. */uint32_t DMA_MemoryBaseAddr; /*!< Specifies the memory base address for DMAy Channelx. */uint32_t DMA_DIR; /*!< Specifies if the peripheral is the source or destination.This parameter can be a value of @ref DMA_data_transfer_direction */uint32_t DMA_BufferSize; /*!< Specifies the buffer size, in data unit, of the specified Channel. The data unit is equal to the configuration set in DMA_PeripheralDataSizeor DMA_MemoryDataSize members depending in the transfer direction. */uint32_t DMA_PeripheralInc; /*!< Specifies whether the Peripheral address register is incremented or not.This parameter can be a value of @ref DMA_peripheral_incremented_mode */uint32_t DMA_MemoryInc; /*!< Specifies whether the memory address register is incremented or not.This parameter can be a value of @ref DMA_memory_incremented_mode */uint32_t DMA_PeripheralDataSize; /*!< Specifies the Peripheral data width.This parameter can be a value of @ref DMA_peripheral_data_size */uint32_t DMA_MemoryDataSize; /*!< Specifies the Memory data width.This parameter can be a value of @ref DMA_memory_data_size */uint32_t DMA_Mode; /*!< Specifies the operation mode of the DMAy Channelx.This parameter can be a value of @ref DMA_circular_normal_mode.@note: The circular buffer mode cannot be used if the memory-to-memorydata transfer is configured on the selected Channel */uint32_t DMA_Priority; /*!< Specifies the software priority for the DMAy Channelx.This parameter can be a value of @ref DMA_priority_level */uint32_t DMA_M2M; /*!< Specifies if the DMAy Channelx will be used in memory-to-memory transfer.This parameter can be a value of @ref DMA_memory_to_memory */
}DMA_InitTypeDef;
DMA初始化结构体主要分为三部分
数据从哪里来,要到哪里去。
uint32_t DMA_PeripheralBaseAddr;uint32_t DMA_MemoryBaseAddr; uint32_t DMA_DIR; uint32_t DMA_M2M;
传输数据的个数,传输数据的大小。
uint32_t DMA_BufferSize; uint32_t DMA_PeripheralInc; uint32_t DMA_MemoryInc; uint32_t DMA_PeripheralDataSize; uint32_t DMA_MemoryDataSize;
什么时候传输结束,以及优先级
uint32_t DMA_Mode; uint32_t DMA_Priority;
当PSIZE和MSIZE不相同时,DMA模块按照下表进行数据对齐。