Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /** |
| 2 | ****************************************************************************** |
||
| 3 | * @file stm32l1xx_hal_adc_ex.h |
||
| 4 | * @author MCD Application Team |
||
| 5 | * @brief Header file of ADC HAL Extension module. |
||
| 6 | ****************************************************************************** |
||
| 7 | * @attention |
||
| 8 | * |
||
| 28 | mjames | 9 | * <h2><center>© Copyright (c) 2017 STMicroelectronics. |
| 10 | * All rights reserved.</center></h2> |
||
| 2 | mjames | 11 | * |
| 28 | mjames | 12 | * This software component is licensed by ST under BSD 3-Clause license, |
| 13 | * the "License"; You may not use this file except in compliance with the |
||
| 14 | * License. You may obtain a copy of the License at: |
||
| 15 | * opensource.org/licenses/BSD-3-Clause |
||
| 2 | mjames | 16 | * |
| 17 | ****************************************************************************** |
||
| 18 | */ |
||
| 19 | |||
| 20 | /* Define to prevent recursive inclusion -------------------------------------*/ |
||
| 21 | #ifndef __STM32L1xx_HAL_ADC_EX_H |
||
| 22 | #define __STM32L1xx_HAL_ADC_EX_H |
||
| 23 | |||
| 24 | #ifdef __cplusplus |
||
| 25 | extern "C" { |
||
| 26 | #endif |
||
| 27 | |||
| 28 | /* Includes ------------------------------------------------------------------*/ |
||
| 29 | #include "stm32l1xx_hal_def.h" |
||
| 30 | |||
| 31 | /** @addtogroup STM32L1xx_HAL_Driver |
||
| 32 | * @{ |
||
| 33 | */ |
||
| 34 | |||
| 35 | /** @addtogroup ADCEx |
||
| 36 | * @{ |
||
| 37 | */ |
||
| 38 | |||
| 39 | /* Exported types ------------------------------------------------------------*/ |
||
| 40 | /** @defgroup ADCEx_Exported_Types ADCEx Exported Types |
||
| 41 | * @{ |
||
| 42 | */ |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @brief ADC Configuration injected Channel structure definition |
||
| 46 | * @note Parameters of this structure are shared within 2 scopes: |
||
| 47 | * - Scope channel: InjectedChannel, InjectedRank, InjectedSamplingTime, InjectedOffset |
||
| 48 | * - Scope injected group (affects all channels of injected group): InjectedNbrOfConversion, InjectedDiscontinuousConvMode, |
||
| 49 | * AutoInjectedConv, ExternalTrigInjecConvEdge, ExternalTrigInjecConv. |
||
| 50 | * @note The setting of these parameters with function HAL_ADCEx_InjectedConfigChannel() is conditioned to ADC state. |
||
| 51 | * ADC state can be either: |
||
| 52 | * - For all parameters: ADC disabled |
||
| 53 | * - For all except parameters 'InjectedDiscontinuousConvMode' and 'AutoInjectedConv': ADC enabled without conversion on going on injected group. |
||
| 54 | * - For parameters 'ExternalTrigInjecConv' and 'ExternalTrigInjecConvEdge': ADC enabled, even with conversion on going on injected group. |
||
| 55 | */ |
||
| 56 | typedef struct |
||
| 57 | { |
||
| 58 | uint32_t InjectedChannel; /*!< Selection of ADC channel to configure |
||
| 59 | This parameter can be a value of @ref ADC_channels |
||
| 60 | Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability. */ |
||
| 61 | uint32_t InjectedRank; /*!< Rank in the injected group sequencer |
||
| 62 | This parameter must be a value of @ref ADCEx_injected_rank |
||
| 63 | Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel setting (or parameter number of conversions can be adjusted) */ |
||
| 64 | uint32_t InjectedSamplingTime; /*!< Sampling time value to be set for the selected channel. |
||
| 65 | Unit: ADC clock cycles |
||
| 66 | Conversion time is the addition of sampling time and processing time (12 ADC clock cycles at ADC resolution 12 bits, 11 cycles at 10 bits, 9 cycles at 8 bits, 7 cycles at 6 bits). |
||
| 67 | This parameter can be a value of @ref ADC_sampling_times |
||
| 68 | Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups. |
||
| 69 | If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting. |
||
| 70 | Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor), |
||
| 71 | sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting) |
||
| 72 | Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 4us min). */ |
||
| 73 | uint32_t InjectedOffset; /*!< Defines the offset to be subtracted from the raw converted data (for channels set on injected group only). |
||
| 74 | Offset value must be a positive number. |
||
| 75 | Depending of ADC resolution selected (12, 10, 8 or 6 bits), |
||
| 76 | this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */ |
||
| 77 | uint32_t InjectedNbrOfConversion; /*!< Specifies the number of ranks that will be converted within the injected group sequencer. |
||
| 78 | To use the injected group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled. |
||
| 79 | This parameter must be a number between Min_Data = 1 and Max_Data = 4. |
||
| 80 | Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to |
||
| 81 | configure a channel on injected group can impact the configuration of other channels previously set. */ |
||
| 28 | mjames | 82 | FunctionalState InjectedDiscontinuousConvMode; /*!< Specifies whether the conversions sequence of injected group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts). |
| 2 | mjames | 83 | Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded. |
| 84 | Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded. |
||
| 85 | This parameter can be set to ENABLE or DISABLE. |
||
| 86 | Note: For injected group, number of discontinuous ranks increment is fixed to one-by-one. |
||
| 87 | Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to |
||
| 88 | configure a channel on injected group can impact the configuration of other channels previously set. */ |
||
| 28 | mjames | 89 | FunctionalState AutoInjectedConv; /*!< Enables or disables the selected ADC automatic injected group conversion after regular one |
| 2 | mjames | 90 | This parameter can be set to ENABLE or DISABLE. |
| 91 | Note: To use Automatic injected conversion, discontinuous mode must be disabled ('DiscontinuousConvMode' and 'InjectedDiscontinuousConvMode' set to DISABLE) |
||
| 92 | Note: To use Automatic injected conversion, injected group external triggers must be disabled ('ExternalTrigInjecConv' set to ADC_SOFTWARE_START) |
||
| 93 | Note: In case of DMA used with regular group: if DMA configured in normal mode (single shot) JAUTO will be stopped upon DMA transfer complete. |
||
| 94 | To maintain JAUTO always enabled, DMA must be configured in circular mode. |
||
| 95 | Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to |
||
| 96 | configure a channel on injected group can impact the configuration of other channels previously set. */ |
||
| 97 | uint32_t ExternalTrigInjecConv; /*!< Selects the external event used to trigger the conversion start of injected group. |
||
| 98 | If set to ADC_INJECTED_SOFTWARE_START, external triggers are disabled. |
||
| 99 | If set to external trigger source, triggering is on event rising edge. |
||
| 100 | This parameter can be a value of @ref ADCEx_External_trigger_source_Injected |
||
| 101 | Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion). |
||
| 102 | If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behaviour in case of another parameter update on the fly) |
||
| 103 | Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to |
||
| 104 | configure a channel on injected group can impact the configuration of other channels previously set. */ |
||
| 105 | uint32_t ExternalTrigInjecConvEdge; /*!< Selects the external trigger edge of injected group. |
||
| 106 | This parameter can be a value of @ref ADCEx_External_trigger_edge_Injected. |
||
| 107 | If trigger is set to ADC_INJECTED_SOFTWARE_START, this parameter is discarded. |
||
| 108 | Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to |
||
| 109 | configure a channel on injected group can impact the configuration of other channels previously set. */ |
||
| 110 | }ADC_InjectionConfTypeDef; |
||
| 111 | /** |
||
| 112 | * @} |
||
| 113 | */ |
||
| 114 | |||
| 115 | |||
| 116 | /* Exported constants --------------------------------------------------------*/ |
||
| 117 | |||
| 118 | /** @defgroup ADCEx_Exported_Constants ADCEx Exported Constants |
||
| 119 | * @{ |
||
| 120 | */ |
||
| 121 | |||
| 122 | /** @defgroup ADCEx_injected_rank ADCEx rank into injected group |
||
| 123 | * @{ |
||
| 124 | */ |
||
| 28 | mjames | 125 | #define ADC_INJECTED_RANK_1 (0x00000001U) |
| 126 | #define ADC_INJECTED_RANK_2 (0x00000002U) |
||
| 127 | #define ADC_INJECTED_RANK_3 (0x00000003U) |
||
| 128 | #define ADC_INJECTED_RANK_4 (0x00000004U) |
||
| 2 | mjames | 129 | /** |
| 130 | * @} |
||
| 131 | */ |
||
| 132 | |||
| 133 | /** @defgroup ADCEx_External_trigger_edge_Injected ADCEx external trigger enable for injected group |
||
| 134 | * @{ |
||
| 135 | */ |
||
| 28 | mjames | 136 | #define ADC_EXTERNALTRIGINJECCONV_EDGE_NONE (0x00000000U) |
| 2 | mjames | 137 | #define ADC_EXTERNALTRIGINJECCONV_EDGE_RISING ((uint32_t)ADC_CR2_JEXTEN_0) |
| 138 | #define ADC_EXTERNALTRIGINJECCONV_EDGE_FALLING ((uint32_t)ADC_CR2_JEXTEN_1) |
||
| 139 | #define ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING ((uint32_t)ADC_CR2_JEXTEN) |
||
| 140 | /** |
||
| 141 | * @} |
||
| 142 | */ |
||
| 143 | |||
| 144 | /** @defgroup ADCEx_External_trigger_source_Injected ADCEx External trigger source Injected |
||
| 145 | * @{ |
||
| 146 | */ |
||
| 147 | /* External triggers for injected groups of ADC1 */ |
||
| 148 | #define ADC_EXTERNALTRIGINJECCONV_T2_CC1 ADC_EXTERNALTRIGINJEC_T2_CC1 |
||
| 149 | #define ADC_EXTERNALTRIGINJECCONV_T2_TRGO ADC_EXTERNALTRIGINJEC_T2_TRGO |
||
| 150 | #define ADC_EXTERNALTRIGINJECCONV_T3_CC4 ADC_EXTERNALTRIGINJEC_T3_CC4 |
||
| 151 | #define ADC_EXTERNALTRIGINJECCONV_T4_TRGO ADC_EXTERNALTRIGINJEC_T4_TRGO |
||
| 152 | #define ADC_EXTERNALTRIGINJECCONV_T4_CC1 ADC_EXTERNALTRIGINJEC_T4_CC1 |
||
| 153 | #define ADC_EXTERNALTRIGINJECCONV_T4_CC2 ADC_EXTERNALTRIGINJEC_T4_CC2 |
||
| 154 | #define ADC_EXTERNALTRIGINJECCONV_T4_CC3 ADC_EXTERNALTRIGINJEC_T4_CC3 |
||
| 155 | #define ADC_EXTERNALTRIGINJECCONV_T7_TRGO ADC_EXTERNALTRIGINJEC_T7_TRGO |
||
| 156 | #define ADC_EXTERNALTRIGINJECCONV_T9_CC1 ADC_EXTERNALTRIGINJEC_T9_CC1 |
||
| 157 | #define ADC_EXTERNALTRIGINJECCONV_T9_TRGO ADC_EXTERNALTRIGINJEC_T9_TRGO |
||
| 158 | #define ADC_EXTERNALTRIGINJECCONV_T10_CC1 ADC_EXTERNALTRIGINJEC_T10_CC1 |
||
| 159 | #define ADC_EXTERNALTRIGINJECCONV_EXT_IT15 ADC_EXTERNALTRIGINJEC_EXT_IT15 |
||
| 28 | mjames | 160 | #define ADC_INJECTED_SOFTWARE_START (0x00000010U) |
| 2 | mjames | 161 | /** |
| 162 | * @} |
||
| 163 | */ |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @} |
||
| 167 | */ |
||
| 168 | |||
| 169 | |||
| 170 | /* Private constants ---------------------------------------------------------*/ |
||
| 171 | |||
| 172 | /** @addtogroup ADCEx_Private_Constants ADCEx Private Constants |
||
| 173 | * @{ |
||
| 174 | */ |
||
| 175 | |||
| 176 | /** @defgroup ADCEx_Internal_HAL_driver_Ext_trig_src_Injected ADCEx Internal HAL driver Ext trig src Injected |
||
| 177 | * @{ |
||
| 178 | */ |
||
| 179 | |||
| 180 | /* List of external triggers of injected group for ADC1: */ |
||
| 181 | /* (used internally by HAL driver. To not use into HAL structure parameters) */ |
||
| 28 | mjames | 182 | #define ADC_EXTERNALTRIGINJEC_T9_CC1 (0x00000000U) |
| 2 | mjames | 183 | #define ADC_EXTERNALTRIGINJEC_T9_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_0)) |
| 184 | #define ADC_EXTERNALTRIGINJEC_T2_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_1 )) |
||
| 185 | #define ADC_EXTERNALTRIGINJEC_T2_CC1 ((uint32_t)( ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0)) |
||
| 186 | #define ADC_EXTERNALTRIGINJEC_T3_CC4 ((uint32_t)( ADC_CR2_JEXTSEL_2 )) |
||
| 187 | #define ADC_EXTERNALTRIGINJEC_T4_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_0)) |
||
| 188 | #define ADC_EXTERNALTRIGINJEC_T4_CC1 ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 )) |
||
| 189 | #define ADC_EXTERNALTRIGINJEC_T4_CC2 ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0)) |
||
| 190 | #define ADC_EXTERNALTRIGINJEC_T4_CC3 ((uint32_t)(ADC_CR2_JEXTSEL_3 )) |
||
| 191 | #define ADC_EXTERNALTRIGINJEC_T10_CC1 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_0)) |
||
| 192 | #define ADC_EXTERNALTRIGINJEC_T7_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_1 )) |
||
| 193 | #define ADC_EXTERNALTRIGINJEC_EXT_IT15 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0)) |
||
| 194 | /** |
||
| 195 | * @} |
||
| 196 | */ |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @} |
||
| 200 | */ |
||
| 201 | |||
| 202 | |||
| 203 | /* Exported macro ------------------------------------------------------------*/ |
||
| 204 | |||
| 205 | /** @defgroup ADCEx_Exported_Macros ADCEx Exported Macros |
||
| 206 | * @{ |
||
| 207 | */ |
||
| 208 | /* Macro for internal HAL driver usage, and possibly can be used into code of */ |
||
| 209 | /* final user. */ |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @brief Selection of channels bank. |
||
| 213 | * Note: Banks availability depends on devices categories. |
||
| 214 | * This macro is intended to change bank selection quickly on the fly, |
||
| 215 | * without going through ADC init structure update and execution of function |
||
| 216 | * 'HAL_ADC_Init()'. |
||
| 217 | * @param __HANDLE__: ADC handle |
||
| 218 | * @param __BANK__: Bank selection. This parameter can be a value of @ref ADC_ChannelsBank. |
||
| 219 | * @retval None |
||
| 220 | */ |
||
| 221 | #define __HAL_ADC_CHANNELS_BANK(__HANDLE__, __BANK__) \ |
||
| 222 | MODIFY_REG((__HANDLE__)->Instance->CR2, ADC_CR2_CFG, (__BANK__)) |
||
| 223 | |||
| 224 | #if defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 225 | /** |
||
| 226 | * @brief Configures the ADC channels speed. |
||
| 227 | * Limited to channels 3, 8, 13 and to devices category Cat.3, Cat.4, Cat.5. |
||
| 228 | * - For ADC_CHANNEL_3: Used as ADC direct channel (fast channel) if OPAMP1 is |
||
| 229 | * in power down mode. |
||
| 230 | * - For ADC_CHANNEL_8: Used as ADC direct channel (fast channel) if OPAMP2 is |
||
| 231 | * in power down mode. |
||
| 232 | * - For ADC_CHANNEL_13: Used as ADC re-routed channel if OPAMP3 is in |
||
| 233 | * power down mode. Otherwise, channel 13 is connected to OPAMP3 output and |
||
| 234 | * routed through switches COMP1_SW1 and VCOMP to ADC switch matrix. |
||
| 235 | * (Note: OPAMP3 is available on STM32L1 Cat.4 only). |
||
| 236 | * @param __CHANNEL__: ADC channel |
||
| 237 | * This parameter can be one of the following values: |
||
| 238 | * @arg ADC_CHANNEL_3: Channel 3 is selected. |
||
| 239 | * @arg ADC_CHANNEL_8: Channel 8 is selected. |
||
| 240 | * @arg ADC_CHANNEL_13: Channel 13 is selected. |
||
| 241 | * @retval None |
||
| 242 | */ |
||
| 243 | #define __HAL_ADC_CHANNEL_SPEED_FAST(__CHANNEL__) \ |
||
| 244 | ( ( ((__CHANNEL__) == ADC_CHANNEL_3) \ |
||
| 245 | )? \ |
||
| 246 | (SET_BIT(COMP->CSR, COMP_CSR_FCH3)) \ |
||
| 247 | : \ |
||
| 248 | ( ( ((__CHANNEL__) == ADC_CHANNEL_8) \ |
||
| 249 | )? \ |
||
| 250 | (SET_BIT(COMP->CSR, COMP_CSR_FCH8)) \ |
||
| 251 | : \ |
||
| 252 | ( ( ((__CHANNEL__) == ADC_CHANNEL_13) \ |
||
| 253 | )? \ |
||
| 254 | (SET_BIT(COMP->CSR, COMP_CSR_RCH13)) \ |
||
| 255 | : \ |
||
| 256 | (SET_BIT(COMP->CSR, 0x00000000)) \ |
||
| 257 | ) \ |
||
| 258 | ) \ |
||
| 259 | ) |
||
| 260 | |||
| 261 | #define __HAL_ADC_CHANNEL_SPEED_SLOW(__CHANNEL__) \ |
||
| 262 | ( ( ((__CHANNEL__) == ADC_CHANNEL_3) \ |
||
| 263 | )? \ |
||
| 264 | (CLEAR_BIT(COMP->CSR, COMP_CSR_FCH3)) \ |
||
| 265 | : \ |
||
| 266 | ( ( ((__CHANNEL__) == ADC_CHANNEL_8) \ |
||
| 267 | )? \ |
||
| 268 | (CLEAR_BIT(COMP->CSR, COMP_CSR_FCH8)) \ |
||
| 269 | : \ |
||
| 270 | ( ( ((__CHANNEL__) == ADC_CHANNEL_13) \ |
||
| 271 | )? \ |
||
| 272 | (CLEAR_BIT(COMP->CSR, COMP_CSR_RCH13)) \ |
||
| 273 | : \ |
||
| 274 | (SET_BIT(COMP->CSR, 0x00000000)) \ |
||
| 275 | ) \ |
||
| 276 | ) \ |
||
| 277 | ) |
||
| 278 | #endif /* STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @} |
||
| 282 | */ |
||
| 283 | |||
| 284 | /* Private macro ------------------------------------------------------------*/ |
||
| 285 | |||
| 286 | /** @defgroup ADCEx_Private_Macro ADCEx Private Macro |
||
| 287 | * @{ |
||
| 288 | */ |
||
| 289 | /* Macro reserved for internal HAL driver usage, not intended to be used in */ |
||
| 290 | /* code of final user. */ |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @brief Set ADC ranks available in register SQR1. |
||
| 294 | * Register SQR1 bits availability depends on device category. |
||
| 295 | * @param _NbrOfConversion_: Regular channel sequence length |
||
| 296 | * @retval None |
||
| 297 | */ |
||
| 298 | #if defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 299 | #define __ADC_SQR1_SQXX (ADC_SQR1_SQ28 | ADC_SQR1_SQ27 | ADC_SQR1_SQ26 | ADC_SQR1_SQ25) |
||
| 300 | #else |
||
| 301 | #define __ADC_SQR1_SQXX (ADC_SQR1_SQ27 | ADC_SQR1_SQ26 | ADC_SQR1_SQ25) |
||
| 302 | #endif /* STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @brief Set the ADC's sample time for channel numbers between 30 and 31. |
||
| 306 | * Register SMPR0 availability depends on device category. If register is not |
||
| 307 | * available on the current device, this macro does nothing. |
||
| 308 | * @retval None |
||
| 309 | * @param _SAMPLETIME_: Sample time parameter. |
||
| 310 | * @param _CHANNELNB_: Channel number. |
||
| 311 | * @retval None |
||
| 312 | */ |
||
| 313 | #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 314 | #define ADC_SMPR0(_SAMPLETIME_, _CHANNELNB_) \ |
||
| 315 | ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 30))) |
||
| 316 | #else |
||
| 317 | #define ADC_SMPR0(_SAMPLETIME_, _CHANNELNB_) \ |
||
| 28 | mjames | 318 | (0x00000000U) |
| 2 | mjames | 319 | #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
| 320 | |||
| 321 | #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 322 | /** |
||
| 323 | * @brief Set the ADC's sample time for channel numbers between 20 and 29. |
||
| 324 | * @param _SAMPLETIME_: Sample time parameter. |
||
| 325 | * @param _CHANNELNB_: Channel number. |
||
| 326 | * @retval None |
||
| 327 | */ |
||
| 328 | #define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) \ |
||
| 329 | ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 20))) |
||
| 330 | #else |
||
| 331 | /** |
||
| 332 | * @brief Set the ADC's sample time for channel numbers between 20 and 26. |
||
| 333 | * @param _SAMPLETIME_: Sample time parameter. |
||
| 334 | * @param _CHANNELNB_: Channel number. |
||
| 335 | * @retval None |
||
| 336 | */ |
||
| 337 | #define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) \ |
||
| 338 | ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 20))) |
||
| 339 | #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @brief Defines the highest channel available in register SMPR1. Channels |
||
| 343 | * availability depends on device category: |
||
| 344 | * Highest channel in register SMPR1 is channel 26 for devices Cat.1, Cat.2, Cat.3 |
||
| 345 | * Highest channel in register SMPR1 is channel 29 for devices Cat.4, Cat.5 |
||
| 346 | * @param None |
||
| 347 | * @retval None |
||
| 348 | */ |
||
| 349 | #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 350 | #define ADC_SMPR1_CHANNEL_MAX ADC_CHANNEL_29 |
||
| 351 | #else |
||
| 352 | #define ADC_SMPR1_CHANNEL_MAX ADC_CHANNEL_26 |
||
| 353 | #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
||
| 354 | |||
| 355 | |||
| 356 | /** |
||
| 357 | * @brief Define mask of configuration bits of ADC and regular group in |
||
| 358 | * register CR2 (bits of ADC enable, conversion start and injected group are |
||
| 359 | * excluded of this mask). |
||
| 360 | * @retval None |
||
| 361 | */ |
||
| 362 | #if defined (STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 363 | #define ADC_CR2_MASK_ADCINIT() \ |
||
| 364 | (ADC_CR2_EXTEN | ADC_CR2_EXTSEL | ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | ADC_CR2_DELS | ADC_CR2_CFG | ADC_CR2_CONT) |
||
| 365 | #else |
||
| 366 | #define ADC_CR2_MASK_ADCINIT() \ |
||
| 367 | (ADC_CR2_EXTEN | ADC_CR2_EXTSEL | ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | ADC_CR2_DELS | ADC_CR2_CONT) |
||
| 368 | #endif |
||
| 369 | |||
| 370 | |||
| 371 | /** |
||
| 372 | * @brief Get the maximum ADC conversion cycles on all channels. |
||
| 373 | * Returns the selected sampling time + conversion time (12.5 ADC clock cycles) |
||
| 374 | * Approximation of sampling time within 2 ranges, returns the highest value: |
||
| 375 | * below 24 cycles {4 cycles; 9 cycles; 16 cycles; 24 cycles} |
||
| 376 | * between 48 cycles and 384 cycles {48 cycles; 96 cycles; 192 cycles; 384 cycles} |
||
| 377 | * Unit: ADC clock cycles |
||
| 378 | * @param __HANDLE__: ADC handle |
||
| 379 | * @retval ADC conversion cycles on all channels |
||
| 380 | */ |
||
| 381 | #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 382 | #define ADC_CONVCYCLES_MAX_RANGE(__HANDLE__) \ |
||
| 383 | (( (((__HANDLE__)->Instance->SMPR3 & ADC_SAMPLETIME_ALLCHANNELS_SMPR3BIT2) == RESET) && \ |
||
| 384 | (((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2) == RESET) && \ |
||
| 385 | (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2) == RESET) && \ |
||
| 386 | (((__HANDLE__)->Instance->SMPR0 & ADC_SAMPLETIME_ALLCHANNELS_SMPR0BIT2) == RESET) ) ? \ |
||
| 387 | \ |
||
| 388 | ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_24CYCLES : ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_384CYCLES \ |
||
| 389 | ) |
||
| 390 | #else |
||
| 391 | #define ADC_CONVCYCLES_MAX_RANGE(__HANDLE__) \ |
||
| 392 | (( (((__HANDLE__)->Instance->SMPR3 & ADC_SAMPLETIME_ALLCHANNELS_SMPR3BIT2) == RESET) && \ |
||
| 393 | (((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2) == RESET) && \ |
||
| 394 | (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2) == RESET) ) ? \ |
||
| 395 | \ |
||
| 396 | ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_24CYCLES : ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_384CYCLES \ |
||
| 397 | ) |
||
| 398 | #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @brief Get the ADC clock prescaler from ADC common control register |
||
| 402 | * and convert it to its decimal number setting (refer to reference manual) |
||
| 403 | * @retval None |
||
| 404 | */ |
||
| 405 | #define ADC_GET_CLOCK_PRESCALER_DECIMAL(__HANDLE__) \ |
||
| 406 | ((0x01) << ((ADC->CCR & ADC_CCR_ADCPRE) >> POSITION_VAL(ADC_CCR_ADCPRE))) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @brief Clear register SMPR0. |
||
| 410 | * Register SMPR0 availability depends on device category. If register is not |
||
| 411 | * available on the current device, this macro performs no action. |
||
| 412 | * @param __HANDLE__: ADC handle |
||
| 413 | * @retval None |
||
| 414 | */ |
||
| 415 | #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 416 | #define ADC_SMPR1_CLEAR(__HANDLE__) \ |
||
| 417 | CLEAR_BIT((__HANDLE__)->Instance->SMPR1, (ADC_SMPR1_SMP29 | ADC_SMPR1_SMP28 | ADC_SMPR1_SMP27 | \ |
||
| 418 | ADC_SMPR1_SMP26 | ADC_SMPR1_SMP25 | ADC_SMPR1_SMP24 | \ |
||
| 419 | ADC_SMPR1_SMP23 | ADC_SMPR1_SMP22 | ADC_SMPR1_SMP21 | \ |
||
| 420 | ADC_SMPR1_SMP20 )) |
||
| 421 | |||
| 422 | #define ADC_SMPR0_CLEAR(__HANDLE__) \ |
||
| 423 | (CLEAR_BIT((__HANDLE__)->Instance->SMPR0, (ADC_SMPR0_SMP31 | ADC_SMPR0_SMP30))) |
||
| 424 | #else |
||
| 425 | #define ADC_SMPR1_CLEAR(__HANDLE__) \ |
||
| 426 | CLEAR_BIT((__HANDLE__)->Instance->SMPR1, (ADC_SMPR1_SMP26 | ADC_SMPR1_SMP25 | ADC_SMPR1_SMP24 | \ |
||
| 427 | ADC_SMPR1_SMP23 | ADC_SMPR1_SMP22 | ADC_SMPR1_SMP21 | \ |
||
| 428 | ADC_SMPR1_SMP20 )) |
||
| 429 | |||
| 430 | #define ADC_SMPR0_CLEAR(__HANDLE__) __NOP() |
||
| 431 | #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
||
| 432 | |||
| 433 | /** |
||
| 434 | * @brief Clear register CR2. |
||
| 435 | * @param __HANDLE__: ADC handle |
||
| 436 | * @retval None |
||
| 437 | */ |
||
| 438 | #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 439 | #define ADC_CR2_CLEAR(__HANDLE__) \ |
||
| 440 | (CLEAR_BIT((__HANDLE__)->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTEN | ADC_CR2_EXTSEL | \ |
||
| 441 | ADC_CR2_JSWSTART | ADC_CR2_JEXTEN | ADC_CR2_JEXTSEL | \ |
||
| 442 | ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | \ |
||
| 443 | ADC_CR2_DMA | ADC_CR2_DELS | ADC_CR2_CFG | \ |
||
| 444 | ADC_CR2_CONT | ADC_CR2_ADON )) \ |
||
| 445 | ) |
||
| 446 | #else |
||
| 447 | #define ADC_CR2_CLEAR(__HANDLE__) \ |
||
| 448 | (CLEAR_BIT((__HANDLE__)->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTEN | ADC_CR2_EXTSEL | \ |
||
| 449 | ADC_CR2_JSWSTART | ADC_CR2_JEXTEN | ADC_CR2_JEXTSEL | \ |
||
| 450 | ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | \ |
||
| 451 | ADC_CR2_DMA | ADC_CR2_DELS | \ |
||
| 452 | ADC_CR2_CONT | ADC_CR2_ADON )) \ |
||
| 453 | ) |
||
| 454 | #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @brief Set the sampling time of selected channel on register SMPR0 |
||
| 458 | * Register SMPR0 availability depends on device category. If register is not |
||
| 459 | * available on the current device, this macro performs no action. |
||
| 460 | * @param __HANDLE__: ADC handle |
||
| 461 | * @param _SAMPLETIME_: Sample time parameter. |
||
| 462 | * @param __CHANNEL__: Channel number. |
||
| 463 | * @retval None |
||
| 464 | */ |
||
| 465 | #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
||
| 466 | #define ADC_SMPR0_CHANNEL_SET(__HANDLE__, _SAMPLETIME_, __CHANNEL__) \ |
||
| 467 | MODIFY_REG((__HANDLE__)->Instance->SMPR0, \ |
||
| 468 | ADC_SMPR0(ADC_SMPR0_SMP30, (__CHANNEL__)), \ |
||
| 469 | ADC_SMPR0((_SAMPLETIME_), (__CHANNEL__)) ) |
||
| 470 | #else |
||
| 471 | #define ADC_SMPR0_CHANNEL_SET(__HANDLE__, _SAMPLETIME_, __CHANNEL__) __NOP() |
||
| 472 | #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
||
| 473 | |||
| 474 | |||
| 475 | #define IS_ADC_INJECTED_RANK(CHANNEL) (((CHANNEL) == ADC_INJECTED_RANK_1) || \ |
||
| 476 | ((CHANNEL) == ADC_INJECTED_RANK_2) || \ |
||
| 477 | ((CHANNEL) == ADC_INJECTED_RANK_3) || \ |
||
| 478 | ((CHANNEL) == ADC_INJECTED_RANK_4) ) |
||
| 479 | |||
| 480 | #define IS_ADC_EXTTRIGINJEC_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE) || \ |
||
| 481 | ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISING) || \ |
||
| 482 | ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_FALLING) || \ |
||
| 483 | ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING) ) |
||
| 484 | |||
| 485 | #define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \ |
||
| 486 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \ |
||
| 487 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \ |
||
| 488 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \ |
||
| 489 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC1) || \ |
||
| 490 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC2) || \ |
||
| 491 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC3) || \ |
||
| 492 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T7_TRGO) || \ |
||
| 493 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T9_CC1) || \ |
||
| 494 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T9_TRGO) || \ |
||
| 495 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T10_CC1) || \ |
||
| 496 | ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \ |
||
| 497 | ((REGTRIG) == ADC_SOFTWARE_START) ) |
||
| 498 | |||
| 499 | /** @defgroup ADCEx_injected_nb_conv_verification ADCEx injected nb conv verification |
||
| 500 | * @{ |
||
| 501 | */ |
||
| 28 | mjames | 502 | #define IS_ADC_INJECTED_NB_CONV(LENGTH) (((LENGTH) >= (1U)) && ((LENGTH) <= (4U))) |
| 2 | mjames | 503 | /** |
| 504 | * @} |
||
| 505 | */ |
||
| 506 | |||
| 507 | /** |
||
| 508 | * @} |
||
| 509 | */ |
||
| 510 | |||
| 511 | |||
| 512 | /* Exported functions --------------------------------------------------------*/ |
||
| 513 | /** @addtogroup ADCEx_Exported_Functions |
||
| 514 | * @{ |
||
| 515 | */ |
||
| 516 | |||
| 517 | /* IO operation functions *****************************************************/ |
||
| 518 | /** @addtogroup ADCEx_Exported_Functions_Group1 |
||
| 519 | * @{ |
||
| 520 | */ |
||
| 521 | |||
| 522 | /* Blocking mode: Polling */ |
||
| 523 | HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc); |
||
| 524 | HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc); |
||
| 525 | HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout); |
||
| 526 | |||
| 527 | /* Non-blocking mode: Interruption */ |
||
| 528 | HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc); |
||
| 529 | HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc); |
||
| 530 | |||
| 531 | /* ADC retrieve conversion value intended to be used with polling or interruption */ |
||
| 532 | uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank); |
||
| 533 | |||
| 534 | /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption) */ |
||
| 535 | void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc); |
||
| 536 | /** |
||
| 537 | * @} |
||
| 538 | */ |
||
| 539 | |||
| 540 | |||
| 541 | /* Peripheral Control functions ***********************************************/ |
||
| 542 | /** @addtogroup ADCEx_Exported_Functions_Group2 |
||
| 543 | * @{ |
||
| 544 | */ |
||
| 545 | |||
| 546 | HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc,ADC_InjectionConfTypeDef* sConfigInjected); |
||
| 547 | /** |
||
| 548 | * @} |
||
| 549 | */ |
||
| 550 | |||
| 551 | |||
| 552 | /** |
||
| 553 | * @} |
||
| 554 | */ |
||
| 555 | |||
| 556 | |||
| 557 | /** |
||
| 558 | * @} |
||
| 559 | */ |
||
| 560 | |||
| 561 | /** |
||
| 562 | * @} |
||
| 563 | */ |
||
| 564 | |||
| 565 | #ifdef __cplusplus |
||
| 566 | } |
||
| 567 | #endif |
||
| 568 | |||
| 569 | #endif /* __STM32L1xx_HAL_ADC_EX_H */ |
||
| 570 | |||
| 571 | |||
| 572 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |