HAL ADC Functions

Initialization and de-initialization functions

group ADC_Exported_Functions_Group1

Set of functions allowing to initialize and deinitialize the ADCx peripheral:

Functions

hal_status_t HAL_ADC_Init ( hal_adc_handle_t * hadc , hal_adc_t instance )

Initialize HAL ADC handle and associate it to the selected ADC instance.

Parameters :
Return values :
  • HAL_ERROR – HAL ADC handle is already initialized and can not be modified.

  • HAL_OK – HAL ADC handle has been correctly initialized.

void HAL_ADC_DeInit ( hal_adc_handle_t * hadc )

Deinitialize the ADC peripheral.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

hal_status_t HAL_ADC_SetLinkNextHandle ( hal_adc_handle_t * hadc_a , hal_adc_handle_t * hadc_b )

Link HAL ADC handles belonging to the same ADC common instance.

Note

Requirement: The selected device must have at least 2 ADC instances sharing the same ADC common instance. Refer to device reference manual of ADC LL driver macro “ADC_COMMON_INSTANCE()” returning ADC common instance from ADC instance.

Note

Link can be performed even if not using the common features. It is recommended to systematically link handles (when compliant instances): this allows functions to perform all cross instances checks possible, for optimal HAL ADC driver usage.

Note

Links are used to access multiple HAL ADC handles (daisy chain: from one to another and circular). Used by functions configuring parameters impacting multiple ADC instances.

Note

A handle can be removed from a chain using function HAL_ADC_DeInit() .

Parameters :
  • hadc_a – Pointer to hal_adc_handle_t structure of an ADC instance (not yet linked or already linked to a chain)

  • hadc_b – Pointer to hal_adc_handle_t structure of another ADC instance sharing the same ADC common instance (not yet linked: to be added to an existing chain)

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_SetDMA ( hal_adc_handle_t * hadc , hal_dma_handle_t * hdma )

Link a HAL ADC handle and a HAL DMA handle for conversion data from ADC group regular.

Parameters :
  • hadc – Pointer to HAL ADC handle.

  • hdma – Pointer to HAL DMA handle.

Return values :

HAL_OK – HAL ADC handle has been correctly configured.

Configuration functions (mandatory features)

group ADC_Exported_Functions_Group2_1

Set of functions allowing to configure ADCx peripheral (mandatory features): Mandatory features for some process functions (at least some of these functions must be used but not necessarily all, depending on process functions used).

Note

For necessary configurations functions, refer to state machine diagram or “How to use the ADC HAL module driver” section).

Functions

hal_status_t HAL_ADC_SetConfig ( hal_adc_handle_t * hadc , const hal_adc_config_t * p_config )

Configure ADC instance.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_GetConfig ( const hal_adc_handle_t * hadc , hal_adc_config_t * p_config )

Get the ADC instance configuration.

Parameters :
hal_status_t HAL_ADC_REG_SetConfig ( hal_adc_handle_t * hadc , const hal_adc_reg_config_t * p_config )

Configure ADC group regular.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_REG_GetConfig ( const hal_adc_handle_t * hadc , hal_adc_reg_config_t * p_config )

Get configuration of ADC group regular.

Parameters :
hal_status_t HAL_ADC_INJ_SetConfig ( hal_adc_handle_t * hadc , const hal_adc_inj_config_t * p_config )

Configure ADC group injected.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_INJ_GetConfig ( const hal_adc_handle_t * hadc , hal_adc_inj_config_t * p_config )

Get configuration of ADC group injected.

Parameters :
hal_status_t HAL_ADC_SetConfigChannel ( hal_adc_handle_t * hadc , hal_adc_channel_t channel , const hal_adc_channel_config_t * p_config )

Configure the selected ADC channel.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_GetConfigChannel ( const hal_adc_handle_t * hadc , hal_adc_channel_t channel , hal_adc_channel_config_t * p_config )

Get configuration of the selected ADC channel.

Note

Specific cases:

  • in case of channel set in ADC groups regular and injected, returned value of ADC group is HAL_ADC_GROUP_REGULAR_INJECTED and sequencer rank referring to group regular.

  • in case of channel not set in any ADC group sequencer, returned value of ADC group is HAL_ADC_GROUP_NONE . Value of sequencer rank is not relevant.

  • in case of channel set multiple times in a ADC group sequencer, returned value of sequencer rank is the lowest one.

Parameters :
hal_status_t HAL_ADC_MM_SetConfig ( hal_adc_handle_t * hadc , const hal_adc_mm_config_t * p_config )

Configure ADC multimode.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() .

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_MM_GetConfig ( const hal_adc_handle_t * hadc , hal_adc_mm_config_t * p_config )

Get configuration of ADC multimode.

Parameters :
hal_status_t HAL_ADC_MM_REG_SetMultiDMA ( hal_adc_handle_t * hadc , const uint8_t * p_data , uint32_t size_byte )

Multimode configuration: conversion data of all ADC instances part of multimode are transferred using multiple DMA channels (one DMA channel assigned to each ADC). This function must be called by each HAL ADC handle part of multimode. Then, multimode conversion is started by HAL_ADC_MM_REG_StartConvM_DMA() / M_DMA_Opt().

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • p_data – Pointer to the data buffer.

  • size_byte – Data buffer size (in bytes).

Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

