STM32L4xx_HAL_Driver  1.14.0
ADC Extended Peripheral Control functions

ADC Extended Peripheral Control functions. More...

Functions

HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel (ADC_HandleTypeDef *hadc, ADC_InjectionConfTypeDef *sConfigInjected)
 Configure a channel to be assigned to ADC group injected. More...
 
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel (ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode)
 Enable ADC multimode and configure multimode parameters. More...
 
HAL_StatusTypeDef HAL_ADCEx_EnableInjectedQueue (ADC_HandleTypeDef *hadc)
 Enable Injected Queue. More...
 
HAL_StatusTypeDef HAL_ADCEx_DisableInjectedQueue (ADC_HandleTypeDef *hadc)
 Disable Injected Queue. More...
 
HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator (ADC_HandleTypeDef *hadc)
 Disable ADC voltage regulator. More...
 
HAL_StatusTypeDef HAL_ADCEx_EnterADCDeepPowerDownMode (ADC_HandleTypeDef *hadc)
 Enter ADC deep-power-down mode. More...
 

Detailed Description

ADC Extended Peripheral Control functions.

 ===============================================================================
             ##### Peripheral Control functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Configure channels on injected group
      (+) Configure multimode when multimode feature is available
      (+) Enable or Disable Injected Queue
      (+) Disable ADC voltage regulator
      (+) Enter ADC deep-power-down mode

Function Documentation

◆ HAL_ADCEx_DisableInjectedQueue()

HAL_StatusTypeDef HAL_ADCEx_DisableInjectedQueue ( ADC_HandleTypeDef hadc)

Disable Injected Queue.

Note
This function sets CFGR register JQDIS bit in order to disable the Injected Queue. JQDIS can be written only when ADSTART and JDSTART are both equal to 0 to ensure that no regular nor injected conversion is ongoing.
Parameters
hadcADC handle
Return values
HALstatus

Definition at line 2224 of file stm32l4xx_hal_adc_ex.c.

2225 {
2226  HAL_StatusTypeDef tmp_hal_status;
2227  uint32_t tmp_adc_is_conversion_on_going_regular;
2228  uint32_t tmp_adc_is_conversion_on_going_injected;
2229 
2230  /* Check the parameters */
2231  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2232 
2233  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2234  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2235 
2236  /* Parameter can be set only if no conversion is on-going */
2237  if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2238  && (tmp_adc_is_conversion_on_going_injected == 0UL)
2239  )
2240  {
2241  LL_ADC_INJ_SetQueueMode(hadc->Instance, LL_ADC_INJ_QUEUE_DISABLE);
2242  tmp_hal_status = HAL_OK;
2243  }
2244  else
2245  {
2246  tmp_hal_status = HAL_ERROR;
2247  }
2248 
2249  return tmp_hal_status;
2250 }
return HAL_OK
__STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group injected conversion state. CR JADSTART LL_ADC_INJ_IsConversionOngoing.
__STATIC_INLINE void LL_ADC_INJ_SetQueueMode(ADC_TypeDef *ADCx, uint32_t QueueMode)
Set ADC group injected contexts queue mode.
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADCEx_DisableVoltageRegulator()

HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator ( ADC_HandleTypeDef hadc)

Disable ADC voltage regulator.

Note
Disabling voltage regulator allows to save power. This operation can be carried out only when ADC is disabled.
To enable again the voltage regulator, the user is expected to resort to HAL_ADC_Init() API.
Parameters
hadcADC handle
Return values
HALstatus

Definition at line 2261 of file stm32l4xx_hal_adc_ex.c.

2262 {
2263  HAL_StatusTypeDef tmp_hal_status;
2264 
2265  /* Check the parameters */
2266  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2267 
2268  /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */
2269  if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
2270  {
2271  LL_ADC_DisableInternalRegulator(hadc->Instance);
2272  tmp_hal_status = HAL_OK;
2273  }
2274  else
2275  {
2276  tmp_hal_status = HAL_ERROR;
2277  }
2278 
2279  return tmp_hal_status;
2280 }
__STATIC_INLINE void LL_ADC_DisableInternalRegulator(ADC_TypeDef *ADCx)
Disable ADC internal voltage regulator.
__STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
Get the selected ADC instance enable state.
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADCEx_EnableInjectedQueue()

