训练营PLSR题目
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

424 řádky
18 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_dma.c
  4. * @author MCD Application Team
  5. * @brief DMA LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file in
  13. * the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. #if defined(USE_FULL_LL_DRIVER)
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32f4xx_ll_dma.h"
  21. #include "stm32f4xx_ll_bus.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif
  27. /** @addtogroup STM32F4xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (DMA1) || defined (DMA2)
  31. /** @defgroup DMA_LL DMA
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /** @addtogroup DMA_LL_Private_Macros
  39. * @{
  40. */
  41. #define IS_LL_DMA_DIRECTION(__VALUE__) (((__VALUE__) == LL_DMA_DIRECTION_PERIPH_TO_MEMORY) || \
  42. ((__VALUE__) == LL_DMA_DIRECTION_MEMORY_TO_PERIPH) || \
  43. ((__VALUE__) == LL_DMA_DIRECTION_MEMORY_TO_MEMORY))
  44. #define IS_LL_DMA_MODE(__VALUE__) (((__VALUE__) == LL_DMA_MODE_NORMAL) || \
  45. ((__VALUE__) == LL_DMA_MODE_CIRCULAR) || \
  46. ((__VALUE__) == LL_DMA_MODE_PFCTRL))
  47. #define IS_LL_DMA_PERIPHINCMODE(__VALUE__) (((__VALUE__) == LL_DMA_PERIPH_INCREMENT) || \
  48. ((__VALUE__) == LL_DMA_PERIPH_NOINCREMENT))
  49. #define IS_LL_DMA_MEMORYINCMODE(__VALUE__) (((__VALUE__) == LL_DMA_MEMORY_INCREMENT) || \
  50. ((__VALUE__) == LL_DMA_MEMORY_NOINCREMENT))
  51. #define IS_LL_DMA_PERIPHDATASIZE(__VALUE__) (((__VALUE__) == LL_DMA_PDATAALIGN_BYTE) || \
  52. ((__VALUE__) == LL_DMA_PDATAALIGN_HALFWORD) || \
  53. ((__VALUE__) == LL_DMA_PDATAALIGN_WORD))
  54. #define IS_LL_DMA_MEMORYDATASIZE(__VALUE__) (((__VALUE__) == LL_DMA_MDATAALIGN_BYTE) || \
  55. ((__VALUE__) == LL_DMA_MDATAALIGN_HALFWORD) || \
  56. ((__VALUE__) == LL_DMA_MDATAALIGN_WORD))
  57. #define IS_LL_DMA_NBDATA(__VALUE__) ((__VALUE__) <= 0x0000FFFFU)
  58. #define IS_LL_DMA_CHANNEL(__VALUE__) (((__VALUE__) == LL_DMA_CHANNEL_0) || \
  59. ((__VALUE__) == LL_DMA_CHANNEL_1) || \
  60. ((__VALUE__) == LL_DMA_CHANNEL_2) || \
  61. ((__VALUE__) == LL_DMA_CHANNEL_3) || \
  62. ((__VALUE__) == LL_DMA_CHANNEL_4) || \
  63. ((__VALUE__) == LL_DMA_CHANNEL_5) || \
  64. ((__VALUE__) == LL_DMA_CHANNEL_6) || \
  65. ((__VALUE__) == LL_DMA_CHANNEL_7))
  66. #define IS_LL_DMA_PRIORITY(__VALUE__) (((__VALUE__) == LL_DMA_PRIORITY_LOW) || \
  67. ((__VALUE__) == LL_DMA_PRIORITY_MEDIUM) || \
  68. ((__VALUE__) == LL_DMA_PRIORITY_HIGH) || \
  69. ((__VALUE__) == LL_DMA_PRIORITY_VERYHIGH))
  70. #define IS_LL_DMA_ALL_STREAM_INSTANCE(INSTANCE, STREAM) ((((INSTANCE) == DMA1) && \
  71. (((STREAM) == LL_DMA_STREAM_0) || \
  72. ((STREAM) == LL_DMA_STREAM_1) || \
  73. ((STREAM) == LL_DMA_STREAM_2) || \
  74. ((STREAM) == LL_DMA_STREAM_3) || \
  75. ((STREAM) == LL_DMA_STREAM_4) || \
  76. ((STREAM) == LL_DMA_STREAM_5) || \
  77. ((STREAM) == LL_DMA_STREAM_6) || \
  78. ((STREAM) == LL_DMA_STREAM_7) || \
  79. ((STREAM) == LL_DMA_STREAM_ALL))) ||\
  80. (((INSTANCE) == DMA2) && \
  81. (((STREAM) == LL_DMA_STREAM_0) || \
  82. ((STREAM) == LL_DMA_STREAM_1) || \
  83. ((STREAM) == LL_DMA_STREAM_2) || \
  84. ((STREAM) == LL_DMA_STREAM_3) || \
  85. ((STREAM) == LL_DMA_STREAM_4) || \
  86. ((STREAM) == LL_DMA_STREAM_5) || \
  87. ((STREAM) == LL_DMA_STREAM_6) || \
  88. ((STREAM) == LL_DMA_STREAM_7) || \
  89. ((STREAM) == LL_DMA_STREAM_ALL))))
  90. #define IS_LL_DMA_FIFO_MODE_STATE(STATE) (((STATE) == LL_DMA_FIFOMODE_DISABLE ) || \
  91. ((STATE) == LL_DMA_FIFOMODE_ENABLE))
  92. #define IS_LL_DMA_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == LL_DMA_FIFOTHRESHOLD_1_4) || \
  93. ((THRESHOLD) == LL_DMA_FIFOTHRESHOLD_1_2) || \
  94. ((THRESHOLD) == LL_DMA_FIFOTHRESHOLD_3_4) || \
  95. ((THRESHOLD) == LL_DMA_FIFOTHRESHOLD_FULL))
  96. #define IS_LL_DMA_MEMORY_BURST(BURST) (((BURST) == LL_DMA_MBURST_SINGLE) || \
  97. ((BURST) == LL_DMA_MBURST_INC4) || \
  98. ((BURST) == LL_DMA_MBURST_INC8) || \
  99. ((BURST) == LL_DMA_MBURST_INC16))
  100. #define IS_LL_DMA_PERIPHERAL_BURST(BURST) (((BURST) == LL_DMA_PBURST_SINGLE) || \
  101. ((BURST) == LL_DMA_PBURST_INC4) || \
  102. ((BURST) == LL_DMA_PBURST_INC8) || \
  103. ((BURST) == LL_DMA_PBURST_INC16))
  104. /**
  105. * @}
  106. */
  107. /* Private function prototypes -----------------------------------------------*/
  108. /* Exported functions --------------------------------------------------------*/
  109. /** @addtogroup DMA_LL_Exported_Functions
  110. * @{
  111. */
  112. /** @addtogroup DMA_LL_EF_Init
  113. * @{
  114. */
  115. /**
  116. * @brief De-initialize the DMA registers to their default reset values.
  117. * @param DMAx DMAx Instance
  118. * @param Stream This parameter can be one of the following values:
  119. * @arg @ref LL_DMA_STREAM_0
  120. * @arg @ref LL_DMA_STREAM_1
  121. * @arg @ref LL_DMA_STREAM_2
  122. * @arg @ref LL_DMA_STREAM_3
  123. * @arg @ref LL_DMA_STREAM_4
  124. * @arg @ref LL_DMA_STREAM_5
  125. * @arg @ref LL_DMA_STREAM_6
  126. * @arg @ref LL_DMA_STREAM_7
  127. * @arg @ref LL_DMA_STREAM_ALL
  128. * @retval An ErrorStatus enumeration value:
  129. * - SUCCESS: DMA registers are de-initialized
  130. * - ERROR: DMA registers are not de-initialized
  131. */
  132. uint32_t LL_DMA_DeInit(DMA_TypeDef *DMAx, uint32_t Stream)
  133. {
  134. DMA_Stream_TypeDef *tmp = (DMA_Stream_TypeDef *)DMA1_Stream0;
  135. ErrorStatus status = SUCCESS;
  136. /* Check the DMA Instance DMAx and Stream parameters*/
  137. assert_param(IS_LL_DMA_ALL_STREAM_INSTANCE(DMAx, Stream));
  138. if (Stream == LL_DMA_STREAM_ALL)
  139. {
  140. if (DMAx == DMA1)
  141. {
  142. /* Force reset of DMA clock */
  143. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA1);
  144. /* Release reset of DMA clock */
  145. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA1);
  146. }
  147. else if (DMAx == DMA2)
  148. {
  149. /* Force reset of DMA clock */
  150. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA2);
  151. /* Release reset of DMA clock */
  152. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA2);
  153. }
  154. else
  155. {
  156. status = ERROR;
  157. }
  158. }
  159. else
  160. {
  161. /* Disable the selected Stream */
  162. LL_DMA_DisableStream(DMAx,Stream);
  163. /* Get the DMA Stream Instance */
  164. tmp = (DMA_Stream_TypeDef *)(__LL_DMA_GET_STREAM_INSTANCE(DMAx, Stream));
  165. /* Reset DMAx_Streamy configuration register */
  166. LL_DMA_WriteReg(tmp, CR, 0U);
  167. /* Reset DMAx_Streamy remaining bytes register */
  168. LL_DMA_WriteReg(tmp, NDTR, 0U);
  169. /* Reset DMAx_Streamy peripheral address register */
  170. LL_DMA_WriteReg(tmp, PAR, 0U);
  171. /* Reset DMAx_Streamy memory address register */
  172. LL_DMA_WriteReg(tmp, M0AR, 0U);
  173. /* Reset DMAx_Streamy memory address register */
  174. LL_DMA_WriteReg(tmp, M1AR, 0U);
  175. /* Reset DMAx_Streamy FIFO control register */
  176. LL_DMA_WriteReg(tmp, FCR, 0x00000021U);
  177. /* Reset Channel register field for DMAx Stream*/
  178. LL_DMA_SetChannelSelection(DMAx, Stream, LL_DMA_CHANNEL_0);
  179. if(Stream == LL_DMA_STREAM_0)
  180. {
  181. /* Reset the Stream0 pending flags */
  182. DMAx->LIFCR = 0x0000003FU;
  183. }
  184. else if(Stream == LL_DMA_STREAM_1)
  185. {
  186. /* Reset the Stream1 pending flags */
  187. DMAx->LIFCR = 0x00000F40U;
  188. }
  189. else if(Stream == LL_DMA_STREAM_2)
  190. {
  191. /* Reset the Stream2 pending flags */
  192. DMAx->LIFCR = 0x003F0000U;
  193. }
  194. else if(Stream == LL_DMA_STREAM_3)
  195. {
  196. /* Reset the Stream3 pending flags */
  197. DMAx->LIFCR = 0x0F400000U;
  198. }
  199. else if(Stream == LL_DMA_STREAM_4)
  200. {
  201. /* Reset the Stream4 pending flags */
  202. DMAx->HIFCR = 0x0000003FU;
  203. }
  204. else if(Stream == LL_DMA_STREAM_5)
  205. {
  206. /* Reset the Stream5 pending flags */
  207. DMAx->HIFCR = 0x00000F40U;
  208. }
  209. else if(Stream == LL_DMA_STREAM_6)
  210. {
  211. /* Reset the Stream6 pending flags */
  212. DMAx->HIFCR = 0x003F0000U;
  213. }
  214. else if(Stream == LL_DMA_STREAM_7)
  215. {
  216. /* Reset the Stream7 pending flags */
  217. DMAx->HIFCR = 0x0F400000U;
  218. }
  219. else
  220. {
  221. status = ERROR;
  222. }
  223. }
  224. return status;
  225. }
  226. /**
  227. * @brief Initialize the DMA registers according to the specified parameters in DMA_InitStruct.
  228. * @note To convert DMAx_Streamy Instance to DMAx Instance and Streamy, use helper macros :
  229. * @arg @ref __LL_DMA_GET_INSTANCE
  230. * @arg @ref __LL_DMA_GET_STREAM
  231. * @param DMAx DMAx Instance
  232. * @param Stream This parameter can be one of the following values:
  233. * @arg @ref LL_DMA_STREAM_0
  234. * @arg @ref LL_DMA_STREAM_1
  235. * @arg @ref LL_DMA_STREAM_2
  236. * @arg @ref LL_DMA_STREAM_3
  237. * @arg @ref LL_DMA_STREAM_4
  238. * @arg @ref LL_DMA_STREAM_5
  239. * @arg @ref LL_DMA_STREAM_6
  240. * @arg @ref LL_DMA_STREAM_7
  241. * @param DMA_InitStruct pointer to a @ref LL_DMA_InitTypeDef structure.
  242. * @retval An ErrorStatus enumeration value:
  243. * - SUCCESS: DMA registers are initialized
  244. * - ERROR: Not applicable
  245. */
  246. uint32_t LL_DMA_Init(DMA_TypeDef *DMAx, uint32_t Stream, LL_DMA_InitTypeDef *DMA_InitStruct)
  247. {
  248. /* Check the DMA Instance DMAx and Stream parameters*/
  249. assert_param(IS_LL_DMA_ALL_STREAM_INSTANCE(DMAx, Stream));
  250. /* Check the DMA parameters from DMA_InitStruct */
  251. assert_param(IS_LL_DMA_DIRECTION(DMA_InitStruct->Direction));
  252. assert_param(IS_LL_DMA_MODE(DMA_InitStruct->Mode));
  253. assert_param(IS_LL_DMA_PERIPHINCMODE(DMA_InitStruct->PeriphOrM2MSrcIncMode));
  254. assert_param(IS_LL_DMA_MEMORYINCMODE(DMA_InitStruct->MemoryOrM2MDstIncMode));
  255. assert_param(IS_LL_DMA_PERIPHDATASIZE(DMA_InitStruct->PeriphOrM2MSrcDataSize));
  256. assert_param(IS_LL_DMA_MEMORYDATASIZE(DMA_InitStruct->MemoryOrM2MDstDataSize));
  257. assert_param(IS_LL_DMA_NBDATA(DMA_InitStruct->NbData));
  258. assert_param(IS_LL_DMA_CHANNEL(DMA_InitStruct->Channel));
  259. assert_param(IS_LL_DMA_PRIORITY(DMA_InitStruct->Priority));
  260. assert_param(IS_LL_DMA_FIFO_MODE_STATE(DMA_InitStruct->FIFOMode));
  261. /* Check the memory burst, peripheral burst and FIFO threshold parameters only
  262. when FIFO mode is enabled */
  263. if(DMA_InitStruct->FIFOMode != LL_DMA_FIFOMODE_DISABLE)
  264. {
  265. assert_param(IS_LL_DMA_FIFO_THRESHOLD(DMA_InitStruct->FIFOThreshold));
  266. assert_param(IS_LL_DMA_MEMORY_BURST(DMA_InitStruct->MemBurst));
  267. assert_param(IS_LL_DMA_PERIPHERAL_BURST(DMA_InitStruct->PeriphBurst));
  268. }
  269. /*---------------------------- DMAx SxCR Configuration ------------------------
  270. * Configure DMAx_Streamy: data transfer direction, data transfer mode,
  271. * peripheral and memory increment mode,
  272. * data size alignment and priority level with parameters :
  273. * - Direction: DMA_SxCR_DIR[1:0] bits
  274. * - Mode: DMA_SxCR_CIRC bit
  275. * - PeriphOrM2MSrcIncMode: DMA_SxCR_PINC bit
  276. * - MemoryOrM2MDstIncMode: DMA_SxCR_MINC bit
  277. * - PeriphOrM2MSrcDataSize: DMA_SxCR_PSIZE[1:0] bits
  278. * - MemoryOrM2MDstDataSize: DMA_SxCR_MSIZE[1:0] bits
  279. * - Priority: DMA_SxCR_PL[1:0] bits
  280. */
  281. LL_DMA_ConfigTransfer(DMAx, Stream, DMA_InitStruct->Direction | \
  282. DMA_InitStruct->Mode | \
  283. DMA_InitStruct->PeriphOrM2MSrcIncMode | \
  284. DMA_InitStruct->MemoryOrM2MDstIncMode | \
  285. DMA_InitStruct->PeriphOrM2MSrcDataSize | \
  286. DMA_InitStruct->MemoryOrM2MDstDataSize | \
  287. DMA_InitStruct->Priority
  288. );
  289. if(DMA_InitStruct->FIFOMode != LL_DMA_FIFOMODE_DISABLE)
  290. {
  291. /*---------------------------- DMAx SxFCR Configuration ------------------------
  292. * Configure DMAx_Streamy: fifo mode and fifo threshold with parameters :
  293. * - FIFOMode: DMA_SxFCR_DMDIS bit
  294. * - FIFOThreshold: DMA_SxFCR_FTH[1:0] bits
  295. */
  296. LL_DMA_ConfigFifo(DMAx, Stream, DMA_InitStruct->FIFOMode, DMA_InitStruct->FIFOThreshold);
  297. /*---------------------------- DMAx SxCR Configuration --------------------------
  298. * Configure DMAx_Streamy: memory burst transfer with parameters :
  299. * - MemBurst: DMA_SxCR_MBURST[1:0] bits
  300. */
  301. LL_DMA_SetMemoryBurstxfer(DMAx,Stream,DMA_InitStruct->MemBurst);
  302. /*---------------------------- DMAx SxCR Configuration --------------------------
  303. * Configure DMAx_Streamy: peripheral burst transfer with parameters :
  304. * - PeriphBurst: DMA_SxCR_PBURST[1:0] bits
  305. */
  306. LL_DMA_SetPeriphBurstxfer(DMAx,Stream,DMA_InitStruct->PeriphBurst);
  307. }
  308. /*-------------------------- DMAx SxM0AR Configuration --------------------------
  309. * Configure the memory or destination base address with parameter :
  310. * - MemoryOrM2MDstAddress: DMA_SxM0AR_M0A[31:0] bits
  311. */
  312. LL_DMA_SetMemoryAddress(DMAx, Stream, DMA_InitStruct->MemoryOrM2MDstAddress);
  313. /*-------------------------- DMAx SxPAR Configuration ---------------------------
  314. * Configure the peripheral or source base address with parameter :
  315. * - PeriphOrM2MSrcAddress: DMA_SxPAR_PA[31:0] bits
  316. */
  317. LL_DMA_SetPeriphAddress(DMAx, Stream, DMA_InitStruct->PeriphOrM2MSrcAddress);
  318. /*--------------------------- DMAx SxNDTR Configuration -------------------------
  319. * Configure the peripheral base address with parameter :
  320. * - NbData: DMA_SxNDT[15:0] bits
  321. */
  322. LL_DMA_SetDataLength(DMAx, Stream, DMA_InitStruct->NbData);
  323. /*--------------------------- DMA SxCR_CHSEL Configuration ----------------------
  324. * Configure the peripheral base address with parameter :
  325. * - PeriphRequest: DMA_SxCR_CHSEL[2:0] bits
  326. */
  327. LL_DMA_SetChannelSelection(DMAx, Stream, DMA_InitStruct->Channel);
  328. return SUCCESS;
  329. }
  330. /**
  331. * @brief Set each @ref LL_DMA_InitTypeDef field to default value.
  332. * @param DMA_InitStruct Pointer to a @ref LL_DMA_InitTypeDef structure.
  333. * @retval None
  334. */
  335. void LL_DMA_StructInit(LL_DMA_InitTypeDef *DMA_InitStruct)
  336. {
  337. /* Set DMA_InitStruct fields to default values */
  338. DMA_InitStruct->PeriphOrM2MSrcAddress = 0x00000000U;
  339. DMA_InitStruct->MemoryOrM2MDstAddress = 0x00000000U;
  340. DMA_InitStruct->Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY;
  341. DMA_InitStruct->Mode = LL_DMA_MODE_NORMAL;
  342. DMA_InitStruct->PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
  343. DMA_InitStruct->MemoryOrM2MDstIncMode = LL_DMA_MEMORY_NOINCREMENT;
  344. DMA_InitStruct->PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_BYTE;
  345. DMA_InitStruct->MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_BYTE;
  346. DMA_InitStruct->NbData = 0x00000000U;
  347. DMA_InitStruct->Channel = LL_DMA_CHANNEL_0;
  348. DMA_InitStruct->Priority = LL_DMA_PRIORITY_LOW;
  349. DMA_InitStruct->FIFOMode = LL_DMA_FIFOMODE_DISABLE;
  350. DMA_InitStruct->FIFOThreshold = LL_DMA_FIFOTHRESHOLD_1_4;
  351. DMA_InitStruct->MemBurst = LL_DMA_MBURST_SINGLE;
  352. DMA_InitStruct->PeriphBurst = LL_DMA_PBURST_SINGLE;
  353. }
  354. /**
  355. * @}
  356. */
  357. /**
  358. * @}
  359. */
  360. /**
  361. * @}
  362. */
  363. #endif /* DMA1 || DMA2 */
  364. /**
  365. * @}
  366. */
  367. #endif /* USE_FULL_LL_DRIVER */