STM32F10x—DMA总结

各个寄存器作用

1)      DMA_CPARx或DMA_CMARx寄存器指定外设基地址或存储器单元

2)      执行一次DMA_CNDTRx寄存器的递减操作,该寄存器包含未完成的操作数目。

3)      每个通道的优先权可以在DMA_CCRx寄存器中设置,有4个等级

4)      外设和存储器的传输数据量可以通过DMA_CCRx寄存器中的PSIZE和MSIZE位编程。

5)      通过设置DMA_CCRx寄存器中的PINC和MINC标志位,外设和存储器的指针在每次传输后可以有选择地完成自动增量

6)      当传输一半的数据后,半传输标志(HTIF)被置1,当设置了允许半传输中断位(HTIE)时,将产生一个中断请求。在数据传输结束后,传输完成标志(TCIF)被置1,当设置了允许传输完成中断位(TCIE)时,将产生一个中断请求。

7)      当在DMA读写操作时发生DMA传输错误时,硬件会自动地清除发生错误的通道所对应的通道配置寄存器(DMA_CCRx)的EN位,该通道操作被停止。此时,在DMA_IFR寄存器中对应该通道的传输错误中断标志位(TEIF)将被置位,如果在DMA_CCRx寄存器中设置了传输错误中断允许位,则将产生中断。

8)      每个DMA通道都可以在DMA传输过半、传输完成和传输错误时产生中断


9)      DMA1控制器从外设(TIMx[x=1、2、3、4]、ADC1、SPI1、SPI/I2S2、I2Cx[x=1、2]和USARTx[x=1、2、3])产生的7个请求,通过逻辑或输入到DMA1控制器

10)  DMA2控制器从外设(TIMx[5、6、7、8]、ADC3、SPI/I2S3、UART4、DAC通道1、2和SDIO)产生的5个请求,经逻辑或输入到DMA2控制器

 

DMA通道配置过程

配置DMA通道x的过程(x代表通道号): 1. 在DMA_CPARx寄存器中设置外设寄存器的地址。发生外设数据传输请求时,这个地址将是数据传输的源或目标。 2.在DMA_CMARx寄存器中设置数据存储器的地址。发生外设数据传输请求时,传输的数据将从这个地址读出或写入这个地址。 3.在DMA_CNDTRx寄存器中设置要传输的数据量。在每个数据传输后,这个数值递减。 4.在DMA_CCRx寄存器的PL[1:0]位中设置通道的优先级。 5.在DMA_CCRx寄存器中设置数据传输的方向、循环模式、外设和存储器的增量模式、外设和存储器的数据宽度、传输一半产生中断或传输完成产生中断。 6.设置DMA_CCRx寄存器的ENABLE位,启动该通道。

 

 

 

 

 

 

DMA寄存器

1)DMA中断状态寄存器(DMA_ISR)

TEIFx:通道x的传输错误标志(x = 1 … 7) (Channel xtransfer error flag)

HTIFx:通道x的半传输标志(x = 1 … 7) (Channel x halftransfer flag)

TCIFx:通道x的传输完成标志(x = 1 … 7) (Channel xtransfer complete flag)

GIFx:通道x的全局中断标志(x = 1 … 7) (Channel xglobal interrupt flag)

2)DMA中断标志清除寄存器(DMA_IFCR)

CTEIFx:清除通道x的传输错误标志(x = 1 … 7) (Channel xtransfer error clear)

CHTIFx:清除通道x的半传输标志(x = 1 … 7) (Channel x halftransfer clear)

CTCIFx:清除通道x的传输完成标志(x = 1 … 7) (Channel xtransfer complete clear)

CGIFx:清除通道x的全局中断标志(x = 1 … 7) (Channel xglobal interrupt clear)

3)DMA通道x配置寄存器(DMA_CCRx)(x = 1…7)

位14 :MEM2MEM:存储器到存储器模式 (Memory to memory mode)

位13:12 :PL[1:0]:通道优先级 (Channel priority level)

MSIZE[1:0]:存储器数据宽度 (Memory size)

PSIZE[1:0]:外设数据宽度 (Peripheral size)

