1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
102
103
107
108
109
110
118
119
128
129
132
133
134
135
136
139
140
141
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
170
171
172
173
174
175
176
177
181
182
183
184
185
186
187
188
189
190
191
192
193
195
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
309
310
311
312
313
314
318
319
320
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
580
581
582
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
627
628
629
634
635
636
641
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
736
737
738
739
740
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
826
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
861
862
863
864
865
866
867
868
869
870
871
875
876
877
878
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
940
941
942
943
944
945
946
947
948
949
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
983
987
991
995
999
1003
1007
1008
1009
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1044
1048
1052
1056
1060
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1076
1077
1078
1082
1083
1084
1085
1086
1087
1088
1089
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1114
1118
1119
1125
1129
1130
1133
1134
1137
1138
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1185
1186
1187
1188
1189
1190
1191
1192
1193
1198
1203
1204
1205
1206
1207
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1230
1236
1238
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1252
1258
1264
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1279
1285
1287
1288
1289
1290
1291
1292
1293
1296
1297
1298
1301
1302
1305
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
/* ... */
#ifdef HAL_DMA_MODULE_ENABLED
typedef struct
{
__IO uint32_t ISR;
__IO uint32_t Reserved0;
__IO uint32_t IFCR;
...} DMA_Base_Registers;
Private types
/* ... */
#define HAL_TIMEOUT_DMA_ABORT 5U
/* ... */
Private constants
/* ... */
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
static uint32_t DMA_CalcBaseAndBitshift(DMA_HandleTypeDef *hdma);
static HAL_StatusTypeDef DMA_CheckFifoParam(DMA_HandleTypeDef *hdma);
/* ... */
Private functions
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
{
uint32_t tmp = 0U;
uint32_t tickstart = HAL_GetTick();
DMA_Base_Registers *regs;
if(hdma == NULL)
{
return HAL_ERROR;
}if (hdma == NULL) { ... }
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
assert_param(IS_DMA_CHANNEL(hdma->Init.Channel));
assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
assert_param(IS_DMA_MODE(hdma->Init.Mode));
assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
assert_param(IS_DMA_FIFO_MODE_STATE(hdma->Init.FIFOMode));
/* ... */
if(hdma->Init.FIFOMode != DMA_FIFOMODE_DISABLE)
{
assert_param(IS_DMA_FIFO_THRESHOLD(hdma->Init.FIFOThreshold));
assert_param(IS_DMA_MEMORY_BURST(hdma->Init.MemBurst));
assert_param(IS_DMA_PERIPHERAL_BURST(hdma->Init.PeriphBurst));
}if (hdma->Init.FIFOMode != DMA_FIFOMODE_DISABLE) { ... }
hdma->State = HAL_DMA_STATE_BUSY;
__HAL_UNLOCK(hdma);
__HAL_DMA_DISABLE(hdma);
while((hdma->Instance->CR & DMA_SxCR_EN) != RESET)
{
if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT)
{
hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT;
hdma->State = HAL_DMA_STATE_TIMEOUT;
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT) { ... }
}while ((hdma->Instance->CR & DMA_SxCR_EN) != RESET) { ... }
tmp = hdma->Instance->CR;
tmp &= ((uint32_t)~(DMA_SxCR_CHSEL | DMA_SxCR_MBURST | DMA_SxCR_PBURST | \
DMA_SxCR_PL | DMA_SxCR_MSIZE | DMA_SxCR_PSIZE | \
DMA_SxCR_MINC | DMA_SxCR_PINC | DMA_SxCR_CIRC | \
DMA_SxCR_DIR | DMA_SxCR_CT | DMA_SxCR_DBM));
tmp |= hdma->Init.Channel | hdma->Init.Direction |
hdma->Init.PeriphInc | hdma->Init.MemInc |
hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
hdma->Init.Mode | hdma->Init.Priority;
if(hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE)
{
tmp |= hdma->Init.MemBurst | hdma->Init.PeriphBurst;
}if (hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE) { ... }
hdma->Instance->CR = tmp;
tmp = hdma->Instance->FCR;
tmp &= (uint32_t)~(DMA_SxFCR_DMDIS | DMA_SxFCR_FTH);
tmp |= hdma->Init.FIFOMode;
if(hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE)
{
tmp |= hdma->Init.FIFOThreshold;
if (hdma->Init.MemBurst != DMA_MBURST_SINGLE)
{
if (DMA_CheckFifoParam(hdma) != HAL_OK)
{
hdma->ErrorCode = HAL_DMA_ERROR_PARAM;
hdma->State = HAL_DMA_STATE_READY;
return HAL_ERROR;
}if (DMA_CheckFifoParam(hdma) != HAL_OK) { ... }
}if (hdma->Init.MemBurst != DMA_MBURST_SINGLE) { ... }
}if (hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE) { ... }
hdma->Instance->FCR = tmp;
/* ... */
regs = (DMA_Base_Registers *)DMA_CalcBaseAndBitshift(hdma);
regs->IFCR = 0x3FU << hdma->StreamIndex;
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
hdma->State = HAL_DMA_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
{
DMA_Base_Registers *regs;
if(hdma == NULL)
{
return HAL_ERROR;
}if (hdma == NULL) { ... }
if(hdma->State == HAL_DMA_STATE_BUSY)
{
return HAL_BUSY;
}if (hdma->State == HAL_DMA_STATE_BUSY) { ... }
assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
__HAL_DMA_DISABLE(hdma);
hdma->Instance->CR = 0U;
hdma->Instance->NDTR = 0U;
hdma->Instance->PAR = 0U;
hdma->Instance->M0AR = 0U;
hdma->Instance->M1AR = 0U;
hdma->Instance->FCR = 0x00000021U;
regs = (DMA_Base_Registers *)DMA_CalcBaseAndBitshift(hdma);
hdma->XferCpltCallback = NULL;
hdma->XferHalfCpltCallback = NULL;
hdma->XferM1CpltCallback = NULL;
hdma->XferM1HalfCpltCallback = NULL;
hdma->XferErrorCallback = NULL;
hdma->XferAbortCallback = NULL;
regs->IFCR = 0x3FU << hdma->StreamIndex;
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
hdma->State = HAL_DMA_STATE_RESET;
__HAL_UNLOCK(hdma);
return HAL_OK;
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
{
HAL_StatusTypeDef status = HAL_OK;
assert_param(IS_DMA_BUFFER_SIZE(DataLength));
__HAL_LOCK(hdma);
if(HAL_DMA_STATE_READY == hdma->State)
{
hdma->State = HAL_DMA_STATE_BUSY;
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
__HAL_DMA_ENABLE(hdma);
}if (HAL_DMA_STATE_READY == hdma->State) { ... }
else
{
__HAL_UNLOCK(hdma);
status = HAL_BUSY;
}else { ... }
return status;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
{
HAL_StatusTypeDef status = HAL_OK;
DMA_Base_Registers *regs = (DMA_Base_Registers *)hdma->StreamBaseAddress;
assert_param(IS_DMA_BUFFER_SIZE(DataLength));
__HAL_LOCK(hdma);
if(HAL_DMA_STATE_READY == hdma->State)
{
hdma->State = HAL_DMA_STATE_BUSY;
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
regs->IFCR = 0x3FU << hdma->StreamIndex;
hdma->Instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME;
if(hdma->XferHalfCpltCallback != NULL)
{
hdma->Instance->CR |= DMA_IT_HT;
}if (hdma->XferHalfCpltCallback != NULL) { ... }
__HAL_DMA_ENABLE(hdma);
}if (HAL_DMA_STATE_READY == hdma->State) { ... }
else
{
__HAL_UNLOCK(hdma);
status = HAL_BUSY;
}else { ... }
return status;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
{
DMA_Base_Registers *regs = (DMA_Base_Registers *)hdma->StreamBaseAddress;
uint32_t tickstart = HAL_GetTick();
if(hdma->State != HAL_DMA_STATE_BUSY)
{
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
__HAL_UNLOCK(hdma);
return HAL_ERROR;
}if (hdma->State != HAL_DMA_STATE_BUSY) { ... }
else
{
hdma->Instance->CR &= ~(DMA_IT_TC | DMA_IT_TE | DMA_IT_DME);
hdma->Instance->FCR &= ~(DMA_IT_FE);
if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
{
hdma->Instance->CR &= ~(DMA_IT_HT);
}if ((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL)) { ... }
__HAL_DMA_DISABLE(hdma);
while((hdma->Instance->CR & DMA_SxCR_EN) != RESET)
{
if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT)
{
hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT;
hdma->State = HAL_DMA_STATE_TIMEOUT;
__HAL_UNLOCK(hdma);
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT) { ... }
}while ((hdma->Instance->CR & DMA_SxCR_EN) != RESET) { ... }
regs->IFCR = 0x3FU << hdma->StreamIndex;
hdma->State = HAL_DMA_STATE_READY;
__HAL_UNLOCK(hdma);
}else { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
{
if(hdma->State != HAL_DMA_STATE_BUSY)
{
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
return HAL_ERROR;
}if (hdma->State != HAL_DMA_STATE_BUSY) { ... }
else
{
hdma->State = HAL_DMA_STATE_ABORT;
__HAL_DMA_DISABLE(hdma);
}else { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout)
{
HAL_StatusTypeDef status = HAL_OK;
uint32_t mask_cpltlevel;
uint32_t tickstart = HAL_GetTick();
uint32_t tmpisr;
DMA_Base_Registers *regs;
if(HAL_DMA_STATE_BUSY != hdma->State)
{
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
__HAL_UNLOCK(hdma);
return HAL_ERROR;
}if (HAL_DMA_STATE_BUSY != hdma->State) { ... }
if ((hdma->Instance->CR & DMA_SxCR_CIRC) != RESET)
{
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
return HAL_ERROR;
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) != RESET) { ... }
if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
{
mask_cpltlevel = DMA_FLAG_TCIF0_4 << hdma->StreamIndex;
}if (CompleteLevel == HAL_DMA_FULL_TRANSFER) { ... }
else
{
mask_cpltlevel = DMA_FLAG_HTIF0_4 << hdma->StreamIndex;
}else { ... }
regs = (DMA_Base_Registers *)hdma->StreamBaseAddress;
tmpisr = regs->ISR;
while(((tmpisr & mask_cpltlevel) == RESET) && ((hdma->ErrorCode & HAL_DMA_ERROR_TE) == RESET))
{
if(Timeout != HAL_MAX_DELAY)
{
if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
{
hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT;
hdma->State = HAL_DMA_STATE_READY;
__HAL_UNLOCK(hdma);
return HAL_TIMEOUT;
}if ((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
tmpisr = regs->ISR;
if((tmpisr & (DMA_FLAG_TEIF0_4 << hdma->StreamIndex)) != RESET)
{
hdma->ErrorCode |= HAL_DMA_ERROR_TE;
regs->IFCR = DMA_FLAG_TEIF0_4 << hdma->StreamIndex;
}if ((tmpisr & (DMA_FLAG_TEIF0_4 << hdma->StreamIndex)) != RESET) { ... }
if((tmpisr & (DMA_FLAG_FEIF0_4 << hdma->StreamIndex)) != RESET)
{
hdma->ErrorCode |= HAL_DMA_ERROR_FE;
regs->IFCR = DMA_FLAG_FEIF0_4 << hdma->StreamIndex;
}if ((tmpisr & (DMA_FLAG_FEIF0_4 << hdma->StreamIndex)) != RESET) { ... }
if((tmpisr & (DMA_FLAG_DMEIF0_4 << hdma->StreamIndex)) != RESET)
{
hdma->ErrorCode |= HAL_DMA_ERROR_DME;
regs->IFCR = DMA_FLAG_DMEIF0_4 << hdma->StreamIndex;
}if ((tmpisr & (DMA_FLAG_DMEIF0_4 << hdma->StreamIndex)) != RESET) { ... }
}while (((tmpisr & mask_cpltlevel) == RESET) && ((hdma->ErrorCode & HAL_DMA_ERROR_TE) == RESET)) { ... }
if(hdma->ErrorCode != HAL_DMA_ERROR_NONE)
{
if((hdma->ErrorCode & HAL_DMA_ERROR_TE) != RESET)
{
HAL_DMA_Abort(hdma);
regs->IFCR = (DMA_FLAG_HTIF0_4 | DMA_FLAG_TCIF0_4) << hdma->StreamIndex;
hdma->State= HAL_DMA_STATE_READY;
__HAL_UNLOCK(hdma);
return HAL_ERROR;
}if ((hdma->ErrorCode & HAL_DMA_ERROR_TE) != RESET) { ... }
}if (hdma->ErrorCode != HAL_DMA_ERROR_NONE) { ... }
if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
{
regs->IFCR = (DMA_FLAG_HTIF0_4 | DMA_FLAG_TCIF0_4) << hdma->StreamIndex;
hdma->State = HAL_DMA_STATE_READY;
__HAL_UNLOCK(hdma);
}if (CompleteLevel == HAL_DMA_FULL_TRANSFER) { ... }
else
{
regs->IFCR = (DMA_FLAG_HTIF0_4) << hdma->StreamIndex;
}else { ... }
return status;
}{ ... }
/* ... */
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
{
uint32_t tmpisr;
__IO uint32_t count = 0U;
uint32_t timeout = SystemCoreClock / 9600U;
DMA_Base_Registers *regs = (DMA_Base_Registers *)hdma->StreamBaseAddress;
tmpisr = regs->ISR;
if ((tmpisr & (DMA_FLAG_TEIF0_4 << hdma->StreamIndex)) != RESET)
{
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET)
{
hdma->Instance->CR &= ~(DMA_IT_TE);
regs->IFCR = DMA_FLAG_TEIF0_4 << hdma->StreamIndex;
hdma->ErrorCode |= HAL_DMA_ERROR_TE;
}if (__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET) { ... }
}if ((tmpisr & (DMA_FLAG_TEIF0_4 << hdma->StreamIndex)) != RESET) { ... }
if ((tmpisr & (DMA_FLAG_FEIF0_4 << hdma->StreamIndex)) != RESET)
{
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_FE) != RESET)
{
regs->IFCR = DMA_FLAG_FEIF0_4 << hdma->StreamIndex;
hdma->ErrorCode |= HAL_DMA_ERROR_FE;
}if (__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_FE) != RESET) { ... }
}if ((tmpisr & (DMA_FLAG_FEIF0_4 << hdma->StreamIndex)) != RESET) { ... }
if ((tmpisr & (DMA_FLAG_DMEIF0_4 << hdma->StreamIndex)) != RESET)
{
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_DME) != RESET)
{
regs->IFCR = DMA_FLAG_DMEIF0_4 << hdma->StreamIndex;
hdma->ErrorCode |= HAL_DMA_ERROR_DME;
}if (__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_DME) != RESET) { ... }
}if ((tmpisr & (DMA_FLAG_DMEIF0_4 << hdma->StreamIndex)) != RESET) { ... }
if ((tmpisr & (DMA_FLAG_HTIF0_4 << hdma->StreamIndex)) != RESET)
{
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET)
{
regs->IFCR = DMA_FLAG_HTIF0_4 << hdma->StreamIndex;
if(((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != RESET)
{
if((hdma->Instance->CR & DMA_SxCR_CT) == RESET)
{
if(hdma->XferHalfCpltCallback != NULL)
{
hdma->XferHalfCpltCallback(hdma);
}if (hdma->XferHalfCpltCallback != NULL) { ... }
}if ((hdma->Instance->CR & DMA_SxCR_CT) == RESET) { ... }
else
{
if(hdma->XferM1HalfCpltCallback != NULL)
{
hdma->XferM1HalfCpltCallback(hdma);
}if (hdma->XferM1HalfCpltCallback != NULL) { ... }
}else { ... }
}if (((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != RESET) { ... }
else
{
if((hdma->Instance->CR & DMA_SxCR_CIRC) == RESET)
{
hdma->Instance->CR &= ~(DMA_IT_HT);
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) == RESET) { ... }
if(hdma->XferHalfCpltCallback != NULL)
{
hdma->XferHalfCpltCallback(hdma);
}if (hdma->XferHalfCpltCallback != NULL) { ... }
}else { ... }
}if (__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET) { ... }
}if ((tmpisr & (DMA_FLAG_HTIF0_4 << hdma->StreamIndex)) != RESET) { ... }
if ((tmpisr & (DMA_FLAG_TCIF0_4 << hdma->StreamIndex)) != RESET)
{
if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET)
{
regs->IFCR = DMA_FLAG_TCIF0_4 << hdma->StreamIndex;
if(HAL_DMA_STATE_ABORT == hdma->State)
{
hdma->Instance->CR &= ~(DMA_IT_TC | DMA_IT_TE | DMA_IT_DME);
hdma->Instance->FCR &= ~(DMA_IT_FE);
if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
{
hdma->Instance->CR &= ~(DMA_IT_HT);
}if ((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL)) { ... }
regs->IFCR = 0x3FU << hdma->StreamIndex;
hdma->State = HAL_DMA_STATE_READY;
__HAL_UNLOCK(hdma);
if(hdma->XferAbortCallback != NULL)
{
hdma->XferAbortCallback(hdma);
}if (hdma->XferAbortCallback != NULL) { ... }
return;
}if (HAL_DMA_STATE_ABORT == hdma->State) { ... }
if(((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != RESET)
{
if((hdma->Instance->CR & DMA_SxCR_CT) == RESET)
{
if(hdma->XferM1CpltCallback != NULL)
{
hdma->XferM1CpltCallback(hdma);
}if (hdma->XferM1CpltCallback != NULL) { ... }
}if ((hdma->Instance->CR & DMA_SxCR_CT) == RESET) { ... }
else
{
if(hdma->XferCpltCallback != NULL)
{
hdma->XferCpltCallback(hdma);
}if (hdma->XferCpltCallback != NULL) { ... }
}else { ... }
}if (((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != RESET) { ... }
else
{
if((hdma->Instance->CR & DMA_SxCR_CIRC) == RESET)
{
hdma->Instance->CR &= ~(DMA_IT_TC);
hdma->State = HAL_DMA_STATE_READY;
__HAL_UNLOCK(hdma);
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) == RESET) { ... }
if(hdma->XferCpltCallback != NULL)
{
hdma->XferCpltCallback(hdma);
}if (hdma->XferCpltCallback != NULL) { ... }
}else { ... }
}if (__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET) { ... }
}if ((tmpisr & (DMA_FLAG_TCIF0_4 << hdma->StreamIndex)) != RESET) { ... }
if(hdma->ErrorCode != HAL_DMA_ERROR_NONE)
{
if((hdma->ErrorCode & HAL_DMA_ERROR_TE) != RESET)
{
hdma->State = HAL_DMA_STATE_ABORT;
__HAL_DMA_DISABLE(hdma);
do
{
if (++count > timeout)
{
break;
}if (++count > timeout) { ... }
...}
while((hdma->Instance->CR & DMA_SxCR_EN) != RESET);
hdma->State = HAL_DMA_STATE_READY;
__HAL_UNLOCK(hdma);
}if ((hdma->ErrorCode & HAL_DMA_ERROR_TE) != RESET) { ... }
if(hdma->XferErrorCallback != NULL)
{
hdma->XferErrorCallback(hdma);
}if (hdma->XferErrorCallback != NULL) { ... }
}if (hdma->ErrorCode != HAL_DMA_ERROR_NONE) { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)(DMA_HandleTypeDef *_hdma))
{
HAL_StatusTypeDef status = HAL_OK;
__HAL_LOCK(hdma);
if(HAL_DMA_STATE_READY == hdma->State)
{
switch (CallbackID)
{
case HAL_DMA_XFER_CPLT_CB_ID:
hdma->XferCpltCallback = pCallback;
break;
case HAL_DMA_XFER_CPLT_CB_ID:
case HAL_DMA_XFER_HALFCPLT_CB_ID:
hdma->XferHalfCpltCallback = pCallback;
break;
case HAL_DMA_XFER_HALFCPLT_CB_ID:
case HAL_DMA_XFER_M1CPLT_CB_ID:
hdma->XferM1CpltCallback = pCallback;
break;
case HAL_DMA_XFER_M1CPLT_CB_ID:
case HAL_DMA_XFER_M1HALFCPLT_CB_ID:
hdma->XferM1HalfCpltCallback = pCallback;
break;
case HAL_DMA_XFER_M1HALFCPLT_CB_ID:
case HAL_DMA_XFER_ERROR_CB_ID:
hdma->XferErrorCallback = pCallback;
break;
case HAL_DMA_XFER_ERROR_CB_ID:
case HAL_DMA_XFER_ABORT_CB_ID:
hdma->XferAbortCallback = pCallback;
break;
case HAL_DMA_XFER_ABORT_CB_ID:
default:
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (HAL_DMA_STATE_READY == hdma->State) { ... }
else
{
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hdma);
return status;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
__HAL_LOCK(hdma);
if(HAL_DMA_STATE_READY == hdma->State)
{
switch (CallbackID)
{
case HAL_DMA_XFER_CPLT_CB_ID:
hdma->XferCpltCallback = NULL;
break;
case HAL_DMA_XFER_CPLT_CB_ID:
case HAL_DMA_XFER_HALFCPLT_CB_ID:
hdma->XferHalfCpltCallback = NULL;
break;
case HAL_DMA_XFER_HALFCPLT_CB_ID:
case HAL_DMA_XFER_M1CPLT_CB_ID:
hdma->XferM1CpltCallback = NULL;
break;
case HAL_DMA_XFER_M1CPLT_CB_ID:
case HAL_DMA_XFER_M1HALFCPLT_CB_ID:
hdma->XferM1HalfCpltCallback = NULL;
break;
case HAL_DMA_XFER_M1HALFCPLT_CB_ID:
case HAL_DMA_XFER_ERROR_CB_ID:
hdma->XferErrorCallback = NULL;
break;
case HAL_DMA_XFER_ERROR_CB_ID:
case HAL_DMA_XFER_ABORT_CB_ID:
hdma->XferAbortCallback = NULL;
break;
case HAL_DMA_XFER_ABORT_CB_ID:
case HAL_DMA_XFER_ALL_CB_ID:
hdma->XferCpltCallback = NULL;
hdma->XferHalfCpltCallback = NULL;
hdma->XferM1CpltCallback = NULL;
hdma->XferM1HalfCpltCallback = NULL;
hdma->XferErrorCallback = NULL;
hdma->XferAbortCallback = NULL;
break;
case HAL_DMA_XFER_ALL_CB_ID:
default:
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (HAL_DMA_STATE_READY == hdma->State) { ... }
else
{
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hdma);
return status;
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
{
return hdma->State;
}{ ... }
/* ... */
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
{
return hdma->ErrorCode;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
{
hdma->Instance->CR &= (uint32_t)(~DMA_SxCR_DBM);
hdma->Instance->NDTR = DataLength;
if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
{
hdma->Instance->PAR = DstAddress;
hdma->Instance->M0AR = SrcAddress;
}if ((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) { ... }
else
{
hdma->Instance->PAR = SrcAddress;
hdma->Instance->M0AR = DstAddress;
}else { ... }
}{ ... }
/* ... */
static uint32_t DMA_CalcBaseAndBitshift(DMA_HandleTypeDef *hdma)
{
uint32_t stream_number = (((uint32_t)hdma->Instance & 0xFFU) - 16U) / 24U;
static const uint8_t flagBitshiftOffset[8U] = {0U, 6U, 16U, 22U, 0U, 6U, 16U, 22U};
hdma->StreamIndex = flagBitshiftOffset[stream_number];
if (stream_number > 3U)
{
hdma->StreamBaseAddress = (((uint32_t)hdma->Instance & (uint32_t)(~0x3FFU)) + 4U);
}if (stream_number > 3U) { ... }
else
{
hdma->StreamBaseAddress = ((uint32_t)hdma->Instance & (uint32_t)(~0x3FFU));
}else { ... }
return hdma->StreamBaseAddress;
}{ ... }
/* ... */
static HAL_StatusTypeDef DMA_CheckFifoParam(DMA_HandleTypeDef *hdma)
{
HAL_StatusTypeDef status = HAL_OK;
uint32_t tmp = hdma->Init.FIFOThreshold;
if(hdma->Init.MemDataAlignment == DMA_MDATAALIGN_BYTE)
{
switch (tmp)
{
case DMA_FIFO_THRESHOLD_1QUARTERFULL:
case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
if ((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1)
{
status = HAL_ERROR;
}if ((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1) { ... }
break;case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
case DMA_FIFO_THRESHOLD_HALFFULL:
if (hdma->Init.MemBurst == DMA_MBURST_INC16)
{
status = HAL_ERROR;
}if (hdma->Init.MemBurst == DMA_MBURST_INC16) { ... }
break;case DMA_FIFO_THRESHOLD_HALFFULL:
case DMA_FIFO_THRESHOLD_FULL:
break;case DMA_FIFO_THRESHOLD_FULL:
default:
break;default
}switch (tmp) { ... }
}if (hdma->Init.MemDataAlignment == DMA_MDATAALIGN_BYTE) { ... }
else if (hdma->Init.MemDataAlignment == DMA_MDATAALIGN_HALFWORD)
{
switch (tmp)
{
case DMA_FIFO_THRESHOLD_1QUARTERFULL:
case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
status = HAL_ERROR;
break;case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
case DMA_FIFO_THRESHOLD_HALFFULL:
if ((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1)
{
status = HAL_ERROR;
}if ((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1) { ... }
break;case DMA_FIFO_THRESHOLD_HALFFULL:
case DMA_FIFO_THRESHOLD_FULL:
if (hdma->Init.MemBurst == DMA_MBURST_INC16)
{
status = HAL_ERROR;
}if (hdma->Init.MemBurst == DMA_MBURST_INC16) { ... }
break; case DMA_FIFO_THRESHOLD_FULL:
default:
break;default
}switch (tmp) { ... }
}else if (hdma->Init.MemDataAlignment == DMA_MDATAALIGN_HALFWORD) { ... }
else
{
switch (tmp)
{
case DMA_FIFO_THRESHOLD_1QUARTERFULL:
case DMA_FIFO_THRESHOLD_HALFFULL:
case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
status = HAL_ERROR;
break;case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
case DMA_FIFO_THRESHOLD_FULL:
if ((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1)
{
status = HAL_ERROR;
}if ((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1) { ... }
break;case DMA_FIFO_THRESHOLD_FULL:
default:
break;default
}switch (tmp) { ... }
}else { ... }
return status;
}{ ... }
/* ... */
/* ... */
#endif
/* ... */
/* ... */