HAL ADF How to Use

group ADF_How_To_Use

How to use the HAL ADF driver

The HAL ADF driver can be used as follows:

ADFx HW IP is composed of a common clock generator and blocks. Each block is composed of sub-blocks:

  • a serial interface.

  • a bitstream matrix.

  • a digital filter.

  • a sound activity detector.

Configuration and activation of common clock generator must be first performed.

Common clock generator usage

  1. Declare a hal_adf_handle_t handle structure and initialize the ADFx driver with a ADFx HW instance by calling the HAL_ADF_Init() . The ADFx clock is enabled inside the HAL_ADF_Init() if USE_HAL_ADF_CLK_ENABLE_MODEL > HAL_CLK_ENABLE_NO.

  2. Configure the low level hardware (GPIO, CLOCK, NVIC, DMA…):

    • Enable the ADFx clock if USE_HAL_ADF_CLK_ENABLE_MODEL = HAL_CLK_ENABLE_NO.

    • ADFx pins configuration:

      • Enable the clock for the ADFx GPIOs

      • Configure ADFx pins as alternate function pull-up

    • NVIC configuration if you need to use interrupt process

      • Configure the ADFx interrupt priority.

      • Enable the NVIC ADFx IRQ handle.

    • DMA configuration if you need to use DMA process

      • Declare a DMA handle structure.

      • Enable the DMAx clock.

      • Configure the declared DMA handle structure with the required parameters.

      • Associate the initialized DMA handle to the ADF DMA handle using HAL_ADF_SetDMA() .

      • Configure the corresponding NVIC line priority and enable it.

    • ADFx kernel source clock has to be activated and selected.

  3. Configure the processing clock divider by calling HAL_ADF_SetConfig() .

  4. Configure and/or enable advanced features. All these advanced configurations are optional (not mandatory) and concerns mainly output clocks (for instance by calling HAL_ADF_SetConfigOutputClock() and HAL_ADF_EnableOutputClock() ).

  5. Activate the clock generator by calling HAL_ADF_Start() .

Serial interface usage

  1. Configure mode, clock source and threshold of a serial interface by calling HAL_ADF_SITF_SetConfig() .

  2. Activate a serial interface by calling HAL_ADF_SITF_Start() .

  3. Clock absence detection feature is available on each serial interface and can be used:

    • By calling HAL_ADF_SITF_IsClockAbsenceDetected in polling mode.

    • By calling HAL_ADF_SITF_StartClockAbsenceDetect_IT in interrupt mode.

Bitstream matrix usage

Connect one serial interface to a bitstream matrix and select edge by calling HAL_ADF_BSMX_SetConfig() .

Digital filter usage

  1. Configure data source, CIC mode, decimation ratio, gain, acquisition mode and trigger parameters of a digital filter by calling HAL_ADF_DFLT_SetConfig() .

  2. Configure and/or enable advanced features. All these advanced configurations are optional (not mandatory) and concerns:

  3. Acquisitions.

Sound activity detector usage

  1. Configure mode, memory transfer, trigger event and minimum ambient noise level by calling HAL_ADF_SAD_SetConfig() .

  2. Configure and/or enable advanced features. All these advanced configurations are optional (not mandatory) and concerns:

  3. Activate a sound activity detector::

Callbacks definition in interrupt or DMA mode:

When the compilation define USE_HAL_ADF_REGISTER_CALLBACKS is set to 1, the user can configure dynamically the driver callbacks, via its own method:

Callback name

Default value

Callback registration function

DFLT_AcqCpltCallback

HAL_ADF_DFLT_AcqCpltCallback()

HAL_ADF_DFLT_RegisterAcqCpltCallback()

DFLT_AcqHalfCpltCallback

HAL_ADF_DFLT_AcqHalfCpltCallback()

HAL_ADF_DFLT_RegisterAcqHalfCpltCallback()

DFLT_AcqStopCpltCallback

HAL_ADF_DFLT_AcqStopCpltCallback()

HAL_ADF_DFLT_RegisterAcqStopCpltCallback()

SAD_SoundLevelCallback

HAL_ADF_SAD_SoundLevelCallback()

HAL_ADF_SAD_RegisterSoundLevelCallback()

SAD_SoundActivityCallback

HAL_ADF_SAD_SoundActivityCallback()

HAL_ADF_SAD_RegisterSoundActivityCallback()

ErrorCallback

HAL_ADF_ErrorCallback()

HAL_ADF_RegisterErrorCallback()

If one needs to unregister a callback, register the default callback via the registration function.

By default, after the HAL_ADF_Init() and when the state is HAL_ADF_STATE_INIT , all callbacks are set to the corresponding default weak functions.

Callbacks can be registered in all states.

When the compilation define USE_HAL_ADF_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration feature is not available and weak callbacks are used, represented by the default value in the table above.