STM32L4xx_HAL_Driver  1.14.0
Channel initialization and de-initialization functions

Channel initialization and de-initialization functions. More...

Functions

HAL_StatusTypeDef HAL_DFSDM_ChannelInit (DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
 Initialize the DFSDM channel according to the specified parameters in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_DFSDM_ChannelDeInit (DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
 De-initialize the DFSDM channel. More...
 
void HAL_DFSDM_ChannelMspInit (DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
 Initialize the DFSDM channel MSP. More...
 
void HAL_DFSDM_ChannelMspDeInit (DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
 De-initialize the DFSDM channel MSP. More...
 
HAL_StatusTypeDef HAL_DFSDM_Channel_RegisterCallback (DFSDM_Channel_HandleTypeDef *hdfsdm_channel, HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID, pDFSDM_Channel_CallbackTypeDef pCallback)
 Register a user DFSDM channel callback to be used instead of the weak predefined callback. More...
 
HAL_StatusTypeDef HAL_DFSDM_Channel_UnRegisterCallback (DFSDM_Channel_HandleTypeDef *hdfsdm_channel, HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID)
 Unregister a user DFSDM channel callback. DFSDM channel callback is redirected to the weak predefined callback. More...
 

Detailed Description

Channel initialization and de-initialization functions.

  ==============================================================================
        ##### Channel initialization and de-initialization functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Initialize the DFSDM channel.
      (+) De-initialize the DFSDM channel.

Function Documentation

◆ HAL_DFSDM_Channel_RegisterCallback()

HAL_StatusTypeDef HAL_DFSDM_Channel_RegisterCallback ( DFSDM_Channel_HandleTypeDef hdfsdm_channel,
HAL_DFSDM_Channel_CallbackIDTypeDef  CallbackID,
pDFSDM_Channel_CallbackTypeDef  pCallback 
)

Register a user DFSDM channel callback to be used instead of the weak predefined callback.

Parameters
hdfsdm_channelDFSDM channel handle.
CallbackIDID of the callback to be registered. This parameter can be one of the following values:
pCallbackpointer to the callback function.
Return values
HALstatus.

Definition at line 558 of file stm32l4xx_hal_dfsdm.c.

561 {
562  HAL_StatusTypeDef status = HAL_OK;
563 
564  if (pCallback == NULL)
565  {
566  /* update return status */
567  status = HAL_ERROR;
568  }
569  else
570  {
571  if (HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State)
572  {
573  switch (CallbackID)
574  {
576  hdfsdm_channel->CkabCallback = pCallback;
577  break;
579  hdfsdm_channel->ScdCallback = pCallback;
580  break;
582  hdfsdm_channel->MspInitCallback = pCallback;
583  break;
585  hdfsdm_channel->MspDeInitCallback = pCallback;
586  break;
587  default :
588  /* update return status */
589  status = HAL_ERROR;
590  break;
591  }
592  }
593  else if (HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State)
594  {
595  switch (CallbackID)
596  {
598  hdfsdm_channel->MspInitCallback = pCallback;
599  break;
601  hdfsdm_channel->MspDeInitCallback = pCallback;
602  break;
603  default :
604  /* update return status */
605  status = HAL_ERROR;
606  break;
607  }
608  }
609  else
610  {
611  /* update return status */
612  status = HAL_ERROR;
613  }
614  }
615  return status;
616 }
return HAL_OK

◆ HAL_DFSDM_Channel_UnRegisterCallback()

HAL_StatusTypeDef HAL_DFSDM_Channel_UnRegisterCallback ( DFSDM_Channel_HandleTypeDef hdfsdm_channel,
HAL_DFSDM_Channel_CallbackIDTypeDef  CallbackID 
)

Unregister a user DFSDM channel callback. DFSDM channel callback is redirected to the weak predefined callback.

Parameters
hdfsdm_channelDFSDM channel handle.
CallbackIDID of the callback to be unregistered. This parameter can be one of the following values:
Return values
HALstatus.

Definition at line 630 of file stm32l4xx_hal_dfsdm.c.

632 {
633  HAL_StatusTypeDef status = HAL_OK;
634 
635  if (HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State)
636  {
637  switch (CallbackID)
638  {
640  hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback;
641  break;
643  hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback;
644  break;
646  hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
647  break;
649  hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
650  break;
651  default :
652  /* update return status */
653  status = HAL_ERROR;
654  break;
655  }
656  }
657  else if (HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State)
658  {
659  switch (CallbackID)
660  {
662  hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
663  break;
665  hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
666  break;
667  default :
668  /* update return status */
669  status = HAL_ERROR;
670  break;
671  }
672  }
673  else
674  {
675  /* update return status */
676  status = HAL_ERROR;
677  }
678  return status;
679 }
void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
Short circuit detection callback.
void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
De-initialize the DFSDM channel MSP.
void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
Clock absence detection callback.
return HAL_OK
void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
Initialize the DFSDM channel MSP.

◆ HAL_DFSDM_ChannelDeInit()

HAL_StatusTypeDef HAL_DFSDM_ChannelDeInit ( DFSDM_Channel_HandleTypeDef hdfsdm_channel)

De-initialize the DFSDM channel.

Parameters
hdfsdm_channelDFSDM channel handle.
Return values
HALstatus.

Definition at line 465 of file stm32l4xx_hal_dfsdm.c.

466 {
467  /* Check DFSDM Channel handle */
468  if (hdfsdm_channel == NULL)
469  {
470  return HAL_ERROR;
471  }
472 
473  /* Check parameters */
474  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
475 
476  /* Check that channel has not been already deinitialized */
477  if (a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] == NULL)
478  {
479  return HAL_ERROR;
480  }
481 
482  /* Disable the DFSDM channel */
483  hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CHEN);
484 
485  /* Update the channel counter */
487 
488  /* Disable global DFSDM at deinit of last channel */
489  if (v_dfsdm1ChannelCounter == 0U)
490  {
491  DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN);
492  }
493 
494  /* Call MSP deinit function */
495 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
496  if (hdfsdm_channel->MspDeInitCallback == NULL)
497  {
498  hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
499  }
500  hdfsdm_channel->MspDeInitCallback(hdfsdm_channel);
501 #else
502  HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel);
503 #endif
504 
505  /* Set DFSDM Channel in reset state */
506  hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_RESET;
507 
508  /* Reset channel handle in DFSDM channel handle table */
510 
511  return HAL_OK;
512 }
static DFSDM_Channel_HandleTypeDef * a_dfsdm1ChannelHandle[DFSDM1_CHANNEL_NUMBER]
struct __DFSDM_Channel_HandleTypeDef else typedef struct endif DFSDM_Channel_HandleTypeDef
DFSDM channel handle structure definition.
void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
De-initialize the DFSDM channel MSP.
static __IO uint32_t v_dfsdm1ChannelCounter
return HAL_OK
static uint32_t DFSDM_GetChannelFromInstance(const DFSDM_Channel_TypeDef *Instance)
This function allows to get the channel number from channel instance.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_DFSDM_ChannelInit()