Configuration functions (optional features)

group ADC_Exported_Functions_Group2_2

Set of functions allowing to configure ADCx peripheral (optional features): Same as other configuration functions for optional features: the non usage of these functions will not block any process function.

Functions

hal_status_t HAL_ADC_SetConfigPostProcessing ( hal_adc_handle_t * hadc , const hal_adc_post_processing_config_t * p_config )

Configure ADC instance advanced features: conversion data post processing.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_GetConfigPostProcessing ( const hal_adc_handle_t * hadc , hal_adc_post_processing_config_t * p_config )

Get the ADC instance configuration for advanced features: conversion data post processing.

Note

Returned value of hal_adc_post_processing_config_t field “gain_compensation_x1000” can differ from value set in HAL_ADC_SetConfigPostProcessing() due to computation rounding.

Parameters :
hal_status_t HAL_ADC_SetConfigLowPower ( hal_adc_handle_t * hadc , const hal_adc_low_power_config_t * p_config )

Configure ADC instance advanced features: low power.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_GetConfigLowPower ( const hal_adc_handle_t * hadc , hal_adc_low_power_config_t * p_config )

Get the ADC instance configuration for advanced features: low power.

Parameters :
hal_status_t HAL_ADC_SetVrefProtection ( hal_adc_handle_t * hadc , hal_adc_vref_protection_t vref_protection )

Set ADC instance feature Vref protection.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_adc_vref_protection_t HAL_ADC_GetVrefProtection ( const hal_adc_handle_t * hadc )

Get ADC instance feature Vref protection.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :

Value – of hal_adc_vref_protection_t

hal_status_t HAL_ADC_SetConfigAnalogWD ( hal_adc_handle_t * hadc , hal_adc_awd_instance_t awd_instance , const hal_adc_awd_config_t * p_config )

Configure ADC analog watchdog.

Note

Specific configurations:

  • to monitor all channels, use following parameters values of hal_adc_awd_config_t : .group = definition of group regular and-or injected .channel = HA_ADC_CHANNEL_ALL

  • to disable ADC analog watchdog, use following parameters values: .group = HAL_ADC_GROUP_NONE .channel = HAL_ADC_CHANNEL_NONE (parameters HAL_ADC_GROUP_NONE and HAL_ADC_CHANNEL_NONE must be used together, not separately)

Note

Analog watchdog instances specificities: refer to description of “hal_adc_awd_instance_t”.

Note

For ADC4: in case of oversampling to be used in application, this function must be called after oversampling enable (due to impact on analog watchdog thresholds values).

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_GetConfigAnalogWD ( const hal_adc_handle_t * hadc , hal_adc_awd_instance_t awd_instance , hal_adc_awd_config_t * p_config )

Get configuration of ADC analog watchdog.

Note

Usage of the returned structure field “channel”: To reinject this channel into another function HAL_ADC_xxx: the returned channel number is only partly formatted on definition of literals HAL_ADC_CHANNEL_x. Therefore, it has to be compared with literals HAL_ADC_CHANNEL_x using helper macro LL_ADC_CHANNEL_TO_DECIMAL_NB() .

Note

For ADC4: in case of oversampling enabled, analog watchdog thresholds are rounded with 4 LSB set to 0.

Parameters :
hal_status_t HAL_ADC_SetAnalogWDThresholds ( hal_adc_handle_t * hadc , hal_adc_awd_instance_t awd_instance , hal_adc_awd_threshold_sel_t awd_threshold_sel , int32_t awd_threshold_value )

Configure ADC analog watchdog parameter: thresholds.

Note

Function intended to update analog watchdog thresholds whatever ADC conversion state, on the fly (other analog watchdog parameters require ADC deactivated or no conversion on going)

Note

For ADC4: in case of oversampling to be used in application, this function must be called after oversampling enable (due to impact on analog watchdog thresholds values).

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • awd_instance – Analog watchdog instance.

  • awd_threshold_sel – Analog watchdog threshold selection (high or low)

  • awd_threshold_value – Analog watchdog threshold value. Value is signed and can exceed ADC resolution with post-processing computation (offset, oversampling, data shift, …). ADC1, 2: between Min_Data=-16777216 (two’s complement 0xFF000000) and Max_Data=+16777215 (0x00FFFFFF) ADC4: between Min_Data=0x000 and Max_Data=0xFFF

Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

int32_t HAL_ADC_GetAnalogWDThresholds ( const hal_adc_handle_t * hadc , hal_adc_awd_instance_t awd_instance , hal_adc_awd_threshold_sel_t awd_threshold_sel )

Get ADC analog watchdog parameter: thresholds.

Note

Function intended to update analog watchdog thresholds whatever ADC conversion state, on the fly (other analog watchdog parameters require ADC deactivated or no conversion on going)

Note

For ADC4: in case of oversampling enabled, analog watchdog thresholds are rounded with 4 LSB set to 0.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • awd_instance – Analog watchdog instance.

  • awd_threshold_sel – Analog watchdog threshold selection (high or low)

Return values :

Analog – watchdog threshold value. Value is signed and can exceed ADC resolution with post-processing computation (offset, oversampling, data shift, …). ADC1, 2: between Min_Data=-16777216 (two’s complement 0xFF000000) and Max_Data=+16777215 (0x00FFFFFF) ADC4: between Min_Data=0x000 and Max_Data=0xFFF

