STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization functions

Initialization and Configuration functions. More...

Functions

HAL_StatusTypeDef HAL_SAI_InitProtocol (SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot)
 Initialize the structure FrameInit, SlotInit and the low part of Init according to the specified parameters and call the function HAL_SAI_Init to initialize the SAI block. More...
 
HAL_StatusTypeDef HAL_SAI_Init (SAI_HandleTypeDef *hsai)
 Initialize the SAI according to the specified parameters. in the SAI_InitTypeDef structure and initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai)
 DeInitialize the SAI peripheral. More...
 
void HAL_SAI_MspInit (SAI_HandleTypeDef *hsai)
 Initialize the SAI MSP. More...
 
void HAL_SAI_MspDeInit (SAI_HandleTypeDef *hsai)
 DeInitialize the SAI MSP. More...
 
HAL_StatusTypeDef HAL_SAI_RegisterCallback (SAI_HandleTypeDef *hsai, HAL_SAI_CallbackIDTypeDef CallbackID, pSAI_CallbackTypeDef pCallback)
 Register a user SAI callback to be used instead of the weak predefined callback. More...
 
HAL_StatusTypeDef HAL_SAI_UnRegisterCallback (SAI_HandleTypeDef *hsai, HAL_SAI_CallbackIDTypeDef CallbackID)
 Unregister a user SAI callback. SAI callback is redirected to the weak predefined callback. More...
 

Detailed Description

Initialization and Configuration functions.

 ===============================================================================
             ##### Initialization and de-initialization functions #####
 ===============================================================================
  [..]  This subsection provides a set of functions allowing to initialize and
        de-initialize the SAIx peripheral:

      (+) User must implement HAL_SAI_MspInit() function in which he configures
          all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).

      (+) Call the function HAL_SAI_Init() to configure the selected device with
          the selected configuration:
        (++) Mode (Master/slave TX/RX)
        (++) Protocol
        (++) Data Size
        (++) MCLK Output
        (++) Audio frequency
        (++) FIFO Threshold
        (++) Frame Config
        (++) Slot Config
        (++) PDM Config (only for STM32L4Rx/STM32L4Sx devices)

      (+) Call the function HAL_SAI_DeInit() to restore the default configuration
          of the selected SAI peripheral.

Function Documentation

◆ HAL_SAI_DeInit()

HAL_StatusTypeDef HAL_SAI_DeInit ( SAI_HandleTypeDef hsai)

DeInitialize the SAI peripheral.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
HALstatus

Definition at line 693 of file stm32l4xx_hal_sai.c.

694 {
695  /* Check the SAI handle allocation */
696  if (hsai == NULL)
697  {
698  return HAL_ERROR;
699  }
700 
701  hsai->State = HAL_SAI_STATE_BUSY;
702 
703  /* Disabled All interrupt and clear all the flag */
704  hsai->Instance->IMR = 0;
705  hsai->Instance->CLRFR = 0xFFFFFFFFU;
706 
707  /* Disable the SAI */
708  if (SAI_Disable(hsai) != HAL_OK)
709  {
710  /* Reset SAI state to ready */
711  hsai->State = HAL_SAI_STATE_READY;
712 
713  /* Release Lock */
714  __HAL_UNLOCK(hsai);
715 
716  return HAL_ERROR;
717  }
718 
719  /* Flush the fifo */
720  SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH);
721 
722 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
723  /* Disable SAI PDM interface */
724  if (hsai->Instance == SAI1_Block_A)
725  {
726  /* Reset PDM delays */
727  SAI1->PDMDLY = 0U;
728 
729  /* Disable PDM interface */
730  SAI1->PDMCR &= ~(SAI_PDMCR_PDMEN);
731  }
732 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
733 
734  /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
735 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
736  if (hsai->MspDeInitCallback == NULL)
737  {
739  }
740  hsai->MspDeInitCallback(hsai);
741 #else
742  HAL_SAI_MspDeInit(hsai);
743 #endif
744 
745  /* Initialize the error code */
746  hsai->ErrorCode = HAL_SAI_ERROR_NONE;
747 
748  /* Initialize the SAI state */
749  hsai->State = HAL_SAI_STATE_RESET;
750 
751  /* Release Lock */
752  __HAL_UNLOCK(hsai);
753 
754  return HAL_OK;
755 }
static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai)
Disable the SAI and wait for the disabling.
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
return HAL_OK
void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai)
DeInitialize the SAI MSP.
void(* MspDeInitCallback)(struct __SAI_HandleTypeDef *hsai)