MINC:存储器地址增量模式 (Memory increment mode)

PINC:外设地址增量模式 (Peripheral increment mode)

CIRC:循环模式 (Circular mode)

DIR:数据传输方向 (Data transfer direction)

TEIE:允许传输错误中断 (Transfer error interruptenable)

HTIE:允许半传输中断 (Half transfer interruptenable)

TCIE:允许传输完成中断 (Transfer complete interruptenable)

EN:通道开启 (Channel enable)

4)DMA通道x传输数量寄存器(DMA_CNDTRx)(x = 1…7)

位15:0 :NDT[15:0]:数据传输数量 (Number of data to transfer)

5)DMA通道x外设地址寄存器(DMA_CPARx)(x = 1…7)

(当开启通道(DMA_CCRx的EN=1)时不能写该寄存器)

PA[31:0]:外设地址 (Peripheral address)

当PSIZE=’01’(16位),不使用PA[0]位。操作自动地与半字地址对齐。 当PSIZE=’10’(32位),不使用PA[1:0]位。操作自动地与字地址对齐。

6)DMA通道x存储器地址寄存器(DMA_CMARx)(x = 1…7)

(当开启通道(DMA_CCRx的EN=1)时不能写该寄存器)

MA[31:0]:存储器地址

 

 

DMA寄存器映像


DMA库函数解析

 

stm32f10x_dma.c

 

#include"stm32f10x_dma.h"

#include"stm32f10x_rcc.h"

#defineDMAy_Channelx_IT_Mask //定义了各个通道的中断mask.

#defineFLAG_Mask   ((uint32_t)0x10000000) // 与DMAy_IT或DMAy_FLAG相与 来判断是DMA1还是DMA2

#defineCCR_CLEAR_Mask //定义了CCR寄存器的清除mask用来在默认设置中清除相应位

 

void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx)

// DMAy_Channelx默认初始化

//复位各个寄存器的,并关DMAy_Channelx中断

 

void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx,DMA_InitTypeDef* DMA_InitStruct)

//检查各个实参正确与否

//将DMAy_Channelx中的MEM2MEM, PL, MSIZE, PSIZE,MINC, PINC, CIRC and DIR清除(CCR_CLEAR_Mask)

//将DMA_InitStruct中的参数“或”到CCR寄存器

//将DMA_InitStruct中的参数写入CNDTR寄存器、CPAR寄存器、CMAR寄存器

 

void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)

//DMA_InitStruct填写默认值,可以快速初始化此结构体

 

void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)

//使能与关闭指令

//先检查两个入口实参是否正确

//然后根据NewState参数 修改NewState

 

void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT,FunctionalState NewState)

//DMA中断配置

//检查入口实参正确性

//3种中断,用DMAy_Channelx->CCR中的3个位来控制开关

 

void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx,uint16_t DataNumber)

//设置DMAy_Channelx传输数量寄存器

//检查入口实参正确性

// DMAy_Channelx->CNDTR = DataNumber

 

uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef*DMAy_Channelx)

//返回DMAy_Channelx传输数量寄存器的值

//检查入口实参正确性

// return ((uint16_t)(DMAy_Channelx->CNDTR));

FlagStatusDMA_GetFlagStatus(uint32_t DMAy_FLAG)

//获取DMAy_FLAG 即:

DMA1_FLAG_GL1: DMA1Channel1 global flag.

DMA1_FLAG_TC1: DMA1Channel1 transfer complete flag.

DMA1_FLAG_HT1: DMA1Channel1 half transfer flag.

DMA1_FLAG_TE1: DMA1Channel1 transfer error flag.

等状态。

//首先验证DMAy_FLAG正确性

//根据DMAy_FLAG& FLAG_Mask 的值来判断相应位的值位0还是1

如DMA1_FLAG_GL1& FLAG_Mask= ((uint32_t)0x00000001) &((uint32_t)0x10000000)

= ((uint32_t)0x00000000) 说明是DMA1的DMAy_FLAG。

如DMA2_FLAG_GL1& FLAG_Mask= ((uint32_t)0x10000001) &((uint32_t)0x10000000)

