File indexing completed on 2025-05-11 08:23:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 #include "stm32h7xx_hal.h"
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 #ifdef HAL_DMA_MODULE_ENABLED
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
0122 {
0123 HAL_StatusTypeDef status = HAL_OK;
0124 __IO uint32_t *ifcRegister_Base;
0125
0126
0127 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
0128 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
0129
0130
0131 if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
0132 {
0133 hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
0134 status = HAL_ERROR;
0135 }
0136 else
0137 {
0138
0139 __HAL_LOCK(hdma);
0140
0141 if(HAL_DMA_STATE_READY == hdma->State)
0142 {
0143
0144 hdma->State = HAL_DMA_STATE_BUSY;
0145
0146
0147 hdma->ErrorCode = HAL_DMA_ERROR_NONE;
0148
0149 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U)
0150 {
0151
0152 ((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_SxCR_DBM;
0153
0154
0155 ((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = SecondMemAddress;
0156
0157
0158 ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));
0159
0160
0161 *ifcRegister_Base = 0x3FUL << (hdma->StreamIndex & 0x1FU);
0162 }
0163 else
0164 {
0165
0166 ((BDMA_Channel_TypeDef *)hdma->Instance)->CCR |= (BDMA_CCR_DBM | BDMA_CCR_CIRC);
0167
0168
0169 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM1AR = SecondMemAddress;
0170
0171
0172 ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 4U));
0173
0174
0175 *ifcRegister_Base = (BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU);
0176 }
0177
0178 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U)
0179 {
0180
0181 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
0182
0183
0184 hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
0185
0186 if(hdma->DMAmuxRequestGen != 0U)
0187 {
0188
0189 hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
0190 }
0191 }
0192
0193
0194 __HAL_DMA_ENABLE(hdma);
0195 }
0196 else
0197 {
0198
0199 hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
0200
0201
0202 status = HAL_ERROR;
0203 }
0204 }
0205 return status;
0206 }
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218 HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
0219 {
0220 HAL_StatusTypeDef status = HAL_OK;
0221 __IO uint32_t *ifcRegister_Base;
0222
0223
0224 assert_param(IS_DMA_BUFFER_SIZE(DataLength));
0225 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
0226
0227
0228 if(hdma->Init.Direction == DMA_MEMORY_TO_MEMORY)
0229 {
0230 hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
0231 return HAL_ERROR;
0232 }
0233
0234
0235 __HAL_LOCK(hdma);
0236
0237 if(HAL_DMA_STATE_READY == hdma->State)
0238 {
0239
0240 hdma->State = HAL_DMA_STATE_BUSY;
0241
0242
0243 hdma->ErrorCode = HAL_DMA_ERROR_NONE;
0244
0245 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U)
0246 {
0247
0248 ((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_SxCR_DBM;
0249
0250
0251 ((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = SecondMemAddress;
0252
0253
0254 ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 8U));
0255
0256
0257 *ifcRegister_Base = 0x3FUL << (hdma->StreamIndex & 0x1FU);
0258 }
0259 else
0260 {
0261
0262 ((BDMA_Channel_TypeDef *)hdma->Instance)->CCR |= (BDMA_CCR_DBM | BDMA_CCR_CIRC);
0263
0264
0265 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM1AR = SecondMemAddress;
0266
0267
0268 ifcRegister_Base = (uint32_t *)((uint32_t)(hdma->StreamBaseAddress + 4U));
0269
0270
0271 *ifcRegister_Base = (BDMA_ISR_GIF0) << (hdma->StreamIndex & 0x1FU);
0272 }
0273
0274
0275 DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength);
0276
0277 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U)
0278 {
0279
0280 hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
0281
0282 if(hdma->DMAmuxRequestGen != 0U)
0283 {
0284
0285 hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
0286 }
0287 }
0288
0289 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U)
0290 {
0291
0292 MODIFY_REG(((DMA_Stream_TypeDef *)hdma->Instance)->CR, (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT), (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME));
0293 ((DMA_Stream_TypeDef *)hdma->Instance)->FCR |= DMA_IT_FE;
0294
0295 if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
0296 {
0297
0298 ((DMA_Stream_TypeDef *)hdma->Instance)->CR |= DMA_IT_HT;
0299 }
0300 }
0301 else
0302 {
0303
0304 MODIFY_REG(((BDMA_Channel_TypeDef *)hdma->Instance)->CCR, (BDMA_CCR_TCIE | BDMA_CCR_HTIE | BDMA_CCR_TEIE), (BDMA_CCR_TCIE | BDMA_CCR_TEIE));
0305
0306 if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
0307 {
0308
0309 ((BDMA_Channel_TypeDef *)hdma->Instance)->CCR |= BDMA_CCR_HTIE;
0310 }
0311 }
0312
0313 if(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance) != 0U)
0314 {
0315
0316 if((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0U)
0317 {
0318
0319 hdma->DMAmuxChannel->CCR |= DMAMUX_CxCR_SOIE;
0320 }
0321
0322 if(hdma->DMAmuxRequestGen != 0U)
0323 {
0324
0325
0326 hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;
0327 }
0328 }
0329
0330
0331 __HAL_DMA_ENABLE(hdma);
0332 }
0333 else
0334 {
0335
0336 hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
0337
0338
0339 status = HAL_ERROR;
0340 }
0341 return status;
0342 }
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358 HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
0359 {
0360 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U)
0361 {
0362 if(memory == MEMORY0)
0363 {
0364
0365 ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = Address;
0366 }
0367 else
0368 {
0369
0370 ((DMA_Stream_TypeDef *)hdma->Instance)->M1AR = Address;
0371 }
0372 }
0373 else
0374 {
0375 if(memory == MEMORY0)
0376 {
0377
0378 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = Address;
0379 }
0380 else
0381 {
0382
0383 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM1AR = Address;
0384 }
0385 }
0386
0387 return HAL_OK;
0388 }
0389
0390
0391
0392
0393
0394
0395
0396
0397 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)
0398 {
0399 uint32_t syncSignalID = 0;
0400 uint32_t syncPolarity = 0;
0401
0402
0403 assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));
0404 assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));
0405 assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));
0406 assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));
0407
0408 if(pSyncConfig->SyncEnable == ENABLE)
0409 {
0410 assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig->SyncPolarity));
0411
0412 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U)
0413 {
0414 assert_param(IS_DMA_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
0415 }
0416 else
0417 {
0418 assert_param(IS_BDMA_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
0419 }
0420 syncSignalID = pSyncConfig->SyncSignalID;
0421 syncPolarity = pSyncConfig->SyncPolarity;
0422 }
0423
0424
0425 if(hdma->State == HAL_DMA_STATE_READY)
0426 {
0427
0428 __HAL_LOCK(hdma);
0429
0430
0431 CLEAR_BIT(hdma->DMAmuxChannel->CCR,(DMAMUX_CxCR_SE | DMAMUX_CxCR_EGE));
0432
0433
0434 MODIFY_REG( hdma->DMAmuxChannel->CCR, \
0435 (~DMAMUX_CxCR_DMAREQ_ID) , \
0436 (syncSignalID << DMAMUX_CxCR_SYNC_ID_Pos) | \
0437 ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
0438 syncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
0439 ((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
0440
0441
0442 __HAL_UNLOCK(hdma);
0443
0444 return HAL_OK;
0445 }
0446 else
0447 {
0448
0449 hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
0450
0451
0452 return HAL_ERROR;
0453 }
0454 }
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
0466 {
0467 HAL_StatusTypeDef status;
0468 HAL_DMA_StateTypeDef temp_state = hdma->State;
0469
0470
0471 assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));
0472
0473 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U)
0474 {
0475 assert_param(IS_DMA_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
0476 }
0477 else
0478 {
0479 assert_param(IS_BDMA_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
0480 }
0481
0482
0483 assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
0484 assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
0485
0486
0487
0488
0489 if(hdma->DMAmuxRequestGen == 0U)
0490 {
0491
0492 hdma->ErrorCode = HAL_DMA_ERROR_PARAM;
0493
0494
0495 status = HAL_ERROR;
0496 }
0497 else if(((hdma->DMAmuxRequestGen->RGCR & DMAMUX_RGxCR_GE) == 0U) && (temp_state == HAL_DMA_STATE_READY))
0498 {
0499
0500
0501
0502 __HAL_LOCK(hdma);
0503
0504
0505 hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \
0506 ((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)| \
0507 pRequestGeneratorConfig->Polarity;
0508
0509 __HAL_UNLOCK(hdma);
0510
0511 return HAL_OK;
0512 }
0513 else
0514 {
0515
0516 hdma->ErrorCode = HAL_DMA_ERROR_BUSY;
0517
0518
0519 status = HAL_ERROR;
0520 }
0521
0522 return status;
0523 }
0524
0525
0526
0527
0528
0529
0530
0531 HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
0532 {
0533
0534 assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));
0535
0536
0537
0538 if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))
0539 {
0540
0541 hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;
0542
0543 return HAL_OK;
0544 }
0545 else
0546 {
0547 return HAL_ERROR;
0548 }
0549 }
0550
0551
0552
0553
0554
0555
0556
0557 HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
0558 {
0559
0560 assert_param(IS_DMA_DMAMUX_ALL_INSTANCE(hdma->Instance));
0561
0562
0563
0564 if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0U))
0565 {
0566
0567 hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;
0568
0569 return HAL_OK;
0570 }
0571 else
0572 {
0573 return HAL_ERROR;
0574 }
0575 }
0576
0577
0578
0579
0580
0581
0582
0583 void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)
0584 {
0585
0586 if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
0587 {
0588
0589 hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
0590
0591
0592 hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
0593
0594
0595 hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
0596
0597 if(hdma->XferErrorCallback != NULL)
0598 {
0599
0600 hdma->XferErrorCallback(hdma);
0601 }
0602 }
0603
0604 if(hdma->DMAmuxRequestGen != 0)
0605 {
0606
0607 if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
0608 {
0609
0610 hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
0611
0612
0613 hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
0614
0615
0616 hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
0617
0618 if(hdma->XferErrorCallback != NULL)
0619 {
0620
0621 hdma->XferErrorCallback(hdma);
0622 }
0623 }
0624 }
0625 }
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647
0648
0649 static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
0650 {
0651 if(IS_DMA_STREAM_INSTANCE(hdma->Instance) != 0U)
0652 {
0653
0654 ((DMA_Stream_TypeDef *)hdma->Instance)->NDTR = DataLength;
0655
0656
0657 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
0658 {
0659
0660 ((DMA_Stream_TypeDef *)hdma->Instance)->PAR = DstAddress;
0661
0662
0663 ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = SrcAddress;
0664 }
0665
0666 else
0667 {
0668
0669 ((DMA_Stream_TypeDef *)hdma->Instance)->PAR = SrcAddress;
0670
0671
0672 ((DMA_Stream_TypeDef *)hdma->Instance)->M0AR = DstAddress;
0673 }
0674 }
0675 else
0676 {
0677
0678 ((BDMA_Channel_TypeDef *)hdma->Instance)->CNDTR = DataLength;
0679
0680
0681 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
0682 {
0683
0684 ((BDMA_Channel_TypeDef *)hdma->Instance)->CPAR = DstAddress;
0685
0686
0687 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = SrcAddress;
0688 }
0689
0690 else
0691 {
0692
0693 ((BDMA_Channel_TypeDef *)hdma->Instance)->CPAR = SrcAddress;
0694
0695
0696 ((BDMA_Channel_TypeDef *)hdma->Instance)->CM0AR = DstAddress;
0697 }
0698 }
0699 }
0700
0701
0702
0703
0704
0705 #endif
0706
0707
0708
0709
0710
0711
0712
0713