STM32L486xx HAL User Manual
stm32l4xx_hal_dma_ex.c
Go to the documentation of this file.
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   @verbatim
00011   ==============================================================================
00012                         ##### How to use this driver #####
00013   ==============================================================================
00014   [..]
00015   The DMA Extension HAL driver can be used as follows:
00016 
00017    (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
00018    (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
00019        Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
00020        to respectively enable/disable the request generator.
00021 
00022    (+) To handle the DMAMUX Interrupts, the function  HAL_DMAEx_MUX_IRQHandler should be called from
00023        the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler.
00024        As only one interrupt line is available for all DMAMUX channels and request generators , HAL_DMAEx_MUX_IRQHandler should be
00025        called with, as parameter, the appropriate DMA handle as many as used DMAs in the user project
00026       (exception done if a given DMA is not using the DMAMUX SYNC block neither a request generator)
00027 
00028   @endverbatim
00029   ******************************************************************************
00030   * @attention
00031   *
00032   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00033   *
00034   * Redistribution and use in source and binary forms, with or without modification,
00035   * are permitted provided that the following conditions are met:
00036   *   1. Redistributions of source code must retain the above copyright notice,
00037   *      this list of conditions and the following disclaimer.
00038   *   2. Redistributions in binary form must reproduce the above copyright notice,
00039   *      this list of conditions and the following disclaimer in the documentation
00040   *      and/or other materials provided with the distribution.
00041   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00042   *      may be used to endorse or promote products derived from this software
00043   *      without specific prior written permission.
00044   *
00045   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00046   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00047   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00048   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00049   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00050   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00051   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00052   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00053   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00054   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00055   *
00056   ******************************************************************************
00057   */
00058 
00059 /* Includes ------------------------------------------------------------------*/
00060 #include "stm32l4xx_hal.h"
00061 
00062 #if defined(DMAMUX1)
00063 
00064 /** @addtogroup STM32L4xx_HAL_Driver
00065   * @{
00066   */
00067 
00068 /** @defgroup DMAEx DMAEx
00069   * @brief DMA Extended HAL module driver
00070   * @{
00071   */
00072 
00073 #ifdef HAL_DMA_MODULE_ENABLED
00074 
00075 /* Private typedef -----------------------------------------------------------*/
00076 /* Private define ------------------------------------------------------------*/
00077 /* Private macro -------------------------------------------------------------*/
00078 /* Private variables ---------------------------------------------------------*/
00079 /* Private Constants ---------------------------------------------------------*/
00080 /* Private function prototypes -----------------------------------------------*/
00081 /* Private functions ---------------------------------------------------------*/
00082 
00083 
00084 /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions
00085   * @{
00086   */
00087 
00088 /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions
00089  *  @brief   Extended features functions
00090  *
00091 @verbatim
00092  ===============================================================================
00093                 #####  Extended features functions  #####
00094  ===============================================================================
00095     [..]  This section provides functions allowing to:
00096 
00097     (+) Configure the DMAMUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function.
00098     (+) Configure the DMAMUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function.
00099        Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used
00100        to respectively enable/disable the request generator.
00101 
00102 @endverbatim
00103   * @{
00104   */
00105 
00106 
00107 /**
00108   * @brief  Configure the DMAMUX synchronization parameters for a given DMA channel (instance).
00109   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains
00110   *                     the configuration information for the specified DMA channel.
00111   * @param  pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters
00112   * @retval HAL status
00113   */
00114 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig)
00115 {
00116   /* Check the parameters */
00117   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
00118 
00119   assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID));
00120 
00121   assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig-> SyncPolarity));
00122   assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable));
00123   assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable));
00124   assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber));
00125 
00126   /*Check if the DMA state is ready */
00127   if(hdma->State == HAL_DMA_STATE_READY)
00128   {
00129     /* Process Locked */
00130     __HAL_LOCK(hdma);
00131 
00132     /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/
00133     MODIFY_REG( hdma->DMAmuxChannel->CCR, \
00134                (~DMAMUX_CxCR_DMAREQ_ID) , \
00135                ((pSyncConfig->SyncSignalID) << DMAMUX_CxCR_SYNC_ID_Pos) | ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \
00136                pSyncConfig->SyncPolarity | (pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \
00137                  (pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos));
00138 
00139     /* Process UnLocked */
00140     __HAL_UNLOCK(hdma);
00141 
00142     return HAL_OK;
00143   }
00144   else
00145   {
00146     /*DMA State not Ready*/
00147     return HAL_ERROR;
00148   }
00149 }
00150 
00151 /**
00152   * @brief  Configure the DMAMUX request generator block used by the given DMA channel (instance).
00153   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains
00154   *                     the configuration information for the specified DMA channel.
00155   * @param  pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef :
00156   *         contains the request generator parameters.
00157   *
00158   * @retval HAL status
00159   */
00160 HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig)
00161 {
00162   /* Check the parameters */
00163   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
00164 
00165   assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID));
00166 
00167   assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity));
00168   assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber));
00169 
00170   /* check if the DMA state is ready
00171      and DMA is using a DMAMUX request generator block
00172   */
00173   if((hdma->State == HAL_DMA_STATE_READY) && (hdma->DMAmuxRequestGen != 0U))
00174   {
00175     /* Process Locked */
00176     __HAL_LOCK(hdma);
00177 
00178     /* Set the request generator new parameters */
00179     hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \
00180                                   ((pRequestGeneratorConfig->RequestNumber - 1U) << DMAMUX_RGxCR_GNBREQ_Pos)| \
00181                                   pRequestGeneratorConfig->Polarity;
00182    /* Process UnLocked */
00183    __HAL_UNLOCK(hdma);
00184 
00185    return HAL_OK;
00186  }
00187  else
00188  {
00189    return HAL_ERROR;
00190  }
00191 }
00192 
00193 /**
00194   * @brief  Enable the DMAMUX request generator block used by the given DMA channel (instance).
00195   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains
00196   *                     the configuration information for the specified DMA channel.
00197   * @retval HAL status
00198   */
00199 HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
00200 {
00201   /* Check the parameters */
00202   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
00203 
00204   /* check if the DMA state is ready
00205      and DMA is using a DMAMUX request generator block
00206   */
00207   if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
00208   {
00209 
00210     /* Enable the request generator*/
00211     hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE;
00212 
00213    return HAL_OK;
00214  }
00215  else
00216  {
00217    return HAL_ERROR;
00218  }
00219 }
00220 
00221 /**
00222   * @brief  Disable the DMAMUX request generator block used by the given DMA channel (instance).
00223   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains
00224   *                     the configuration information for the specified DMA channel.
00225   * @retval HAL status
00226   */
00227 HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma)
00228 {
00229   /* Check the parameters */
00230   assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
00231 
00232   /* check if the DMA state is ready
00233      and DMA is using a DMAMUX request generator block
00234   */
00235   if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0))
00236   {
00237 
00238     /* Disable the request generator*/
00239     hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE;
00240 
00241     return HAL_OK;
00242   }
00243   else
00244   {
00245     return HAL_ERROR;
00246   }
00247 }
00248 
00249 /**
00250   * @brief  Handles DMAMUX interrupt request.
00251   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
00252   *               the configuration information for the specified DMA channel.
00253   * @retval None
00254   */
00255 void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma)
00256 {
00257   /* Check for DMAMUX Synchronization overrun */
00258   if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U)
00259   {
00260     /* Disable the synchro overrun interrupt */
00261     hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE;
00262 
00263     /* Clear the DMAMUX synchro overrun flag */
00264     hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask;
00265 
00266     /* Update error code */
00267     hdma->ErrorCode |= HAL_DMA_ERROR_SYNC;
00268 
00269     if(hdma->XferErrorCallback != NULL)
00270     {
00271       /* Transfer error callback */
00272       hdma->XferErrorCallback(hdma);
00273     }
00274   }
00275 
00276   if(hdma->DMAmuxRequestGen != 0)
00277   {
00278    /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */
00279     if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U)
00280     {
00281       /* Disable the request gen overrun interrupt */
00282       hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE;
00283 
00284       /* Clear the DMAMUX request generator overrun flag */
00285       hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask;
00286 
00287       /* Update error code */
00288       hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN;
00289 
00290       if(hdma->XferErrorCallback != NULL)
00291       {
00292         /* Transfer error callback */
00293         hdma->XferErrorCallback(hdma);
00294       }
00295     }
00296   }
00297 }
00298 
00299 /**
00300   * @}
00301   */
00302 
00303 /**
00304   * @}
00305   */
00306 
00307 #endif /* HAL_DMA_MODULE_ENABLED */
00308 
00309 /**
00310   * @}
00311   */
00312 
00313 /**
00314   * @}
00315   */
00316 
00317 #endif /* DMAMUX1 */
00318 
00319 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/