STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_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) 2017 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 -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed. 00040 -@- When Multi (Double) Buffer mode is enabled, the transfer is circular by default. 00041 -@- In Multi (Double) buffer mode, it is possible to update the base address for 00042 the AHB memory port on the fly (DMA_CM0ARx or DMA_CM1ARx) when the channel is enabled. 00043 00044 00045 @endverbatim 00046 ****************************************************************************** 00047 */ 00048 00049 /* Includes ------------------------------------------------------------------*/ 00050 #include "stm32l4xx_hal.h" 00051 00052 #if defined(DMAMUX1) 00053 00054 /** @addtogroup STM32L4xx_HAL_Driver 00055 * @{ 00056 */ 00057 00058 /** @defgroup DMAEx DMAEx 00059 * @brief DMA Extended HAL module driver 00060 * @{ 00061 */ 00062 00063 #ifdef HAL_DMA_MODULE_ENABLED 00064 00065 /* Private typedef -----------------------------------------------------------*/ 00066 /* Private define ------------------------------------------------------------*/ 00067 /* Private macro -------------------------------------------------------------*/ 00068 /* Private variables ---------------------------------------------------------*/ 00069 /* Private Constants ---------------------------------------------------------*/ 00070 /* Private function prototypes -----------------------------------------------*/ 00071 /* Private functions ---------------------------------------------------------*/ 00072 00073 00074 /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 00075 * @{ 00076 */ 00077 00078 /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions 00079 * @brief Extended features functions 00080 * 00081 @verbatim 00082 =============================================================================== 00083 ##### Extended features functions ##### 00084 =============================================================================== 00085 [..] This section provides functions allowing to: 00086 00087 (+) Configure the DMAMUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function. 00088 (+) Configure the DMAMUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function. 00089 Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used 00090 to respectively enable/disable the request generator. 00091 00092 @endverbatim 00093 * @{ 00094 */ 00095 00096 00097 /** 00098 * @brief Configure the DMAMUX synchronization parameters for a given DMA channel (instance). 00099 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00100 * the configuration information for the specified DMA channel. 00101 * @param pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters 00102 * @retval HAL status 00103 */ 00104 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig) 00105 { 00106 /* Check the parameters */ 00107 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 00108 00109 assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID)); 00110 00111 assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig-> SyncPolarity)); 00112 assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable)); 00113 assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable)); 00114 assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber)); 00115 00116 /*Check if the DMA state is ready */ 00117 if(hdma->State == HAL_DMA_STATE_READY) 00118 { 00119 /* Process Locked */ 00120 __HAL_LOCK(hdma); 00121 00122 /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/ 00123 MODIFY_REG( hdma->DMAmuxChannel->CCR, \ 00124 (~DMAMUX_CxCR_DMAREQ_ID) , \ 00125 ((pSyncConfig->SyncSignalID) << DMAMUX_CxCR_SYNC_ID_Pos) | ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \ 00126 pSyncConfig->SyncPolarity | ((uint32_t)pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \ 00127 ((uint32_t)pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos)); 00128 00129 /* Process UnLocked */ 00130 __HAL_UNLOCK(hdma); 00131 00132 return HAL_OK; 00133 } 00134 else 00135 { 00136 /*DMA State not Ready*/ 00137 return HAL_ERROR; 00138 } 00139 } 00140 00141 /** 00142 * @brief Configure the DMAMUX request generator block used by the given DMA channel (instance). 00143 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00144 * the configuration information for the specified DMA channel. 00145 * @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef : 00146 * contains the request generator parameters. 00147 * 00148 * @retval HAL status 00149 */ 00150 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig) 00151 { 00152 /* Check the parameters */ 00153 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 00154 00155 assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID)); 00156 00157 assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity)); 00158 assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber)); 00159 00160 /* check if the DMA state is ready 00161 and DMA is using a DMAMUX request generator block 00162 */ 00163 if((hdma->State == HAL_DMA_STATE_READY) && (hdma->DMAmuxRequestGen != 0U)) 00164 { 00165 /* Process Locked */ 00166 __HAL_LOCK(hdma); 00167 00168 /* Set the request generator new parameters */ 00169 hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \ 00170 ((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)| \ 00171 pRequestGeneratorConfig->Polarity; 00172 /* Process UnLocked */ 00173 __HAL_UNLOCK(hdma); 00174 00175 return HAL_OK; 00176 } 00177 else 00178 { 00179 return HAL_ERROR; 00180 } 00181 } 00182 00183 /** 00184 * @brief Enable the DMAMUX request generator block used by the given DMA channel (instance). 00185 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00186 * the configuration information for the specified DMA channel. 00187 * @retval HAL status 00188 */ 00189 HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma) 00190 { 00191 /* Check the parameters */ 00192 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 00193 00194 /* check if the DMA state is ready 00195 and DMA is using a DMAMUX request generator block 00196 */ 00197 if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0)) 00198 { 00199 00200 /* Enable the request generator*/ 00201 hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE; 00202 00203 return HAL_OK; 00204 } 00205 else 00206 { 00207 return HAL_ERROR; 00208 } 00209 } 00210 00211 /** 00212 * @brief Disable the DMAMUX request generator block used by the given DMA channel (instance). 00213 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00214 * the configuration information for the specified DMA channel. 00215 * @retval HAL status 00216 */ 00217 HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma) 00218 { 00219 /* Check the parameters */ 00220 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 00221 00222 /* check if the DMA state is ready 00223 and DMA is using a DMAMUX request generator block 00224 */ 00225 if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0)) 00226 { 00227 00228 /* Disable the request generator*/ 00229 hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE; 00230 00231 return HAL_OK; 00232 } 00233 else 00234 { 00235 return HAL_ERROR; 00236 } 00237 } 00238 00239 /** 00240 * @brief Handles DMAMUX interrupt request. 00241 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00242 * the configuration information for the specified DMA channel. 00243 * @retval None 00244 */ 00245 void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma) 00246 { 00247 /* Check for DMAMUX Synchronization overrun */ 00248 if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U) 00249 { 00250 /* Disable the synchro overrun interrupt */ 00251 hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE; 00252 00253 /* Clear the DMAMUX synchro overrun flag */ 00254 hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask; 00255 00256 /* Update error code */ 00257 hdma->ErrorCode |= HAL_DMA_ERROR_SYNC; 00258 00259 if(hdma->XferErrorCallback != NULL) 00260 { 00261 /* Transfer error callback */ 00262 hdma->XferErrorCallback(hdma); 00263 } 00264 } 00265 00266 if(hdma->DMAmuxRequestGen != 0) 00267 { 00268 /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */ 00269 if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U) 00270 { 00271 /* Disable the request gen overrun interrupt */ 00272 hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE; 00273 00274 /* Clear the DMAMUX request generator overrun flag */ 00275 hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask; 00276 00277 /* Update error code */ 00278 hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN; 00279 00280 if(hdma->XferErrorCallback != NULL) 00281 { 00282 /* Transfer error callback */ 00283 hdma->XferErrorCallback(hdma); 00284 } 00285 } 00286 } 00287 } 00288 00289 /** 00290 * @} 00291 */ 00292 00293 /** 00294 * @} 00295 */ 00296 00297 #endif /* HAL_DMA_MODULE_ENABLED */ 00298 00299 /** 00300 * @} 00301 */ 00302 00303 /** 00304 * @} 00305 */ 00306 00307 #endif /* DMAMUX1 */