◆ HAL_SAI_Init()

HAL_StatusTypeDef HAL_SAI_Init ( SAI_HandleTypeDef hsai)

Initialize the SAI according to the specified parameters. in the SAI_InitTypeDef structure and initialize the associated handle.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
HALstatus

Definition at line 369 of file stm32l4xx_hal_sai.c.

370 {
371  uint32_t tmpregisterGCR;
372  uint32_t ckstr_bits;
373  uint32_t syncen_bits;
374 
375  /* Check the SAI handle allocation */
376  if (hsai == NULL)
377  {
378  return HAL_ERROR;
379  }
380 
381  /* check the instance */
382  assert_param(IS_SAI_ALL_INSTANCE(hsai->Instance));
383 
384  /* Check the SAI Block parameters */
385  assert_param(IS_SAI_AUDIO_FREQUENCY(hsai->Init.AudioFrequency));
386  assert_param(IS_SAI_BLOCK_PROTOCOL(hsai->Init.Protocol));
387  assert_param(IS_SAI_BLOCK_MODE(hsai->Init.AudioMode));
388  assert_param(IS_SAI_BLOCK_DATASIZE(hsai->Init.DataSize));
389  assert_param(IS_SAI_BLOCK_FIRST_BIT(hsai->Init.FirstBit));
390  assert_param(IS_SAI_BLOCK_CLOCK_STROBING(hsai->Init.ClockStrobing));
391  assert_param(IS_SAI_BLOCK_SYNCHRO(hsai->Init.Synchro));
392  assert_param(IS_SAI_BLOCK_OUTPUT_DRIVE(hsai->Init.OutputDrive));
393  assert_param(IS_SAI_BLOCK_NODIVIDER(hsai->Init.NoDivider));
394  assert_param(IS_SAI_BLOCK_FIFO_THRESHOLD(hsai->Init.FIFOThreshold));
395  assert_param(IS_SAI_MONO_STEREO_MODE(hsai->Init.MonoStereoMode));
396  assert_param(IS_SAI_BLOCK_COMPANDING_MODE(hsai->Init.CompandingMode));
397  assert_param(IS_SAI_BLOCK_TRISTATE_MANAGEMENT(hsai->Init.TriState));
398  assert_param(IS_SAI_BLOCK_SYNCEXT(hsai->Init.SynchroExt));
399 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
400  assert_param(IS_SAI_BLOCK_MCK_OVERSAMPLING(hsai->Init.MckOverSampling));
401 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
402 
403  /* Check the SAI Block Frame parameters */
404  assert_param(IS_SAI_BLOCK_FRAME_LENGTH(hsai->FrameInit.FrameLength));
405  assert_param(IS_SAI_BLOCK_ACTIVE_FRAME(hsai->FrameInit.ActiveFrameLength));
406  assert_param(IS_SAI_BLOCK_FS_DEFINITION(hsai->FrameInit.FSDefinition));
407  assert_param(IS_SAI_BLOCK_FS_POLARITY(hsai->FrameInit.FSPolarity));
408  assert_param(IS_SAI_BLOCK_FS_OFFSET(hsai->FrameInit.FSOffset));
409 
410  /* Check the SAI Block Slot parameters */
411  assert_param(IS_SAI_BLOCK_FIRSTBIT_OFFSET(hsai->SlotInit.FirstBitOffset));
412  assert_param(IS_SAI_BLOCK_SLOT_SIZE(hsai->SlotInit.SlotSize));
413  assert_param(IS_SAI_BLOCK_SLOT_NUMBER(hsai->SlotInit.SlotNumber));
414  assert_param(IS_SAI_SLOT_ACTIVE(hsai->SlotInit.SlotActive));
415 
416 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
417  /* Check the SAI PDM parameters */
418  assert_param(IS_FUNCTIONAL_STATE(hsai->Init.PdmInit.Activation));
419  if (hsai->Init.PdmInit.Activation == ENABLE)
420  {
421  assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(hsai->Init.PdmInit.MicPairsNbr));
422  assert_param(IS_SAI_PDM_CLOCK_ENABLE(hsai->Init.PdmInit.ClockEnable));
423  /* Check that SAI sub-block is SAI1 sub-block A, in master RX mode with free protocol */
424  if ((hsai->Instance != SAI1_Block_A) ||
425  (hsai->Init.AudioMode != SAI_MODEMASTER_RX) ||
426  (hsai->Init.Protocol != SAI_FREE_PROTOCOL))
427  {
428  return HAL_ERROR;
429  }
430  }
431 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
432 
433  if (hsai->State == HAL_SAI_STATE_RESET)
434  {
435  /* Allocate lock resource and initialize it */
436  hsai->Lock = HAL_UNLOCKED;
437 
438 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
439  /* Reset callback pointers to the weak predefined callbacks */
445 
446  /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
447  if (hsai->MspInitCallback == NULL)
448  {
450  }
451  hsai->MspInitCallback(hsai);
452 #else
453  /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
454  HAL_SAI_MspInit(hsai);
455 #endif
456  }
457 
458  /* Disable the selected SAI peripheral */
459  if (SAI_Disable(hsai) != HAL_OK)
460  {
461  return HAL_ERROR;
462  }
463 
464  hsai->State = HAL_SAI_STATE_BUSY;
465 
466  /* SAI Block Synchro Configuration -----------------------------------------*/
467  /* This setting must be done with both audio block (A & B) disabled */
468  switch (hsai->Init.SynchroExt)
469  {
470  case SAI_SYNCEXT_DISABLE :
471  tmpregisterGCR = 0;
472  break;
473  case SAI_SYNCEXT_OUTBLOCKA_ENABLE :
474  tmpregisterGCR = SAI_GCR_SYNCOUT_0;
475  break;
476  case SAI_SYNCEXT_OUTBLOCKB_ENABLE :
477  tmpregisterGCR = SAI_GCR_SYNCOUT_1;
478  break;
479  default :
480  tmpregisterGCR = 0;
481  break;
482  }
483 
484  switch (hsai->Init.Synchro)
485  {
486  case SAI_ASYNCHRONOUS :
487  syncen_bits = 0;
488  break;
489  case SAI_SYNCHRONOUS :
490  syncen_bits = SAI_xCR1_SYNCEN_0;
491  break;
492  case SAI_SYNCHRONOUS_EXT_SAI1 :
493  syncen_bits = SAI_xCR1_SYNCEN_1;
494  break;
495  case SAI_SYNCHRONOUS_EXT_SAI2 :
496  syncen_bits = SAI_xCR1_SYNCEN_1;
497  tmpregisterGCR |= SAI_GCR_SYNCIN_0;
498  break;
499  default :
500  syncen_bits = 0;
501  break;
502  }
503 
504 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || \
505  defined(STM32L496xx) || defined(STM32L4A6xx) || \
506  defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
507 
508  if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B))
509  {
510  SAI1->GCR = tmpregisterGCR;
511  }
512  else
513  {
514  SAI2->GCR = tmpregisterGCR;
515  }
516 
517 #else
518 
519  SAI1->GCR = tmpregisterGCR;
520 
521 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || */
522  /* STM32L496xx || STM32L4A6xx || */
523  /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
524 
525  if (hsai->Init.AudioFrequency != SAI_AUDIO_FREQUENCY_MCKDIV)
526  {
527  uint32_t freq;
528  uint32_t tmpval;
529 
530  /* In this case, the MCKDIV value is calculated to get AudioFrequency */
531 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || \
532  defined(STM32L496xx) || defined(STM32L4A6xx) || \
533  defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
534 
535  if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B))
536  {
537  freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI1);
538  }
539  else
540  {
541  /* SAI2_Block_A or SAI2_Block_B */
542  freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI2);
543  }
544 
545 #else
546 
547  freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI1);
548 
549 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || */
550  /* STM32L496xx || STM32L4A6xx || */
551  /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
552 
553 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
554  /* Configure Master Clock Divider using the following formula :
555  - If NOMCK = 1 :
556  MCKDIV[5:0] = SAI_CK_x / (FS * (FRL + 1))
557  - If NOMCK = 0 :
558  MCKDIV[5:0] = SAI_CK_x / (FS * (OSR + 1) * 256) */
559  if (hsai->Init.NoDivider == SAI_MASTERDIVIDER_DISABLE)
560  {
561  /* NOMCK = 1 */
562  /* (freq x 10) to keep Significant digits */
563  tmpval = (freq * 10U) / (hsai->Init.AudioFrequency * hsai->FrameInit.FrameLength);
564  }
565  else
566  {
567  /* NOMCK = 0 */
568  uint32_t tmposr;
569  tmposr = (hsai->Init.MckOverSampling == SAI_MCK_OVERSAMPLING_ENABLE) ? 2U : 1U;
570  /* (freq x 10) to keep Significant digits */
571  tmpval = (freq * 10U) / (hsai->Init.AudioFrequency * tmposr * 256U);
572  }
573  hsai->Init.Mckdiv = tmpval / 10U;
574 
575  /* Round result to the nearest integer */
576  if ((tmpval % 10U) > 8U)
577  {
578  hsai->Init.Mckdiv += 1U;
579  }
580 #else
581  /* Configure Master Clock using the following formula :
582  MCLK_x = SAI_CK_x / (MCKDIV[3:0] * 2) with MCLK_x = 256 * FS
583  FS = SAI_CK_x / (MCKDIV[3:0] * 2) * 256
584  MCKDIV[3:0] = SAI_CK_x / FS * 512 */
585  /* (freq x 10) to keep Significant digits */
586  tmpval = (freq * 10U) / (hsai->Init.AudioFrequency * 2U * 256U);
587  hsai->Init.Mckdiv = tmpval / 10U;
588 
589  /* Round result to the nearest integer */
590  if ((tmpval % 10U) > 8U)
591  {
592  hsai->Init.Mckdiv += 1U;
593  }
594 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
595  }
596  /* Check the SAI Block master clock divider parameter */
597  assert_param(IS_SAI_BLOCK_MASTER_DIVIDER(hsai->Init.Mckdiv));
598 
599  /* Compute CKSTR bits of SAI CR1 according ClockStrobing and AudioMode */
600  if ((hsai->Init.AudioMode == SAI_MODEMASTER_TX) || (hsai->Init.AudioMode == SAI_MODESLAVE_TX))
601  {
602  /* Transmit */
603  ckstr_bits = (hsai->Init.ClockStrobing == SAI_CLOCKSTROBING_RISINGEDGE) ? 0U : SAI_xCR1_CKSTR;
604  }
605  else
606  {
607  /* Receive */
608  ckstr_bits = (hsai->Init.ClockStrobing == SAI_CLOCKSTROBING_RISINGEDGE) ? SAI_xCR1_CKSTR : 0U;
609  }
610 
611  /* SAI Block Configuration -------------------------------------------------*/
612  /* SAI CR1 Configuration */
613 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
614  hsai->Instance->CR1 &= ~(SAI_xCR1_MODE | SAI_xCR1_PRTCFG | SAI_xCR1_DS | \
615  SAI_xCR1_LSBFIRST | SAI_xCR1_CKSTR | SAI_xCR1_SYNCEN | \
616  SAI_xCR1_MONO | SAI_xCR1_OUTDRIV | SAI_xCR1_DMAEN | \
617  SAI_xCR1_NOMCK | SAI_xCR1_MCKDIV | SAI_xCR1_OSR);
618 
619  hsai->Instance->CR1 |= (hsai->Init.AudioMode | hsai->Init.Protocol | \
620  hsai->Init.DataSize | hsai->Init.FirstBit | \
621  ckstr_bits | syncen_bits | \
622  hsai->Init.MonoStereoMode | hsai->Init.OutputDrive | \
623  hsai->Init.NoDivider | (hsai->Init.Mckdiv << 20) | \
624  hsai->Init.MckOverSampling);
625 #else
626  hsai->Instance->CR1 &= ~(SAI_xCR1_MODE | SAI_xCR1_PRTCFG | SAI_xCR1_DS | \
627  SAI_xCR1_LSBFIRST | SAI_xCR1_CKSTR | SAI_xCR1_SYNCEN | \
628  SAI_xCR1_MONO | SAI_xCR1_OUTDRIV | SAI_xCR1_DMAEN | \
629  SAI_xCR1_NODIV | SAI_xCR1_MCKDIV);
630 
631  hsai->Instance->CR1 |= (hsai->Init.AudioMode | hsai->Init.Protocol | \
632  hsai->Init.DataSize | hsai->Init.FirstBit | \
633  ckstr_bits | syncen_bits | \
634  hsai->Init.MonoStereoMode | hsai->Init.OutputDrive | \
635  hsai->Init.NoDivider | (hsai->Init.Mckdiv << 20));
636 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
637 
638  /* SAI CR2 Configuration */
639  hsai->Instance->CR2 &= ~(SAI_xCR2_FTH | SAI_xCR2_FFLUSH | SAI_xCR2_COMP | SAI_xCR2_CPL);
640  hsai->Instance->CR2 |= (hsai->Init.FIFOThreshold | hsai->Init.CompandingMode | hsai->Init.TriState);
641 
642  /* SAI Frame Configuration -----------------------------------------*/
643  hsai->Instance->FRCR &= (~(SAI_xFRCR_FRL | SAI_xFRCR_FSALL | SAI_xFRCR_FSDEF | \
644  SAI_xFRCR_FSPOL | SAI_xFRCR_FSOFF));
645  hsai->Instance->FRCR |= ((hsai->FrameInit.FrameLength - 1U) |
646  hsai->FrameInit.FSOffset |
647  hsai->FrameInit.FSDefinition |
648  hsai->FrameInit.FSPolarity |
649  ((hsai->FrameInit.ActiveFrameLength - 1U) << 8));
650 
651  /* SAI Block_x SLOT Configuration ------------------------------------------*/
652  /* This register has no meaning in AC 97 and SPDIF audio protocol */
653  hsai->Instance->SLOTR &= (~(SAI_xSLOTR_FBOFF | SAI_xSLOTR_SLOTSZ | \
654  SAI_xSLOTR_NBSLOT | SAI_xSLOTR_SLOTEN));
655 
656  hsai->Instance->SLOTR |= hsai->SlotInit.FirstBitOffset | hsai->SlotInit.SlotSize | \
657  (hsai->SlotInit.SlotActive << 16) | ((hsai->SlotInit.SlotNumber - 1U) << 8);
658 
659 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
660  /* SAI PDM Configuration ---------------------------------------------------*/
661  if (hsai->Instance == SAI1_Block_A)
662  {
663  /* Disable PDM interface */
664  SAI1->PDMCR &= ~(SAI_PDMCR_PDMEN);
665  if (hsai->Init.PdmInit.Activation == ENABLE)
666  {
667  /* Configure and enable PDM interface */
668  SAI1->PDMCR = (hsai->Init.PdmInit.ClockEnable |
669  ((hsai->Init.PdmInit.MicPairsNbr - 1U) << SAI_PDMCR_MICNBR_Pos));
670  SAI1->PDMCR |= SAI_PDMCR_PDMEN;
671  }
672  }
673 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
674 
675  /* Initialize the error code */
676  hsai->ErrorCode = HAL_SAI_ERROR_NONE;
677 
678  /* Initialize the SAI state */
679  hsai->State = HAL_SAI_STATE_READY;
680 
681  /* Release Lock */
682  __HAL_UNLOCK(hsai);
683 
684  return HAL_OK;
685 }
static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai)
Disable the SAI and wait for the disabling.
void(* TxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
HAL_LockTypeDef Lock
void(* RxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer half completed callback.
void(* RxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
return HAL_OK
void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
SAI error callback.
SAI_InitTypeDef Init
SAI_SlotInitTypeDef SlotInit
FunctionalState Activation
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer completed callback.
SAI_FrameInitTypeDef FrameInit
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
Return the peripheral clock frequency for peripherals with clock source from PLLSAIs.
SAI_PdmInitTypeDef PdmInit
void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai)
Initialize the SAI MSP.
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer completed callback.
void(* TxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void(* MspInitCallback)(struct __SAI_HandleTypeDef *hsai)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer Half completed callback.
void(* ErrorCallback)(struct __SAI_HandleTypeDef *hsai)

◆ HAL_SAI_InitProtocol()

HAL_StatusTypeDef HAL_SAI_InitProtocol ( SAI_HandleTypeDef hsai,
uint32_t  protocol,
uint32_t  datasize,
uint32_t  nbslot 
)

Initialize the structure FrameInit, SlotInit and the low part of Init according to the specified parameters and call the function HAL_SAI_Init to initialize the SAI block.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
protocolone of the supported protocol SAI Supported protocol
datasizeone of the supported datasize SAI protocol data size the configuration information for SAI module.
nbslotNumber of slot.
Return values
HALstatus

Definition at line 330 of file stm32l4xx_hal_sai.c.

331 {
332  HAL_StatusTypeDef status;
333 
334  /* Check the parameters */
335  assert_param(IS_SAI_SUPPORTED_PROTOCOL(protocol));
336  assert_param(IS_SAI_PROTOCOL_DATASIZE(datasize));
337 
338  switch (protocol)
339  {
340  case SAI_I2S_STANDARD :
341  case SAI_I2S_MSBJUSTIFIED :
342  case SAI_I2S_LSBJUSTIFIED :
343  status = SAI_InitI2S(hsai, protocol, datasize, nbslot);
344  break;
345  case SAI_PCM_LONG :
346  case SAI_PCM_SHORT :
347  status = SAI_InitPCM(hsai, protocol, datasize, nbslot);
348  break;
349  default :
350  status = HAL_ERROR;
351  break;
352  }
353 
354  if (status == HAL_OK)
355  {
356  status = HAL_SAI_Init(hsai);
357  }
358 
359  return status;
360 }
static HAL_StatusTypeDef SAI_InitPCM(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot)
Initialize the SAI PCM protocol according to the specified parameters in the SAI_InitTypeDef and crea...
return HAL_OK
HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai)
Initialize the SAI according to the specified parameters. in the SAI_InitTypeDef structure and initia...
static HAL_StatusTypeDef SAI_InitI2S(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot)
Initialize the SAI I2S protocol according to the specified parameters in the SAI_InitTypeDef and crea...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SAI_MspDeInit()

__weak void HAL_SAI_MspDeInit ( SAI_HandleTypeDef hsai)

DeInitialize the SAI MSP.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 779 of file stm32l4xx_hal_sai.c.

780 {
781  /* Prevent unused argument(s) compilation warning */
782  UNUSED(hsai);
783 
784  /* NOTE : This function should not be modified, when the callback is needed,
785  the HAL_SAI_MspDeInit could be implemented in the user file
786  */
787 }

◆ HAL_SAI_MspInit()

__weak void HAL_SAI_MspInit ( SAI_HandleTypeDef hsai)

Initialize the SAI MSP.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 763 of file stm32l4xx_hal_sai.c.

764 {
765  /* Prevent unused argument(s) compilation warning */
766  UNUSED(hsai);
767 
768  /* NOTE : This function should not be modified, when the callback is needed,
769  the HAL_SAI_MspInit could be implemented in the user file
770  */
771 }

◆ HAL_SAI_RegisterCallback()

HAL_StatusTypeDef HAL_SAI_RegisterCallback ( SAI_HandleTypeDef hsai,
HAL_SAI_CallbackIDTypeDef  CallbackID,
pSAI_CallbackTypeDef  pCallback 
)

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

Parameters
hsaiSAI 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 806 of file stm32l4xx_hal_sai.c.

809 {
810  HAL_StatusTypeDef status = HAL_OK;
811 
812  if (pCallback == NULL)
813  {
814  /* update the error code */
815  hsai->ErrorCode |= HAL_SAI_ERROR_INVALID_CALLBACK;
816  /* update return status */
817  status = HAL_ERROR;
818  }
819  else
820  {
821  if (HAL_SAI_STATE_READY == hsai->State)
822  {
823  switch (CallbackID)
824  {
826  hsai->RxCpltCallback = pCallback;
827  break;
829  hsai->RxHalfCpltCallback = pCallback;
830  break;
832  hsai->TxCpltCallback = pCallback;
833  break;
835  hsai->TxHalfCpltCallback = pCallback;
836  break;
837  case HAL_SAI_ERROR_CB_ID :
838  hsai->ErrorCallback = pCallback;
839  break;
840  case HAL_SAI_MSPINIT_CB_ID :
841  hsai->MspInitCallback = pCallback;
842  break;
844  hsai->MspDeInitCallback = pCallback;
845  break;
846  default :
847  /* update the error code */
848  hsai->ErrorCode |= HAL_SAI_ERROR_INVALID_CALLBACK;
849  /* update return status */
850  status = HAL_ERROR;
851  break;
852  }
853  }
854  else if (HAL_SAI_STATE_RESET == hsai->State)
855  {
856  switch (CallbackID)
857  {
858  case HAL_SAI_MSPINIT_CB_ID :
859  hsai->MspInitCallback = pCallback;
860  break;
862  hsai->MspDeInitCallback = pCallback;
863  break;
864  default :
865  /* update the error code */
866  hsai->ErrorCode |= HAL_SAI_ERROR_INVALID_CALLBACK;
867  /* update return status */
868  status = HAL_ERROR;
869  break;
870  }
871  }
872  else
873  {
874  /* update the error code */
875  hsai->ErrorCode |= HAL_SAI_ERROR_INVALID_CALLBACK;
876  /* update return status */
877  status = HAL_ERROR;
878  }
879  }
880  return status;
881 }
void(* TxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void(* RxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void(* RxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
__IO HAL_SAI_StateTypeDef State
return HAL_OK
void(* MspDeInitCallback)(struct __SAI_HandleTypeDef *hsai)
void(* TxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void(* MspInitCallback)(struct __SAI_HandleTypeDef *hsai)
void(* ErrorCallback)(struct __SAI_HandleTypeDef *hsai)

◆ HAL_SAI_UnRegisterCallback()

HAL_StatusTypeDef HAL_SAI_UnRegisterCallback ( SAI_HandleTypeDef hsai,
HAL_SAI_CallbackIDTypeDef  CallbackID 
)

Unregister a user SAI callback. SAI callback is redirected to the weak predefined callback.

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

Definition at line 898 of file stm32l4xx_hal_sai.c.

900 {
901  HAL_StatusTypeDef status = HAL_OK;
902 
903  if (HAL_SAI_STATE_READY == hsai->State)
904  {
905  switch (CallbackID)
906  {
909  break;
912  break;
915  break;
918  break;
919  case HAL_SAI_ERROR_CB_ID :
921  break;
922  case HAL_SAI_MSPINIT_CB_ID :
924  break;
927  break;
928  default :
929  /* update the error code */
930  hsai->ErrorCode |= HAL_SAI_ERROR_INVALID_CALLBACK;
931  /* update return status */
932  status = HAL_ERROR;
933  break;
934  }
935  }
936  else if (HAL_SAI_STATE_RESET == hsai->State)
937  {
938  switch (CallbackID)
939  {
940  case HAL_SAI_MSPINIT_CB_ID :
942  break;
945  break;
946  default :
947  /* update the error code */
948  hsai->ErrorCode |= HAL_SAI_ERROR_INVALID_CALLBACK;
949  /* update return status */
950  status = HAL_ERROR;
951  break;
952  }
953  }
954  else
955  {
956  /* update the error code */
957  hsai->ErrorCode |= HAL_SAI_ERROR_INVALID_CALLBACK;
958  /* update return status */
959  status = HAL_ERROR;
960  }
961  return status;
962 }
void(* TxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void(* RxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer half completed callback.
void(* RxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
__IO HAL_SAI_StateTypeDef State
return HAL_OK
void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
SAI error callback.
void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai)
DeInitialize the SAI MSP.
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer completed callback.
void(* MspDeInitCallback)(struct __SAI_HandleTypeDef *hsai)
void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai)
Initialize the SAI MSP.
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer completed callback.
void(* TxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void(* MspInitCallback)(struct __SAI_HandleTypeDef *hsai)
void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer Half completed callback.
void(* ErrorCallback)(struct __SAI_HandleTypeDef *hsai)