2 ******************************************************************************
3 * @file stm32f3xx_hal_adc.c
4 * @author MCD Application Team
5 * @brief This file provides firmware functions to manage the following
6 * functionalities of the Analog to Digital Convertor (ADC)
8 * + Initialization and de-initialization functions
9 * ++ Initialization and Configuration of ADC
10 * + Operation functions
11 * ++ Start, stop, get result of conversions of regular
12 * group, using 3 possible modes: polling, interruption or DMA.
14 * ++ Channels configuration on regular group
15 * ++ Channels configuration on injected group
16 * ++ Analog Watchdog configuration
18 * ++ ADC state machine management
19 * ++ Interrupts and flags management
20 * Other functions (extended functions) are available in file
21 * "stm32f3xx_hal_adc_ex.c".
24 ==============================================================================
25 ##### ADC peripheral features #####
26 ==============================================================================
28 (+) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution (available only on
31 (+) Interrupt generation at the end of regular conversion, end of injected
32 conversion, and in case of analog watchdog or overrun events.
34 (+) Single and continuous conversion modes.
36 (+) Scan mode for conversion of several channels sequentially.
38 (+) Data alignment with in-built data coherency.
40 (+) Programmable sampling time (channel wise)
42 (+) ADC conversion of regular group and injected group.
44 (+) External trigger (timer or EXTI) with configurable polarity
45 for both regular and injected groups.
47 (+) DMA request generation for transfer of conversions data of regular group.
49 (+) Multimode dual mode (available on devices with 2 ADCs or more).
51 (+) Configurable DMA data storage in Multimode Dual mode (available on devices
54 (+) Configurable delay between conversions in Dual interleaved mode (available
55 on devices with 2 DCs or more).
59 (+) ADC channels selectable single/differential input (available only on
62 (+) ADC Injected sequencer&channels configuration context queue (available
63 only on STM32F30xxC devices)
65 (+) ADC offset on injected and regular groups (offset on regular group
66 available only on STM32F30xxC devices)
68 (+) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at
71 (+) ADC input range: from Vref- (connected to Vssa) to Vref+ (connected to
72 Vdda or to an external voltage reference).
75 ##### How to use this driver #####
76 ==============================================================================
79 *** Configuration of top level parameters related to ADC ***
80 ============================================================
83 (#) Enable the ADC interface
84 (++) As prerequisite, ADC clock must be configured at RCC top level.
86 (++) For STM32F30x/STM32F33x devices:
87 Two possible clock sources: synchronous clock derived from AHB clock
88 or asynchronous clock derived from ADC dedicated PLL 72MHz.
89 - Synchronous clock is mandatory since used as ADC core clock.
90 Synchronous clock can be used optionally as ADC conversion clock, depending on ADC init structure clock setting.
91 Synchronous clock is configured using macro __ADCx_CLK_ENABLE().
92 - Asynchronous can be used optionally as ADC conversion clock, depending on ADC init structure clock setting.
93 Asynchronous clock is configured using function HAL_RCCEx_PeriphCLKConfig().
94 (+++) For example, in case of device with a single ADC:
95 Into HAL_ADC_MspInit() (recommended code location) or with
96 other device clock parameters configuration:
97 (+++) __HAL_RCC_ADC1_CLK_ENABLE() (mandatory)
98 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if ADC conversion from asynchronous clock)
99 (+++) PeriphClkInit.Adc1ClockSelection = RCC_ADC1PLLCLK_DIV1 (optional, if ADC conversion from asynchronous clock)
100 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if ADC conversion from asynchronous clock)
102 (+++) For example, in case of device with 4 ADCs:
104 (+++) if((hadc->Instance == ADC1) || (hadc->Instance == ADC2))
106 (+++) __HAL_RCC_ADC12_CLK_ENABLE() (mandatory)
107 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if ADC conversion from asynchronous clock)
108 (+++) PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_DIV1 (optional, if ADC conversion from asynchronous clock)
109 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if ADC conversion from asynchronous clock)
113 (+++) __HAL_RCC_ADC34_CLK_ENABLE() (mandatory)
114 (+++) PeriphClkInit.Adc34ClockSelection = RCC_ADC34PLLCLK_DIV1; (optional, if ADC conversion from asynchronous clock)
115 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure); (optional, if ADC conversion from asynchronous clock)
118 (++) For STM32F37x devices:
119 One clock setting is mandatory:
120 ADC clock (core and conversion clock) from APB2 clock.
122 Into HAL_ADC_MspInit() (recommended code location) or with
123 other device clock parameters configuration:
124 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC
125 (+++) PeriphClkInit.AdcClockSelection = RCC_ADCPLLCLK_DIV2
126 (+++) HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)
128 (#) ADC pins configuration
129 (++) Enable the clock for the ADC GPIOs
130 using macro __HAL_RCC_GPIOx_CLK_ENABLE()
131 (++) Configure these ADC pins in analog mode
132 using function HAL_GPIO_Init()
134 (#) Optionally, in case of usage of ADC with interruptions:
135 (++) Configure the NVIC for ADC
136 using function HAL_NVIC_EnableIRQ(ADCx_IRQn)
137 (++) Insert the ADC interruption handler function HAL_ADC_IRQHandler()
138 into the function of corresponding ADC interruption vector
141 (#) Optionally, in case of usage of DMA:
142 (++) Configure the DMA (DMA channel, mode normal or circular, ...)
143 using function HAL_DMA_Init().
144 (++) Configure the NVIC for DMA
145 using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn)
146 (++) Insert the ADC interruption handler function HAL_ADC_IRQHandler()
147 into the function of corresponding DMA interruption vector
148 DMAx_Channelx_IRQHandler().
150 *** Configuration of ADC, groups regular/injected, channels parameters ***
151 ==========================================================================
154 (#) Configure the ADC parameters (resolution, data alignment, ...)
155 and regular group parameters (conversion trigger, sequencer, ...)
156 using function HAL_ADC_Init().
158 (#) Configure the channels for regular group parameters (channel number,
159 channel rank into sequencer, ..., into regular group)
160 using function HAL_ADC_ConfigChannel().
162 (#) Optionally, configure the injected group parameters (conversion trigger,
163 sequencer, ..., of injected group)
164 and the channels for injected group parameters (channel number,
165 channel rank into sequencer, ..., into injected group)
166 using function HAL_ADCEx_InjectedConfigChannel().
168 (#) Optionally, configure the analog watchdog parameters (channels
169 monitored, thresholds, ...)
170 using function HAL_ADC_AnalogWDGConfig().
172 (#) Optionally, for devices with several ADC instances: configure the
174 using function HAL_ADCEx_MultiModeConfigChannel().
176 *** Execution of ADC conversions ***
177 ====================================
180 (#) Optionally, perform an automatic ADC calibration to improve the
182 using function HAL_ADCEx_Calibration_Start().
184 (#) ADC driver can be used among three modes: polling, interruption,
187 (++) ADC conversion by polling:
188 (+++) Activate the ADC peripheral and start conversions
189 using function HAL_ADC_Start()
190 (+++) Wait for ADC conversion completion
191 using function HAL_ADC_PollForConversion()
192 (or for injected group: HAL_ADCEx_InjectedPollForConversion() )
193 (+++) Retrieve conversion results
194 using function HAL_ADC_GetValue()
195 (or for injected group: HAL_ADCEx_InjectedGetValue() )
196 (+++) Stop conversion and disable the ADC peripheral
197 using function HAL_ADC_Stop()
199 (++) ADC conversion by interruption:
200 (+++) Activate the ADC peripheral and start conversions
201 using function HAL_ADC_Start_IT()
202 (+++) Wait for ADC conversion completion by call of function
203 HAL_ADC_ConvCpltCallback()
204 (this function must be implemented in user program)
205 (or for injected group: HAL_ADCEx_InjectedConvCpltCallback() )
206 (+++) Retrieve conversion results
207 using function HAL_ADC_GetValue()
208 (or for injected group: HAL_ADCEx_InjectedGetValue() )
209 (+++) Stop conversion and disable the ADC peripheral
210 using function HAL_ADC_Stop_IT()
212 (++) ADC conversion with transfer by DMA:
213 (+++) Activate the ADC peripheral and start conversions
214 using function HAL_ADC_Start_DMA()
215 (+++) Wait for ADC conversion completion by call of function
216 HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
217 (these functions must be implemented in user program)
218 (+++) Conversion results are automatically transferred by DMA into
219 destination variable address.
220 (+++) Stop conversion and disable the ADC peripheral
221 using function HAL_ADC_Stop_DMA()
223 (++) For devices with several ADCs: ADC multimode conversion
224 with transfer by DMA:
225 (+++) Activate the ADC peripheral (slave)
226 using function HAL_ADC_Start()
227 (conversion start pending ADC master)
228 (+++) Activate the ADC peripheral (master) and start conversions
229 using function HAL_ADCEx_MultiModeStart_DMA()
230 (+++) Wait for ADC conversion completion by call of function
231 HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
232 (these functions must be implemented in user program)
233 (+++) Conversion results are automatically transferred by DMA into
234 destination variable address.
235 (+++) Stop conversion and disable the ADC peripheral (master)
236 using function HAL_ADCEx_MultiModeStop_DMA()
237 (+++) Stop conversion and disable the ADC peripheral (slave)
238 using function HAL_ADC_Stop_IT()
242 (@) Callback functions must be implemented in user program:
243 (+@) HAL_ADC_ErrorCallback()
244 (+@) HAL_ADC_LevelOutOfWindowCallback() (callback of analog watchdog)
245 (+@) HAL_ADC_ConvCpltCallback()
246 (+@) HAL_ADC_ConvHalfCpltCallback
247 (+@) HAL_ADCEx_InjectedConvCpltCallback()
248 (+@) HAL_ADCEx_InjectedQueueOverflowCallback() (for STM32F30x/STM32F33x devices)
250 *** Deinitialization of ADC ***
251 ============================================================
254 (#) Disable the ADC interface
255 (++) ADC clock can be hard reset and disabled at RCC top level.
256 (++) Hard reset of ADC peripherals
257 using macro __ADCx_FORCE_RESET(), __ADCx_RELEASE_RESET().
258 (++) ADC clock disable
259 using the equivalent macro/functions as configuration step.
261 (++) For STM32F30x/STM32F33x devices:
262 Caution: For devices with several ADCs:
263 These settings impact both ADC of common group: ADC1&ADC2, ADC3&ADC4
264 if available (ADC2, ADC3, ADC4 availability depends on STM32 product)
266 (+++) For example, in case of device with a single ADC:
267 Into HAL_ADC_MspDeInit() (recommended code location) or with
268 other device clock parameters configuration:
269 (+++) __HAL_RCC_ADC1_FORCE_RESET() (optional)
270 (+++) __HAL_RCC_ADC1_RELEASE_RESET() (optional)
271 (+++) __HAL_RCC_ADC1_CLK_DISABLE() (mandatory)
272 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if configured before)
273 (+++) PeriphClkInit.Adc1ClockSelection = RCC_ADC1PLLCLK_OFF (optional, if configured before)
274 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
276 (+++) For example, in case of device with 4 ADCs:
277 (+++) if((hadc->Instance == ADC1) || (hadc->Instance == ADC2))
279 (+++) __HAL_RCC_ADC12_FORCE_RESET() (optional)
280 (+++) __HAL_RCC_ADC12_RELEASE_RESET() (optional)
281 (+++) __HAL_RCC_ADC12_CLK_DISABLE() (mandatory)
282 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if configured before)
283 (+++) PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_OFF (optional, if configured before)
284 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
288 (+++) __HAL_RCC_ADC32_FORCE_RESET() (optional)
289 (+++) __HAL_RCC_ADC32_RELEASE_RESET() (optional)
290 (+++) __HAL_RCC_ADC34_CLK_DISABLE() (mandatory)
291 (+++) PeriphClkInit.Adc34ClockSelection = RCC_ADC34PLLCLK_OFF (optional, if configured before)
292 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
295 (++) For STM32F37x devices:
297 Into HAL_ADC_MspDeInit() (recommended code location) or with
298 other device clock parameters configuration:
299 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC
300 (+++) PeriphClkInit.AdcClockSelection = RCC_ADCPLLCLK_OFF
301 (+++) HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)
303 (#) ADC pins configuration
304 (++) Disable the clock for the ADC GPIOs
305 using macro __HAL_RCC_GPIOx_CLK_DISABLE()
307 (#) Optionally, in case of usage of ADC with interruptions:
308 (++) Disable the NVIC for ADC
309 using function HAL_NVIC_EnableIRQ(ADCx_IRQn)
311 (#) Optionally, in case of usage of DMA:
312 (++) Deinitialize the DMA
313 using function HAL_DMA_Init().
314 (++) Disable the NVIC for DMA
315 using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn)
320 ******************************************************************************
323 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
325 * Redistribution and use in source and binary forms, with or without modification,
326 * are permitted provided that the following conditions are met:
327 * 1. Redistributions of source code must retain the above copyright notice,
328 * this list of conditions and the following disclaimer.
329 * 2. Redistributions in binary form must reproduce the above copyright notice,
330 * this list of conditions and the following disclaimer in the documentation
331 * and/or other materials provided with the distribution.
332 * 3. Neither the name of STMicroelectronics nor the names of its contributors
333 * may be used to endorse or promote products derived from this software
334 * without specific prior written permission.
336 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
337 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
338 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
339 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
340 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
341 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
342 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
343 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
344 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
345 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
347 ******************************************************************************
350 /* Includes ------------------------------------------------------------------*/
351 #include "stm32f3xx_hal.h"
353 /** @addtogroup STM32F3xx_HAL_Driver
357 /** @defgroup ADC ADC
358 * @brief ADC HAL module driver
362 #ifdef HAL_ADC_MODULE_ENABLED
364 /* Private typedef -----------------------------------------------------------*/
365 /* Private define ------------------------------------------------------------*/
366 /* Private macro -------------------------------------------------------------*/
367 /* Private variables ---------------------------------------------------------*/
368 /* Private function prototypes -----------------------------------------------*/
369 /* Exported functions --------------------------------------------------------*/
371 /** @defgroup ADC_Exported_Functions ADC Exported Functions
375 /** @defgroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions
376 * @brief Initialization and Configuration functions
379 ===============================================================================
380 ##### Initialization and de-initialization functions #####
381 ===============================================================================
382 [..] This section provides functions allowing to:
383 (+) Initialize and configure the ADC.
384 (+) De-initialize the ADC.
391 * @brief Initializes the ADC peripheral and regular group according to
392 * parameters specified in structure "ADC_InitTypeDef".
393 * @note As prerequisite, ADC clock must be configured at RCC top level
394 * depending on both possible clock sources: PLL clock or AHB clock.
395 * See commented example code below that can be copied and uncommented
396 * into HAL_ADC_MspInit().
397 * @note Possibility to update parameters on the fly:
398 * This function initializes the ADC MSP (HAL_ADC_MspInit()) only when
399 * coming from ADC state reset. Following calls to this function can
400 * be used to reconfigure some parameters of ADC_InitTypeDef
401 * structure on the fly, without modifying MSP configuration. If ADC
402 * MSP has to be modified again, HAL_ADC_DeInit() must be called
403 * before HAL_ADC_Init().
404 * The setting of these parameters is conditioned to ADC state.
405 * For parameters constraints, see comments of structure
407 * @note This function configures the ADC within 2 scopes: scope of entire
408 * ADC and scope of regular group. For parameters details, see comments
409 * of structure "ADC_InitTypeDef".
410 * @note For devices with several ADCs: parameters related to common ADC
411 * registers (ADC clock mode) are set only if all ADCs sharing the
412 * same common group are disabled.
413 * If this is not the case, these common parameters setting are
414 * bypassed without error reporting: it can be the intended behaviour in
415 * case of update of a parameter of ADC_InitTypeDef on the fly,
416 * without disabling the other ADCs sharing the same common group.
417 * @param hadc ADC handle
420 __weak HAL_StatusTypeDef
HAL_ADC_Init(ADC_HandleTypeDef
* hadc
)
422 /* Prevent unused argument(s) compilation warning */
425 /* Note : This function is defined into this file for library reference. */
426 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
428 /* Return function status */
433 * @brief Deinitialize the ADC peripheral registers to their default reset
434 * values, with deinitialization of the ADC MSP.
435 * @note For devices with several ADCs: reset of ADC common registers is done
436 * only if all ADCs sharing the same common group are disabled.
437 * If this is not the case, reset of these common parameters reset is
438 * bypassed without error reporting: it can be the intended behaviour in
439 * case of reset of a single ADC while the other ADCs sharing the same
440 * common group is still running.
441 * @note For devices with several ADCs: Global reset of all ADCs sharing a
442 * common group is possible.
443 * As this function is intended to reset a single ADC, to not impact
444 * other ADCs, instructions for global reset of multiple ADCs have been
445 * let commented below.
446 * If needed, the example code can be copied and uncommented into
447 * function HAL_ADC_MspDeInit().
448 * @param hadc ADC handle
451 __weak HAL_StatusTypeDef
HAL_ADC_DeInit(ADC_HandleTypeDef
* hadc
)
453 /* Prevent unused argument(s) compilation warning */
456 /* Note : This function is defined into this file for library reference. */
457 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
459 /* Return function status */
464 * @brief Initializes the ADC MSP.
465 * @param hadc ADC handle
468 __weak
void HAL_ADC_MspInit(ADC_HandleTypeDef
* hadc
)
470 /* Prevent unused argument(s) compilation warning */
473 /* NOTE : This function should not be modified. When the callback is needed,
474 function HAL_ADC_MspInit must be implemented in the user file.
479 * @brief DeInitializes the ADC MSP.
480 * @param hadc ADC handle
483 __weak
void HAL_ADC_MspDeInit(ADC_HandleTypeDef
* hadc
)
485 /* Prevent unused argument(s) compilation warning */
488 /* NOTE : This function should not be modified. When the callback is needed,
489 function HAL_ADC_MspDeInit must be implemented in the user file.
497 /** @defgroup ADC_Exported_Functions_Group2 Input and Output operation functions
498 * @brief IO operation functions
501 ===============================================================================
502 ##### IO operation functions #####
503 ===============================================================================
504 [..] This section provides functions allowing to:
505 (+) Start conversion of regular group.
506 (+) Stop conversion of regular group.
507 (+) Poll for conversion complete on regular group.
508 (+) Poll for conversion event.
509 (+) Get result of regular channel conversion.
510 (+) Start conversion of regular group and enable interruptions.
511 (+) Stop conversion of regular group and disable interruptions.
512 (+) Handle ADC interrupt request
513 (+) Start conversion of regular group and enable DMA transfer.
514 (+) Stop conversion of regular group and disable ADC DMA transfer.
520 * @brief Enables ADC, starts conversion of regular group.
521 * Interruptions enabled in this function: None.
522 * @note: Case of multimode enabled (for devices with several ADCs): This
523 * function must be called for ADC slave first, then ADC master.
524 * For ADC slave, ADC is enabled only (conversion is not started).
525 * For ADC master, ADC is enabled and multimode conversion is started.
526 * @param hadc ADC handle
529 __weak HAL_StatusTypeDef
HAL_ADC_Start(ADC_HandleTypeDef
* hadc
)
531 /* Prevent unused argument(s) compilation warning */
534 /* Return function status */
539 * @brief Stop ADC conversion of regular group (and injected group in
540 * case of auto_injection mode), disable ADC peripheral.
541 * @note: ADC peripheral disable is forcing stop of potential
542 * conversion on injected group. If injected group is under use, it
543 * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
544 * @note: Case of multimode enabled (for devices with several ADCs): This
545 * function must be called for ADC master first, then ADC slave.
546 * For ADC master, converson is stopped and ADC is disabled.
547 * For ADC slave, ADC is disabled only (conversion stop of ADC master
548 * has already stopped conversion of ADC slave).
549 * @param hadc ADC handle
550 * @retval HAL status.
552 __weak HAL_StatusTypeDef
HAL_ADC_Stop(ADC_HandleTypeDef
* hadc
)
554 /* Prevent unused argument(s) compilation warning */
557 /* Note : This function is defined into this file for library reference. */
558 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
560 /* Return function status */
565 * @brief Wait for regular group conversion to be completed.
566 * @param hadc ADC handle
567 * @param Timeout Timeout value in millisecond.
570 __weak HAL_StatusTypeDef
HAL_ADC_PollForConversion(ADC_HandleTypeDef
* hadc
, uint32_t Timeout
)
572 /* Prevent unused argument(s) compilation warning */
576 /* Note : This function is defined into this file for library reference. */
577 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
579 /* Return function status */
584 * @brief Poll for conversion event.
585 * @param hadc ADC handle
586 * @param EventType the ADC event type.
587 * This parameter can be one of the following values:
588 * @arg ADC_AWD_EVENT: ADC Analog watchdog 1 event (main analog watchdog, present on all STM32 devices)
589 * @arg ADC_AWD2_EVENT: ADC Analog watchdog 2 event (additional analog watchdog, present only on STM32F3 devices)
590 * @arg ADC_AWD3_EVENT: ADC Analog watchdog 3 event (additional analog watchdog, present only on STM32F3 devices)
591 * @arg ADC_OVR_EVENT: ADC Overrun event
592 * @arg ADC_JQOVF_EVENT: ADC Injected context queue overflow event
593 * @param Timeout Timeout value in millisecond.
596 __weak HAL_StatusTypeDef
HAL_ADC_PollForEvent(ADC_HandleTypeDef
* hadc
, uint32_t EventType
, uint32_t Timeout
)
598 /* Prevent unused argument(s) compilation warning */
603 /* Note : This function is defined into this file for library reference. */
604 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
606 /* Return function status */
611 * @brief Enables ADC, starts conversion of regular group with interruption.
612 * Interruptions enabled in this function:
613 * - EOC (end of conversion of regular group) or EOS (end of
614 * sequence of regular group) depending on ADC initialization
615 * parameter "EOCSelection" (if available)
616 * - overrun (if available)
617 * Each of these interruptions has its dedicated callback function.
618 * @note: Case of multimode enabled (for devices with several ADCs): This
619 * function must be called for ADC slave first, then ADC master.
620 * For ADC slave, ADC is enabled only (conversion is not started).
621 * For ADC master, ADC is enabled and multimode conversion is started.
622 * @param hadc ADC handle
625 __weak HAL_StatusTypeDef
HAL_ADC_Start_IT(ADC_HandleTypeDef
* hadc
)
627 /* Prevent unused argument(s) compilation warning */
630 /* Note : This function is defined into this file for library reference. */
631 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
633 /* Return function status */
638 * @brief Stop ADC conversion of regular group (and injected group in
639 * case of auto_injection mode), disable interruption of
640 * end-of-conversion, disable ADC peripheral.
641 * @note: ADC peripheral disable is forcing stop of potential
642 * conversion on injected group. If injected group is under use, it
643 * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
644 * @note: Case of multimode enabled (for devices with several ADCs): This
645 * function must be called for ADC master first, then ADC slave.
646 * For ADC master, conversion is stopped and ADC is disabled.
647 * For ADC slave, ADC is disabled only (conversion stop of ADC master
648 * has already stopped conversion of ADC slave).
649 * @param hadc ADC handle
650 * @retval HAL status.
652 __weak HAL_StatusTypeDef
HAL_ADC_Stop_IT(ADC_HandleTypeDef
* hadc
)
654 /* Prevent unused argument(s) compilation warning */
657 /* Note : This function is defined into this file for library reference. */
658 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
660 /* Return function status */
665 * @brief Enables ADC, starts conversion of regular group and transfers result
667 * Interruptions enabled in this function:
668 * - DMA transfer complete
669 * - DMA half transfer
670 * - overrun (if available)
671 * Each of these interruptions has its dedicated callback function.
672 * @note: Case of multimode enabled (for devices with several ADCs): This
673 * function is for single-ADC mode only. For multimode, use the
674 * dedicated MultimodeStart function.
675 * @param hadc ADC handle
676 * @param pData The destination Buffer address.
677 * @param Length The length of data to be transferred from ADC peripheral to memory.
680 __weak HAL_StatusTypeDef
HAL_ADC_Start_DMA(ADC_HandleTypeDef
* hadc
, uint32_t* pData
, uint32_t Length
)
682 /* Prevent unused argument(s) compilation warning */
687 /* Note : This function is defined into this file for library reference. */
688 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
690 /* Return function status */
695 * @brief Stop ADC conversion of regular group (and injected group in
696 * case of auto_injection mode), disable ADC DMA transfer, disable
698 * @note: ADC peripheral disable is forcing stop of potential
699 * conversion on injected group. If injected group is under use, it
700 * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
701 * @note: Case of multimode enabled (for devices with several ADCs): This
702 * function is for single-ADC mode only. For multimode, use the
703 * dedicated MultimodeStop function.
704 * @param hadc ADC handle
705 * @retval HAL status.
707 __weak HAL_StatusTypeDef
HAL_ADC_Stop_DMA(ADC_HandleTypeDef
* hadc
)
709 /* Prevent unused argument(s) compilation warning */
712 /* Note : This function is defined into this file for library reference. */
713 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
715 /* Return function status */
720 * @brief Get ADC regular group conversion result.
721 * @note Reading DR register automatically clears EOC (end of conversion of
722 * regular group) flag.
723 * Additionally, this functions clears EOS (end of sequence of
724 * regular group) flag, in case of the end of the sequence is reached.
725 * @param hadc ADC handle
726 * @retval Converted value
728 __weak
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef
* hadc
)
730 /* Note : This function is defined into this file for library reference. */
731 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
733 /* Return ADC converted value */
734 return hadc
->Instance
->DR
;
738 * @brief Handles ADC interrupt request.
739 * @param hadc ADC handle
742 __weak
void HAL_ADC_IRQHandler(ADC_HandleTypeDef
* hadc
)
744 /* Prevent unused argument(s) compilation warning */
747 /* Note : This function is defined into this file for library reference. */
748 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
752 * @brief Conversion complete callback in non blocking mode
753 * @param hadc ADC handle
756 __weak
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef
* hadc
)
758 /* Prevent unused argument(s) compilation warning */
761 /* NOTE : This function should not be modified. When the callback is needed,
762 function HAL_ADC_ConvCpltCallback must be implemented in the user file.
767 * @brief Conversion DMA half-transfer callback in non blocking mode
768 * @param hadc ADC handle
771 __weak
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef
* hadc
)
773 /* Prevent unused argument(s) compilation warning */
776 /* NOTE : This function should not be modified. When the callback is needed,
777 function HAL_ADC_ConvHalfCpltCallback must be implemented in the user file.
782 * @brief Analog watchdog callback in non blocking mode.
783 * @param hadc ADC handle
786 __weak
void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef
* hadc
)
788 /* Prevent unused argument(s) compilation warning */
791 /* NOTE : This function should not be modified. When the callback is needed,
792 function HAL_ADC_LevelOoutOfWindowCallback must be implemented in the user file.
797 * @brief ADC error callback in non blocking mode
798 * (ADC conversion with interruption or transfer by DMA)
799 * @param hadc ADC handle
802 __weak
void HAL_ADC_ErrorCallback(ADC_HandleTypeDef
*hadc
)
804 /* Prevent unused argument(s) compilation warning */
807 /* NOTE : This function should not be modified. When the callback is needed,
808 function HAL_ADC_ErrorCallback must be implemented in the user file.
816 /** @defgroup ADC_Exported_Functions_Group3 Peripheral Control functions
817 * @brief Peripheral Control functions
820 ===============================================================================
821 ##### Peripheral Control functions #####
822 ===============================================================================
823 [..] This section provides functions allowing to:
824 (+) Configure channels on regular group
825 (+) Configure the analog watchdog
832 * @brief Configures the the selected channel to be linked to the regular
834 * @note In case of usage of internal measurement channels:
835 * Vbat/VrefInt/TempSensor.
836 * The recommended sampling time is at least:
837 * - For devices STM32F37x: 17.1us for temperature sensor
838 * - For the other STM32F3 devices: 2.2us for each of channels
839 * Vbat/VrefInt/TempSensor.
840 * These internal paths can be be disabled using function
842 * @note Possibility to update parameters on the fly:
843 * This function initializes channel into regular group, following
844 * calls to this function can be used to reconfigure some parameters
845 * of structure "ADC_ChannelConfTypeDef" on the fly, without reseting
847 * The setting of these parameters is conditioned to ADC state.
848 * For parameters constraints, see comments of structure
849 * "ADC_ChannelConfTypeDef".
850 * @param hadc ADC handle
851 * @param sConfig Structure of ADC channel for regular group.
854 __weak HAL_StatusTypeDef
HAL_ADC_ConfigChannel(ADC_HandleTypeDef
* hadc
, ADC_ChannelConfTypeDef
* sConfig
)
856 /* Prevent unused argument(s) compilation warning */
860 /* Note : This function is defined into this file for library reference. */
861 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
863 /* Return function status */
868 * @brief Configures the analog watchdog.
869 * @note Possibility to update parameters on the fly:
870 * This function initializes the selected analog watchdog, following
871 * calls to this function can be used to reconfigure some parameters
872 * of structure "ADC_AnalogWDGConfTypeDef" on the fly, without reseting
874 * The setting of these parameters is conditioned to ADC state.
875 * For parameters constraints, see comments of structure
876 * "ADC_AnalogWDGConfTypeDef".
877 * @param hadc ADC handle
878 * @param AnalogWDGConfig Structure of ADC analog watchdog configuration
881 __weak HAL_StatusTypeDef
HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef
* hadc
, ADC_AnalogWDGConfTypeDef
* AnalogWDGConfig
)
883 /* Prevent unused argument(s) compilation warning */
885 UNUSED(AnalogWDGConfig
);
887 /* Note : This function is defined into this file for library reference. */
888 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
890 /* Return function status */
898 /** @defgroup ADC_Exported_Functions_Group4 Peripheral State functions
899 * @brief ADC Peripheral State functions
902 ===============================================================================
903 ##### Peripheral state and errors functions #####
904 ===============================================================================
906 This subsection provides functions to get in run-time the status of the
908 (+) Check the ADC state
909 (+) Check the ADC error code
916 * @brief return the ADC state
917 * @note ADC state machine is managed by bitfield, state must be compared
920 * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) "
921 * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1) ) "
922 * @param hadc ADC handle
925 uint32_t HAL_ADC_GetState(ADC_HandleTypeDef
* hadc
)
927 /* Check the parameters */
928 assert_param(IS_ADC_ALL_INSTANCE(hadc
->Instance
));
930 /* Return ADC state */
935 * @brief Return the ADC error code
936 * @param hadc ADC handle
937 * @retval ADC Error Code
939 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef
*hadc
)
941 return hadc
->ErrorCode
;
952 #endif /* HAL_ADC_MODULE_ENABLED */
961 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/