HAL_StatusTypeDef HAL_DFSDM_ChannelInit ( DFSDM_Channel_HandleTypeDef hdfsdm_channel)

Initialize the DFSDM channel according to the specified parameters in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle.

Parameters
hdfsdm_channelDFSDM channel handle.
Return values
HALstatus.

Definition at line 358 of file stm32l4xx_hal_dfsdm.c.

359 {
360  /* Check DFSDM Channel handle */
361  if (hdfsdm_channel == NULL)
362  {
363  return HAL_ERROR;
364  }
365 
366  /* Check parameters */
367  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
368  assert_param(IS_FUNCTIONAL_STATE(hdfsdm_channel->Init.OutputClock.Activation));
369  assert_param(IS_DFSDM_CHANNEL_INPUT(hdfsdm_channel->Init.Input.Multiplexer));
370  assert_param(IS_DFSDM_CHANNEL_DATA_PACKING(hdfsdm_channel->Init.Input.DataPacking));
371  assert_param(IS_DFSDM_CHANNEL_INPUT_PINS(hdfsdm_channel->Init.Input.Pins));
372  assert_param(IS_DFSDM_CHANNEL_SERIAL_INTERFACE_TYPE(hdfsdm_channel->Init.SerialInterface.Type));
373  assert_param(IS_DFSDM_CHANNEL_SPI_CLOCK(hdfsdm_channel->Init.SerialInterface.SpiClock));
374  assert_param(IS_DFSDM_CHANNEL_FILTER_ORDER(hdfsdm_channel->Init.Awd.FilterOrder));
375  assert_param(IS_DFSDM_CHANNEL_FILTER_OVS_RATIO(hdfsdm_channel->Init.Awd.Oversampling));
376  assert_param(IS_DFSDM_CHANNEL_OFFSET(hdfsdm_channel->Init.Offset));
377  assert_param(IS_DFSDM_CHANNEL_RIGHT_BIT_SHIFT(hdfsdm_channel->Init.RightBitShift));
378 
379  /* Check that channel has not been already initialized */
380  if (a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] != NULL)
381  {
382  return HAL_ERROR;
383  }
384 
385 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
386  /* Reset callback pointers to the weak predefined callbacks */
387  hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback;
388  hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback;
389 
390  /* Call MSP init function */
391  if (hdfsdm_channel->MspInitCallback == NULL)
392  {
393  hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
394  }
395  hdfsdm_channel->MspInitCallback(hdfsdm_channel);
396 #else
397  /* Call MSP init function */
398  HAL_DFSDM_ChannelMspInit(hdfsdm_channel);
399 #endif
400 
401  /* Update the channel counter */
403 
404  /* Configure output serial clock and enable global DFSDM interface only for first channel */
405  if (v_dfsdm1ChannelCounter == 1U)
406  {
407  assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel->Init.OutputClock.Selection));
408  /* Set the output serial clock source */
409  DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTSRC);
410  DFSDM1_Channel0->CHCFGR1 |= hdfsdm_channel->Init.OutputClock.Selection;
411 
412  /* Reset clock divider */
413  DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTDIV);
414  if (hdfsdm_channel->Init.OutputClock.Activation == ENABLE)
415  {
416  assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel->Init.OutputClock.Divider));
417  /* Set the output clock divider */
418  DFSDM1_Channel0->CHCFGR1 |= (uint32_t)((hdfsdm_channel->Init.OutputClock.Divider - 1U) <<
419  DFSDM_CHCFGR1_CKOUTDIV_Pos);
420  }
421 
422  /* enable the DFSDM global interface */
423  DFSDM1_Channel0->CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN;
424  }
425 
426  /* Set channel input parameters */
427  hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DATPACK | DFSDM_CHCFGR1_DATMPX |
428  DFSDM_CHCFGR1_CHINSEL);
429  hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.Input.Multiplexer |
430  hdfsdm_channel->Init.Input.DataPacking |
431  hdfsdm_channel->Init.Input.Pins);
432 
433  /* Set serial interface parameters */
434  hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SITP | DFSDM_CHCFGR1_SPICKSEL);
435  hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.SerialInterface.Type |
436  hdfsdm_channel->Init.SerialInterface.SpiClock);
437 
438  /* Set analog watchdog parameters */
439  hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_AWFORD | DFSDM_CHAWSCDR_AWFOSR);
440  hdfsdm_channel->Instance->CHAWSCDR |= (hdfsdm_channel->Init.Awd.FilterOrder |
441  ((hdfsdm_channel->Init.Awd.Oversampling - 1U) << DFSDM_CHAWSCDR_AWFOSR_Pos));
442 
443  /* Set channel offset and right bit shift */
444  hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET | DFSDM_CHCFGR2_DTRBS);
445  hdfsdm_channel->Instance->CHCFGR2 |= (((uint32_t) hdfsdm_channel->Init.Offset << DFSDM_CHCFGR2_OFFSET_Pos) |
446  (hdfsdm_channel->Init.RightBitShift << DFSDM_CHCFGR2_DTRBS_Pos));
447 
448  /* Enable DFSDM channel */
449  hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CHEN;
450 
451  /* Set DFSDM Channel to ready state */
452  hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_READY;
453 
454  /* Store channel handle in DFSDM channel handle table */
455  a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = hdfsdm_channel;
456 
457  return HAL_OK;
458 }
static DFSDM_Channel_HandleTypeDef * a_dfsdm1ChannelHandle[DFSDM1_CHANNEL_NUMBER]
void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
Short circuit detection callback.
static __IO uint32_t v_dfsdm1ChannelCounter
void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
Clock absence detection callback.
return HAL_OK
static uint32_t DFSDM_GetChannelFromInstance(const DFSDM_Channel_TypeDef *Instance)
This function allows to get the channel number from channel instance.
void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
Initialize the DFSDM channel MSP.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_DFSDM_ChannelMspDeInit()