HAL_StatusTypeDef HAL_ADCEx_EnableInjectedQueue ( ADC_HandleTypeDef hadc)

Enable Injected Queue.

Note
This function resets CFGR register JQDIS bit in order to enable the Injected Queue. JQDIS can be written only when ADSTART and JDSTART are both equal to 0 to ensure that no regular nor injected conversion is ongoing.
Parameters
hadcADC handle
Return values
HALstatus

Definition at line 2183 of file stm32l4xx_hal_adc_ex.c.

2184 {
2185  HAL_StatusTypeDef tmp_hal_status;
2186  uint32_t tmp_adc_is_conversion_on_going_regular;
2187  uint32_t tmp_adc_is_conversion_on_going_injected;
2188 
2189  /* Check the parameters */
2190  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2191 
2192  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2193  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2194 
2195  /* Parameter can be set only if no conversion is on-going */
2196  if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2197  && (tmp_adc_is_conversion_on_going_injected == 0UL)
2198  )
2199  {
2200  CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
2201 
2202  /* Update state, clear previous result related to injected queue overflow */
2203  CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_JQOVF);
2204 
2205  tmp_hal_status = HAL_OK;
2206  }
2207  else
2208  {
2209  tmp_hal_status = HAL_ERROR;
2210  }
2211 
2212  return tmp_hal_status;
2213 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
__STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group injected conversion state. CR JADSTART LL_ADC_INJ_IsConversionOngoing.
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADCEx_EnterADCDeepPowerDownMode()

HAL_StatusTypeDef HAL_ADCEx_EnterADCDeepPowerDownMode ( ADC_HandleTypeDef hadc)

Enter ADC deep-power-down mode.

Note
This mode is achieved in setting DEEPPWD bit and allows to save power in reducing leakage currents. It is particularly interesting before entering stop modes.
Setting DEEPPWD automatically clears ADVREGEN bit and disables the ADC voltage regulator. This means that this API encompasses HAL_ADCEx_DisableVoltageRegulator(). Additionally, the internal calibration is lost.
To exit the ADC deep-power-down mode, the user is expected to resort to HAL_ADC_Init() API as well as to relaunch a calibration with HAL_ADCEx_Calibration_Start() API or to re-apply a previously saved calibration factor.
Parameters
hadcADC handle
Return values
HALstatus

Definition at line 2298 of file stm32l4xx_hal_adc_ex.c.

2299 {
2300  HAL_StatusTypeDef tmp_hal_status;
2301 
2302  /* Check the parameters */
2303  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2304 
2305  /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */
2306  if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
2307  {
2308  LL_ADC_EnableDeepPowerDown(hadc->Instance);
2309  tmp_hal_status = HAL_OK;
2310  }
2311  else
2312  {
2313  tmp_hal_status = HAL_ERROR;
2314  }
2315 
2316  return tmp_hal_status;
2317 }
__STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
Get the selected ADC instance enable state.
return HAL_OK
__STATIC_INLINE void LL_ADC_EnableDeepPowerDown(ADC_TypeDef *ADCx)
Put ADC instance in deep power down state.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADCEx_InjectedConfigChannel()

HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel ( ADC_HandleTypeDef hadc,
ADC_InjectionConfTypeDef sConfigInjected 
)

Configure a channel to be assigned to ADC group injected.

Note
Possibility to update parameters on the fly: This function initializes injected group, following calls to this function can be used to reconfigure some parameters of structure "ADC_InjectionConfTypeDef" on the fly, without resetting the ADC. The setting of these parameters is conditioned to ADC state: Refer to comments of structure "ADC_InjectionConfTypeDef".
In case of usage of internal measurement channels: Vbat/VrefInt/TempSensor. These internal paths can be disabled using function HAL_ADC_DeInit().
Caution: For Injected Context Queue use, a context must be fully defined before start of injected conversion. All channels are configured consecutively for the same ADC instance. Therefore, the number of calls to HAL_ADCEx_InjectedConfigChannel() must be equal to the value of parameter InjectedNbrOfConversion for each context.
  • Example 1: If 1 context is intended to be used (or if there is no use of the Injected Queue Context feature) and if the context contains 3 injected ranks (InjectedNbrOfConversion = 3), HAL_ADCEx_InjectedConfigChannel() must be called once for each channel (i.e. 3 times) before starting a conversion. This function must not be called to configure a 4th injected channel: it would start a new context into context queue.
  • Example 2: If 2 contexts are intended to be used and each of them contains 3 injected ranks (InjectedNbrOfConversion = 3), HAL_ADCEx_InjectedConfigChannel() must be called once for each channel and for each context (3 channels x 2 contexts = 6 calls). Conversion can start once the 1st context is set, that is after the first three HAL_ADCEx_InjectedConfigChannel() calls. The 2nd context can be set on the fly.
