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.
 
 
 

347 lines
13 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_bdma.c
  4. * @author MCD Application Team
  5. * @brief BDMA LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32h7xx_ll_bdma.h"
  22. #include "stm32h7xx_ll_bus.h"
  23. #ifdef USE_FULL_ASSERT
  24. #include "stm32_assert.h"
  25. #else
  26. #define assert_param(expr) ((void)0U)
  27. #endif
  28. /** @addtogroup STM32H7xx_LL_Driver
  29. * @{
  30. */
  31. #if defined (BDMA) || defined (BDMA1) || defined (BDMA2)
  32. /** @addtogroup BDMA_LL
  33. * @{
  34. */
  35. /* Private types -------------------------------------------------------------*/
  36. /* Private variables ---------------------------------------------------------*/
  37. /* Private constants ---------------------------------------------------------*/
  38. /* Private macros ------------------------------------------------------------*/
  39. /** @addtogroup BDMA_LL_Private_Macros
  40. * @{
  41. */
  42. #define IS_LL_BDMA_DIRECTION(__VALUE__) (((__VALUE__) == LL_BDMA_DIRECTION_PERIPH_TO_MEMORY) || \
  43. ((__VALUE__) == LL_BDMA_DIRECTION_MEMORY_TO_PERIPH) || \
  44. ((__VALUE__) == LL_BDMA_DIRECTION_MEMORY_TO_MEMORY))
  45. #define IS_LL_BDMA_MODE(__VALUE__) (((__VALUE__) == LL_BDMA_MODE_NORMAL) || \
  46. ((__VALUE__) == LL_BDMA_MODE_CIRCULAR))
  47. #define IS_LL_BDMA_PERIPHINCMODE(__VALUE__) (((__VALUE__) == LL_BDMA_PERIPH_INCREMENT) || \
  48. ((__VALUE__) == LL_BDMA_PERIPH_NOINCREMENT))
  49. #define IS_LL_BDMA_MEMORYINCMODE(__VALUE__) (((__VALUE__) == LL_BDMA_MEMORY_INCREMENT) || \
  50. ((__VALUE__) == LL_BDMA_MEMORY_NOINCREMENT))
  51. #define IS_LL_BDMA_PERIPHDATASIZE(__VALUE__) (((__VALUE__) == LL_BDMA_PDATAALIGN_BYTE) || \
  52. ((__VALUE__) == LL_BDMA_PDATAALIGN_HALFWORD) || \
  53. ((__VALUE__) == LL_BDMA_PDATAALIGN_WORD))
  54. #define IS_LL_BDMA_MEMORYDATASIZE(__VALUE__) (((__VALUE__) == LL_BDMA_MDATAALIGN_BYTE) || \
  55. ((__VALUE__) == LL_BDMA_MDATAALIGN_HALFWORD) || \
  56. ((__VALUE__) == LL_BDMA_MDATAALIGN_WORD))
  57. #define IS_LL_BDMA_NBDATA(__VALUE__) ((__VALUE__) <= 0x0000FFFFU)
  58. #if defined(ADC3)
  59. #define IS_LL_BDMA_PERIPHREQUEST(__VALUE__) ((__VALUE__) <= LL_DMAMUX2_REQ_ADC3)
  60. #else
  61. #define IS_LL_BDMA_PERIPHREQUEST(__VALUE__) ((__VALUE__) <= LL_DMAMUX2_REQ_DFSDM2_FLT0)
  62. #endif /* ADC3 */
  63. #define IS_LL_BDMA_PRIORITY(__VALUE__) (((__VALUE__) == LL_BDMA_PRIORITY_LOW) || \
  64. ((__VALUE__) == LL_BDMA_PRIORITY_MEDIUM) || \
  65. ((__VALUE__) == LL_BDMA_PRIORITY_HIGH) || \
  66. ((__VALUE__) == LL_BDMA_PRIORITY_VERYHIGH))
  67. #define IS_LL_BDMA_ALL_CHANNEL_INSTANCE(INSTANCE, CHANNEL) ((((INSTANCE) == BDMA) && \
  68. (((CHANNEL) == LL_BDMA_CHANNEL_0) || \
  69. ((CHANNEL) == LL_BDMA_CHANNEL_1) || \
  70. ((CHANNEL) == LL_BDMA_CHANNEL_2) || \
  71. ((CHANNEL) == LL_BDMA_CHANNEL_3) || \
  72. ((CHANNEL) == LL_BDMA_CHANNEL_4) || \
  73. ((CHANNEL) == LL_BDMA_CHANNEL_5) || \
  74. ((CHANNEL) == LL_BDMA_CHANNEL_6) || \
  75. ((CHANNEL) == LL_BDMA_CHANNEL_7))))
  76. /**
  77. * @}
  78. */
  79. /* Private function prototypes -----------------------------------------------*/
  80. /* Exported functions --------------------------------------------------------*/
  81. /** @addtogroup BDMA_LL_Exported_Functions
  82. * @{
  83. */
  84. /** @addtogroup BDMA_LL_EF_Init
  85. * @{
  86. */
  87. /**
  88. * @brief De-initialize the DMA registers to their default reset values.
  89. * @param BDMAx BDMAx Instance
  90. * @param Channel This parameter can be one of the following values:
  91. * @arg @ref LL_BDMA_CHANNEL_0
  92. * @arg @ref LL_BDMA_CHANNEL_1
  93. * @arg @ref LL_BDMA_CHANNEL_2
  94. * @arg @ref LL_BDMA_CHANNEL_3
  95. * @arg @ref LL_BDMA_CHANNEL_4
  96. * @arg @ref LL_BDMA_CHANNEL_5
  97. * @arg @ref LL_BDMA_CHANNEL_6
  98. * @arg @ref LL_BDMA_CHANNEL_7
  99. * @arg @ref LL_BDMA_CHANNEL_ALL
  100. * @retval An ErrorStatus enumeration value:
  101. * - SUCCESS: DMA registers are de-initialized
  102. * - ERROR: DMA registers are not de-initialized
  103. */
  104. uint32_t LL_BDMA_DeInit(BDMA_TypeDef *BDMAx, uint32_t Channel)
  105. {
  106. BDMA_Channel_TypeDef *tmp ;
  107. ErrorStatus status = SUCCESS;
  108. /* Check the DMA Instance DMAx and Channel parameters */
  109. assert_param(IS_LL_BDMA_ALL_CHANNEL_INSTANCE(BDMAx, Channel) || (Channel == LL_BDMA_CHANNEL_ALL));
  110. if (Channel == LL_BDMA_CHANNEL_ALL)
  111. {
  112. if (BDMAx == BDMA)
  113. {
  114. /* Force reset of BDMA clock */
  115. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA1);
  116. /* Release reset of BDMA clock */
  117. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA1);
  118. }
  119. else
  120. {
  121. status = ERROR;
  122. }
  123. }
  124. else
  125. {
  126. tmp = (BDMA_Channel_TypeDef *)(__LL_BDMA_GET_CHANNEL_INSTANCE(BDMAx, Channel));
  127. /* Disable the selected DMAx_Channely */
  128. CLEAR_BIT(tmp->CCR, BDMA_CCR_EN);
  129. /* Reset DMAx_Channely control register */
  130. LL_BDMA_WriteReg(tmp, CCR, 0U);
  131. /* Reset DMAx_Channely remaining bytes register */
  132. LL_BDMA_WriteReg(tmp, CNDTR, 0U);
  133. /* Reset DMAx_Channely peripheral address register */
  134. LL_BDMA_WriteReg(tmp, CPAR, 0U);
  135. /* Reset DMAx_Channely memory 0 address register */
  136. LL_BDMA_WriteReg(tmp, CM0AR, 0U);
  137. /* Reset DMAx_Channely memory 1 address register */
  138. LL_BDMA_WriteReg(tmp, CM1AR, 0U);
  139. /* Reset Request register field for BDMAx Channel */
  140. LL_BDMA_SetPeriphRequest(BDMAx, Channel, LL_DMAMUX2_REQ_MEM2MEM);
  141. if (Channel == LL_BDMA_CHANNEL_0)
  142. {
  143. /* Reset interrupt pending bits for DMAx Channel0 */
  144. LL_BDMA_ClearFlag_GI0(BDMAx);
  145. }
  146. else if (Channel == LL_BDMA_CHANNEL_1)
  147. {
  148. /* Reset interrupt pending bits for DMAx Channel1 */
  149. LL_BDMA_ClearFlag_GI1(BDMAx);
  150. }
  151. else if (Channel == LL_BDMA_CHANNEL_2)
  152. {
  153. /* Reset interrupt pending bits for DMAx Channel2 */
  154. LL_BDMA_ClearFlag_GI2(BDMAx);
  155. }
  156. else if (Channel == LL_BDMA_CHANNEL_3)
  157. {
  158. /* Reset interrupt pending bits for DMAx Channel3 */
  159. LL_BDMA_ClearFlag_GI3(BDMAx);
  160. }
  161. else if (Channel == LL_BDMA_CHANNEL_4)
  162. {
  163. /* Reset interrupt pending bits for DMAx Channel4 */
  164. LL_BDMA_ClearFlag_GI4(BDMAx);
  165. }
  166. else if (Channel == LL_BDMA_CHANNEL_5)
  167. {
  168. /* Reset interrupt pending bits for DMAx Channel5 */
  169. LL_BDMA_ClearFlag_GI5(BDMAx);
  170. }
  171. else if (Channel == LL_BDMA_CHANNEL_6)
  172. {
  173. /* Reset interrupt pending bits for DMAx Channel6 */
  174. LL_BDMA_ClearFlag_GI6(BDMAx);
  175. }
  176. else if (Channel == LL_BDMA_CHANNEL_7)
  177. {
  178. /* Reset interrupt pending bits for DMAx Channel7 */
  179. LL_BDMA_ClearFlag_GI7(BDMAx);
  180. }
  181. else
  182. {
  183. status = ERROR;
  184. }
  185. }
  186. return (uint32_t)status;
  187. }
  188. /**
  189. * @brief Initialize the BDMA registers according to the specified parameters in BDMA_InitStruct.
  190. * @note To convert BDMAx_Channely Instance to BDMAx Instance and Channely, use helper macros :
  191. * @arg @ref __LL_BDMA_GET_INSTANCE
  192. * @arg @ref __LL_BDMA_GET_CHANNEL
  193. * @param BDMAx BDMAx Instance
  194. * @param Channel This parameter can be one of the following values:
  195. * @arg @ref LL_BDMA_CHANNEL_0
  196. * @arg @ref LL_BDMA_CHANNEL_1
  197. * @arg @ref LL_BDMA_CHANNEL_2
  198. * @arg @ref LL_BDMA_CHANNEL_3
  199. * @arg @ref LL_BDMA_CHANNEL_4
  200. * @arg @ref LL_BDMA_CHANNEL_5
  201. * @arg @ref LL_BDMA_CHANNEL_6
  202. * @arg @ref LL_BDMA_CHANNEL_7
  203. * @param BDMA_InitStruct pointer to a @ref LL_BDMA_InitTypeDef structure.
  204. * @retval An ErrorStatus enumeration value:
  205. * - SUCCESS: DMA registers are initialized
  206. * - ERROR: Not applicable
  207. */
  208. uint32_t LL_BDMA_Init(BDMA_TypeDef *BDMAx, uint32_t Channel, LL_BDMA_InitTypeDef *BDMA_InitStruct)
  209. {
  210. /* Check the DMA Instance DMAx and Channel parameters */
  211. assert_param(IS_LL_BDMA_ALL_CHANNEL_INSTANCE(BDMAx, Channel));
  212. /* Check the DMA parameters from BDMA_InitStruct */
  213. assert_param(IS_LL_BDMA_DIRECTION(BDMA_InitStruct->Direction));
  214. assert_param(IS_LL_BDMA_MODE(BDMA_InitStruct->Mode));
  215. assert_param(IS_LL_BDMA_PERIPHINCMODE(BDMA_InitStruct->PeriphOrM2MSrcIncMode));
  216. assert_param(IS_LL_BDMA_MEMORYINCMODE(BDMA_InitStruct->MemoryOrM2MDstIncMode));
  217. assert_param(IS_LL_BDMA_PERIPHDATASIZE(BDMA_InitStruct->PeriphOrM2MSrcDataSize));
  218. assert_param(IS_LL_BDMA_MEMORYDATASIZE(BDMA_InitStruct->MemoryOrM2MDstDataSize));
  219. assert_param(IS_LL_BDMA_NBDATA(BDMA_InitStruct->NbData));
  220. assert_param(IS_LL_BDMA_PERIPHREQUEST(BDMA_InitStruct->PeriphRequest));
  221. assert_param(IS_LL_BDMA_PRIORITY(BDMA_InitStruct->Priority));
  222. /*---------------------------- DMAx CCR Configuration ------------------------
  223. * Configure DMAx_Channely: data transfer direction, data transfer mode,
  224. * peripheral and memory increment mode,
  225. * data size alignment and priority level with parameters :
  226. * - Direction: BDMA_CCR_DIR and BDMA_CCR_MEM2MEM bits
  227. * - Mode: BDMA_CCR_CIRC bit
  228. * - PeriphOrM2MSrcIncMode: BDMA_CCR_PINC bit
  229. * - MemoryOrM2MDstIncMode: BDMA_CCR_MINC bit
  230. * - PeriphOrM2MSrcDataSize: BDMA_CCR_PSIZE[1:0] bits
  231. * - MemoryOrM2MDstDataSize: BDMA_CCR_MSIZE[1:0] bits
  232. * - Priority: BDMA_CCR_PL[1:0] bits
  233. */
  234. LL_BDMA_ConfigTransfer(BDMAx, Channel, BDMA_InitStruct->Direction | \
  235. BDMA_InitStruct->Mode | \
  236. BDMA_InitStruct->PeriphOrM2MSrcIncMode | \
  237. BDMA_InitStruct->MemoryOrM2MDstIncMode | \
  238. BDMA_InitStruct->PeriphOrM2MSrcDataSize | \
  239. BDMA_InitStruct->MemoryOrM2MDstDataSize | \
  240. BDMA_InitStruct->Priority);
  241. /*-------------------------- DMAx CMAR Configuration -------------------------
  242. * Configure the memory or destination base address with parameter :
  243. * - MemoryOrM2MDstAddress: BDMA_CMAR_MA[31:0] bits
  244. */
  245. LL_BDMA_SetMemoryAddress(BDMAx, Channel, BDMA_InitStruct->MemoryOrM2MDstAddress);
  246. /*-------------------------- DMAx CPAR Configuration -------------------------
  247. * Configure the peripheral or source base address with parameter :
  248. * - PeriphOrM2MSrcAddress: BDMA_CPAR_PA[31:0] bits
  249. */
  250. LL_BDMA_SetPeriphAddress(BDMAx, Channel, BDMA_InitStruct->PeriphOrM2MSrcAddress);
  251. /*--------------------------- DMAx CNDTR Configuration -----------------------
  252. * Configure the peripheral base address with parameter :
  253. * - NbData: BDMA_CNDTR_NDT[15:0] bits
  254. */
  255. LL_BDMA_SetDataLength(BDMAx, Channel, BDMA_InitStruct->NbData);
  256. /*--------------------------- DMAMUXx CCR Configuration ----------------------
  257. * Configure the DMA request for DMA Channels on DMAMUX Channel x with parameter :
  258. * - PeriphRequest: BDMA_CxCR[7:0] bits
  259. */
  260. LL_BDMA_SetPeriphRequest(BDMAx, Channel, BDMA_InitStruct->PeriphRequest);
  261. return (uint32_t)SUCCESS;
  262. }
  263. /**
  264. * @brief Set each @ref LL_BDMA_InitTypeDef field to default value.
  265. * @param BDMA_InitStruct Pointer to a @ref LL_BDMA_InitTypeDef structure.
  266. * @retval None
  267. */
  268. void LL_BDMA_StructInit(LL_BDMA_InitTypeDef *BDMA_InitStruct)
  269. {
  270. /* Set BDMA_InitStruct fields to default values */
  271. BDMA_InitStruct->PeriphOrM2MSrcAddress = 0x00000000U;
  272. BDMA_InitStruct->MemoryOrM2MDstAddress = 0x00000000U;
  273. BDMA_InitStruct->Direction = LL_BDMA_DIRECTION_PERIPH_TO_MEMORY;
  274. BDMA_InitStruct->Mode = LL_BDMA_MODE_NORMAL;
  275. BDMA_InitStruct->PeriphOrM2MSrcIncMode = LL_BDMA_PERIPH_NOINCREMENT;
  276. BDMA_InitStruct->MemoryOrM2MDstIncMode = LL_BDMA_MEMORY_NOINCREMENT;
  277. BDMA_InitStruct->PeriphOrM2MSrcDataSize = LL_BDMA_PDATAALIGN_BYTE;
  278. BDMA_InitStruct->MemoryOrM2MDstDataSize = LL_BDMA_MDATAALIGN_BYTE;
  279. BDMA_InitStruct->NbData = 0x00000000U;
  280. BDMA_InitStruct->PeriphRequest = LL_DMAMUX2_REQ_MEM2MEM;
  281. BDMA_InitStruct->Priority = LL_BDMA_PRIORITY_LOW;
  282. }
  283. /**
  284. * @}
  285. */
  286. /**
  287. * @}
  288. */
  289. /**
  290. * @}
  291. */
  292. #endif /* BDMA || BDMA1 || BDMA2 */
  293. /**
  294. * @}
  295. */
  296. #endif /* USE_FULL_LL_DRIVER */
  297. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/