hal_status_t HAL_ADC_SetAnalogWDChannel ( hal_adc_handle_t * hadc , hal_adc_awd_instance_t awd_instance , hal_adc_channel_t channel )

Configure ADC analog watchdog parameter: ADC channel.

Note

This function keeps unchanged ADC group configuration monitored by analog watchdog, must have been previously configured. For analog watchdog monitoring to be effective, the selected ADC channel must be converted by this ADC group. If needed to update it, use function HAL_ADC_SetConfigAnalogWD() .

Note

Analog watchdog instances specificities: refer to description of “hal_adc_awd_instance_t”.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • awd_instance – Analog watchdog instance.

  • channel – ADC channel to be monitored

Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_adc_channel_t HAL_ADC_GetAnalogWDChannel ( const hal_adc_handle_t * hadc , hal_adc_awd_instance_t awd_instance )

Get ADC analog watchdog parameter: ADC channel.

Note

This function does not return information of ADC group configuration monitored by analog watchdog. For analog watchdog monitoring to be effective, the selected ADC channel must be converted by this ADC group. If needed to retrieve it, use function HAL_ADC_GetConfigAnalogWD() .

Note

Usage of the returned channel value: To reinject this channel into another function HAL_ADC_xxx: the returned channel number is only partly formatted on definition of literals HAL_ADC_CHANNEL_x. Therefore, it has to be compared with literals HAL_ADC_CHANNEL_x using helper macro LL_ADC_CHANNEL_TO_DECIMAL_NB() .

Note

Analog watchdog instances specificities: refer to description of “hal_adc_awd_instance_t”.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • awd_instance – Analog watchdog instance.

Return values :

ADC – channel partially corresponding to literals of hal_adc_channel_t (the returned value is only partially formatted on definition of hal_adc_channel_t . It can be reinjected in other functions or used with LL_ADC_CHANNEL_TO_DECIMAL_NB() )

hal_status_t HAL_ADC_SetConfigOverSampling ( hal_adc_handle_t * hadc , hal_adc_ovs_instance_t ovs_instance , const hal_adc_ovs_config_t * p_config )

Configure ADC oversampling.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_GetConfigOverSampling ( const hal_adc_handle_t * hadc , hal_adc_ovs_instance_t ovs_instance , hal_adc_ovs_config_t * p_config )

Get configuration of ADC oversampling.

Parameters :
uint32_t HAL_ADC_GetOverSamplingShiftKeepRes ( uint32_t ratio )

Compute ADC oversampling right bit shift value in function of ratio to have oversampling data keeping current resolution (example: to keep data resolution, ratio x8 requires right shift of 3 bits).

Note

Value intended to be used for parameter “shift” of hal_adc_ovs_config_t .

Parameters :

ratio – ADC oversampling ratio, value must be from 1 to 1024 and a power of 2: {1; 2; 4; 8; …; 1024}.

Return values :

Value – of right bit shift (number between Min_Data = 1 and Max_Data = 10)

hal_status_t HAL_ADC_SetConfigOffset ( hal_adc_handle_t * hadc , hal_adc_offset_instance_t offset_instance , const hal_adc_offset_config_t * p_config )

Configure ADC offset subblock features (offset level, sign, saturation, …)

Note

To remove a channel from an offset instance, set configuration with channel to HAL_ADC_CHANNEL_NONE.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

void HAL_ADC_GetConfigOffset ( const hal_adc_handle_t * hadc , hal_adc_offset_instance_t offset_instance , hal_adc_offset_config_t * p_config )

Get configuration of ADC offset subblock features (offset level, sign, saturation, …)

Note

Usage of the returned structure field “channel”: To reinject this channel into another function HAL_ADC_xxx: the returned channel number is only partly formatted on definition of literals HAL_ADC_CHANNEL_x. Therefore, it has to be compared with literals HAL_ADC_CHANNEL_x using helper macro LL_ADC_CHANNEL_TO_DECIMAL_NB() .

Parameters :
hal_status_t HAL_ADC_SetOffsetLevel ( hal_adc_handle_t * hadc , hal_adc_offset_instance_t offset_instance , int32_t offset_level )

Set ADC offset subblock parameter: offset level.

Note

Other ADC offset subblock parameters can be set using HAL_ADC_SetConfigOffset() .

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • offset_instance – Offset instance.

  • offset_level – ADC offset level, signed value between: Min_Data = -33554431 (two’s complement 0xFE000001) and Max_Data = +33554431 (0x1FFFFFF).

Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

int32_t HAL_ADC_GetOffsetLevel ( const hal_adc_handle_t * hadc , hal_adc_offset_instance_t offset_instance )

Get ADC offset subblock parameter: offset level.

Note

Other ADC offset subblock parameters can be retrieved using HAL_ADC_GetConfigOffset() .

Parameters :
Return values :

ADC – offset level, signed value between: Min_Data = -33554431 (two’s complement 0xFE000001) and Max_Data = +33554431 (0x1FFFFFF).

IRQHandler and Callbacks functions

group ADC_Exported_Functions_Group3

Set of function to handle the ADC interruptions :

Functions

