简介 DMA: Data Memory Access,直接存储器访问。 主要功能是可以把数据从一个地方搬到另外一个地方,而且不占用CPU。不用CPU暂存数据 DMA1: 有7个通道,可以实现 P->M, M->P,M->M DMA2: 有7个通道,可以实现 P->M, M->P,M->M M:Memery P:Peripheral P->M:ADC
DMA功能框图 1-DMA请求 2-通道 3-仲裁器 仲裁器 多个DMA请求一起来,怎么办? 1、软件阶段, DMA_CCRx: PL[1:0]。00/01/10/11 2、硬件阶段,通道编号小的优先级大, DM1的优先级高于DMA2的优先级。
DMA结构体:
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_PeripheralDataSize or 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-memory data 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 */ //memory to memory 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;固件库函数
void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx); void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct); void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct); void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState); void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState); void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber); uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx); FlagStatus DMA_GetFlagStatus(uint32_t DMAy_FLAG); void DMA_ClearFlag(uint32_t DMAy_FLAG); ITStatus DMA_GetITStatus(uint32_t DMAy_IT); void DMA_ClearITPendingBit(uint32_t DMAy_IT);*下一节开始编程。