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

  1. 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.

  2. 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.

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

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

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

Serial interface usage

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

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

  3. 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

  1. Configure threshold and break signals of a short-circuit detector by calling HAL_MDF_SCD_SetConfig() .

  2. 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

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

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

  3. Acquisitions.

Out-of-limit detector usage

  1. Configure CIC order, decimation ratio, thresholds, event configuration and break signals of an out-of-limit detector by calling HAL_MDF_OLD_SetConfig() .

  2. 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

HAL_MDF_DFLT_AcqCpltCallback()

HAL_MDF_DFLT_RegisterAcqCpltCallback()

DFLT_AcqHalfCpltCallback

HAL_MDF_DFLT_AcqHalfCpltCallback()

HAL_MDF_DFLT_RegisterAcqHalfCpltCallback()

DFLT_AcqStopCpltCallback

HAL_MDF_DFLT_AcqStopCpltCallback()

HAL_MDF_DFLT_RegisterAcqStopCpltCallback()

OLD_Callback

HAL_MDF_OLD_Callback()

HAL_MDF_OLD_RegisterCallback()

ErrorCallback

HAL_MDF_ErrorCallback()

HAL_MDF_RegisterErrorCallback()

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.