void HAL_ADC_IRQHandler ( hal_adc_handle_t * hadc )

Handle all ADC interrupt requests.

Note

For optimized process of specific interrupts, refer to other HAL_ADC_IRQHandler_x functions.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_IRQHandler_REG ( hal_adc_handle_t * hadc )

Handle ADC interrupt requests optimized: specific to ADC group regular.

Note

For generic process of all ADC interrupts request, use function HAL_ADC_IRQHandler() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_IRQHandler_INJ ( hal_adc_handle_t * hadc )

Handle ADC interrupt requests optimized: specific to ADC group injected.

Note

For generic process of all ADC interrupts request, use function HAL_ADC_IRQHandler() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_IRQHandler_AWD ( hal_adc_handle_t * hadc )

Handle ADC interrupt requests optimized: specific to ADC analog watchdog.

Note

For generic process of all ADC interrupts request, use function HAL_ADC_IRQHandler() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_ErrorCallback ( hal_adc_handle_t * hadc )

HAL ADC error callback.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_REG_EndOfSamplingCallback ( hal_adc_handle_t * hadc )

ADC group regular end of sampling phase callback.

Note

ADC conversion has 2 phases (sampling, SAR conversion). Conversion data is available upon conversion complete callbacks.

Note

Sampling phase duration can be set using ADC channel sampling time.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_REG_UnitaryConvCpltCallback ( hal_adc_handle_t * hadc )

ADC group regular end of unitary conversion callback.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_REG_SequenceConvCpltCallback ( hal_adc_handle_t * hadc )

ADC group regular end of sequence conversions callback.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_REG_DataTransferHalfCallback ( hal_adc_handle_t * hadc )

ADC group regular conversion data buffer half transfer.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_REG_DataTransferCpltCallback ( hal_adc_handle_t * hadc )

ADC group regular conversion data buffer transfer complete.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_REG_DataTransferStopCallback ( hal_adc_handle_t * hadc )

ADC group regular conversion data transfer abort.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_INJ_UnitaryConvCpltCallback ( hal_adc_handle_t * hadc )

ADC group injected end of unitary conversion callback.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_INJ_SequenceConvCpltCallback ( hal_adc_handle_t * hadc )

ADC group injected end of sequence conversions callback.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

void HAL_ADC_AnalogWD_OutOfWindowCallback ( hal_adc_handle_t * hadc , hal_adc_awd_instance_t awd_instance )

ADC group regular analog watchdog out of window event callback.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • awd_instance – Analog watchdog instance

hal_status_t HAL_ADC_RegisterErrorCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC error callback function to be used in place of the weak HAL_ADC_ErrorCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterRegEndOfSamplingCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC group regular end of sampling phase callback function to be used in place of the weak HAL_ADC_REG_EndOfSamplingCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterRegUnitaryConvCpltCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC group regular end of unitary conversion callback to be used in place of the weak HAL_ADC_REG_UnitaryConvCpltCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterRegSequenceConvCpltCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC group regular end of sequence conversions callback function to be used in place of the weak HAL_ADC_REG_SequenceConvCpltCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterDataTransferHalfCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC group regular conv data buffer half transfer callback function to be used in place of the weak HAL_ADC_REG_DataTransferHalfCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterDataTransferCpltCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC group regular conv data buffer transfer complete callback function to be used in place of the weak HAL_ADC_REG_DataTransferCpltCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterDataTransferStopCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC group regular conv data transfer abort callback function to be used in place of the weak HAL_ADC_REG_DataTransferStopCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterInjUnitaryConvCpltCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC group injected end of unitary conversion callback to be used in place of the weak HAL_ADC_INJ_UnitaryConvCpltCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterInjSequenceConvCpltCallback ( hal_adc_handle_t * hadc , hal_adc_cb_t p_callback )

Register ADC group injected end of sequence conversions callback function to be used in place of the weak HAL_ADC_INJ_SequenceConvCpltCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

hal_status_t HAL_ADC_RegisterAwdOutOfWindowCallback ( hal_adc_handle_t * hadc , hal_adc_awd_cb_t p_callback )

Register ADC analog watchdog out of window event callback function to be used in place of the weak HAL_ADC_AnalogWD_OutOfWindowCallback() predefined callback.

Parameters :
Return values :
  • HAL_OK – Register completed successfully.

  • HAL_ERROR – Register completed with error.

Peripheral State, Error functions

group ADC_Exported_Functions_Group4

Set of function to handle the HAL ADC driver state, errors, kernel clock frequency:

Functions

hal_adc_state_t HAL_ADC_GetState ( const hal_adc_handle_t * hadc )

Retrieve the HAL ADC global state.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :

hal_adc_state_t – HAL ADC global state

hal_adc_group_state_t HAL_ADC_GetStateGroup ( const hal_adc_handle_t * hadc , hal_adc_group_t group )

Retrieve the HAL ADC groups (regular, injected) state.

Parameters :
Return values :

hal_adc_group_state_t – HAL ADC global state

hal_adc_common_state_t HAL_ADC_GetStateCommon ( const hal_adc_handle_t * hadc )

Retrieve the HAL ADC handle link to common instance state.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :

hal_adc_common_state_t – HAL ADC global state