= ((uint32_t)0x10000000)!=0 说明是DMA2的DMAy_FLAG。

//将DMAy的中断状态寄存器与DMAy_FLAG相与,如果为0则说明相应位为0,

说明状态为RESET,反之为SET。并返回该状态

 

void DMA_ClearFlag(uint32_tDMAy_FLAG)

//清除DMAy_FLAG对应位,

//首先验证DMAy_FLAG正确性

// 根据(DMAy_FLAG & FLAG_Mask)判断是DMA1还是DMA2

//然后将DMAy->IFCR = DMAy_FLAG 清除相应位

 

ITStatus DMA_GetITStatus(uint32_tDMAy_IT)

//判断DMAy Channelx的某种中断是否发生了

DMAy_IT的值类似如下

DMA1_IT_GL1: DMA1 Channel1 global interrupt. ((uint32_t)0x00000001)

DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt. ((uint32_t)0x00000002)

DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt. ((uint32_t)0x00000004)

DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt. ((uint32_t)0x00000008)

//首先验证DMAy_IT正确性

//根据(DMAy_IT & FLAG_Mask)判断是DMA1还是DMA2

// (DMAy->ISR & DMAy_IT)判断对应位的值,从而判断中断发生与否

 

void DMA_ClearITPendingBit(uint32_t DMAy_IT)

//清除DMAy Channelx中断标志

DMAy_IT的值类似如下

DMA1_IT_GL1: DMA1 Channel1 global interrupt. ((uint32_t)0x00000001)

DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt. ((uint32_t)0x00000002)

DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt. ((uint32_t)0x00000004)

DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt. ((uint32_t)0x00000008)

 

//首先验证DMAy_IT正确性

// DMAy_IT & FLAG_Mask来判断DMA1还是DMA2

//DMA1->IFCR = DMAy_IT来清除对应位

 

stm32f10x_dma.h

定义函数原型、结构体、宏定义

//避免重定义

#ifndef __STM32F10x_DMA_H

#define __STM32F10x_DMA_H

#include "stm32f10x.h"

typedef struct

{

 外设地址

存储器地址

方向

数据大小

模式等等

}DMA_InitTypeDef;

#define IS_DMA_ALL_PERIPH(PERIPH)  (((PERIPH) == DMA1_Channel1) || \

                                   ((PERIPH) ==DMA1_Channel2) || \

··········//判断是否为DMA通道(格式检查)

#define DMA_DIR_PeripheralDST              ((uint32_t)0x00000010)//因为DIR在DMA_CCRx第四位

#define DMA_DIR_PeripheralSRC              ((uint32_t)0x00000000)

#define IS_DMA_DIR(DIR) (((DIR)== DMA_DIR_PeripheralDST) || \

                         ((DIR) ==DMA_DIR_PeripheralSRC))//检查DIR参数输入格式

//后面斜体灰字部分与上边验证DIR同理

#defineDMA_PeripheralInc_Enable           ((uint32_t)0x00000040)

#defineDMA_PeripheralInc_Disable         ((uint32_t)0x00000000)

#defineIS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PeripheralInc_Enable) || \

                                           ((STATE) == DMA_PeripheralInc_Disable))

 

#defineDMA_MemoryInc_Enable              ((uint32_t)0x00000080)

#defineDMA_MemoryInc_Disable             ((uint32_t)0x00000000)

#defineIS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MemoryInc_Enable) || \

                                        ((STATE) == DMA_MemoryInc_Disable))

 

#defineDMA_PeripheralDataSize_Byte       ((uint32_t)0x00000000)

#defineDMA_PeripheralDataSize_HalfWord   ((uint32_t)0x00000100)

#defineDMA_PeripheralDataSize_Word       ((uint32_t)0x00000200)

#defineIS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PeripheralDataSize_Byte) || \

                                          ((SIZE) == DMA_PeripheralDataSize_HalfWord) || \

                                          ((SIZE) == DMA_PeripheralDataSize_Word))

 

#define DMA_MemoryDataSize_Byte            ((uint32_t)0x00000000)