Parameters
hadcADC handle
sConfigInjectedStructure of ADC injected group and ADC channel for injected group.
Return values
HALstatus

Definition at line 1631 of file stm32l4xx_hal_adc_ex.c.

1632 {
1633  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
1634  uint32_t tmpOffsetShifted;
1635  uint32_t tmp_config_internal_channel;
1636  uint32_t tmp_adc_is_conversion_on_going_regular;
1637  uint32_t tmp_adc_is_conversion_on_going_injected;
1638  __IO uint32_t wait_loop_index = 0;
1639 
1640  uint32_t tmp_JSQR_ContextQueueBeingBuilt = 0U;
1641 
1642  /* Check the parameters */
1643  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1644  assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime));
1645  assert_param(IS_ADC_SINGLE_DIFFERENTIAL(sConfigInjected->InjectedSingleDiff));
1646  assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv));
1647  assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->QueueInjectedContext));
1648  assert_param(IS_ADC_EXTTRIGINJEC_EDGE(sConfigInjected->ExternalTrigInjecConvEdge));
1649  assert_param(IS_ADC_EXTTRIGINJEC(hadc, sConfigInjected->ExternalTrigInjecConv));
1650  assert_param(IS_ADC_OFFSET_NUMBER(sConfigInjected->InjectedOffsetNumber));
1651  assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset));
1652  assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjecOversamplingMode));
1653 
1654  if (hadc->Init.ScanConvMode != ADC_SCAN_DISABLE)
1655  {
1656  assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
1657  assert_param(IS_ADC_INJECTED_NB_CONV(sConfigInjected->InjectedNbrOfConversion));
1658  assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
1659  }
1660 
1661 
1662  /* if JOVSE is set, the value of the OFFSETy_EN bit in ADCx_OFRy register is
1663  ignored (considered as reset) */
1664  assert_param(!((sConfigInjected->InjectedOffsetNumber != ADC_OFFSET_NONE) && (sConfigInjected->InjecOversamplingMode == ENABLE)));
1665 
1666  /* JDISCEN and JAUTO bits can't be set at the same time */
1667  assert_param(!((sConfigInjected->InjectedDiscontinuousConvMode == ENABLE) && (sConfigInjected->AutoInjectedConv == ENABLE)));
1668 
1669  /* DISCEN and JAUTO bits can't be set at the same time */
1670  assert_param(!((hadc->Init.DiscontinuousConvMode == ENABLE) && (sConfigInjected->AutoInjectedConv == ENABLE)));
1671 
1672  /* Verification of channel number */
1673  if (sConfigInjected->InjectedSingleDiff != ADC_DIFFERENTIAL_ENDED)
1674  {
1675  assert_param(IS_ADC_CHANNEL(hadc, sConfigInjected->InjectedChannel));
1676  }
1677  else
1678  {
1679  assert_param(IS_ADC_DIFF_CHANNEL(hadc, sConfigInjected->InjectedChannel));
1680  }
1681 
1682  /* Process locked */
1683  __HAL_LOCK(hadc);
1684 
1685  /* Configuration of injected group sequencer: */
1686  /* Hardware constraint: Must fully define injected context register JSQR */
1687  /* before make it entering into injected sequencer queue. */
1688  /* */
1689  /* - if scan mode is disabled: */
1690  /* * Injected channels sequence length is set to 0x00: 1 channel */
1691  /* converted (channel on injected rank 1) */
1692  /* Parameter "InjectedNbrOfConversion" is discarded. */
1693  /* * Injected context register JSQR setting is simple: register is fully */
1694  /* defined on one call of this function (for injected rank 1) and can */
1695  /* be entered into queue directly. */
1696  /* - if scan mode is enabled: */
1697  /* * Injected channels sequence length is set to parameter */
1698  /* "InjectedNbrOfConversion". */
1699  /* * Injected context register JSQR setting more complex: register is */
1700  /* fully defined over successive calls of this function, for each */
1701  /* injected channel rank. It is entered into queue only when all */
1702  /* injected ranks have been set. */
1703  /* Note: Scan mode is not present by hardware on this device, but used */
1704  /* by software for alignment over all STM32 devices. */
1705 
1706  if ((hadc->Init.ScanConvMode == ADC_SCAN_DISABLE) ||
1707  (sConfigInjected->InjectedNbrOfConversion == 1U))
1708  {
1709  /* Configuration of context register JSQR: */
1710  /* - number of ranks in injected group sequencer: fixed to 1st rank */
1711  /* (scan mode disabled, only rank 1 used) */
1712  /* - external trigger to start conversion */
1713  /* - external trigger polarity */
1714  /* - channel set to rank 1 (scan mode disabled, only rank 1 can be used) */
1715 
1716  if (sConfigInjected->InjectedRank == ADC_INJECTED_RANK_1)
1717  {
1718  /* Enable external trigger if trigger selection is different of */
1719  /* software start. */
1720  /* Note: This configuration keeps the hardware feature of parameter */
1721  /* ExternalTrigInjecConvEdge "trigger edge none" equivalent to */
1722  /* software start. */
1723  if (sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
1724  {
1725  tmp_JSQR_ContextQueueBeingBuilt = (ADC_JSQR_RK(sConfigInjected->InjectedChannel, ADC_INJECTED_RANK_1)
1726  | (sConfigInjected->ExternalTrigInjecConv & ADC_JSQR_JEXTSEL)
1727  | sConfigInjected->ExternalTrigInjecConvEdge
1728  );
1729  }
1730  else
1731  {
1732  tmp_JSQR_ContextQueueBeingBuilt = (ADC_JSQR_RK(sConfigInjected->InjectedChannel, ADC_INJECTED_RANK_1));
1733  }
1734 
1735  MODIFY_REG(hadc->Instance->JSQR, ADC_JSQR_FIELDS, tmp_JSQR_ContextQueueBeingBuilt);
1736  /* For debug and informative reasons, hadc handle saves JSQR setting */
1737  hadc->InjectionConfig.ContextQueue = tmp_JSQR_ContextQueueBeingBuilt;
1738 
1739  }
1740  }
1741  else
1742  {
1743  /* Case of scan mode enabled, several channels to set into injected group */
1744  /* sequencer. */
1745  /* */
1746  /* Procedure to define injected context register JSQR over successive */
1747  /* calls of this function, for each injected channel rank: */
1748  /* 1. Start new context and set parameters related to all injected */
1749  /* channels: injected sequence length and trigger. */
1750 
1751  /* if hadc->InjectionConfig.ChannelCount is equal to 0, this is the first */
1752  /* call of the context under setting */
1753  if (hadc->InjectionConfig.ChannelCount == 0U)
1754  {
1755  /* Initialize number of channels that will be configured on the context */
1756  /* being built */
1757  hadc->InjectionConfig.ChannelCount = sConfigInjected->InjectedNbrOfConversion;
1758  /* Handle hadc saves the context under build up over each HAL_ADCEx_InjectedConfigChannel()
1759  call, this context will be written in JSQR register at the last call.
1760  At this point, the context is merely reset */
1761  hadc->InjectionConfig.ContextQueue = 0x00000000U;
1762 
1763  /* Configuration of context register JSQR: */
1764  /* - number of ranks in injected group sequencer */
1765  /* - external trigger to start conversion */
1766  /* - external trigger polarity */
1767 
1768  /* Enable external trigger if trigger selection is different of */
1769  /* software start. */
1770  /* Note: This configuration keeps the hardware feature of parameter */
1771  /* ExternalTrigInjecConvEdge "trigger edge none" equivalent to */
1772  /* software start. */
1773  if (sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
1774  {
1775  tmp_JSQR_ContextQueueBeingBuilt = ((sConfigInjected->InjectedNbrOfConversion - 1U)
1776  | (sConfigInjected->ExternalTrigInjecConv & ADC_JSQR_JEXTSEL)
1777  | sConfigInjected->ExternalTrigInjecConvEdge
1778  );
1779  }
1780  else
1781  {
1782  tmp_JSQR_ContextQueueBeingBuilt = ((sConfigInjected->InjectedNbrOfConversion - 1U));
1783  }
1784 
1785  }
1786 
1787  /* 2. Continue setting of context under definition with parameter */
1788  /* related to each channel: channel rank sequence */
1789  /* Clear the old JSQx bits for the selected rank */
1790  tmp_JSQR_ContextQueueBeingBuilt &= ~ADC_JSQR_RK(ADC_SQR3_SQ10, sConfigInjected->InjectedRank);
1791 
1792  /* Set the JSQx bits for the selected rank */
1793  tmp_JSQR_ContextQueueBeingBuilt |= ADC_JSQR_RK(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank);
1794 
1795  /* Decrease channel count */
1796  hadc->InjectionConfig.ChannelCount--;
1797 
1798  /* 3. tmp_JSQR_ContextQueueBeingBuilt is fully built for this HAL_ADCEx_InjectedConfigChannel()
1799  call, aggregate the setting to those already built during the previous
1800  HAL_ADCEx_InjectedConfigChannel() calls (for the same context of course) */
1801  hadc->InjectionConfig.ContextQueue |= tmp_JSQR_ContextQueueBeingBuilt;
1802 
1803  /* 4. End of context setting: if this is the last channel set, then write context
1804  into register JSQR and make it enter into queue */
1805  if (hadc->InjectionConfig.ChannelCount == 0U)
1806  {
1807  MODIFY_REG(hadc->Instance->JSQR, ADC_JSQR_FIELDS, hadc->InjectionConfig.ContextQueue);
1808  }
1809  }
1810 
1811  /* Parameters update conditioned to ADC state: */
1812  /* Parameters that can be updated when ADC is disabled or enabled without */
1813  /* conversion on going on injected group: */
1814  /* - Injected context queue: Queue disable (active context is kept) or */
1815  /* enable (context decremented, up to 2 contexts queued) */
1816  /* - Injected discontinuous mode: can be enabled only if auto-injected */
1817  /* mode is disabled. */
1818  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1819  {
1820  /* If auto-injected mode is disabled: no constraint */
1821  if (sConfigInjected->AutoInjectedConv == DISABLE)
1822  {
1823  MODIFY_REG(hadc->Instance->CFGR,
1824  ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
1825  ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext) |
1826  ADC_CFGR_INJECT_DISCCONTINUOUS((uint32_t)sConfigInjected->InjectedDiscontinuousConvMode));
1827  }
1828  /* If auto-injected mode is enabled: Injected discontinuous setting is */
1829  /* discarded. */
1830  else
1831  {
1832  MODIFY_REG(hadc->Instance->CFGR,
1833  ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
1834  ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext));
1835  }
1836 
1837  }
1838 
1839  /* Parameters update conditioned to ADC state: */
1840  /* Parameters that can be updated when ADC is disabled or enabled without */
1841  /* conversion on going on regular and injected groups: */
1842  /* - Automatic injected conversion: can be enabled if injected group */
1843  /* external triggers are disabled. */
1844  /* - Channel sampling time */
1845  /* - Channel offset */
1846  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
1847  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
1848 
1849  if ((tmp_adc_is_conversion_on_going_regular == 0UL)
1850  && (tmp_adc_is_conversion_on_going_injected == 0UL)
1851  )
1852  {
1853  /* If injected group external triggers are disabled (set to injected */
1854  /* software start): no constraint */
1855  if ((sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START)
1856  || (sConfigInjected->ExternalTrigInjecConvEdge == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE))
1857  {
1858  if (sConfigInjected->AutoInjectedConv == ENABLE)
1859  {
1860  SET_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
1861  }
1862  else
1863  {
1864  CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
1865  }
1866  }
1867  /* If Automatic injected conversion was intended to be set and could not */
1868  /* due to injected group external triggers enabled, error is reported. */
1869  else
1870  {
1871  if (sConfigInjected->AutoInjectedConv == ENABLE)
1872  {
1873  /* Update ADC state machine to error */
1874  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1875 
1876  tmp_hal_status = HAL_ERROR;
1877  }
1878  else
1879  {
1880  CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
1881  }
1882  }
1883 
1884  if (sConfigInjected->InjecOversamplingMode == ENABLE)
1885  {
1886  assert_param(IS_ADC_OVERSAMPLING_RATIO(sConfigInjected->InjecOversampling.Ratio));
1887  assert_param(IS_ADC_RIGHT_BIT_SHIFT(sConfigInjected->InjecOversampling.RightBitShift));
1888 
1889  /* JOVSE must be reset in case of triggered regular mode */
1890  assert_param(!(READ_BIT(hadc->Instance->CFGR2, ADC_CFGR2_ROVSE | ADC_CFGR2_TROVS) == (ADC_CFGR2_ROVSE | ADC_CFGR2_TROVS)));
1891 
1892  /* Configuration of Injected Oversampler: */
1893  /* - Oversampling Ratio */
1894  /* - Right bit shift */
1895 
1896  /* Enable OverSampling mode */
1897  MODIFY_REG(hadc->Instance->CFGR2,
1898  ADC_CFGR2_JOVSE |
1899  ADC_CFGR2_OVSR |
1900  ADC_CFGR2_OVSS,
1901  ADC_CFGR2_JOVSE |
1902  sConfigInjected->InjecOversampling.Ratio |
1903  sConfigInjected->InjecOversampling.RightBitShift
1904  );
1905  }
1906  else
1907  {
1908  /* Disable Regular OverSampling */
1909  CLEAR_BIT(hadc->Instance->CFGR2, ADC_CFGR2_JOVSE);
1910  }
1911 
1912 #if defined(ADC_SMPR1_SMPPLUS)
1913  /* Manage specific case of sampling time 3.5 cycles replacing 2.5 cyles */
1914  if (sConfigInjected->InjectedSamplingTime == ADC_SAMPLETIME_3CYCLES_5)
1915  {
1916  /* Set sampling time of the selected ADC channel */
1917  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfigInjected->InjectedChannel, LL_ADC_SAMPLINGTIME_2CYCLES_5);
1918 
1919  /* Set ADC sampling time common configuration */
1920  LL_ADC_SetSamplingTimeCommonConfig(hadc->Instance, LL_ADC_SAMPLINGTIME_COMMON_3C5_REPL_2C5);
1921  }
1922  else
1923  {
1924  /* Set sampling time of the selected ADC channel */
1925  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSamplingTime);
1926 
1927  /* Set ADC sampling time common configuration */
1928  LL_ADC_SetSamplingTimeCommonConfig(hadc->Instance, LL_ADC_SAMPLINGTIME_COMMON_DEFAULT);
1929  }
1930 #else
1931  /* Set sampling time of the selected ADC channel */
1932  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSamplingTime);
1933 #endif
1934 
1935  /* Configure the offset: offset enable/disable, channel, offset value */
1936 
1937  /* Shift the offset with respect to the selected ADC resolution. */
1938  /* Offset has to be left-aligned on bit 11, the LSB (right bits) are set to 0 */
1939  tmpOffsetShifted = ADC_OFFSET_SHIFT_RESOLUTION(hadc, sConfigInjected->InjectedOffset);
1940 
1941  if (sConfigInjected->InjectedOffsetNumber != ADC_OFFSET_NONE)
1942  {
1943  /* Set ADC selected offset number */
1944  LL_ADC_SetOffset(hadc->Instance, sConfigInjected->InjectedOffsetNumber, sConfigInjected->InjectedChannel,
1945  tmpOffsetShifted);
1946 
1947  }
1948  else
1949  {
1950  /* Scan each offset register to check if the selected channel is targeted. */
1951  /* If this is the case, the corresponding offset number is disabled. */
1952  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_1)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
1953  {
1954  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_1, LL_ADC_OFFSET_DISABLE);
1955  }
1956  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_2)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
1957  {
1958  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_2, LL_ADC_OFFSET_DISABLE);
1959  }
1960  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_3)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
1961  {
1962  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_3, LL_ADC_OFFSET_DISABLE);
1963  }
1964  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_4)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
1965  {
1966  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_4, LL_ADC_OFFSET_DISABLE);
1967  }
1968  }
1969 
1970  }
1971 
1972  /* Parameters update conditioned to ADC state: */
1973  /* Parameters that can be updated only when ADC is disabled: */
1974  /* - Single or differential mode */
1975  if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
1976  {
1977  /* Set mode single-ended or differential input of the selected ADC channel */
1978  LL_ADC_SetChannelSingleDiff(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSingleDiff);
1979 
1980  /* Configuration of differential mode */
1981  /* Note: ADC channel number masked with value "0x1F" to ensure shift value within 32 bits range */
1982  if (sConfigInjected->InjectedSingleDiff == ADC_DIFFERENTIAL_ENDED)
1983  {
1984  /* Set sampling time of the selected ADC channel */
1985  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);
1986  }
1987 
1988  }
1989 
1990  /* Management of internal measurement channels: Vbat/VrefInt/TempSensor */
1991  /* internal measurement paths enable: If internal channel selected, */
1992  /* enable dedicated internal buffers and path. */
1993  /* Note: these internal measurement paths can be disabled using */
1994  /* HAL_ADC_DeInit(). */
1995 
1996  if (__LL_ADC_IS_CHANNEL_INTERNAL(sConfigInjected->InjectedChannel))
1997  {
1998  tmp_config_internal_channel = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
1999 
2000  /* If the requested internal measurement path has already been enabled, */
2001  /* bypass the configuration processing. */
2002  if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR)
2003  && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0UL))
2004  {
2005  if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc))
2006  {
2007  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2008  LL_ADC_PATH_INTERNAL_TEMPSENSOR | tmp_config_internal_channel);
2009 
2010  /* Delay for temperature sensor stabilization time */
2011  /* Wait loop initialization and execution */
2012  /* Note: Variable divided by 2 to compensate partially */
2013  /* CPU processing cycles, scaling in us split to not */
2014  /* exceed 32 bits register capacity and handle low frequency. */
2015  wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
2016  while (wait_loop_index != 0UL)
2017  {
2018  wait_loop_index--;
2019  }
2020  }
2021  }
2022  else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT)
2023  && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VBAT) == 0UL))
2024  {
2025  if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc))
2026  {
2027  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2028  LL_ADC_PATH_INTERNAL_VBAT | tmp_config_internal_channel);
2029  }
2030  }
2031  else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)
2032  && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VREFINT) == 0UL))
2033  {
2034  if (ADC_VREFINT_INSTANCE(hadc))
2035  {
2036  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2037  LL_ADC_PATH_INTERNAL_VREFINT | tmp_config_internal_channel);
2038  }
2039  }
2040  else
2041  {
2042  /* nothing to do */
2043  }
2044  }
2045 
2046  /* Process unlocked */
2047  __HAL_UNLOCK(hadc);
2048 
2049  /* Return function status */
2050  return tmp_hal_status;
2051 }
__STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
Get the selected ADC instance enable state.
__STATIC_INLINE uint32_t LL_ADC_GetOffsetChannel(ADC_TypeDef *ADCx, uint32_t Offsety)
Get for the ADC selected offset number 1, 2, 3 or 4: Channel to which the offset programmed will be a...
__STATIC_INLINE void LL_ADC_SetChannelSingleDiff(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SingleDiff)
Set mode single-ended or differential input of the selected ADC channel.
__HAL_UNLOCK(hrtc)
__STATIC_INLINE void LL_ADC_SetOffsetState(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t OffsetState)
Set for the ADC selected offset number 1, 2, 3 or 4: force offset state disable or enable without mod...
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
__STATIC_INLINE void LL_ADC_SetChannelSamplingTime(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SamplingTime)
Set sampling time of the selected ADC channel Unit: ADC clock cycles.
return HAL_OK
FunctionalState InjectedDiscontinuousConvMode
__STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group injected conversion state. CR JADSTART LL_ADC_INJ_IsConversionOngoing.
__STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON)
Get parameter common to several ADC: measurement path to internal channels (VrefInt, temperature sensor, ...).
ADC_InjOversamplingTypeDef InjecOversampling
__STATIC_INLINE void LL_ADC_SetOffset(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t Channel, uint32_t OffsetLevel)
Set ADC selected offset number 1, 2, 3 or 4.
FunctionalState QueueInjectedContext
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
FunctionalState InjecOversamplingMode
__STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
Set parameter common to several ADC: measurement path to internal channels (VrefInt, temperature sensor, ...).
__STATIC_INLINE void LL_ADC_SetSamplingTimeCommonConfig(ADC_TypeDef *ADCx, uint32_t SamplingTimeCommonConfig)
Set ADC sampling time common configuration impacting settings of sampling time channel wise...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADCEx_MultiModeConfigChannel()

HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel ( ADC_HandleTypeDef hadc,
ADC_MultiModeTypeDef multimode 
)

Enable ADC multimode and configure multimode parameters.

Note
Possibility to update parameters on the fly: This function initializes multimode parameters, following calls to this function can be used to reconfigure some parameters of structure "ADC_MultiModeTypeDef" on the fly, without resetting the ADCs. The setting of these parameters is conditioned to ADC state. For parameters constraints, see comments of structure "ADC_MultiModeTypeDef".
To move back configuration from multimode to single mode, ADC must be reset (using function HAL_ADC_Init() ).
Parameters
hadcMaster ADC handle
multimodeStructure of ADC multimode configuration
Return values
HALstatus

Definition at line 2070 of file stm32l4xx_hal_adc_ex.c.

2071 {
2072  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
2073  ADC_Common_TypeDef *tmpADC_Common;
2074  ADC_HandleTypeDef tmphadcSlave;
2075  uint32_t tmphadcSlave_conversion_on_going;
2076 
2077  /* Check the parameters */
2078  assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
2079  assert_param(IS_ADC_MULTIMODE(multimode->Mode));
2080  if (multimode->Mode != ADC_MODE_INDEPENDENT)
2081  {
2082  assert_param(IS_ADC_DMA_ACCESS_MULTIMODE(multimode->DMAAccessMode));
2083  assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay));
2084  }
2085 
2086  /* Process locked */
2087  __HAL_LOCK(hadc);
2088 
2089  ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
2090 
2091  if (tmphadcSlave.Instance == NULL)
2092  {
2093  /* Update ADC state machine to error */
2094  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2095 
2096  /* Process unlocked */
2097  __HAL_UNLOCK(hadc);
2098 
2099  return HAL_ERROR;
2100  }
2101 
2102  /* Parameters update conditioned to ADC state: */
2103  /* Parameters that can be updated when ADC is disabled or enabled without */
2104  /* conversion on going on regular group: */
2105  /* - Multimode DMA configuration */
2106  /* - Multimode DMA mode */
2107  tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
2108  if ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
2109  && (tmphadcSlave_conversion_on_going == 0UL))
2110  {
2111  /* Pointer to the common control register */
2112  tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance);
2113 
2114  /* If multimode is selected, configure all multimode parameters. */
2115  /* Otherwise, reset multimode parameters (can be used in case of */
2116  /* transition from multimode to independent mode). */
2117  if (multimode->Mode != ADC_MODE_INDEPENDENT)
2118  {
2119  MODIFY_REG(tmpADC_Common->CCR, ADC_CCR_MDMA | ADC_CCR_DMACFG,
2120  multimode->DMAAccessMode |
2121  ADC_CCR_MULTI_DMACONTREQ((uint32_t)hadc->Init.DMAContinuousRequests));
2122 
2123  /* Parameters that can be updated only when ADC is disabled: */
2124  /* - Multimode mode selection */
2125  /* - Multimode delay */
2126  /* Note: Delay range depends on selected resolution: */
2127  /* from 1 to 12 clock cycles for 12 bits */
2128  /* from 1 to 10 clock cycles for 10 bits, */
2129  /* from 1 to 8 clock cycles for 8 bits */
2130  /* from 1 to 6 clock cycles for 6 bits */
2131  /* If a higher delay is selected, it will be clipped to maximum delay */
2132  /* range */
2133  if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
2134  {
2135  MODIFY_REG(tmpADC_Common->CCR,
2136  ADC_CCR_DUAL |
2137  ADC_CCR_DELAY,
2138  multimode->Mode |
2139  multimode->TwoSamplingDelay
2140  );
2141  }
2142  }
2143  else /* ADC_MODE_INDEPENDENT */
2144  {
2145  CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_MDMA | ADC_CCR_DMACFG);
2146 
2147  /* Parameters that can be updated only when ADC is disabled: */
2148  /* - Multimode mode selection */
2149  /* - Multimode delay */
2150  if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
2151  {
2152  CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_DUAL | ADC_CCR_DELAY);
2153  }
2154  }
2155  }
2156  /* If one of the ADC sharing the same common group is enabled, no update */
2157  /* could be done on neither of the multimode structure parameters. */
2158  else
2159  {
2160  /* Update ADC state machine to error */
2161  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2162 
2163  tmp_hal_status = HAL_ERROR;
2164  }
2165 
2166  /* Process unlocked */
2167  __HAL_UNLOCK(hadc);
2168 
2169  /* Return function status */
2170  return tmp_hal_status;
2171 }
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
struct __ADC_HandleTypeDef else typedef struct endif ADC_HandleTypeDef
ADC handle Structure definition.
return HAL_OK
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))