STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_adc_ex.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) 00007 * peripheral: 00008 * + Peripheral Control functions 00009 * Other functions (generic functions) are available in file 00010 * "stm32h7xx_hal_adc.c". 00011 * 00012 ****************************************************************************** 00013 * @attention 00014 * 00015 * Copyright (c) 2017 STMicroelectronics. 00016 * All rights reserved. 00017 * 00018 * This software is licensed under terms that can be found in the LICENSE file 00019 * in the root directory of this software component. 00020 * If no LICENSE file comes with this software, it is provided AS-IS. 00021 * 00022 ****************************************************************************** 00023 @verbatim 00024 [..] 00025 (@) Sections "ADC peripheral features" and "How to use this driver" are 00026 available in file of generic functions "stm32h7xx_hal_adc.c". 00027 [..] 00028 @endverbatim 00029 ****************************************************************************** 00030 */ 00031 00032 /* Includes ------------------------------------------------------------------*/ 00033 #include "stm32h7xx_hal.h" 00034 00035 /** @addtogroup STM32H7xx_HAL_Driver 00036 * @{ 00037 */ 00038 00039 /** @defgroup ADCEx ADCEx 00040 * @brief ADC Extended HAL module driver 00041 * @{ 00042 */ 00043 00044 #ifdef HAL_ADC_MODULE_ENABLED 00045 00046 /* Private typedef -----------------------------------------------------------*/ 00047 /* Private define ------------------------------------------------------------*/ 00048 00049 /** @defgroup ADCEx_Private_Constants ADC Extended Private Constants 00050 * @{ 00051 */ 00052 00053 #define ADC_JSQR_FIELDS ((ADC_JSQR_JL | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN |\ 00054 ADC_JSQR_JSQ1 | ADC_JSQR_JSQ2 |\ 00055 ADC_JSQR_JSQ3 | ADC_JSQR_JSQ4 )) /*!< ADC_JSQR fields of parameters that can be updated anytime 00056 once the ADC is enabled */ 00057 00058 /* Fixed timeout value for ADC calibration. */ 00059 /* Fixed timeout value for ADC calibration. */ 00060 /* Values defined to be higher than worst cases: low clock frequency, */ 00061 /* maximum prescalers. */ 00062 /* Ex of profile low frequency : f_ADC at 0.125 Mhz (minimum value */ 00063 /* according to Data sheet), calibration_time MAX = 165010 / f_ADC */ 00064 /* 165010 / 125000 = 1.32s */ 00065 /* At maximum CPU speed (480 MHz), this means */ 00066 /* 1.32 * 480 MHz = 633600000 CPU cycles */ 00067 #define ADC_CALIBRATION_TIMEOUT (633600000U) /*!< ADC calibration time-out value */ 00068 00069 00070 /** 00071 * @} 00072 */ 00073 00074 /* Private macro -------------------------------------------------------------*/ 00075 /* Private variables ---------------------------------------------------------*/ 00076 /* Private function prototypes -----------------------------------------------*/ 00077 /* Exported functions --------------------------------------------------------*/ 00078 00079 /** @defgroup ADCEx_Exported_Functions ADC Extended Exported Functions 00080 * @{ 00081 */ 00082 00083 /** @defgroup ADCEx_Exported_Functions_Group1 Extended Input and Output operation functions 00084 * @brief Extended IO operation functions 00085 * 00086 @verbatim 00087 =============================================================================== 00088 ##### IO operation functions ##### 00089 =============================================================================== 00090 [..] This section provides functions allowing to: 00091 00092 (+) Perform the ADC self-calibration for single or differential ending. 00093 (+) Get calibration factors for single or differential ending. 00094 (+) Set calibration factors for single or differential ending. 00095 00096 (+) Start conversion of ADC group injected. 00097 (+) Stop conversion of ADC group injected. 00098 (+) Poll for conversion complete on ADC group injected. 00099 (+) Get result of ADC group injected channel conversion. 00100 (+) Start conversion of ADC group injected and enable interruptions. 00101 (+) Stop conversion of ADC group injected and disable interruptions. 00102 00103 (+) When multimode feature is available, start multimode and enable DMA transfer. 00104 (+) Stop multimode and disable ADC DMA transfer. 00105 (+) Get result of multimode conversion. 00106 00107 @endverbatim 00108 * @{ 00109 */ 00110 00111 /** 00112 * @brief Perform an ADC automatic self-calibration 00113 * Calibration prerequisite: ADC must be disabled (execute this 00114 * function before HAL_ADC_Start() or after HAL_ADC_Stop() ). 00115 * @param hadc ADC handle 00116 * @param CalibrationMode Selection of calibration offset or 00117 * linear calibration offset. 00118 * @arg ADC_CALIB_OFFSET Channel in mode calibration offset 00119 * @arg ADC_CALIB_OFFSET_LINEARITY Channel in mode linear calibration offset 00120 * @param SingleDiff Selection of single-ended or differential input 00121 * This parameter can be one of the following values: 00122 * @arg @ref ADC_SINGLE_ENDED Channel in mode input single ended 00123 * @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended 00124 * @retval HAL status 00125 */ 00126 HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t CalibrationMode, uint32_t SingleDiff) 00127 { 00128 HAL_StatusTypeDef tmp_hal_status; 00129 __IO uint32_t wait_loop_index = 0UL; 00130 00131 /* Check the parameters */ 00132 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00133 assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff)); 00134 00135 /* Process locked */ 00136 __HAL_LOCK(hadc); 00137 00138 /* Calibration prerequisite: ADC must be disabled. */ 00139 00140 /* Disable the ADC (if not already disabled) */ 00141 tmp_hal_status = ADC_Disable(hadc); 00142 00143 /* Check if ADC is effectively disabled */ 00144 if (tmp_hal_status == HAL_OK) 00145 { 00146 /* Set ADC state */ 00147 ADC_STATE_CLR_SET(hadc->State, 00148 HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, 00149 HAL_ADC_STATE_BUSY_INTERNAL); 00150 00151 /* Start ADC calibration in mode single-ended or differential */ 00152 LL_ADC_StartCalibration(hadc->Instance, CalibrationMode, SingleDiff); 00153 00154 /* Wait for calibration completion */ 00155 while (LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL) 00156 { 00157 wait_loop_index++; 00158 if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT) 00159 { 00160 /* Update ADC state machine to error */ 00161 ADC_STATE_CLR_SET(hadc->State, 00162 HAL_ADC_STATE_BUSY_INTERNAL, 00163 HAL_ADC_STATE_ERROR_INTERNAL); 00164 00165 /* Process unlocked */ 00166 __HAL_UNLOCK(hadc); 00167 00168 return HAL_ERROR; 00169 } 00170 } 00171 00172 /* Set ADC state */ 00173 ADC_STATE_CLR_SET(hadc->State, 00174 HAL_ADC_STATE_BUSY_INTERNAL, 00175 HAL_ADC_STATE_READY); 00176 } 00177 else 00178 { 00179 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); 00180 00181 /* Note: No need to update variable "tmp_hal_status" here: already set */ 00182 /* to state "HAL_ERROR" by function disabling the ADC. */ 00183 } 00184 00185 /* Process unlocked */ 00186 __HAL_UNLOCK(hadc); 00187 00188 /* Return function status */ 00189 return tmp_hal_status; 00190 } 00191 00192 /** 00193 * @brief Get the calibration factor. 00194 * @param hadc ADC handle. 00195 * @param SingleDiff This parameter can be only: 00196 * @arg @ref ADC_SINGLE_ENDED Channel in mode input single ended 00197 * @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended 00198 * @retval Calibration value. 00199 */ 00200 uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff) 00201 { 00202 /* Check the parameters */ 00203 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00204 assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff)); 00205 00206 /* Return the selected ADC calibration value */ 00207 return LL_ADC_GetCalibrationOffsetFactor(hadc->Instance, SingleDiff); 00208 } 00209 00210 /** 00211 * @brief Get the calibration factor from automatic conversion result 00212 * @param hadc ADC handle 00213 * @param LinearCalib_Buffer: Linear calibration factor 00214 * @retval HAL state 00215 */ 00216 HAL_StatusTypeDef HAL_ADCEx_LinearCalibration_GetValue(ADC_HandleTypeDef *hadc, uint32_t *LinearCalib_Buffer) 00217 { 00218 uint32_t cnt; 00219 HAL_StatusTypeDef tmp_hal_status = HAL_OK; 00220 uint32_t temp_REG_IsConversionOngoing = 0UL; 00221 00222 /* Check the parameters */ 00223 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00224 00225 /* Enable the ADC ADEN = 1 to be able to read the linear calibration factor */ 00226 if (LL_ADC_IsEnabled(hadc->Instance) == 0UL) 00227 { 00228 tmp_hal_status = ADC_Enable(hadc); 00229 } 00230 00231 if (tmp_hal_status == HAL_OK) 00232 { 00233 if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL) 00234 { 00235 LL_ADC_REG_StopConversion(hadc->Instance); 00236 temp_REG_IsConversionOngoing = 1UL; 00237 } 00238 for (cnt = ADC_LINEAR_CALIB_REG_COUNT; cnt > 0UL; cnt--) 00239 { 00240 LinearCalib_Buffer[cnt - 1U] = LL_ADC_GetCalibrationLinearFactor(hadc->Instance, ADC_CR_LINCALRDYW6 >> (ADC_LINEAR_CALIB_REG_COUNT - cnt)); 00241 } 00242 if (temp_REG_IsConversionOngoing != 0UL) 00243 { 00244 LL_ADC_REG_StartConversion(hadc->Instance); 00245 } 00246 } 00247 00248 return tmp_hal_status; 00249 } 00250 00251 /** 00252 * @brief Set the calibration factor to overwrite automatic conversion result. 00253 * ADC must be enabled and no conversion is ongoing. 00254 * @param hadc ADC handle 00255 * @param SingleDiff This parameter can be only: 00256 * @arg @ref ADC_SINGLE_ENDED Channel in mode input single ended 00257 * @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended 00258 * @param CalibrationFactor Calibration factor (coded on 7 bits maximum) 00259 * @retval HAL state 00260 */ 00261 HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff, uint32_t CalibrationFactor) 00262 { 00263 HAL_StatusTypeDef tmp_hal_status = HAL_OK; 00264 uint32_t tmp_adc_is_conversion_on_going_regular; 00265 uint32_t tmp_adc_is_conversion_on_going_injected; 00266 00267 /* Check the parameters */ 00268 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00269 assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff)); 00270 assert_param(IS_ADC_CALFACT(CalibrationFactor)); 00271 00272 /* Process locked */ 00273 __HAL_LOCK(hadc); 00274 00275 /* Verification of hardware constraints before modifying the calibration */ 00276 /* factors register: ADC must be enabled, no conversion on going. */ 00277 tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance); 00278 tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance); 00279 00280 if ((LL_ADC_IsEnabled(hadc->Instance) != 0UL) 00281 && (tmp_adc_is_conversion_on_going_regular == 0UL) 00282 && (tmp_adc_is_conversion_on_going_injected == 0UL) 00283 ) 00284 { 00285 /* Set the selected ADC calibration value */ 00286 LL_ADC_SetCalibrationOffsetFactor(hadc->Instance, SingleDiff, CalibrationFactor); 00287 } 00288 else 00289 { 00290 /* Update ADC state machine */ 00291 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 00292 /* Update ADC error code */ 00293 SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); 00294 00295 /* Update ADC state machine to error */ 00296 tmp_hal_status = HAL_ERROR; 00297 } 00298 00299 /* Process unlocked */ 00300 __HAL_UNLOCK(hadc); 00301 00302 /* Return function status */ 00303 return tmp_hal_status; 00304 } 00305 00306 /** 00307 * @brief Set the linear calibration factor 00308 * @param hadc ADC handle 00309 * @param LinearCalib_Buffer: Linear calibration factor 00310 * @retval HAL state 00311 */ 00312 HAL_StatusTypeDef HAL_ADCEx_LinearCalibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t *LinearCalib_Buffer) 00313 { 00314 uint32_t cnt; 00315 __IO uint32_t wait_loop_index = 0; 00316 uint32_t temp_REG_IsConversionOngoing = 0UL; 00317 00318 /* Check the parameters */ 00319 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00320 00321 /* - Exit from deep-power-down mode and ADC voltage regulator enable */ 00322 /* Exit deep power down mode if still in that state */ 00323 if (HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_DEEPPWD)) 00324 { 00325 /* Exit deep power down mode */ 00326 CLEAR_BIT(hadc->Instance->CR, ADC_CR_DEEPPWD); 00327 00328 /* System was in deep power down mode, calibration must 00329 be relaunched or a previously saved calibration factor 00330 re-applied once the ADC voltage regulator is enabled */ 00331 } 00332 00333 00334 if (HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADVREGEN)) 00335 { 00336 /* Enable ADC internal voltage regulator */ 00337 SET_BIT(hadc->Instance->CR, ADC_CR_ADVREGEN); 00338 /* Delay for ADC stabilization time */ 00339 /* Wait loop initialization and execution */ 00340 /* Note: Variable divided by 2 to compensate partially */ 00341 /* CPU processing cycles. */ 00342 wait_loop_index = ((ADC_STAB_DELAY_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL)); 00343 while (wait_loop_index != 0UL) 00344 { 00345 wait_loop_index--; 00346 } 00347 } 00348 00349 00350 /* Verification that ADC voltage regulator is correctly enabled, whether */ 00351 /* or not ADC is coming from state reset (if any potential problem of */ 00352 /* clocking, voltage regulator would not be enabled). */ 00353 if (HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADVREGEN)) 00354 { 00355 /* Update ADC state machine to error */ 00356 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); 00357 00358 /* Set ADC error code to ADC peripheral internal error */ 00359 SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); 00360 00361 return HAL_ERROR; 00362 } 00363 /* Enable the ADC peripheral */ 00364 if (LL_ADC_IsEnabled(hadc->Instance) == 0UL) /* Enable the ADC if it is disabled */ 00365 { 00366 if (ADC_Enable(hadc) != HAL_OK) 00367 { 00368 return HAL_ERROR; 00369 } 00370 else 00371 { 00372 for (cnt = ADC_LINEAR_CALIB_REG_COUNT; cnt > 0UL ; cnt--) 00373 { 00374 LL_ADC_SetCalibrationLinearFactor(hadc->Instance, ADC_CR_LINCALRDYW6 >> (ADC_LINEAR_CALIB_REG_COUNT - cnt), LinearCalib_Buffer[cnt - 1U]); 00375 } 00376 (void)ADC_Disable(hadc); 00377 } 00378 } 00379 else /* ADC is already enabled, so no need to enable it but need to stop conversion */ 00380 { 00381 if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL) 00382 { 00383 LL_ADC_REG_StopConversion(hadc->Instance); 00384 temp_REG_IsConversionOngoing = 1UL; 00385 } 00386 for (cnt = ADC_LINEAR_CALIB_REG_COUNT; cnt > 0UL ; cnt--) 00387 { 00388 LL_ADC_SetCalibrationLinearFactor(hadc->Instance, ADC_CR_LINCALRDYW6 >> (ADC_LINEAR_CALIB_REG_COUNT - cnt), LinearCalib_Buffer[cnt - 1U]); 00389 } 00390 if (temp_REG_IsConversionOngoing != 0UL) 00391 { 00392 LL_ADC_REG_StartConversion(hadc->Instance); 00393 } 00394 } 00395 return HAL_OK; 00396 } 00397 00398 /** 00399 * @brief Load the calibration factor from engi bytes 00400 * @param hadc ADC handle 00401 * @retval HAL state 00402 */ 00403 HAL_StatusTypeDef HAL_ADCEx_LinearCalibration_FactorLoad(ADC_HandleTypeDef *hadc) 00404 { 00405 HAL_StatusTypeDef tmp_hal_status = HAL_OK; 00406 uint32_t cnt, FactorOffset; 00407 uint32_t LinearCalib_Buffer[ADC_LINEAR_CALIB_REG_COUNT]; 00408 00409 /* Linearity calibration is retrieved from engi bytes 00410 read values from registers and put them to the CALFACT2 register */ 00411 /* If needed linearity calibration can be done in runtime using 00412 LL_ADC_GetCalibrationLinearFactor() */ 00413 if (hadc->Instance == ADC1) 00414 { 00415 FactorOffset = 0UL; 00416 } 00417 else if (hadc->Instance == ADC2) 00418 { 00419 FactorOffset = 8UL; 00420 } 00421 else /*Case ADC3*/ 00422 { 00423 FactorOffset = 16UL; 00424 } 00425 00426 for (cnt = 0UL; cnt < ADC_LINEAR_CALIB_REG_COUNT; cnt++) 00427 { 00428 LinearCalib_Buffer[cnt] = *(uint32_t *)(ADC_LINEAR_CALIB_REG_1_ADDR + FactorOffset + cnt); 00429 } 00430 if (HAL_ADCEx_LinearCalibration_SetValue(hadc, (uint32_t *)LinearCalib_Buffer) != HAL_OK) 00431 { 00432 tmp_hal_status = HAL_ERROR; 00433 } 00434 00435 return tmp_hal_status; 00436 } 00437 00438 /** 00439 * @brief Enable ADC, start conversion of injected group. 00440 * @note Interruptions enabled in this function: None. 00441 * @note Case of multimode enabled when multimode feature is available: 00442 * HAL_ADCEx_InjectedStart() API must be called for ADC slave first, 00443 * then for ADC master. 00444 * For ADC slave, ADC is enabled only (conversion is not started). 00445 * For ADC master, ADC is enabled and multimode conversion is started. 00446 * @param hadc ADC handle. 00447 * @retval HAL status 00448 */ 00449 HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef *hadc) 00450 { 00451 HAL_StatusTypeDef tmp_hal_status; 00452 uint32_t tmp_config_injected_queue; 00453 uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance)); 00454 00455 /* Check the parameters */ 00456 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00457 00458 if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL) 00459 { 00460 return HAL_BUSY; 00461 } 00462 else 00463 { 00464 /* In case of software trigger detection enabled, JQDIS must be set 00465 (which can be done only if ADSTART and JADSTART are both cleared). 00466 If JQDIS is not set at that point, returns an error 00467 - since software trigger detection is disabled. User needs to 00468 resort to HAL_ADCEx_DisableInjectedQueue() API to set JQDIS. 00469 - or (if JQDIS is intentionally reset) since JEXTEN = 0 which means 00470 the queue is empty */ 00471 tmp_config_injected_queue = READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS); 00472 00473 if ((READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == 0UL) 00474 && (tmp_config_injected_queue == 0UL) 00475 ) 00476 { 00477 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 00478 return HAL_ERROR; 00479 } 00480 00481 /* Process locked */ 00482 __HAL_LOCK(hadc); 00483 00484 /* Enable the ADC peripheral */ 00485 tmp_hal_status = ADC_Enable(hadc); 00486 00487 /* Start conversion if ADC is effectively enabled */ 00488 if (tmp_hal_status == HAL_OK) 00489 { 00490 /* Check if a regular conversion is ongoing */ 00491 if ((hadc->State & HAL_ADC_STATE_REG_BUSY) != 0UL) 00492 { 00493 /* Reset ADC error code field related to injected conversions only */ 00494 CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF); 00495 } 00496 else 00497 { 00498 /* Set ADC error code to none */ 00499 ADC_CLEAR_ERRORCODE(hadc); 00500 } 00501 00502 /* Set ADC state */ 00503 /* - Clear state bitfield related to injected group conversion results */ 00504 /* - Set state bitfield related to injected operation */ 00505 ADC_STATE_CLR_SET(hadc->State, 00506 HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC, 00507 HAL_ADC_STATE_INJ_BUSY); 00508 00509 /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit 00510 - if ADC instance is master or if multimode feature is not available 00511 - if multimode setting is disabled (ADC instance slave in independent mode) */ 00512 if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance) 00513 || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT) 00514 ) 00515 { 00516 CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE); 00517 } 00518 00519 /* Clear ADC group injected group conversion flag */ 00520 /* (To ensure of no unknown state from potential previous ADC operations) */ 00521 __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS)); 00522 00523 /* Process unlocked */ 00524 /* Unlock before starting ADC conversions: in case of potential */ 00525 /* interruption, to let the process to ADC IRQ Handler. */ 00526 __HAL_UNLOCK(hadc); 00527 00528 /* Enable conversion of injected group, if automatic injected conversion */ 00529 /* is disabled. */ 00530 /* If software start has been selected, conversion starts immediately. */ 00531 /* If external trigger has been selected, conversion will start at next */ 00532 /* trigger event. */ 00533 /* Case of multimode enabled (when multimode feature is available): */ 00534 /* if ADC is slave, */ 00535 /* - ADC is enabled only (conversion is not started), */ 00536 /* - if multimode only concerns regular conversion, ADC is enabled */ 00537 /* and conversion is started. */ 00538 /* If ADC is master or independent, */ 00539 /* - ADC is enabled and conversion is started. */ 00540 if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance) 00541 || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT) 00542 || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT) 00543 || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL) 00544 ) 00545 { 00546 /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */ 00547 if (LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT) 00548 { 00549 LL_ADC_INJ_StartConversion(hadc->Instance); 00550 } 00551 } 00552 else 00553 { 00554 /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */ 00555 SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE); 00556 } 00557 00558 } 00559 else 00560 { 00561 /* Process unlocked */ 00562 __HAL_UNLOCK(hadc); 00563 } 00564 00565 /* Return function status */ 00566 return tmp_hal_status; 00567 } 00568 } 00569 00570 /** 00571 * @brief Stop conversion of injected channels. Disable ADC peripheral if 00572 * no regular conversion is on going. 00573 * @note If ADC must be disabled and if conversion is on going on 00574 * regular group, function HAL_ADC_Stop must be used to stop both 00575 * injected and regular groups, and disable the ADC. 00576 * @note If injected group mode auto-injection is enabled, 00577 * function HAL_ADC_Stop must be used. 00578 * @note In case of multimode enabled (when multimode feature is available), 00579 * HAL_ADCEx_InjectedStop() must be called for ADC master first, then for ADC slave. 00580 * For ADC master, conversion is stopped and ADC is disabled. 00581 * For ADC slave, ADC is disabled only (conversion stop of ADC master 00582 * has already stopped conversion of ADC slave). 00583 * @param hadc ADC handle. 00584 * @retval HAL status 00585 */ 00586 HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef *hadc) 00587 { 00588 HAL_StatusTypeDef tmp_hal_status; 00589 00590 /* Check the parameters */ 00591 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00592 00593 /* Process locked */ 00594 __HAL_LOCK(hadc); 00595 00596 /* 1. Stop potential conversion on going on injected group only. */ 00597 tmp_hal_status = ADC_ConversionStop(hadc, ADC_INJECTED_GROUP); 00598 00599 /* Disable ADC peripheral if injected conversions are effectively stopped */ 00600 /* and if no conversion on regular group is on-going */ 00601 if (tmp_hal_status == HAL_OK) 00602 { 00603 if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL) 00604 { 00605 /* 2. Disable the ADC peripheral */ 00606 tmp_hal_status = ADC_Disable(hadc); 00607 00608 /* Check if ADC is effectively disabled */ 00609 if (tmp_hal_status == HAL_OK) 00610 { 00611 /* Set ADC state */ 00612 ADC_STATE_CLR_SET(hadc->State, 00613 HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, 00614 HAL_ADC_STATE_READY); 00615 } 00616 } 00617 /* Conversion on injected group is stopped, but ADC not disabled since */ 00618 /* conversion on regular group is still running. */ 00619 else 00620 { 00621 /* Set ADC state */ 00622 CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY); 00623 } 00624 } 00625 00626 /* Process unlocked */ 00627 __HAL_UNLOCK(hadc); 00628 00629 /* Return function status */ 00630 return tmp_hal_status; 00631 } 00632 00633 /** 00634 * @brief Wait for injected group conversion to be completed. 00635 * @param hadc ADC handle 00636 * @param Timeout Timeout value in millisecond. 00637 * @note Depending on hadc->Init.EOCSelection, JEOS or JEOC is 00638 * checked and cleared depending on AUTDLY bit status. 00639 * @retval HAL status 00640 */ 00641 HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout) 00642 { 00643 uint32_t tickstart; 00644 uint32_t tmp_Flag_End; 00645 uint32_t tmp_adc_inj_is_trigger_source_sw_start; 00646 uint32_t tmp_adc_reg_is_trigger_source_sw_start; 00647 uint32_t tmp_cfgr; 00648 const ADC_TypeDef *tmpADC_Master; 00649 uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance)); 00650 00651 /* Check the parameters */ 00652 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00653 00654 /* If end of sequence selected */ 00655 if (hadc->Init.EOCSelection == ADC_EOC_SEQ_CONV) 00656 { 00657 tmp_Flag_End = ADC_FLAG_JEOS; 00658 } 00659 else /* end of conversion selected */ 00660 { 00661 tmp_Flag_End = ADC_FLAG_JEOC; 00662 } 00663 00664 /* Get timeout */ 00665 tickstart = HAL_GetTick(); 00666 00667 /* Wait until End of Conversion or Sequence flag is raised */ 00668 while ((hadc->Instance->ISR & tmp_Flag_End) == 0UL) 00669 { 00670 /* Check if timeout is disabled (set to infinite wait) */ 00671 if (Timeout != HAL_MAX_DELAY) 00672 { 00673 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL)) 00674 { 00675 if((hadc->Instance->ISR & tmp_Flag_End) == 0UL) 00676 { 00677 /* Update ADC state machine to timeout */ 00678 SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT); 00679 00680 /* Process unlocked */ 00681 __HAL_UNLOCK(hadc); 00682 00683 return HAL_TIMEOUT; 00684 } 00685 } 00686 } 00687 } 00688 00689 /* Retrieve ADC configuration */ 00690 tmp_adc_inj_is_trigger_source_sw_start = LL_ADC_INJ_IsTriggerSourceSWStart(hadc->Instance); 00691 tmp_adc_reg_is_trigger_source_sw_start = LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance); 00692 /* Get relevant register CFGR in ADC instance of ADC master or slave */ 00693 /* in function of multimode state (for devices with multimode */ 00694 /* available). */ 00695 if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance) 00696 || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT) 00697 || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT) 00698 || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL) 00699 ) 00700 { 00701 tmp_cfgr = READ_REG(hadc->Instance->CFGR); 00702 } 00703 else 00704 { 00705 tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance); 00706 tmp_cfgr = READ_REG(tmpADC_Master->CFGR); 00707 } 00708 00709 /* Update ADC state machine */ 00710 SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC); 00711 00712 /* Determine whether any further conversion upcoming on group injected */ 00713 /* by external trigger or by automatic injected conversion */ 00714 /* from group regular. */ 00715 if ((tmp_adc_inj_is_trigger_source_sw_start != 0UL) || 00716 ((READ_BIT(tmp_cfgr, ADC_CFGR_JAUTO) == 0UL) && 00717 ((tmp_adc_reg_is_trigger_source_sw_start != 0UL) && 00718 (READ_BIT(tmp_cfgr, ADC_CFGR_CONT) == 0UL)))) 00719 { 00720 /* Check whether end of sequence is reached */ 00721 if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS)) 00722 { 00723 /* Particular case if injected contexts queue is enabled: */ 00724 /* when the last context has been fully processed, JSQR is reset */ 00725 /* by the hardware. Even if no injected conversion is planned to come */ 00726 /* (queue empty, triggers are ignored), it can start again */ 00727 /* immediately after setting a new context (JADSTART is still set). */ 00728 /* Therefore, state of HAL ADC injected group is kept to busy. */ 00729 if (READ_BIT(tmp_cfgr, ADC_CFGR_JQM) == 0UL) 00730 { 00731 /* Set ADC state */ 00732 CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY); 00733 00734 if ((hadc->State & HAL_ADC_STATE_REG_BUSY) == 0UL) 00735 { 00736 SET_BIT(hadc->State, HAL_ADC_STATE_READY); 00737 } 00738 } 00739 } 00740 } 00741 00742 /* Clear polled flag */ 00743 if (tmp_Flag_End == ADC_FLAG_JEOS) 00744 { 00745 /* Clear end of sequence JEOS flag of injected group if low power feature */ 00746 /* "LowPowerAutoWait " is disabled, to not interfere with this feature. */ 00747 /* For injected groups, no new conversion will start before JEOS is */ 00748 /* cleared. */ 00749 if (READ_BIT(tmp_cfgr, ADC_CFGR_AUTDLY) == 0UL) 00750 { 00751 __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS)); 00752 } 00753 } 00754 else 00755 { 00756 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC); 00757 } 00758 00759 /* Return API HAL status */ 00760 return HAL_OK; 00761 } 00762 00763 /** 00764 * @brief Enable ADC, start conversion of injected group with interruption. 00765 * @note Interruptions enabled in this function according to initialization 00766 * setting : JEOC (end of conversion) or JEOS (end of sequence) 00767 * @note Case of multimode enabled (when multimode feature is enabled): 00768 * HAL_ADCEx_InjectedStart_IT() API must be called for ADC slave first, 00769 * then for ADC master. 00770 * For ADC slave, ADC is enabled only (conversion is not started). 00771 * For ADC master, ADC is enabled and multimode conversion is started. 00772 * @param hadc ADC handle. 00773 * @retval HAL status. 00774 */ 00775 HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef *hadc) 00776 { 00777 HAL_StatusTypeDef tmp_hal_status; 00778 uint32_t tmp_config_injected_queue; 00779 uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance)); 00780 00781 /* Check the parameters */ 00782 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00783 00784 if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL) 00785 { 00786 return HAL_BUSY; 00787 } 00788 else 00789 { 00790 /* In case of software trigger detection enabled, JQDIS must be set 00791 (which can be done only if ADSTART and JADSTART are both cleared). 00792 If JQDIS is not set at that point, returns an error 00793 - since software trigger detection is disabled. User needs to 00794 resort to HAL_ADCEx_DisableInjectedQueue() API to set JQDIS. 00795 - or (if JQDIS is intentionally reset) since JEXTEN = 0 which means 00796 the queue is empty */ 00797 tmp_config_injected_queue = READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS); 00798 00799 if ((READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == 0UL) 00800 && (tmp_config_injected_queue == 0UL) 00801 ) 00802 { 00803 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 00804 return HAL_ERROR; 00805 } 00806 00807 /* Process locked */ 00808 __HAL_LOCK(hadc); 00809 00810 /* Enable the ADC peripheral */ 00811 tmp_hal_status = ADC_Enable(hadc); 00812 00813 /* Start conversion if ADC is effectively enabled */ 00814 if (tmp_hal_status == HAL_OK) 00815 { 00816 /* Check if a regular conversion is ongoing */ 00817 if ((hadc->State & HAL_ADC_STATE_REG_BUSY) != 0UL) 00818 { 00819 /* Reset ADC error code field related to injected conversions only */ 00820 CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF); 00821 } 00822 else 00823 { 00824 /* Set ADC error code to none */ 00825 ADC_CLEAR_ERRORCODE(hadc); 00826 } 00827 00828 /* Set ADC state */ 00829 /* - Clear state bitfield related to injected group conversion results */ 00830 /* - Set state bitfield related to injected operation */ 00831 ADC_STATE_CLR_SET(hadc->State, 00832 HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC, 00833 HAL_ADC_STATE_INJ_BUSY); 00834 00835 /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit 00836 - if ADC instance is master or if multimode feature is not available 00837 - if multimode setting is disabled (ADC instance slave in independent mode) */ 00838 if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance) 00839 || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT) 00840 ) 00841 { 00842 CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE); 00843 } 00844 00845 /* Clear ADC group injected group conversion flag */ 00846 /* (To ensure of no unknown state from potential previous ADC operations) */ 00847 __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS)); 00848 00849 /* Process unlocked */ 00850 /* Unlock before starting ADC conversions: in case of potential */ 00851 /* interruption, to let the process to ADC IRQ Handler. */ 00852 __HAL_UNLOCK(hadc); 00853 00854 /* Enable ADC Injected context queue overflow interrupt if this feature */ 00855 /* is enabled. */ 00856 if ((hadc->Instance->CFGR & ADC_CFGR_JQM) != 0UL) 00857 { 00858 __HAL_ADC_ENABLE_IT(hadc, ADC_FLAG_JQOVF); 00859 } 00860 00861 /* Enable ADC end of conversion interrupt */ 00862 switch (hadc->Init.EOCSelection) 00863 { 00864 case ADC_EOC_SEQ_CONV: 00865 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC); 00866 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOS); 00867 break; 00868 /* case ADC_EOC_SINGLE_CONV */ 00869 default: 00870 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOS); 00871 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC); 00872 break; 00873 } 00874 00875 /* Enable conversion of injected group, if automatic injected conversion */ 00876 /* is disabled. */ 00877 /* If software start has been selected, conversion starts immediately. */ 00878 /* If external trigger has been selected, conversion will start at next */ 00879 /* trigger event. */ 00880 /* Case of multimode enabled (when multimode feature is available): */ 00881 /* if ADC is slave, */ 00882 /* - ADC is enabled only (conversion is not started), */ 00883 /* - if multimode only concerns regular conversion, ADC is enabled */ 00884 /* and conversion is started. */ 00885 /* If ADC is master or independent, */ 00886 /* - ADC is enabled and conversion is started. */ 00887 if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance) 00888 || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT) 00889 || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT) 00890 || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL) 00891 ) 00892 { 00893 /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */ 00894 if (LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT) 00895 { 00896 LL_ADC_INJ_StartConversion(hadc->Instance); 00897 } 00898 } 00899 else 00900 { 00901 /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */ 00902 SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE); 00903 } 00904 00905 } 00906 else 00907 { 00908 /* Process unlocked */ 00909 __HAL_UNLOCK(hadc); 00910 } 00911 00912 /* Return function status */ 00913 return tmp_hal_status; 00914 } 00915 } 00916 00917 /** 00918 * @brief Stop conversion of injected channels, disable interruption of 00919 * end-of-conversion. Disable ADC peripheral if no regular conversion 00920 * is on going. 00921 * @note If ADC must be disabled and if conversion is on going on 00922 * regular group, function HAL_ADC_Stop must be used to stop both 00923 * injected and regular groups, and disable the ADC. 00924 * @note If injected group mode auto-injection is enabled, 00925 * function HAL_ADC_Stop must be used. 00926 * @note Case of multimode enabled (when multimode feature is available): 00927 * HAL_ADCEx_InjectedStop_IT() API must be called for ADC master first, 00928 * then for ADC slave. 00929 * For ADC master, conversion is stopped and ADC is disabled. 00930 * For ADC slave, ADC is disabled only (conversion stop of ADC master 00931 * has already stopped conversion of ADC slave). 00932 * @note In case of auto-injection mode, HAL_ADC_Stop() must be used. 00933 * @param hadc ADC handle 00934 * @retval HAL status 00935 */ 00936 HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef *hadc) 00937 { 00938 HAL_StatusTypeDef tmp_hal_status; 00939 00940 /* Check the parameters */ 00941 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 00942 00943 /* Process locked */ 00944 __HAL_LOCK(hadc); 00945 00946 /* 1. Stop potential conversion on going on injected group only. */ 00947 tmp_hal_status = ADC_ConversionStop(hadc, ADC_INJECTED_GROUP); 00948 00949 /* Disable ADC peripheral if injected conversions are effectively stopped */ 00950 /* and if no conversion on the other group (regular group) is intended to */ 00951 /* continue. */ 00952 if (tmp_hal_status == HAL_OK) 00953 { 00954 /* Disable ADC end of conversion interrupt for injected channels */ 00955 __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_JEOC | ADC_IT_JEOS | ADC_FLAG_JQOVF)); 00956 00957 if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL) 00958 { 00959 /* 2. Disable the ADC peripheral */ 00960 tmp_hal_status = ADC_Disable(hadc); 00961 00962 /* Check if ADC is effectively disabled */ 00963 if (tmp_hal_status == HAL_OK) 00964 { 00965 /* Set ADC state */ 00966 ADC_STATE_CLR_SET(hadc->State, 00967 HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, 00968 HAL_ADC_STATE_READY); 00969 } 00970 } 00971 /* Conversion on injected group is stopped, but ADC not disabled since */ 00972 /* conversion on regular group is still running. */ 00973 else 00974 { 00975 /* Set ADC state */ 00976 CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY); 00977 } 00978 } 00979 00980 /* Process unlocked */ 00981 __HAL_UNLOCK(hadc); 00982 00983 /* Return function status */ 00984 return tmp_hal_status; 00985 } 00986 00987 /** 00988 * @brief Enable ADC, start MultiMode conversion and transfer regular results through DMA. 00989 * @note Multimode must have been previously configured using 00990 * HAL_ADCEx_MultiModeConfigChannel() function. 00991 * Interruptions enabled in this function: 00992 * overrun, DMA half transfer, DMA transfer complete. 00993 * Each of these interruptions has its dedicated callback function. 00994 * @note State field of Slave ADC handle is not updated in this configuration: 00995 * user should not rely on it for information related to Slave regular 00996 * conversions. 00997 * @param hadc ADC handle of ADC master (handle of ADC slave must not be used) 00998 * @param pData Destination Buffer address. 00999 * @param Length Length of data to be transferred from ADC peripheral to memory (in bytes). 01000 * @retval HAL status 01001 */ 01002 HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length) 01003 { 01004 HAL_StatusTypeDef tmp_hal_status; 01005 ADC_HandleTypeDef tmphadcSlave; 01006 ADC_Common_TypeDef *tmpADC_Common; 01007 01008 /* Check the parameters */ 01009 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance)); 01010 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode)); 01011 assert_param(IS_ADC_EXTTRIG_EDGE(hadc->Init.ExternalTrigConvEdge)); 01012 01013 if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL) 01014 { 01015 return HAL_BUSY; 01016 } 01017 else 01018 { 01019 /* Process locked */ 01020 __HAL_LOCK(hadc); 01021 01022 tmphadcSlave.State = HAL_ADC_STATE_RESET; 01023 tmphadcSlave.ErrorCode = HAL_ADC_ERROR_NONE; 01024 /* Set a temporary handle of the ADC slave associated to the ADC master */ 01025 ADC_MULTI_SLAVE(hadc, &tmphadcSlave); 01026 01027 if (tmphadcSlave.Instance == NULL) 01028 { 01029 /* Set ADC state */ 01030 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 01031 01032 /* Process unlocked */ 01033 __HAL_UNLOCK(hadc); 01034 01035 return HAL_ERROR; 01036 } 01037 01038 /* Enable the ADC peripherals: master and slave (in case if not already */ 01039 /* enabled previously) */ 01040 tmp_hal_status = ADC_Enable(hadc); 01041 if (tmp_hal_status == HAL_OK) 01042 { 01043 tmp_hal_status = ADC_Enable(&tmphadcSlave); 01044 } 01045 01046 /* Start multimode conversion of ADCs pair */ 01047 if (tmp_hal_status == HAL_OK) 01048 { 01049 /* Set ADC state */ 01050 ADC_STATE_CLR_SET(hadc->State, 01051 (HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP), 01052 HAL_ADC_STATE_REG_BUSY); 01053 01054 /* Set ADC error code to none */ 01055 ADC_CLEAR_ERRORCODE(hadc); 01056 01057 /* Set the DMA transfer complete callback */ 01058 hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt; 01059 01060 /* Set the DMA half transfer complete callback */ 01061 hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt; 01062 01063 /* Set the DMA error callback */ 01064 hadc->DMA_Handle->XferErrorCallback = ADC_DMAError ; 01065 01066 /* Pointer to the common control register */ 01067 tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance); 01068 01069 /* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC */ 01070 /* start (in case of SW start): */ 01071 01072 /* Clear regular group conversion flag and overrun flag */ 01073 /* (To ensure of no unknown state from potential previous ADC operations) */ 01074 __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS | ADC_FLAG_OVR)); 01075 01076 /* Process unlocked */ 01077 /* Unlock before starting ADC conversions: in case of potential */ 01078 /* interruption, to let the process to ADC IRQ Handler. */ 01079 __HAL_UNLOCK(hadc); 01080 01081 /* Enable ADC overrun interrupt */ 01082 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR); 01083 01084 /* Start the DMA channel */ 01085 tmp_hal_status = HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&tmpADC_Common->CDR, (uint32_t)pData, Length); 01086 01087 /* Enable conversion of regular group. */ 01088 /* If software start has been selected, conversion starts immediately. */ 01089 /* If external trigger has been selected, conversion will start at next */ 01090 /* trigger event. */ 01091 /* Start ADC group regular conversion */ 01092 LL_ADC_REG_StartConversion(hadc->Instance); 01093 } 01094 else 01095 { 01096 /* Process unlocked */ 01097 __HAL_UNLOCK(hadc); 01098 } 01099 01100 /* Return function status */ 01101 return tmp_hal_status; 01102 } 01103 } 01104 01105 /** 01106 * @brief Stop multimode ADC conversion, disable ADC DMA transfer, disable ADC peripheral. 01107 * @note Multimode is kept enabled after this function. MultiMode DMA bits 01108 * (MDMA and DMACFG bits of common CCR register) are maintained. To disable 01109 * Multimode (set with HAL_ADCEx_MultiModeConfigChannel()), ADC must be 01110 * reinitialized using HAL_ADC_Init() or HAL_ADC_DeInit(), or the user can 01111 * resort to HAL_ADCEx_DisableMultiMode() API. 01112 * @note In case of DMA configured in circular mode, function 01113 * HAL_ADC_Stop_DMA() must be called after this function with handle of 01114 * ADC slave, to properly disable the DMA channel. 01115 * @param hadc ADC handle of ADC master (handle of ADC slave must not be used) 01116 * @retval HAL status 01117 */ 01118 HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc) 01119 { 01120 HAL_StatusTypeDef tmp_hal_status; 01121 uint32_t tickstart; 01122 ADC_HandleTypeDef tmphadcSlave; 01123 uint32_t tmphadcSlave_conversion_on_going; 01124 HAL_StatusTypeDef tmphadcSlave_disable_status; 01125 01126 /* Check the parameters */ 01127 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance)); 01128 01129 /* Process locked */ 01130 __HAL_LOCK(hadc); 01131 01132 01133 /* 1. Stop potential multimode conversion on going, on regular and injected groups */ 01134 tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_INJECTED_GROUP); 01135 01136 /* Disable ADC peripheral if conversions are effectively stopped */ 01137 if (tmp_hal_status == HAL_OK) 01138 { 01139 tmphadcSlave.State = HAL_ADC_STATE_RESET; 01140 tmphadcSlave.ErrorCode = HAL_ADC_ERROR_NONE; 01141 01142 /* Set a temporary handle of the ADC slave associated to the ADC master */ 01143 ADC_MULTI_SLAVE(hadc, &tmphadcSlave); 01144 01145 if (tmphadcSlave.Instance == NULL) 01146 { 01147 /* Update ADC state machine to error */ 01148 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 01149 01150 /* Process unlocked */ 01151 __HAL_UNLOCK(hadc); 01152 01153 return HAL_ERROR; 01154 } 01155 01156 /* Procedure to disable the ADC peripheral: wait for conversions */ 01157 /* effectively stopped (ADC master and ADC slave), then disable ADC */ 01158 01159 /* 1. Wait for ADC conversion completion for ADC master and ADC slave */ 01160 tickstart = HAL_GetTick(); 01161 01162 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance); 01163 while ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL) 01164 || (tmphadcSlave_conversion_on_going == 1UL) 01165 ) 01166 { 01167 if ((HAL_GetTick() - tickstart) > ADC_STOP_CONVERSION_TIMEOUT) 01168 { 01169 /* New check to avoid false timeout detection in case of preemption */ 01170 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance); 01171 01172 if((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL) 01173 || (tmphadcSlave_conversion_on_going == 1UL) 01174 ) 01175 { 01176 /* Update ADC state machine to error */ 01177 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); 01178 01179 /* Process unlocked */ 01180 __HAL_UNLOCK(hadc); 01181 01182 return HAL_ERROR; 01183 } 01184 } 01185 01186 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance); 01187 } 01188 01189 /* Disable the DMA channel (in case of DMA in circular mode or stop */ 01190 /* while DMA transfer is on going) */ 01191 /* Note: DMA channel of ADC slave should be stopped after this function */ 01192 /* with HAL_ADC_Stop_DMA() API. */ 01193 tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); 01194 01195 /* Check if DMA channel effectively disabled */ 01196 if (tmp_hal_status == HAL_ERROR) 01197 { 01198 /* Update ADC state machine to error */ 01199 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); 01200 } 01201 01202 /* Disable ADC overrun interrupt */ 01203 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); 01204 01205 /* 2. Disable the ADC peripherals: master and slave */ 01206 /* Update "tmp_hal_status" only if DMA channel disabling passed, to keep in */ 01207 /* memory a potential failing status. */ 01208 if (tmp_hal_status == HAL_OK) 01209 { 01210 tmphadcSlave_disable_status = ADC_Disable(&tmphadcSlave); 01211 if ((ADC_Disable(hadc) == HAL_OK) && 01212 (tmphadcSlave_disable_status == HAL_OK)) 01213 { 01214 tmp_hal_status = HAL_OK; 01215 } 01216 } 01217 else 01218 { 01219 /* In case of error, attempt to disable ADC master and slave without status assert */ 01220 (void) ADC_Disable(hadc); 01221 (void) ADC_Disable(&tmphadcSlave); 01222 } 01223 01224 /* Set ADC state (ADC master) */ 01225 ADC_STATE_CLR_SET(hadc->State, 01226 HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, 01227 HAL_ADC_STATE_READY); 01228 } 01229 01230 /* Process unlocked */ 01231 __HAL_UNLOCK(hadc); 01232 01233 /* Return function status */ 01234 return tmp_hal_status; 01235 } 01236 01237 /** 01238 * @brief Return the last ADC Master and Slave regular conversions results when in multimode configuration. 01239 * @param hadc ADC handle of ADC Master (handle of ADC Slave must not be used) 01240 * @retval The converted data values. 01241 */ 01242 uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef *hadc) 01243 { 01244 const ADC_Common_TypeDef *tmpADC_Common; 01245 01246 /* Check the parameters */ 01247 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance)); 01248 01249 /* Prevent unused argument(s) compilation warning if no assert_param check */ 01250 /* and possible no usage in __LL_ADC_COMMON_INSTANCE() below */ 01251 UNUSED(hadc); 01252 01253 /* Pointer to the common control register */ 01254 tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance); 01255 01256 /* Return the multi mode conversion value */ 01257 return tmpADC_Common->CDR; 01258 } 01259 01260 /** 01261 * @brief Get ADC injected group conversion result. 01262 * @note Reading register JDRx automatically clears ADC flag JEOC 01263 * (ADC group injected end of unitary conversion). 01264 * @note This function does not clear ADC flag JEOS 01265 * (ADC group injected end of sequence conversion) 01266 * Occurrence of flag JEOS rising: 01267 * - If sequencer is composed of 1 rank, flag JEOS is equivalent 01268 * to flag JEOC. 01269 * - If sequencer is composed of several ranks, during the scan 01270 * sequence flag JEOC only is raised, at the end of the scan sequence 01271 * both flags JEOC and EOS are raised. 01272 * Flag JEOS must not be cleared by this function because 01273 * it would not be compliant with low power features 01274 * (feature low power auto-wait, not available on all STM32 families). 01275 * To clear this flag, either use function: 01276 * in programming model IT: @ref HAL_ADC_IRQHandler(), in programming 01277 * model polling: @ref HAL_ADCEx_InjectedPollForConversion() 01278 * or @ref __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_JEOS). 01279 * @param hadc ADC handle 01280 * @param InjectedRank the converted ADC injected rank. 01281 * This parameter can be one of the following values: 01282 * @arg @ref ADC_INJECTED_RANK_1 ADC group injected rank 1 01283 * @arg @ref ADC_INJECTED_RANK_2 ADC group injected rank 2 01284 * @arg @ref ADC_INJECTED_RANK_3 ADC group injected rank 3 01285 * @arg @ref ADC_INJECTED_RANK_4 ADC group injected rank 4 01286 * @retval ADC group injected conversion data 01287 */ 01288 uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef *hadc, uint32_t InjectedRank) 01289 { 01290 uint32_t tmp_jdr; 01291 01292 /* Check the parameters */ 01293 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 01294 assert_param(IS_ADC_INJECTED_RANK(InjectedRank)); 01295 01296 /* Get ADC converted value */ 01297 switch (InjectedRank) 01298 { 01299 case ADC_INJECTED_RANK_4: 01300 tmp_jdr = hadc->Instance->JDR4; 01301 break; 01302 case ADC_INJECTED_RANK_3: 01303 tmp_jdr = hadc->Instance->JDR3; 01304 break; 01305 case ADC_INJECTED_RANK_2: 01306 tmp_jdr = hadc->Instance->JDR2; 01307 break; 01308 case ADC_INJECTED_RANK_1: 01309 default: 01310 tmp_jdr = hadc->Instance->JDR1; 01311 break; 01312 } 01313 01314 /* Return ADC converted value */ 01315 return tmp_jdr; 01316 } 01317 01318 /** 01319 * @brief Injected conversion complete callback in non-blocking mode. 01320 * @param hadc ADC handle 01321 * @retval None 01322 */ 01323 __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc) 01324 { 01325 /* Prevent unused argument(s) compilation warning */ 01326 UNUSED(hadc); 01327 01328 /* NOTE : This function should not be modified. When the callback is needed, 01329 function HAL_ADCEx_InjectedConvCpltCallback must be implemented in the user file. 01330 */ 01331 } 01332 01333 /** 01334 * @brief Injected context queue overflow callback. 01335 * @note This callback is called if injected context queue is enabled 01336 (parameter "QueueInjectedContext" in injected channel configuration) 01337 and if a new injected context is set when queue is full (maximum 2 01338 contexts). 01339 * @param hadc ADC handle 01340 * @retval None 01341 */ 01342 __weak void HAL_ADCEx_InjectedQueueOverflowCallback(ADC_HandleTypeDef *hadc) 01343 { 01344 /* Prevent unused argument(s) compilation warning */ 01345 UNUSED(hadc); 01346 01347 /* NOTE : This function should not be modified. When the callback is needed, 01348 function HAL_ADCEx_InjectedQueueOverflowCallback must be implemented in the user file. 01349 */ 01350 } 01351 01352 /** 01353 * @brief Analog watchdog 2 callback in non-blocking mode. 01354 * @param hadc ADC handle 01355 * @retval None 01356 */ 01357 __weak void HAL_ADCEx_LevelOutOfWindow2Callback(ADC_HandleTypeDef *hadc) 01358 { 01359 /* Prevent unused argument(s) compilation warning */ 01360 UNUSED(hadc); 01361 01362 /* NOTE : This function should not be modified. When the callback is needed, 01363 function HAL_ADCEx_LevelOutOfWindow2Callback must be implemented in the user file. 01364 */ 01365 } 01366 01367 /** 01368 * @brief Analog watchdog 3 callback in non-blocking mode. 01369 * @param hadc ADC handle 01370 * @retval None 01371 */ 01372 __weak void HAL_ADCEx_LevelOutOfWindow3Callback(ADC_HandleTypeDef *hadc) 01373 { 01374 /* Prevent unused argument(s) compilation warning */ 01375 UNUSED(hadc); 01376 01377 /* NOTE : This function should not be modified. When the callback is needed, 01378 function HAL_ADCEx_LevelOutOfWindow3Callback must be implemented in the user file. 01379 */ 01380 } 01381 01382 01383 /** 01384 * @brief End Of Sampling callback in non-blocking mode. 01385 * @param hadc ADC handle 01386 * @retval None 01387 */ 01388 __weak void HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef *hadc) 01389 { 01390 /* Prevent unused argument(s) compilation warning */ 01391 UNUSED(hadc); 01392 01393 /* NOTE : This function should not be modified. When the callback is needed, 01394 function HAL_ADCEx_EndOfSamplingCallback must be implemented in the user file. 01395 */ 01396 } 01397 01398 /** 01399 * @brief Stop ADC conversion of regular group (and injected channels in 01400 * case of auto_injection mode), disable ADC peripheral if no 01401 * conversion is on going on injected group. 01402 * @param hadc ADC handle 01403 * @retval HAL status. 01404 */ 01405 HAL_StatusTypeDef HAL_ADCEx_RegularStop(ADC_HandleTypeDef *hadc) 01406 { 01407 HAL_StatusTypeDef tmp_hal_status; 01408 01409 /* Check the parameters */ 01410 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 01411 01412 /* Process locked */ 01413 __HAL_LOCK(hadc); 01414 01415 /* 1. Stop potential regular conversion on going */ 01416 tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP); 01417 01418 /* Disable ADC peripheral if regular conversions are effectively stopped 01419 and if no injected conversions are on-going */ 01420 if (tmp_hal_status == HAL_OK) 01421 { 01422 /* Clear HAL_ADC_STATE_REG_BUSY bit */ 01423 CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY); 01424 01425 if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL) 01426 { 01427 /* 2. Disable the ADC peripheral */ 01428 tmp_hal_status = ADC_Disable(hadc); 01429 01430 /* Check if ADC is effectively disabled */ 01431 if (tmp_hal_status == HAL_OK) 01432 { 01433 /* Set ADC state */ 01434 ADC_STATE_CLR_SET(hadc->State, 01435 HAL_ADC_STATE_INJ_BUSY, 01436 HAL_ADC_STATE_READY); 01437 } 01438 } 01439 /* Conversion on injected group is stopped, but ADC not disabled since */ 01440 /* conversion on regular group is still running. */ 01441 else 01442 { 01443 SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY); 01444 } 01445 } 01446 01447 /* Process unlocked */ 01448 __HAL_UNLOCK(hadc); 01449 01450 /* Return function status */ 01451 return tmp_hal_status; 01452 } 01453 01454 01455 /** 01456 * @brief Stop ADC conversion of ADC groups regular and injected, 01457 * disable interrution of end-of-conversion, 01458 * disable ADC peripheral if no conversion is on going 01459 * on injected group. 01460 * @param hadc ADC handle 01461 * @retval HAL status. 01462 */ 01463 HAL_StatusTypeDef HAL_ADCEx_RegularStop_IT(ADC_HandleTypeDef *hadc) 01464 { 01465 HAL_StatusTypeDef tmp_hal_status; 01466 01467 /* Check the parameters */ 01468 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 01469 01470 /* Process locked */ 01471 __HAL_LOCK(hadc); 01472 01473 /* 1. Stop potential regular conversion on going */ 01474 tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP); 01475 01476 /* Disable ADC peripheral if conversions are effectively stopped 01477 and if no injected conversion is on-going */ 01478 if (tmp_hal_status == HAL_OK) 01479 { 01480 /* Clear HAL_ADC_STATE_REG_BUSY bit */ 01481 CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY); 01482 01483 /* Disable all regular-related interrupts */ 01484 __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS | ADC_IT_OVR)); 01485 01486 /* 2. Disable ADC peripheral if no injected conversions are on-going */ 01487 if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL) 01488 { 01489 tmp_hal_status = ADC_Disable(hadc); 01490 /* if no issue reported */ 01491 if (tmp_hal_status == HAL_OK) 01492 { 01493 /* Set ADC state */ 01494 ADC_STATE_CLR_SET(hadc->State, 01495 HAL_ADC_STATE_INJ_BUSY, 01496 HAL_ADC_STATE_READY); 01497 } 01498 } 01499 else 01500 { 01501 SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY); 01502 } 01503 } 01504 01505 /* Process unlocked */ 01506 __HAL_UNLOCK(hadc); 01507 01508 /* Return function status */ 01509 return tmp_hal_status; 01510 } 01511 01512 /** 01513 * @brief Stop ADC conversion of regular group (and injected group in 01514 * case of auto_injection mode), disable ADC DMA transfer, disable 01515 * ADC peripheral if no conversion is on going 01516 * on injected group. 01517 * @note HAL_ADCEx_RegularStop_DMA() function is dedicated to single-ADC mode only. 01518 * For multimode (when multimode feature is available), 01519 * HAL_ADCEx_RegularMultiModeStop_DMA() API must be used. 01520 * @param hadc ADC handle 01521 * @retval HAL status. 01522 */ 01523 HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef *hadc) 01524 { 01525 HAL_StatusTypeDef tmp_hal_status; 01526 01527 /* Check the parameters */ 01528 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 01529 01530 /* Process locked */ 01531 __HAL_LOCK(hadc); 01532 01533 /* 1. Stop potential regular conversion on going */ 01534 tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP); 01535 01536 /* Disable ADC peripheral if conversions are effectively stopped 01537 and if no injected conversion is on-going */ 01538 if (tmp_hal_status == HAL_OK) 01539 { 01540 /* Clear HAL_ADC_STATE_REG_BUSY bit */ 01541 CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY); 01542 01543 /* Disable ADC DMA (ADC DMA configuration ADC_CFGR_DMACFG is kept) */ 01544 MODIFY_REG(hadc->Instance->CFGR, ADC_CFGR_DMNGT_0 | ADC_CFGR_DMNGT_1, 0UL); 01545 01546 /* Disable the DMA channel (in case of DMA in circular mode or stop while */ 01547 /* while DMA transfer is on going) */ 01548 tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); 01549 01550 /* Check if DMA channel effectively disabled */ 01551 if (tmp_hal_status != HAL_OK) 01552 { 01553 /* Update ADC state machine to error */ 01554 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); 01555 } 01556 01557 /* Disable ADC overrun interrupt */ 01558 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); 01559 01560 /* 2. Disable the ADC peripheral */ 01561 /* Update "tmp_hal_status" only if DMA channel disabling passed, */ 01562 /* to keep in memory a potential failing status. */ 01563 if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL) 01564 { 01565 if (tmp_hal_status == HAL_OK) 01566 { 01567 tmp_hal_status = ADC_Disable(hadc); 01568 } 01569 else 01570 { 01571 (void)ADC_Disable(hadc); 01572 } 01573 01574 /* Check if ADC is effectively disabled */ 01575 if (tmp_hal_status == HAL_OK) 01576 { 01577 /* Set ADC state */ 01578 ADC_STATE_CLR_SET(hadc->State, 01579 HAL_ADC_STATE_INJ_BUSY, 01580 HAL_ADC_STATE_READY); 01581 } 01582 } 01583 else 01584 { 01585 SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY); 01586 } 01587 } 01588 01589 /* Process unlocked */ 01590 __HAL_UNLOCK(hadc); 01591 01592 /* Return function status */ 01593 return tmp_hal_status; 01594 } 01595 01596 /** 01597 * @brief Stop DMA-based multimode ADC conversion, disable ADC DMA transfer, disable ADC peripheral if no injected conversion is on-going. 01598 * @note Multimode is kept enabled after this function. Multimode DMA bits 01599 * (MDMA and DMACFG bits of common CCR register) are maintained. To disable 01600 * multimode (set with HAL_ADCEx_MultiModeConfigChannel()), ADC must be 01601 * reinitialized using HAL_ADC_Init() or HAL_ADC_DeInit(), or the user can 01602 * resort to HAL_ADCEx_DisableMultiMode() API. 01603 * @note In case of DMA configured in circular mode, function 01604 * HAL_ADCEx_RegularStop_DMA() must be called after this function with handle of 01605 * ADC slave, to properly disable the DMA channel. 01606 * @param hadc ADC handle of ADC master (handle of ADC slave must not be used) 01607 * @retval HAL status 01608 */ 01609 HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef *hadc) 01610 { 01611 HAL_StatusTypeDef tmp_hal_status; 01612 uint32_t tickstart; 01613 ADC_HandleTypeDef tmphadcSlave; 01614 uint32_t tmphadcSlave_conversion_on_going; 01615 01616 /* Check the parameters */ 01617 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance)); 01618 01619 /* Process locked */ 01620 __HAL_LOCK(hadc); 01621 01622 01623 /* 1. Stop potential multimode conversion on going, on regular groups */ 01624 tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP); 01625 01626 /* Disable ADC peripheral if conversions are effectively stopped */ 01627 if (tmp_hal_status == HAL_OK) 01628 { 01629 /* Clear HAL_ADC_STATE_REG_BUSY bit */ 01630 CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY); 01631 01632 tmphadcSlave.State = HAL_ADC_STATE_RESET; 01633 tmphadcSlave.ErrorCode = HAL_ADC_ERROR_NONE; 01634 01635 /* Set a temporary handle of the ADC slave associated to the ADC master */ 01636 ADC_MULTI_SLAVE(hadc, &tmphadcSlave); 01637 01638 if (tmphadcSlave.Instance == NULL) 01639 { 01640 /* Update ADC state machine to error */ 01641 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 01642 01643 /* Process unlocked */ 01644 __HAL_UNLOCK(hadc); 01645 01646 return HAL_ERROR; 01647 } 01648 01649 /* Procedure to disable the ADC peripheral: wait for conversions */ 01650 /* effectively stopped (ADC master and ADC slave), then disable ADC */ 01651 01652 /* 1. Wait for ADC conversion completion for ADC master and ADC slave */ 01653 tickstart = HAL_GetTick(); 01654 01655 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance); 01656 while ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL) 01657 || (tmphadcSlave_conversion_on_going == 1UL) 01658 ) 01659 { 01660 if ((HAL_GetTick() - tickstart) > ADC_STOP_CONVERSION_TIMEOUT) 01661 { 01662 /* New check to avoid false timeout detection in case of preemption */ 01663 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance); 01664 01665 if((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL) 01666 || (tmphadcSlave_conversion_on_going == 1UL) 01667 ) 01668 { 01669 /* Update ADC state machine to error */ 01670 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); 01671 01672 /* Process unlocked */ 01673 __HAL_UNLOCK(hadc); 01674 01675 return HAL_ERROR; 01676 } 01677 } 01678 01679 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance); 01680 } 01681 01682 /* Disable the DMA channel (in case of DMA in circular mode or stop */ 01683 /* while DMA transfer is on going) */ 01684 /* Note: DMA channel of ADC slave should be stopped after this function */ 01685 /* with HAL_ADCEx_RegularStop_DMA() API. */ 01686 tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); 01687 01688 /* Check if DMA channel effectively disabled */ 01689 if (tmp_hal_status != HAL_OK) 01690 { 01691 /* Update ADC state machine to error */ 01692 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); 01693 } 01694 01695 /* Disable ADC overrun interrupt */ 01696 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); 01697 01698 /* 2. Disable the ADC peripherals: master and slave if no injected */ 01699 /* conversion is on-going. */ 01700 /* Update "tmp_hal_status" only if DMA channel disabling passed, to keep in */ 01701 /* memory a potential failing status. */ 01702 if (tmp_hal_status == HAL_OK) 01703 { 01704 if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL) 01705 { 01706 tmp_hal_status = ADC_Disable(hadc); 01707 if (tmp_hal_status == HAL_OK) 01708 { 01709 if (LL_ADC_INJ_IsConversionOngoing((&tmphadcSlave)->Instance) == 0UL) 01710 { 01711 tmp_hal_status = ADC_Disable(&tmphadcSlave); 01712 } 01713 } 01714 } 01715 01716 if (tmp_hal_status == HAL_OK) 01717 { 01718 /* Both Master and Slave ADC's could be disabled. Update Master State */ 01719 /* Clear HAL_ADC_STATE_INJ_BUSY bit, set HAL_ADC_STATE_READY bit */ 01720 ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY); 01721 } 01722 else 01723 { 01724 /* injected (Master or Slave) conversions are still on-going, 01725 no Master State change */ 01726 } 01727 } 01728 } 01729 01730 /* Process unlocked */ 01731 __HAL_UNLOCK(hadc); 01732 01733 /* Return function status */ 01734 return tmp_hal_status; 01735 } 01736 01737 /** 01738 * @} 01739 */ 01740 01741 /** @defgroup ADCEx_Exported_Functions_Group2 ADC Extended Peripheral Control functions 01742 * @brief ADC Extended Peripheral Control functions 01743 * 01744 @verbatim 01745 =============================================================================== 01746 ##### Peripheral Control functions ##### 01747 =============================================================================== 01748 [..] This section provides functions allowing to: 01749 (+) Configure channels on injected group 01750 (+) Configure multimode when multimode feature is available 01751 (+) Enable or Disable Injected Queue 01752 (+) Disable ADC voltage regulator 01753 (+) Enter ADC deep-power-down mode 01754 01755 @endverbatim 01756 * @{ 01757 */ 01758 01759 /** 01760 * @brief Configure a channel to be assigned to ADC group injected. 01761 * @note Possibility to update parameters on the fly: 01762 * This function initializes injected group, following calls to this 01763 * function can be used to reconfigure some parameters of structure 01764 * "ADC_InjectionConfTypeDef" on the fly, without resetting the ADC. 01765 * The setting of these parameters is conditioned to ADC state: 01766 * Refer to comments of structure "ADC_InjectionConfTypeDef". 01767 * @note In case of usage of internal measurement channels: 01768 * Vbat/VrefInt/TempSensor. 01769 * These internal paths can be disabled using function 01770 * HAL_ADC_DeInit(). 01771 * @note Caution: For Injected Context Queue use, a context must be fully 01772 * defined before start of injected conversion. All channels are configured 01773 * consecutively for the same ADC instance. Therefore, the number of calls to 01774 * HAL_ADCEx_InjectedConfigChannel() must be equal to the value of parameter 01775 * InjectedNbrOfConversion for each context. 01776 * - Example 1: If 1 context is intended to be used (or if there is no use of the 01777 * Injected Queue Context feature) and if the context contains 3 injected ranks 01778 * (InjectedNbrOfConversion = 3), HAL_ADCEx_InjectedConfigChannel() must be 01779 * called once for each channel (i.e. 3 times) before starting a conversion. 01780 * This function must not be called to configure a 4th injected channel: 01781 * it would start a new context into context queue. 01782 * - Example 2: If 2 contexts are intended to be used and each of them contains 01783 * 3 injected ranks (InjectedNbrOfConversion = 3), 01784 * HAL_ADCEx_InjectedConfigChannel() must be called once for each channel and 01785 * for each context (3 channels x 2 contexts = 6 calls). Conversion can 01786 * start once the 1st context is set, that is after the first three 01787 * HAL_ADCEx_InjectedConfigChannel() calls. The 2nd context can be set on the fly. 01788 * @param hadc ADC handle 01789 * @param sConfigInjected Structure of ADC injected group and ADC channel for 01790 * injected group. 01791 * @retval HAL status 01792 */ 01793 HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_InjectionConfTypeDef *sConfigInjected) 01794 { 01795 HAL_StatusTypeDef tmp_hal_status = HAL_OK; 01796 uint32_t tmpOffsetShifted; 01797 uint32_t tmp_config_internal_channel; 01798 uint32_t tmp_adc_is_conversion_on_going_regular; 01799 uint32_t tmp_adc_is_conversion_on_going_injected; 01800 __IO uint32_t wait_loop_index = 0; 01801 01802 uint32_t tmp_JSQR_ContextQueueBeingBuilt = 0U; 01803 01804 /* Check the parameters */ 01805 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 01806 assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime)); 01807 assert_param(IS_ADC_SINGLE_DIFFERENTIAL(sConfigInjected->InjectedSingleDiff)); 01808 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv)); 01809 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->QueueInjectedContext)); 01810 assert_param(IS_ADC_EXTTRIGINJEC_EDGE(sConfigInjected->ExternalTrigInjecConvEdge)); 01811 assert_param(IS_ADC_EXTTRIGINJEC(sConfigInjected->ExternalTrigInjecConv)); 01812 assert_param(IS_ADC_OFFSET_NUMBER(sConfigInjected->InjectedOffsetNumber)); 01813 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjecOversamplingMode)); 01814 #if defined(ADC_VER_V5_V90) 01815 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedOffsetSaturation)); 01816 if (hadc->Instance == ADC3) 01817 { 01818 assert_param(IS_ADC3_OFFSET_SIGN(sConfigInjected->InjectedOffsetSign)); 01819 assert_param(IS_ADC3_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset)); 01820 } 01821 else 01822 #endif /* ADC_VER_V5_V90 */ 01823 { 01824 assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset)); 01825 } 01826 01827 if (hadc->Init.ScanConvMode != ADC_SCAN_DISABLE) 01828 { 01829 assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank)); 01830 assert_param(IS_ADC_INJECTED_NB_CONV(sConfigInjected->InjectedNbrOfConversion)); 01831 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode)); 01832 } 01833 01834 /* Check offset range according to oversampling setting */ 01835 if (hadc->Init.OversamplingMode == ENABLE) 01836 { 01837 assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset / (hadc->Init.Oversampling.Ratio + 1U))); 01838 } 01839 else 01840 { 01841 assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset)); 01842 } 01843 #if defined(ADC_VER_V5_V90) 01844 /* if JOVSE is set, the value of the OFFSETy_EN bit in ADCx_OFRy register is 01845 ignored (considered as reset) */ 01846 if (hadc->Instance == ADC3) 01847 { 01848 assert_param(!((sConfigInjected->InjectedOffsetNumber != ADC_OFFSET_NONE) && (sConfigInjected->InjecOversamplingMode == ENABLE))); 01849 } 01850 #endif /* ADC_VER_V5_V90 */ 01851 /* JDISCEN and JAUTO bits can't be set at the same time */ 01852 assert_param(!((sConfigInjected->InjectedDiscontinuousConvMode == ENABLE) && (sConfigInjected->AutoInjectedConv == ENABLE))); 01853 01854 /* DISCEN and JAUTO bits can't be set at the same time */ 01855 assert_param(!((hadc->Init.DiscontinuousConvMode == ENABLE) && (sConfigInjected->AutoInjectedConv == ENABLE))); 01856 01857 /* Verification of channel number */ 01858 if (sConfigInjected->InjectedSingleDiff != ADC_DIFFERENTIAL_ENDED) 01859 { 01860 assert_param(IS_ADC_CHANNEL(sConfigInjected->InjectedChannel)); 01861 } 01862 else 01863 { 01864 if (hadc->Instance == ADC1) 01865 { 01866 assert_param(IS_ADC1_DIFF_CHANNEL(sConfigInjected->InjectedChannel)); 01867 } 01868 if (hadc->Instance == ADC2) 01869 { 01870 assert_param(IS_ADC2_DIFF_CHANNEL(sConfigInjected->InjectedChannel)); 01871 } 01872 #if defined (ADC3) 01873 if (hadc->Instance == ADC3) 01874 { 01875 assert_param(IS_ADC3_DIFF_CHANNEL(sConfigInjected->InjectedChannel)); 01876 } 01877 #endif 01878 } 01879 01880 /* Process locked */ 01881 __HAL_LOCK(hadc); 01882 01883 /* Configuration of injected group sequencer: */ 01884 /* Hardware constraint: Must fully define injected context register JSQR */ 01885 /* before make it entering into injected sequencer queue. */ 01886 /* */ 01887 /* - if scan mode is disabled: */ 01888 /* * Injected channels sequence length is set to 0x00: 1 channel */ 01889 /* converted (channel on injected rank 1) */ 01890 /* Parameter "InjectedNbrOfConversion" is discarded. */ 01891 /* * Injected context register JSQR setting is simple: register is fully */ 01892 /* defined on one call of this function (for injected rank 1) and can */ 01893 /* be entered into queue directly. */ 01894 /* - if scan mode is enabled: */ 01895 /* * Injected channels sequence length is set to parameter */ 01896 /* "InjectedNbrOfConversion". */ 01897 /* * Injected context register JSQR setting more complex: register is */ 01898 /* fully defined over successive calls of this function, for each */ 01899 /* injected channel rank. It is entered into queue only when all */ 01900 /* injected ranks have been set. */ 01901 /* Note: Scan mode is not present by hardware on this device, but used */ 01902 /* by software for alignment over all STM32 devices. */ 01903 01904 if ((hadc->Init.ScanConvMode == ADC_SCAN_DISABLE) || 01905 (sConfigInjected->InjectedNbrOfConversion == 1U)) 01906 { 01907 /* Configuration of context register JSQR: */ 01908 /* - number of ranks in injected group sequencer: fixed to 1st rank */ 01909 /* (scan mode disabled, only rank 1 used) */ 01910 /* - external trigger to start conversion */ 01911 /* - external trigger polarity */ 01912 /* - channel set to rank 1 (scan mode disabled, only rank 1 can be used) */ 01913 01914 if (sConfigInjected->InjectedRank == ADC_INJECTED_RANK_1) 01915 { 01916 /* Enable external trigger if trigger selection is different of */ 01917 /* software start. */ 01918 /* Note: This configuration keeps the hardware feature of parameter */ 01919 /* ExternalTrigInjecConvEdge "trigger edge none" equivalent to */ 01920 /* software start. */ 01921 if (sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START) 01922 { 01923 tmp_JSQR_ContextQueueBeingBuilt = (ADC_JSQR_RK(sConfigInjected->InjectedChannel, ADC_INJECTED_RANK_1) 01924 | (sConfigInjected->ExternalTrigInjecConv & ADC_JSQR_JEXTSEL) 01925 | sConfigInjected->ExternalTrigInjecConvEdge 01926 ); 01927 } 01928 else 01929 { 01930 tmp_JSQR_ContextQueueBeingBuilt = (ADC_JSQR_RK(sConfigInjected->InjectedChannel, ADC_INJECTED_RANK_1)); 01931 } 01932 01933 MODIFY_REG(hadc->Instance->JSQR, ADC_JSQR_FIELDS, tmp_JSQR_ContextQueueBeingBuilt); 01934 /* For debug and informative reasons, hadc handle saves JSQR setting */ 01935 hadc->InjectionConfig.ContextQueue = tmp_JSQR_ContextQueueBeingBuilt; 01936 01937 } 01938 } 01939 else 01940 { 01941 /* Case of scan mode enabled, several channels to set into injected group */ 01942 /* sequencer. */ 01943 /* */ 01944 /* Procedure to define injected context register JSQR over successive */ 01945 /* calls of this function, for each injected channel rank: */ 01946 /* 1. Start new context and set parameters related to all injected */ 01947 /* channels: injected sequence length and trigger. */ 01948 01949 /* if hadc->InjectionConfig.ChannelCount is equal to 0, this is the first */ 01950 /* call of the context under setting */ 01951 if (hadc->InjectionConfig.ChannelCount == 0U) 01952 { 01953 /* Initialize number of channels that will be configured on the context */ 01954 /* being built */ 01955 hadc->InjectionConfig.ChannelCount = sConfigInjected->InjectedNbrOfConversion; 01956 /* Handle hadc saves the context under build up over each HAL_ADCEx_InjectedConfigChannel() 01957 call, this context will be written in JSQR register at the last call. 01958 At this point, the context is merely reset */ 01959 hadc->InjectionConfig.ContextQueue = 0x00000000U; 01960 01961 /* Configuration of context register JSQR: */ 01962 /* - number of ranks in injected group sequencer */ 01963 /* - external trigger to start conversion */ 01964 /* - external trigger polarity */ 01965 01966 /* Enable external trigger if trigger selection is different of */ 01967 /* software start. */ 01968 /* Note: This configuration keeps the hardware feature of parameter */ 01969 /* ExternalTrigInjecConvEdge "trigger edge none" equivalent to */ 01970 /* software start. */ 01971 if (sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START) 01972 { 01973 tmp_JSQR_ContextQueueBeingBuilt = ((sConfigInjected->InjectedNbrOfConversion - 1U) 01974 | (sConfigInjected->ExternalTrigInjecConv & ADC_JSQR_JEXTSEL) 01975 | sConfigInjected->ExternalTrigInjecConvEdge 01976 ); 01977 } 01978 else 01979 { 01980 tmp_JSQR_ContextQueueBeingBuilt = ((sConfigInjected->InjectedNbrOfConversion - 1U)); 01981 } 01982 01983 } 01984 01985 /* 2. Continue setting of context under definition with parameter */ 01986 /* related to each channel: channel rank sequence */ 01987 /* Clear the old JSQx bits for the selected rank */ 01988 tmp_JSQR_ContextQueueBeingBuilt &= ~ADC_JSQR_RK(ADC_SQR3_SQ10, sConfigInjected->InjectedRank); 01989 01990 /* Set the JSQx bits for the selected rank */ 01991 tmp_JSQR_ContextQueueBeingBuilt |= ADC_JSQR_RK(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank); 01992 01993 /* Decrease channel count */ 01994 hadc->InjectionConfig.ChannelCount--; 01995 01996 /* 3. tmp_JSQR_ContextQueueBeingBuilt is fully built for this HAL_ADCEx_InjectedConfigChannel() 01997 call, aggregate the setting to those already built during the previous 01998 HAL_ADCEx_InjectedConfigChannel() calls (for the same context of course) */ 01999 hadc->InjectionConfig.ContextQueue |= tmp_JSQR_ContextQueueBeingBuilt; 02000 02001 /* 4. End of context setting: if this is the last channel set, then write context 02002 into register JSQR and make it enter into queue */ 02003 if (hadc->InjectionConfig.ChannelCount == 0U) 02004 { 02005 MODIFY_REG(hadc->Instance->JSQR, ADC_JSQR_FIELDS, hadc->InjectionConfig.ContextQueue); 02006 } 02007 } 02008 02009 /* Parameters update conditioned to ADC state: */ 02010 /* Parameters that can be updated when ADC is disabled or enabled without */ 02011 /* conversion on going on injected group: */ 02012 /* - Injected context queue: Queue disable (active context is kept) or */ 02013 /* enable (context decremented, up to 2 contexts queued) */ 02014 /* - Injected discontinuous mode: can be enabled only if auto-injected */ 02015 /* mode is disabled. */ 02016 if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL) 02017 { 02018 #if defined(ADC_VER_V5_V90) 02019 if (hadc->Instance != ADC3) 02020 { 02021 /* ADC channels preselection */ 02022 hadc->Instance->PCSEL_RES0 |= (1UL << (__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel) & 0x1FUL)); 02023 } 02024 #else 02025 /* ADC channels preselection */ 02026 hadc->Instance->PCSEL |= (1UL << (__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel) & 0x1FUL)); 02027 #endif /* ADC_VER_V5_V90 */ 02028 02029 /* If auto-injected mode is disabled: no constraint */ 02030 if (sConfigInjected->AutoInjectedConv == DISABLE) 02031 { 02032 MODIFY_REG(hadc->Instance->CFGR, 02033 ADC_CFGR_JQM | ADC_CFGR_JDISCEN, 02034 ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext) | 02035 ADC_CFGR_INJECT_DISCCONTINUOUS((uint32_t)sConfigInjected->InjectedDiscontinuousConvMode)); 02036 } 02037 /* If auto-injected mode is enabled: Injected discontinuous setting is */ 02038 /* discarded. */ 02039 else 02040 { 02041 MODIFY_REG(hadc->Instance->CFGR, 02042 ADC_CFGR_JQM | ADC_CFGR_JDISCEN, 02043 ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext)); 02044 } 02045 02046 } 02047 02048 /* Parameters update conditioned to ADC state: */ 02049 /* Parameters that can be updated when ADC is disabled or enabled without */ 02050 /* conversion on going on regular and injected groups: */ 02051 /* - Automatic injected conversion: can be enabled if injected group */ 02052 /* external triggers are disabled. */ 02053 /* - Channel sampling time */ 02054 /* - Channel offset */ 02055 tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance); 02056 tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance); 02057 02058 if ((tmp_adc_is_conversion_on_going_regular == 0UL) 02059 && (tmp_adc_is_conversion_on_going_injected == 0UL) 02060 ) 02061 { 02062 /* If injected group external triggers are disabled (set to injected */ 02063 /* software start): no constraint */ 02064 if ((sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START) 02065 || (sConfigInjected->ExternalTrigInjecConvEdge == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE)) 02066 { 02067 if (sConfigInjected->AutoInjectedConv == ENABLE) 02068 { 02069 SET_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO); 02070 } 02071 else 02072 { 02073 CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO); 02074 } 02075 } 02076 /* If Automatic injected conversion was intended to be set and could not */ 02077 /* due to injected group external triggers enabled, error is reported. */ 02078 else 02079 { 02080 if (sConfigInjected->AutoInjectedConv == ENABLE) 02081 { 02082 /* Update ADC state machine to error */ 02083 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 02084 02085 tmp_hal_status = HAL_ERROR; 02086 } 02087 else 02088 { 02089 CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO); 02090 } 02091 } 02092 02093 if (sConfigInjected->InjecOversamplingMode == ENABLE) 02094 { 02095 #if defined(ADC_VER_V5_V90) 02096 if (hadc->Instance == ADC3) 02097 { 02098 assert_param(IS_ADC_OVERSAMPLING_RATIO_ADC3(sConfigInjected->InjecOversampling.Ratio)); 02099 } 02100 else 02101 { 02102 assert_param(IS_ADC_OVERSAMPLING_RATIO(sConfigInjected->InjecOversampling.Ratio)); 02103 } 02104 #else 02105 assert_param(IS_ADC_OVERSAMPLING_RATIO(sConfigInjected->InjecOversampling.Ratio)); 02106 #endif 02107 assert_param(IS_ADC_RIGHT_BIT_SHIFT(sConfigInjected->InjecOversampling.RightBitShift)); 02108 02109 /* JOVSE must be reset in case of triggered regular mode */ 02110 assert_param(!(READ_BIT(hadc->Instance->CFGR2, ADC_CFGR2_ROVSE | ADC_CFGR2_TROVS) == (ADC_CFGR2_ROVSE | ADC_CFGR2_TROVS))); 02111 02112 /* Configuration of Injected Oversampler: */ 02113 /* - Oversampling Ratio */ 02114 /* - Right bit shift */ 02115 02116 /* Enable OverSampling mode */ 02117 #if defined(ADC_VER_V5_V90) 02118 if (hadc->Instance != ADC3) 02119 { 02120 MODIFY_REG(hadc->Instance->CFGR2, 02121 ADC_CFGR2_JOVSE | 02122 ADC_CFGR2_OVSR | 02123 ADC_CFGR2_OVSS, 02124 ADC_CFGR2_JOVSE | 02125 ((sConfigInjected->InjecOversampling.Ratio - 1UL) << ADC_CFGR2_OVSR_Pos) | 02126 sConfigInjected->InjecOversampling.RightBitShift 02127 ); 02128 } 02129 else 02130 { 02131 MODIFY_REG(hadc->Instance->CFGR2, 02132 ADC_CFGR2_JOVSE | 02133 ADC3_CFGR2_OVSR | 02134 ADC_CFGR2_OVSS, 02135 ADC_CFGR2_JOVSE | 02136 (sConfigInjected->InjecOversampling.Ratio) | 02137 sConfigInjected->InjecOversampling.RightBitShift 02138 ); 02139 } 02140 #else 02141 MODIFY_REG(hadc->Instance->CFGR2, 02142 ADC_CFGR2_JOVSE | 02143 ADC_CFGR2_OVSR | 02144 ADC_CFGR2_OVSS, 02145 ADC_CFGR2_JOVSE | 02146 ((sConfigInjected->InjecOversampling.Ratio - 1UL) << ADC_CFGR2_OVSR_Pos) | 02147 sConfigInjected->InjecOversampling.RightBitShift 02148 ); 02149 #endif 02150 } 02151 else 02152 { 02153 /* Disable Regular OverSampling */ 02154 CLEAR_BIT(hadc->Instance->CFGR2, ADC_CFGR2_JOVSE); 02155 } 02156 02157 /* Set sampling time of the selected ADC channel */ 02158 LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSamplingTime); 02159 02160 /* Configure the offset: offset enable/disable, channel, offset value */ 02161 02162 /* Shift the offset with respect to the selected ADC resolution. */ 02163 /* Offset has to be left-aligned on bit 11, the LSB (right bits) are set to 0 */ 02164 #if defined(ADC_VER_V5_V90) 02165 if (hadc->Instance == ADC3) 02166 { 02167 tmpOffsetShifted = ADC3_OFFSET_SHIFT_RESOLUTION(hadc, sConfigInjected->InjectedOffset); 02168 } 02169 else 02170 #endif /* ADC_VER_V5_V90 */ 02171 { 02172 tmpOffsetShifted = ADC_OFFSET_SHIFT_RESOLUTION(hadc, sConfigInjected->InjectedOffset); 02173 } 02174 02175 if (sConfigInjected->InjectedOffsetNumber != ADC_OFFSET_NONE) 02176 { 02177 /* Set ADC selected offset number */ 02178 LL_ADC_SetOffset(hadc->Instance, sConfigInjected->InjectedOffsetNumber, sConfigInjected->InjectedChannel, tmpOffsetShifted); 02179 02180 #if defined(ADC_VER_V5_V90) 02181 if (hadc->Instance == ADC3) 02182 { 02183 /* Set ADC selected offset sign & saturation */ 02184 LL_ADC_SetOffsetSign(hadc->Instance, sConfigInjected->InjectedOffsetNumber, sConfigInjected->InjectedOffsetSign); 02185 LL_ADC_SetOffsetSaturation(hadc->Instance, sConfigInjected->InjectedOffsetNumber, (sConfigInjected->InjectedOffsetSaturation == ENABLE) ? LL_ADC_OFFSET_SATURATION_ENABLE : LL_ADC_OFFSET_SATURATION_DISABLE); 02186 } 02187 else 02188 #endif /* ADC_VER_V5_V90 */ 02189 { 02190 /* Set ADC selected offset signed saturation */ 02191 LL_ADC_SetOffsetSignedSaturation(hadc->Instance, sConfigInjected->InjectedOffsetNumber, (sConfigInjected->InjectedOffsetSignedSaturation == ENABLE) ? LL_ADC_OFFSET_SIGNED_SATURATION_ENABLE : LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE); 02192 } 02193 02194 } 02195 else 02196 { 02197 #if defined(ADC_VER_V5_V90) 02198 if (hadc->Instance == ADC3) 02199 { 02200 /* Scan each offset register to check if the selected channel is targeted. */ 02201 /* If this is the case, the corresponding offset number is disabled. */ 02202 if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_1)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel)) 02203 { 02204 LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_1, LL_ADC_OFFSET_DISABLE); 02205 } 02206 if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_2)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel)) 02207 { 02208 LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_2, LL_ADC_OFFSET_DISABLE); 02209 } 02210 if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_3)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel)) 02211 { 02212 LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_3, LL_ADC_OFFSET_DISABLE); 02213 } 02214 if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_4)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel)) 02215 { 02216 LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_4, LL_ADC_OFFSET_DISABLE); 02217 } 02218 } 02219 else 02220 #endif /* ADC_VER_V5_V90 */ 02221 { 02222 /* Scan each offset register to check if the selected channel is targeted. */ 02223 /* If this is the case, the corresponding offset number is disabled. */ 02224 if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_1)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel)) 02225 { 02226 LL_ADC_SetOffset(hadc->Instance, LL_ADC_OFFSET_1, sConfigInjected->InjectedChannel, LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE); 02227 } 02228 if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_2)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel)) 02229 { 02230 LL_ADC_SetOffset(hadc->Instance, LL_ADC_OFFSET_2, sConfigInjected->InjectedChannel, LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE); 02231 } 02232 if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_3)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel)) 02233 { 02234 LL_ADC_SetOffset(hadc->Instance, LL_ADC_OFFSET_4, sConfigInjected->InjectedChannel, LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE); 02235 } 02236 if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_4)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel)) 02237 { 02238 LL_ADC_SetOffset(hadc->Instance, LL_ADC_OFFSET_4, sConfigInjected->InjectedChannel, LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE); 02239 } 02240 } 02241 } 02242 02243 } 02244 02245 /* Parameters update conditioned to ADC state: */ 02246 /* Parameters that can be updated only when ADC is disabled: */ 02247 /* - Single or differential mode */ 02248 /* - Internal measurement channels: Vbat/VrefInt/TempSensor */ 02249 if (LL_ADC_IsEnabled(hadc->Instance) == 0UL) 02250 { 02251 /* Set mode single-ended or differential input of the selected ADC channel */ 02252 LL_ADC_SetChannelSingleDiff(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSingleDiff); 02253 02254 /* Configuration of differential mode */ 02255 /* Note: ADC channel number masked with value "0x1F" to ensure shift value within 32 bits range */ 02256 if (sConfigInjected->InjectedSingleDiff == ADC_DIFFERENTIAL_ENDED) 02257 { 02258 /* Set sampling time of the selected ADC channel */ 02259 LL_ADC_SetChannelSamplingTime(hadc->Instance, (uint32_t)(__LL_ADC_DECIMAL_NB_TO_CHANNEL((__LL_ADC_CHANNEL_TO_DECIMAL_NB((uint32_t)sConfigInjected->InjectedChannel) + 1UL) & 0x1FUL)), sConfigInjected->InjectedSamplingTime); 02260 } 02261 02262 /* Management of internal measurement channels: Vbat/VrefInt/TempSensor */ 02263 /* internal measurement paths enable: If internal channel selected, */ 02264 /* enable dedicated internal buffers and path. */ 02265 /* Note: these internal measurement paths can be disabled using */ 02266 /* HAL_ADC_DeInit(). */ 02267 02268 if (__LL_ADC_IS_CHANNEL_INTERNAL(sConfigInjected->InjectedChannel)) 02269 { 02270 /* Configuration of common ADC parameters (continuation) */ 02271 /* Software is allowed to change common parameters only when all ADCs */ 02272 /* of the common group are disabled. */ 02273 if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL) 02274 { 02275 tmp_config_internal_channel = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance)); 02276 02277 /* If the requested internal measurement path has already been enabled, */ 02278 /* bypass the configuration processing. */ 02279 if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0UL)) 02280 { 02281 if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc)) 02282 { 02283 LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_TEMPSENSOR | tmp_config_internal_channel); 02284 02285 /* Delay for temperature sensor stabilization time */ 02286 /* Wait loop initialization and execution */ 02287 /* Note: Variable divided by 2 to compensate partially */ 02288 /* CPU processing cycles, scaling in us split to not */ 02289 /* exceed 32 bits register capacity and handle low frequency. */ 02290 wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL)); 02291 while (wait_loop_index != 0UL) 02292 { 02293 wait_loop_index--; 02294 } 02295 } 02296 } 02297 else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VBAT) == 0UL)) 02298 { 02299 if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc)) 02300 { 02301 LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VBAT | tmp_config_internal_channel); 02302 } 02303 } 02304 else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VREFINT) == 0UL)) 02305 { 02306 if (ADC_VREFINT_INSTANCE(hadc)) 02307 { 02308 LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VREFINT | tmp_config_internal_channel); 02309 } 02310 } 02311 else 02312 { 02313 /* nothing to do */ 02314 } 02315 } 02316 /* If the requested internal measurement path has already been enabled */ 02317 /* and other ADC of the common group are enabled, internal */ 02318 /* measurement paths cannot be enabled. */ 02319 else 02320 { 02321 /* Update ADC state machine to error */ 02322 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 02323 02324 tmp_hal_status = HAL_ERROR; 02325 } 02326 } 02327 02328 } 02329 02330 /* Process unlocked */ 02331 __HAL_UNLOCK(hadc); 02332 02333 /* Return function status */ 02334 return tmp_hal_status; 02335 } 02336 02337 /** 02338 * @brief Enable ADC multimode and configure multimode parameters 02339 * @note Possibility to update parameters on the fly: 02340 * This function initializes multimode parameters, following 02341 * calls to this function can be used to reconfigure some parameters 02342 * of structure "ADC_MultiModeTypeDef" on the fly, without resetting 02343 * the ADCs. 02344 * The setting of these parameters is conditioned to ADC state. 02345 * For parameters constraints, see comments of structure 02346 * "ADC_MultiModeTypeDef". 02347 * @note To move back configuration from multimode to single mode, ADC must 02348 * be reset (using function HAL_ADC_Init() ). 02349 * @param hadc Master ADC handle 02350 * @param multimode Structure of ADC multimode configuration 02351 * @retval HAL status 02352 */ 02353 HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode) 02354 { 02355 HAL_StatusTypeDef tmp_hal_status = HAL_OK; 02356 ADC_Common_TypeDef *tmpADC_Common; 02357 ADC_HandleTypeDef tmphadcSlave; 02358 uint32_t tmphadcSlave_conversion_on_going; 02359 02360 /* Check the parameters */ 02361 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance)); 02362 assert_param(IS_ADC_MULTIMODE(multimode->Mode)); 02363 if (multimode->Mode != ADC_MODE_INDEPENDENT) 02364 { 02365 assert_param(IS_ADC_DUAL_DATA_MODE(multimode->DualModeData)); 02366 assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay)); 02367 } 02368 02369 /* Process locked */ 02370 __HAL_LOCK(hadc); 02371 02372 tmphadcSlave.State = HAL_ADC_STATE_RESET; 02373 tmphadcSlave.ErrorCode = HAL_ADC_ERROR_NONE; 02374 02375 ADC_MULTI_SLAVE(hadc, &tmphadcSlave); 02376 02377 if (tmphadcSlave.Instance == NULL) 02378 { 02379 /* Update ADC state machine to error */ 02380 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 02381 02382 /* Process unlocked */ 02383 __HAL_UNLOCK(hadc); 02384 02385 return HAL_ERROR; 02386 } 02387 02388 /* Parameters update conditioned to ADC state: */ 02389 /* Parameters that can be updated when ADC is disabled or enabled without */ 02390 /* conversion on going on regular group: */ 02391 /* - Multimode DATA Format configuration */ 02392 tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance); 02393 if ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL) 02394 && (tmphadcSlave_conversion_on_going == 0UL)) 02395 { 02396 /* Pointer to the common control register */ 02397 tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance); 02398 02399 /* If multimode is selected, configure all multimode parameters. */ 02400 /* Otherwise, reset multimode parameters (can be used in case of */ 02401 /* transition from multimode to independent mode). */ 02402 if (multimode->Mode != ADC_MODE_INDEPENDENT) 02403 { 02404 MODIFY_REG(tmpADC_Common->CCR, ADC_CCR_DAMDF, multimode->DualModeData); 02405 02406 /* Parameters that can be updated only when ADC is disabled: */ 02407 /* - Multimode mode selection */ 02408 /* - Multimode delay */ 02409 /* Note: Delay range depends on selected resolution: */ 02410 /* from 1 to 9 clock cycles for 16 bits */ 02411 /* from 1 to 9 clock cycles for 14 bits, */ 02412 /* from 1 to 8 clock cycles for 12 bits */ 02413 /* from 1 to 6 clock cycles for 10 and 8 bits */ 02414 /* If a higher delay is selected, it will be clipped to maximum delay */ 02415 /* range */ 02416 02417 if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL) 02418 { 02419 MODIFY_REG(tmpADC_Common->CCR, 02420 ADC_CCR_DUAL | 02421 ADC_CCR_DELAY, 02422 multimode->Mode | 02423 multimode->TwoSamplingDelay 02424 ); 02425 } 02426 } 02427 else /* ADC_MODE_INDEPENDENT */ 02428 { 02429 CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_DAMDF); 02430 02431 /* Parameters that can be updated only when ADC is disabled: */ 02432 /* - Multimode mode selection */ 02433 /* - Multimode delay */ 02434 if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL) 02435 { 02436 CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_DUAL | ADC_CCR_DELAY); 02437 } 02438 } 02439 } 02440 /* If one of the ADC sharing the same common group is enabled, no update */ 02441 /* could be done on neither of the multimode structure parameters. */ 02442 else 02443 { 02444 /* Update ADC state machine to error */ 02445 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG); 02446 02447 tmp_hal_status = HAL_ERROR; 02448 } 02449 02450 /* Process unlocked */ 02451 __HAL_UNLOCK(hadc); 02452 02453 /* Return function status */ 02454 return tmp_hal_status; 02455 } 02456 02457 /** 02458 * @brief Enable Injected Queue 02459 * @note This function resets CFGR register JQDIS bit in order to enable the 02460 * Injected Queue. JQDIS can be written only when ADSTART and JDSTART 02461 * are both equal to 0 to ensure that no regular nor injected 02462 * conversion is ongoing. 02463 * @param hadc ADC handle 02464 * @retval HAL status 02465 */ 02466 HAL_StatusTypeDef HAL_ADCEx_EnableInjectedQueue(ADC_HandleTypeDef *hadc) 02467 { 02468 HAL_StatusTypeDef tmp_hal_status; 02469 uint32_t tmp_adc_is_conversion_on_going_regular; 02470 uint32_t tmp_adc_is_conversion_on_going_injected; 02471 02472 /* Check the parameters */ 02473 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 02474 02475 tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance); 02476 tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance); 02477 02478 /* Parameter can be set only if no conversion is on-going */ 02479 if ((tmp_adc_is_conversion_on_going_regular == 0UL) 02480 && (tmp_adc_is_conversion_on_going_injected == 0UL) 02481 ) 02482 { 02483 CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS); 02484 02485 /* Update state, clear previous result related to injected queue overflow */ 02486 CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_JQOVF); 02487 02488 tmp_hal_status = HAL_OK; 02489 } 02490 else 02491 { 02492 tmp_hal_status = HAL_ERROR; 02493 } 02494 02495 return tmp_hal_status; 02496 } 02497 02498 /** 02499 * @brief Disable Injected Queue 02500 * @note This function sets CFGR register JQDIS bit in order to disable the 02501 * Injected Queue. JQDIS can be written only when ADSTART and JDSTART 02502 * are both equal to 0 to ensure that no regular nor injected 02503 * conversion is ongoing. 02504 * @param hadc ADC handle 02505 * @retval HAL status 02506 */ 02507 HAL_StatusTypeDef HAL_ADCEx_DisableInjectedQueue(ADC_HandleTypeDef *hadc) 02508 { 02509 HAL_StatusTypeDef tmp_hal_status; 02510 uint32_t tmp_adc_is_conversion_on_going_regular; 02511 uint32_t tmp_adc_is_conversion_on_going_injected; 02512 02513 /* Check the parameters */ 02514 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 02515 02516 tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance); 02517 tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance); 02518 02519 /* Parameter can be set only if no conversion is on-going */ 02520 if ((tmp_adc_is_conversion_on_going_regular == 0UL) 02521 && (tmp_adc_is_conversion_on_going_injected == 0UL) 02522 ) 02523 { 02524 LL_ADC_INJ_SetQueueMode(hadc->Instance, LL_ADC_INJ_QUEUE_DISABLE); 02525 tmp_hal_status = HAL_OK; 02526 } 02527 else 02528 { 02529 tmp_hal_status = HAL_ERROR; 02530 } 02531 02532 return tmp_hal_status; 02533 } 02534 02535 /** 02536 * @brief Disable ADC voltage regulator. 02537 * @note Disabling voltage regulator allows to save power. This operation can 02538 * be carried out only when ADC is disabled. 02539 * @note To enable again the voltage regulator, the user is expected to 02540 * resort to HAL_ADC_Init() API. 02541 * @param hadc ADC handle 02542 * @retval HAL status 02543 */ 02544 HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef *hadc) 02545 { 02546 HAL_StatusTypeDef tmp_hal_status; 02547 02548 /* Check the parameters */ 02549 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 02550 02551 /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */ 02552 if (LL_ADC_IsEnabled(hadc->Instance) == 0UL) 02553 { 02554 LL_ADC_DisableInternalRegulator(hadc->Instance); 02555 tmp_hal_status = HAL_OK; 02556 } 02557 else 02558 { 02559 tmp_hal_status = HAL_ERROR; 02560 } 02561 02562 return tmp_hal_status; 02563 } 02564 02565 /** 02566 * @brief Enter ADC deep-power-down mode 02567 * @note This mode is achieved in setting DEEPPWD bit and allows to save power 02568 * in reducing leakage currents. It is particularly interesting before 02569 * entering stop modes. 02570 * @note Setting DEEPPWD automatically clears ADVREGEN bit and disables the 02571 * ADC voltage regulator. This means that this API encompasses 02572 * HAL_ADCEx_DisableVoltageRegulator(). Additionally, the internal 02573 * calibration is lost. 02574 * @note To exit the ADC deep-power-down mode, the user is expected to 02575 * resort to HAL_ADC_Init() API as well as to relaunch a calibration 02576 * with HAL_ADCEx_Calibration_Start() API or to re-apply a previously 02577 * saved calibration factor. 02578 * @param hadc ADC handle 02579 * @retval HAL status 02580 */ 02581 HAL_StatusTypeDef HAL_ADCEx_EnterADCDeepPowerDownMode(ADC_HandleTypeDef *hadc) 02582 { 02583 HAL_StatusTypeDef tmp_hal_status; 02584 02585 /* Check the parameters */ 02586 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); 02587 02588 /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */ 02589 if (LL_ADC_IsEnabled(hadc->Instance) == 0UL) 02590 { 02591 LL_ADC_EnableDeepPowerDown(hadc->Instance); 02592 tmp_hal_status = HAL_OK; 02593 } 02594 else 02595 { 02596 tmp_hal_status = HAL_ERROR; 02597 } 02598 02599 return tmp_hal_status; 02600 } 02601 02602 /** 02603 * @} 02604 */ 02605 02606 /** 02607 * @} 02608 */ 02609 02610 #endif /* HAL_ADC_MODULE_ENABLED */ 02611 /** 02612 * @} 02613 */ 02614 02615 /** 02616 * @} 02617 */ 02618