stm32f4xx_hal_dcmi.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_dcmi.c
  4. * @author MCD Application Team
  5. * @brief DCMI HAL module driver
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Digital Camera Interface (DCMI) peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State and Error functions
  12. *
  13. @verbatim
  14. ==============================================================================
  15. ##### How to use this driver #####
  16. ==============================================================================
  17. [..]
  18. The sequence below describes how to use this driver to capture image
  19. from a camera module connected to the DCMI Interface.
  20. This sequence does not take into account the configuration of the
  21. camera module, which should be made before to configure and enable
  22. the DCMI to capture images.
  23. (#) Program the required configuration through following parameters:
  24. horizontal and vertical polarity, pixel clock polarity, Capture Rate,
  25. Synchronization Mode, code of the frame delimiter and data width
  26. using HAL_DCMI_Init() function.
  27. (#) Configure the DMA2_Stream1 channel1 to transfer Data from DCMI DR
  28. register to the destination memory buffer.
  29. (#) Program the required configuration through following parameters:
  30. DCMI mode, destination memory Buffer address and the data length
  31. and enable capture using HAL_DCMI_Start_DMA() function.
  32. (#) Optionally, configure and Enable the CROP feature to select a rectangular
  33. window from the received image using HAL_DCMI_ConfigCrop()
  34. and HAL_DCMI_EnableCROP() functions
  35. (#) The capture can be stopped using HAL_DCMI_Stop() function.
  36. (#) To control DCMI state you can use the function HAL_DCMI_GetState().
  37. *** DCMI HAL driver macros list ***
  38. =============================================
  39. [..]
  40. Below the list of most used macros in DCMI HAL driver.
  41. (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral.
  42. (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral.
  43. (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags.
  44. (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags.
  45. (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts.
  46. (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts.
  47. (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not.
  48. [..]
  49. (@) You can refer to the DCMI HAL driver header file for more useful macros
  50. *** Callback registration ***
  51. =============================
  52. The compilation define USE_HAL_DCMI_REGISTER_CALLBACKS when set to 1
  53. allows the user to configure dynamically the driver callbacks.
  54. Use functions @ref HAL_DCMI_RegisterCallback() to register a user callback.
  55. Function @ref HAL_DCMI_RegisterCallback() allows to register following callbacks:
  56. (+) FrameEventCallback : DCMI Frame Event.
  57. (+) VsyncEventCallback : DCMI Vsync Event.
  58. (+) LineEventCallback : DCMI Line Event.
  59. (+) ErrorCallback : DCMI error.
  60. (+) MspInitCallback : DCMI MspInit.
  61. (+) MspDeInitCallback : DCMI MspDeInit.
  62. This function takes as parameters the HAL peripheral handle, the callback ID
  63. and a pointer to the user callback function.
  64. Use function @ref HAL_DCMI_UnRegisterCallback() to reset a callback to the default
  65. weak (surcharged) function.
  66. @ref HAL_DCMI_UnRegisterCallback() takes as parameters the HAL peripheral handle,
  67. and the callback ID.
  68. This function allows to reset following callbacks:
  69. (+) FrameEventCallback : DCMI Frame Event.
  70. (+) VsyncEventCallback : DCMI Vsync Event.
  71. (+) LineEventCallback : DCMI Line Event.
  72. (+) ErrorCallback : DCMI error.
  73. (+) MspInitCallback : DCMI MspInit.
  74. (+) MspDeInitCallback : DCMI MspDeInit.
  75. By default, after the @ref HAL_DCMI_Init and if the state is HAL_DCMI_STATE_RESET
  76. all callbacks are reset to the corresponding legacy weak (surcharged) functions:
  77. examples @ref FrameEventCallback(), @ref HAL_DCMI_ErrorCallback().
  78. Exception done for MspInit and MspDeInit callbacks that are respectively
  79. reset to the legacy weak (surcharged) functions in the @ref HAL_DCMI_Init
  80. and @ref HAL_DCMI_DeInit only when these callbacks are null (not registered beforehand).
  81. If not, MspInit or MspDeInit are not null, the @ref HAL_DCMI_Init and @ref HAL_DCMI_DeInit
  82. keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
  83. Callbacks can be registered/unregistered in READY state only.
  84. Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
  85. in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
  86. during the Init/DeInit.
  87. In that case first register the MspInit/MspDeInit user callbacks
  88. using @ref HAL_DCMI_RegisterCallback before calling @ref HAL_DCMI_DeInit
  89. or @ref HAL_DCMI_Init function.
  90. When the compilation define USE_HAL_DCMI_REGISTER_CALLBACKS is set to 0 or
  91. not defined, the callback registering feature is not available
  92. and weak (surcharged) callbacks are used.
  93. @endverbatim
  94. ******************************************************************************
  95. * @attention
  96. *
  97. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  98. * All rights reserved.</center></h2>
  99. *
  100. * This software component is licensed by ST under BSD 3-Clause license,
  101. * the "License"; You may not use this file except in compliance with the
  102. * License. You may obtain a copy of the License at:
  103. * opensource.org/licenses/BSD-3-Clause
  104. *
  105. ******************************************************************************
  106. */
  107. /* Includes ------------------------------------------------------------------*/
  108. #include "stm32f4xx_hal.h"
  109. /** @addtogroup STM32F4xx_HAL_Driver
  110. * @{
  111. */
  112. /** @defgroup DCMI DCMI
  113. * @brief DCMI HAL module driver
  114. * @{
  115. */
  116. #ifdef HAL_DCMI_MODULE_ENABLED
  117. #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) ||\
  118. defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) ||\
  119. defined(STM32F479xx)
  120. /* Private typedef -----------------------------------------------------------*/
  121. /* Private define ------------------------------------------------------------*/
  122. #define HAL_TIMEOUT_DCMI_STOP 14U /* Set timeout to 1s */
  123. /* Private macro -------------------------------------------------------------*/
  124. /* Private variables ---------------------------------------------------------*/
  125. /* Private function prototypes -----------------------------------------------*/
  126. static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma);
  127. static void DCMI_DMAError(DMA_HandleTypeDef *hdma);
  128. /* Exported functions --------------------------------------------------------*/
  129. /** @defgroup DCMI_Exported_Functions DCMI Exported Functions
  130. * @{
  131. */
  132. /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
  133. * @brief Initialization and Configuration functions
  134. *
  135. @verbatim
  136. ===============================================================================
  137. ##### Initialization and Configuration functions #####
  138. ===============================================================================
  139. [..] This section provides functions allowing to:
  140. (+) Initialize and configure the DCMI
  141. (+) De-initialize the DCMI
  142. @endverbatim
  143. * @{
  144. */
  145. /**
  146. * @brief Initializes the DCMI according to the specified
  147. * parameters in the DCMI_InitTypeDef and create the associated handle.
  148. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  149. * the configuration information for DCMI.
  150. * @retval HAL status
  151. */
  152. __weak HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
  153. {
  154. /* Check the DCMI peripheral state */
  155. if(hdcmi == NULL)
  156. {
  157. return HAL_ERROR;
  158. }
  159. /* Check function parameters */
  160. assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
  161. assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
  162. assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
  163. assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
  164. assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
  165. assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
  166. assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
  167. assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
  168. if(hdcmi->State == HAL_DCMI_STATE_RESET)
  169. {
  170. /* Allocate lock resource and initialize it */
  171. hdcmi->Lock = HAL_UNLOCKED;
  172. /* Init the low level hardware */
  173. /* Init the DCMI Callback settings */
  174. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  175. hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
  176. hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
  177. hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
  178. hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
  179. if(hdcmi->MspInitCallback == NULL)
  180. {
  181. /* Legacy weak MspInit Callback */
  182. hdcmi->MspInitCallback = HAL_DCMI_MspInit;
  183. }
  184. /* Initialize the low level hardware (MSP) */
  185. hdcmi->MspInitCallback(hdcmi);
  186. #else
  187. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  188. HAL_DCMI_MspInit(hdcmi);
  189. #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
  190. HAL_DCMI_MspInit(hdcmi);
  191. }
  192. /* Change the DCMI state */
  193. hdcmi->State = HAL_DCMI_STATE_BUSY;
  194. /* Set DCMI parameters */
  195. /* Configures the HS, VS, DE and PC polarity */
  196. hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |
  197. DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |
  198. DCMI_CR_ESS);
  199. hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \
  200. hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \
  201. hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \
  202. hdcmi->Init.JPEGMode);
  203. if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
  204. {
  205. hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
  206. ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|
  207. ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |
  208. ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
  209. }
  210. /* Enable the Line, Vsync, Error and Overrun interrupts */
  211. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
  212. /* Update error code */
  213. hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
  214. /* Initialize the DCMI state*/
  215. hdcmi->State = HAL_DCMI_STATE_READY;
  216. return HAL_OK;
  217. }
  218. /**
  219. * @brief Deinitializes the DCMI peripheral registers to their default reset
  220. * values.
  221. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  222. * the configuration information for DCMI.
  223. * @retval HAL status
  224. */
  225. HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
  226. {
  227. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  228. if(hdcmi->MspDeInitCallback == NULL)
  229. {
  230. hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
  231. }
  232. /* De-Initialize the low level hardware (MSP) */
  233. hdcmi->MspDeInitCallback(hdcmi);
  234. #else
  235. /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
  236. HAL_DCMI_MspDeInit(hdcmi);
  237. #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
  238. /* Update error code */
  239. hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
  240. /* Initialize the DCMI state*/
  241. hdcmi->State = HAL_DCMI_STATE_RESET;
  242. /* Release Lock */
  243. __HAL_UNLOCK(hdcmi);
  244. return HAL_OK;
  245. }
  246. /**
  247. * @brief Initializes the DCMI MSP.
  248. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  249. * the configuration information for DCMI.
  250. * @retval None
  251. */
  252. __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
  253. {
  254. /* Prevent unused argument(s) compilation warning */
  255. UNUSED(hdcmi);
  256. /* NOTE : This function Should not be modified, when the callback is needed,
  257. the HAL_DCMI_MspInit could be implemented in the user file
  258. */
  259. }
  260. /**
  261. * @brief DeInitializes the DCMI MSP.
  262. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  263. * the configuration information for DCMI.
  264. * @retval None
  265. */
  266. __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
  267. {
  268. /* Prevent unused argument(s) compilation warning */
  269. UNUSED(hdcmi);
  270. /* NOTE : This function Should not be modified, when the callback is needed,
  271. the HAL_DCMI_MspDeInit could be implemented in the user file
  272. */
  273. }
  274. /**
  275. * @}
  276. */
  277. /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions
  278. * @brief IO operation functions
  279. *
  280. @verbatim
  281. ===============================================================================
  282. ##### IO operation functions #####
  283. ===============================================================================
  284. [..] This section provides functions allowing to:
  285. (+) Configure destination address and data length and
  286. Enables DCMI DMA request and enables DCMI capture
  287. (+) Stop the DCMI capture.
  288. (+) Handles DCMI interrupt request.
  289. @endverbatim
  290. * @{
  291. */
  292. /**
  293. * @brief Enables DCMI DMA request and enables DCMI capture
  294. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  295. * the configuration information for DCMI.
  296. * @param DCMI_Mode DCMI capture mode snapshot or continuous grab.
  297. * @param pData The destination memory Buffer address (LCD Frame buffer).
  298. * @param Length The length of capture to be transferred.
  299. * @retval HAL status
  300. */
  301. HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
  302. {
  303. /* Initialize the second memory address */
  304. uint32_t SecondMemAddress = 0U;
  305. /* Check function parameters */
  306. assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
  307. /* Process Locked */
  308. __HAL_LOCK(hdcmi);
  309. /* Lock the DCMI peripheral state */
  310. hdcmi->State = HAL_DCMI_STATE_BUSY;
  311. /* Enable DCMI by setting DCMIEN bit */
  312. __HAL_DCMI_ENABLE(hdcmi);
  313. /* Configure the DCMI Mode */
  314. hdcmi->Instance->CR &= ~(DCMI_CR_CM);
  315. hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode);
  316. /* Set the DMA memory0 conversion complete callback */
  317. hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt;
  318. /* Set the DMA error callback */
  319. hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
  320. /* Set the dma abort callback */
  321. hdcmi->DMA_Handle->XferAbortCallback = NULL;
  322. /* Reset transfer counters value */
  323. hdcmi->XferCount = 0U;
  324. hdcmi->XferTransferNumber = 0U;
  325. if(Length <= 0xFFFFU)
  326. {
  327. /* Enable the DMA Stream */
  328. HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length);
  329. }
  330. else /* DCMI_DOUBLE_BUFFER Mode */
  331. {
  332. /* Set the DMA memory1 conversion complete callback */
  333. hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt;
  334. /* Initialize transfer parameters */
  335. hdcmi->XferCount = 1U;
  336. hdcmi->XferSize = Length;
  337. hdcmi->pBuffPtr = pData;
  338. /* Get the number of buffer */
  339. while(hdcmi->XferSize > 0xFFFFU)
  340. {
  341. hdcmi->XferSize = (hdcmi->XferSize/2U);
  342. hdcmi->XferCount = hdcmi->XferCount*2U;
  343. }
  344. /* Update DCMI counter and transfer number*/
  345. hdcmi->XferCount = (hdcmi->XferCount - 2U);
  346. hdcmi->XferTransferNumber = hdcmi->XferCount;
  347. /* Update second memory address */
  348. SecondMemAddress = (uint32_t)(pData + (4U*hdcmi->XferSize));
  349. /* Start DMA multi buffer transfer */
  350. HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize);
  351. }
  352. /* Enable Capture */
  353. hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
  354. /* Release Lock */
  355. __HAL_UNLOCK(hdcmi);
  356. /* Return function status */
  357. return HAL_OK;
  358. }
  359. /**
  360. * @brief Disable DCMI DMA request and Disable DCMI capture
  361. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  362. * the configuration information for DCMI.
  363. * @retval HAL status
  364. */
  365. HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
  366. {
  367. __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP;
  368. HAL_StatusTypeDef status = HAL_OK;
  369. /* Process locked */
  370. __HAL_LOCK(hdcmi);
  371. /* Lock the DCMI peripheral state */
  372. hdcmi->State = HAL_DCMI_STATE_BUSY;
  373. /* Disable Capture */
  374. hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
  375. /* Check if the DCMI capture effectively disabled */
  376. do
  377. {
  378. if (count-- == 0U)
  379. {
  380. /* Update error code */
  381. hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
  382. status = HAL_TIMEOUT;
  383. break;
  384. }
  385. }
  386. while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U);
  387. /* Disable the DCMI */
  388. __HAL_DCMI_DISABLE(hdcmi);
  389. /* Disable the DMA */
  390. HAL_DMA_Abort(hdcmi->DMA_Handle);
  391. /* Update error code */
  392. hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
  393. /* Change DCMI state */
  394. hdcmi->State = HAL_DCMI_STATE_READY;
  395. /* Process Unlocked */
  396. __HAL_UNLOCK(hdcmi);
  397. /* Return function status */
  398. return status;
  399. }
  400. /**
  401. * @brief Suspend DCMI capture
  402. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  403. * the configuration information for DCMI.
  404. * @retval HAL status
  405. */
  406. HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi)
  407. {
  408. __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP;
  409. HAL_StatusTypeDef status = HAL_OK;
  410. /* Process locked */
  411. __HAL_LOCK(hdcmi);
  412. if(hdcmi->State == HAL_DCMI_STATE_BUSY)
  413. {
  414. /* Change DCMI state */
  415. hdcmi->State = HAL_DCMI_STATE_SUSPENDED;
  416. /* Disable Capture */
  417. hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
  418. /* Check if the DCMI capture effectively disabled */
  419. do
  420. {
  421. if (count-- == 0U)
  422. {
  423. /* Update error code */
  424. hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
  425. /* Change DCMI state */
  426. hdcmi->State = HAL_DCMI_STATE_READY;
  427. status = HAL_TIMEOUT;
  428. break;
  429. }
  430. }
  431. while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0);
  432. }
  433. /* Process Unlocked */
  434. __HAL_UNLOCK(hdcmi);
  435. /* Return function status */
  436. return status;
  437. }
  438. /**
  439. * @brief Resume DCMI capture
  440. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  441. * the configuration information for DCMI.
  442. * @retval HAL status
  443. */
  444. HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef* hdcmi)
  445. {
  446. /* Process locked */
  447. __HAL_LOCK(hdcmi);
  448. if(hdcmi->State == HAL_DCMI_STATE_SUSPENDED)
  449. {
  450. /* Change DCMI state */
  451. hdcmi->State = HAL_DCMI_STATE_BUSY;
  452. /* Disable Capture */
  453. hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
  454. }
  455. /* Process Unlocked */
  456. __HAL_UNLOCK(hdcmi);
  457. /* Return function status */
  458. return HAL_OK;
  459. }
  460. /**
  461. * @brief Handles DCMI interrupt request.
  462. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  463. * the configuration information for the DCMI.
  464. * @retval None
  465. */
  466. void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
  467. {
  468. uint32_t isr_value = READ_REG(hdcmi->Instance->MISR);
  469. /* Synchronization error interrupt management *******************************/
  470. if((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI)
  471. {
  472. /* Clear the Synchronization error flag */
  473. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
  474. /* Update error code */
  475. hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
  476. /* Change DCMI state */
  477. hdcmi->State = HAL_DCMI_STATE_ERROR;
  478. /* Set the synchronization error callback */
  479. hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
  480. /* Abort the DMA Transfer */
  481. HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
  482. }
  483. /* Overflow interrupt management ********************************************/
  484. if((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI)
  485. {
  486. /* Clear the Overflow flag */
  487. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
  488. /* Update error code */
  489. hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR;
  490. /* Change DCMI state */
  491. hdcmi->State = HAL_DCMI_STATE_ERROR;
  492. /* Set the overflow callback */
  493. hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
  494. /* Abort the DMA Transfer */
  495. HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
  496. }
  497. /* Line Interrupt management ************************************************/
  498. if((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI)
  499. {
  500. /* Clear the Line interrupt flag */
  501. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
  502. /* Line interrupt Callback */
  503. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  504. /*Call registered DCMI line event callback*/
  505. hdcmi->LineEventCallback(hdcmi);
  506. #else
  507. HAL_DCMI_LineEventCallback(hdcmi);
  508. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  509. }
  510. /* VSYNC interrupt management ***********************************************/
  511. if((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI)
  512. {
  513. /* Clear the VSYNC flag */
  514. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
  515. /* VSYNC Callback */
  516. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  517. /*Call registered DCMI vsync event callback*/
  518. hdcmi->VsyncEventCallback(hdcmi);
  519. #else
  520. HAL_DCMI_VsyncEventCallback(hdcmi);
  521. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  522. }
  523. /* FRAME interrupt management ***********************************************/
  524. if((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI)
  525. {
  526. /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
  527. if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
  528. {
  529. /* Disable the Line, Vsync, Error and Overrun interrupts */
  530. __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
  531. }
  532. /* Disable the Frame interrupt */
  533. __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
  534. /* Frame Callback */
  535. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  536. /*Call registered DCMI frame event callback*/
  537. hdcmi->FrameEventCallback(hdcmi);
  538. #else
  539. HAL_DCMI_FrameEventCallback(hdcmi);
  540. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  541. }
  542. }
  543. /**
  544. * @brief Error DCMI callback.
  545. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  546. * the configuration information for DCMI.
  547. * @retval None
  548. */
  549. __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
  550. {
  551. /* Prevent unused argument(s) compilation warning */
  552. UNUSED(hdcmi);
  553. /* NOTE : This function Should not be modified, when the callback is needed,
  554. the HAL_DCMI_ErrorCallback could be implemented in the user file
  555. */
  556. }
  557. /**
  558. * @brief Line Event callback.
  559. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  560. * the configuration information for DCMI.
  561. * @retval None
  562. */
  563. __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
  564. {
  565. /* Prevent unused argument(s) compilation warning */
  566. UNUSED(hdcmi);
  567. /* NOTE : This function Should not be modified, when the callback is needed,
  568. the HAL_DCMI_LineEventCallback could be implemented in the user file
  569. */
  570. }
  571. /**
  572. * @brief VSYNC Event callback.
  573. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  574. * the configuration information for DCMI.
  575. * @retval None
  576. */
  577. __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
  578. {
  579. /* Prevent unused argument(s) compilation warning */
  580. UNUSED(hdcmi);
  581. /* NOTE : This function Should not be modified, when the callback is needed,
  582. the HAL_DCMI_VsyncEventCallback could be implemented in the user file
  583. */
  584. }
  585. /**
  586. * @brief Frame Event callback.
  587. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  588. * the configuration information for DCMI.
  589. * @retval None
  590. */
  591. __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
  592. {
  593. /* Prevent unused argument(s) compilation warning */
  594. UNUSED(hdcmi);
  595. /* NOTE : This function Should not be modified, when the callback is needed,
  596. the HAL_DCMI_FrameEventCallback could be implemented in the user file
  597. */
  598. }
  599. /**
  600. * @}
  601. */
  602. /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions
  603. * @brief Peripheral Control functions
  604. *
  605. @verbatim
  606. ===============================================================================
  607. ##### Peripheral Control functions #####
  608. ===============================================================================
  609. [..] This section provides functions allowing to:
  610. (+) Configure the CROP feature.
  611. (+) Enable/Disable the CROP feature.
  612. @endverbatim
  613. * @{
  614. */
  615. /**
  616. * @brief Configure the DCMI CROP coordinate.
  617. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  618. * the configuration information for DCMI.
  619. * @param X0 DCMI window X offset
  620. * @param Y0 DCMI window Y offset
  621. * @param XSize DCMI Pixel per line
  622. * @param YSize DCMI Line number
  623. * @retval HAL status
  624. */
  625. HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
  626. {
  627. /* Process Locked */
  628. __HAL_LOCK(hdcmi);
  629. /* Lock the DCMI peripheral state */
  630. hdcmi->State = HAL_DCMI_STATE_BUSY;
  631. /* Check the parameters */
  632. assert_param(IS_DCMI_WINDOW_COORDINATE(X0));
  633. assert_param(IS_DCMI_WINDOW_COORDINATE(YSize));
  634. assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));
  635. assert_param(IS_DCMI_WINDOW_HEIGHT(Y0));
  636. /* Configure CROP */
  637. hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_POSITION_CWSIZE_VLINE));
  638. hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_POSITION_CWSTRT_VST));
  639. /* Initialize the DCMI state*/
  640. hdcmi->State = HAL_DCMI_STATE_READY;
  641. /* Process Unlocked */
  642. __HAL_UNLOCK(hdcmi);
  643. return HAL_OK;
  644. }
  645. /**
  646. * @brief Disable the Crop feature.
  647. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  648. * the configuration information for DCMI.
  649. * @retval HAL status
  650. */
  651. HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi)
  652. {
  653. /* Process Locked */
  654. __HAL_LOCK(hdcmi);
  655. /* Lock the DCMI peripheral state */
  656. hdcmi->State = HAL_DCMI_STATE_BUSY;
  657. /* Disable DCMI Crop feature */
  658. hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP;
  659. /* Change the DCMI state*/
  660. hdcmi->State = HAL_DCMI_STATE_READY;
  661. /* Process Unlocked */
  662. __HAL_UNLOCK(hdcmi);
  663. return HAL_OK;
  664. }
  665. /**
  666. * @brief Enable the Crop feature.
  667. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  668. * the configuration information for DCMI.
  669. * @retval HAL status
  670. */
  671. HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi)
  672. {
  673. /* Process Locked */
  674. __HAL_LOCK(hdcmi);
  675. /* Lock the DCMI peripheral state */
  676. hdcmi->State = HAL_DCMI_STATE_BUSY;
  677. /* Enable DCMI Crop feature */
  678. hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP;
  679. /* Change the DCMI state*/
  680. hdcmi->State = HAL_DCMI_STATE_READY;
  681. /* Process Unlocked */
  682. __HAL_UNLOCK(hdcmi);
  683. return HAL_OK;
  684. }
  685. /**
  686. * @brief Set embedded synchronization delimiters unmasks.
  687. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  688. * the configuration information for DCMI.
  689. * @param SyncUnmask pointer to a DCMI_SyncUnmaskTypeDef structure that contains
  690. * the embedded synchronization delimiters unmasks.
  691. * @retval HAL status
  692. */
  693. HAL_StatusTypeDef HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask)
  694. {
  695. /* Process Locked */
  696. __HAL_LOCK(hdcmi);
  697. /* Lock the DCMI peripheral state */
  698. hdcmi->State = HAL_DCMI_STATE_BUSY;
  699. /* Write DCMI embedded synchronization unmask register */
  700. hdcmi->Instance->ESUR = (((uint32_t)SyncUnmask->FrameStartUnmask) |\
  701. ((uint32_t)SyncUnmask->LineStartUnmask << DCMI_ESUR_LSU_Pos)|\
  702. ((uint32_t)SyncUnmask->LineEndUnmask << DCMI_ESUR_LEU_Pos)|\
  703. ((uint32_t)SyncUnmask->FrameEndUnmask << DCMI_ESUR_FEU_Pos));
  704. /* Change the DCMI state*/
  705. hdcmi->State = HAL_DCMI_STATE_READY;
  706. /* Process Unlocked */
  707. __HAL_UNLOCK(hdcmi);
  708. return HAL_OK;
  709. }
  710. /**
  711. * @}
  712. */
  713. /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions
  714. * @brief Peripheral State functions
  715. *
  716. @verbatim
  717. ===============================================================================
  718. ##### Peripheral State and Errors functions #####
  719. ===============================================================================
  720. [..]
  721. This subsection provides functions allowing to
  722. (+) Check the DCMI state.
  723. (+) Get the specific DCMI error flag.
  724. @endverbatim
  725. * @{
  726. */
  727. /**
  728. * @brief Return the DCMI state
  729. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  730. * the configuration information for DCMI.
  731. * @retval HAL state
  732. */
  733. HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)
  734. {
  735. return hdcmi->State;
  736. }
  737. /**
  738. * @brief Return the DCMI error code
  739. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  740. * the configuration information for DCMI.
  741. * @retval DCMI Error Code
  742. */
  743. uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
  744. {
  745. return hdcmi->ErrorCode;
  746. }
  747. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  748. /**
  749. * @brief DCMI Callback registering
  750. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  751. * the configuration information for DCMI.
  752. * @param CallbackID dcmi Callback ID
  753. * @param pCallback pointer to DCMI_CallbackTypeDef structure
  754. * @retval status
  755. */
  756. HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback)
  757. {
  758. HAL_StatusTypeDef status = HAL_OK;
  759. if(pCallback == NULL)
  760. {
  761. /* update the error code */
  762. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  763. /* update return status */
  764. status = HAL_ERROR;
  765. }
  766. else
  767. {
  768. if(hdcmi->State == HAL_DCMI_STATE_READY)
  769. {
  770. switch (CallbackID)
  771. {
  772. case HAL_DCMI_FRAME_EVENT_CB_ID :
  773. hdcmi->FrameEventCallback = pCallback;
  774. break;
  775. case HAL_DCMI_VSYNC_EVENT_CB_ID :
  776. hdcmi->VsyncEventCallback = pCallback;
  777. break;
  778. case HAL_DCMI_LINE_EVENT_CB_ID :
  779. hdcmi->LineEventCallback = pCallback;
  780. break;
  781. case HAL_DCMI_ERROR_CB_ID :
  782. hdcmi->ErrorCallback = pCallback;
  783. break;
  784. case HAL_DCMI_MSPINIT_CB_ID :
  785. hdcmi->MspInitCallback = pCallback;
  786. break;
  787. case HAL_DCMI_MSPDEINIT_CB_ID :
  788. hdcmi->MspDeInitCallback = pCallback;
  789. break;
  790. default :
  791. /* Return error status */
  792. status = HAL_ERROR;
  793. break;
  794. }
  795. }
  796. else if(hdcmi->State == HAL_DCMI_STATE_RESET)
  797. {
  798. switch (CallbackID)
  799. {
  800. case HAL_DCMI_MSPINIT_CB_ID :
  801. hdcmi->MspInitCallback = pCallback;
  802. break;
  803. case HAL_DCMI_MSPDEINIT_CB_ID :
  804. hdcmi->MspDeInitCallback = pCallback;
  805. break;
  806. default :
  807. /* update the error code */
  808. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  809. /* update return status */
  810. status = HAL_ERROR;
  811. break;
  812. }
  813. }
  814. else
  815. {
  816. /* update the error code */
  817. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  818. /* update return status */
  819. status = HAL_ERROR;
  820. }
  821. }
  822. return status;
  823. }
  824. /**
  825. * @brief DCMI Callback Unregistering
  826. * @param hdcmi dcmi handle
  827. * @param CallbackID dcmi Callback ID
  828. * @retval status
  829. */
  830. HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID)
  831. {
  832. HAL_StatusTypeDef status = HAL_OK;
  833. if(hdcmi->State == HAL_DCMI_STATE_READY)
  834. {
  835. switch (CallbackID)
  836. {
  837. case HAL_DCMI_FRAME_EVENT_CB_ID :
  838. hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
  839. break;
  840. case HAL_DCMI_VSYNC_EVENT_CB_ID :
  841. hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
  842. break;
  843. case HAL_DCMI_LINE_EVENT_CB_ID :
  844. hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
  845. break;
  846. case HAL_DCMI_ERROR_CB_ID :
  847. hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
  848. break;
  849. case HAL_DCMI_MSPINIT_CB_ID :
  850. hdcmi->MspInitCallback = HAL_DCMI_MspInit;
  851. break;
  852. case HAL_DCMI_MSPDEINIT_CB_ID :
  853. hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
  854. break;
  855. default :
  856. /* update the error code */
  857. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  858. /* update return status */
  859. status = HAL_ERROR;
  860. break;
  861. }
  862. }
  863. else if(hdcmi->State == HAL_DCMI_STATE_RESET)
  864. {
  865. switch (CallbackID)
  866. {
  867. case HAL_DCMI_MSPINIT_CB_ID :
  868. hdcmi->MspInitCallback = HAL_DCMI_MspInit;
  869. break;
  870. case HAL_DCMI_MSPDEINIT_CB_ID :
  871. hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
  872. break;
  873. default :
  874. /* update the error code */
  875. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  876. /* update return status */
  877. status = HAL_ERROR;
  878. break;
  879. }
  880. }
  881. else
  882. {
  883. /* update the error code */
  884. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  885. /* update return status */
  886. status = HAL_ERROR;
  887. }
  888. return status;
  889. }
  890. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  891. /**
  892. * @}
  893. */
  894. /* Private functions ---------------------------------------------------------*/
  895. /** @defgroup DCMI_Private_Functions DCMI Private Functions
  896. * @{
  897. */
  898. /**
  899. * @brief DMA conversion complete callback.
  900. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  901. * the configuration information for the specified DMA module.
  902. * @retval None
  903. */
  904. static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
  905. {
  906. uint32_t tmp = 0U;
  907. DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  908. if(hdcmi->XferCount != 0U)
  909. {
  910. /* Update memory 0 address location */
  911. tmp = ((hdcmi->DMA_Handle->Instance->CR) & DMA_SxCR_CT);
  912. if(((hdcmi->XferCount % 2U) == 0U) && (tmp != 0U))
  913. {
  914. tmp = hdcmi->DMA_Handle->Instance->M0AR;
  915. HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY0);
  916. hdcmi->XferCount--;
  917. }
  918. /* Update memory 1 address location */
  919. else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U)
  920. {
  921. tmp = hdcmi->DMA_Handle->Instance->M1AR;
  922. HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY1);
  923. hdcmi->XferCount--;
  924. }
  925. }
  926. /* Update memory 0 address location */
  927. else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0U)
  928. {
  929. hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr;
  930. }
  931. /* Update memory 1 address location */
  932. else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U)
  933. {
  934. tmp = hdcmi->pBuffPtr;
  935. hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4U*hdcmi->XferSize));
  936. hdcmi->XferCount = hdcmi->XferTransferNumber;
  937. }
  938. /* Check if the frame is transferred */
  939. if(hdcmi->XferCount == hdcmi->XferTransferNumber)
  940. {
  941. /* Enable the Frame interrupt */
  942. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
  943. /* When snapshot mode, set dcmi state to ready */
  944. if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
  945. {
  946. hdcmi->State= HAL_DCMI_STATE_READY;
  947. }
  948. }
  949. }
  950. /**
  951. * @brief DMA error callback
  952. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  953. * the configuration information for the specified DMA module.
  954. * @retval None
  955. */
  956. static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
  957. {
  958. DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  959. if(hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE)
  960. {
  961. /* Initialize the DCMI state*/
  962. hdcmi->State = HAL_DCMI_STATE_READY;
  963. }
  964. /* DCMI error Callback */
  965. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  966. /*Call registered DCMI error callback*/
  967. hdcmi->ErrorCallback(hdcmi);
  968. #else
  969. HAL_DCMI_ErrorCallback(hdcmi);
  970. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  971. }
  972. /**
  973. * @}
  974. */
  975. /**
  976. * @}
  977. */
  978. #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
  979. STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\
  980. STM32F479xx */
  981. #endif /* HAL_DCMI_MODULE_ENABLED */
  982. /**
  983. * @}
  984. */
  985. /**
  986. * @}
  987. */
  988. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/