#defineDMA_MemoryDataSize_HalfWord       ((uint32_t)0x00000400)

#defineDMA_MemoryDataSize_Word           ((uint32_t)0x00000800)

#defineIS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MemoryDataSize_Byte) || \

                                       ((SIZE)== DMA_MemoryDataSize_HalfWord) || \

                                       ((SIZE)== DMA_MemoryDataSize_Word))

 

#defineDMA_Mode_Circular                 ((uint32_t)0x00000020)

#defineDMA_Mode_Normal                   ((uint32_t)0x00000000)

#defineIS_DMA_MODE(MODE) (((MODE) == DMA_Mode_Circular) || ((MODE) ==DMA_Mode_Normal))

 

#defineDMA_Priority_VeryHigh             ((uint32_t)0x00003000)

#defineDMA_Priority_High                 ((uint32_t)0x00002000)

#defineDMA_Priority_Medium               ((uint32_t)0x00001000)

#defineDMA_Priority_Low                  ((uint32_t)0x00000000)

#defineIS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_Priority_VeryHigh) || \

                                   ((PRIORITY) ==DMA_Priority_High) || \

                                   ((PRIORITY)== DMA_Priority_Medium) || \

                                   ((PRIORITY)== DMA_Priority_Low))

 

#defineDMA_M2M_Enable                     ((uint32_t)0x00004000)

#defineDMA_M2M_Disable                   ((uint32_t)0x00000000)

#defineIS_DMA_M2M_STATE(STATE) (((STATE) == DMA_M2M_Enable) || ((STATE) ==DMA_M2M_Disable))

 

// DMA_ITConfig()函数中中断方式配置

#defineDMA_IT_TC                          ((uint32_t)0x00000002)

#defineDMA_IT_HT                         ((uint32_t)0x00000004)

#defineDMA_IT_TE                         ((uint32_t)0x00000008)

#defineIS_DMA_CONFIG_IT(IT) ((((IT) & 0xFFFFFFF1) == 0x00) && ((IT) !=0x00))

//中断状态寄存器和中断清除寄存器各个位

#define DMA1_IT_GL1                        ((uint32_t)0x00000001)

#define DMA1_IT_TC1                        ((uint32_t)0x00000002)

#define DMA1_IT_HT1                        ((uint32_t)0x00000004)

#define DMA1_IT_TE1                        ((uint32_t)0x00000008)

#define DMA1_IT_GL2                        ((uint32_t)0x00000010)

#define DMA1_IT_TC2                        ((uint32_t)0x00000020)

#define DMA1_IT_HT2                        ((uint32_t)0x00000040)

#define DMA1_IT_TE2                        ((uint32_t)0x00000080)

#define DMA1_IT_GL3                        ((uint32_t)0x00000100)

#define DMA1_IT_TC3                        ((uint32_t)0x00000200)

#define DMA1_IT_HT3                        ((uint32_t)0x00000400)

#define DMA1_IT_TE3                        ((uint32_t)0x00000800)

#define DMA1_IT_GL4                        ((uint32_t)0x00001000)

#define DMA1_IT_TC4                        ((uint32_t)0x00002000)

#define DMA1_IT_HT4                        ((uint32_t)0x00004000)

#define DMA1_IT_TE4                        ((uint32_t)0x00008000)

#define DMA1_IT_GL5                        ((uint32_t)0x00010000)

#define DMA1_IT_TC5                        ((uint32_t)0x00020000)

#define DMA1_IT_HT5                        ((uint32_t)0x00040000)

#define DMA1_IT_TE5                       ((uint32_t)0x00080000)

#define DMA1_IT_GL6                        ((uint32_t)0x00100000)

#define DMA1_IT_TC6                        ((uint32_t)0x00200000)

#define DMA1_IT_HT6                        ((uint32_t)0x00400000)

#define DMA1_IT_TE6                        ((uint32_t)0x00800000)

#define DMA1_IT_GL7                        ((uint32_t)0x01000000)

#define DMA1_IT_TC7                        ((uint32_t)0x02000000)

#define DMA1_IT_HT7                        ((uint32_t)0x04000000)

