HAL MDF How to Use ¶
- group MDF_How_To_Use
-
How to use the HAL MDF driver ¶
The HAL MDF driver can be used as follows: ¶
MDFx 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 short-circuit detector.
-
a digital filter.
-
an out-of-limit detector.
Configuration and activation of common clock generator must be first performed.
Common clock generator usage ¶
-
Declare a hal_mdf_handle_t handle structure and initialize the MDFx driver with a MDFx HW instance by calling the HAL_MDF_Init() . The MDFx clock is enabled inside the HAL_MDF_Init() if USE_HAL_MDF_CLK_ENABLE_MODEL > HAL_CLK_ENABLE_NO.
-
Configure the low level hardware (GPIO, CLOCK, NVIC, DMA…):
-
Enable the MDFx clock if USE_HAL_MDF_CLK_ENABLE_MODEL = HAL_CLK_ENABLE_NO.
-
MDFx pins configuration:
-
Enable the clock for the MDFx GPIOs
-
Configure MDFx pins as alternate function pull-up
-
-
NVIC configuration if you need to use interrupt process
-
Configure the MDFx interrupt priority.
-
Enable the NVIC MDFx 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 MDF DMA handle using HAL_MDF_SetDMA() .
-
Configure the corresponding NVIC line priority and enable it.
-
-
MDFx kernel source clock has to be activated and selected.
-
-
Configure the processing clock divider by calling HAL_MDF_SetConfig() .
-
Configure and/or enable advanced features. All these advanced configurations are optional (not mandatory) and concerns:
-
Output clocks (for instance by calling HAL_MDF_SetConfigOutputClock() and HAL_MDF_EnableOutputClock() ).
-
Interleaved filters (by calling HAL_MDF_SetInterleavedFilters).
-
-
Activate the clock generator by calling HAL_MDF_Start() .
Serial interface usage ¶
-
Configure mode, clock source and threshold of a serial interface by calling HAL_MDF_SITF_SetConfig() .
-
Activate a serial interface by calling HAL_MDF_SITF_Start() .
-
Clock absence detection feature is available on each serial interface and can be used:
-
By calling HAL_MDF_SITF_IsClockAbsenceDetected in polling mode.
-
By calling HAL_MDF_SITF_StartClockAbsenceDetect_IT in interrupt mode.
-
Bitstream matrix usage ¶
Connect one serial interface to a bitstream matrix and select edge by calling HAL_MDF_BSMX_SetConfig() .
Short-circuit detector usage ¶
-
Configure threshold and break signals of a short-circuit detector by calling HAL_MDF_SCD_SetConfig() .
-
Activate a short-circuit detector:
-
By calling HAL_MDF_SCD_Start in polling mode.
-
By calling HAL_MDF_SCD_Start_IT in interrupt mode.
-
Digital filter usage ¶
-
Configure data source, CIC mode, decimation ratio, gain, acquisition mode and trigger parameters of a digital filter by calling HAL_MDF_DFLT_SetConfig() .
-
Configure and/or enable advanced features. All these advanced configurations are optional (not mandatory) and concerns:
-
Samples delay by calling HAL_MDF_DFLT_SetSamplesDelay() .
-
Offset compensation by calling HAL_MDF_DFLT_SetOffsetCompensation() .
-
Integrator by calling HAL_MDF_DFLT_SetIntegrator() .
-
FIFO threshold by calling HAL_MDF_DFLT_SetFifoThreshold() .
-
Discard samples by calling HAL_MDF_DFLT_SetDiscardSamples() .
-
Snapshot format by calling HAL_MDF_DFLT_SetSnapshotFormat() .
-
Reshape filter by calling HAL_MDF_DFLT_EnableReshapeFilter() .
-
High-pass filter by calling HAL_MDF_DFLT_EnableHighPassFilter() .
-
-
Acquisitions.
-
Polling mode:
-
Start acquisition by calling HAL_MDF_DFLT_StartAcq() .
-
Wait for the end of acquisition by calling HAL_MDF_DFLT_PollForAcq() or HAL_MDF_DFLT_PollForSnapshotAcq() .
-
Get acquisition value by calling HAL_MDF_DFLT_GetAcqValue() or HAL_MDF_DFLT_GetSnapshotAcqValue() .
-
Stop acquisition by calling HAL_MDF_DFLT_StopAcq() .
-
-
Interrupt mode:
-
Start acquisition by calling HAL_MDF_DFLT_StartAcq_IT() or HAL_MDF_DFLT_StartAcq_IT_Opt() .
-
Wait for the end of acquisition ( HAL_MDF_DFLT_AcqCpltCallback() occurrence).
-
Get acquisition value by calling HAL_MDF_DFLT_GetAcqValue() or HAL_MDF_DFLT_GetSnapshotAcqValue() .
-
Stop acquisition by calling HAL_MDF_DFLT_StopAcq_IT() .
-
-
DMA mode:
-
Start acquisition by calling HAL_MDF_DFLT_StartAcq_DMA() or HAL_MDF_DFLT_StartAcq_DMA_Opt() .
-
Wait for acquisitions ( HAL_MDF_DFLT_AcqHalfCpltCallback() and HAL_MDF_DFLT_AcqCpltCallback() occurrences).
-
Stop acquisition by calling HAL_MDF_DFLT_StopAcq_DMA() .
-
-
Out-of-limit detector usage ¶
-
Configure CIC order, decimation ratio, thresholds, event configuration and break signals of an out-of-limit detector by calling HAL_MDF_OLD_SetConfig() .
-
Activate an out-of-limit detector:
-
By calling HAL_MDF_OLD_Start in polling mode.
-
By calling HAL_MDF_OLD_Start_IT in interrupt mode.
-
Callbacks definition in interrupt or DMA mode: ¶
When the compilation define USE_HAL_MDF_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
OLD_Callback
ErrorCallback
If one needs to unregister a callback, register the default callback via the registration function.
By default, after the HAL_MDF_Init() and when the state is HAL_MDF_STATE_INIT , all callbacks are set to the corresponding default weak functions.
Callbacks can be registered in handle global_state HAL_MDF_STATE_INIT and HAL_MDF_STATE_IDLE .
When the compilation define USE_HAL_MDF_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.
-