STM32F479xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_adc.c 00004 * @author MCD Application Team 00005 * @brief This file provides firmware functions to manage the following 00006 * functionalities of the Analog to Digital Converter (ADC) peripheral: 00007 * + Initialization and de-initialization functions 00008 * + IO operation functions 00009 * + State and errors functions 00010 * 00011 @verbatim 00012 ============================================================================== 00013 ##### ADC Peripheral features ##### 00014 ============================================================================== 00015 [..] 00016 (#) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution. 00017 (#) Interrupt generation at the end of conversion, end of injected conversion, 00018 and in case of analog watchdog or overrun events 00019 (#) Single and continuous conversion modes. 00020 (#) Scan mode for automatic conversion of channel 0 to channel x. 00021 (#) Data alignment with in-built data coherency. 00022 (#) Channel-wise programmable sampling time. 00023 (#) External trigger option with configurable polarity for both regular and 00024 injected conversion. 00025 (#) Dual/Triple mode (on devices with 2 ADCs or more). 00026 (#) Configurable DMA data storage in Dual/Triple ADC mode. 00027 (#) Configurable delay between conversions in Dual/Triple interleaved mode. 00028 (#) ADC conversion type (refer to the datasheets). 00029 (#) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at 00030 slower speed. 00031 (#) ADC input range: VREF(minus) = VIN = VREF(plus). 00032 (#) DMA request generation during regular channel conversion. 00033 00034 00035 ##### How to use this driver ##### 00036 ============================================================================== 00037 [..] 00038 (#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit(): 00039 (##) Enable the ADC interface clock using __HAL_RCC_ADC_CLK_ENABLE() 00040 (##) ADC pins configuration 00041 (+++) Enable the clock for the ADC GPIOs using the following function: 00042 __HAL_RCC_GPIOx_CLK_ENABLE() 00043 (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init() 00044 (##) In case of using interrupts (e.g. HAL_ADC_Start_IT()) 00045 (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority() 00046 (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ() 00047 (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler() 00048 (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA()) 00049 (+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE() 00050 (+++) Configure and enable two DMA streams stream for managing data 00051 transfer from peripheral to memory (output stream) 00052 (+++) Associate the initialized DMA handle to the CRYP DMA handle 00053 using __HAL_LINKDMA() 00054 (+++) Configure the priority and enable the NVIC for the transfer complete 00055 interrupt on the two DMA Streams. The output stream should have higher 00056 priority than the input stream. 00057 00058 *** Configuration of ADC, groups regular/injected, channels parameters *** 00059 ============================================================================== 00060 [..] 00061 (#) Configure the ADC parameters (resolution, data alignment, ...) 00062 and regular group parameters (conversion trigger, sequencer, ...) 00063 using function HAL_ADC_Init(). 00064 00065 (#) Configure the channels for regular group parameters (channel number, 00066 channel rank into sequencer, ..., into regular group) 00067 using function HAL_ADC_ConfigChannel(). 00068 00069 (#) Optionally, configure the injected group parameters (conversion trigger, 00070 sequencer, ..., of injected group) 00071 and the channels for injected group parameters (channel number, 00072 channel rank into sequencer, ..., into injected group) 00073 using function HAL_ADCEx_InjectedConfigChannel(). 00074 00075 (#) Optionally, configure the analog watchdog parameters (channels 00076 monitored, thresholds, ...) using function HAL_ADC_AnalogWDGConfig(). 00077 00078 (#) Optionally, for devices with several ADC instances: configure the 00079 multimode parameters using function HAL_ADCEx_MultiModeConfigChannel(). 00080 00081 *** Execution of ADC conversions *** 00082 ============================================================================== 00083 [..] 00084 (#) ADC driver can be used among three modes: polling, interruption, 00085 transfer by DMA. 00086 00087 *** Polling mode IO operation *** 00088 ================================= 00089 [..] 00090 (+) Start the ADC peripheral using HAL_ADC_Start() 00091 (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage 00092 user can specify the value of timeout according to his end application 00093 (+) To read the ADC converted values, use the HAL_ADC_GetValue() function. 00094 (+) Stop the ADC peripheral using HAL_ADC_Stop() 00095 00096 *** Interrupt mode IO operation *** 00097 =================================== 00098 [..] 00099 (+) Start the ADC peripheral using HAL_ADC_Start_IT() 00100 (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine 00101 (+) At ADC end of conversion HAL_ADC_ConvCpltCallback() function is executed and user can 00102 add his own code by customization of function pointer HAL_ADC_ConvCpltCallback 00103 (+) In case of ADC Error, HAL_ADC_ErrorCallback() function is executed and user can 00104 add his own code by customization of function pointer HAL_ADC_ErrorCallback 00105 (+) Stop the ADC peripheral using HAL_ADC_Stop_IT() 00106 00107 *** DMA mode IO operation *** 00108 ============================== 00109 [..] 00110 (+) Start the ADC peripheral using HAL_ADC_Start_DMA(), at this stage the user specify the length 00111 of data to be transferred at each end of conversion 00112 (+) At The end of data transfer by HAL_ADC_ConvCpltCallback() function is executed and user can 00113 add his own code by customization of function pointer HAL_ADC_ConvCpltCallback 00114 (+) In case of transfer Error, HAL_ADC_ErrorCallback() function is executed and user can 00115 add his own code by customization of function pointer HAL_ADC_ErrorCallback 00116 (+) Stop the ADC peripheral using HAL_ADC_Stop_DMA() 00117 00118 *** ADC HAL driver macros list *** 00119 ============================================= 00120 [..] 00121 Below the list of most used macros in ADC HAL driver. 00122 00123 (+) __HAL_ADC_ENABLE : Enable the ADC peripheral 00124 (+) __HAL_ADC_DISABLE : Disable the ADC peripheral 00125 (+) __HAL_ADC_ENABLE_IT: Enable the ADC end of conversion interrupt 00126 (+) __HAL_ADC_DISABLE_IT: Disable the ADC end of conversion interrupt 00127 (+) __HAL_ADC_GET_IT_SOURCE: Check if the specified ADC interrupt source is enabled or disabled 00128 (+) __HAL_ADC_CLEAR_FLAG: Clear the ADC's pending flags 00129 (+) __HAL_ADC_GET_FLAG: Get the selected ADC's flag status 00130 (+) ADC_GET_RESOLUTION: Return resolution bits in CR1 register 00131 00132 [..] 00133 (@) You can refer to the ADC HAL driver header file for more useful macros 00134 00135 *** Deinitialization of ADC *** 00136 ============================================================================== 00137 [..] 00138 (#) Disable the ADC interface 00139 (++) ADC clock can be hard reset and disabled at RCC top level. 00140 (++) Hard reset of ADC peripherals 00141 using macro __HAL_RCC_ADC_FORCE_RESET(), __HAL_RCC_ADC_RELEASE_RESET(). 00142 (++) ADC clock disable using the equivalent macro/functions as configuration step. 00143 (+++) Example: 00144 Into HAL_ADC_MspDeInit() (recommended code location) or with 00145 other device clock parameters configuration: 00146 (+++) HAL_RCC_GetOscConfig(&RCC_OscInitStructure); 00147 (+++) RCC_OscInitStructure.OscillatorType = RCC_OSCILLATORTYPE_HSI; 00148 (+++) RCC_OscInitStructure.HSIState = RCC_HSI_OFF; (if not used for system clock) 00149 (+++) HAL_RCC_OscConfig(&RCC_OscInitStructure); 00150 00151 (#) ADC pins configuration 00152 (++) Disable the clock for the ADC GPIOs using macro __HAL_RCC_GPIOx_CLK_DISABLE() 00153 00154 (#) Optionally, in case of usage of ADC with interruptions: 00155 (++) Disable the NVIC for ADC using function HAL_NVIC_DisableIRQ(ADCx_IRQn) 00156 00157 (#) Optionally, in case of usage of DMA: 00158 (++) Deinitialize the DMA using function HAL_DMA_DeInit(). 00159 (++) Disable the NVIC for DMA using function HAL_NVIC_DisableIRQ(DMAx_Channelx_IRQn) 00160 *** Callback registration *** 00161 ============================================================================== 00162 [..] 00163 00164 The compilation flag USE_HAL_ADC_REGISTER_CALLBACKS, when set to 1, 00165 allows the user to configure dynamically the driver callbacks. 00166 Use Functions HAL_ADC_RegisterCallback() 00167 to register an interrupt callback. 00168 [..] 00169 00170 Function HAL_ADC_RegisterCallback() allows to register following callbacks: 00171 (+) ConvCpltCallback : ADC conversion complete callback 00172 (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback 00173 (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback 00174 (+) ErrorCallback : ADC error callback 00175 (+) InjectedConvCpltCallback : ADC group injected conversion complete callback 00176 (+) InjectedQueueOverflowCallback : ADC group injected context queue overflow callback 00177 (+) LevelOutOfWindow2Callback : ADC analog watchdog 2 callback 00178 (+) LevelOutOfWindow3Callback : ADC analog watchdog 3 callback 00179 (+) EndOfSamplingCallback : ADC end of sampling callback 00180 (+) MspInitCallback : ADC Msp Init callback 00181 (+) MspDeInitCallback : ADC Msp DeInit callback 00182 This function takes as parameters the HAL peripheral handle, the Callback ID 00183 and a pointer to the user callback function. 00184 [..] 00185 00186 Use function HAL_ADC_UnRegisterCallback to reset a callback to the default 00187 weak function. 00188 [..] 00189 00190 HAL_ADC_UnRegisterCallback takes as parameters the HAL peripheral handle, 00191 and the Callback ID. 00192 This function allows to reset following callbacks: 00193 (+) ConvCpltCallback : ADC conversion complete callback 00194 (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback 00195 (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback 00196 (+) ErrorCallback : ADC error callback 00197 (+) InjectedConvCpltCallback : ADC group injected conversion complete callback 00198 (+) InjectedQueueOverflowCallback : ADC group injected context queue overflow callback 00199 (+) LevelOutOfWindow2Callback : ADC analog watchdog 2 callback 00200 (+) LevelOutOfWindow3Callback : ADC analog watchdog 3 callback 00201 (+) EndOfSamplingCallback : ADC end of sampling callback 00202 (+) MspInitCallback : ADC Msp Init callback 00203 (+) MspDeInitCallback : ADC Msp DeInit callback 00204 [..] 00205 00206 By default, after the HAL_ADC_Init() and when the state is HAL_ADC_STATE_RESET 00207 all callbacks are set to the corresponding weak functions: 00208 examples HAL_ADC_ConvCpltCallback(), HAL_ADC_ErrorCallback(). 00209 Exception done for MspInit and MspDeInit functions that are 00210 reset to the legacy weak functions in the HAL_ADC_Init()/ HAL_ADC_DeInit() only when 00211 these callbacks are null (not registered beforehand). 00212 [..] 00213 00214 If MspInit or MspDeInit are not null, the HAL_ADC_Init()/ HAL_ADC_DeInit() 00215 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state. 00216 [..] 00217 00218 Callbacks can be registered/unregistered in HAL_ADC_STATE_READY state only. 00219 Exception done MspInit/MspDeInit functions that can be registered/unregistered 00220 in HAL_ADC_STATE_READY or HAL_ADC_STATE_RESET state, 00221 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. 00222 [..] 00223 00224 Then, the user first registers the MspInit/MspDeInit user callbacks 00225 using HAL_ADC_RegisterCallback() before calling HAL_ADC_DeInit() 00226 or HAL_ADC_Init() function. 00227 [..] 00228 00229 When the compilation flag USE_HAL_ADC_REGISTER_CALLBACKS is set to 0 or 00230 not defined, the callback registration feature is not available and all callbacks 00231 are set to the corresponding weak functions. 00232 00233 @endverbatim 00234 ****************************************************************************** 00235 * @attention 00236 * 00237 * <h2><center>© Copyright (c) 2017 STMicroelectronics. 00238 * All rights reserved.</center></h2> 00239 * 00240 * This software component is licensed by ST under BSD 3-Clause license, 00241 * the "License"; You may not use this file except in compliance with the 00242 * License. You may obtain a copy of the License at: 00243 * opensource.org/licenses/BSD-3-Clause 00244 * 00245 ****************************************************************************** 00246 */ 00247 00248 /* Includes ------------------------------------------------------------------*/ 00249 #include "stm32f4xx_hal.h" 00250 00251 /** @addtogroup STM32F4xx_HAL_Driver 00252 * @{ 00253 */ 00254 00255 /** @defgroup ADC ADC 00256 * @brief ADC driver modules 00257 * @{ 00258 */ 00259 00260 #ifdef HAL_ADC_MODULE_ENABLED 00261 00262 /* Private typedef -----------------------------------------------------------*/ 00263 /* Private define ------------------------------------------------------------*/ 00264 /* Private macro -------------------------------------------------------------*/ 00265 /* Private variables ---------------------------------------------------------*/ 00266 /** @addtogroup ADC_Private_Functions 00267 * @{ 00268 */ 00269 /* Private function prototypes -----------------------------------------------*/ 00270 static void ADC_Init(ADC_HandleTypeDef* hadc); 00271 static void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma); 00272 static void ADC_DMAError(DMA_HandleTypeDef *hdma); 00273 static void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma); 00274 /** 00275 * @} 00276 */ 00277 /* Exported functions --------------------------------------------------------*/ 00278 /** @defgroup ADC_Exported_Functions ADC Exported Functions 00279 * @{ 00280 */ 00281 00282 /** @defgroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions 00283 * @brief Initialization and Configuration functions 00284 * 00285 @verbatim 00286 =============================================================================== 00287 ##### Initialization and de-initialization functions ##### 00288 =============================================================================== 00289 [..] This section provides functions allowing to: 00290 (+) Initialize and configure the ADC. 00291 (+) De-initialize the ADC. 00292 00293 @endverbatim 00294 * @{ 00295 */ 00296 00297 /** 00298 * @brief Initializes the ADCx peripheral according to the specified parameters 00299 * in the ADC_InitStruct and initializes the ADC MSP. 00300 * 00301 * @note This function is used to configure the global features of the ADC ( 00302 * ClockPrescaler, Resolution, Data Alignment and number of conversion), however, 00303 * the rest of the configuration parameters are specific to the regular 00304 * channels group (scan mode activation, continuous mode activation, 00305 * External trigger source and edge, DMA continuous request after the 00306 * last transfer and End of conversion selection). 00307 * 00308 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 00309 * the configuration information for the specified ADC. 00310 * @retval HAL status 00311 */ 00312 HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc) 00313 { 00314 HAL_StatusTypeDef tmp_hal_status = HAL_OK; 00315 00316 /* Check ADC handle */ 00317 if(hadc == NULL) 00318 { 00319 return HAL_ERROR; 00320 } 00321 00322 /* Check the parameters */ 00323 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00324 assert_param(IS_ADC_CLOCKPRESCALER(hadc->Init.ClockPrescaler)); 00325 assert_param(IS_ADC_RESOLUTION(hadc->Init.Resolution)); 00326 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ScanConvMode)); 00327 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode)); 00328 assert_param(IS_ADC_EXT_TRIG(hadc->Init.ExternalTrigConv)); 00329 assert_param(IS_ADC_DATA_ALIGN(hadc->Init.DataAlign)); 00330 assert_param(IS_ADC_REGULAR_LENGTH(hadc->Init.NbrOfConversion)); 00331 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests)); 00332 assert_param(IS_ADC_EOCSelection(hadc->Init.EOCSelection)); 00333 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DiscontinuousConvMode)); 00334 00335 if(hadc->Init.ExternalTrigConv != ADC_SOFTWARE_START) 00336 { 00337 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge)); 00338 } 00339 00340 if(hadc->State == HAL_ADC_STATE_RESET) 00341 { 00342 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 00343 /* Init the ADC Callback settings */ 00344 hadc->ConvCpltCallback = HAL_ADC_ConvCpltCallback; /* Legacy weak callback */ 00345 hadc->ConvHalfCpltCallback = HAL_ADC_ConvHalfCpltCallback; /* Legacy weak callback */ 00346 hadc->LevelOutOfWindowCallback = HAL_ADC_LevelOutOfWindowCallback; /* Legacy weak callback */ 00347 hadc->ErrorCallback = HAL_ADC_ErrorCallback; /* Legacy weak callback */ 00348 hadc->InjectedConvCpltCallback = HAL_ADCEx_InjectedConvCpltCallback; /* Legacy weak callback */ 00349 if (hadc->MspInitCallback == NULL) 00350 { 00351 hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ 00352 } 00353 00354 /* Init the low level hardware */ 00355 hadc->MspInitCallback(hadc); 00356 #else 00357 /* Init the low level hardware */ 00358 HAL_ADC_MspInit(hadc); 00359 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 00360 00361 /* Initialize ADC error code */ 00362 ADC_CLEAR_ERRORCODE(hadc); 00363 00364 /* Allocate lock resource and initialize it */ 00365 hadc->Lock = HAL_UNLOCKED; 00366 } 00367 00368 /* Configuration of ADC parameters if previous preliminary actions are */ 00369 /* correctly completed. */ 00370 if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL)) 00371 { 00372 /* Set ADC state */ 00373 ADC_STATE_CLR_SET(hadc->State, 00374 HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, 00375 HAL_ADC_STATE_BUSY_INTERNAL); 00376 00377 /* Set ADC parameters */ 00378 ADC_Init(hadc); 00379 00380 /* Set ADC error code to none */ 00381 ADC_CLEAR_ERRORCODE(hadc); 00382 00383 /* Set the ADC state */ 00384 ADC_STATE_CLR_SET(hadc->State, 00385 HAL_ADC_STATE_BUSY_INTERNAL, 00386 HAL_ADC_STATE_READY); 00387 } 00388 else 00389 { 00390 tmp_hal_status = HAL_ERROR; 00391 } 00392 00393 /* Release Lock */ 00394 __HAL_UNLOCK(hadc); 00395 00396 /* Return function status */ 00397 return tmp_hal_status; 00398 } 00399 00400 /** 00401 * @brief Deinitializes the ADCx peripheral registers to their default reset values. 00402 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 00403 * the configuration information for the specified ADC. 00404 * @retval HAL status 00405 */ 00406 HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc) 00407 { 00408 HAL_StatusTypeDef tmp_hal_status = HAL_OK; 00409 00410 /* Check ADC handle */ 00411 if(hadc == NULL) 00412 { 00413 return HAL_ERROR; 00414 } 00415 00416 /* Check the parameters */ 00417 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00418 00419 /* Set ADC state */ 00420 SET_BIT(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL); 00421 00422 /* Stop potential conversion on going, on regular and injected groups */ 00423 /* Disable ADC peripheral */ 00424 __HAL_ADC_DISABLE(hadc); 00425 00426 /* Configuration of ADC parameters if previous preliminary actions are */ 00427 /* correctly completed. */ 00428 if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON)) 00429 { 00430 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 00431 if (hadc->MspDeInitCallback == NULL) 00432 { 00433 hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ 00434 } 00435 00436 /* DeInit the low level hardware: RCC clock, NVIC */ 00437 hadc->MspDeInitCallback(hadc); 00438 #else 00439 /* DeInit the low level hardware: RCC clock, NVIC */ 00440 HAL_ADC_MspDeInit(hadc); 00441 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 00442 00443 /* Set ADC error code to none */ 00444 ADC_CLEAR_ERRORCODE(hadc); 00445 00446 /* Set ADC state */ 00447 hadc->State = HAL_ADC_STATE_RESET; 00448 } 00449 00450 /* Process unlocked */ 00451 __HAL_UNLOCK(hadc); 00452 00453 /* Return function status */ 00454 return tmp_hal_status; 00455 } 00456 00457 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 00458 /** 00459 * @brief Register a User ADC Callback 00460 * To be used instead of the weak predefined callback 00461 * @param hadc Pointer to a ADC_HandleTypeDef structure that contains 00462 * the configuration information for the specified ADC. 00463 * @param CallbackID ID of the callback to be registered 00464 * This parameter can be one of the following values: 00465 * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID 00466 * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion DMA half-transfer callback ID 00467 * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID 00468 * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID 00469 * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID 00470 * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID 00471 * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID 00472 * @param pCallback pointer to the Callback function 00473 * @retval HAL status 00474 */ 00475 HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback) 00476 { 00477 HAL_StatusTypeDef status = HAL_OK; 00478 00479 if (pCallback == NULL) 00480 { 00481 /* Update the error code */ 00482 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; 00483 00484 return HAL_ERROR; 00485 } 00486 00487 if ((hadc->State & HAL_ADC_STATE_READY) != 0UL) 00488 { 00489 switch (CallbackID) 00490 { 00491 case HAL_ADC_CONVERSION_COMPLETE_CB_ID : 00492 hadc->ConvCpltCallback = pCallback; 00493 break; 00494 00495 case HAL_ADC_CONVERSION_HALF_CB_ID : 00496 hadc->ConvHalfCpltCallback = pCallback; 00497 break; 00498 00499 case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID : 00500 hadc->LevelOutOfWindowCallback = pCallback; 00501 break; 00502 00503 case HAL_ADC_ERROR_CB_ID : 00504 hadc->ErrorCallback = pCallback; 00505 break; 00506 00507 case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID : 00508 hadc->InjectedConvCpltCallback = pCallback; 00509 break; 00510 00511 case HAL_ADC_MSPINIT_CB_ID : 00512 hadc->MspInitCallback = pCallback; 00513 break; 00514 00515 case HAL_ADC_MSPDEINIT_CB_ID : 00516 hadc->MspDeInitCallback = pCallback; 00517 break; 00518 00519 default : 00520 /* Update the error code */ 00521 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; 00522 00523 /* Return error status */ 00524 status = HAL_ERROR; 00525 break; 00526 } 00527 } 00528 else if (HAL_ADC_STATE_RESET == hadc->State) 00529 { 00530 switch (CallbackID) 00531 { 00532 case HAL_ADC_MSPINIT_CB_ID : 00533 hadc->MspInitCallback = pCallback; 00534 break; 00535 00536 case HAL_ADC_MSPDEINIT_CB_ID : 00537 hadc->MspDeInitCallback = pCallback; 00538 break; 00539 00540 default : 00541 /* Update the error code */ 00542 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; 00543 00544 /* Return error status */ 00545 status = HAL_ERROR; 00546 break; 00547 } 00548 } 00549 else 00550 { 00551 /* Update the error code */ 00552 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; 00553 00554 /* Return error status */ 00555 status = HAL_ERROR; 00556 } 00557 00558 return status; 00559 } 00560 00561 /** 00562 * @brief Unregister a ADC Callback 00563 * ADC callback is redirected to the weak predefined callback 00564 * @param hadc Pointer to a ADC_HandleTypeDef structure that contains 00565 * the configuration information for the specified ADC. 00566 * @param CallbackID ID of the callback to be unregistered 00567 * This parameter can be one of the following values: 00568 * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID 00569 * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion DMA half-transfer callback ID 00570 * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID 00571 * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID 00572 * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID 00573 * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID 00574 * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID 00575 * @retval HAL status 00576 */ 00577 HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID) 00578 { 00579 HAL_StatusTypeDef status = HAL_OK; 00580 00581 if ((hadc->State & HAL_ADC_STATE_READY) != 0UL) 00582 { 00583 switch (CallbackID) 00584 { 00585 case HAL_ADC_CONVERSION_COMPLETE_CB_ID : 00586 hadc->ConvCpltCallback = HAL_ADC_ConvCpltCallback; 00587 break; 00588 00589 case HAL_ADC_CONVERSION_HALF_CB_ID : 00590 hadc->ConvHalfCpltCallback = HAL_ADC_ConvHalfCpltCallback; 00591 break; 00592 00593 case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID : 00594 hadc->LevelOutOfWindowCallback = HAL_ADC_LevelOutOfWindowCallback; 00595 break; 00596 00597 case HAL_ADC_ERROR_CB_ID : 00598 hadc->ErrorCallback = HAL_ADC_ErrorCallback; 00599 break; 00600 00601 case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID : 00602 hadc->InjectedConvCpltCallback = HAL_ADCEx_InjectedConvCpltCallback; 00603 break; 00604 00605 case HAL_ADC_MSPINIT_CB_ID : 00606 hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ 00607 break; 00608 00609 case HAL_ADC_MSPDEINIT_CB_ID : 00610 hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ 00611 break; 00612 00613 default : 00614 /* Update the error code */ 00615 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; 00616 00617 /* Return error status */ 00618 status = HAL_ERROR; 00619 break; 00620 } 00621 } 00622 else if (HAL_ADC_STATE_RESET == hadc->State) 00623 { 00624 switch (CallbackID) 00625 { 00626 case HAL_ADC_MSPINIT_CB_ID : 00627 hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ 00628 break; 00629 00630 case HAL_ADC_MSPDEINIT_CB_ID : 00631 hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ 00632 break; 00633 00634 default : 00635 /* Update the error code */ 00636 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; 00637 00638 /* Return error status */ 00639 status = HAL_ERROR; 00640 break; 00641 } 00642 } 00643 else 00644 { 00645 /* Update the error code */ 00646 hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; 00647 00648 /* Return error status */ 00649 status = HAL_ERROR; 00650 } 00651 00652 return status; 00653 } 00654 00655 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 00656 00657 /** 00658 * @brief Initializes the ADC MSP. 00659 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 00660 * the configuration information for the specified ADC. 00661 * @retval None 00662 */ 00663 __weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) 00664 { 00665 /* Prevent unused argument(s) compilation warning */ 00666 UNUSED(hadc); 00667 /* NOTE : This function Should not be modified, when the callback is needed, 00668 the HAL_ADC_MspInit could be implemented in the user file 00669 */ 00670 } 00671 00672 /** 00673 * @brief DeInitializes the ADC MSP. 00674 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 00675 * the configuration information for the specified ADC. 00676 * @retval None 00677 */ 00678 __weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) 00679 { 00680 /* Prevent unused argument(s) compilation warning */ 00681 UNUSED(hadc); 00682 /* NOTE : This function Should not be modified, when the callback is needed, 00683 the HAL_ADC_MspDeInit could be implemented in the user file 00684 */ 00685 } 00686 00687 /** 00688 * @} 00689 */ 00690 00691 /** @defgroup ADC_Exported_Functions_Group2 IO operation functions 00692 * @brief IO operation functions 00693 * 00694 @verbatim 00695 =============================================================================== 00696 ##### IO operation functions ##### 00697 =============================================================================== 00698 [..] This section provides functions allowing to: 00699 (+) Start conversion of regular channel. 00700 (+) Stop conversion of regular channel. 00701 (+) Start conversion of regular channel and enable interrupt. 00702 (+) Stop conversion of regular channel and disable interrupt. 00703 (+) Start conversion of regular channel and enable DMA transfer. 00704 (+) Stop conversion of regular channel and disable DMA transfer. 00705 (+) Handle ADC interrupt request. 00706 00707 @endverbatim 00708 * @{ 00709 */ 00710 00711 /** 00712 * @brief Enables ADC and starts conversion of the regular channels. 00713 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 00714 * the configuration information for the specified ADC. 00715 * @retval HAL status 00716 */ 00717 HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc) 00718 { 00719 __IO uint32_t counter = 0U; 00720 ADC_Common_TypeDef *tmpADC_Common; 00721 00722 /* Check the parameters */ 00723 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode)); 00724 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge)); 00725 00726 /* Process locked */ 00727 __HAL_LOCK(hadc); 00728 00729 /* Enable the ADC peripheral */ 00730 /* Check if ADC peripheral is disabled in order to enable it and wait during 00731 Tstab time the ADC's stabilization */ 00732 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) 00733 { 00734 /* Enable the Peripheral */ 00735 __HAL_ADC_ENABLE(hadc); 00736 00737 /* Delay for ADC stabilization time */ 00738 /* Compute number of CPU cycles to wait for */ 00739 counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U)); 00740 while(counter != 0U) 00741 { 00742 counter--; 00743 } 00744 } 00745 00746 /* Start conversion if ADC is effectively enabled */ 00747 if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON)) 00748 { 00749 /* Set ADC state */ 00750 /* - Clear state bitfield related to regular group conversion results */ 00751 /* - Set state bitfield related to regular group operation */ 00752 ADC_STATE_CLR_SET(hadc->State, 00753 HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR, 00754 HAL_ADC_STATE_REG_BUSY); 00755 00756 /* If conversions on group regular are also triggering group injected, */ 00757 /* update ADC state. */ 00758 if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET) 00759 { 00760 ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY); 00761 } 00762 00763 /* State machine update: Check if an injected conversion is ongoing */ 00764 if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY)) 00765 { 00766 /* Reset ADC error code fields related to conversions on group regular */ 00767 CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA)); 00768 } 00769 else 00770 { 00771 /* Reset ADC all error code fields */ 00772 ADC_CLEAR_ERRORCODE(hadc); 00773 } 00774 00775 /* Process unlocked */ 00776 /* Unlock before starting ADC conversions: in case of potential */ 00777 /* interruption, to let the process to ADC IRQ Handler. */ 00778 __HAL_UNLOCK(hadc); 00779 00780 /* Pointer to the common control register to which is belonging hadc */ 00781 /* (Depending on STM32F4 product, there may be up to 3 ADCs and 1 common */ 00782 /* control register) */ 00783 tmpADC_Common = ADC_COMMON_REGISTER(hadc); 00784 00785 /* Clear regular group conversion flag and overrun flag */ 00786 /* (To ensure of no unknown state from potential previous ADC operations) */ 00787 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOC | ADC_FLAG_OVR); 00788 00789 /* Check if Multimode enabled */ 00790 if(HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_MULTI)) 00791 { 00792 #if defined(ADC2) && defined(ADC3) 00793 if((hadc->Instance == ADC1) || ((hadc->Instance == ADC2) && ((ADC->CCR & ADC_CCR_MULTI_Msk) < ADC_CCR_MULTI_0)) \ 00794 || ((hadc->Instance == ADC3) && ((ADC->CCR & ADC_CCR_MULTI_Msk) < ADC_CCR_MULTI_4))) 00795 { 00796 #endif /* ADC2 || ADC3 */ 00797 /* if no external trigger present enable software conversion of regular channels */ 00798 if((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET) 00799 { 00800 /* Enable the selected ADC software conversion for regular group */ 00801 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART; 00802 } 00803 #if defined(ADC2) && defined(ADC3) 00804 } 00805 #endif /* ADC2 || ADC3 */ 00806 } 00807 else 00808 { 00809 /* if instance of handle correspond to ADC1 and no external trigger present enable software conversion of regular channels */ 00810 if((hadc->Instance == ADC1) && ((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET)) 00811 { 00812 /* Enable the selected ADC software conversion for regular group */ 00813 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART; 00814 } 00815 } 00816 } 00817 else 00818 { 00819 /* Update ADC state machine to error */ 00820 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); 00821 00822 /* Set ADC error code to ADC IP internal error */ 00823 SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); 00824 } 00825 00826 /* Return function status */ 00827 return HAL_OK; 00828 } 00829 00830 /** 00831 * @brief Disables ADC and stop conversion of regular channels. 00832 * 00833 * @note Caution: This function will stop also injected channels. 00834 * 00835 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 00836 * the configuration information for the specified ADC. 00837 * 00838 * @retval HAL status. 00839 */ 00840 HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc) 00841 { 00842 /* Check the parameters */ 00843 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00844 00845 /* Process locked */ 00846 __HAL_LOCK(hadc); 00847 00848 /* Stop potential conversion on going, on regular and injected groups */ 00849 /* Disable ADC peripheral */ 00850 __HAL_ADC_DISABLE(hadc); 00851 00852 /* Check if ADC is effectively disabled */ 00853 if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON)) 00854 { 00855 /* Set ADC state */ 00856 ADC_STATE_CLR_SET(hadc->State, 00857 HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, 00858 HAL_ADC_STATE_READY); 00859 } 00860 00861 /* Process unlocked */ 00862 __HAL_UNLOCK(hadc); 00863 00864 /* Return function status */ 00865 return HAL_OK; 00866 } 00867 00868 /** 00869 * @brief Poll for regular conversion complete 00870 * @note ADC conversion flags EOS (end of sequence) and EOC (end of 00871 * conversion) are cleared by this function. 00872 * @note This function cannot be used in a particular setup: ADC configured 00873 * in DMA mode and polling for end of each conversion (ADC init 00874 * parameter "EOCSelection" set to ADC_EOC_SINGLE_CONV). 00875 * In this case, DMA resets the flag EOC and polling cannot be 00876 * performed on each conversion. Nevertheless, polling can still 00877 * be performed on the complete sequence. 00878 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 00879 * the configuration information for the specified ADC. 00880 * @param Timeout Timeout value in millisecond. 00881 * @retval HAL status 00882 */ 00883 HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout) 00884 { 00885 uint32_t tickstart = 0U; 00886 00887 /* Verification that ADC configuration is compliant with polling for */ 00888 /* each conversion: */ 00889 /* Particular case is ADC configured in DMA mode and ADC sequencer with */ 00890 /* several ranks and polling for end of each conversion. */ 00891 /* For code simplicity sake, this particular case is generalized to */ 00892 /* ADC configured in DMA mode and polling for end of each conversion. */ 00893 if (HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_EOCS) && 00894 HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_DMA) ) 00895 { 00896 /* Update ADC state machine to error */ 00897 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 00898 00899 /* Process unlocked */ 00900 __HAL_UNLOCK(hadc); 00901 00902 return HAL_ERROR; 00903 } 00904 00905 /* Get tick */ 00906 tickstart = HAL_GetTick(); 00907 00908 /* Check End of conversion flag */ 00909 while(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC))) 00910 { 00911 /* Check if timeout is disabled (set to infinite wait) */ 00912 if(Timeout != HAL_MAX_DELAY) 00913 { 00914 if((Timeout == 0U) || ((HAL_GetTick() - tickstart ) > Timeout)) 00915 { 00916 /* New check to avoid false timeout detection in case of preemption */ 00917 if(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC))) 00918 { 00919 /* Update ADC state machine to timeout */ 00920 SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT); 00921 00922 /* Process unlocked */ 00923 __HAL_UNLOCK(hadc); 00924 00925 return HAL_TIMEOUT; 00926 } 00927 } 00928 } 00929 } 00930 00931 /* Clear regular group conversion flag */ 00932 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_STRT | ADC_FLAG_EOC); 00933 00934 /* Update ADC state machine */ 00935 SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC); 00936 00937 /* Determine whether any further conversion upcoming on group regular */ 00938 /* by external trigger, continuous mode or scan sequence on going. */ 00939 /* Note: On STM32F4, there is no independent flag of end of sequence. */ 00940 /* The test of scan sequence on going is done either with scan */ 00941 /* sequence disabled or with end of conversion flag set to */ 00942 /* of end of sequence. */ 00943 if(ADC_IS_SOFTWARE_START_REGULAR(hadc) && 00944 (hadc->Init.ContinuousConvMode == DISABLE) && 00945 (HAL_IS_BIT_CLR(hadc->Instance->SQR1, ADC_SQR1_L) || 00946 HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_EOCS) ) ) 00947 { 00948 /* Set ADC state */ 00949 CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY); 00950 00951 if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY)) 00952 { 00953 SET_BIT(hadc->State, HAL_ADC_STATE_READY); 00954 } 00955 } 00956 00957 /* Return ADC state */ 00958 return HAL_OK; 00959 } 00960 00961 /** 00962 * @brief Poll for conversion event 00963 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 00964 * the configuration information for the specified ADC. 00965 * @param EventType the ADC event type. 00966 * This parameter can be one of the following values: 00967 * @arg ADC_AWD_EVENT: ADC Analog watch Dog event. 00968 * @arg ADC_OVR_EVENT: ADC Overrun event. 00969 * @param Timeout Timeout value in millisecond. 00970 * @retval HAL status 00971 */ 00972 HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout) 00973 { 00974 uint32_t tickstart = 0U; 00975 00976 /* Check the parameters */ 00977 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00978 assert_param(IS_ADC_EVENT_TYPE(EventType)); 00979 00980 /* Get tick */ 00981 tickstart = HAL_GetTick(); 00982 00983 /* Check selected event flag */ 00984 while(!(__HAL_ADC_GET_FLAG(hadc,EventType))) 00985 { 00986 /* Check for the Timeout */ 00987 if(Timeout != HAL_MAX_DELAY) 00988 { 00989 if((Timeout == 0U) || ((HAL_GetTick() - tickstart ) > Timeout)) 00990 { 00991 /* New check to avoid false timeout detection in case of preemption */ 00992 if(!(__HAL_ADC_GET_FLAG(hadc,EventType))) 00993 { 00994 /* Update ADC state machine to timeout */ 00995 SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT); 00996 00997 /* Process unlocked */ 00998 __HAL_UNLOCK(hadc); 00999 01000 return HAL_TIMEOUT; 01001 } 01002 } 01003 } 01004 } 01005 01006 /* Analog watchdog (level out of window) event */ 01007 if(EventType == ADC_AWD_EVENT) 01008 { 01009 /* Set ADC state */ 01010 SET_BIT(hadc->State, HAL_ADC_STATE_AWD1); 01011 01012 /* Clear ADC analog watchdog flag */ 01013 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD); 01014 } 01015 /* Overrun event */ 01016 else 01017 { 01018 /* Set ADC state */ 01019 SET_BIT(hadc->State, HAL_ADC_STATE_REG_OVR); 01020 /* Set ADC error code to overrun */ 01021 SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_OVR); 01022 01023 /* Clear ADC overrun flag */ 01024 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR); 01025 } 01026 01027 /* Return ADC state */ 01028 return HAL_OK; 01029 } 01030 01031 01032 /** 01033 * @brief Enables the interrupt and starts ADC conversion of regular channels. 01034 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01035 * the configuration information for the specified ADC. 01036 * @retval HAL status. 01037 */ 01038 HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc) 01039 { 01040 __IO uint32_t counter = 0U; 01041 ADC_Common_TypeDef *tmpADC_Common; 01042 01043 /* Check the parameters */ 01044 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode)); 01045 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge)); 01046 01047 /* Process locked */ 01048 __HAL_LOCK(hadc); 01049 01050 /* Enable the ADC peripheral */ 01051 /* Check if ADC peripheral is disabled in order to enable it and wait during 01052 Tstab time the ADC's stabilization */ 01053 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) 01054 { 01055 /* Enable the Peripheral */ 01056 __HAL_ADC_ENABLE(hadc); 01057 01058 /* Delay for ADC stabilization time */ 01059 /* Compute number of CPU cycles to wait for */ 01060 counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U)); 01061 while(counter != 0U) 01062 { 01063 counter--; 01064 } 01065 } 01066 01067 /* Start conversion if ADC is effectively enabled */ 01068 if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON)) 01069 { 01070 /* Set ADC state */ 01071 /* - Clear state bitfield related to regular group conversion results */ 01072 /* - Set state bitfield related to regular group operation */ 01073 ADC_STATE_CLR_SET(hadc->State, 01074 HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR, 01075 HAL_ADC_STATE_REG_BUSY); 01076 01077 /* If conversions on group regular are also triggering group injected, */ 01078 /* update ADC state. */ 01079 if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET) 01080 { 01081 ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY); 01082 } 01083 01084 /* State machine update: Check if an injected conversion is ongoing */ 01085 if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY)) 01086 { 01087 /* Reset ADC error code fields related to conversions on group regular */ 01088 CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA)); 01089 } 01090 else 01091 { 01092 /* Reset ADC all error code fields */ 01093 ADC_CLEAR_ERRORCODE(hadc); 01094 } 01095 01096 /* Process unlocked */ 01097 /* Unlock before starting ADC conversions: in case of potential */ 01098 /* interruption, to let the process to ADC IRQ Handler. */ 01099 __HAL_UNLOCK(hadc); 01100 01101 /* Pointer to the common control register to which is belonging hadc */ 01102 /* (Depending on STM32F4 product, there may be up to 3 ADCs and 1 common */ 01103 /* control register) */ 01104 tmpADC_Common = ADC_COMMON_REGISTER(hadc); 01105 01106 /* Clear regular group conversion flag and overrun flag */ 01107 /* (To ensure of no unknown state from potential previous ADC operations) */ 01108 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOC | ADC_FLAG_OVR); 01109 01110 /* Enable end of conversion interrupt for regular group */ 01111 __HAL_ADC_ENABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_OVR)); 01112 01113 /* Check if Multimode enabled */ 01114 if(HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_MULTI)) 01115 { 01116 #if defined(ADC2) && defined(ADC3) 01117 if((hadc->Instance == ADC1) || ((hadc->Instance == ADC2) && ((ADC->CCR & ADC_CCR_MULTI_Msk) < ADC_CCR_MULTI_0)) \ 01118 || ((hadc->Instance == ADC3) && ((ADC->CCR & ADC_CCR_MULTI_Msk) < ADC_CCR_MULTI_4))) 01119 { 01120 #endif /* ADC2 || ADC3 */ 01121 /* if no external trigger present enable software conversion of regular channels */ 01122 if((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET) 01123 { 01124 /* Enable the selected ADC software conversion for regular group */ 01125 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART; 01126 } 01127 #if defined(ADC2) && defined(ADC3) 01128 } 01129 #endif /* ADC2 || ADC3 */ 01130 } 01131 else 01132 { 01133 /* if instance of handle correspond to ADC1 and no external trigger present enable software conversion of regular channels */ 01134 if((hadc->Instance == ADC1) && ((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET)) 01135 { 01136 /* Enable the selected ADC software conversion for regular group */ 01137 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART; 01138 } 01139 } 01140 } 01141 else 01142 { 01143 /* Update ADC state machine to error */ 01144 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); 01145 01146 /* Set ADC error code to ADC IP internal error */ 01147 SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); 01148 } 01149 01150 /* Return function status */ 01151 return HAL_OK; 01152 } 01153 01154 /** 01155 * @brief Disables the interrupt and stop ADC conversion of regular channels. 01156 * 01157 * @note Caution: This function will stop also injected channels. 01158 * 01159 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01160 * the configuration information for the specified ADC. 01161 * @retval HAL status. 01162 */ 01163 HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc) 01164 { 01165 /* Check the parameters */ 01166 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 01167 01168 /* Process locked */ 01169 __HAL_LOCK(hadc); 01170 01171 /* Stop potential conversion on going, on regular and injected groups */ 01172 /* Disable ADC peripheral */ 01173 __HAL_ADC_DISABLE(hadc); 01174 01175 /* Check if ADC is effectively disabled */ 01176 if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON)) 01177 { 01178 /* Disable ADC end of conversion interrupt for regular group */ 01179 __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_OVR)); 01180 01181 /* Set ADC state */ 01182 ADC_STATE_CLR_SET(hadc->State, 01183 HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, 01184 HAL_ADC_STATE_READY); 01185 } 01186 01187 /* Process unlocked */ 01188 __HAL_UNLOCK(hadc); 01189 01190 /* Return function status */ 01191 return HAL_OK; 01192 } 01193 01194 /** 01195 * @brief Handles ADC interrupt request 01196 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01197 * the configuration information for the specified ADC. 01198 * @retval None 01199 */ 01200 void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc) 01201 { 01202 uint32_t tmp1 = 0U, tmp2 = 0U; 01203 01204 /* Check the parameters */ 01205 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode)); 01206 assert_param(IS_ADC_REGULAR_LENGTH(hadc->Init.NbrOfConversion)); 01207 assert_param(IS_ADC_EOCSelection(hadc->Init.EOCSelection)); 01208 01209 tmp1 = __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC); 01210 tmp2 = __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_EOC); 01211 /* Check End of conversion flag for regular channels */ 01212 if(tmp1 && tmp2) 01213 { 01214 /* Update state machine on conversion status if not in error state */ 01215 if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL)) 01216 { 01217 /* Set ADC state */ 01218 SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC); 01219 } 01220 01221 /* Determine whether any further conversion upcoming on group regular */ 01222 /* by external trigger, continuous mode or scan sequence on going. */ 01223 /* Note: On STM32F4, there is no independent flag of end of sequence. */ 01224 /* The test of scan sequence on going is done either with scan */ 01225 /* sequence disabled or with end of conversion flag set to */ 01226 /* of end of sequence. */ 01227 if(ADC_IS_SOFTWARE_START_REGULAR(hadc) && 01228 (hadc->Init.ContinuousConvMode == DISABLE) && 01229 (HAL_IS_BIT_CLR(hadc->Instance->SQR1, ADC_SQR1_L) || 01230 HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_EOCS) ) ) 01231 { 01232 /* Disable ADC end of single conversion interrupt on group regular */ 01233 /* Note: Overrun interrupt was enabled with EOC interrupt in */ 01234 /* HAL_ADC_Start_IT(), but is not disabled here because can be used */ 01235 /* by overrun IRQ process below. */ 01236 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC); 01237 01238 /* Set ADC state */ 01239 CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY); 01240 01241 if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY)) 01242 { 01243 SET_BIT(hadc->State, HAL_ADC_STATE_READY); 01244 } 01245 } 01246 01247 /* Conversion complete callback */ 01248 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 01249 hadc->ConvCpltCallback(hadc); 01250 #else 01251 HAL_ADC_ConvCpltCallback(hadc); 01252 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 01253 01254 /* Clear regular group conversion flag */ 01255 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_STRT | ADC_FLAG_EOC); 01256 } 01257 01258 tmp1 = __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOC); 01259 tmp2 = __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_JEOC); 01260 /* Check End of conversion flag for injected channels */ 01261 if(tmp1 && tmp2) 01262 { 01263 /* Update state machine on conversion status if not in error state */ 01264 if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL)) 01265 { 01266 /* Set ADC state */ 01267 SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC); 01268 } 01269 01270 /* Determine whether any further conversion upcoming on group injected */ 01271 /* by external trigger, scan sequence on going or by automatic injected */ 01272 /* conversion from group regular (same conditions as group regular */ 01273 /* interruption disabling above). */ 01274 if(ADC_IS_SOFTWARE_START_INJECTED(hadc) && 01275 (HAL_IS_BIT_CLR(hadc->Instance->JSQR, ADC_JSQR_JL) || 01276 HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_EOCS) ) && 01277 (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) && 01278 (ADC_IS_SOFTWARE_START_REGULAR(hadc) && 01279 (hadc->Init.ContinuousConvMode == DISABLE) ) ) ) 01280 { 01281 /* Disable ADC end of single conversion interrupt on group injected */ 01282 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC); 01283 01284 /* Set ADC state */ 01285 CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY); 01286 01287 if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY)) 01288 { 01289 SET_BIT(hadc->State, HAL_ADC_STATE_READY); 01290 } 01291 } 01292 01293 /* Conversion complete callback */ 01294 /* Conversion complete callback */ 01295 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 01296 hadc->InjectedConvCpltCallback(hadc); 01297 #else 01298 HAL_ADCEx_InjectedConvCpltCallback(hadc); 01299 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 01300 01301 /* Clear injected group conversion flag */ 01302 __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JSTRT | ADC_FLAG_JEOC)); 01303 } 01304 01305 tmp1 = __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_AWD); 01306 tmp2 = __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_AWD); 01307 /* Check Analog watchdog flag */ 01308 if(tmp1 && tmp2) 01309 { 01310 if(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_AWD)) 01311 { 01312 /* Set ADC state */ 01313 SET_BIT(hadc->State, HAL_ADC_STATE_AWD1); 01314 01315 /* Level out of window callback */ 01316 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 01317 hadc->LevelOutOfWindowCallback(hadc); 01318 #else 01319 HAL_ADC_LevelOutOfWindowCallback(hadc); 01320 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 01321 01322 /* Clear the ADC analog watchdog flag */ 01323 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD); 01324 } 01325 } 01326 01327 tmp1 = __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_OVR); 01328 tmp2 = __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_OVR); 01329 /* Check Overrun flag */ 01330 if(tmp1 && tmp2) 01331 { 01332 /* Note: On STM32F4, ADC overrun can be set through other parameters */ 01333 /* refer to description of parameter "EOCSelection" for more */ 01334 /* details. */ 01335 01336 /* Set ADC error code to overrun */ 01337 SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_OVR); 01338 01339 /* Clear ADC overrun flag */ 01340 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR); 01341 01342 /* Error callback */ 01343 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 01344 hadc->ErrorCallback(hadc); 01345 #else 01346 HAL_ADC_ErrorCallback(hadc); 01347 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 01348 01349 /* Clear the Overrun flag */ 01350 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR); 01351 } 01352 } 01353 01354 /** 01355 * @brief Enables ADC DMA request after last transfer (Single-ADC mode) and enables ADC peripheral 01356 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01357 * the configuration information for the specified ADC. 01358 * @param pData The destination Buffer address. 01359 * @param Length The length of data to be transferred from ADC peripheral to memory. 01360 * @retval HAL status 01361 */ 01362 HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length) 01363 { 01364 __IO uint32_t counter = 0U; 01365 ADC_Common_TypeDef *tmpADC_Common; 01366 01367 /* Check the parameters */ 01368 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode)); 01369 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge)); 01370 01371 /* Process locked */ 01372 __HAL_LOCK(hadc); 01373 01374 /* Enable the ADC peripheral */ 01375 /* Check if ADC peripheral is disabled in order to enable it and wait during 01376 Tstab time the ADC's stabilization */ 01377 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) 01378 { 01379 /* Enable the Peripheral */ 01380 __HAL_ADC_ENABLE(hadc); 01381 01382 /* Delay for ADC stabilization time */ 01383 /* Compute number of CPU cycles to wait for */ 01384 counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U)); 01385 while(counter != 0U) 01386 { 01387 counter--; 01388 } 01389 } 01390 01391 /* Check ADC DMA Mode */ 01392 /* - disable the DMA Mode if it is already enabled */ 01393 if((hadc->Instance->CR2 & ADC_CR2_DMA) == ADC_CR2_DMA) 01394 { 01395 CLEAR_BIT(hadc->Instance->CR2, ADC_CR2_DMA); 01396 } 01397 01398 /* Start conversion if ADC is effectively enabled */ 01399 if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON)) 01400 { 01401 /* Set ADC state */ 01402 /* - Clear state bitfield related to regular group conversion results */ 01403 /* - Set state bitfield related to regular group operation */ 01404 ADC_STATE_CLR_SET(hadc->State, 01405 HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR, 01406 HAL_ADC_STATE_REG_BUSY); 01407 01408 /* If conversions on group regular are also triggering group injected, */ 01409 /* update ADC state. */ 01410 if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET) 01411 { 01412 ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY); 01413 } 01414 01415 /* State machine update: Check if an injected conversion is ongoing */ 01416 if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY)) 01417 { 01418 /* Reset ADC error code fields related to conversions on group regular */ 01419 CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA)); 01420 } 01421 else 01422 { 01423 /* Reset ADC all error code fields */ 01424 ADC_CLEAR_ERRORCODE(hadc); 01425 } 01426 01427 /* Process unlocked */ 01428 /* Unlock before starting ADC conversions: in case of potential */ 01429 /* interruption, to let the process to ADC IRQ Handler. */ 01430 __HAL_UNLOCK(hadc); 01431 01432 /* Pointer to the common control register to which is belonging hadc */ 01433 /* (Depending on STM32F4 product, there may be up to 3 ADCs and 1 common */ 01434 /* control register) */ 01435 tmpADC_Common = ADC_COMMON_REGISTER(hadc); 01436 01437 /* Set the DMA transfer complete callback */ 01438 hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt; 01439 01440 /* Set the DMA half transfer complete callback */ 01441 hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt; 01442 01443 /* Set the DMA error callback */ 01444 hadc->DMA_Handle->XferErrorCallback = ADC_DMAError; 01445 01446 01447 /* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC */ 01448 /* start (in case of SW start): */ 01449 01450 /* Clear regular group conversion flag and overrun flag */ 01451 /* (To ensure of no unknown state from potential previous ADC operations) */ 01452 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOC | ADC_FLAG_OVR); 01453 01454 /* Enable ADC overrun interrupt */ 01455 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR); 01456 01457 /* Enable ADC DMA mode */ 01458 hadc->Instance->CR2 |= ADC_CR2_DMA; 01459 01460 /* Start the DMA channel */ 01461 HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length); 01462 01463 /* Check if Multimode enabled */ 01464 if(HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_MULTI)) 01465 { 01466 #if defined(ADC2) && defined(ADC3) 01467 if((hadc->Instance == ADC1) || ((hadc->Instance == ADC2) && ((ADC->CCR & ADC_CCR_MULTI_Msk) < ADC_CCR_MULTI_0)) \ 01468 || ((hadc->Instance == ADC3) && ((ADC->CCR & ADC_CCR_MULTI_Msk) < ADC_CCR_MULTI_4))) 01469 { 01470 #endif /* ADC2 || ADC3 */ 01471 /* if no external trigger present enable software conversion of regular channels */ 01472 if((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET) 01473 { 01474 /* Enable the selected ADC software conversion for regular group */ 01475 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART; 01476 } 01477 #if defined(ADC2) && defined(ADC3) 01478 } 01479 #endif /* ADC2 || ADC3 */ 01480 } 01481 else 01482 { 01483 /* if instance of handle correspond to ADC1 and no external trigger present enable software conversion of regular channels */ 01484 if((hadc->Instance == ADC1) && ((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET)) 01485 { 01486 /* Enable the selected ADC software conversion for regular group */ 01487 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART; 01488 } 01489 } 01490 } 01491 else 01492 { 01493 /* Update ADC state machine to error */ 01494 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); 01495 01496 /* Set ADC error code to ADC IP internal error */ 01497 SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); 01498 } 01499 01500 /* Return function status */ 01501 return HAL_OK; 01502 } 01503 01504 /** 01505 * @brief Disables ADC DMA (Single-ADC mode) and disables ADC peripheral 01506 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01507 * the configuration information for the specified ADC. 01508 * @retval HAL status 01509 */ 01510 HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc) 01511 { 01512 HAL_StatusTypeDef tmp_hal_status = HAL_OK; 01513 01514 /* Check the parameters */ 01515 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 01516 01517 /* Process locked */ 01518 __HAL_LOCK(hadc); 01519 01520 /* Stop potential conversion on going, on regular and injected groups */ 01521 /* Disable ADC peripheral */ 01522 __HAL_ADC_DISABLE(hadc); 01523 01524 /* Check if ADC is effectively disabled */ 01525 if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON)) 01526 { 01527 /* Disable the selected ADC DMA mode */ 01528 hadc->Instance->CR2 &= ~ADC_CR2_DMA; 01529 01530 /* Disable the DMA channel (in case of DMA in circular mode or stop while */ 01531 /* DMA transfer is on going) */ 01532 if (hadc->DMA_Handle->State == HAL_DMA_STATE_BUSY) 01533 { 01534 tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); 01535 01536 /* Check if DMA channel effectively disabled */ 01537 if (tmp_hal_status != HAL_OK) 01538 { 01539 /* Update ADC state machine to error */ 01540 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); 01541 } 01542 } 01543 01544 /* Disable ADC overrun interrupt */ 01545 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); 01546 01547 /* Set ADC state */ 01548 ADC_STATE_CLR_SET(hadc->State, 01549 HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, 01550 HAL_ADC_STATE_READY); 01551 } 01552 01553 /* Process unlocked */ 01554 __HAL_UNLOCK(hadc); 01555 01556 /* Return function status */ 01557 return tmp_hal_status; 01558 } 01559 01560 /** 01561 * @brief Gets the converted value from data register of regular channel. 01562 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01563 * the configuration information for the specified ADC. 01564 * @retval Converted value 01565 */ 01566 uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc) 01567 { 01568 /* Return the selected ADC converted value */ 01569 return hadc->Instance->DR; 01570 } 01571 01572 /** 01573 * @brief Regular conversion complete callback in non blocking mode 01574 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01575 * the configuration information for the specified ADC. 01576 * @retval None 01577 */ 01578 __weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) 01579 { 01580 /* Prevent unused argument(s) compilation warning */ 01581 UNUSED(hadc); 01582 /* NOTE : This function Should not be modified, when the callback is needed, 01583 the HAL_ADC_ConvCpltCallback could be implemented in the user file 01584 */ 01585 } 01586 01587 /** 01588 * @brief Regular conversion half DMA transfer callback in non blocking mode 01589 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01590 * the configuration information for the specified ADC. 01591 * @retval None 01592 */ 01593 __weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc) 01594 { 01595 /* Prevent unused argument(s) compilation warning */ 01596 UNUSED(hadc); 01597 /* NOTE : This function Should not be modified, when the callback is needed, 01598 the HAL_ADC_ConvHalfCpltCallback could be implemented in the user file 01599 */ 01600 } 01601 01602 /** 01603 * @brief Analog watchdog callback in non blocking mode 01604 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01605 * the configuration information for the specified ADC. 01606 * @retval None 01607 */ 01608 __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc) 01609 { 01610 /* Prevent unused argument(s) compilation warning */ 01611 UNUSED(hadc); 01612 /* NOTE : This function Should not be modified, when the callback is needed, 01613 the HAL_ADC_LevelOoutOfWindowCallback could be implemented in the user file 01614 */ 01615 } 01616 01617 /** 01618 * @brief Error ADC callback. 01619 * @note In case of error due to overrun when using ADC with DMA transfer 01620 * (HAL ADC handle paramater "ErrorCode" to state "HAL_ADC_ERROR_OVR"): 01621 * - Reinitialize the DMA using function "HAL_ADC_Stop_DMA()". 01622 * - If needed, restart a new ADC conversion using function 01623 * "HAL_ADC_Start_DMA()" 01624 * (this function is also clearing overrun flag) 01625 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01626 * the configuration information for the specified ADC. 01627 * @retval None 01628 */ 01629 __weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc) 01630 { 01631 /* Prevent unused argument(s) compilation warning */ 01632 UNUSED(hadc); 01633 /* NOTE : This function Should not be modified, when the callback is needed, 01634 the HAL_ADC_ErrorCallback could be implemented in the user file 01635 */ 01636 } 01637 01638 /** 01639 * @} 01640 */ 01641 01642 /** @defgroup ADC_Exported_Functions_Group3 Peripheral Control functions 01643 * @brief Peripheral Control functions 01644 * 01645 @verbatim 01646 =============================================================================== 01647 ##### Peripheral Control functions ##### 01648 =============================================================================== 01649 [..] This section provides functions allowing to: 01650 (+) Configure regular channels. 01651 (+) Configure injected channels. 01652 (+) Configure multimode. 01653 (+) Configure the analog watch dog. 01654 01655 @endverbatim 01656 * @{ 01657 */ 01658 01659 /** 01660 * @brief Configures for the selected ADC regular channel its corresponding 01661 * rank in the sequencer and its sample time. 01662 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01663 * the configuration information for the specified ADC. 01664 * @param sConfig ADC configuration structure. 01665 * @retval HAL status 01666 */ 01667 HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig) 01668 { 01669 __IO uint32_t counter = 0U; 01670 ADC_Common_TypeDef *tmpADC_Common; 01671 01672 /* Check the parameters */ 01673 assert_param(IS_ADC_CHANNEL(sConfig->Channel)); 01674 assert_param(IS_ADC_REGULAR_RANK(sConfig->Rank)); 01675 assert_param(IS_ADC_SAMPLE_TIME(sConfig->SamplingTime)); 01676 01677 /* Process locked */ 01678 __HAL_LOCK(hadc); 01679 01680 /* if ADC_Channel_10 ... ADC_Channel_18 is selected */ 01681 if (sConfig->Channel > ADC_CHANNEL_9) 01682 { 01683 /* Clear the old sample time */ 01684 hadc->Instance->SMPR1 &= ~ADC_SMPR1(ADC_SMPR1_SMP10, sConfig->Channel); 01685 01686 /* Set the new sample time */ 01687 hadc->Instance->SMPR1 |= ADC_SMPR1(sConfig->SamplingTime, sConfig->Channel); 01688 } 01689 else /* ADC_Channel include in ADC_Channel_[0..9] */ 01690 { 01691 /* Clear the old sample time */ 01692 hadc->Instance->SMPR2 &= ~ADC_SMPR2(ADC_SMPR2_SMP0, sConfig->Channel); 01693 01694 /* Set the new sample time */ 01695 hadc->Instance->SMPR2 |= ADC_SMPR2(sConfig->SamplingTime, sConfig->Channel); 01696 } 01697 01698 /* For Rank 1 to 6 */ 01699 if (sConfig->Rank < 7U) 01700 { 01701 /* Clear the old SQx bits for the selected rank */ 01702 hadc->Instance->SQR3 &= ~ADC_SQR3_RK(ADC_SQR3_SQ1, sConfig->Rank); 01703 01704 /* Set the SQx bits for the selected rank */ 01705 hadc->Instance->SQR3 |= ADC_SQR3_RK(sConfig->Channel, sConfig->Rank); 01706 } 01707 /* For Rank 7 to 12 */ 01708 else if (sConfig->Rank < 13U) 01709 { 01710 /* Clear the old SQx bits for the selected rank */ 01711 hadc->Instance->SQR2 &= ~ADC_SQR2_RK(ADC_SQR2_SQ7, sConfig->Rank); 01712 01713 /* Set the SQx bits for the selected rank */ 01714 hadc->Instance->SQR2 |= ADC_SQR2_RK(sConfig->Channel, sConfig->Rank); 01715 } 01716 /* For Rank 13 to 16 */ 01717 else 01718 { 01719 /* Clear the old SQx bits for the selected rank */ 01720 hadc->Instance->SQR1 &= ~ADC_SQR1_RK(ADC_SQR1_SQ13, sConfig->Rank); 01721 01722 /* Set the SQx bits for the selected rank */ 01723 hadc->Instance->SQR1 |= ADC_SQR1_RK(sConfig->Channel, sConfig->Rank); 01724 } 01725 01726 /* Pointer to the common control register to which is belonging hadc */ 01727 /* (Depending on STM32F4 product, there may be up to 3 ADCs and 1 common */ 01728 /* control register) */ 01729 tmpADC_Common = ADC_COMMON_REGISTER(hadc); 01730 01731 /* if ADC1 Channel_18 is selected for VBAT Channel ennable VBATE */ 01732 if ((hadc->Instance == ADC1) && (sConfig->Channel == ADC_CHANNEL_VBAT)) 01733 { 01734 /* Disable the TEMPSENSOR channel in case of using board with multiplixed ADC_CHANNEL_VBAT & ADC_CHANNEL_TEMPSENSOR*/ 01735 if ((uint16_t)ADC_CHANNEL_TEMPSENSOR == (uint16_t)ADC_CHANNEL_VBAT) 01736 { 01737 tmpADC_Common->CCR &= ~ADC_CCR_TSVREFE; 01738 } 01739 /* Enable the VBAT channel*/ 01740 tmpADC_Common->CCR |= ADC_CCR_VBATE; 01741 } 01742 01743 /* if ADC1 Channel_16 or Channel_18 is selected for Temperature sensor or 01744 Channel_17 is selected for VREFINT enable TSVREFE */ 01745 if ((hadc->Instance == ADC1) && ((sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) || (sConfig->Channel == ADC_CHANNEL_VREFINT))) 01746 { 01747 /* Disable the VBAT channel in case of using board with multiplixed ADC_CHANNEL_VBAT & ADC_CHANNEL_TEMPSENSOR*/ 01748 if ((uint16_t)ADC_CHANNEL_TEMPSENSOR == (uint16_t)ADC_CHANNEL_VBAT) 01749 { 01750 tmpADC_Common->CCR &= ~ADC_CCR_VBATE; 01751 } 01752 /* Enable the Temperature sensor and VREFINT channel*/ 01753 tmpADC_Common->CCR |= ADC_CCR_TSVREFE; 01754 01755 if(sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) 01756 { 01757 /* Delay for temperature sensor stabilization time */ 01758 /* Compute number of CPU cycles to wait for */ 01759 counter = (ADC_TEMPSENSOR_DELAY_US * (SystemCoreClock / 1000000U)); 01760 while(counter != 0U) 01761 { 01762 counter--; 01763 } 01764 } 01765 } 01766 01767 /* Process unlocked */ 01768 __HAL_UNLOCK(hadc); 01769 01770 /* Return function status */ 01771 return HAL_OK; 01772 } 01773 01774 /** 01775 * @brief Configures the analog watchdog. 01776 * @note Analog watchdog thresholds can be modified while ADC conversion 01777 * is on going. 01778 * In this case, some constraints must be taken into account: 01779 * The programmed threshold values are effective from the next 01780 * ADC EOC (end of unitary conversion). 01781 * Considering that registers write delay may happen due to 01782 * bus activity, this might cause an uncertainty on the 01783 * effective timing of the new programmed threshold values. 01784 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01785 * the configuration information for the specified ADC. 01786 * @param AnalogWDGConfig pointer to an ADC_AnalogWDGConfTypeDef structure 01787 * that contains the configuration information of ADC analog watchdog. 01788 * @retval HAL status 01789 */ 01790 HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig) 01791 { 01792 #ifdef USE_FULL_ASSERT 01793 uint32_t tmp = 0U; 01794 #endif /* USE_FULL_ASSERT */ 01795 01796 /* Check the parameters */ 01797 assert_param(IS_ADC_ANALOG_WATCHDOG(AnalogWDGConfig->WatchdogMode)); 01798 assert_param(IS_ADC_CHANNEL(AnalogWDGConfig->Channel)); 01799 assert_param(IS_FUNCTIONAL_STATE(AnalogWDGConfig->ITMode)); 01800 01801 #ifdef USE_FULL_ASSERT 01802 tmp = ADC_GET_RESOLUTION(hadc); 01803 assert_param(IS_ADC_RANGE(tmp, AnalogWDGConfig->HighThreshold)); 01804 assert_param(IS_ADC_RANGE(tmp, AnalogWDGConfig->LowThreshold)); 01805 #endif /* USE_FULL_ASSERT */ 01806 01807 /* Process locked */ 01808 __HAL_LOCK(hadc); 01809 01810 if(AnalogWDGConfig->ITMode == ENABLE) 01811 { 01812 /* Enable the ADC Analog watchdog interrupt */ 01813 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_AWD); 01814 } 01815 else 01816 { 01817 /* Disable the ADC Analog watchdog interrupt */ 01818 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_AWD); 01819 } 01820 01821 /* Clear AWDEN, JAWDEN and AWDSGL bits */ 01822 hadc->Instance->CR1 &= ~(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN | ADC_CR1_AWDEN); 01823 01824 /* Set the analog watchdog enable mode */ 01825 hadc->Instance->CR1 |= AnalogWDGConfig->WatchdogMode; 01826 01827 /* Set the high threshold */ 01828 hadc->Instance->HTR = AnalogWDGConfig->HighThreshold; 01829 01830 /* Set the low threshold */ 01831 hadc->Instance->LTR = AnalogWDGConfig->LowThreshold; 01832 01833 /* Clear the Analog watchdog channel select bits */ 01834 hadc->Instance->CR1 &= ~ADC_CR1_AWDCH; 01835 01836 /* Set the Analog watchdog channel */ 01837 hadc->Instance->CR1 |= (uint32_t)((uint16_t)(AnalogWDGConfig->Channel)); 01838 01839 /* Process unlocked */ 01840 __HAL_UNLOCK(hadc); 01841 01842 /* Return function status */ 01843 return HAL_OK; 01844 } 01845 01846 /** 01847 * @} 01848 */ 01849 01850 /** @defgroup ADC_Exported_Functions_Group4 ADC Peripheral State functions 01851 * @brief ADC Peripheral State functions 01852 * 01853 @verbatim 01854 =============================================================================== 01855 ##### Peripheral State and errors functions ##### 01856 =============================================================================== 01857 [..] 01858 This subsection provides functions allowing to 01859 (+) Check the ADC state 01860 (+) Check the ADC Error 01861 01862 @endverbatim 01863 * @{ 01864 */ 01865 01866 /** 01867 * @brief return the ADC state 01868 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01869 * the configuration information for the specified ADC. 01870 * @retval HAL state 01871 */ 01872 uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc) 01873 { 01874 /* Return ADC state */ 01875 return hadc->State; 01876 } 01877 01878 /** 01879 * @brief Return the ADC error code 01880 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01881 * the configuration information for the specified ADC. 01882 * @retval ADC Error Code 01883 */ 01884 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc) 01885 { 01886 return hadc->ErrorCode; 01887 } 01888 01889 /** 01890 * @} 01891 */ 01892 01893 /** @addtogroup ADC_Private_Functions 01894 * @{ 01895 */ 01896 01897 /** 01898 * @brief Initializes the ADCx peripheral according to the specified parameters 01899 * in the ADC_InitStruct without initializing the ADC MSP. 01900 * @param hadc pointer to a ADC_HandleTypeDef structure that contains 01901 * the configuration information for the specified ADC. 01902 * @retval None 01903 */ 01904 static void ADC_Init(ADC_HandleTypeDef* hadc) 01905 { 01906 ADC_Common_TypeDef *tmpADC_Common; 01907 01908 /* Set ADC parameters */ 01909 /* Pointer to the common control register to which is belonging hadc */ 01910 /* (Depending on STM32F4 product, there may be up to 3 ADCs and 1 common */ 01911 /* control register) */ 01912 tmpADC_Common = ADC_COMMON_REGISTER(hadc); 01913 01914 /* Set the ADC clock prescaler */ 01915 tmpADC_Common->CCR &= ~(ADC_CCR_ADCPRE); 01916 tmpADC_Common->CCR |= hadc->Init.ClockPrescaler; 01917 01918 /* Set ADC scan mode */ 01919 hadc->Instance->CR1 &= ~(ADC_CR1_SCAN); 01920 hadc->Instance->CR1 |= ADC_CR1_SCANCONV(hadc->Init.ScanConvMode); 01921 01922 /* Set ADC resolution */ 01923 hadc->Instance->CR1 &= ~(ADC_CR1_RES); 01924 hadc->Instance->CR1 |= hadc->Init.Resolution; 01925 01926 /* Set ADC data alignment */ 01927 hadc->Instance->CR2 &= ~(ADC_CR2_ALIGN); 01928 hadc->Instance->CR2 |= hadc->Init.DataAlign; 01929 01930 /* Enable external trigger if trigger selection is different of software */ 01931 /* start. */ 01932 /* Note: This configuration keeps the hardware feature of parameter */ 01933 /* ExternalTrigConvEdge "trigger edge none" equivalent to */ 01934 /* software start. */ 01935 if(hadc->Init.ExternalTrigConv != ADC_SOFTWARE_START) 01936 { 01937 /* Select external trigger to start conversion */ 01938 hadc->Instance->CR2 &= ~(ADC_CR2_EXTSEL); 01939 hadc->Instance->CR2 |= hadc->Init.ExternalTrigConv; 01940 01941 /* Select external trigger polarity */ 01942 hadc->Instance->CR2 &= ~(ADC_CR2_EXTEN); 01943 hadc->Instance->CR2 |= hadc->Init.ExternalTrigConvEdge; 01944 } 01945 else 01946 { 01947 /* Reset the external trigger */ 01948 hadc->Instance->CR2 &= ~(ADC_CR2_EXTSEL); 01949 hadc->Instance->CR2 &= ~(ADC_CR2_EXTEN); 01950 } 01951 01952 /* Enable or disable ADC continuous conversion mode */ 01953 hadc->Instance->CR2 &= ~(ADC_CR2_CONT); 01954 hadc->Instance->CR2 |= ADC_CR2_CONTINUOUS((uint32_t)hadc->Init.ContinuousConvMode); 01955 01956 if(hadc->Init.DiscontinuousConvMode != DISABLE) 01957 { 01958 assert_param(IS_ADC_REGULAR_DISC_NUMBER(hadc->Init.NbrOfDiscConversion)); 01959 01960 /* Enable the selected ADC regular discontinuous mode */ 01961 hadc->Instance->CR1 |= (uint32_t)ADC_CR1_DISCEN; 01962 01963 /* Set the number of channels to be converted in discontinuous mode */ 01964 hadc->Instance->CR1 &= ~(ADC_CR1_DISCNUM); 01965 hadc->Instance->CR1 |= ADC_CR1_DISCONTINUOUS(hadc->Init.NbrOfDiscConversion); 01966 } 01967 else 01968 { 01969 /* Disable the selected ADC regular discontinuous mode */ 01970 hadc->Instance->CR1 &= ~(ADC_CR1_DISCEN); 01971 } 01972 01973 /* Set ADC number of conversion */ 01974 hadc->Instance->SQR1 &= ~(ADC_SQR1_L); 01975 hadc->Instance->SQR1 |= ADC_SQR1(hadc->Init.NbrOfConversion); 01976 01977 /* Enable or disable ADC DMA continuous request */ 01978 hadc->Instance->CR2 &= ~(ADC_CR2_DDS); 01979 hadc->Instance->CR2 |= ADC_CR2_DMAContReq((uint32_t)hadc->Init.DMAContinuousRequests); 01980 01981 /* Enable or disable ADC end of conversion selection */ 01982 hadc->Instance->CR2 &= ~(ADC_CR2_EOCS); 01983 hadc->Instance->CR2 |= ADC_CR2_EOCSelection(hadc->Init.EOCSelection); 01984 } 01985 01986 /** 01987 * @brief DMA transfer complete callback. 01988 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 01989 * the configuration information for the specified DMA module. 01990 * @retval None 01991 */ 01992 static void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma) 01993 { 01994 /* Retrieve ADC handle corresponding to current DMA handle */ 01995 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; 01996 01997 /* Update state machine on conversion status if not in error state */ 01998 if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL | HAL_ADC_STATE_ERROR_DMA)) 01999 { 02000 /* Update ADC state machine */ 02001 SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC); 02002 02003 /* Determine whether any further conversion upcoming on group regular */ 02004 /* by external trigger, continuous mode or scan sequence on going. */ 02005 /* Note: On STM32F4, there is no independent flag of end of sequence. */ 02006 /* The test of scan sequence on going is done either with scan */ 02007 /* sequence disabled or with end of conversion flag set to */ 02008 /* of end of sequence. */ 02009 if(ADC_IS_SOFTWARE_START_REGULAR(hadc) && 02010 (hadc->Init.ContinuousConvMode == DISABLE) && 02011 (HAL_IS_BIT_CLR(hadc->Instance->SQR1, ADC_SQR1_L) || 02012 HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_EOCS) ) ) 02013 { 02014 /* Disable ADC end of single conversion interrupt on group regular */ 02015 /* Note: Overrun interrupt was enabled with EOC interrupt in */ 02016 /* HAL_ADC_Start_IT(), but is not disabled here because can be used */ 02017 /* by overrun IRQ process below. */ 02018 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC); 02019 02020 /* Set ADC state */ 02021 CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY); 02022 02023 if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY)) 02024 { 02025 SET_BIT(hadc->State, HAL_ADC_STATE_READY); 02026 } 02027 } 02028 02029 /* Conversion complete callback */ 02030 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 02031 hadc->ConvCpltCallback(hadc); 02032 #else 02033 HAL_ADC_ConvCpltCallback(hadc); 02034 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 02035 } 02036 else /* DMA and-or internal error occurred */ 02037 { 02038 if ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) != 0UL) 02039 { 02040 /* Call HAL ADC Error Callback function */ 02041 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 02042 hadc->ErrorCallback(hadc); 02043 #else 02044 HAL_ADC_ErrorCallback(hadc); 02045 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 02046 } 02047 else 02048 { 02049 /* Call DMA error callback */ 02050 hadc->DMA_Handle->XferErrorCallback(hdma); 02051 } 02052 } 02053 } 02054 02055 /** 02056 * @brief DMA half transfer complete callback. 02057 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 02058 * the configuration information for the specified DMA module. 02059 * @retval None 02060 */ 02061 static void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma) 02062 { 02063 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; 02064 /* Half conversion callback */ 02065 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 02066 hadc->ConvHalfCpltCallback(hadc); 02067 #else 02068 HAL_ADC_ConvHalfCpltCallback(hadc); 02069 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 02070 } 02071 02072 /** 02073 * @brief DMA error callback 02074 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 02075 * the configuration information for the specified DMA module. 02076 * @retval None 02077 */ 02078 static void ADC_DMAError(DMA_HandleTypeDef *hdma) 02079 { 02080 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; 02081 hadc->State= HAL_ADC_STATE_ERROR_DMA; 02082 /* Set ADC error code to DMA error */ 02083 hadc->ErrorCode |= HAL_ADC_ERROR_DMA; 02084 /* Error callback */ 02085 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 02086 hadc->ErrorCallback(hadc); 02087 #else 02088 HAL_ADC_ErrorCallback(hadc); 02089 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 02090 } 02091 02092 /** 02093 * @} 02094 */ 02095 02096 /** 02097 * @} 02098 */ 02099 02100 #endif /* HAL_ADC_MODULE_ENABLED */ 02101 /** 02102 * @} 02103 */ 02104 02105 /** 02106 * @} 02107 */ 02108 02109 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/