以USART为例子来使用DMA分两部分,第一为,DMA这个外设自身的配置;第二为,USART的DMA部分配置,
DMA与USART的DMA配置
[cpp] view plain copy
- void SYS_DMA_Init(void)
- {
- CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);</span> //打开时钟,很重要
- /* Deinitialize DMA channels */
- DMA_GlobalDeInit();
-
- DMA_DeInit(DMA1_Channel1);
- DMA_DeInit(DMA1_Channel2);
-
- /* DMA channel Rx of USART Configuration */
- //该函数主要要配置好接受的数组,以及USART的数据寄存器地址,数组大小,以及DMA模式
- DMA_Init(DMA1_Channel2, (uint16_t)RxBuffer, (uint16_t)0x5231, \
- 10, DMA_DIR_PeripheralToMemory, DMA_Mode_Normal, \
- DMA_MemoryIncMode_Inc, DMA_Priority_Low, DMA_MemoryDataSize_Byte);
-
- /* DMA channel Tx of USART Configuration */
- //该函数主要配置发送数组,以及USART的数据寄存器地址,数组大小,以及DMA模式
- DMA_Init(DMA1_Channel1, (uint16_t)TxBuffer, (uint16_t)0x5231, \
- 60, DMA_DIR_MemoryToPeripheral, DMA_Mode_Normal, \
- DMA_MemoryIncMode_Inc, DMA_Priority_High, DMA_MemoryDataSize_Byte);
-
- /* Enable the USART Tx/Rx DMA requests */
- USART_DMACmd(USART1, USART_DMAReq_TX, ENABLE);
- USART_DMACmd(USART1, USART_DMAReq_RX, ENABLE);
-
- /* Global DMA Enable */
- DMA_GlobalCmd(ENABLE);
-
- /* Enable the USART Tx DMA channel */
- DMA_Cmd(DMA1_Channel1, ENABLE);
- /* Enable the USART Rx DMA channel */
- DMA_Cmd(DMA1_Channel2, ENABLE);
- }
下面主要对void DMA_Init(DMA_Channel_TypeDef* DMA_Channelx,
uint32_t DMA_Memory0BaseAddr,
uint16_t DMA_PeripheralMemory1BaseAddr,
uint8_t DMA_BufferSize,
DMA_DIR_TypeDef DMA_DIR,
DMA_Mode_TypeDef DMA_Mode,
DMA_MemoryIncMode_TypeDef DMA_MemoryIncMode,
DMA_Priority_TypeDef DMA_Priority,
DMA_MemoryDataSize_TypeDef DMA_MemoryDataSize )
|