You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1320 lines
40 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_dma.c
  4. * @author MCD Application Team
  5. * @version V1.5.2
  6. * @date 22-September-2016
  7. * @brief DMA HAL module driver.
  8. *
  9. * This file provides firmware functions to manage the following
  10. * functionalities of the Direct Memory Access (DMA) peripheral:
  11. * + Initialization and de-initialization functions
  12. * + IO operation functions
  13. * + Peripheral State and errors functions
  14. @verbatim
  15. ==============================================================================
  16. ##### How to use this driver #####
  17. ==============================================================================
  18. [..]
  19. (#) Enable and configure the peripheral to be connected to the DMA Stream
  20. (except for internal SRAM/FLASH memories: no initialization is
  21. necessary) please refer to Reference manual for connection between peripherals
  22. and DMA requests.
  23. (#) For a given Stream, program the required configuration through the following parameters:
  24. Transfer Direction, Source and Destination data formats,
  25. Circular, Normal or peripheral flow control mode, Stream Priority level,
  26. Source and Destination Increment mode, FIFO mode and its Threshold (if needed),
  27. Burst mode for Source and/or Destination (if needed) using HAL_DMA_Init() function.
  28. -@- Prior to HAL_DMA_Init() the clock must be enabled for DMA through the following macros:
  29. __HAL_RCC_DMA1_CLK_ENABLE() or __HAL_RCC_DMA2_CLK_ENABLE().
  30. *** Polling mode IO operation ***
  31. =================================
  32. [..]
  33. (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source
  34. address and destination address and the Length of data to be transferred.
  35. (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this
  36. case a fixed Timeout can be configured by User depending from his application.
  37. (+) Use HAL_DMA_Abort() function to abort the current transfer.
  38. *** Interrupt mode IO operation ***
  39. ===================================
  40. [..]
  41. (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
  42. (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ()
  43. (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of
  44. Source address and destination address and the Length of data to be transferred. In this
  45. case the DMA interrupt is configured
  46. (+) Use HAL_DMA_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
  47. (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can
  48. add his own function by customization of function pointer XferCpltCallback and
  49. XferErrorCallback (i.e a member of DMA handle structure).
  50. [..]
  51. (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error
  52. detection.
  53. (#) Use HAL_DMA_Abort_IT() function to abort the current transfer
  54. -@- In Memory-to-Memory transfer mode, Circular mode is not allowed.
  55. -@- The FIFO is used mainly to reduce bus usage and to allow data packing/unpacking: it is
  56. possible to set different Data Sizes for the Peripheral and the Memory (ie. you can set
  57. Half-Word data size for the peripheral to access its data register and set Word data size
  58. for the Memory to gain in access time. Each two half words will be packed and written in
  59. a single access to a Word in the Memory).
  60. -@- When FIFO is disabled, it is not allowed to configure different Data Sizes for Source
  61. and Destination. In this case the Peripheral Data Size will be applied to both Source
  62. and Destination.
  63. *** DMA HAL driver macros list ***
  64. =============================================
  65. [..]
  66. Below the list of most used macros in DMA HAL driver.
  67. (+) __HAL_DMA_ENABLE: Enable the specified DMA Stream.
  68. (+) __HAL_DMA_DISABLE: Disable the specified DMA Stream.
  69. (+) __HAL_DMA_GET_FS: Return the current DMA Stream FIFO filled level.
  70. (+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Stream interrupts.
  71. (+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Stream interrupts.
  72. (+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Stream interrupt has occurred or not.
  73. [..]
  74. (@) You can refer to the DMA HAL driver header file for more useful macros
  75. @endverbatim
  76. ******************************************************************************
  77. * @attention
  78. *
  79. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  80. *
  81. * Redistribution and use in source and binary forms, with or without modification,
  82. * are permitted provided that the following conditions are met:
  83. * 1. Redistributions of source code must retain the above copyright notice,
  84. * this list of conditions and the following disclaimer.
  85. * 2. Redistributions in binary form must reproduce the above copyright notice,
  86. * this list of conditions and the following disclaimer in the documentation
  87. * and/or other materials provided with the distribution.
  88. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  89. * may be used to endorse or promote products derived from this software
  90. * without specific prior written permission.
  91. *
  92. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  93. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  94. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  95. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  96. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  97. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  98. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  99. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  100. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  101. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  102. *
  103. ******************************************************************************
  104. */
  105. /* Includes ------------------------------------------------------------------*/
  106. #include "stm32f4xx_hal.h"
  107. /** @addtogroup STM32F4xx_HAL_Driver
  108. * @{
  109. */
  110. /** @defgroup DMA DMA
  111. * @brief DMA HAL module driver
  112. * @{
  113. */
  114. #ifdef HAL_DMA_MODULE_ENABLED
  115. /* Private types -------------------------------------------------------------*/
  116. typedef struct
  117. {
  118. __IO uint32_t ISR; /*!< DMA interrupt status register */
  119. __IO uint32_t Reserved0;
  120. __IO uint32_t IFCR; /*!< DMA interrupt flag clear register */
  121. } DMA_Base_Registers;
  122. /* Private variables ---------------------------------------------------------*/
  123. /* Private constants ---------------------------------------------------------*/
  124. /** @addtogroup DMA_Private_Constants
  125. * @{
  126. */
  127. #define HAL_TIMEOUT_DMA_ABORT ((uint32_t)5) /* 5 ms */
  128. /**
  129. * @}
  130. */
  131. /* Private macros ------------------------------------------------------------*/
  132. /* Private functions ---------------------------------------------------------*/
  133. /** @addtogroup DMA_Private_Functions
  134. * @{
  135. */
  136. static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
  137. static uint32_t DMA_CalcBaseAndBitshift(DMA_HandleTypeDef *hdma);
  138. static HAL_StatusTypeDef DMA_CheckFifoParam(DMA_HandleTypeDef *hdma);
  139. /**
  140. * @}
  141. */
  142. /* Exported functions --------------------------------------------------------*/
  143. /** @addtogroup DMA_Exported_Functions
  144. * @{
  145. */
  146. /** @addtogroup DMA_Exported_Functions_Group1
  147. *
  148. @verbatim
  149. ===============================================================================
  150. ##### Initialization and de-initialization functions #####
  151. ===============================================================================
  152. [..]
  153. This section provides functions allowing to initialize the DMA Stream source
  154. and destination addresses, incrementation and data sizes, transfer direction,
  155. circular/normal mode selection, memory-to-memory mode selection and Stream priority value.
  156. [..]
  157. The HAL_DMA_Init() function follows the DMA configuration procedures as described in
  158. reference manual.
  159. @endverbatim
  160. * @{
  161. */
  162. /**
  163. * @brief Initializes the DMA according to the specified
  164. * parameters in the DMA_InitTypeDef and create the associated handle.
  165. * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
  166. * the configuration information for the specified DMA Stream.
  167. * @retval HAL status
  168. */
  169. HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
  170. {
  171. uint32_t tmp = 0U;
  172. uint32_t tickstart = HAL_GetTick();
  173. DMA_Base_Registers *regs;
  174. /* Check the DMA peripheral state */
  175. if(hdma == NULL)
  176. {
  177. return HAL_ERROR;
  178. }
  179. /* Check the parameters */
  180. assert_param(IS_DMA_STREAM_ALL_INSTANCE(hdma->Instance));
  181. assert_param(IS_DMA_CHANNEL(hdma->Init.Channel));
  182. assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
  183. assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
  184. assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
  185. assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
  186. assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
  187. assert_param(IS_DMA_MODE(hdma->Init.Mode));
  188. assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
  189. assert_param(IS_DMA_FIFO_MODE_STATE(hdma->Init.FIFOMode));
  190. /* Check the memory burst, peripheral burst and FIFO threshold parameters only
  191. when FIFO mode is enabled */
  192. if(hdma->Init.FIFOMode != DMA_FIFOMODE_DISABLE)
  193. {
  194. assert_param(IS_DMA_FIFO_THRESHOLD(hdma->Init.FIFOThreshold));
  195. assert_param(IS_DMA_MEMORY_BURST(hdma->Init.MemBurst));
  196. assert_param(IS_DMA_PERIPHERAL_BURST(hdma->Init.PeriphBurst));
  197. }
  198. /* Allocate lock resource */
  199. __HAL_UNLOCK(hdma);
  200. /* Change DMA peripheral state */
  201. hdma->State = HAL_DMA_STATE_BUSY;
  202. /* Disable the peripheral */
  203. __HAL_DMA_DISABLE(hdma);
  204. /* Check if the DMA Stream is effectively disabled */
  205. while((hdma->Instance->CR & DMA_SxCR_EN) != RESET)
  206. {
  207. /* Check for the Timeout */
  208. if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT)
  209. {
  210. /* Update error code */
  211. hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT;
  212. /* Change the DMA state */
  213. hdma->State = HAL_DMA_STATE_TIMEOUT;
  214. return HAL_TIMEOUT;
  215. }
  216. }
  217. /* Get the CR register value */
  218. tmp = hdma->Instance->CR;
  219. /* Clear CHSEL, MBURST, PBURST, PL, MSIZE, PSIZE, MINC, PINC, CIRC, DIR, CT and DBM bits */
  220. tmp &= ((uint32_t)~(DMA_SxCR_CHSEL | DMA_SxCR_MBURST | DMA_SxCR_PBURST | \
  221. DMA_SxCR_PL | DMA_SxCR_MSIZE | DMA_SxCR_PSIZE | \
  222. DMA_SxCR_MINC | DMA_SxCR_PINC | DMA_SxCR_CIRC | \
  223. DMA_SxCR_DIR | DMA_SxCR_CT | DMA_SxCR_DBM));
  224. /* Prepare the DMA Stream configuration */
  225. tmp |= hdma->Init.Channel | hdma->Init.Direction |
  226. hdma->Init.PeriphInc | hdma->Init.MemInc |
  227. hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
  228. hdma->Init.Mode | hdma->Init.Priority;
  229. /* the Memory burst and peripheral burst are not used when the FIFO is disabled */
  230. if(hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE)
  231. {
  232. /* Get memory burst and peripheral burst */
  233. tmp |= hdma->Init.MemBurst | hdma->Init.PeriphBurst;
  234. }
  235. /* Write to DMA Stream CR register */
  236. hdma->Instance->CR = tmp;
  237. /* Get the FCR register value */
  238. tmp = hdma->Instance->FCR;
  239. /* Clear Direct mode and FIFO threshold bits */
  240. tmp &= (uint32_t)~(DMA_SxFCR_DMDIS | DMA_SxFCR_FTH);
  241. /* Prepare the DMA Stream FIFO configuration */
  242. tmp |= hdma->Init.FIFOMode;
  243. /* the FIFO threshold is not used when the FIFO mode is disabled */
  244. if(hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE)
  245. {
  246. /* Get the FIFO threshold */
  247. tmp |= hdma->Init.FIFOThreshold;
  248. if(DMA_CheckFifoParam(hdma) != HAL_OK)
  249. {
  250. /* Update error code */
  251. hdma->ErrorCode = HAL_DMA_ERROR_PARAM;
  252. /* Change the DMA state */
  253. hdma->State = HAL_DMA_STATE_READY;
  254. return HAL_ERROR;
  255. }
  256. }
  257. /* Write to DMA Stream FCR */
  258. hdma->Instance->FCR = tmp;
  259. /* Initialize StreamBaseAddress and StreamIndex parameters to be used to calculate
  260. DMA steam Base Address needed by HAL_DMA_IRQHandler() and HAL_DMA_PollForTransfer() */
  261. regs = (DMA_Base_Registers *)DMA_CalcBaseAndBitshift(hdma);
  262. /* Clear all interrupt flags */
  263. regs->IFCR = 0x3FU << hdma->StreamIndex;
  264. /* Initialize the error code */
  265. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  266. /* Initialize the DMA state */
  267. hdma->State = HAL_DMA_STATE_READY;
  268. return HAL_OK;
  269. }
  270. /**
  271. * @brief DeInitializes the DMA peripheral
  272. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  273. * the configuration information for the specified DMA Stream.
  274. * @retval HAL status
  275. */
  276. HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
  277. {
  278. DMA_Base_Registers *regs;
  279. /* Check the DMA peripheral state */
  280. if(hdma == NULL)
  281. {
  282. return HAL_ERROR;
  283. }
  284. /* Check the DMA peripheral state */
  285. if(hdma->State == HAL_DMA_STATE_BUSY)
  286. {
  287. /* Return error status */
  288. return HAL_BUSY;
  289. }
  290. /* Disable the selected DMA Streamx */
  291. __HAL_DMA_DISABLE(hdma);
  292. /* Reset DMA Streamx control register */
  293. hdma->Instance->CR = 0U;
  294. /* Reset DMA Streamx number of data to transfer register */
  295. hdma->Instance->NDTR = 0U;
  296. /* Reset DMA Streamx peripheral address register */
  297. hdma->Instance->PAR = 0U;
  298. /* Reset DMA Streamx memory 0 address register */
  299. hdma->Instance->M0AR = 0U;
  300. /* Reset DMA Streamx memory 1 address register */
  301. hdma->Instance->M1AR = 0U;
  302. /* Reset DMA Streamx FIFO control register */
  303. hdma->Instance->FCR = (uint32_t)0x00000021U;
  304. /* Get DMA steam Base Address */
  305. regs = (DMA_Base_Registers *)DMA_CalcBaseAndBitshift(hdma);
  306. /* Clear all interrupt flags at correct offset within the register */
  307. regs->IFCR = 0x3FU << hdma->StreamIndex;
  308. /* Initialize the error code */
  309. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  310. /* Initialize the DMA state */
  311. hdma->State = HAL_DMA_STATE_RESET;
  312. /* Release Lock */
  313. __HAL_UNLOCK(hdma);
  314. return HAL_OK;
  315. }
  316. /**
  317. * @}
  318. */
  319. /** @addtogroup DMA_Exported_Functions_Group2
  320. *
  321. @verbatim
  322. ===============================================================================
  323. ##### IO operation functions #####
  324. ===============================================================================
  325. [..] This section provides functions allowing to:
  326. (+) Configure the source, destination address and data length and Start DMA transfer
  327. (+) Configure the source, destination address and data length and
  328. Start DMA transfer with interrupt
  329. (+) Abort DMA transfer
  330. (+) Poll for transfer complete
  331. (+) Handle DMA interrupt request
  332. @endverbatim
  333. * @{
  334. */
  335. /**
  336. * @brief Starts the DMA Transfer.
  337. * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
  338. * the configuration information for the specified DMA Stream.
  339. * @param SrcAddress: The source memory Buffer address
  340. * @param DstAddress: The destination memory Buffer address
  341. * @param DataLength: The length of data to be transferred from source to destination
  342. * @retval HAL status
  343. */
  344. HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
  345. {
  346. HAL_StatusTypeDef status = HAL_OK;
  347. /* Check the parameters */
  348. assert_param(IS_DMA_BUFFER_SIZE(DataLength));
  349. /* Process locked */
  350. __HAL_LOCK(hdma);
  351. if(HAL_DMA_STATE_READY == hdma->State)
  352. {
  353. /* Change DMA peripheral state */
  354. hdma->State = HAL_DMA_STATE_BUSY;
  355. /* Initialize the error code */
  356. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  357. /* Configure the source, destination address and the data length */
  358. DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
  359. /* Enable the Peripheral */
  360. __HAL_DMA_ENABLE(hdma);
  361. }
  362. else
  363. {
  364. /* Process unlocked */
  365. __HAL_UNLOCK(hdma);
  366. /* Return error status */
  367. status = HAL_BUSY;
  368. }
  369. return status;
  370. }
  371. /**
  372. * @brief Starts the DMA Transfer with interrupt enabled.
  373. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  374. * the configuration information for the specified DMA Stream.
  375. * @param SrcAddress: The source memory Buffer address
  376. * @param DstAddress: The destination memory Buffer address
  377. * @param DataLength: The length of data to be transferred from source to destination
  378. * @retval HAL status
  379. */
  380. HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
  381. {
  382. HAL_StatusTypeDef status = HAL_OK;
  383. /* calculate DMA base and stream number */
  384. DMA_Base_Registers *regs = (DMA_Base_Registers *)hdma->StreamBaseAddress;
  385. /* Check the parameters */
  386. assert_param(IS_DMA_BUFFER_SIZE(DataLength));
  387. /* Process locked */
  388. __HAL_LOCK(hdma);
  389. if(HAL_DMA_STATE_READY == hdma->State)
  390. {
  391. /* Change DMA peripheral state */
  392. hdma->State = HAL_DMA_STATE_BUSY;
  393. /* Initialize the error code */
  394. hdma->ErrorCode = HAL_DMA_ERROR_NONE;
  395. /* Configure the source, destination address and the data length */
  396. DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
  397. /* Clear all interrupt flags at correct offset within the register */
  398. regs->IFCR = 0x3FU << hdma->StreamIndex;
  399. /* Enable Common interrupts*/
  400. hdma->Instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME;
  401. hdma->Instance->FCR |= DMA_IT_FE;
  402. if(hdma->XferHalfCpltCallback != NULL)
  403. {
  404. hdma->Instance->CR |= DMA_IT_HT;
  405. }
  406. /* Enable the Peripheral */
  407. __HAL_DMA_ENABLE(hdma);
  408. }
  409. else
  410. {
  411. /* Process unlocked */
  412. __HAL_UNLOCK(hdma);
  413. /* Return error status */
  414. status = HAL_BUSY;
  415. }
  416. return status;
  417. }
  418. /**
  419. * @brief Aborts the DMA Transfer.
  420. * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
  421. * the configuration information for the specified DMA Stream.
  422. *
  423. * @note After disabling a DMA Stream, a check for wait until the DMA Stream is
  424. * effectively disabled is added. If a Stream is disabled
  425. * while a data transfer is ongoing, the current data will be transferred
  426. * and the Stream will be effectively disabled only after the transfer of
  427. * this single data is finished.
  428. * @retval HAL status
  429. */
  430. HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
  431. {
  432. /* calculate DMA base and stream number */
  433. DMA_Base_Registers *regs = (DMA_Base_Registers *)hdma->StreamBaseAddress;
  434. uint32_t tickstart = HAL_GetTick();
  435. if(hdma->State != HAL_DMA_STATE_BUSY)
  436. {
  437. hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
  438. /* Process Unlocked */
  439. __HAL_UNLOCK(hdma);
  440. return HAL_ERROR;
  441. }
  442. else
  443. {
  444. /* Disable all the transfer interrupts */
  445. hdma->Instance->CR &= ~(DMA_IT_TC | DMA_IT_TE | DMA_IT_DME);
  446. hdma->Instance->FCR &= ~(DMA_IT_FE);
  447. if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
  448. {
  449. hdma->Instance->CR &= ~(DMA_IT_HT);
  450. }
  451. /* Disable the stream */
  452. __HAL_DMA_DISABLE(hdma);
  453. /* Check if the DMA Stream is effectively disabled */
  454. while((hdma->Instance->CR & DMA_SxCR_EN) != RESET)
  455. {
  456. /* Check for the Timeout */
  457. if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA_ABORT)
  458. {
  459. /* Update error code */
  460. hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT;
  461. /* Process Unlocked */
  462. __HAL_UNLOCK(hdma);
  463. /* Change the DMA state */
  464. hdma->State = HAL_DMA_STATE_TIMEOUT;
  465. return HAL_TIMEOUT;
  466. }
  467. }
  468. /* Clear all interrupt flags at correct offset within the register */
  469. regs->IFCR = 0x3FU << hdma->StreamIndex;
  470. /* Process Unlocked */
  471. __HAL_UNLOCK(hdma);
  472. /* Change the DMA state*/
  473. hdma->State = HAL_DMA_STATE_READY;
  474. }
  475. return HAL_OK;
  476. }
  477. /**
  478. * @brief Aborts the DMA Transfer in Interrupt mode.
  479. * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
  480. * the configuration information for the specified DMA Stream.
  481. * @retval HAL status
  482. */
  483. HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
  484. {
  485. if(hdma->State != HAL_DMA_STATE_BUSY)
  486. {
  487. hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
  488. return HAL_ERROR;
  489. }
  490. else
  491. {
  492. /* Set Abort State */
  493. hdma->State = HAL_DMA_STATE_ABORT;
  494. /* Disable the stream */
  495. __HAL_DMA_DISABLE(hdma);
  496. }
  497. return HAL_OK;
  498. }
  499. /**
  500. * @brief Polling for transfer complete.
  501. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  502. * the configuration information for the specified DMA Stream.
  503. * @param CompleteLevel: Specifies the DMA level complete.
  504. * @note The polling mode is kept in this version for legacy. it is recommanded to use the IT model instead.
  505. * This model could be used for debug purpose.
  506. * @note The HAL_DMA_PollForTransfer API cannot be used in circular and double buffering mode (automatic circular mode).
  507. * @param Timeout: Timeout duration.
  508. * @retval HAL status
  509. */
  510. HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout)
  511. {
  512. HAL_StatusTypeDef status = HAL_OK;
  513. uint32_t mask_cpltlevel;
  514. uint32_t tickstart = HAL_GetTick();
  515. uint32_t tmpisr;
  516. /* calculate DMA base and stream number */
  517. DMA_Base_Registers *regs;
  518. if(HAL_DMA_STATE_BUSY != hdma->State)
  519. {
  520. /* No transfer ongoing */
  521. hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
  522. __HAL_UNLOCK(hdma);
  523. return HAL_ERROR;
  524. }
  525. /* Polling mode not supported in circular mode and double buffering mode */
  526. if ((hdma->Instance->CR & DMA_SxCR_CIRC) != RESET)
  527. {
  528. hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
  529. return HAL_ERROR;
  530. }
  531. /* Get the level transfer complete flag */
  532. if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
  533. {
  534. /* Transfer Complete flag */
  535. mask_cpltlevel = DMA_FLAG_TCIF0_4 << hdma->StreamIndex;
  536. }
  537. else
  538. {
  539. /* Half Transfer Complete flag */
  540. mask_cpltlevel = DMA_FLAG_HTIF0_4 << hdma->StreamIndex;
  541. }
  542. regs = (DMA_Base_Registers *)hdma->StreamBaseAddress;
  543. tmpisr = regs->ISR;
  544. while(((tmpisr & mask_cpltlevel) == RESET) && ((hdma->ErrorCode & HAL_DMA_ERROR_TE) == RESET))
  545. {
  546. /* Check for the Timeout (Not applicable in circular mode)*/
  547. if(Timeout != HAL_MAX_DELAY)
  548. {
  549. if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
  550. {
  551. /* Update error code */
  552. hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT;
  553. /* Process Unlocked */
  554. __HAL_UNLOCK(hdma);
  555. /* Change the DMA state */
  556. hdma->State = HAL_DMA_STATE_READY;
  557. return HAL_TIMEOUT;
  558. }
  559. }
  560. /* Get the ISR register value */
  561. tmpisr = regs->ISR;
  562. if((tmpisr & (DMA_FLAG_TEIF0_4 << hdma->StreamIndex)) != RESET)
  563. {
  564. /* Update error code */
  565. hdma->ErrorCode |= HAL_DMA_ERROR_TE;
  566. /* Clear the transfer error flag */
  567. regs->IFCR = DMA_FLAG_TEIF0_4 << hdma->StreamIndex;
  568. }
  569. if((tmpisr & (DMA_FLAG_FEIF0_4 << hdma->StreamIndex)) != RESET)
  570. {
  571. /* Update error code */
  572. hdma->ErrorCode |= HAL_DMA_ERROR_FE;
  573. /* Clear the FIFO error flag */
  574. regs->IFCR = DMA_FLAG_FEIF0_4 << hdma->StreamIndex;
  575. }
  576. if((tmpisr & (DMA_FLAG_DMEIF0_4 << hdma->StreamIndex)) != RESET)
  577. {
  578. /* Update error code */
  579. hdma->ErrorCode |= HAL_DMA_ERROR_DME;
  580. /* Clear the Direct Mode error flag */
  581. regs->IFCR = DMA_FLAG_DMEIF0_4 << hdma->StreamIndex;
  582. }
  583. }
  584. if(hdma->ErrorCode != HAL_DMA_ERROR_NONE)
  585. {
  586. if((hdma->ErrorCode & HAL_DMA_ERROR_TE) != RESET)
  587. {
  588. HAL_DMA_Abort(hdma);
  589. /* Clear the half transfer and transfer complete flags */
  590. regs->IFCR = (DMA_FLAG_HTIF0_4 | DMA_FLAG_TCIF0_4) << hdma->StreamIndex;
  591. /* Process Unlocked */
  592. __HAL_UNLOCK(hdma);
  593. /* Change the DMA state */
  594. hdma->State= HAL_DMA_STATE_READY;
  595. return HAL_ERROR;
  596. }
  597. }
  598. /* Get the level transfer complete flag */
  599. if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
  600. {
  601. /* Clear the half transfer and transfer complete flags */
  602. regs->IFCR = (DMA_FLAG_HTIF0_4 | DMA_FLAG_TCIF0_4) << hdma->StreamIndex;
  603. /* Process Unlocked */
  604. __HAL_UNLOCK(hdma);
  605. hdma->State = HAL_DMA_STATE_READY;
  606. }
  607. else
  608. {
  609. /* Clear the half transfer and transfer complete flags */
  610. regs->IFCR = (DMA_FLAG_HTIF0_4) << hdma->StreamIndex;
  611. }
  612. return status;
  613. }
  614. /**
  615. * @brief Handles DMA interrupt request.
  616. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  617. * the configuration information for the specified DMA Stream.
  618. * @retval None
  619. */
  620. void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
  621. {
  622. uint32_t tmpisr;
  623. __IO uint32_t count = 0;
  624. uint32_t timeout = SystemCoreClock / 9600;
  625. /* calculate DMA base and stream number */
  626. DMA_Base_Registers *regs = (DMA_Base_Registers *)hdma->StreamBaseAddress;
  627. tmpisr = regs->ISR;
  628. /* Transfer Error Interrupt management ***************************************/
  629. if ((tmpisr & (DMA_FLAG_TEIF0_4 << hdma->StreamIndex)) != RESET)
  630. {
  631. if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TE) != RESET)
  632. {
  633. /* Disable the transfer error interrupt */
  634. hdma->Instance->CR &= ~(DMA_IT_TE);
  635. /* Clear the transfer error flag */
  636. regs->IFCR = DMA_FLAG_TEIF0_4 << hdma->StreamIndex;
  637. /* Update error code */
  638. hdma->ErrorCode |= HAL_DMA_ERROR_TE;
  639. }
  640. }
  641. /* FIFO Error Interrupt management ******************************************/
  642. if ((tmpisr & (DMA_FLAG_FEIF0_4 << hdma->StreamIndex)) != RESET)
  643. {
  644. if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_FE) != RESET)
  645. {
  646. /* Clear the FIFO error flag */
  647. regs->IFCR = DMA_FLAG_FEIF0_4 << hdma->StreamIndex;
  648. /* Update error code */
  649. hdma->ErrorCode |= HAL_DMA_ERROR_FE;
  650. }
  651. }
  652. /* Direct Mode Error Interrupt management ***********************************/
  653. if ((tmpisr & (DMA_FLAG_DMEIF0_4 << hdma->StreamIndex)) != RESET)
  654. {
  655. if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_DME) != RESET)
  656. {
  657. /* Clear the direct mode error flag */
  658. regs->IFCR = DMA_FLAG_DMEIF0_4 << hdma->StreamIndex;
  659. /* Update error code */
  660. hdma->ErrorCode |= HAL_DMA_ERROR_DME;
  661. }
  662. }
  663. /* Half Transfer Complete Interrupt management ******************************/
  664. if ((tmpisr & (DMA_FLAG_HTIF0_4 << hdma->StreamIndex)) != RESET)
  665. {
  666. if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_HT) != RESET)
  667. {
  668. /* Clear the half transfer complete flag */
  669. regs->IFCR = DMA_FLAG_HTIF0_4 << hdma->StreamIndex;
  670. /* Multi_Buffering mode enabled */
  671. if(((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != RESET)
  672. {
  673. /* Current memory buffer used is Memory 0 */
  674. if((hdma->Instance->CR & DMA_SxCR_CT) == RESET)
  675. {
  676. if(hdma->XferHalfCpltCallback != NULL)
  677. {
  678. /* Half transfer callback */
  679. hdma->XferHalfCpltCallback(hdma);
  680. }
  681. }
  682. /* Current memory buffer used is Memory 1 */
  683. else
  684. {
  685. if(hdma->XferM1HalfCpltCallback != NULL)
  686. {
  687. /* Half transfer callback */
  688. hdma->XferM1HalfCpltCallback(hdma);
  689. }
  690. }
  691. }
  692. else
  693. {
  694. /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
  695. if((hdma->Instance->CR & DMA_SxCR_CIRC) == RESET)
  696. {
  697. /* Disable the half transfer interrupt */
  698. hdma->Instance->CR &= ~(DMA_IT_HT);
  699. }
  700. if(hdma->XferHalfCpltCallback != NULL)
  701. {
  702. /* Half transfer callback */
  703. hdma->XferHalfCpltCallback(hdma);
  704. }
  705. }
  706. }
  707. }
  708. /* Transfer Complete Interrupt management ***********************************/
  709. if ((tmpisr & (DMA_FLAG_TCIF0_4 << hdma->StreamIndex)) != RESET)
  710. {
  711. if(__HAL_DMA_GET_IT_SOURCE(hdma, DMA_IT_TC) != RESET)
  712. {
  713. /* Clear the transfer complete flag */
  714. regs->IFCR = DMA_FLAG_TCIF0_4 << hdma->StreamIndex;
  715. if(HAL_DMA_STATE_ABORT == hdma->State)
  716. {
  717. /* Disable all the transfer interrupts */
  718. hdma->Instance->CR &= ~(DMA_IT_TC | DMA_IT_TE | DMA_IT_DME);
  719. hdma->Instance->FCR &= ~(DMA_IT_FE);
  720. if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL))
  721. {
  722. hdma->Instance->CR &= ~(DMA_IT_HT);
  723. }
  724. /* Clear all interrupt flags at correct offset within the register */
  725. regs->IFCR = 0x3FU << hdma->StreamIndex;
  726. /* Process Unlocked */
  727. __HAL_UNLOCK(hdma);
  728. /* Change the DMA state */
  729. hdma->State = HAL_DMA_STATE_READY;
  730. if(hdma->XferAbortCallback != NULL)
  731. {
  732. hdma->XferAbortCallback(hdma);
  733. }
  734. return;
  735. }
  736. if(((hdma->Instance->CR) & (uint32_t)(DMA_SxCR_DBM)) != RESET)
  737. {
  738. /* Current memory buffer used is Memory 0 */
  739. if((hdma->Instance->CR & DMA_SxCR_CT) == RESET)
  740. {
  741. if(hdma->XferM1CpltCallback != NULL)
  742. {
  743. /* Transfer complete Callback for memory1 */
  744. hdma->XferM1CpltCallback(hdma);
  745. }
  746. }
  747. /* Current memory buffer used is Memory 1 */
  748. else
  749. {
  750. if(hdma->XferCpltCallback != NULL)
  751. {
  752. /* Transfer complete Callback for memory0 */
  753. hdma->XferCpltCallback(hdma);
  754. }
  755. }
  756. }
  757. /* Disable the transfer complete interrupt if the DMA mode is not CIRCULAR */
  758. else
  759. {
  760. if((hdma->Instance->CR & DMA_SxCR_CIRC) == RESET)
  761. {
  762. /* Disable the transfer complete interrupt */
  763. hdma->Instance->CR &= ~(DMA_IT_TC);
  764. /* Process Unlocked */
  765. __HAL_UNLOCK(hdma);
  766. /* Change the DMA state */
  767. hdma->State = HAL_DMA_STATE_READY;
  768. }
  769. if(hdma->XferCpltCallback != NULL)
  770. {
  771. /* Transfer complete callback */
  772. hdma->XferCpltCallback(hdma);
  773. }
  774. }
  775. }
  776. }
  777. /* manage error case */
  778. if(hdma->ErrorCode != HAL_DMA_ERROR_NONE)
  779. {
  780. if((hdma->ErrorCode & HAL_DMA_ERROR_TE) != RESET)
  781. {
  782. hdma->State = HAL_DMA_STATE_ABORT;
  783. /* Disable the stream */
  784. __HAL_DMA_DISABLE(hdma);
  785. do
  786. {
  787. if (++count > timeout)
  788. {
  789. break;
  790. }
  791. }
  792. while((hdma->Instance->CR & DMA_SxCR_EN) != RESET);
  793. /* Process Unlocked */
  794. __HAL_UNLOCK(hdma);
  795. /* Change the DMA state */
  796. hdma->State = HAL_DMA_STATE_READY;
  797. }
  798. if(hdma->XferErrorCallback != NULL)
  799. {
  800. /* Transfer error callback */
  801. hdma->XferErrorCallback(hdma);
  802. }
  803. }
  804. }
  805. /**
  806. * @brief Register callbacks
  807. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  808. * the configuration information for the specified DMA Stream.
  809. * @param CallbackID: User Callback identifer
  810. * a DMA_HandleTypeDef structure as parameter.
  811. * @param pCallback: pointer to private callbacsk function which has pointer to
  812. * a DMA_HandleTypeDef structure as parameter.
  813. * @retval HAL status
  814. */
  815. HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)(DMA_HandleTypeDef *_hdma))
  816. {
  817. HAL_StatusTypeDef status = HAL_OK;
  818. /* Process locked */
  819. __HAL_LOCK(hdma);
  820. if(HAL_DMA_STATE_READY == hdma->State)
  821. {
  822. switch (CallbackID)
  823. {
  824. case HAL_DMA_XFER_CPLT_CB_ID:
  825. hdma->XferCpltCallback = pCallback;
  826. break;
  827. case HAL_DMA_XFER_HALFCPLT_CB_ID:
  828. hdma->XferHalfCpltCallback = pCallback;
  829. break;
  830. case HAL_DMA_XFER_M1CPLT_CB_ID:
  831. hdma->XferM1CpltCallback = pCallback;
  832. break;
  833. case HAL_DMA_XFER_M1HALFCPLT_CB_ID:
  834. hdma->XferM1HalfCpltCallback = pCallback;
  835. break;
  836. case HAL_DMA_XFER_ERROR_CB_ID:
  837. hdma->XferErrorCallback = pCallback;
  838. break;
  839. case HAL_DMA_XFER_ABORT_CB_ID:
  840. hdma->XferAbortCallback = pCallback;
  841. break;
  842. default:
  843. break;
  844. }
  845. }
  846. else
  847. {
  848. /* Return error status */
  849. status = HAL_ERROR;
  850. }
  851. /* Release Lock */
  852. __HAL_UNLOCK(hdma);
  853. return status;
  854. }
  855. /**
  856. * @brief UnRegister callbacks
  857. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  858. * the configuration information for the specified DMA Stream.
  859. * @param CallbackID: User Callback identifer
  860. * a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
  861. * @retval HAL status
  862. */
  863. HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID)
  864. {
  865. HAL_StatusTypeDef status = HAL_OK;
  866. /* Process locked */
  867. __HAL_LOCK(hdma);
  868. if(HAL_DMA_STATE_READY == hdma->State)
  869. {
  870. switch (CallbackID)
  871. {
  872. case HAL_DMA_XFER_CPLT_CB_ID:
  873. hdma->XferCpltCallback = NULL;
  874. break;
  875. case HAL_DMA_XFER_HALFCPLT_CB_ID:
  876. hdma->XferHalfCpltCallback = NULL;
  877. break;
  878. case HAL_DMA_XFER_M1CPLT_CB_ID:
  879. hdma->XferM1CpltCallback = NULL;
  880. break;
  881. case HAL_DMA_XFER_M1HALFCPLT_CB_ID:
  882. hdma->XferM1HalfCpltCallback = NULL;
  883. break;
  884. case HAL_DMA_XFER_ERROR_CB_ID:
  885. hdma->XferErrorCallback = NULL;
  886. break;
  887. case HAL_DMA_XFER_ABORT_CB_ID:
  888. hdma->XferAbortCallback = NULL;
  889. break;
  890. case HAL_DMA_XFER_ALL_CB_ID:
  891. hdma->XferCpltCallback = NULL;
  892. hdma->XferHalfCpltCallback = NULL;
  893. hdma->XferM1CpltCallback = NULL;
  894. hdma->XferM1HalfCpltCallback = NULL;
  895. hdma->XferErrorCallback = NULL;
  896. hdma->XferAbortCallback = NULL;
  897. break;
  898. default:
  899. status = HAL_ERROR;
  900. break;
  901. }
  902. }
  903. else
  904. {
  905. status = HAL_ERROR;
  906. }
  907. /* Release Lock */
  908. __HAL_UNLOCK(hdma);
  909. return status;
  910. }
  911. /**
  912. * @}
  913. */
  914. /** @addtogroup DMA_Exported_Functions_Group3
  915. *
  916. @verbatim
  917. ===============================================================================
  918. ##### State and Errors functions #####
  919. ===============================================================================
  920. [..]
  921. This subsection provides functions allowing to
  922. (+) Check the DMA state
  923. (+) Get error code
  924. @endverbatim
  925. * @{
  926. */
  927. /**
  928. * @brief Returns the DMA state.
  929. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  930. * the configuration information for the specified DMA Stream.
  931. * @retval HAL state
  932. */
  933. HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
  934. {
  935. return hdma->State;
  936. }
  937. /**
  938. * @brief Return the DMA error code
  939. * @param hdma : pointer to a DMA_HandleTypeDef structure that contains
  940. * the configuration information for the specified DMA Stream.
  941. * @retval DMA Error Code
  942. */
  943. uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
  944. {
  945. return hdma->ErrorCode;
  946. }
  947. /**
  948. * @}
  949. */
  950. /**
  951. * @}
  952. */
  953. /** @addtogroup DMA_Private_Functions
  954. * @{
  955. */
  956. /**
  957. * @brief Sets the DMA Transfer parameter.
  958. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  959. * the configuration information for the specified DMA Stream.
  960. * @param SrcAddress: The source memory Buffer address
  961. * @param DstAddress: The destination memory Buffer address
  962. * @param DataLength: The length of data to be transferred from source to destination
  963. * @retval HAL status
  964. */
  965. static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
  966. {
  967. /* Clear DBM bit */
  968. hdma->Instance->CR &= (uint32_t)(~DMA_SxCR_DBM);
  969. /* Configure DMA Stream data length */
  970. hdma->Instance->NDTR = DataLength;
  971. /* Peripheral to Memory */
  972. if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
  973. {
  974. /* Configure DMA Stream destination address */
  975. hdma->Instance->PAR = DstAddress;
  976. /* Configure DMA Stream source address */
  977. hdma->Instance->M0AR = SrcAddress;
  978. }
  979. /* Memory to Peripheral */
  980. else
  981. {
  982. /* Configure DMA Stream source address */
  983. hdma->Instance->PAR = SrcAddress;
  984. /* Configure DMA Stream destination address */
  985. hdma->Instance->M0AR = DstAddress;
  986. }
  987. }
  988. /**
  989. * @brief Returns the DMA Stream base address depending on stream number
  990. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  991. * the configuration information for the specified DMA Stream.
  992. * @retval Stream base address
  993. */
  994. static uint32_t DMA_CalcBaseAndBitshift(DMA_HandleTypeDef *hdma)
  995. {
  996. uint32_t stream_number = (((uint32_t)hdma->Instance & 0xFFU) - 16U) / 24U;
  997. /* lookup table for necessary bitshift of flags within status registers */
  998. static const uint8_t flagBitshiftOffset[8U] = {0U, 6U, 16U, 22U, 0U, 6U, 16U, 22U};
  999. hdma->StreamIndex = flagBitshiftOffset[stream_number];
  1000. if (stream_number > 3U)
  1001. {
  1002. /* return pointer to HISR and HIFCR */
  1003. hdma->StreamBaseAddress = (((uint32_t)hdma->Instance & (uint32_t)(~0x3FFU)) + 4U);
  1004. }
  1005. else
  1006. {
  1007. /* return pointer to LISR and LIFCR */
  1008. hdma->StreamBaseAddress = ((uint32_t)hdma->Instance & (uint32_t)(~0x3FFU));
  1009. }
  1010. return hdma->StreamBaseAddress;
  1011. }
  1012. /**
  1013. * @brief Checks compatibility between FIFO threshold level and size of the memory burst
  1014. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  1015. * the configuration information for the specified DMA Stream.
  1016. * @retval HAL status
  1017. */
  1018. static HAL_StatusTypeDef DMA_CheckFifoParam(DMA_HandleTypeDef *hdma)
  1019. {
  1020. HAL_StatusTypeDef status = HAL_OK;
  1021. uint32_t tmp = hdma->Init.FIFOThreshold;
  1022. /* Memory Data size equal to Byte */
  1023. if(hdma->Init.MemDataAlignment == DMA_MDATAALIGN_BYTE)
  1024. {
  1025. switch (tmp)
  1026. {
  1027. case DMA_FIFO_THRESHOLD_1QUARTERFULL:
  1028. if((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1)
  1029. {
  1030. status = HAL_ERROR;
  1031. }
  1032. break;
  1033. case DMA_FIFO_THRESHOLD_HALFFULL:
  1034. if(hdma->Init.MemBurst == DMA_MBURST_INC16)
  1035. {
  1036. status = HAL_ERROR;
  1037. }
  1038. break;
  1039. case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
  1040. if((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1)
  1041. {
  1042. status = HAL_ERROR;
  1043. }
  1044. break;
  1045. case DMA_FIFO_THRESHOLD_FULL:
  1046. break;
  1047. default:
  1048. break;
  1049. }
  1050. }
  1051. /* Memory Data size equal to Half-Word */
  1052. else if (hdma->Init.MemDataAlignment == DMA_MDATAALIGN_HALFWORD)
  1053. {
  1054. switch (tmp)
  1055. {
  1056. case DMA_FIFO_THRESHOLD_1QUARTERFULL:
  1057. status = HAL_ERROR;
  1058. break;
  1059. case DMA_FIFO_THRESHOLD_HALFFULL:
  1060. if ((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1)
  1061. {
  1062. status = HAL_ERROR;
  1063. }
  1064. break;
  1065. case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
  1066. status = HAL_ERROR;
  1067. break;
  1068. case DMA_FIFO_THRESHOLD_FULL:
  1069. if (hdma->Init.MemBurst == DMA_MBURST_INC16)
  1070. {
  1071. status = HAL_ERROR;
  1072. }
  1073. break;
  1074. default:
  1075. break;
  1076. }
  1077. }
  1078. /* Memory Data size equal to Word */
  1079. else
  1080. {
  1081. switch (tmp)
  1082. {
  1083. case DMA_FIFO_THRESHOLD_1QUARTERFULL:
  1084. case DMA_FIFO_THRESHOLD_HALFFULL:
  1085. case DMA_FIFO_THRESHOLD_3QUARTERSFULL:
  1086. status = HAL_ERROR;
  1087. break;
  1088. case DMA_FIFO_THRESHOLD_FULL:
  1089. if ((hdma->Init.MemBurst & DMA_SxCR_MBURST_1) == DMA_SxCR_MBURST_1)
  1090. {
  1091. status = HAL_ERROR;
  1092. }
  1093. break;
  1094. default:
  1095. break;
  1096. }
  1097. }
  1098. return status;
  1099. }
  1100. /**
  1101. * @}
  1102. */
  1103. #endif /* HAL_DMA_MODULE_ENABLED */
  1104. /**
  1105. * @}
  1106. */
  1107. /**
  1108. * @}
  1109. */
  1110. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/