18 #ifndef __STM32F10x_DMA_H
19 #define __STM32F10x_DMA_H
22 #include "stm32f10x_map.h"
28 u32 DMA_PeripheralBaseAddr;
29 u32 DMA_MemoryBaseAddr;
32 u32 DMA_PeripheralInc;
34 u32 DMA_PeripheralDataSize;
35 u32 DMA_MemoryDataSize;
42 #define IS_DMA_ALL_PERIPH(PERIPH) (((*(u32*)&(PERIPH)) == DMA1_Channel1_BASE) || \
43 ((*(u32*)&(PERIPH)) == DMA1_Channel2_BASE) || \
44 ((*(u32*)&(PERIPH)) == DMA1_Channel3_BASE) || \
45 ((*(u32*)&(PERIPH)) == DMA1_Channel4_BASE) || \
46 ((*(u32*)&(PERIPH)) == DMA1_Channel5_BASE) || \
47 ((*(u32*)&(PERIPH)) == DMA1_Channel6_BASE) || \
48 ((*(u32*)&(PERIPH)) == DMA1_Channel7_BASE) || \
49 ((*(u32*)&(PERIPH)) == DMA2_Channel1_BASE) || \
50 ((*(u32*)&(PERIPH)) == DMA2_Channel2_BASE) || \
51 ((*(u32*)&(PERIPH)) == DMA2_Channel3_BASE) || \
52 ((*(u32*)&(PERIPH)) == DMA2_Channel4_BASE) || \
53 ((*(u32*)&(PERIPH)) == DMA2_Channel5_BASE))
56 #define DMA_DIR_PeripheralDST ((u32)0x00000010)
57 #define DMA_DIR_PeripheralSRC ((u32)0x00000000)
59 #define IS_DMA_DIR(DIR) (((DIR) == DMA_DIR_PeripheralDST) || \
60 ((DIR) == DMA_DIR_PeripheralSRC))
63 #define DMA_PeripheralInc_Enable ((u32)0x00000040)
64 #define DMA_PeripheralInc_Disable ((u32)0x00000000)
66 #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PeripheralInc_Enable) || \
67 ((STATE) == DMA_PeripheralInc_Disable))
70 #define DMA_MemoryInc_Enable ((u32)0x00000080)
71 #define DMA_MemoryInc_Disable ((u32)0x00000000)
73 #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MemoryInc_Enable) || \
74 ((STATE) == DMA_MemoryInc_Disable))
77 #define DMA_PeripheralDataSize_Byte ((u32)0x00000000)
78 #define DMA_PeripheralDataSize_HalfWord ((u32)0x00000100)
79 #define DMA_PeripheralDataSize_Word ((u32)0x00000200)
81 #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PeripheralDataSize_Byte) || \
82 ((SIZE) == DMA_PeripheralDataSize_HalfWord) || \
83 ((SIZE) == DMA_PeripheralDataSize_Word))
86 #define DMA_MemoryDataSize_Byte ((u32)0x00000000)
87 #define DMA_MemoryDataSize_HalfWord ((u32)0x00000400)
88 #define DMA_MemoryDataSize_Word ((u32)0x00000800)
90 #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MemoryDataSize_Byte) || \
91 ((SIZE) == DMA_MemoryDataSize_HalfWord) || \
92 ((SIZE) == DMA_MemoryDataSize_Word))
95 #define DMA_Mode_Circular ((u32)0x00000020)
96 #define DMA_Mode_Normal ((u32)0x00000000)
98 #define IS_DMA_MODE(MODE) (((MODE) == DMA_Mode_Circular) || ((MODE) == DMA_Mode_Normal))
101 #define DMA_Priority_VeryHigh ((u32)0x00003000)
102 #define DMA_Priority_High ((u32)0x00002000)
103 #define DMA_Priority_Medium ((u32)0x00001000)
104 #define DMA_Priority_Low ((u32)0x00000000)
106 #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_Priority_VeryHigh) || \
107 ((PRIORITY) == DMA_Priority_High) || \
108 ((PRIORITY) == DMA_Priority_Medium) || \
109 ((PRIORITY) == DMA_Priority_Low))
112 #define DMA_M2M_Enable ((u32)0x00004000)
113 #define DMA_M2M_Disable ((u32)0x00000000)
115 #define IS_DMA_M2M_STATE(STATE) (((STATE) == DMA_M2M_Enable) || ((STATE) == DMA_M2M_Disable))
118 #define DMA_IT_TC ((u32)0x00000002)
119 #define DMA_IT_HT ((u32)0x00000004)
120 #define DMA_IT_TE ((u32)0x00000008)
122 #define IS_DMA_CONFIG_IT(IT) ((((IT) & 0xFFFFFFF1) == 0x00) && ((IT) != 0x00))
125 #define DMA1_IT_GL1 ((u32)0x00000001)
126 #define DMA1_IT_TC1 ((u32)0x00000002)
127 #define DMA1_IT_HT1 ((u32)0x00000004)
128 #define DMA1_IT_TE1 ((u32)0x00000008)
129 #define DMA1_IT_GL2 ((u32)0x00000010)
130 #define DMA1_IT_TC2 ((u32)0x00000020)
131 #define DMA1_IT_HT2 ((u32)0x00000040)
132 #define DMA1_IT_TE2 ((u32)0x00000080)
133 #define DMA1_IT_GL3 ((u32)0x00000100)
134 #define DMA1_IT_TC3 ((u32)0x00000200)
135 #define DMA1_IT_HT3 ((u32)0x00000400)
136 #define DMA1_IT_TE3 ((u32)0x00000800)
137 #define DMA1_IT_GL4 ((u32)0x00001000)
138 #define DMA1_IT_TC4 ((u32)0x00002000)
139 #define DMA1_IT_HT4 ((u32)0x00004000)
140 #define DMA1_IT_TE4 ((u32)0x00008000)
141 #define DMA1_IT_GL5 ((u32)0x00010000)
142 #define DMA1_IT_TC5 ((u32)0x00020000)
143 #define DMA1_IT_HT5 ((u32)0x00040000)
144 #define DMA1_IT_TE5 ((u32)0x00080000)
145 #define DMA1_IT_GL6 ((u32)0x00100000)
146 #define DMA1_IT_TC6 ((u32)0x00200000)
147 #define DMA1_IT_HT6 ((u32)0x00400000)
148 #define DMA1_IT_TE6 ((u32)0x00800000)
149 #define DMA1_IT_GL7 ((u32)0x01000000)
150 #define DMA1_IT_TC7 ((u32)0x02000000)
151 #define DMA1_IT_HT7 ((u32)0x04000000)
152 #define DMA1_IT_TE7 ((u32)0x08000000)
154 #define DMA2_IT_GL1 ((u32)0x10000001)
155 #define DMA2_IT_TC1 ((u32)0x10000002)
156 #define DMA2_IT_HT1 ((u32)0x10000004)
157 #define DMA2_IT_TE1 ((u32)0x10000008)
158 #define DMA2_IT_GL2 ((u32)0x10000010)
159 #define DMA2_IT_TC2 ((u32)0x10000020)
160 #define DMA2_IT_HT2 ((u32)0x10000040)
161 #define DMA2_IT_TE2 ((u32)0x10000080)
162 #define DMA2_IT_GL3 ((u32)0x10000100)
163 #define DMA2_IT_TC3 ((u32)0x10000200)
164 #define DMA2_IT_HT3 ((u32)0x10000400)
165 #define DMA2_IT_TE3 ((u32)0x10000800)
166 #define DMA2_IT_GL4 ((u32)0x10001000)
167 #define DMA2_IT_TC4 ((u32)0x10002000)
168 #define DMA2_IT_HT4 ((u32)0x10004000)
169 #define DMA2_IT_TE4 ((u32)0x10008000)
170 #define DMA2_IT_GL5 ((u32)0x10010000)
171 #define DMA2_IT_TC5 ((u32)0x10020000)
172 #define DMA2_IT_HT5 ((u32)0x10040000)
173 #define DMA2_IT_TE5 ((u32)0x10080000)
175 #define IS_DMA_CLEAR_IT(IT) (((((IT) & 0xF0000000) == 0x00) || (((IT) & 0xEFF00000) == 0x00)) && ((IT) != 0x00))
176 #define IS_DMA_GET_IT(IT) (((IT) == DMA1_IT_GL1) || ((IT) == DMA1_IT_TC1) || \
177 ((IT) == DMA1_IT_HT1) || ((IT) == DMA1_IT_TE1) || \
178 ((IT) == DMA1_IT_GL2) || ((IT) == DMA1_IT_TC2) || \
179 ((IT) == DMA1_IT_HT2) || ((IT) == DMA1_IT_TE2) || \
180 ((IT) == DMA1_IT_GL3) || ((IT) == DMA1_IT_TC3) || \
181 ((IT) == DMA1_IT_HT3) || ((IT) == DMA1_IT_TE3) || \
182 ((IT) == DMA1_IT_GL4) || ((IT) == DMA1_IT_TC4) || \
183 ((IT) == DMA1_IT_HT4) || ((IT) == DMA1_IT_TE4) || \
184 ((IT) == DMA1_IT_GL5) || ((IT) == DMA1_IT_TC5) || \
185 ((IT) == DMA1_IT_HT5) || ((IT) == DMA1_IT_TE5) || \
186 ((IT) == DMA1_IT_GL6) || ((IT) == DMA1_IT_TC6) || \
187 ((IT) == DMA1_IT_HT6) || ((IT) == DMA1_IT_TE6) || \
188 ((IT) == DMA1_IT_GL7) || ((IT) == DMA1_IT_TC7) || \
189 ((IT) == DMA1_IT_HT7) || ((IT) == DMA1_IT_TE7) || \
190 ((IT) == DMA2_IT_GL1) || ((IT) == DMA2_IT_TC1) || \
191 ((IT) == DMA2_IT_HT1) || ((IT) == DMA2_IT_TE1) || \
192 ((IT) == DMA2_IT_GL2) || ((IT) == DMA2_IT_TC2) || \
193 ((IT) == DMA2_IT_HT2) || ((IT) == DMA2_IT_TE2) || \
194 ((IT) == DMA2_IT_GL3) || ((IT) == DMA2_IT_TC3) || \
195 ((IT) == DMA2_IT_HT3) || ((IT) == DMA2_IT_TE3) || \
196 ((IT) == DMA2_IT_GL4) || ((IT) == DMA2_IT_TC4) || \
197 ((IT) == DMA2_IT_HT4) || ((IT) == DMA2_IT_TE4) || \
198 ((IT) == DMA2_IT_GL5) || ((IT) == DMA2_IT_TC5) || \
199 ((IT) == DMA2_IT_HT5) || ((IT) == DMA2_IT_TE5))
203 #define DMA1_FLAG_GL1 ((u32)0x00000001)
204 #define DMA1_FLAG_TC1 ((u32)0x00000002)
205 #define DMA1_FLAG_HT1 ((u32)0x00000004)
206 #define DMA1_FLAG_TE1 ((u32)0x00000008)
207 #define DMA1_FLAG_GL2 ((u32)0x00000010)
208 #define DMA1_FLAG_TC2 ((u32)0x00000020)
209 #define DMA1_FLAG_HT2 ((u32)0x00000040)
210 #define DMA1_FLAG_TE2 ((u32)0x00000080)
211 #define DMA1_FLAG_GL3 ((u32)0x00000100)
212 #define DMA1_FLAG_TC3 ((u32)0x00000200)
213 #define DMA1_FLAG_HT3 ((u32)0x00000400)
214 #define DMA1_FLAG_TE3 ((u32)0x00000800)
215 #define DMA1_FLAG_GL4 ((u32)0x00001000)
216 #define DMA1_FLAG_TC4 ((u32)0x00002000)
217 #define DMA1_FLAG_HT4 ((u32)0x00004000)
218 #define DMA1_FLAG_TE4 ((u32)0x00008000)
219 #define DMA1_FLAG_GL5 ((u32)0x00010000)
220 #define DMA1_FLAG_TC5 ((u32)0x00020000)
221 #define DMA1_FLAG_HT5 ((u32)0x00040000)
222 #define DMA1_FLAG_TE5 ((u32)0x00080000)
223 #define DMA1_FLAG_GL6 ((u32)0x00100000)
224 #define DMA1_FLAG_TC6 ((u32)0x00200000)
225 #define DMA1_FLAG_HT6 ((u32)0x00400000)
226 #define DMA1_FLAG_TE6 ((u32)0x00800000)
227 #define DMA1_FLAG_GL7 ((u32)0x01000000)
228 #define DMA1_FLAG_TC7 ((u32)0x02000000)
229 #define DMA1_FLAG_HT7 ((u32)0x04000000)
230 #define DMA1_FLAG_TE7 ((u32)0x08000000)
232 #define DMA2_FLAG_GL1 ((u32)0x10000001)
233 #define DMA2_FLAG_TC1 ((u32)0x10000002)
234 #define DMA2_FLAG_HT1 ((u32)0x10000004)
235 #define DMA2_FLAG_TE1 ((u32)0x10000008)
236 #define DMA2_FLAG_GL2 ((u32)0x10000010)
237 #define DMA2_FLAG_TC2 ((u32)0x10000020)
238 #define DMA2_FLAG_HT2 ((u32)0x10000040)
239 #define DMA2_FLAG_TE2 ((u32)0x10000080)
240 #define DMA2_FLAG_GL3 ((u32)0x10000100)
241 #define DMA2_FLAG_TC3 ((u32)0x10000200)
242 #define DMA2_FLAG_HT3 ((u32)0x10000400)
243 #define DMA2_FLAG_TE3 ((u32)0x10000800)
244 #define DMA2_FLAG_GL4 ((u32)0x10001000)
245 #define DMA2_FLAG_TC4 ((u32)0x10002000)
246 #define DMA2_FLAG_HT4 ((u32)0x10004000)
247 #define DMA2_FLAG_TE4 ((u32)0x10008000)
248 #define DMA2_FLAG_GL5 ((u32)0x10010000)
249 #define DMA2_FLAG_TC5 ((u32)0x10020000)
250 #define DMA2_FLAG_HT5 ((u32)0x10040000)
251 #define DMA2_FLAG_TE5 ((u32)0x10080000)
253 #define IS_DMA_CLEAR_FLAG(FLAG) (((((FLAG) & 0xF0000000) == 0x00) || (((FLAG) & 0xEFF00000) == 0x00)) && ((FLAG) != 0x00))
254 #define IS_DMA_GET_FLAG(FLAG) (((FLAG) == DMA1_FLAG_GL1) || ((FLAG) == DMA1_FLAG_TC1) || \
255 ((FLAG) == DMA1_FLAG_HT1) || ((FLAG) == DMA1_FLAG_TE1) || \
256 ((FLAG) == DMA1_FLAG_GL2) || ((FLAG) == DMA1_FLAG_TC2) || \
257 ((FLAG) == DMA1_FLAG_HT2) || ((FLAG) == DMA1_FLAG_TE2) || \
258 ((FLAG) == DMA1_FLAG_GL3) || ((FLAG) == DMA1_FLAG_TC3) || \
259 ((FLAG) == DMA1_FLAG_HT3) || ((FLAG) == DMA1_FLAG_TE3) || \
260 ((FLAG) == DMA1_FLAG_GL4) || ((FLAG) == DMA1_FLAG_TC4) || \
261 ((FLAG) == DMA1_FLAG_HT4) || ((FLAG) == DMA1_FLAG_TE4) || \
262 ((FLAG) == DMA1_FLAG_GL5) || ((FLAG) == DMA1_FLAG_TC5) || \
263 ((FLAG) == DMA1_FLAG_HT5) || ((FLAG) == DMA1_FLAG_TE5) || \
264 ((FLAG) == DMA1_FLAG_GL6) || ((FLAG) == DMA1_FLAG_TC6) || \
265 ((FLAG) == DMA1_FLAG_HT6) || ((FLAG) == DMA1_FLAG_TE6) || \
266 ((FLAG) == DMA1_FLAG_GL7) || ((FLAG) == DMA1_FLAG_TC7) || \
267 ((FLAG) == DMA1_FLAG_HT7) || ((FLAG) == DMA1_FLAG_TE7) || \
268 ((FLAG) == DMA2_FLAG_GL1) || ((FLAG) == DMA2_FLAG_TC1) || \
269 ((FLAG) == DMA2_FLAG_HT1) || ((FLAG) == DMA2_FLAG_TE1) || \
270 ((FLAG) == DMA2_FLAG_GL2) || ((FLAG) == DMA2_FLAG_TC2) || \
271 ((FLAG) == DMA2_FLAG_HT2) || ((FLAG) == DMA2_FLAG_TE2) || \
272 ((FLAG) == DMA2_FLAG_GL3) || ((FLAG) == DMA2_FLAG_TC3) || \
273 ((FLAG) == DMA2_FLAG_HT3) || ((FLAG) == DMA2_FLAG_TE3) || \
274 ((FLAG) == DMA2_FLAG_GL4) || ((FLAG) == DMA2_FLAG_TC4) || \
275 ((FLAG) == DMA2_FLAG_HT4) || ((FLAG) == DMA2_FLAG_TE4) || \
276 ((FLAG) == DMA2_FLAG_GL5) || ((FLAG) == DMA2_FLAG_TC5) || \
277 ((FLAG) == DMA2_FLAG_HT5) || ((FLAG) == DMA2_FLAG_TE5))
280 #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000))
284 void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx);
285 void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct);
286 void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct);
287 void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState);
288 void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, u32 DMA_IT, FunctionalState NewState);
289 u16 DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx);
290 FlagStatus DMA_GetFlagStatus(u32 DMA_FLAG);
291 void DMA_ClearFlag(u32 DMA_FLAG);
292 ITStatus DMA_GetITStatus(u32 DMA_IT);
293 void DMA_ClearITPendingBit(u32 DMA_IT);