uint32_t HAL_ADC_GetLastErrorCodes ( const hal_adc_handle_t * hadc )

Retrieve the HAL ADC last error codes.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :

uint32_t – last error code. This parameter can be a combination (bitfields) of the following values:

uint32_t HAL_ADC_GetClockFreq ( const hal_adc_handle_t * hadc )

Return the peripheral clock frequency for ADC.

Note

Clock frequency corresponds to ADC kernel clock, including clock source and prescaler configurations from all related modules (RCC and ADC).

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :

uint32_t – Frequency in Hz. 0 if the source clock of the ADC is not configured or not ready.

Process functions

group ADC_Exported_Functions_Group5

Set of functions allowing to operate ADCx peripheral.

  • Activation and deactivation

  • Calibration

  • ADC conversions management

Note

For more details, refer to state machine diagram or “How to use the ADC HAL module driver” section).

Functions

hal_status_t HAL_ADC_Start ( hal_adc_handle_t * hadc )

Activate ADC instance.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_Stop ( hal_adc_handle_t * hadc )

Deactivate ADC instance.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_Calibrate ( hal_adc_handle_t * hadc )

Perform self-calibration of ADC instance.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_GetCalibrationFactor ( hal_adc_handle_t * hadc , hal_adc_calib_t * p_calib )

Get ADC instance calibration factors.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_SetCalibrationFactor ( hal_adc_handle_t * hadc , const hal_adc_calib_t * p_calib )

Set ADC instance calibration factors.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_PollForEvent ( hal_adc_handle_t * hadc , hal_adc_event_t event , uint32_t timeout_ms )

Poll for ADC event.

HAL ADC state machine is not updated by this function (on the contrary to other polling functions: HAL_ADC_REG_PollForConv() , …)

Parameters :
Return values :
  • HAL_TIMEOUT – Operation exceeds user timeout

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_StartConv ( hal_adc_handle_t * hadc )

Start conversion on ADC group regular.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_StartConv_IT ( hal_adc_handle_t * hadc )

Start conversion on ADC group regular with interruption: default interruptions. Default interruptions used: end of unitary conversion, overrun. To use other interruptions, refer to HAL_ADC_REG_StartConv_IT_Opt() .

Note

Callback functions “HAL_ADC_REG_…Callback()” (corresponding to these interruptions) will be triggered.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_StartConv_IT_Opt ( hal_adc_handle_t * hadc , uint32_t it_opt )

Start conversion on ADC group regular with interruption: selected optional interruptions.

Note

Callback functions “HAL_ADC_REG_…Callback()” (corresponding to these interruptions) will be triggered.

Parameters :
Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_StartConv_DMA ( hal_adc_handle_t * hadc , const uint8_t * p_data , uint32_t size_byte )

Start conversion on ADC group regular with data transfer by DMA. Default interruptions used: buffer half transfer and transfer complete. To use other interruptions, refer to HAL_ADC_REG_StartConv_DMA_Opt() .

Note

Callback functions HAL_ADC_REG_DataTransferHalfCallback and HAL_ADC_REG_DataTransferCpltCallback (corresponding to these interruptions) will be triggered.

Note

This function configures automatically ADC data transfer by DMA mode limited or unlimited in function of DMA configuration one shot or circular mode.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • p_data – Pointer to the data buffer.

  • size_byte – Data buffer size (in bytes).

Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_StartConv_DMA_Opt ( hal_adc_handle_t * hadc , const uint8_t * p_data , uint32_t size_byte , uint32_t it_opt )

Start conversion on ADC group regular with data transfer by DMA and selected optional interruptions.

Note

Callback functions “HAL_ADC_REG_DataTransfer…Callback” (corresponding to these interruptions) will be triggered.

Note

This function configure automatically ADC data transfer by DMA mode limited or unlimited in function of DMA configuration one shot or circular mode.

Note

Optional interruptions not applicable: HAL_ADC_OPT_IT_REG_EOC (flag cleared by DMA) and HAL_ADC_OPT_IT_REG_OVR (always enabled: overrun event is an error in case of DMA transfer)

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_TrigNextConv ( hal_adc_handle_t * hadc )

Trig conversion (SW start) on ADC group regular for a conversion process on going.

Note

This function can be used to iterate a conversion process on going initiated by HAL_ADC_REG_StartConv…() (for example, sequence in discontinuous mode or DMA transfer from unitary conversions by SW start).

Warning

