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.

stm32f4xx_hal_adc_ex.c 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_adc_ex.c
  4. * @author MCD Application Team
  5. * @brief This file provides firmware functions to manage the following
  6. * functionalities of the ADC extension peripheral:
  7. * + Extended features functions
  8. *
  9. @verbatim
  10. ==============================================================================
  11. ##### How to use this driver #####
  12. ==============================================================================
  13. [..]
  14. (#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit():
  15. (##) Enable the ADC interface clock using __HAL_RCC_ADC_CLK_ENABLE()
  16. (##) ADC pins configuration
  17. (+++) Enable the clock for the ADC GPIOs using the following function:
  18. __HAL_RCC_GPIOx_CLK_ENABLE()
  19. (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init()
  20. (##) In case of using interrupts (e.g. HAL_ADC_Start_IT())
  21. (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority()
  22. (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ()
  23. (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler()
  24. (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA())
  25. (+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE()
  26. (+++) Configure and enable two DMA streams stream for managing data
  27. transfer from peripheral to memory (output stream)
  28. (+++) Associate the initialized DMA handle to the ADC DMA handle
  29. using __HAL_LINKDMA()
  30. (+++) Configure the priority and enable the NVIC for the transfer complete
  31. interrupt on the two DMA Streams. The output stream should have higher
  32. priority than the input stream.
  33. (#) Configure the ADC Prescaler, conversion resolution and data alignment
  34. using the HAL_ADC_Init() function.
  35. (#) Configure the ADC Injected channels group features, use HAL_ADC_Init()
  36. and HAL_ADC_ConfigChannel() functions.
  37. (#) Three operation modes are available within this driver:
  38. *** Polling mode IO operation ***
  39. =================================
  40. [..]
  41. (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart()
  42. (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage
  43. user can specify the value of timeout according to his end application
  44. (+) To read the ADC converted values, use the HAL_ADCEx_InjectedGetValue() function.
  45. (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop()
  46. *** Interrupt mode IO operation ***
  47. ===================================
  48. [..]
  49. (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart_IT()
  50. (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine
  51. (+) At ADC end of conversion HAL_ADCEx_InjectedConvCpltCallback() function is executed and user can
  52. add his own code by customization of function pointer HAL_ADCEx_InjectedConvCpltCallback
  53. (+) In case of ADC Error, HAL_ADCEx_InjectedErrorCallback() function is executed and user can
  54. add his own code by customization of function pointer HAL_ADCEx_InjectedErrorCallback
  55. (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop_IT()
  56. *** Multi mode ADCs Regular channels configuration ***
  57. ======================================================
  58. [..]
  59. (+) Select the Multi mode ADC regular channels features (dual or triple mode)
  60. and configure the DMA mode using HAL_ADCEx_MultiModeConfigChannel() functions.
  61. (+) Start the ADC peripheral using HAL_ADCEx_MultiModeStart_DMA(), at this stage the user specify the length
  62. of data to be transferred at each end of conversion
  63. (+) Read the ADCs converted values using the HAL_ADCEx_MultiModeGetValue() function.
  64. @endverbatim
  65. ******************************************************************************
  66. * @attention
  67. *
  68. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  69. * All rights reserved.</center></h2>
  70. *
  71. * This software component is licensed by ST under BSD 3-Clause license,
  72. * the "License"; You may not use this file except in compliance with the
  73. * License. You may obtain a copy of the License at:
  74. * opensource.org/licenses/BSD-3-Clause
  75. *
  76. ******************************************************************************
  77. */
  78. /* Includes ------------------------------------------------------------------*/
  79. #include "stm32f4xx_hal.h"
  80. /** @addtogroup STM32F4xx_HAL_Driver
  81. * @{
  82. */
  83. /** @defgroup ADCEx ADCEx
  84. * @brief ADC Extended driver modules
  85. * @{
  86. */
  87. #ifdef HAL_ADC_MODULE_ENABLED
  88. /* Private typedef -----------------------------------------------------------*/
  89. /* Private define ------------------------------------------------------------*/
  90. /* Private macro -------------------------------------------------------------*/
  91. /* Private variables ---------------------------------------------------------*/
  92. /** @addtogroup ADCEx_Private_Functions
  93. * @{
  94. */
  95. /* Private function prototypes -----------------------------------------------*/
  96. static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma);
  97. static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma);
  98. static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma);
  99. /**
  100. * @}
  101. */
  102. /* Exported functions --------------------------------------------------------*/
  103. /** @defgroup ADCEx_Exported_Functions ADC Exported Functions
  104. * @{
  105. */
  106. /** @defgroup ADCEx_Exported_Functions_Group1 Extended features functions
  107. * @brief Extended features functions
  108. *
  109. @verbatim
  110. ===============================================================================
  111. ##### Extended features functions #####
  112. ===============================================================================
  113. [..] This section provides functions allowing to:
  114. (+) Start conversion of injected channel.
  115. (+) Stop conversion of injected channel.
  116. (+) Start multimode and enable DMA transfer.
  117. (+) Stop multimode and disable DMA transfer.
  118. (+) Get result of injected channel conversion.
  119. (+) Get result of multimode conversion.
  120. (+) Configure injected channels.
  121. (+) Configure multimode.
  122. @endverbatim
  123. * @{
  124. */
  125. /**
  126. * @brief Enables the selected ADC software start conversion of the injected channels.
  127. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  128. * the configuration information for the specified ADC.
  129. * @retval HAL status
  130. */
  131. HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
  132. {
  133. __IO uint32_t counter = 0U;
  134. uint32_t tmp1 = 0U, tmp2 = 0U;
  135. ADC_Common_TypeDef *tmpADC_Common;
  136. /* Process locked */
  137. __HAL_LOCK(hadc);
  138. /* Enable the ADC peripheral */
  139. /* Check if ADC peripheral is disabled in order to enable it and wait during
  140. Tstab time the ADC's stabilization */
  141. if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
  142. {
  143. /* Enable the Peripheral */
  144. __HAL_ADC_ENABLE(hadc);
  145. /* Delay for ADC stabilization time */
  146. /* Compute number of CPU cycles to wait for */
  147. counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U));
  148. while(counter != 0U)
  149. {
  150. counter--;
  151. }
  152. }
  153. /* Start conversion if ADC is effectively enabled */
  154. if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON))
  155. {
  156. /* Set ADC state */
  157. /* - Clear state bitfield related to injected group conversion results */
  158. /* - Set state bitfield related to injected operation */
  159. ADC_STATE_CLR_SET(hadc->State,
  160. HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
  161. HAL_ADC_STATE_INJ_BUSY);
  162. /* Check if a regular conversion is ongoing */
  163. /* Note: On this device, there is no ADC error code fields related to */
  164. /* conversions on group injected only. In case of conversion on */
  165. /* going on group regular, no error code is reset. */
  166. if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
  167. {
  168. /* Reset ADC all error code fields */
  169. ADC_CLEAR_ERRORCODE(hadc);
  170. }
  171. /* Process unlocked */
  172. /* Unlock before starting ADC conversions: in case of potential */
  173. /* interruption, to let the process to ADC IRQ Handler. */
  174. __HAL_UNLOCK(hadc);
  175. /* Clear injected group conversion flag */
  176. /* (To ensure of no unknown state from potential previous ADC operations) */
  177. __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
  178. /* Pointer to the common control register to which is belonging hadc */
  179. /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
  180. /* control register) */
  181. tmpADC_Common = ADC_COMMON_REGISTER(hadc);
  182. /* Check if Multimode enabled */
  183. if(HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_MULTI))
  184. {
  185. tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
  186. tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
  187. if(tmp1 && tmp2)
  188. {
  189. /* Enable the selected ADC software conversion for injected group */
  190. hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
  191. }
  192. }
  193. else
  194. {
  195. tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
  196. tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
  197. if((hadc->Instance == ADC1) && tmp1 && tmp2)
  198. {
  199. /* Enable the selected ADC software conversion for injected group */
  200. hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
  201. }
  202. }
  203. }
  204. /* Return function status */
  205. return HAL_OK;
  206. }
  207. /**
  208. * @brief Enables the interrupt and starts ADC conversion of injected channels.
  209. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  210. * the configuration information for the specified ADC.
  211. *
  212. * @retval HAL status.
  213. */
  214. HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
  215. {
  216. __IO uint32_t counter = 0U;
  217. uint32_t tmp1 = 0U, tmp2 = 0U;
  218. ADC_Common_TypeDef *tmpADC_Common;
  219. /* Process locked */
  220. __HAL_LOCK(hadc);
  221. /* Enable the ADC peripheral */
  222. /* Check if ADC peripheral is disabled in order to enable it and wait during
  223. Tstab time the ADC's stabilization */
  224. if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
  225. {
  226. /* Enable the Peripheral */
  227. __HAL_ADC_ENABLE(hadc);
  228. /* Delay for ADC stabilization time */
  229. /* Compute number of CPU cycles to wait for */
  230. counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U));
  231. while(counter != 0U)
  232. {
  233. counter--;
  234. }
  235. }
  236. /* Start conversion if ADC is effectively enabled */
  237. if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON))
  238. {
  239. /* Set ADC state */
  240. /* - Clear state bitfield related to injected group conversion results */
  241. /* - Set state bitfield related to injected operation */
  242. ADC_STATE_CLR_SET(hadc->State,
  243. HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
  244. HAL_ADC_STATE_INJ_BUSY);
  245. /* Check if a regular conversion is ongoing */
  246. /* Note: On this device, there is no ADC error code fields related to */
  247. /* conversions on group injected only. In case of conversion on */
  248. /* going on group regular, no error code is reset. */
  249. if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
  250. {
  251. /* Reset ADC all error code fields */
  252. ADC_CLEAR_ERRORCODE(hadc);
  253. }
  254. /* Process unlocked */
  255. /* Unlock before starting ADC conversions: in case of potential */
  256. /* interruption, to let the process to ADC IRQ Handler. */
  257. __HAL_UNLOCK(hadc);
  258. /* Clear injected group conversion flag */
  259. /* (To ensure of no unknown state from potential previous ADC operations) */
  260. __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
  261. /* Enable end of conversion interrupt for injected channels */
  262. __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
  263. /* Pointer to the common control register to which is belonging hadc */
  264. /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
  265. /* control register) */
  266. tmpADC_Common = ADC_COMMON_REGISTER(hadc);
  267. /* Check if Multimode enabled */
  268. if(HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_MULTI))
  269. {
  270. tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
  271. tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
  272. if(tmp1 && tmp2)
  273. {
  274. /* Enable the selected ADC software conversion for injected group */
  275. hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
  276. }
  277. }
  278. else
  279. {
  280. tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
  281. tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
  282. if((hadc->Instance == ADC1) && tmp1 && tmp2)
  283. {
  284. /* Enable the selected ADC software conversion for injected group */
  285. hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
  286. }
  287. }
  288. }
  289. /* Return function status */
  290. return HAL_OK;
  291. }
  292. /**
  293. * @brief Stop conversion of injected channels. Disable ADC peripheral if
  294. * no regular conversion is on going.
  295. * @note If ADC must be disabled and if conversion is on going on
  296. * regular group, function HAL_ADC_Stop must be used to stop both
  297. * injected and regular groups, and disable the ADC.
  298. * @note If injected group mode auto-injection is enabled,
  299. * function HAL_ADC_Stop must be used.
  300. * @note In case of auto-injection mode, HAL_ADC_Stop must be used.
  301. * @param hadc ADC handle
  302. * @retval None
  303. */
  304. HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
  305. {
  306. HAL_StatusTypeDef tmp_hal_status = HAL_OK;
  307. /* Check the parameters */
  308. assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
  309. /* Process locked */
  310. __HAL_LOCK(hadc);
  311. /* Stop potential conversion and disable ADC peripheral */
  312. /* Conditioned to: */
  313. /* - No conversion on the other group (regular group) is intended to */
  314. /* continue (injected and regular groups stop conversion and ADC disable */
  315. /* are common) */
  316. /* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
  317. if(((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) &&
  318. HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) )
  319. {
  320. /* Stop potential conversion on going, on regular and injected groups */
  321. /* Disable ADC peripheral */
  322. __HAL_ADC_DISABLE(hadc);
  323. /* Check if ADC is effectively disabled */
  324. if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON))
  325. {
  326. /* Set ADC state */
  327. ADC_STATE_CLR_SET(hadc->State,
  328. HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
  329. HAL_ADC_STATE_READY);
  330. }
  331. }
  332. else
  333. {
  334. /* Update ADC state machine to error */
  335. SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
  336. tmp_hal_status = HAL_ERROR;
  337. }
  338. /* Process unlocked */
  339. __HAL_UNLOCK(hadc);
  340. /* Return function status */
  341. return tmp_hal_status;
  342. }
  343. /**
  344. * @brief Poll for injected conversion complete
  345. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  346. * the configuration information for the specified ADC.
  347. * @param Timeout Timeout value in millisecond.
  348. * @retval HAL status
  349. */
  350. HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
  351. {
  352. uint32_t tickstart = 0U;
  353. /* Get tick */
  354. tickstart = HAL_GetTick();
  355. /* Check End of conversion flag */
  356. while(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOC)))
  357. {
  358. /* Check for the Timeout */
  359. if(Timeout != HAL_MAX_DELAY)
  360. {
  361. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  362. {
  363. hadc->State= HAL_ADC_STATE_TIMEOUT;
  364. /* Process unlocked */
  365. __HAL_UNLOCK(hadc);
  366. return HAL_TIMEOUT;
  367. }
  368. }
  369. }
  370. /* Clear injected group conversion flag */
  371. __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JSTRT | ADC_FLAG_JEOC);
  372. /* Update ADC state machine */
  373. SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC);
  374. /* Determine whether any further conversion upcoming on group injected */
  375. /* by external trigger, continuous mode or scan sequence on going. */
  376. /* Note: On STM32F4, there is no independent flag of end of sequence. */
  377. /* The test of scan sequence on going is done either with scan */
  378. /* sequence disabled or with end of conversion flag set to */
  379. /* of end of sequence. */
  380. if(ADC_IS_SOFTWARE_START_INJECTED(hadc) &&
  381. (HAL_IS_BIT_CLR(hadc->Instance->JSQR, ADC_JSQR_JL) ||
  382. HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_EOCS) ) &&
  383. (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) &&
  384. (ADC_IS_SOFTWARE_START_REGULAR(hadc) &&
  385. (hadc->Init.ContinuousConvMode == DISABLE) ) ) )
  386. {
  387. /* Set ADC state */
  388. CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
  389. if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
  390. {
  391. SET_BIT(hadc->State, HAL_ADC_STATE_READY);
  392. }
  393. }
  394. /* Return ADC state */
  395. return HAL_OK;
  396. }
  397. /**
  398. * @brief Stop conversion of injected channels, disable interruption of
  399. * end-of-conversion. Disable ADC peripheral if no regular conversion
  400. * is on going.
  401. * @note If ADC must be disabled and if conversion is on going on
  402. * regular group, function HAL_ADC_Stop must be used to stop both
  403. * injected and regular groups, and disable the ADC.
  404. * @note If injected group mode auto-injection is enabled,
  405. * function HAL_ADC_Stop must be used.
  406. * @param hadc ADC handle
  407. * @retval None
  408. */
  409. HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
  410. {
  411. HAL_StatusTypeDef tmp_hal_status = HAL_OK;
  412. /* Check the parameters */
  413. assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
  414. /* Process locked */
  415. __HAL_LOCK(hadc);
  416. /* Stop potential conversion and disable ADC peripheral */
  417. /* Conditioned to: */
  418. /* - No conversion on the other group (regular group) is intended to */
  419. /* continue (injected and regular groups stop conversion and ADC disable */
  420. /* are common) */
  421. /* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
  422. if(((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) &&
  423. HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) )
  424. {
  425. /* Stop potential conversion on going, on regular and injected groups */
  426. /* Disable ADC peripheral */
  427. __HAL_ADC_DISABLE(hadc);
  428. /* Check if ADC is effectively disabled */
  429. if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON))
  430. {
  431. /* Disable ADC end of conversion interrupt for injected channels */
  432. __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
  433. /* Set ADC state */
  434. ADC_STATE_CLR_SET(hadc->State,
  435. HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
  436. HAL_ADC_STATE_READY);
  437. }
  438. }
  439. else
  440. {
  441. /* Update ADC state machine to error */
  442. SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
  443. tmp_hal_status = HAL_ERROR;
  444. }
  445. /* Process unlocked */
  446. __HAL_UNLOCK(hadc);
  447. /* Return function status */
  448. return tmp_hal_status;
  449. }
  450. /**
  451. * @brief Gets the converted value from data register of injected channel.
  452. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  453. * the configuration information for the specified ADC.
  454. * @param InjectedRank the ADC injected rank.
  455. * This parameter can be one of the following values:
  456. * @arg ADC_INJECTED_RANK_1: Injected Channel1 selected
  457. * @arg ADC_INJECTED_RANK_2: Injected Channel2 selected
  458. * @arg ADC_INJECTED_RANK_3: Injected Channel3 selected
  459. * @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
  460. * @retval None
  461. */
  462. uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank)
  463. {
  464. __IO uint32_t tmp = 0U;
  465. /* Check the parameters */
  466. assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
  467. /* Clear injected group conversion flag to have similar behaviour as */
  468. /* regular group: reading data register also clears end of conversion flag. */
  469. __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
  470. /* Return the selected ADC converted value */
  471. switch(InjectedRank)
  472. {
  473. case ADC_INJECTED_RANK_4:
  474. {
  475. tmp = hadc->Instance->JDR4;
  476. }
  477. break;
  478. case ADC_INJECTED_RANK_3:
  479. {
  480. tmp = hadc->Instance->JDR3;
  481. }
  482. break;
  483. case ADC_INJECTED_RANK_2:
  484. {
  485. tmp = hadc->Instance->JDR2;
  486. }
  487. break;
  488. case ADC_INJECTED_RANK_1:
  489. {
  490. tmp = hadc->Instance->JDR1;
  491. }
  492. break;
  493. default:
  494. break;
  495. }
  496. return tmp;
  497. }
  498. /**
  499. * @brief Enables ADC DMA request after last transfer (Multi-ADC mode) and enables ADC peripheral
  500. *
  501. * @note Caution: This function must be used only with the ADC master.
  502. *
  503. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  504. * the configuration information for the specified ADC.
  505. * @param pData Pointer to buffer in which transferred from ADC peripheral to memory will be stored.
  506. * @param Length The length of data to be transferred from ADC peripheral to memory.
  507. * @retval HAL status
  508. */
  509. HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
  510. {
  511. __IO uint32_t counter = 0U;
  512. ADC_Common_TypeDef *tmpADC_Common;
  513. /* Check the parameters */
  514. assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
  515. assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
  516. assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests));
  517. /* Process locked */
  518. __HAL_LOCK(hadc);
  519. /* Check if ADC peripheral is disabled in order to enable it and wait during
  520. Tstab time the ADC's stabilization */
  521. if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
  522. {
  523. /* Enable the Peripheral */
  524. __HAL_ADC_ENABLE(hadc);
  525. /* Delay for temperature sensor stabilization time */
  526. /* Compute number of CPU cycles to wait for */
  527. counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U));
  528. while(counter != 0U)
  529. {
  530. counter--;
  531. }
  532. }
  533. /* Start conversion if ADC is effectively enabled */
  534. if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON))
  535. {
  536. /* Set ADC state */
  537. /* - Clear state bitfield related to regular group conversion results */
  538. /* - Set state bitfield related to regular group operation */
  539. ADC_STATE_CLR_SET(hadc->State,
  540. HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR,
  541. HAL_ADC_STATE_REG_BUSY);
  542. /* If conversions on group regular are also triggering group injected, */
  543. /* update ADC state. */
  544. if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET)
  545. {
  546. ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
  547. }
  548. /* State machine update: Check if an injected conversion is ongoing */
  549. if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY))
  550. {
  551. /* Reset ADC error code fields related to conversions on group regular */
  552. CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA));
  553. }
  554. else
  555. {
  556. /* Reset ADC all error code fields */
  557. ADC_CLEAR_ERRORCODE(hadc);
  558. }
  559. /* Process unlocked */
  560. /* Unlock before starting ADC conversions: in case of potential */
  561. /* interruption, to let the process to ADC IRQ Handler. */
  562. __HAL_UNLOCK(hadc);
  563. /* Set the DMA transfer complete callback */
  564. hadc->DMA_Handle->XferCpltCallback = ADC_MultiModeDMAConvCplt;
  565. /* Set the DMA half transfer complete callback */
  566. hadc->DMA_Handle->XferHalfCpltCallback = ADC_MultiModeDMAHalfConvCplt;
  567. /* Set the DMA error callback */
  568. hadc->DMA_Handle->XferErrorCallback = ADC_MultiModeDMAError ;
  569. /* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC */
  570. /* start (in case of SW start): */
  571. /* Clear regular group conversion flag and overrun flag */
  572. /* (To ensure of no unknown state from potential previous ADC operations) */
  573. __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOC);
  574. /* Enable ADC overrun interrupt */
  575. __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
  576. /* Pointer to the common control register to which is belonging hadc */
  577. /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
  578. /* control register) */
  579. tmpADC_Common = ADC_COMMON_REGISTER(hadc);
  580. if (hadc->Init.DMAContinuousRequests != DISABLE)
  581. {
  582. /* Enable the selected ADC DMA request after last transfer */
  583. tmpADC_Common->CCR |= ADC_CCR_DDS;
  584. }
  585. else
  586. {
  587. /* Disable the selected ADC EOC rising on each regular channel conversion */
  588. tmpADC_Common->CCR &= ~ADC_CCR_DDS;
  589. }
  590. /* Enable the DMA Stream */
  591. HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&tmpADC_Common->CDR, (uint32_t)pData, Length);
  592. /* if no external trigger present enable software conversion of regular channels */
  593. if((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET)
  594. {
  595. /* Enable the selected ADC software conversion for regular group */
  596. hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
  597. }
  598. }
  599. /* Return function status */
  600. return HAL_OK;
  601. }
  602. /**
  603. * @brief Disables ADC DMA (multi-ADC mode) and disables ADC peripheral
  604. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  605. * the configuration information for the specified ADC.
  606. * @retval HAL status
  607. */
  608. HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
  609. {
  610. HAL_StatusTypeDef tmp_hal_status = HAL_OK;
  611. ADC_Common_TypeDef *tmpADC_Common;
  612. /* Check the parameters */
  613. assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
  614. /* Process locked */
  615. __HAL_LOCK(hadc);
  616. /* Stop potential conversion on going, on regular and injected groups */
  617. /* Disable ADC peripheral */
  618. __HAL_ADC_DISABLE(hadc);
  619. /* Pointer to the common control register to which is belonging hadc */
  620. /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
  621. /* control register) */
  622. tmpADC_Common = ADC_COMMON_REGISTER(hadc);
  623. /* Check if ADC is effectively disabled */
  624. if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON))
  625. {
  626. /* Disable the selected ADC DMA mode for multimode */
  627. tmpADC_Common->CCR &= ~ADC_CCR_DDS;
  628. /* Disable the DMA channel (in case of DMA in circular mode or stop while */
  629. /* DMA transfer is on going) */
  630. tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
  631. /* Disable ADC overrun interrupt */
  632. __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
  633. /* Set ADC state */
  634. ADC_STATE_CLR_SET(hadc->State,
  635. HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
  636. HAL_ADC_STATE_READY);
  637. }
  638. /* Process unlocked */
  639. __HAL_UNLOCK(hadc);
  640. /* Return function status */
  641. return tmp_hal_status;
  642. }
  643. /**
  644. * @brief Returns the last ADC1, ADC2 and ADC3 regular conversions results
  645. * data in the selected multi mode.
  646. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  647. * the configuration information for the specified ADC.
  648. * @retval The converted data value.
  649. */
  650. uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
  651. {
  652. ADC_Common_TypeDef *tmpADC_Common;
  653. /* Pointer to the common control register to which is belonging hadc */
  654. /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
  655. /* control register) */
  656. tmpADC_Common = ADC_COMMON_REGISTER(hadc);
  657. /* Return the multi mode conversion value */
  658. return tmpADC_Common->CDR;
  659. }
  660. /**
  661. * @brief Injected conversion complete callback in non blocking mode
  662. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  663. * the configuration information for the specified ADC.
  664. * @retval None
  665. */
  666. __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
  667. {
  668. /* Prevent unused argument(s) compilation warning */
  669. UNUSED(hadc);
  670. /* NOTE : This function Should not be modified, when the callback is needed,
  671. the HAL_ADC_InjectedConvCpltCallback could be implemented in the user file
  672. */
  673. }
  674. /**
  675. * @brief Configures for the selected ADC injected channel its corresponding
  676. * rank in the sequencer and its sample time.
  677. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  678. * the configuration information for the specified ADC.
  679. * @param sConfigInjected ADC configuration structure for injected channel.
  680. * @retval None
  681. */
  682. HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected)
  683. {
  684. #ifdef USE_FULL_ASSERT
  685. uint32_t tmp = 0U;
  686. #endif /* USE_FULL_ASSERT */
  687. ADC_Common_TypeDef *tmpADC_Common;
  688. /* Check the parameters */
  689. assert_param(IS_ADC_CHANNEL(sConfigInjected->InjectedChannel));
  690. assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
  691. assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime));
  692. assert_param(IS_ADC_EXT_INJEC_TRIG(sConfigInjected->ExternalTrigInjecConv));
  693. assert_param(IS_ADC_INJECTED_LENGTH(sConfigInjected->InjectedNbrOfConversion));
  694. assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv));
  695. assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
  696. #ifdef USE_FULL_ASSERT
  697. tmp = ADC_GET_RESOLUTION(hadc);
  698. assert_param(IS_ADC_RANGE(tmp, sConfigInjected->InjectedOffset));
  699. #endif /* USE_FULL_ASSERT */
  700. if(sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
  701. {
  702. assert_param(IS_ADC_EXT_INJEC_TRIG_EDGE(sConfigInjected->ExternalTrigInjecConvEdge));
  703. }
  704. /* Process locked */
  705. __HAL_LOCK(hadc);
  706. /* if ADC_Channel_10 ... ADC_Channel_18 is selected */
  707. if (sConfigInjected->InjectedChannel > ADC_CHANNEL_9)
  708. {
  709. /* Clear the old sample time */
  710. hadc->Instance->SMPR1 &= ~ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel);
  711. /* Set the new sample time */
  712. hadc->Instance->SMPR1 |= ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel);
  713. }
  714. else /* ADC_Channel include in ADC_Channel_[0..9] */
  715. {
  716. /* Clear the old sample time */
  717. hadc->Instance->SMPR2 &= ~ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel);
  718. /* Set the new sample time */
  719. hadc->Instance->SMPR2 |= ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel);
  720. }
  721. /*---------------------------- ADCx JSQR Configuration -----------------*/
  722. hadc->Instance->JSQR &= ~(ADC_JSQR_JL);
  723. hadc->Instance->JSQR |= ADC_SQR1(sConfigInjected->InjectedNbrOfConversion);
  724. /* Rank configuration */
  725. /* Clear the old SQx bits for the selected rank */
  726. hadc->Instance->JSQR &= ~ADC_JSQR(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion);
  727. /* Set the SQx bits for the selected rank */
  728. hadc->Instance->JSQR |= ADC_JSQR(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion);
  729. /* Enable external trigger if trigger selection is different of software */
  730. /* start. */
  731. /* Note: This configuration keeps the hardware feature of parameter */
  732. /* ExternalTrigConvEdge "trigger edge none" equivalent to */
  733. /* software start. */
  734. if(sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
  735. {
  736. /* Select external trigger to start conversion */
  737. hadc->Instance->CR2 &= ~(ADC_CR2_JEXTSEL);
  738. hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConv;
  739. /* Select external trigger polarity */
  740. hadc->Instance->CR2 &= ~(ADC_CR2_JEXTEN);
  741. hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConvEdge;
  742. }
  743. else
  744. {
  745. /* Reset the external trigger */
  746. hadc->Instance->CR2 &= ~(ADC_CR2_JEXTSEL);
  747. hadc->Instance->CR2 &= ~(ADC_CR2_JEXTEN);
  748. }
  749. if (sConfigInjected->AutoInjectedConv != DISABLE)
  750. {
  751. /* Enable the selected ADC automatic injected group conversion */
  752. hadc->Instance->CR1 |= ADC_CR1_JAUTO;
  753. }
  754. else
  755. {
  756. /* Disable the selected ADC automatic injected group conversion */
  757. hadc->Instance->CR1 &= ~(ADC_CR1_JAUTO);
  758. }
  759. if (sConfigInjected->InjectedDiscontinuousConvMode != DISABLE)
  760. {
  761. /* Enable the selected ADC injected discontinuous mode */
  762. hadc->Instance->CR1 |= ADC_CR1_JDISCEN;
  763. }
  764. else
  765. {
  766. /* Disable the selected ADC injected discontinuous mode */
  767. hadc->Instance->CR1 &= ~(ADC_CR1_JDISCEN);
  768. }
  769. switch(sConfigInjected->InjectedRank)
  770. {
  771. case 1U:
  772. /* Set injected channel 1 offset */
  773. hadc->Instance->JOFR1 &= ~(ADC_JOFR1_JOFFSET1);
  774. hadc->Instance->JOFR1 |= sConfigInjected->InjectedOffset;
  775. break;
  776. case 2U:
  777. /* Set injected channel 2 offset */
  778. hadc->Instance->JOFR2 &= ~(ADC_JOFR2_JOFFSET2);
  779. hadc->Instance->JOFR2 |= sConfigInjected->InjectedOffset;
  780. break;
  781. case 3U:
  782. /* Set injected channel 3 offset */
  783. hadc->Instance->JOFR3 &= ~(ADC_JOFR3_JOFFSET3);
  784. hadc->Instance->JOFR3 |= sConfigInjected->InjectedOffset;
  785. break;
  786. default:
  787. /* Set injected channel 4 offset */
  788. hadc->Instance->JOFR4 &= ~(ADC_JOFR4_JOFFSET4);
  789. hadc->Instance->JOFR4 |= sConfigInjected->InjectedOffset;
  790. break;
  791. }
  792. /* Pointer to the common control register to which is belonging hadc */
  793. /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
  794. /* control register) */
  795. tmpADC_Common = ADC_COMMON_REGISTER(hadc);
  796. /* if ADC1 Channel_18 is selected enable VBAT Channel */
  797. if ((hadc->Instance == ADC1) && (sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT))
  798. {
  799. /* Enable the VBAT channel*/
  800. tmpADC_Common->CCR |= ADC_CCR_VBATE;
  801. }
  802. /* if ADC1 Channel_16 or Channel_17 is selected enable TSVREFE Channel(Temperature sensor and VREFINT) */
  803. if ((hadc->Instance == ADC1) && ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)))
  804. {
  805. /* Enable the TSVREFE channel*/
  806. tmpADC_Common->CCR |= ADC_CCR_TSVREFE;
  807. }
  808. /* Process unlocked */
  809. __HAL_UNLOCK(hadc);
  810. /* Return function status */
  811. return HAL_OK;
  812. }
  813. /**
  814. * @brief Configures the ADC multi-mode
  815. * @param hadc pointer to a ADC_HandleTypeDef structure that contains
  816. * the configuration information for the specified ADC.
  817. * @param multimode pointer to an ADC_MultiModeTypeDef structure that contains
  818. * the configuration information for multimode.
  819. * @retval HAL status
  820. */
  821. HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode)
  822. {
  823. ADC_Common_TypeDef *tmpADC_Common;
  824. /* Check the parameters */
  825. assert_param(IS_ADC_MODE(multimode->Mode));
  826. assert_param(IS_ADC_DMA_ACCESS_MODE(multimode->DMAAccessMode));
  827. assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay));
  828. /* Process locked */
  829. __HAL_LOCK(hadc);
  830. /* Pointer to the common control register to which is belonging hadc */
  831. /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
  832. /* control register) */
  833. tmpADC_Common = ADC_COMMON_REGISTER(hadc);
  834. /* Set ADC mode */
  835. tmpADC_Common->CCR &= ~(ADC_CCR_MULTI);
  836. tmpADC_Common->CCR |= multimode->Mode;
  837. /* Set the ADC DMA access mode */
  838. tmpADC_Common->CCR &= ~(ADC_CCR_DMA);
  839. tmpADC_Common->CCR |= multimode->DMAAccessMode;
  840. /* Set delay between two sampling phases */
  841. tmpADC_Common->CCR &= ~(ADC_CCR_DELAY);
  842. tmpADC_Common->CCR |= multimode->TwoSamplingDelay;
  843. /* Process unlocked */
  844. __HAL_UNLOCK(hadc);
  845. /* Return function status */
  846. return HAL_OK;
  847. }
  848. /**
  849. * @}
  850. */
  851. /**
  852. * @brief DMA transfer complete callback.
  853. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  854. * the configuration information for the specified DMA module.
  855. * @retval None
  856. */
  857. static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma)
  858. {
  859. /* Retrieve ADC handle corresponding to current DMA handle */
  860. ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  861. /* Update state machine on conversion status if not in error state */
  862. if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL | HAL_ADC_STATE_ERROR_DMA))
  863. {
  864. /* Update ADC state machine */
  865. SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC);
  866. /* Determine whether any further conversion upcoming on group regular */
  867. /* by external trigger, continuous mode or scan sequence on going. */
  868. /* Note: On STM32F4, there is no independent flag of end of sequence. */
  869. /* The test of scan sequence on going is done either with scan */
  870. /* sequence disabled or with end of conversion flag set to */
  871. /* of end of sequence. */
  872. if(ADC_IS_SOFTWARE_START_REGULAR(hadc) &&
  873. (hadc->Init.ContinuousConvMode == DISABLE) &&
  874. (HAL_IS_BIT_CLR(hadc->Instance->SQR1, ADC_SQR1_L) ||
  875. HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_EOCS) ) )
  876. {
  877. /* Disable ADC end of single conversion interrupt on group regular */
  878. /* Note: Overrun interrupt was enabled with EOC interrupt in */
  879. /* HAL_ADC_Start_IT(), but is not disabled here because can be used */
  880. /* by overrun IRQ process below. */
  881. __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
  882. /* Set ADC state */
  883. CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
  884. if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY))
  885. {
  886. SET_BIT(hadc->State, HAL_ADC_STATE_READY);
  887. }
  888. }
  889. /* Conversion complete callback */
  890. HAL_ADC_ConvCpltCallback(hadc);
  891. }
  892. else
  893. {
  894. /* Call DMA error callback */
  895. hadc->DMA_Handle->XferErrorCallback(hdma);
  896. }
  897. }
  898. /**
  899. * @brief DMA half transfer 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 ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma)
  905. {
  906. ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  907. /* Conversion complete callback */
  908. HAL_ADC_ConvHalfCpltCallback(hadc);
  909. }
  910. /**
  911. * @brief DMA error callback
  912. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  913. * the configuration information for the specified DMA module.
  914. * @retval None
  915. */
  916. static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma)
  917. {
  918. ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  919. hadc->State= HAL_ADC_STATE_ERROR_DMA;
  920. /* Set ADC error code to DMA error */
  921. hadc->ErrorCode |= HAL_ADC_ERROR_DMA;
  922. HAL_ADC_ErrorCallback(hadc);
  923. }
  924. /**
  925. * @}
  926. */
  927. #endif /* HAL_ADC_MODULE_ENABLED */
  928. /**
  929. * @}
  930. */
  931. /**
  932. * @}
  933. */
  934. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/