#define DMA1_IT_TE7                        ((uint32_t)0x08000000)

 

#define DMA2_IT_GL1                        ((uint32_t)0x10000001)

#define DMA2_IT_TC1                        ((uint32_t)0x10000002)

#define DMA2_IT_HT1                        ((uint32_t)0x10000004)

#define DMA2_IT_TE1                        ((uint32_t)0x10000008)

#define DMA2_IT_GL2                        ((uint32_t)0x10000010)

#define DMA2_IT_TC2                        ((uint32_t)0x10000020)

#define DMA2_IT_HT2                        ((uint32_t)0x10000040)

#define DMA2_IT_TE2                        ((uint32_t)0x10000080)

#define DMA2_IT_GL3                        ((uint32_t)0x10000100)

#define DMA2_IT_TC3                        ((uint32_t)0x10000200)

#define DMA2_IT_HT3                        ((uint32_t)0x10000400)

#define DMA2_IT_TE3                        ((uint32_t)0x10000800)

#define DMA2_IT_GL4                        ((uint32_t)0x10001000)

#define DMA2_IT_TC4                        ((uint32_t)0x10002000)

#define DMA2_IT_HT4                        ((uint32_t)0x10004000)

#define DMA2_IT_TE4                        ((uint32_t)0x10008000)

#define DMA2_IT_GL5                        ((uint32_t)0x10010000)

#define DMA2_IT_TC5                        ((uint32_t)0x10020000)

#define DMA2_IT_HT5                       ((uint32_t)0x10040000)

#define DMA2_IT_TE5                        ((uint32_t)0x10080000)

// DMA_ClearITPendingBit函数中判断DMAy_IT是否格式正确——IT最高4位为0000或者0001并且IT不等于0——函数值的值是可以或组合,达到同时清除的目的。

#define IS_DMA_CLEAR_IT(IT) (((((IT) & 0xF0000000)== 0x00) || (((IT) & 0xEFF00000) == 0x00)) && ((IT) != 0x00))

 

//判断格式

#define IS_DMA_GET_IT(IT) (((IT) == DMA1_IT_GL1) ||((IT) == DMA1_IT_TC1) || \

                           ((IT) ==DMA1_IT_HT1) || ((IT) == DMA1_IT_TE1) || \

                           ((IT) ==DMA1_IT_GL2) || ((IT) == DMA1_IT_TC2) || \

                           ((IT) ==DMA1_IT_HT2) || ((IT) == DMA1_IT_TE2) || \

                           ((IT) ==DMA1_IT_GL3) || ((IT) == DMA1_IT_TC3) || \

                          ((IT) == DMA1_IT_HT3) ||((IT) == DMA1_IT_TE3) || \

                           ((IT) ==DMA1_IT_GL4) || ((IT) == DMA1_IT_TC4) || \

                           ((IT) ==DMA1_IT_HT4) || ((IT) == DMA1_IT_TE4) || \

                           ((IT) ==DMA1_IT_GL5) || ((IT) == DMA1_IT_TC5) || \

                           ((IT) ==DMA1_IT_HT5) || ((IT) == DMA1_IT_TE5) || \

                           ((IT) ==DMA1_IT_GL6) || ((IT) == DMA1_IT_TC6) || \

                          ((IT) == DMA1_IT_HT6) ||((IT) == DMA1_IT_TE6) || \

                           ((IT) ==DMA1_IT_GL7) || ((IT) == DMA1_IT_TC7) || \

                           ((IT) ==DMA1_IT_HT7) || ((IT) == DMA1_IT_TE7) || \

                           ((IT) == DMA2_IT_GL1)|| ((IT) == DMA2_IT_TC1) || \

                           ((IT) ==DMA2_IT_HT1) || ((IT) == DMA2_IT_TE1) || \

                           ((IT) ==DMA2_IT_GL2) || ((IT) == DMA2_IT_TC2) || \

                           ((IT) ==DMA2_IT_HT2) || ((IT) == DMA2_IT_TE2) || \

                           ((IT) ==DMA2_IT_GL3) || ((IT) == DMA2_IT_TC3) || \

                           ((IT) ==DMA2_IT_HT3) || ((IT) == DMA2_IT_TE3) || \

                           ((IT) ==DMA2_IT_GL4) || ((IT) == DMA2_IT_TC4) || \

                           ((IT) ==DMA2_IT_HT4) || ((IT) == DMA2_IT_TE4) || \

                           ((IT) ==DMA2_IT_GL5) || ((IT) == DMA2_IT_TC5) || \

                           ((IT) ==DMA2_IT_HT5) || ((IT) == DMA2_IT_TE5))