__weak void HAL_DFSDM_ChannelMspDeInit ( DFSDM_Channel_HandleTypeDef hdfsdm_channel)

De-initialize the DFSDM channel MSP.

Parameters
hdfsdm_channelDFSDM channel handle.
Return values
None

Definition at line 534 of file stm32l4xx_hal_dfsdm.c.

535 {
536  /* Prevent unused argument(s) compilation warning */
537  UNUSED(hdfsdm_channel);
538 
539  /* NOTE : This function should not be modified, when the function is needed,
540  the HAL_DFSDM_ChannelMspDeInit could be implemented in the user file.
541  */
542 }

◆ HAL_DFSDM_ChannelMspInit()

__weak void HAL_DFSDM_ChannelMspInit ( DFSDM_Channel_HandleTypeDef hdfsdm_channel)

Initialize the DFSDM channel MSP.

Parameters
hdfsdm_channelDFSDM channel handle.
Return values
None

Definition at line 519 of file stm32l4xx_hal_dfsdm.c.

520 {
521  /* Prevent unused argument(s) compilation warning */
522  UNUSED(hdfsdm_channel);
523 
524  /* NOTE : This function should not be modified, when the function is needed,
525  the HAL_DFSDM_ChannelMspInit could be implemented in the user file.
526  */
527 }