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 ¶
-
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.
-
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.
-
-
Configure the processing clock divider by calling HAL_ADF_SetConfig() .
-
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() ).
-
Activate the clock generator by calling HAL_ADF_Start() .
Serial interface usage ¶
-
Configure mode, clock source and threshold of a serial interface by calling HAL_ADF_SITF_SetConfig() .
-
Activate a serial interface by calling HAL_ADF_SITF_Start() .
-
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 ¶
-
Configure data source, CIC mode, decimation ratio, gain, acquisition mode and trigger parameters of a digital filter by calling HAL_ADF_DFLT_SetConfig() .
-
Configure and/or enable advanced features. All these advanced configurations are optional (not mandatory) and concerns:
-
Samples delay by calling HAL_ADF_DFLT_SetSamplesDelay() .
-
FIFO threshold by calling HAL_ADF_DFLT_SetFifoThreshold() .
-
Discard samples by calling HAL_ADF_DFLT_SetDiscardSamples() .
-
Reshape filter by calling HAL_ADF_DFLT_EnableReshapeFilter() .
-
High-pass filter by calling HAL_ADF_DFLT_EnableHighPassFilter() .
-
-
Acquisitions.
-
Polling mode:
-
Start acquisition by calling HAL_ADF_DFLT_StartAcq() .
-
Wait for the end of acquisition by calling HAL_ADF_DFLT_PollForAcq() .
-
Get acquisition value by calling HAL_ADF_DFLT_GetAcqValue() .
-
Stop acquisition by calling HAL_ADF_DFLT_StopAcq() .
-
-
Interrupt mode:
-
Start acquisition by calling HAL_ADF_DFLT_StartAcq_IT() or HAL_ADF_DFLT_StartAcq_IT_Opt() .
-
Wait for the end of acquisition ( HAL_ADF_DFLT_AcqCpltCallback() occurrence).
-
Get acquisition value by calling HAL_ADF_DFLT_GetAcqValue() .
-
Stop acquisition by calling HAL_ADF_DFLT_StopAcq_IT() .
-
-
DMA mode:
-
Start acquisition by calling HAL_ADF_DFLT_StartAcq_DMA() or HAL_ADF_DFLT_StartAcq_DMA_Opt() .
-
Wait for acquisitions ( HAL_ADF_DFLT_AcqHalfCpltCallback() and HAL_ADF_DFLT_AcqCpltCallback() occurrences).
-
Stop acquisition by calling HAL_ADF_DFLT_StopAcq_DMA() .
-
-
Sound activity detector usage ¶
-
Configure mode, memory transfer, trigger event and minimum ambient noise level by calling HAL_ADF_SAD_SetConfig() .
-
Configure and/or enable advanced features. All these advanced configurations are optional (not mandatory) and concerns:
-
Frame size by calling HAL_ADF_SAD_SetFrameSize() .
-
Learning frames by calling HAL_ADF_SAD_SetLearningFrames() .
-
Signal to noise threshold by calling HAL_ADF_SAD_SetSignalToNoiseThreshold() .
-
Ambient noise slope by calling HAL_ADF_SAD_SetAmbientNoiseSlope() .
-
Hangover time window by calling HAL_ADF_SAD_SetHangoverTimeWindow() .
-
Hysteresis by calling HAL_ADF_SAD_EnableHysteresis() .
-
-
Activate a sound activity detector::
-
By calling HAL_ADF_SAD_Start() in polling mode.
-
By calling HAL_ADF_SAD_Start_IT() or HAL_ADF_SAD_Start_IT_Opt() in interrupt mode.
-
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
DFLT_AcqHalfCpltCallback
DFLT_AcqStopCpltCallback
SAD_SoundLevelCallback
SAD_SoundActivityCallback
ErrorCallback
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.
-