//中断状态位

#define DMA1_FLAG_GL1                      ((uint32_t)0x00000001)

#define DMA1_FLAG_TC1                      ((uint32_t)0x00000002)

#define DMA1_FLAG_HT1                      ((uint32_t)0x00000004)

#define DMA1_FLAG_TE1                      ((uint32_t)0x00000008)

#define DMA1_FLAG_GL2                      ((uint32_t)0x00000010)

#define DMA1_FLAG_TC2                      ((uint32_t)0x00000020)

#define DMA1_FLAG_HT2                      ((uint32_t)0x00000040)

#define DMA1_FLAG_TE2                      ((uint32_t)0x00000080)

#define DMA1_FLAG_GL3                      ((uint32_t)0x00000100)

#define DMA1_FLAG_TC3                      ((uint32_t)0x00000200)

#define DMA1_FLAG_HT3                      ((uint32_t)0x00000400)

#define DMA1_FLAG_TE3                      ((uint32_t)0x00000800)

#define DMA1_FLAG_GL4                      ((uint32_t)0x00001000)

#define DMA1_FLAG_TC4                      ((uint32_t)0x00002000)

#define DMA1_FLAG_HT4                      ((uint32_t)0x00004000)

#define DMA1_FLAG_TE4                      ((uint32_t)0x00008000)

#define DMA1_FLAG_GL5                      ((uint32_t)0x00010000)

#define DMA1_FLAG_TC5                      ((uint32_t)0x00020000)

#define DMA1_FLAG_HT5                      ((uint32_t)0x00040000)

#define DMA1_FLAG_TE5                      ((uint32_t)0x00080000)

#define DMA1_FLAG_GL6                      ((uint32_t)0x00100000)

#define DMA1_FLAG_TC6                      ((uint32_t)0x00200000)

#define DMA1_FLAG_HT6                      ((uint32_t)0x00400000)

#define DMA1_FLAG_TE6                      ((uint32_t)0x00800000)

#define DMA1_FLAG_GL7                      ((uint32_t)0x01000000)

#define DMA1_FLAG_TC7                      ((uint32_t)0x02000000)

#define DMA1_FLAG_HT7                      ((uint32_t)0x04000000)

#define DMA1_FLAG_TE7                      ((uint32_t)0x08000000)

 

#define DMA2_FLAG_GL1                      ((uint32_t)0x10000001)

#define DMA2_FLAG_TC1                      ((uint32_t)0x10000002)

#define DMA2_FLAG_HT1                      ((uint32_t)0x10000004)

#define DMA2_FLAG_TE1                      ((uint32_t)0x10000008)

#define DMA2_FLAG_GL2                      ((uint32_t)0x10000010)

#define DMA2_FLAG_TC2                      ((uint32_t)0x10000020)

#define DMA2_FLAG_HT2                      ((uint32_t)0x10000040)

#define DMA2_FLAG_TE2                      ((uint32_t)0x10000080)

#define DMA2_FLAG_GL3                      ((uint32_t)0x10000100)

#define DMA2_FLAG_TC3                      ((uint32_t)0x10000200)

#define DMA2_FLAG_HT3                      ((uint32_t)0x10000400)

#define DMA2_FLAG_TE3                      ((uint32_t)0x10000800)

#define DMA2_FLAG_GL4                      ((uint32_t)0x10001000)

#define DMA2_FLAG_TC4                      ((uint32_t)0x10002000)

#define DMA2_FLAG_HT4                      ((uint32_t)0x10004000)

#define DMA2_FLAG_TE4                      ((uint32_t)0x10008000)

