1 /**
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)
7 * peripheral:
8 * + Initialization and de-initialization functions
9 * + Peripheral Control functions
10 * + Peripheral State functions
11 * Other functions (extended functions) are available in file
12 * "stm32f3xx_hal_adc_ex.c".
13 *
14 ******************************************************************************
15 * @attention
16 *
17 * Copyright (c) 2016 STMicroelectronics.
18 * All rights reserved.
19 *
20 * This software is licensed under terms that can be found in the LICENSE file
21 * in the root directory of this software component.
22 * If no LICENSE file comes with this software, it is provided AS-IS.
23 *
24 ******************************************************************************
25 @verbatim
26 ==============================================================================
27 ##### ADC peripheral features #####
28 ==============================================================================
29 [..]
30 (+) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution (available only on
31 STM32F30xxC devices).
32
33 (+) Interrupt generation at the end of regular conversion, end of injected
34 conversion, and in case of analog watchdog or overrun events.
35
36 (+) Single and continuous conversion modes.
37
38 (+) Scan mode for conversion of several channels sequentially.
39
40 (+) Data alignment with in-built data coherency.
41
42 (+) Programmable sampling time (channel wise)
43
44 (+) ADC conversion of regular group and injected group.
45
46 (+) External trigger (timer or EXTI) with configurable polarity
47 for both regular and injected groups.
48
49 (+) DMA request generation for transfer of conversions data of regular group.
50
51 (+) Multimode dual mode (available on devices with 2 ADCs or more).
52
53 (+) Configurable DMA data storage in Multimode Dual mode (available on devices
54 with 2 DCs or more).
55
56 (+) Configurable delay between conversions in Dual interleaved mode (available
57 on devices with 2 DCs or more).
58
59 (+) ADC calibration
60
61 (+) ADC channels selectable single/differential input (available only on
62 STM32F30xxC devices)
63
64 (+) ADC Injected sequencer&channels configuration context queue (available
65 only on STM32F30xxC devices)
66
67 (+) ADC offset on injected and regular groups (offset on regular group
68 available only on STM32F30xxC devices)
69
70 (+) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at
71 slower speed.
72
73 (+) ADC input range: from Vref- (connected to Vssa) to Vref+ (connected to
74 Vdda or to an external voltage reference).
75
76
77 ##### How to use this driver #####
78 ==============================================================================
79 [..]
80
81 *** Configuration of top level parameters related to ADC ***
82 ============================================================
83 [..]
84
85 (#) Enable the ADC interface
86 (++) As prerequisite, ADC clock must be configured at RCC top level.
87
88 (++) For STM32F30x/STM32F33x devices:
89 Two possible clock sources: synchronous clock derived from AHB clock
90 or asynchronous clock derived from ADC dedicated PLL 72MHz.
91 - Synchronous clock is mandatory since used as ADC core clock.
92 Synchronous clock can be used optionally as ADC conversion clock, depending on ADC init structure clock setting.
93 Synchronous clock is configured using macro __ADCx_CLK_ENABLE().
94 - Asynchronous can be used optionally as ADC conversion clock, depending on ADC init structure clock setting.
95 Asynchronous clock is configured using function HAL_RCCEx_PeriphCLKConfig().
96 (+++) For example, in case of device with a single ADC:
97 Into HAL_ADC_MspInit() (recommended code location) or with
98 other device clock parameters configuration:
99 (+++) __HAL_RCC_ADC1_CLK_ENABLE() (mandatory)
100 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if ADC conversion from asynchronous clock)
101 (+++) PeriphClkInit.Adc1ClockSelection = RCC_ADC1PLLCLK_DIV1 (optional, if ADC conversion from asynchronous clock)
102 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if ADC conversion from asynchronous clock)
103
104 (+++) For example, in case of device with 4 ADCs:
105
106 (+++) if((hadc->Instance == ADC1) || (hadc->Instance == ADC2))
107 (+++) {
108 (+++) __HAL_RCC_ADC12_CLK_ENABLE() (mandatory)
109 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if ADC conversion from asynchronous clock)
110 (+++) PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_DIV1 (optional, if ADC conversion from asynchronous clock)
111 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if ADC conversion from asynchronous clock)
112 (+++) }
113 (+++) else
114 (+++) {
115 (+++) __HAL_RCC_ADC34_CLK_ENABLE() (mandatory)
116 (+++) PeriphClkInit.Adc34ClockSelection = RCC_ADC34PLLCLK_DIV1; (optional, if ADC conversion from asynchronous clock)
117 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure); (optional, if ADC conversion from asynchronous clock)
118 (+++) }
119
120 (++) For STM32F37x devices:
121 One clock setting is mandatory:
122 ADC clock (core and conversion clock) from APB2 clock.
123 (+++) Example:
124 Into HAL_ADC_MspInit() (recommended code location) or with
125 other device clock parameters configuration:
126 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC
127 (+++) PeriphClkInit.AdcClockSelection = RCC_ADCPLLCLK_DIV2
128 (+++) HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)
129
130 (#) ADC pins configuration
131 (++) Enable the clock for the ADC GPIOs
132 using macro __HAL_RCC_GPIOx_CLK_ENABLE()
133 (++) Configure these ADC pins in analog mode
134 using function HAL_GPIO_Init()
135
136 (#) Optionally, in case of usage of ADC with interruptions:
137 (++) Configure the NVIC for ADC
138 using function HAL_NVIC_EnableIRQ(ADCx_IRQn)
139 (++) Insert the ADC interruption handler function HAL_ADC_IRQHandler()
140 into the function of corresponding ADC interruption vector
141 ADCx_IRQHandler().
142
143 (#) Optionally, in case of usage of DMA:
144 (++) Configure the DMA (DMA channel, mode normal or circular, ...)
145 using function HAL_DMA_Init().
146 (++) Configure the NVIC for DMA
147 using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn)
148 (++) Insert the ADC interruption handler function HAL_ADC_IRQHandler()
149 into the function of corresponding DMA interruption vector
150 DMAx_Channelx_IRQHandler().
151
152 *** Configuration of ADC, groups regular/injected, channels parameters ***
153 ==========================================================================
154 [..]
155
156 (#) Configure the ADC parameters (resolution, data alignment, ...)
157 and regular group parameters (conversion trigger, sequencer, ...)
158 using function HAL_ADC_Init().
159
160 (#) Configure the channels for regular group parameters (channel number,
161 channel rank into sequencer, ..., into regular group)
162 using function HAL_ADC_ConfigChannel().
163
164 (#) Optionally, configure the injected group parameters (conversion trigger,
165 sequencer, ..., of injected group)
166 and the channels for injected group parameters (channel number,
167 channel rank into sequencer, ..., into injected group)
168 using function HAL_ADCEx_InjectedConfigChannel().
169
170 (#) Optionally, configure the analog watchdog parameters (channels
171 monitored, thresholds, ...)
172 using function HAL_ADC_AnalogWDGConfig().
173
174 (#) Optionally, for devices with several ADC instances: configure the
175 multimode parameters
176 using function HAL_ADCEx_MultiModeConfigChannel().
177
178 *** Execution of ADC conversions ***
179 ====================================
180 [..]
181
182 (#) Optionally, perform an automatic ADC calibration to improve the
183 conversion accuracy
184 using function HAL_ADCEx_Calibration_Start().
185
186 (#) ADC driver can be used among three modes: polling, interruption,
187 transfer by DMA.
188
189 (++) ADC conversion by polling:
190 (+++) Activate the ADC peripheral and start conversions
191 using function HAL_ADC_Start()
192 (+++) Wait for ADC conversion completion
193 using function HAL_ADC_PollForConversion()
194 (or for injected group: HAL_ADCEx_InjectedPollForConversion() )
195 (+++) Retrieve conversion results
196 using function HAL_ADC_GetValue()
197 (or for injected group: HAL_ADCEx_InjectedGetValue() )
198 (+++) Stop conversion and disable the ADC peripheral
199 using function HAL_ADC_Stop()
200
201 (++) ADC conversion by interruption:
202 (+++) Activate the ADC peripheral and start conversions
203 using function HAL_ADC_Start_IT()
204 (+++) Wait for ADC conversion completion by call of function
205 HAL_ADC_ConvCpltCallback()
206 (this function must be implemented in user program)
207 (or for injected group: HAL_ADCEx_InjectedConvCpltCallback() )
208 (+++) Retrieve conversion results
209 using function HAL_ADC_GetValue()
210 (or for injected group: HAL_ADCEx_InjectedGetValue() )
211 (+++) Stop conversion and disable the ADC peripheral
212 using function HAL_ADC_Stop_IT()
213
214 (++) ADC conversion with transfer by DMA:
215 (+++) Activate the ADC peripheral and start conversions
216 using function HAL_ADC_Start_DMA()
217 (+++) Wait for ADC conversion completion by call of function
218 HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
219 (these functions must be implemented in user program)
220 (+++) Conversion results are automatically transferred by DMA into
221 destination variable address.
222 (+++) Stop conversion and disable the ADC peripheral
223 using function HAL_ADC_Stop_DMA()
224
225 (++) For devices with several ADCs: ADC multimode conversion
226 with transfer by DMA:
227 (+++) Activate the ADC peripheral (slave)
228 using function HAL_ADC_Start()
229 (conversion start pending ADC master)
230 (+++) Activate the ADC peripheral (master) and start conversions
231 using function HAL_ADCEx_MultiModeStart_DMA()
232 (+++) Wait for ADC conversion completion by call of function
233 HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
234 (these functions must be implemented in user program)
235 (+++) Conversion results are automatically transferred by DMA into
236 destination variable address.
237 (+++) Stop conversion and disable the ADC peripheral (master)
238 using function HAL_ADCEx_MultiModeStop_DMA()
239 (+++) Stop conversion and disable the ADC peripheral (slave)
240 using function HAL_ADC_Stop_IT()
241
242 [..]
243
244 (@) Callback functions must be implemented in user program:
245 (+@) HAL_ADC_ErrorCallback()
246 (+@) HAL_ADC_LevelOutOfWindowCallback() (callback of analog watchdog)
247 (+@) HAL_ADC_ConvCpltCallback()
248 (+@) HAL_ADC_ConvHalfCpltCallback
249 (+@) HAL_ADCEx_InjectedConvCpltCallback()
250 (+@) HAL_ADCEx_InjectedQueueOverflowCallback() (for STM32F30x/STM32F33x devices)
251
252 *** Deinitialization of ADC ***
253 ============================================================
254 [..]
255
256 (#) Disable the ADC interface
257 (++) ADC clock can be hard reset and disabled at RCC top level.
258 (++) Hard reset of ADC peripherals
259 using macro __ADCx_FORCE_RESET(), __ADCx_RELEASE_RESET().
260 (++) ADC clock disable
261 using the equivalent macro/functions as configuration step.
262
263 (++) For STM32F30x/STM32F33x devices:
264 Caution: For devices with several ADCs:
265 These settings impact both ADC of common group: ADC1&ADC2, ADC3&ADC4
266 if available (ADC2, ADC3, ADC4 availability depends on STM32 product)
267
268 (+++) For example, in case of device with a single ADC:
269 Into HAL_ADC_MspDeInit() (recommended code location) or with
270 other device clock parameters configuration:
271 (+++) __HAL_RCC_ADC1_FORCE_RESET() (optional)
272 (+++) __HAL_RCC_ADC1_RELEASE_RESET() (optional)
273 (+++) __HAL_RCC_ADC1_CLK_DISABLE() (mandatory)
274 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if configured before)
275 (+++) PeriphClkInit.Adc1ClockSelection = RCC_ADC1PLLCLK_OFF (optional, if configured before)
276 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
277
278 (+++) For example, in case of device with 4 ADCs:
279 (+++) if((hadc->Instance == ADC1) || (hadc->Instance == ADC2))
280 (+++) {
281 (+++) __HAL_RCC_ADC12_FORCE_RESET() (optional)
282 (+++) __HAL_RCC_ADC12_RELEASE_RESET() (optional)
283 (+++) __HAL_RCC_ADC12_CLK_DISABLE() (mandatory)
284 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if configured before)
285 (+++) PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_OFF (optional, if configured before)
286 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
287 (+++) }
288 (+++) else
289 (+++) {
290 (+++) __HAL_RCC_ADC32_FORCE_RESET() (optional)
291 (+++) __HAL_RCC_ADC32_RELEASE_RESET() (optional)
292 (+++) __HAL_RCC_ADC34_CLK_DISABLE() (mandatory)
293 (+++) PeriphClkInit.Adc34ClockSelection = RCC_ADC34PLLCLK_OFF (optional, if configured before)
294 (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
295 (+++) }
296
297 (++) For STM32F37x devices:
298 (+++) Example:
299 Into HAL_ADC_MspDeInit() (recommended code location) or with
300 other device clock parameters configuration:
301 (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC
302 (+++) PeriphClkInit.AdcClockSelection = RCC_ADCPLLCLK_OFF
303 (+++) HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)
304
305 (#) ADC pins configuration
306 (++) Disable the clock for the ADC GPIOs
307 using macro __HAL_RCC_GPIOx_CLK_DISABLE()
308
309 (#) Optionally, in case of usage of ADC with interruptions:
310 (++) Disable the NVIC for ADC
311 using function HAL_NVIC_DisableIRQ(ADCx_IRQn)
312
313 (#) Optionally, in case of usage of DMA:
314 (++) Deinitialize the DMA
315 using function HAL_DMA_DeInit().
316 (++) Disable the NVIC for DMA
317 using function HAL_NVIC_DisableIRQ(DMAx_Channelx_IRQn)
318
319 [..]
320
321 *** Callback registration ***
322 =============================================
323 [..]
324
325 The compilation flag USE_HAL_ADC_REGISTER_CALLBACKS, when set to 1,
326 allows the user to configure dynamically the driver callbacks.
327 Use Functions HAL_ADC_RegisterCallback()
328 to register an interrupt callback.
329 [..]
330
331 Function HAL_ADC_RegisterCallback() allows to register following callbacks:
332 (+) ConvCpltCallback : ADC conversion complete callback
333 (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback
334 (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback
335 (+) ErrorCallback : ADC error callback
336 (+) InjectedConvCpltCallback : ADC group injected conversion complete callback
337 (+) MspInitCallback : ADC Msp Init callback
338 (+) MspDeInitCallback : ADC Msp DeInit callback
339 This function takes as parameters the HAL peripheral handle, the Callback ID
340 and a pointer to the user callback function.
341 [..]
342
343 Use function HAL_ADC_UnRegisterCallback to reset a callback to the default
344 weak function.
345 [..]
346
347 HAL_ADC_UnRegisterCallback takes as parameters the HAL peripheral handle,
348 and the Callback ID.
349 This function allows to reset following callbacks:
350 (+) ConvCpltCallback : ADC conversion complete callback
351 (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback
352 (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback
353 (+) ErrorCallback : ADC error callback
354 (+) InjectedConvCpltCallback : ADC group injected conversion complete callback
355 (+) MspInitCallback : ADC Msp Init callback
356 (+) MspDeInitCallback : ADC Msp DeInit callback
357 [..]
358
359 By default, after the HAL_ADC_Init() and when the state is HAL_ADC_STATE_RESET
360 all callbacks are set to the corresponding weak functions:
361 examples HAL_ADC_ConvCpltCallback(), HAL_ADC_ErrorCallback().
362 Exception done for MspInit and MspDeInit functions that are
363 reset to the legacy weak functions in the HAL_ADC_Init()/ HAL_ADC_DeInit() only when
364 these callbacks are null (not registered beforehand).
365 [..]
366
367 If MspInit or MspDeInit are not null, the HAL_ADC_Init()/ HAL_ADC_DeInit()
368 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
369 [..]
370
371 Callbacks can be registered/unregistered in HAL_ADC_STATE_READY state only.
372 Exception done MspInit/MspDeInit functions that can be registered/unregistered
373 in HAL_ADC_STATE_READY or HAL_ADC_STATE_RESET state,
374 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
375 [..]
376
377 Then, the user first registers the MspInit/MspDeInit user callbacks
378 using HAL_ADC_RegisterCallback() before calling HAL_ADC_DeInit()
379 or HAL_ADC_Init() function.
380 [..]
381
382 When the compilation flag USE_HAL_ADC_REGISTER_CALLBACKS is set to 0 or
383 not defined, the callback registration feature is not available and all callbacks
384 are set to the corresponding weak functions.
385
386 @endverbatim
387 */
388
389 /* Includes ------------------------------------------------------------------*/
390 #include "stm32f3xx_hal.h"
391
392 /** @addtogroup STM32F3xx_HAL_Driver
393 * @{
394 */
395
396 /** @defgroup ADC ADC
397 * @brief ADC HAL module driver
398 * @{
399 */
400
401 #ifdef HAL_ADC_MODULE_ENABLED
402
403 /* Private typedef -----------------------------------------------------------*/
404 /* Private define ------------------------------------------------------------*/
405 /* Private macro -------------------------------------------------------------*/
406 /* Private variables ---------------------------------------------------------*/
407 /* Private function prototypes -----------------------------------------------*/
408 /* Exported functions --------------------------------------------------------*/
409
410 /** @defgroup ADC_Exported_Functions ADC Exported Functions
411 * @{
412 */
413
414 /** @defgroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions
415 * @brief Initialization and Configuration functions
416 *
417 @verbatim
418 ===============================================================================
419 ##### Initialization and de-initialization functions #####
420 ===============================================================================
421 [..] This section provides functions allowing to:
422 (+) Initialize and configure the ADC.
423 (+) De-initialize the ADC.
424
425 @endverbatim
426 * @{
427 */
428
429 /**
430 * @brief Initializes the ADC peripheral and regular group according to
431 * parameters specified in structure "ADC_InitTypeDef".
432 * @note As prerequisite, ADC clock must be configured at RCC top level
433 * depending on both possible clock sources: PLL clock or AHB clock.
434 * See commented example code below that can be copied and uncommented
435 * into HAL_ADC_MspInit().
436 * @note Possibility to update parameters on the fly:
437 * This function initializes the ADC MSP (HAL_ADC_MspInit()) only when
438 * coming from ADC state reset. Following calls to this function can
439 * be used to reconfigure some parameters of ADC_InitTypeDef
440 * structure on the fly, without modifying MSP configuration. If ADC
441 * MSP has to be modified again, HAL_ADC_DeInit() must be called
442 * before HAL_ADC_Init().
443 * The setting of these parameters is conditioned to ADC state.
444 * For parameters constraints, see comments of structure
445 * "ADC_InitTypeDef".
446 * @note This function configures the ADC within 2 scopes: scope of entire
447 * ADC and scope of regular group. For parameters details, see comments
448 * of structure "ADC_InitTypeDef".
449 * @note For devices with several ADCs: parameters related to common ADC
450 * registers (ADC clock mode) are set only if all ADCs sharing the
451 * same common group are disabled.
452 * If this is not the case, these common parameters setting are
453 * bypassed without error reporting: it can be the intended behaviour in
454 * case of update of a parameter of ADC_InitTypeDef on the fly,
455 * without disabling the other ADCs sharing the same common group.
456 * @param hadc ADC handle
457 * @retval HAL status
458 */
HAL_ADC_Init(ADC_HandleTypeDef * hadc)459 __weak HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
460 {
461 /* Prevent unused argument(s) compilation warning */
462 UNUSED(hadc);
463
464 /* Note : This function is defined into this file for library reference. */
465 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
466
467 /* Return function status */
468 return HAL_ERROR;
469 }
470
471 /**
472 * @brief Deinitialize the ADC peripheral registers to their default reset
473 * values, with deinitialization of the ADC MSP.
474 * @note For devices with several ADCs: reset of ADC common registers is done
475 * only if all ADCs sharing the same common group are disabled.
476 * If this is not the case, reset of these common parameters reset is
477 * bypassed without error reporting: it can be the intended behaviour in
478 * case of reset of a single ADC while the other ADCs sharing the same
479 * common group is still running.
480 * @note For devices with several ADCs: Global reset of all ADCs sharing a
481 * common group is possible.
482 * As this function is intended to reset a single ADC, to not impact
483 * other ADCs, instructions for global reset of multiple ADCs have been
484 * let commented below.
485 * If needed, the example code can be copied and uncommented into
486 * function HAL_ADC_MspDeInit().
487 * @param hadc ADC handle
488 * @retval HAL status
489 */
HAL_ADC_DeInit(ADC_HandleTypeDef * hadc)490 __weak HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
491 {
492 /* Prevent unused argument(s) compilation warning */
493 UNUSED(hadc);
494
495 /* Note : This function is defined into this file for library reference. */
496 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
497
498 /* Return function status */
499 return HAL_ERROR;
500 }
501
502 /**
503 * @brief Initializes the ADC MSP.
504 * @param hadc ADC handle
505 * @retval None
506 */
HAL_ADC_MspInit(ADC_HandleTypeDef * hadc)507 __weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
508 {
509 /* Prevent unused argument(s) compilation warning */
510 UNUSED(hadc);
511
512 /* NOTE : This function should not be modified. When the callback is needed,
513 function HAL_ADC_MspInit must be implemented in the user file.
514 */
515 }
516
517 /**
518 * @brief DeInitializes the ADC MSP.
519 * @param hadc ADC handle
520 * @retval None
521 */
HAL_ADC_MspDeInit(ADC_HandleTypeDef * hadc)522 __weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
523 {
524 /* Prevent unused argument(s) compilation warning */
525 UNUSED(hadc);
526
527 /* NOTE : This function should not be modified. When the callback is needed,
528 function HAL_ADC_MspDeInit must be implemented in the user file.
529 */
530 }
531
532 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
533 /**
534 * @brief Register a User ADC Callback
535 * To be used instead of the weak predefined callback
536 * @param hadc Pointer to a ADC_HandleTypeDef structure that contains
537 * the configuration information for the specified ADC.
538 * @param CallbackID ID of the callback to be registered
539 * This parameter can be one of the following values:
540 * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID
541 * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion complete callback ID
542 * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID
543 * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID
544 * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID
545 * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID
546 * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID
547 * @arg @ref HAL_ADC_MSPINIT_CB_ID MspInit callback ID
548 * @arg @ref HAL_ADC_MSPDEINIT_CB_ID MspDeInit callback ID
549 * @param pCallback pointer to the Callback function
550 * @retval HAL status
551 */
HAL_ADC_RegisterCallback(ADC_HandleTypeDef * hadc,HAL_ADC_CallbackIDTypeDef CallbackID,pADC_CallbackTypeDef pCallback)552 HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback)
553 {
554 HAL_StatusTypeDef status = HAL_OK;
555
556 if (pCallback == NULL)
557 {
558 /* Update the error code */
559 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
560
561 return HAL_ERROR;
562 }
563
564 if ((hadc->State & HAL_ADC_STATE_READY) != 0)
565 {
566 switch (CallbackID)
567 {
568 case HAL_ADC_CONVERSION_COMPLETE_CB_ID :
569 hadc->ConvCpltCallback = pCallback;
570 break;
571
572 case HAL_ADC_CONVERSION_HALF_CB_ID :
573 hadc->ConvHalfCpltCallback = pCallback;
574 break;
575
576 case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID :
577 hadc->LevelOutOfWindowCallback = pCallback;
578 break;
579
580 case HAL_ADC_ERROR_CB_ID :
581 hadc->ErrorCallback = pCallback;
582 break;
583
584 case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID :
585 hadc->InjectedConvCpltCallback = pCallback;
586 break;
587
588 case HAL_ADC_MSPINIT_CB_ID :
589 hadc->MspInitCallback = pCallback;
590 break;
591
592 case HAL_ADC_MSPDEINIT_CB_ID :
593 hadc->MspDeInitCallback = pCallback;
594 break;
595
596 default :
597 /* Update the error code */
598 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
599
600 /* Return error status */
601 status = HAL_ERROR;
602 break;
603 }
604 }
605 else if (HAL_ADC_STATE_RESET == hadc->State)
606 {
607 switch (CallbackID)
608 {
609 case HAL_ADC_MSPINIT_CB_ID :
610 hadc->MspInitCallback = pCallback;
611 break;
612
613 case HAL_ADC_MSPDEINIT_CB_ID :
614 hadc->MspDeInitCallback = pCallback;
615 break;
616
617 default :
618 /* Update the error code */
619 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
620
621 /* Return error status */
622 status = HAL_ERROR;
623 break;
624 }
625 }
626 else
627 {
628 /* Update the error code */
629 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
630
631 /* Return error status */
632 status = HAL_ERROR;
633 }
634
635 return status;
636 }
637
638 /**
639 * @brief Unregister a ADC Callback
640 * ADC callback is redirected to the weak predefined callback
641 * @param hadc Pointer to a ADC_HandleTypeDef structure that contains
642 * the configuration information for the specified ADC.
643 * @param CallbackID ID of the callback to be unregistered
644 * This parameter can be one of the following values:
645 * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID
646 * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion complete callback ID
647 * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID
648 * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID
649 * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID
650 * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID
651 * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID
652 * @arg @ref HAL_ADC_MSPINIT_CB_ID MspInit callback ID
653 * @arg @ref HAL_ADC_MSPDEINIT_CB_ID MspDeInit callback ID
654 * @retval HAL status
655 */
HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef * hadc,HAL_ADC_CallbackIDTypeDef CallbackID)656 HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID)
657 {
658 HAL_StatusTypeDef status = HAL_OK;
659
660 if ((hadc->State & HAL_ADC_STATE_READY) != 0)
661 {
662 switch (CallbackID)
663 {
664 case HAL_ADC_CONVERSION_COMPLETE_CB_ID :
665 hadc->ConvCpltCallback = HAL_ADC_ConvCpltCallback;
666 break;
667
668 case HAL_ADC_CONVERSION_HALF_CB_ID :
669 hadc->ConvHalfCpltCallback = HAL_ADC_ConvHalfCpltCallback;
670 break;
671
672 case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID :
673 hadc->LevelOutOfWindowCallback = HAL_ADC_LevelOutOfWindowCallback;
674 break;
675
676 case HAL_ADC_ERROR_CB_ID :
677 hadc->ErrorCallback = HAL_ADC_ErrorCallback;
678 break;
679
680 case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID :
681 hadc->InjectedConvCpltCallback = HAL_ADCEx_InjectedConvCpltCallback;
682 break;
683
684 case HAL_ADC_MSPINIT_CB_ID :
685 hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */
686 break;
687
688 case HAL_ADC_MSPDEINIT_CB_ID :
689 hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */
690 break;
691
692 default :
693 /* Update the error code */
694 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
695
696 /* Return error status */
697 status = HAL_ERROR;
698 break;
699 }
700 }
701 else if (HAL_ADC_STATE_RESET == hadc->State)
702 {
703 switch (CallbackID)
704 {
705 case HAL_ADC_MSPINIT_CB_ID :
706 hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */
707 break;
708
709 case HAL_ADC_MSPDEINIT_CB_ID :
710 hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */
711 break;
712
713 default :
714 /* Update the error code */
715 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
716
717 /* Return error status */
718 status = HAL_ERROR;
719 break;
720 }
721 }
722 else
723 {
724 /* Update the error code */
725 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
726
727 /* Return error status */
728 status = HAL_ERROR;
729 }
730
731 return status;
732 }
733
734 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
735
736 /**
737 * @}
738 */
739
740 /** @defgroup ADC_Exported_Functions_Group2 Input and Output operation functions
741 * @brief IO operation functions
742 *
743 @verbatim
744 ===============================================================================
745 ##### IO operation functions #####
746 ===============================================================================
747 [..] This section provides functions allowing to:
748 (+) Start conversion of regular group.
749 (+) Stop conversion of regular group.
750 (+) Poll for conversion complete on regular group.
751 (+) Poll for conversion event.
752 (+) Get result of regular channel conversion.
753 (+) Start conversion of regular group and enable interruptions.
754 (+) Stop conversion of regular group and disable interruptions.
755 (+) Handle ADC interrupt request
756 (+) Start conversion of regular group and enable DMA transfer.
757 (+) Stop conversion of regular group and disable ADC DMA transfer.
758
759 @endverbatim
760 * @{
761 */
762 /**
763 * @brief Enables ADC, starts conversion of regular group.
764 * Interruptions enabled in this function: None.
765 * @note: Case of multimode enabled (for devices with several ADCs): This
766 * function must be called for ADC slave first, then ADC master.
767 * For ADC slave, ADC is enabled only (conversion is not started).
768 * For ADC master, ADC is enabled and multimode conversion is started.
769 * @param hadc ADC handle
770 * @retval HAL status
771 */
HAL_ADC_Start(ADC_HandleTypeDef * hadc)772 __weak HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
773 {
774 /* Prevent unused argument(s) compilation warning */
775 UNUSED(hadc);
776
777 /* Return function status */
778 return HAL_ERROR;
779 }
780
781 /**
782 * @brief Stop ADC conversion of regular group (and injected group in
783 * case of auto_injection mode), disable ADC peripheral.
784 * @note: ADC peripheral disable is forcing stop of potential
785 * conversion on injected group. If injected group is under use, it
786 * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
787 * @note: Case of multimode enabled (for devices with several ADCs): This
788 * function must be called for ADC master first, then ADC slave.
789 * For ADC master, conversion is stopped and ADC is disabled.
790 * For ADC slave, ADC is disabled only (conversion stop of ADC master
791 * has already stopped conversion of ADC slave).
792 * @param hadc ADC handle
793 * @retval HAL status.
794 */
HAL_ADC_Stop(ADC_HandleTypeDef * hadc)795 __weak HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc)
796 {
797 /* Prevent unused argument(s) compilation warning */
798 UNUSED(hadc);
799
800 /* Note : This function is defined into this file for library reference. */
801 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
802
803 /* Return function status */
804 return HAL_ERROR;
805 }
806
807 /**
808 * @brief Wait for regular group conversion to be completed.
809 * @param hadc ADC handle
810 * @param Timeout Timeout value in millisecond.
811 * @retval HAL status
812 */
HAL_ADC_PollForConversion(ADC_HandleTypeDef * hadc,uint32_t Timeout)813 __weak HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
814 {
815 /* Prevent unused argument(s) compilation warning */
816 UNUSED(hadc);
817 UNUSED(Timeout);
818
819 /* Note : This function is defined into this file for library reference. */
820 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
821
822 /* Return function status */
823 return HAL_ERROR;
824 }
825
826 /**
827 * @brief Poll for conversion event.
828 * @param hadc ADC handle
829 * @param EventType the ADC event type.
830 * This parameter can be one of the following values:
831 * @arg ADC_AWD_EVENT: ADC Analog watchdog 1 event (main analog watchdog, present on all STM32 devices)
832 * @arg ADC_AWD2_EVENT: ADC Analog watchdog 2 event (additional analog watchdog, present only on STM32F3 devices)
833 * @arg ADC_AWD3_EVENT: ADC Analog watchdog 3 event (additional analog watchdog, present only on STM32F3 devices)
834 * @arg ADC_OVR_EVENT: ADC Overrun event
835 * @arg ADC_JQOVF_EVENT: ADC Injected context queue overflow event
836 * @param Timeout Timeout value in millisecond.
837 * @retval HAL status
838 */
HAL_ADC_PollForEvent(ADC_HandleTypeDef * hadc,uint32_t EventType,uint32_t Timeout)839 __weak HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout)
840 {
841 /* Prevent unused argument(s) compilation warning */
842 UNUSED(hadc);
843 UNUSED(EventType);
844 UNUSED(Timeout);
845
846 /* Note : This function is defined into this file for library reference. */
847 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
848
849 /* Return function status */
850 return HAL_ERROR;
851 }
852
853 /**
854 * @brief Enables ADC, starts conversion of regular group with interruption.
855 * Interruptions enabled in this function:
856 * - EOC (end of conversion of regular group) or EOS (end of
857 * sequence of regular group) depending on ADC initialization
858 * parameter "EOCSelection" (if available)
859 * - overrun (if available)
860 * Each of these interruptions has its dedicated callback function.
861 * @note: Case of multimode enabled (for devices with several ADCs): This
862 * function must be called for ADC slave first, then ADC master.
863 * For ADC slave, ADC is enabled only (conversion is not started).
864 * For ADC master, ADC is enabled and multimode conversion is started.
865 * @param hadc ADC handle
866 * @retval HAL status
867 */
HAL_ADC_Start_IT(ADC_HandleTypeDef * hadc)868 __weak HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
869 {
870 /* Prevent unused argument(s) compilation warning */
871 UNUSED(hadc);
872
873 /* Note : This function is defined into this file for library reference. */
874 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
875
876 /* Return function status */
877 return HAL_ERROR;
878 }
879
880 /**
881 * @brief Stop ADC conversion of regular group (and injected group in
882 * case of auto_injection mode), disable interruption of
883 * end-of-conversion, disable ADC peripheral.
884 * @note: ADC peripheral disable is forcing stop of potential
885 * conversion on injected group. If injected group is under use, it
886 * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
887 * @note: Case of multimode enabled (for devices with several ADCs): This
888 * function must be called for ADC master first, then ADC slave.
889 * For ADC master, conversion is stopped and ADC is disabled.
890 * For ADC slave, ADC is disabled only (conversion stop of ADC master
891 * has already stopped conversion of ADC slave).
892 * @param hadc ADC handle
893 * @retval HAL status.
894 */
HAL_ADC_Stop_IT(ADC_HandleTypeDef * hadc)895 __weak HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc)
896 {
897 /* Prevent unused argument(s) compilation warning */
898 UNUSED(hadc);
899
900 /* Note : This function is defined into this file for library reference. */
901 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
902
903 /* Return function status */
904 return HAL_ERROR;
905 }
906
907 /**
908 * @brief Enables ADC, starts conversion of regular group and transfers result
909 * through DMA.
910 * Interruptions enabled in this function:
911 * - DMA transfer complete
912 * - DMA half transfer
913 * - overrun (if available)
914 * Each of these interruptions has its dedicated callback function.
915 * @note: Case of multimode enabled (for devices with several ADCs): This
916 * function is for single-ADC mode only. For multimode, use the
917 * dedicated MultimodeStart function.
918 * @param hadc ADC handle
919 * @param pData The destination Buffer address.
920 * @param Length The length of data to be transferred from ADC peripheral to memory.
921 * @retval None
922 */
HAL_ADC_Start_DMA(ADC_HandleTypeDef * hadc,uint32_t * pData,uint32_t Length)923 __weak HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
924 {
925 /* Prevent unused argument(s) compilation warning */
926 UNUSED(hadc);
927 UNUSED(pData);
928 UNUSED(Length);
929
930 /* Note : This function is defined into this file for library reference. */
931 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
932
933 /* Return function status */
934 return HAL_ERROR;
935 }
936
937 /**
938 * @brief Stop ADC conversion of regular group (and injected group in
939 * case of auto_injection mode), disable ADC DMA transfer, disable
940 * ADC peripheral.
941 * @note: ADC peripheral disable is forcing stop of potential
942 * conversion on injected group. If injected group is under use, it
943 * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
944 * @note: Case of multimode enabled (for devices with several ADCs): This
945 * function is for single-ADC mode only. For multimode, use the
946 * dedicated MultimodeStop function.
947 * @param hadc ADC handle
948 * @retval HAL status.
949 */
HAL_ADC_Stop_DMA(ADC_HandleTypeDef * hadc)950 __weak HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc)
951 {
952 /* Prevent unused argument(s) compilation warning */
953 UNUSED(hadc);
954
955 /* Note : This function is defined into this file for library reference. */
956 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
957
958 /* Return function status */
959 return HAL_ERROR;
960 }
961
962 /**
963 * @brief Get ADC regular group conversion result.
964 * @note Reading DR register automatically clears EOC (end of conversion of
965 * regular group) flag.
966 * Additionally, this functions clears EOS (end of sequence of
967 * regular group) flag, in case of the end of the sequence is reached.
968 * @param hadc ADC handle
969 * @retval Converted value
970 */
HAL_ADC_GetValue(ADC_HandleTypeDef * hadc)971 __weak uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc)
972 {
973 /* Note : This function is defined into this file for library reference. */
974 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
975
976 /* Return ADC converted value */
977 return hadc->Instance->DR;
978 }
979
980 /**
981 * @brief Handles ADC interrupt request.
982 * @param hadc ADC handle
983 * @retval None
984 */
HAL_ADC_IRQHandler(ADC_HandleTypeDef * hadc)985 __weak void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
986 {
987 /* Prevent unused argument(s) compilation warning */
988 UNUSED(hadc);
989
990 /* Note : This function is defined into this file for library reference. */
991 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
992 }
993
994 /**
995 * @brief Conversion complete callback in non blocking mode
996 * @param hadc ADC handle
997 * @retval None
998 */
HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc)999 __weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
1000 {
1001 /* Prevent unused argument(s) compilation warning */
1002 UNUSED(hadc);
1003
1004 /* NOTE : This function should not be modified. When the callback is needed,
1005 function HAL_ADC_ConvCpltCallback must be implemented in the user file.
1006 */
1007 }
1008
1009 /**
1010 * @brief Conversion DMA half-transfer callback in non blocking mode
1011 * @param hadc ADC handle
1012 * @retval None
1013 */
HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef * hadc)1014 __weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
1015 {
1016 /* Prevent unused argument(s) compilation warning */
1017 UNUSED(hadc);
1018
1019 /* NOTE : This function should not be modified. When the callback is needed,
1020 function HAL_ADC_ConvHalfCpltCallback must be implemented in the user file.
1021 */
1022 }
1023
1024 /**
1025 * @brief Analog watchdog callback in non blocking mode.
1026 * @param hadc ADC handle
1027 * @retval None
1028 */
HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef * hadc)1029 __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
1030 {
1031 /* Prevent unused argument(s) compilation warning */
1032 UNUSED(hadc);
1033
1034 /* NOTE : This function should not be modified. When the callback is needed,
1035 function HAL_ADC_LevelOoutOfWindowCallback must be implemented in the user file.
1036 */
1037 }
1038
1039 /**
1040 * @brief ADC error callback in non blocking mode
1041 * (ADC conversion with interruption or transfer by DMA)
1042 * @param hadc ADC handle
1043 * @retval None
1044 */
HAL_ADC_ErrorCallback(ADC_HandleTypeDef * hadc)1045 __weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)
1046 {
1047 /* Prevent unused argument(s) compilation warning */
1048 UNUSED(hadc);
1049
1050 /* NOTE : This function should not be modified. When the callback is needed,
1051 function HAL_ADC_ErrorCallback must be implemented in the user file.
1052 */
1053 }
1054
1055 /**
1056 * @}
1057 */
1058
1059 /** @defgroup ADC_Exported_Functions_Group3 Peripheral Control functions
1060 * @brief Peripheral Control functions
1061 *
1062 @verbatim
1063 ===============================================================================
1064 ##### Peripheral Control functions #####
1065 ===============================================================================
1066 [..] This section provides functions allowing to:
1067 (+) Configure channels on regular group
1068 (+) Configure the analog watchdog
1069
1070 @endverbatim
1071 * @{
1072 */
1073
1074 /**
1075 * @brief Configures the the selected channel to be linked to the regular
1076 * group.
1077 * @note In case of usage of internal measurement channels:
1078 * Vbat/VrefInt/TempSensor.
1079 * The recommended sampling time is at least:
1080 * - For devices STM32F37x: 17.1us for temperature sensor
1081 * - For the other STM32F3 devices: 2.2us for each of channels
1082 * Vbat/VrefInt/TempSensor.
1083 * These internal paths can be be disabled using function
1084 * HAL_ADC_DeInit().
1085 * @note Possibility to update parameters on the fly:
1086 * This function initializes channel into regular group, following
1087 * calls to this function can be used to reconfigure some parameters
1088 * of structure "ADC_ChannelConfTypeDef" on the fly, without resetting
1089 * the ADC.
1090 * The setting of these parameters is conditioned to ADC state.
1091 * For parameters constraints, see comments of structure
1092 * "ADC_ChannelConfTypeDef".
1093 * @param hadc ADC handle
1094 * @param sConfig Structure of ADC channel for regular group.
1095 * @retval HAL status
1096 */
HAL_ADC_ConfigChannel(ADC_HandleTypeDef * hadc,ADC_ChannelConfTypeDef * sConfig)1097 __weak HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig)
1098 {
1099 /* Prevent unused argument(s) compilation warning */
1100 UNUSED(hadc);
1101 UNUSED(sConfig);
1102
1103 /* Note : This function is defined into this file for library reference. */
1104 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
1105
1106 /* Return function status */
1107 return HAL_ERROR;
1108 }
1109
1110 /**
1111 * @brief Configures the analog watchdog.
1112 * @note Possibility to update parameters on the fly:
1113 * This function initializes the selected analog watchdog, following
1114 * calls to this function can be used to reconfigure some parameters
1115 * of structure "ADC_AnalogWDGConfTypeDef" on the fly, without resetting
1116 * the ADC.
1117 * The setting of these parameters is conditioned to ADC state.
1118 * For parameters constraints, see comments of structure
1119 * "ADC_AnalogWDGConfTypeDef".
1120 * @param hadc ADC handle
1121 * @param AnalogWDGConfig Structure of ADC analog watchdog configuration
1122 * @retval HAL status
1123 */
HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef * hadc,ADC_AnalogWDGConfTypeDef * AnalogWDGConfig)1124 __weak HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig)
1125 {
1126 /* Prevent unused argument(s) compilation warning */
1127 UNUSED(hadc);
1128 UNUSED(AnalogWDGConfig);
1129
1130 /* Note : This function is defined into this file for library reference. */
1131 /* Function content is located into file stm32f3xx_hal_adc_ex.c */
1132
1133 /* Return function status */
1134 return HAL_ERROR;
1135 }
1136
1137 /**
1138 * @}
1139 */
1140
1141 /** @defgroup ADC_Exported_Functions_Group4 Peripheral State functions
1142 * @brief ADC Peripheral State functions
1143 *
1144 @verbatim
1145 ===============================================================================
1146 ##### Peripheral state and errors functions #####
1147 ===============================================================================
1148 [..]
1149 This subsection provides functions to get in run-time the status of the
1150 peripheral.
1151 (+) Check the ADC state
1152 (+) Check the ADC error code
1153
1154 @endverbatim
1155 * @{
1156 */
1157
1158 /**
1159 * @brief return the ADC state
1160 * @note ADC state machine is managed by bitfield, state must be compared
1161 * with bit by bit.
1162 * For example:
1163 * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) "
1164 * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1) ) "
1165 * @param hadc ADC handle
1166 * @retval HAL state
1167 */
HAL_ADC_GetState(ADC_HandleTypeDef * hadc)1168 uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc)
1169 {
1170 /* Check the parameters */
1171 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1172
1173 /* Return ADC state */
1174 return hadc->State;
1175 }
1176
1177 /**
1178 * @brief Return the ADC error code
1179 * @param hadc ADC handle
1180 * @retval ADC Error Code
1181 */
HAL_ADC_GetError(ADC_HandleTypeDef * hadc)1182 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc)
1183 {
1184 return hadc->ErrorCode;
1185 }
1186
1187 /**
1188 * @}
1189 */
1190
1191 /**
1192 * @}
1193 */
1194
1195 #endif /* HAL_ADC_MODULE_ENABLED */
1196 /**
1197 * @}
1198 */
1199
1200 /**
1201 * @}
1202 */
1203
1204