|
STM32G474xx HAL 用户手册
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_hal_dma_ex.c 00004 * @author MCD Application Team 00005 * @brief DMA Extension HAL module driver 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the DMA Extension peripheral: 00008 * + Extended features functions 00009 * 00010 ****************************************************************************** 00011 * @attention 00012 * 00013 * Copyright (c) 2019 STMicroelectronics. 00014 * All rights reserved. 00015 * 00016 * This software is licensed under terms that can be found in the LICENSE file 00017 * in the root directory of this software component. 00018 * If no LICENSE file comes with this software, it is provided AS-IS. 00019 * 00020 ****************************************************************************** 00021 @verbatim 00022 ============================================================================== 00023 ##### How to use this driver ##### 00024 ============================================================================== 00025 [..] 00026 The DMA Extension HAL driver can be used as follows: 00027 00028 (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function. 00029 (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function. 00030 Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used 00031 to respectively enable/disable the request generator. 00032 00033 (+) To handle the DMAMUX Interrupts, the function HAL_DMAEx_MUX_IRQHandler should be called from 00034 the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler. 00035 As only one interrupt line is available for all DMAMUX channels and request generators , HAL_DMAEx_MUX_IRQHandler should be 00036 called with, as parameter, the appropriate DMA handle as many as used DMAs in the user project 00037 (exception done if a given DMA is not using the DMAMUX SYNC block neither a request generator) 00038 00039 @endverbatim 00040 */ 00041 00042 /* Includes ------------------------------------------------------------------*/ 00043 #include "stm32g4xx_hal.h" 00044 00045 /** @addtogroup STM32G4xx_HAL_Driver 00046 * @{ 00047 */ 00048 00049 /** @defgroup DMAEx DMAEx 00050 * @brief DMA Extended HAL module driver 00051 * @{ 00052 */ 00053 00054 #ifdef HAL_DMA_MODULE_ENABLED 00055 00056 /* Private typedef -----------------------------------------------------------*/ 00057 /* Private define ------------------------------------------------------------*/ 00058 /* Private macro -------------------------------------------------------------*/ 00059 /* Private variables ---------------------------------------------------------*/ 00060 /* Private Constants ---------------------------------------------------------*/ 00061 /* Private function prototypes -----------------------------------------------*/ 00062 /* Private functions ---------------------------------------------------------*/ 00063 00064 00065 /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 00066 * @{ 00067 */ 00068 00069 /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions 00070 * @brief Extended features functions 00071 * 00072 @verbatim 00073 =============================================================================== 00074 ##### Extended features functions ##### 00075 =============================================================================== 00076 [..] This section provides functions allowing to: 00077 00078 (+) Configure the DMAMUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function. 00079 (+) Configure the DMAMUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function. 00080 Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used 00081 to respectively enable/disable the request generator. 00082 00083 @endverbatim 00084 * @{ 00085 */ 00086 00087 00088 /** 00089 * @brief Configure the DMAMUX synchronization parameters for a given DMA channel (instance). 00090 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 00091 * the configuration information for the specified DMA channel. 00092 * @param pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters 00093 * @retval HAL status 00094 */ 00095 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig) 00096 { 00097 /* Check the parameters */ 00098 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 00099 00100 assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID)); 00101 00102 assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig-> SyncPolarity)); 00103 assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable)); 00104 assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable)); 00105 assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber)); 00106 00107 /*Check if the DMA state is ready */ 00108 if (hdma->State == HAL_DMA_STATE_READY) 00109 { 00110 /* Process Locked */ 00111 __HAL_LOCK(hdma); 00112 00113 /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/ 00114 MODIFY_REG(hdma->DMAmuxChannel->CCR, \ 00115 (~DMAMUX_CxCR_DMAREQ_ID), \ 00116 ((pSyncConfig->SyncSignalID) << DMAMUX_CxCR_SYNC_ID_Pos) | ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \ 00117 pSyncConfig->SyncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \ 00118 ((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos)); 00119 00120 /* Process UnLocked */ 00121 __HAL_UNLOCK(hdma); 00122 00123 return HAL_OK; 00124 } 00125 else 00126 { 00127 /*DMA State not Ready*/ 00128 return HAL_ERROR; 00129 } 00130 } 00131 00132 /** 00133 * @brief Configure the DMAMUX request generator block used by the given DMA channel (instance). 00134 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 00135 * the configuration information for the specified DMA channel. 00136 * @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef : 00137 * contains the request generator parameters. 00138 * 00139 * @retval HAL status 00140 */ 00141 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator(DMA_HandleTypeDef *hdma, 00142