#define DMA2_FLAG_GL5                      ((uint32_t)0x10010000)

#define DMA2_FLAG_TC5                      ((uint32_t)0x10020000)

#define DMA2_FLAG_HT5                      ((uint32_t)0x10040000)

#define DMA2_FLAG_TE5                      ((uint32_t)0x10080000)

//同上:#define IS_DMA_CLEAR_IT(IT)中的定义——是否格式正确——IT最高4位为0000或者0001并且IT不等于0——函数值的值是可以或组合,达到同时清除的目的。

#define IS_DMA_CLEAR_FLAG(FLAG) (((((FLAG) &0xF0000000) == 0x00) || (((FLAG) & 0xEFF00000) == 0x00)) && ((FLAG)!= 0x00))

//格式检查

#define IS_DMA_GET_FLAG(FLAG) (((FLAG) ==DMA1_FLAG_GL1) || ((FLAG) == DMA1_FLAG_TC1) || \

                               ((FLAG) ==DMA1_FLAG_HT1) || ((FLAG) == DMA1_FLAG_TE1) || \

                               ((FLAG) ==DMA1_FLAG_GL2) || ((FLAG) == DMA1_FLAG_TC2) || \

                               ((FLAG) ==DMA1_FLAG_HT2) || ((FLAG) == DMA1_FLAG_TE2) || \

                               ((FLAG) ==DMA1_FLAG_GL3) || ((FLAG) == DMA1_FLAG_TC3) || \

                               ((FLAG) ==DMA1_FLAG_HT3) || ((FLAG) == DMA1_FLAG_TE3) || \

                               ((FLAG) ==DMA1_FLAG_GL4) || ((FLAG) == DMA1_FLAG_TC4) || \

                               ((FLAG) ==DMA1_FLAG_HT4) || ((FLAG) == DMA1_FLAG_TE4) || \

                               ((FLAG) ==DMA1_FLAG_GL5) || ((FLAG) == DMA1_FLAG_TC5) || \

                               ((FLAG) ==DMA1_FLAG_HT5) || ((FLAG) == DMA1_FLAG_TE5) || \

                               ((FLAG) ==DMA1_FLAG_GL6) || ((FLAG) == DMA1_FLAG_TC6) || \

                               ((FLAG) ==DMA1_FLAG_HT6) || ((FLAG) == DMA1_FLAG_TE6) || \

                               ((FLAG) ==DMA1_FLAG_GL7) || ((FLAG) == DMA1_FLAG_TC7) || \

                              ((FLAG) == DMA1_FLAG_HT7)|| ((FLAG) == DMA1_FLAG_TE7) || \

                               ((FLAG) ==DMA2_FLAG_GL1) || ((FLAG) == DMA2_FLAG_TC1) || \

                               ((FLAG) ==DMA2_FLAG_HT1) || ((FLAG) == DMA2_FLAG_TE1) || \

                               ((FLAG) ==DMA2_FLAG_GL2) || ((FLAG) == DMA2_FLAG_TC2) || \

                               ((FLAG) ==DMA2_FLAG_HT2) || ((FLAG) == DMA2_FLAG_TE2) || \

                               ((FLAG) ==DMA2_FLAG_GL3) || ((FLAG) == DMA2_FLAG_TC3) || \

                               ((FLAG) ==DMA2_FLAG_HT3) || ((FLAG) == DMA2_FLAG_TE3) || \

                               ((FLAG) ==DMA2_FLAG_GL4) || ((FLAG) == DMA2_FLAG_TC4) || \

                               ((FLAG) ==DMA2_FLAG_HT4) || ((FLAG) == DMA2_FLAG_TE4) || \

                               ((FLAG) ==DMA2_FLAG_GL5) || ((FLAG) == DMA2_FLAG_TC5) || \

                               ((FLAG) ==DMA2_FLAG_HT5) || ((FLAG) == DMA2_FLAG_TE5))

//SIZE大小检查

#define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1)&& ((SIZE) < 0x10000))

//函数声明

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);

你可能感兴趣的:(杂七杂八-stage,1)