2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_adc_ex.c
\r
4 * @author MCD Application Team
\r
6 * @date 24-March-2015
\r
7 * @brief This file provides firmware functions to manage the following
\r
8 * functionalities of the ADC extension peripheral:
\r
9 * + Extended features functions
\r
12 ==============================================================================
\r
13 ##### How to use this driver #####
\r
14 ==============================================================================
\r
16 (#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit():
\r
17 (##) Enable the ADC interface clock using __HAL_RCC_ADC_CLK_ENABLE()
\r
18 (##) ADC pins configuration
\r
19 (+++) Enable the clock for the ADC GPIOs using the following function:
\r
20 __HAL_RCC_GPIOx_CLK_ENABLE()
\r
21 (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init()
\r
22 (##) In case of using interrupts (e.g. HAL_ADC_Start_IT())
\r
23 (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority()
\r
24 (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ()
\r
25 (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler()
\r
26 (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA())
\r
27 (+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE()
\r
28 (+++) Configure and enable two DMA streams stream for managing data
\r
29 transfer from peripheral to memory (output stream)
\r
30 (+++) Associate the initialized DMA handle to the ADC DMA handle
\r
31 using __HAL_LINKDMA()
\r
32 (+++) Configure the priority and enable the NVIC for the transfer complete
\r
33 interrupt on the two DMA Streams. The output stream should have higher
\r
34 priority than the input stream.
\r
35 (#) Configure the ADC Prescaler, conversion resolution and data alignment
\r
36 using the HAL_ADC_Init() function.
\r
38 (#) Configure the ADC Injected channels group features, use HAL_ADC_Init()
\r
39 and HAL_ADC_ConfigChannel() functions.
\r
41 (#) Three operation modes are available within this driver :
\r
43 *** Polling mode IO operation ***
\r
44 =================================
\r
46 (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart()
\r
47 (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage
\r
48 user can specify the value of timeout according to his end application
\r
49 (+) To read the ADC converted values, use the HAL_ADCEx_InjectedGetValue() function.
\r
50 (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop()
\r
52 *** Interrupt mode IO operation ***
\r
53 ===================================
\r
55 (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart_IT()
\r
56 (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine
\r
57 (+) At ADC end of conversion HAL_ADCEx_InjectedConvCpltCallback() function is executed and user can
\r
58 add his own code by customization of function pointer HAL_ADCEx_InjectedConvCpltCallback
\r
59 (+) In case of ADC Error, HAL_ADCEx_InjectedErrorCallback() function is executed and user can
\r
60 add his own code by customization of function pointer HAL_ADCEx_InjectedErrorCallback
\r
61 (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop_IT()
\r
64 *** DMA mode IO operation ***
\r
65 ==============================
\r
67 (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart_DMA(), at this stage the user specify the length
\r
68 of data to be transferred at each end of conversion
\r
69 (+) At The end of data transfer ba HAL_ADCEx_InjectedConvCpltCallback() function is executed and user can
\r
70 add his own code by customization of function pointer HAL_ADCEx_InjectedConvCpltCallback
\r
71 (+) In case of transfer Error, HAL_ADCEx_InjectedErrorCallback() function is executed and user can
\r
72 add his own code by customization of function pointer HAL_ADCEx_InjectedErrorCallback
\r
73 (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop_DMA()
\r
75 *** Multi mode ADCs Regular channels configuration ***
\r
76 ======================================================
\r
78 (+) Select the Multi mode ADC regular channels features (dual or triple mode)
\r
79 and configure the DMA mode using HAL_ADCEx_MultiModeConfigChannel() functions.
\r
80 (+) Start the ADC peripheral using HAL_ADCEx_MultiModeStart_DMA(), at this stage the user specify the length
\r
81 of data to be transferred at each end of conversion
\r
82 (+) Read the ADCs converted values using the HAL_ADCEx_MultiModeGetValue() function.
\r
86 ******************************************************************************
\r
89 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
91 * Redistribution and use in source and binary forms, with or without modification,
\r
92 * are permitted provided that the following conditions are met:
\r
93 * 1. Redistributions of source code must retain the above copyright notice,
\r
94 * this list of conditions and the following disclaimer.
\r
95 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
96 * this list of conditions and the following disclaimer in the documentation
\r
97 * and/or other materials provided with the distribution.
\r
98 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
99 * may be used to endorse or promote products derived from this software
\r
100 * without specific prior written permission.
\r
102 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
103 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
104 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
105 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
106 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
107 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
108 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
109 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
110 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
111 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
113 ******************************************************************************
\r
116 /* Includes ------------------------------------------------------------------*/
\r
117 #include "stm32f7xx_hal.h"
\r
119 /** @addtogroup STM32F7xx_HAL_Driver
\r
123 /** @defgroup ADCEx ADCEx
\r
124 * @brief ADC Extended driver modules
\r
128 #ifdef HAL_ADC_MODULE_ENABLED
\r
130 /* Private typedef -----------------------------------------------------------*/
\r
131 /* Private define ------------------------------------------------------------*/
\r
132 /* Private macro -------------------------------------------------------------*/
\r
133 /* Private variables ---------------------------------------------------------*/
\r
134 /* Private function prototypes -----------------------------------------------*/
\r
135 /** @addtogroup ADCEx_Private_Functions
\r
138 static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma);
\r
139 static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma);
\r
140 static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma);
\r
145 /* Exported functions ---------------------------------------------------------*/
\r
146 /** @defgroup ADCEx_Exported_Functions ADC Exported Functions
\r
150 /** @defgroup ADCEx_Exported_Functions_Group1 Extended features functions
\r
151 * @brief Extended features functions
\r
154 ===============================================================================
\r
155 ##### Extended features functions #####
\r
156 ===============================================================================
\r
157 [..] This section provides functions allowing to:
\r
158 (+) Start conversion of injected channel.
\r
159 (+) Stop conversion of injected channel.
\r
160 (+) Start multimode and enable DMA transfer.
\r
161 (+) Stop multimode and disable DMA transfer.
\r
162 (+) Get result of injected channel conversion.
\r
163 (+) Get result of multimode conversion.
\r
164 (+) Configure injected channels.
\r
165 (+) Configure multimode.
\r
172 * @brief Enables the selected ADC software start conversion of the injected channels.
\r
173 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
174 * the configuration information for the specified ADC.
\r
175 * @retval HAL status
\r
177 HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
\r
179 __IO uint32_t counter = 0;
\r
180 uint32_t tmp1 = 0, tmp2 = 0;
\r
182 /* Process locked */
\r
185 /* Check if a regular conversion is ongoing */
\r
186 if(hadc->State == HAL_ADC_STATE_BUSY_REG)
\r
188 /* Change ADC state */
\r
189 hadc->State = HAL_ADC_STATE_BUSY_INJ_REG;
\r
193 /* Change ADC state */
\r
194 hadc->State = HAL_ADC_STATE_BUSY_INJ;
\r
197 /* Check if ADC peripheral is disabled in order to enable it and wait during
\r
198 Tstab time the ADC's stabilization */
\r
199 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
\r
201 /* Enable the Peripheral */
\r
202 __HAL_ADC_ENABLE(hadc);
\r
204 /* Delay for temperature sensor stabilization time */
\r
205 /* Compute number of CPU cycles to wait for */
\r
206 counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000));
\r
207 while(counter != 0)
\r
213 /* Check if Multimode enabled */
\r
214 if(HAL_IS_BIT_CLR(ADC->CCR, ADC_CCR_MULTI))
\r
216 tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
\r
217 tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
\r
220 /* Enable the selected ADC software conversion for injected group */
\r
221 hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
\r
226 tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
\r
227 tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
\r
228 if((hadc->Instance == ADC1) && tmp1 && tmp2)
\r
230 /* Enable the selected ADC software conversion for injected group */
\r
231 hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
\r
235 /* Process unlocked */
\r
236 __HAL_UNLOCK(hadc);
\r
238 /* Return function status */
\r
243 * @brief Enables the interrupt and starts ADC conversion of injected channels.
\r
244 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
245 * the configuration information for the specified ADC.
\r
247 * @retval HAL status.
\r
249 HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
\r
251 __IO uint32_t counter = 0;
\r
252 uint32_t tmp1 = 0, tmp2 =0;
\r
254 /* Process locked */
\r
257 /* Check if a regular conversion is ongoing */
\r
258 if(hadc->State == HAL_ADC_STATE_BUSY_REG)
\r
260 /* Change ADC state */
\r
261 hadc->State = HAL_ADC_STATE_BUSY_INJ_REG;
\r
265 /* Change ADC state */
\r
266 hadc->State = HAL_ADC_STATE_BUSY_INJ;
\r
269 /* Set ADC error code to none */
\r
270 hadc->ErrorCode = HAL_ADC_ERROR_NONE;
\r
272 /* Check if ADC peripheral is disabled in order to enable it and wait during
\r
273 Tstab time the ADC's stabilization */
\r
274 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
\r
276 /* Enable the Peripheral */
\r
277 __HAL_ADC_ENABLE(hadc);
\r
279 /* Delay for temperature sensor stabilization time */
\r
280 /* Compute number of CPU cycles to wait for */
\r
281 counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000));
\r
282 while(counter != 0)
\r
288 /* Enable the ADC end of conversion interrupt for injected group */
\r
289 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
\r
291 /* Enable the ADC overrun interrupt */
\r
292 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
\r
294 /* Check if Multimode enabled */
\r
295 if(HAL_IS_BIT_CLR(ADC->CCR, ADC_CCR_MULTI))
\r
297 tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
\r
298 tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
\r
301 /* Enable the selected ADC software conversion for injected group */
\r
302 hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
\r
307 tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
\r
308 tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
\r
309 if((hadc->Instance == ADC1) && tmp1 && tmp2)
\r
311 /* Enable the selected ADC software conversion for injected group */
\r
312 hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
\r
316 /* Process unlocked */
\r
317 __HAL_UNLOCK(hadc);
\r
319 /* Return function status */
\r
324 * @brief Disables ADC and stop conversion of injected channels.
\r
326 * @note Caution: This function will stop also regular channels.
\r
328 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
329 * the configuration information for the specified ADC.
\r
330 * @retval HAL status.
\r
332 HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
\r
334 /* Disable the Peripheral */
\r
335 __HAL_ADC_DISABLE(hadc);
\r
337 /* Change ADC state */
\r
338 hadc->State = HAL_ADC_STATE_READY;
\r
340 /* Return function status */
\r
345 * @brief Poll for injected conversion complete
\r
346 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
347 * the configuration information for the specified ADC.
\r
348 * @param Timeout: Timeout value in millisecond.
\r
349 * @retval HAL status
\r
351 HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
\r
353 uint32_t tickstart = 0;
\r
356 tickstart = HAL_GetTick();
\r
358 /* Check End of conversion flag */
\r
359 while(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOC)))
\r
361 /* Check for the Timeout */
\r
362 if(Timeout != HAL_MAX_DELAY)
\r
364 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
366 hadc->State= HAL_ADC_STATE_TIMEOUT;
\r
367 /* Process unlocked */
\r
368 __HAL_UNLOCK(hadc);
\r
369 return HAL_TIMEOUT;
\r
374 /* Check if a regular conversion is ready */
\r
375 if(hadc->State == HAL_ADC_STATE_EOC_REG)
\r
377 /* Change ADC state */
\r
378 hadc->State = HAL_ADC_STATE_EOC_INJ_REG;
\r
382 /* Change ADC state */
\r
383 hadc->State = HAL_ADC_STATE_EOC_INJ;
\r
386 /* Return ADC state */
\r
391 * @brief Disables the interrupt and stop ADC conversion of injected channels.
\r
393 * @note Caution: This function will stop also regular channels.
\r
395 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
396 * the configuration information for the specified ADC.
\r
397 * @retval HAL status.
\r
399 HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
\r
401 /* Disable the ADC end of conversion interrupt for regular group */
\r
402 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
\r
404 /* Disable the ADC end of conversion interrupt for injected group */
\r
405 __HAL_ADC_DISABLE_IT(hadc, ADC_CR1_JEOCIE);
\r
407 /* Enable the Peripheral */
\r
408 __HAL_ADC_DISABLE(hadc);
\r
410 /* Change ADC state */
\r
411 hadc->State = HAL_ADC_STATE_READY;
\r
413 /* Return function status */
\r
418 * @brief Gets the converted value from data register of injected channel.
\r
419 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
420 * the configuration information for the specified ADC.
\r
421 * @param InjectedRank: the ADC injected rank.
\r
422 * This parameter can be one of the following values:
\r
423 * @arg ADC_INJECTED_RANK_1: Injected Channel1 selected
\r
424 * @arg ADC_INJECTED_RANK_2: Injected Channel2 selected
\r
425 * @arg ADC_INJECTED_RANK_3: Injected Channel3 selected
\r
426 * @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
\r
429 uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank)
\r
431 __IO uint32_t tmp = 0;
\r
433 /* Check the parameters */
\r
434 assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
\r
436 /* Clear the ADCx's flag for injected end of conversion */
\r
437 __HAL_ADC_CLEAR_FLAG(hadc,ADC_FLAG_JEOC);
\r
439 /* Return the selected ADC converted value */
\r
440 switch(InjectedRank)
\r
442 case ADC_INJECTED_RANK_4:
\r
444 tmp = hadc->Instance->JDR4;
\r
447 case ADC_INJECTED_RANK_3:
\r
449 tmp = hadc->Instance->JDR3;
\r
452 case ADC_INJECTED_RANK_2:
\r
454 tmp = hadc->Instance->JDR2;
\r
457 case ADC_INJECTED_RANK_1:
\r
459 tmp = hadc->Instance->JDR1;
\r
469 * @brief Enables ADC DMA request after last transfer (Multi-ADC mode) and enables ADC peripheral
\r
471 * @note Caution: This function must be used only with the ADC master.
\r
473 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
474 * the configuration information for the specified ADC.
\r
475 * @param pData: Pointer to buffer in which transferred from ADC peripheral to memory will be stored.
\r
476 * @param Length: The length of data to be transferred from ADC peripheral to memory.
\r
477 * @retval HAL status
\r
479 HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
\r
481 __IO uint32_t counter = 0;
\r
483 /* Check the parameters */
\r
484 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
\r
485 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
\r
486 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests));
\r
488 /* Process locked */
\r
491 /* Enable ADC overrun interrupt */
\r
492 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
\r
494 if (hadc->Init.DMAContinuousRequests != DISABLE)
\r
496 /* Enable the selected ADC DMA request after last transfer */
\r
497 ADC->CCR |= ADC_CCR_DDS;
\r
501 /* Disable the selected ADC EOC rising on each regular channel conversion */
\r
502 ADC->CCR &= ~ADC_CCR_DDS;
\r
505 /* Set the DMA transfer complete callback */
\r
506 hadc->DMA_Handle->XferCpltCallback = ADC_MultiModeDMAConvCplt;
\r
508 /* Set the DMA half transfer complete callback */
\r
509 hadc->DMA_Handle->XferHalfCpltCallback = ADC_MultiModeDMAHalfConvCplt;
\r
511 /* Set the DMA error callback */
\r
512 hadc->DMA_Handle->XferErrorCallback = ADC_MultiModeDMAError ;
\r
514 /* Enable the DMA Stream */
\r
515 HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&ADC->CDR, (uint32_t)pData, Length);
\r
517 /* Change ADC state */
\r
518 hadc->State = HAL_ADC_STATE_BUSY_REG;
\r
520 /* Check if ADC peripheral is disabled in order to enable it and wait during
\r
521 Tstab time the ADC's stabilization */
\r
522 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
\r
524 /* Enable the Peripheral */
\r
525 __HAL_ADC_ENABLE(hadc);
\r
527 /* Delay for temperature sensor stabilization time */
\r
528 /* Compute number of CPU cycles to wait for */
\r
529 counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000));
\r
530 while(counter != 0)
\r
536 /* if no external trigger present enable software conversion of regular channels */
\r
537 if((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET)
\r
539 /* Enable the selected ADC software conversion for regular group */
\r
540 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
\r
543 /* Process unlocked */
\r
544 __HAL_UNLOCK(hadc);
\r
546 /* Return function status */
\r
551 * @brief Disables ADC DMA (multi-ADC mode) and disables ADC peripheral
\r
552 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
553 * the configuration information for the specified ADC.
\r
554 * @retval HAL status
\r
556 HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
\r
558 /* Process locked */
\r
561 /* Enable the Peripheral */
\r
562 __HAL_ADC_DISABLE(hadc);
\r
564 /* Disable ADC overrun interrupt */
\r
565 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
\r
567 /* Disable the selected ADC DMA request after last transfer */
\r
568 ADC->CCR &= ~ADC_CCR_DDS;
\r
570 /* Disable the ADC DMA Stream */
\r
571 HAL_DMA_Abort(hadc->DMA_Handle);
\r
573 /* Change ADC state */
\r
574 hadc->State = HAL_ADC_STATE_READY;
\r
576 /* Process unlocked */
\r
577 __HAL_UNLOCK(hadc);
\r
579 /* Return function status */
\r
584 * @brief Returns the last ADC1, ADC2 and ADC3 regular conversions results
\r
585 * data in the selected multi mode.
\r
586 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
587 * the configuration information for the specified ADC.
\r
588 * @retval The converted data value.
\r
590 uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
\r
592 /* Return the multi mode conversion value */
\r
597 * @brief Injected conversion complete callback in non blocking mode
\r
598 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
599 * the configuration information for the specified ADC.
\r
602 __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
\r
604 /* NOTE : This function Should not be modified, when the callback is needed,
\r
605 the HAL_ADC_InjectedConvCpltCallback could be implemented in the user file
\r
610 * @brief Configures for the selected ADC injected channel its corresponding
\r
611 * rank in the sequencer and its sample time.
\r
612 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
\r
613 * the configuration information for the specified ADC.
\r
614 * @param sConfigInjected: ADC configuration structure for injected channel.
\r
617 HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected)
\r
620 #ifdef USE_FULL_ASSERT
\r
622 #endif /* USE_FULL_ASSERT */
\r
624 /* Check the parameters */
\r
625 assert_param(IS_ADC_CHANNEL(sConfigInjected->InjectedChannel));
\r
626 assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
\r
627 assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime));
\r
628 assert_param(IS_ADC_EXT_INJEC_TRIG(sConfigInjected->ExternalTrigInjecConv));
\r
629 assert_param(IS_ADC_EXT_INJEC_TRIG_EDGE(sConfigInjected->ExternalTrigInjecConvEdge));
\r
630 assert_param(IS_ADC_INJECTED_LENGTH(sConfigInjected->InjectedNbrOfConversion));
\r
631 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv));
\r
632 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
\r
634 #ifdef USE_FULL_ASSERT
\r
635 tmp = ADC_GET_RESOLUTION(hadc);
\r
636 assert_param(IS_ADC_RANGE(tmp, sConfigInjected->InjectedOffset));
\r
637 #endif /* USE_FULL_ASSERT */
\r
639 /* Process locked */
\r
642 /* if ADC_Channel_10 ... ADC_Channel_18 is selected */
\r
643 if (sConfigInjected->InjectedChannel > ADC_CHANNEL_9)
\r
645 /* Clear the old sample time */
\r
646 hadc->Instance->SMPR1 &= ~ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel);
\r
648 /* Set the new sample time */
\r
649 hadc->Instance->SMPR1 |= ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel);
\r
651 else /* ADC_Channel include in ADC_Channel_[0..9] */
\r
653 /* Clear the old sample time */
\r
654 hadc->Instance->SMPR2 &= ~ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel);
\r
656 /* Set the new sample time */
\r
657 hadc->Instance->SMPR2 |= ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel);
\r
660 /*---------------------------- ADCx JSQR Configuration -----------------*/
\r
661 hadc->Instance->JSQR &= ~(ADC_JSQR_JL);
\r
662 hadc->Instance->JSQR |= ADC_SQR1(sConfigInjected->InjectedNbrOfConversion);
\r
664 /* Rank configuration */
\r
666 /* Clear the old SQx bits for the selected rank */
\r
667 hadc->Instance->JSQR &= ~ADC_JSQR(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion);
\r
669 /* Set the SQx bits for the selected rank */
\r
670 hadc->Instance->JSQR |= ADC_JSQR(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion);
\r
672 /* Select external trigger to start conversion */
\r
673 hadc->Instance->CR2 &= ~(ADC_CR2_JEXTSEL);
\r
674 hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConv;
\r
676 /* Select external trigger polarity */
\r
677 hadc->Instance->CR2 &= ~(ADC_CR2_JEXTEN);
\r
678 hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConvEdge;
\r
680 if (sConfigInjected->AutoInjectedConv != DISABLE)
\r
682 /* Enable the selected ADC automatic injected group conversion */
\r
683 hadc->Instance->CR1 |= ADC_CR1_JAUTO;
\r
687 /* Disable the selected ADC automatic injected group conversion */
\r
688 hadc->Instance->CR1 &= ~(ADC_CR1_JAUTO);
\r
691 if (sConfigInjected->InjectedDiscontinuousConvMode != DISABLE)
\r
693 /* Enable the selected ADC injected discontinuous mode */
\r
694 hadc->Instance->CR1 |= ADC_CR1_JDISCEN;
\r
698 /* Disable the selected ADC injected discontinuous mode */
\r
699 hadc->Instance->CR1 &= ~(ADC_CR1_JDISCEN);
\r
702 switch(sConfigInjected->InjectedRank)
\r
705 /* Set injected channel 1 offset */
\r
706 hadc->Instance->JOFR1 &= ~(ADC_JOFR1_JOFFSET1);
\r
707 hadc->Instance->JOFR1 |= sConfigInjected->InjectedOffset;
\r
710 /* Set injected channel 2 offset */
\r
711 hadc->Instance->JOFR2 &= ~(ADC_JOFR2_JOFFSET2);
\r
712 hadc->Instance->JOFR2 |= sConfigInjected->InjectedOffset;
\r
715 /* Set injected channel 3 offset */
\r
716 hadc->Instance->JOFR3 &= ~(ADC_JOFR3_JOFFSET3);
\r
717 hadc->Instance->JOFR3 |= sConfigInjected->InjectedOffset;
\r
720 /* Set injected channel 4 offset */
\r
721 hadc->Instance->JOFR4 &= ~(ADC_JOFR4_JOFFSET4);
\r
722 hadc->Instance->JOFR4 |= sConfigInjected->InjectedOffset;
\r
726 /* if ADC1 Channel_18 is selected enable VBAT Channel */
\r
727 if ((hadc->Instance == ADC1) && (sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT))
\r
729 /* Enable the VBAT channel*/
\r
730 ADC->CCR |= ADC_CCR_VBATE;
\r
733 /* if ADC1 Channel_16 or Channel_17 is selected enable TSVREFE Channel(Temperature sensor and VREFINT) */
\r
734 if ((hadc->Instance == ADC1) && ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)))
\r
736 /* Enable the TSVREFE channel*/
\r
737 ADC->CCR |= ADC_CCR_TSVREFE;
\r
740 /* Process unlocked */
\r
741 __HAL_UNLOCK(hadc);
\r
743 /* Return function status */
\r
748 * @brief Configures the ADC multi-mode
\r
749 * @param hadc : pointer to a ADC_HandleTypeDef structure that contains
\r
750 * the configuration information for the specified ADC.
\r
751 * @param multimode : pointer to an ADC_MultiModeTypeDef structure that contains
\r
752 * the configuration information for multimode.
\r
753 * @retval HAL status
\r
755 HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode)
\r
757 /* Check the parameters */
\r
758 assert_param(IS_ADC_MODE(multimode->Mode));
\r
759 assert_param(IS_ADC_DMA_ACCESS_MODE(multimode->DMAAccessMode));
\r
760 assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay));
\r
762 /* Process locked */
\r
766 ADC->CCR &= ~(ADC_CCR_MULTI);
\r
767 ADC->CCR |= multimode->Mode;
\r
769 /* Set the ADC DMA access mode */
\r
770 ADC->CCR &= ~(ADC_CCR_DMA);
\r
771 ADC->CCR |= multimode->DMAAccessMode;
\r
773 /* Set delay between two sampling phases */
\r
774 ADC->CCR &= ~(ADC_CCR_DELAY);
\r
775 ADC->CCR |= multimode->TwoSamplingDelay;
\r
777 /* Process unlocked */
\r
778 __HAL_UNLOCK(hadc);
\r
780 /* Return function status */
\r
789 * @brief DMA transfer complete callback.
\r
790 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
791 * the configuration information for the specified DMA module.
\r
794 static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma)
\r
796 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
798 /* Check if an injected conversion is ready */
\r
799 if(hadc->State == HAL_ADC_STATE_EOC_INJ)
\r
801 /* Change ADC state */
\r
802 hadc->State = HAL_ADC_STATE_EOC_INJ_REG;
\r
806 /* Change ADC state */
\r
807 hadc->State = HAL_ADC_STATE_EOC_REG;
\r
810 HAL_ADC_ConvCpltCallback(hadc);
\r
814 * @brief DMA half transfer complete callback.
\r
815 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
816 * the configuration information for the specified DMA module.
\r
819 static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma)
\r
821 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
822 /* Conversion complete callback */
\r
823 HAL_ADC_ConvHalfCpltCallback(hadc);
\r
827 * @brief DMA error callback
\r
828 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
829 * the configuration information for the specified DMA module.
\r
832 static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma)
\r
834 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
835 hadc->State= HAL_ADC_STATE_ERROR;
\r
836 /* Set ADC error code to DMA error */
\r
837 hadc->ErrorCode |= HAL_ADC_ERROR_DMA;
\r
838 HAL_ADC_ErrorCallback(hadc);
\r
845 #endif /* HAL_ADC_MODULE_ENABLED */
\r
854 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r