Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
stm32f1xx_hal_dma.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_hal_dma.c 00004 * @author MCD Application Team 00005 * @version V1.0.4 00006 * @date 29-April-2016 00007 * @brief DMA HAL module driver. 00008 * 00009 * This file provides firmware functions to manage the following 00010 * functionalities of the Direct Memory Access (DMA) peripheral: 00011 * + Initialization and de-initialization functions 00012 * + IO operation functions 00013 * + Peripheral State and errors functions 00014 @verbatim 00015 ============================================================================== 00016 ##### How to use this driver ##### 00017 ============================================================================== 00018 [..] 00019 (#) Enable and configure the peripheral to be connected to the DMA Channel 00020 (except for internal SRAM / FLASH memories: no initialization is 00021 necessary) please refer to Reference manual for connection between peripherals 00022 and DMA requests. 00023 00024 (#) For a given Channel, program the required configuration through the following parameters: 00025 Transfer Direction, Source and Destination data formats, 00026 Circular or Normal mode, Channel Priority level, Source and Destination Increment mode, 00027 using HAL_DMA_Init() function. 00028 00029 (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error 00030 detection. 00031 00032 (#) Use HAL_DMA_Abort() function to abort the current transfer 00033 00034 -@- In Memory-to-Memory transfer mode, Circular mode is not allowed. 00035 *** Polling mode IO operation *** 00036 ================================= 00037 [..] 00038 (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source 00039 address and destination address and the Length of data to be transferred 00040 (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this 00041 case a fixed Timeout can be configured by User depending from his application. 00042 00043 *** Interrupt mode IO operation *** 00044 =================================== 00045 [..] 00046 (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority() 00047 (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ() 00048 (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of 00049 Source address and destination address and the Length of data to be transferred. 00050 In this case the DMA interrupt is configured 00051 (+) Use HAL_DMAy_Channelx_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine 00052 (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can 00053 add his own function by customization of function pointer XferCpltCallback and 00054 XferErrorCallback (i.e a member of DMA handle structure). 00055 00056 *** DMA HAL driver macros list *** 00057 ============================================= 00058 [..] 00059 Below the list of most used macros in DMA HAL driver. 00060 00061 (+) __HAL_DMA_ENABLE: Enable the specified DMA Channel. 00062 (+) __HAL_DMA_DISABLE: Disable the specified DMA Channel. 00063 (+) __HAL_DMA_GET_FLAG: Get the DMA Channel pending flags. 00064 (+) __HAL_DMA_CLEAR_FLAG: Clear the DMA Channel pending flags. 00065 (+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Channel interrupts. 00066 (+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Channel interrupts. 00067 (+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Channel interrupt has occurred or not. 00068 00069 [..] 00070 (@) You can refer to the DMA HAL driver header file for more useful macros 00071 00072 @endverbatim 00073 ****************************************************************************** 00074 * @attention 00075 * 00076 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00077 * 00078 * Redistribution and use in source and binary forms, with or without modification, 00079 * are permitted provided that the following conditions are met: 00080 * 1. Redistributions of source code must retain the above copyright notice, 00081 * this list of conditions and the following disclaimer. 00082 * 2. Redistributions in binary form must reproduce the above copyright notice, 00083 * this list of conditions and the following disclaimer in the documentation 00084 * and/or other materials provided with the distribution. 00085 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00086 * may be used to endorse or promote products derived from this software 00087 * without specific prior written permission. 00088 * 00089 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00090 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00091 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00092 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00093 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00094 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00095 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00096 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00097 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00098 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00099 * 00100 ****************************************************************************** 00101 */ 00102 00103 /* Includes ------------------------------------------------------------------*/ 00104 #include "stm32f1xx_hal.h" 00105 00106 /** @addtogroup STM32F1xx_HAL_Driver 00107 * @{ 00108 */ 00109 00110 /** @defgroup DMA DMA 00111 * @brief DMA HAL module driver 00112 * @{ 00113 */ 00114 00115 #ifdef HAL_DMA_MODULE_ENABLED 00116 00117 /* Private typedef -----------------------------------------------------------*/ 00118 /* Private define ------------------------------------------------------------*/ 00119 /** @defgroup DMA_Private_Constants DMA Private Constants 00120 * @{ 00121 */ 00122 #define HAL_TIMEOUT_DMA_ABORT ((uint32_t)1000) /* 1s */ 00123 /** 00124 * @} 00125 */ 00126 00127 /* Private macro -------------------------------------------------------------*/ 00128 /* Private variables ---------------------------------------------------------*/ 00129 /* Private function prototypes -----------------------------------------------*/ 00130 /** @defgroup DMA_Private_Functions DMA Private Functions 00131 * @{ 00132 */ 00133 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); 00134 /** 00135 * @} 00136 */ 00137 00138 /* Exported functions ---------------------------------------------------------*/ 00139 00140 /** @defgroup DMA_Exported_Functions DMA Exported Functions 00141 * @{ 00142 */ 00143 00144 /** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions 00145 * @brief Initialization and de-initialization functions 00146 * 00147 @verbatim 00148 =============================================================================== 00149 ##### Initialization and de-initialization functions ##### 00150 =============================================================================== 00151 [..] 00152 This section provides functions allowing to initialize the DMA Channel source 00153 and destination addresses, incrementation and data sizes, transfer direction, 00154 circular/normal mode selection, memory-to-memory mode selection and Channel priority value. 00155 [..] 00156 The HAL_DMA_Init() function follows the DMA configuration procedures as described in 00157 reference manual. 00158 00159 @endverbatim 00160 * @{ 00161 */ 00162 00163 /** 00164 * @brief Initializes the DMA according to the specified 00165 * parameters in the DMA_InitTypeDef and create the associated handle. 00166 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains 00167 * the configuration information for the specified DMA Channel. 00168 * @retval HAL status 00169 */ 00170 HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma) 00171 { 00172 uint32_t tmp = 0; 00173 00174 /* Check the DMA handle allocation */ 00175 if(hdma == NULL) 00176 { 00177 return HAL_ERROR; 00178 } 00179 00180 /* Check the parameters */ 00181 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 00182 assert_param(IS_DMA_DIRECTION(hdma->Init.Direction)); 00183 assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc)); 00184 assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc)); 00185 assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment)); 00186 assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment)); 00187 assert_param(IS_DMA_MODE(hdma->Init.Mode)); 00188 assert_param(IS_DMA_PRIORITY(hdma->Init.Priority)); 00189 00190 if(hdma->State == HAL_DMA_STATE_RESET) 00191 { 00192 /* Allocate lock resource and initialize it */ 00193 hdma->Lock = HAL_UNLOCKED; 00194 } 00195 00196 /* Change DMA peripheral state */ 00197 hdma->State = HAL_DMA_STATE_BUSY; 00198 00199 /* Get the CR register value */ 00200 tmp = hdma->Instance->CCR; 00201 00202 /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR bits */ 00203 tmp &= ((uint32_t)~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE | \ 00204 DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC | \ 00205 DMA_CCR_DIR)); 00206 00207 /* Prepare the DMA Channel configuration */ 00208 tmp |= hdma->Init.Direction | 00209 hdma->Init.PeriphInc | hdma->Init.MemInc | 00210 hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment | 00211 hdma->Init.Mode | hdma->Init.Priority; 00212 00213 /* Write to DMA Channel CR register */ 00214 hdma->Instance->CCR = tmp; 00215 00216 /* Initialise the error code */ 00217 hdma->ErrorCode = HAL_DMA_ERROR_NONE; 00218 00219 /* Initialize the DMA state*/ 00220 hdma->State = HAL_DMA_STATE_READY; 00221 00222 return HAL_OK; 00223 } 00224 00225 /** 00226 * @brief DeInitializes the DMA peripheral 00227 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 00228 * the configuration information for the specified DMA Channel. 00229 * @retval HAL status 00230 */ 00231 HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma) 00232 { 00233 /* Check the DMA handle allocation */ 00234 if(hdma == NULL) 00235 { 00236 return HAL_ERROR; 00237 } 00238 00239 /* Check the parameters */ 00240 assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 00241 00242 /* Check the DMA peripheral state */ 00243 if(hdma->State == HAL_DMA_STATE_BUSY) 00244 { 00245 return HAL_ERROR; 00246 } 00247 00248 /* Disable the selected DMA Channelx */ 00249 __HAL_DMA_DISABLE(hdma); 00250 00251 /* Reset DMA Channel control register */ 00252 hdma->Instance->CCR = 0; 00253 00254 /* Reset DMA Channel Number of Data to Transfer register */ 00255 hdma->Instance->CNDTR = 0; 00256 00257 /* Reset DMA Channel peripheral address register */ 00258 hdma->Instance->CPAR = 0; 00259 00260 /* Reset DMA Channel memory address register */ 00261 hdma->Instance->CMAR = 0; 00262 00263 /* Clear all flags */ 00264 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); 00265 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); 00266 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); 00267 00268 /* Initialize the error code */ 00269 hdma->ErrorCode = HAL_DMA_ERROR_NONE; 00270 00271 /* Initialize the DMA state */ 00272 hdma->State = HAL_DMA_STATE_RESET; 00273 00274 /* Release Lock */ 00275 __HAL_UNLOCK(hdma); 00276 00277 return HAL_OK; 00278 } 00279 00280 /** 00281 * @} 00282 */ 00283 00284 /** @defgroup DMA_Exported_Functions_Group2 Input and Output operation functions 00285 * @brief I/O operation functions 00286 * 00287 @verbatim 00288 =============================================================================== 00289 ##### IO operation functions ##### 00290 =============================================================================== 00291 [..] This section provides functions allowing to: 00292 (+) Configure the source, destination address and data length and Start DMA transfer 00293 (+) Configure the source, destination address and data length and 00294 Start DMA transfer with interrupt 00295 (+) Abort DMA transfer 00296 (+) Poll for transfer complete 00297 (+) Handle DMA interrupt request 00298 00299 @endverbatim 00300 * @{ 00301 */ 00302 00303 /** 00304 * @brief Starts the DMA Transfer. 00305 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains 00306 * the configuration information for the specified DMA Channel. 00307 * @param SrcAddress: The source memory Buffer address 00308 * @param DstAddress: The destination memory Buffer address 00309 * @param DataLength: The length of data to be transferred from source to destination 00310 * @retval HAL status 00311 */ 00312 HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) 00313 { 00314 /* Process locked */ 00315 __HAL_LOCK(hdma); 00316 00317 /* Change DMA peripheral state */ 00318 hdma->State = HAL_DMA_STATE_BUSY; 00319 00320 /* Check the parameters */ 00321 assert_param(IS_DMA_BUFFER_SIZE(DataLength)); 00322 00323 /* Disable the peripheral */ 00324 __HAL_DMA_DISABLE(hdma); 00325 00326 /* Configure the source, destination address and the data length */ 00327 DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength); 00328 00329 /* Enable the Peripheral */ 00330 __HAL_DMA_ENABLE(hdma); 00331 00332 return HAL_OK; 00333 } 00334 00335 /** 00336 * @brief Start the DMA Transfer with interrupt enabled. 00337 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 00338 * the configuration information for the specified DMA Channel. 00339 * @param SrcAddress: The source memory Buffer address 00340 * @param DstAddress: The destination memory Buffer address 00341 * @param DataLength: The length of data to be transferred from source to destination 00342 * @retval HAL status 00343 */ 00344 HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) 00345 { 00346 /* Process locked */ 00347 __HAL_LOCK(hdma); 00348 00349 /* Change DMA peripheral state */ 00350 hdma->State = HAL_DMA_STATE_BUSY; 00351 00352 /* Check the parameters */ 00353 assert_param(IS_DMA_BUFFER_SIZE(DataLength)); 00354 00355 /* Disable the peripheral */ 00356 __HAL_DMA_DISABLE(hdma); 00357 00358 /* Configure the source, destination address and the data length */ 00359 DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength); 00360 00361 /* Enable the transfer complete interrupt */ 00362 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC); 00363 00364 /* Enable the Half transfer complete interrupt */ 00365 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT); 00366 00367 /* Enable the transfer Error interrupt */ 00368 __HAL_DMA_ENABLE_IT(hdma, DMA_IT_TE); 00369 00370 /* Enable the Peripheral */ 00371 __HAL_DMA_ENABLE(hdma); 00372 00373 return HAL_OK; 00374 } 00375 00376 /** 00377 * @brief Aborts the DMA Transfer. 00378 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains 00379 * the configuration information for the specified DMA Channel. 00380 * 00381 * @note After disabling a DMA Channel, a check for wait until the DMA Channel is 00382 * effectively disabled is added. If a Channel is disabled 00383 * while a data transfer is ongoing, the current data will be transferred 00384 * and the Channel will be effectively disabled only after the transfer of 00385 * this single data is finished. 00386 * @retval HAL status 00387 */ 00388 HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma) 00389 { 00390 uint32_t tickstart = 0x00; 00391 00392 /* Disable the channel */ 00393 __HAL_DMA_DISABLE(hdma); 00394 00395 /* Get tick */ 00396 tickstart = HAL_GetTick(); 00397 00398 /* Check if the DMA Channel is effectively disabled */ 00399 while((hdma->Instance->CCR & DMA_CCR_EN) != 0) 00400 { 00401 /* Check for the Timeout */ 00402 if((HAL_GetTick() - tickstart) > HAL_TIMEOUT_DMA_ABORT) 00403 { 00404 /* Update error code */ 00405 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT); 00406 00407 /* Change the DMA state */ 00408 hdma->State = HAL_DMA_STATE_TIMEOUT; 00409 00410 /* Process Unlocked */ 00411 __HAL_UNLOCK(hdma); 00412 00413 return HAL_TIMEOUT; 00414 } 00415 } 00416 /* Change the DMA state */ 00417 hdma->State = HAL_DMA_STATE_READY; 00418 00419 /* Process Unlocked */ 00420 __HAL_UNLOCK(hdma); 00421 00422 return HAL_OK; 00423 } 00424 00425 /** 00426 * @brief Polling for transfer complete. 00427 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 00428 * the configuration information for the specified DMA Channel. 00429 * @param CompleteLevel: Specifies the DMA level complete. 00430 * @param Timeout: Timeout duration. 00431 * @retval HAL status 00432 */ 00433 HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout) 00434 { 00435 uint32_t temp; 00436 uint32_t tickstart = 0x00; 00437 00438 /* Get the level transfer complete flag */ 00439 if(CompleteLevel == HAL_DMA_FULL_TRANSFER) 00440 { 00441 /* Transfer Complete flag */ 00442 temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma); 00443 } 00444 else 00445 { 00446 /* Half Transfer Complete flag */ 00447 temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma); 00448 } 00449 00450 /* Get tick */ 00451 tickstart = HAL_GetTick(); 00452 00453 while(__HAL_DMA_GET_FLAG(hdma, temp) == RESET) 00454 { 00455 if((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET)) 00456 { 00457 /* Clear the transfer error flags */ 00458 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); 00459 00460 /* Update error code */ 00461 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE); 00462 00463 /* Change the DMA state */ 00464 hdma->State= HAL_DMA_STATE_ERROR; 00465 00466 /* Process Unlocked */ 00467 __HAL_UNLOCK(hdma); 00468 00469 return HAL_ERROR; 00470 } 00471 /* Check for the Timeout */ 00472 if(Timeout != HAL_MAX_DELAY) 00473 { 00474 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout)) 00475 { 00476 /* Update error code */ 00477 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT); 00478 00479 /* Change the DMA state */ 00480 hdma->State = HAL_DMA_STATE_TIMEOUT; 00481 00482 /* Process Unlocked */ 00483 __HAL_UNLOCK(hdma); 00484 00485 return HAL_TIMEOUT; 00486 } 00487 } 00488 } 00489 00490 if(CompleteLevel == HAL_DMA_FULL_TRANSFER) 00491 { 00492 /* Clear the transfer complete flag */ 00493 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); 00494 00495 /* The selected Channelx EN bit is cleared (DMA is disabled and 00496 all transfers are complete) */ 00497 hdma->State = HAL_DMA_STATE_READY; 00498 00499 } 00500 else 00501 { 00502 /* Clear the half transfer complete flag */ 00503 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); 00504 00505 /* The selected Channelx EN bit is cleared (DMA is disabled and 00506 all transfers of half buffer are complete) */ 00507 hdma->State = HAL_DMA_STATE_READY_HALF; 00508 } 00509 00510 /* Process unlocked */ 00511 __HAL_UNLOCK(hdma); 00512 00513 return HAL_OK; 00514 } 00515 00516 /** 00517 * @brief Handles DMA interrupt request. 00518 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 00519 * the configuration information for the specified DMA Channel. 00520 * @retval None 00521 */ 00522 void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma) 00523 { 00524 /* Transfer Error Interrupt management ***************************************/ 00525 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET) 00526 { 00527 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET) 00528 { 00529 /* Disable the transfer error interrupt */ 00530 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE); 00531 00532 /* Clear the transfer error flag */ 00533 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); 00534 00535 /* Update error code */ 00536 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE); 00537 00538 /* Change the DMA state */ 00539 hdma->State = HAL_DMA_STATE_ERROR; 00540 00541 /* Process Unlocked */ 00542 __HAL_UNLOCK(hdma); 00543 00544 if (hdma->XferErrorCallback != NULL) 00545 { 00546 /* Transfer error callback */ 00547 hdma->XferErrorCallback(hdma); 00548 } 00549 } 00550 } 00551 00552 /* Half Transfer Complete Interrupt management ******************************/ 00553 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)) != RESET) 00554 { 00555 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET) 00556 { 00557 /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */ 00558 if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0) 00559 { 00560 /* Disable the half transfer interrupt */ 00561 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT); 00562 } 00563 /* Clear the half transfer complete flag */ 00564 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); 00565 00566 /* Change DMA peripheral state */ 00567 hdma->State = HAL_DMA_STATE_READY_HALF; 00568 00569 if(hdma->XferHalfCpltCallback != NULL) 00570 { 00571 /* Half transfer callback */ 00572 hdma->XferHalfCpltCallback(hdma); 00573 } 00574 } 00575 } 00576 00577 /* Transfer Complete Interrupt management ***********************************/ 00578 if(__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)) != RESET) 00579 { 00580 if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET) 00581 { 00582 if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0) 00583 { 00584 /* Disable the transfer complete interrupt */ 00585 __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TC); 00586 } 00587 /* Clear the transfer complete flag */ 00588 __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); 00589 00590 /* Update error code */ 00591 SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_NONE); 00592 00593 /* Change the DMA state */ 00594 hdma->State = HAL_DMA_STATE_READY; 00595 00596 /* Process Unlocked */ 00597 __HAL_UNLOCK(hdma); 00598 00599 if(hdma->XferCpltCallback != NULL) 00600 { 00601 /* Transfer complete callback */ 00602 hdma->XferCpltCallback(hdma); 00603 } 00604 } 00605 } 00606 } 00607 00608 /** 00609 * @} 00610 */ 00611 00612 /** @defgroup DMA_Exported_Functions_Group3 Peripheral State functions 00613 * @brief Peripheral State functions 00614 * 00615 @verbatim 00616 =============================================================================== 00617 ##### State and Errors functions ##### 00618 =============================================================================== 00619 [..] 00620 This subsection provides functions allowing to 00621 (+) Check the DMA state 00622 (+) Get error code 00623 00624 @endverbatim 00625 * @{ 00626 */ 00627 00628 /** 00629 * @brief Returns the DMA state. 00630 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 00631 * the configuration information for the specified DMA Channel. 00632 * @retval HAL state 00633 */ 00634 HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma) 00635 { 00636 return hdma->State; 00637 } 00638 00639 /** 00640 * @brief Return the DMA error code 00641 * @param hdma : pointer to a DMA_HandleTypeDef structure that contains 00642 * the configuration information for the specified DMA Channel. 00643 * @retval DMA Error Code 00644 */ 00645 uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma) 00646 { 00647 return hdma->ErrorCode; 00648 } 00649 00650 /** 00651 * @} 00652 */ 00653 00654 /** 00655 * @} 00656 */ 00657 00658 /** @addtogroup DMA_Private_Functions DMA Private Functions 00659 * @{ 00660 */ 00661 00662 /** 00663 * @brief Sets the DMA Transfer parameter. 00664 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 00665 * the configuration information for the specified DMA Channel. 00666 * @param SrcAddress: The source memory Buffer address 00667 * @param DstAddress: The destination memory Buffer address 00668 * @param DataLength: The length of data to be transferred from source to destination 00669 * @retval HAL status 00670 */ 00671 static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) 00672 { 00673 /* Configure DMA Channel data length */ 00674 hdma->Instance->CNDTR = DataLength; 00675 00676 /* Peripheral to Memory */ 00677 if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) 00678 { 00679 /* Configure DMA Channel destination address */ 00680 hdma->Instance->CPAR = DstAddress; 00681 00682 /* Configure DMA Channel source address */ 00683 hdma->Instance->CMAR = SrcAddress; 00684 } 00685 /* Memory to Peripheral */ 00686 else 00687 { 00688 /* Configure DMA Channel source address */ 00689 hdma->Instance->CPAR = SrcAddress; 00690 00691 /* Configure DMA Channel destination address */ 00692 hdma->Instance->CMAR = DstAddress; 00693 } 00694 } 00695 00696 /** 00697 * @} 00698 */ 00699 00700 #endif /* HAL_DMA_MODULE_ENABLED */ 00701 /** 00702 * @} 00703 */ 00704 00705 /** 00706 * @} 00707 */ 00708 00709 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 15:37:23 by
1.7.2