Necessary condition: previous conversion must be completed (state HAL_ADC_GROUP_STATE_IDLE, ensured by polling ( HAL_ADC_REG_PollForConv() ) or interruption ( HAL_ADC_IRQHandler() ).

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_StopConv ( hal_adc_handle_t * hadc )

Stop conversion on ADC group regular.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_StopConv_IT ( hal_adc_handle_t * hadc )

Stop conversion on ADC group regular with interruption.

Note

This function disable interruptions enabled by start conversion function except analog watchdog interrutpions possibly used by group injected. To disable them, use HAL_ADC_Stop() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_StopConv_DMA ( hal_adc_handle_t * hadc )

Stop conversion on ADC group regular with data transfer by DMA.

Note

This function disable interruptions enabled by start conversion function except analog watchdog interrutpions possibly used by group injected. To disable them, use HAL_ADC_Stop() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_REG_PollForConv ( hal_adc_handle_t * hadc , uint32_t timeout_ms )

Wait for conversion on ADC group regular to be completed.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • timeout_ms – ADC conversion time out value (unit: ms)

Return values :
  • HAL_TIMEOUT – Operation exceeds user timeout

  • HAL_OK – Operation completed successfully

int32_t HAL_ADC_REG_GetValue ( const hal_adc_handle_t * hadc )

Get ADC group regular conversion data.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :

conversion – data (signed value (can be negative after post-processing computation: offset feature) between Min_Data=-2147483648 (two’s complement 0x80000000) and Max_Data=+2147483647 (0x7FFFFFFF))

hal_status_t HAL_ADC_INJ_StartConv ( hal_adc_handle_t * hadc )

Start conversion on ADC group injected.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_INJ_StartConv_IT ( hal_adc_handle_t * hadc )

Start conversion on ADC group injected with interruption: default interruptions. Default interruptions used: end of unitary conversion. To use other interruptions, refer to HAL_ADC_INJ_StartConv_IT_Opt() .

Note

Callback functions “HAL_ADC_INJ_…Callback()” (corresponding to these interruptions) will be triggered.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_INJ_StartConv_IT_Opt ( hal_adc_handle_t * hadc , uint32_t it_opt )

Start conversion on ADC group injected with interruption: selected optional interruptions.

Note

Callback functions “HAL_ADC_INJ_…Callback()” (corresponding to these interruptions) will be triggered.

Parameters :
Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_INJ_TrigNextConv ( hal_adc_handle_t * hadc )

Trig conversion (SW start) on ADC group injected for a conversion process on going.

Note

This function can be used to iterate a conversion process on going initiated by HAL_ADC_INJ_StartConv…() (for example, sequence in discontinuous mode).

Warning

Necessary condition: previous conversion must be completed (state HAL_ADC_GROUP_STATE_IDLE, ensured by polling ( HAL_ADC_INJ_PollForConv() ) or interruption ( HAL_ADC_IRQHandler() ).

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_INJ_StopConv ( hal_adc_handle_t * hadc )

Stop conversion on ADC group injected.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_INJ_StopConv_IT ( hal_adc_handle_t * hadc )

Stop conversion on ADC group injected with interruption.

Note

This function disable interruptions enabled by start conversion function except analog watchdog interrutpions possibly used by group regular. To disable them, use HAL_ADC_Stop() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_INJ_PollForConv ( hal_adc_handle_t * hadc , uint32_t timeout_ms )

Wait for conversion on ADC group injected to be completed.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • timeout_ms – ADC conversion time out value (unit: ms)

Return values :
  • HAL_TIMEOUT – Operation exceeds user timeout

  • HAL_OK – Operation completed successfully

int32_t HAL_ADC_INJ_GetValue ( const hal_adc_handle_t * hadc , uint8_t sequencer_rank )

Get ADC group injected conversion data.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • sequencer_rank – ADC group injected sequencer rank. Can be a number between Min_Data = 1, Max_Data = 4

Return values :

conversion – data (signed value (can be negative after post-processing computation: offset feature) between Min_Data=-2147483648 (two’s complement 0x80000000) and Max_Data=+2147483647 (0x7FFFFFFF))

hal_status_t HAL_ADC_MM_Start ( hal_adc_handle_t * hadc )

Multimode operation: Activate ADC instances part of multimode.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_Stop ( hal_adc_handle_t * hadc )

Multimode operation: Deactivate ADC instances part of multimode.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_Calibrate ( hal_adc_handle_t * hadc )

Multimode operation: Perform self-calibration of ADC instances part of multimode.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StartConv ( hal_adc_handle_t * hadc )

Multimode operation: Start conversion on multimode ADC instances group regular. Callback functions “HAL_ADC_INJ_…Callback” (depending on ADC interrupt selected) will be triggered.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StartConv_IT ( hal_adc_handle_t * hadc )

Multimode operation: Start conversion on multimode ADC instances group regular with interruption: default interruptions. Default interruptions used: end of unitary conversion, overrun. To use other interruptions, refer to HAL_ADC_REG_StartConv_IT_Opt() .

Note

Callback functions “HAL_ADC_REG_…Callback()” (corresponding to these interruptions) will be triggered.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StartConv_IT_Opt ( hal_adc_handle_t * hadc , uint32_t it_opt )

Multimode operation: Start conversion on multimode ADC instances group regular with interruption: selected optional interruptions.

Note

Callback functions “HAL_ADC_REG_…Callback()” (corresponding to these interruptions) will be triggered.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :
Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StartConv_DMA ( hal_adc_handle_t * hadc , const uint8_t * p_data , uint32_t size_byte )

Multimode operation: Start conversion on multimode ADC instances group regular with data transfer by DMA. In this mode, multimode conversion data of all ADC instances part of multimode are concatenated and transferred using only one DMA channel (the one assigned to ADC master). Default interruptions used: buffer half transfer and transfer complete. To use other interruptions, refer to HAL_ADC_MM_REG_StartConv_DMA_Opt() .

Note

Callback functions HAL_ADC_REG_DataTransferHalfCallback and HAL_ADC_REG_DataTransferCpltCallback (corresponding to these interruptions) will be triggered.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

  • p_data – Pointer to the data buffer.

  • size_byte – Data buffer size (in bytes).

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StartConv_DMA_Opt ( hal_adc_handle_t * hadc , const uint8_t * p_data , uint32_t size_byte , uint32_t it_opt )

Multimode operation: Start conversion on multimode ADC instances group regular with data transfer by DMA and selected optional interruptions. In this mode, multimode conversion data of all ADC instances part of multimode are concatenated and transferred using only one DMA channel (the one assigned to ADC master).

Note

Callback functions “HAL_ADC_REG_DataTransfer…Callback” (corresponding to these interruptions) will be triggered.

Note

Optional interruptions not applicable: HAL_ADC_OPT_IT_REG_EOC (flag cleared by DMA) and HAL_ADC_OPT_IT_REG_OVR (always enabled: overrun event is an error in case of DMA transfer)

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter

  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StartConvM_DMA ( hal_adc_handle_t * hadc )

Multimode operation: Start conversion on multimode ADC instances group regular with data transfer by DMA using multiple DMA channels (“M_DMA” stands for multiple DMA).

Note

In this mode, multimode conversion data of all ADC instances part of multimode are transferred using multiple DMA channels (the one assigned to each ADC). DMA transfer must have been configured using HAL_ADC_MM_REG_SetMultiDMA() . Default interruptions used: buffer half transfer and transfer complete. To use other interruptions, refer to HAL_ADC_MM_REG_StartConvM_DMA_Opt() .

Note

Callback functions “HAL_ADC_REG_DataTransfer…Callback” (corresponding to these interruptions) will be triggered.

Note

To stop conversion data and transfer by DMA of all ADC instances part of multimode use function HAL_ADC_MM_REG_StopConv_DMA() . To restart new conversion DMA transfer must have been re-configured using HAL_ADC_MM_REG_SetMultiDMA() before calling this function.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StartConvM_DMA_Opt ( hal_adc_handle_t * hadc , uint32_t it_opt )

Multimode operation: Start conversion on multimode ADC instances group regular with data transfer by DMA using multiple DMA channels (“M_DMA” stands for multiple DMA), and selected optional interruptions.

Note

In this mode, multimode conversion data of all ADC instances part of multimode are transferred using multiple DMA channels (the one assigned to each ADC). DMA transfer must have been configured using HAL_ADC_MM_REG_SetMultiDMA() .

Note

Callback functions “HAL_ADC_REG_DataTransfer…Callback” (corresponding to these interruptions) will be triggered.

Note

Optional interruptions not applicable: HAL_ADC_OPT_IT_REG_EOC (flag cleared by DMA) and HAL_ADC_OPT_IT_REG_OVR (always enabled: overrun event is an error in case of DMA transfer)

Note

To stop conversion data and transfer by DMA of all ADC instances part of multimode use function HAL_ADC_MM_REG_StopConv_DMA() . To restart new conversion DMA transfer must have been re-configured using HAL_ADC_MM_REG_SetMultiDMA() before calling this function.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :
Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_TrigNextConv ( hal_adc_handle_t * hadc )

Trig conversion (SW start) on multimode ADC instances group regular for a conversion process on going.

Note

This function can be used to iterate a conversion process on going initiated by HAL_ADC_REG_StartConv…() (for example, sequence in discontinuous mode or DMA transfer from unitary conversions by SW start).

Note

This function is not compliant with multimode regular interleaved.

Warning

Necessary condition: previous conversion must be completed (state HAL_ADC_GROUP_STATE_IDLE, ensured by polling ( HAL_ADC_REG_PollForConv() ) or interruption ( HAL_ADC_IRQHandler() ).

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StopConv ( hal_adc_handle_t * hadc )

Multimode operation: Stop conversion on multimode ADC instances group regular.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StopConv_IT ( hal_adc_handle_t * hadc )

Multimode operation: Stop conversion on multimode ADC instances group regular with interruption.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_StopConv_DMA ( hal_adc_handle_t * hadc )

Multimode operation: Stop conversion on multimode ADC instances group regular with data transfer by DMA.

Note

This function disable interruptions enabled by start conversion function except analog watchdog interrutpions possibly used by group injected. To disable them, use HAL_ADC_MM_Stop() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_REG_PollForConv ( hal_adc_handle_t * hadc , uint32_t timeout_ms )

Multimode operation: Wait for conversion on ADC group regular to be completed (for all ADC instances part of multimode)

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

  • timeout_ms – ADC conversion time out value (unit: ms)

Return values :
  • HAL_TIMEOUT – Operation exceeds user timeout

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

uint32_t HAL_ADC_MM_REG_GetValue ( const hal_adc_handle_t * hadc , hal_adc_mm_inst_t multi_inst )

Multimode operation: Get ADC group regular conversion data of ADC master, ADC slave or ADC master and slave concatenated.

Note

This function is relevant only for ADC multimode group regular data format with packing: each ADC conversion data concatenated in a single register (refer to hal_adc_mm_reg_data_format_t ).

Note

Each ADC conversion data width is limited to 8 or 16 bits depending on data packing setting. If expected data width is wider (this can be the case with features extending data width (oversampling, data shift,…), others services must be used:

  • function “HAL_ADC_REG_GetValue()” for each ADC instance part of multimode.

  • multimode functions with data transfer by DMA.

Note

Returned value is unsigned, due to concatenation of multiple data. In case of signed data expected (with features changing data sign: offset), use function “HAL_ADC_REG_GetValue()” for each ADC instance part of multimode.

Parameters :
Return values :

conversion – data (unsigned value between Min_Data = 0x00000000 and Max_Data = 0xFFFFFFFF)

hal_status_t HAL_ADC_MM_INJ_StartConv ( hal_adc_handle_t * hadc )

Multimode operation: Start conversion on multimode ADC instances group injected.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_INJ_StartConv_IT ( hal_adc_handle_t * hadc )

Multimode operation: Start conversion on multimode ADC instances group injected with interruption: default interruptions. Default interruptions used: end of unitary conversion, overrun. To use other interruptions, refer to HAL_ADC_MM_INJ_StartConv_IT_Opt() .

Note

Callback functions “HAL_ADC_INJ_…Callback()” (corresponding to these interruptions) will be triggered.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_INJ_StartConv_IT_Opt ( hal_adc_handle_t * hadc , uint32_t it_opt )

Multimode operation: Start conversion on multimode ADC instances group injected with interruption: selected optional interruptions.

Note

Callback functions “HAL_ADC_INJ_…Callback()” (corresponding to these interruptions) will be triggered.

Warning

Prerequisite: HAL ADC handles part of multimode setup must have been linked using function HAL_ADC_SetLinkNextHandle() and multimode must have been configured using function HAL_ADC_MM_SetConfig() .

Parameters :
Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_INJ_TrigNextConv ( hal_adc_handle_t * hadc )

Trig conversion (SW start) on multimode ADC instances group injected for a conversion process on going.

Note

This function can be used to iterate a conversion process on going initiated by HAL_ADC_INJ_StartConv…() (for example, sequence in discontinuous mode).

Warning

Necessary condition: previous conversion must be completed (state HAL_ADC_GROUP_STATE_IDLE, ensured by polling ( HAL_ADC_INJ_PollForConv() ) or interruption ( HAL_ADC_IRQHandler() ).

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_BUSY – HAL ADC state machine not in expected initial state

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_INJ_StopConv ( hal_adc_handle_t * hadc )

Multimode operation: Stop conversion on multimode ADC instances group injected.

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_INJ_StopConv_IT ( hal_adc_handle_t * hadc )

Multimode operation: Stop conversion on multimode ADC instances group injected.

Note

This function disable interruptions enabled by start conversion function except analog watchdog interrutpions possibly used by group regular. To disable them, use HAL_ADC_Stop() .

Parameters :

hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

Return values :
  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

hal_status_t HAL_ADC_MM_INJ_PollForConv ( hal_adc_handle_t * hadc , uint32_t timeout_ms )

Multimode operation: Wait for conversion on ADC group injected to be completed (for all ADC instances part of multimode)

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure. Must be the handle of ADC master.

  • timeout_ms – ADC conversion time out value (unit: ms)

Return values :
  • HAL_TIMEOUT – Operation exceeds user timeout

  • HAL_ERROR – Operation completed with error

  • HAL_OK – Operation completed successfully

uint32_t HAL_ADC_MM_INJ_GetValue ( const hal_adc_handle_t * hadc , hal_adc_mm_inst_t multi_inst , uint8_t sequencer_rank )

Multimode operation: Get ADC group injected conversion data of ADC master, ADC slave or ADC master and slave concatenated.

Note

With ADC master and slave concatenated: Data width is limited to 16 bits (due to register 32 bits containing conversion data of two ADC instances: ADC master and slave data in ranges [15:0] and [31:16] respectively). If expected data width is wider (this can be the case with features extending data width (oversampling, data shift,…), others services must be used:

  • this function with parameter HAL_ADC_MM_MASTER or HAL_ADC_MM_SLAVE

  • function “HAL_ADC_INJ_GetValue()” for each ADC instance part of multimode.

Note

Returned value is unsigned, due to concatenation of multiple data. In case of signed data expected (with features changing data sign: offset), use function “HAL_ADC_INJ_GetValue()” for each ADC instance part of multimode.

Parameters :
  • hadc – Pointer to a hal_adc_handle_t structure.

  • multi_inst – Value of hal_adc_mm_inst_t

  • sequencer_rank – ADC group injected sequencer rank. Can be a number between Min_Data = 1, Max_Data = 4

Return values :

conversion – data (unsigned value between Min_Data = 0x00000000 and Max_Data = 0xFFFFFFFF)

User data functions

group ADC_Exported_Functions_Group6

This subsection provides functions allowing to:

  • Set a user data pointer (ex: a user context) in a HAL ADC handle,

  • Get a user data pointer (ex: a user context) from a HAL ADC handle.

Note

A typical usage is to set user data pointer before starting a data conversion, then retrieve it within the user conversion completion callback.

Functions

void HAL_ADC_SetUserData ( hal_adc_handle_t * hadc , const void * p_user_data )

Store user data pointer into the adc handle.

Parameters :
const void * HAL_ADC_GetUserData ( const hal_adc_handle_t * hadc )

Retrieve user data pointer from the adc handle.

Parameters :

hadc – Pointer to a hal_adc_handle_t .

Return values :