STM32L4xx_HAL_Driver  1.14.0
IO operation functions

Data transfers functions. More...

Functions

HAL_StatusTypeDef HAL_SAI_Transmit (SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout)
 Transmit an amount of data in blocking mode. More...
 
HAL_StatusTypeDef HAL_SAI_Receive (SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout)
 Receive an amount of data in blocking mode. More...
 
HAL_StatusTypeDef HAL_SAI_Transmit_IT (SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size)
 Transmit an amount of data in non-blocking mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SAI_Receive_IT (SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size)
 Receive an amount of data in non-blocking mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SAI_Transmit_DMA (SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size)
 Transmit an amount of data in non-blocking mode with DMA. More...
 
HAL_StatusTypeDef HAL_SAI_Receive_DMA (SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size)
 Receive an amount of data in non-blocking mode with DMA. More...
 
HAL_StatusTypeDef HAL_SAI_DMAPause (SAI_HandleTypeDef *hsai)
 Pause the audio stream playing from the Media. More...
 
HAL_StatusTypeDef HAL_SAI_DMAResume (SAI_HandleTypeDef *hsai)
 Resume the audio stream playing from the Media. More...
 
HAL_StatusTypeDef HAL_SAI_DMAStop (SAI_HandleTypeDef *hsai)
 Stop the audio stream playing from the Media. More...
 
HAL_StatusTypeDef HAL_SAI_Abort (SAI_HandleTypeDef *hsai)
 Abort the current transfer and disable the SAI. More...
 
HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode (SAI_HandleTypeDef *hsai, uint16_t val)
 Enable the Tx mute mode. More...
 
HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode (SAI_HandleTypeDef *hsai)
 Disable the Tx mute mode. More...
 
HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode (SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter)
 Enable the Rx mute detection. More...
 
HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode (SAI_HandleTypeDef *hsai)
 Disable the Rx mute detection. More...
 
void HAL_SAI_IRQHandler (SAI_HandleTypeDef *hsai)
 Handle SAI interrupt request. More...
 
void HAL_SAI_TxHalfCpltCallback (SAI_HandleTypeDef *hsai)
 Tx Transfer Half completed callback. More...
 
void HAL_SAI_TxCpltCallback (SAI_HandleTypeDef *hsai)
 Tx Transfer completed callback. More...
 
void HAL_SAI_RxHalfCpltCallback (SAI_HandleTypeDef *hsai)
 Rx Transfer half completed callback. More...
 
void HAL_SAI_RxCpltCallback (SAI_HandleTypeDef *hsai)
 Rx Transfer completed callback. More...
 
void HAL_SAI_ErrorCallback (SAI_HandleTypeDef *hsai)
 SAI error callback. More...
 

Detailed Description

Data transfers functions.

  ==============================================================================
                      ##### IO operation functions #####
  ==============================================================================
  [..]
    This subsection provides a set of functions allowing to manage the SAI data
    transfers.

    (+) There are two modes of transfer:
      (++) Blocking mode : The communication is performed in the polling mode.
           The status of all data processing is returned by the same function
           after finishing transfer.
      (++) No-Blocking mode : The communication is performed using Interrupts
           or DMA. These functions return the status of the transfer startup.
           The end of the data processing will be indicated through the
           dedicated SAI IRQ when using Interrupt mode or the DMA IRQ when
           using DMA mode.

    (+) Blocking mode functions are :
      (++) HAL_SAI_Transmit()
      (++) HAL_SAI_Receive()

    (+) Non Blocking mode functions with Interrupt are :
      (++) HAL_SAI_Transmit_IT()
      (++) HAL_SAI_Receive_IT()

    (+) Non Blocking mode functions with DMA are :
      (++) HAL_SAI_Transmit_DMA()
      (++) HAL_SAI_Receive_DMA()

    (+) A set of Transfer Complete Callbacks are provided in non Blocking mode:
      (++) HAL_SAI_TxCpltCallback()
      (++) HAL_SAI_RxCpltCallback()
      (++) HAL_SAI_ErrorCallback()

Function Documentation

◆ HAL_SAI_Abort()

HAL_StatusTypeDef HAL_SAI_Abort ( SAI_HandleTypeDef hsai)

Abort the current transfer and disable the SAI.

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

Definition at line 1472 of file stm32l4xx_hal_sai.c.

1473 {
1474  HAL_StatusTypeDef status = HAL_OK;
1475 
1476  /* Process Locked */
1477  __HAL_LOCK(hsai);
1478 
1479  /* Check SAI DMA is enabled or not */
1480  if ((hsai->Instance->CR1 & SAI_xCR1_DMAEN) == SAI_xCR1_DMAEN)
1481  {
1482  /* Disable the SAI DMA request */
1483  hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN;
1484 
1485  /* Abort the SAI Tx DMA Stream */
1486  if ((hsai->State == HAL_SAI_STATE_BUSY_TX) && (hsai->hdmatx != NULL))
1487  {
1488  if (HAL_DMA_Abort(hsai->hdmatx) != HAL_OK)
1489  {
1490  /* If the DMA Tx errorCode is different from DMA No Transfer then return Error */
1491  if (hsai->hdmatx->ErrorCode != HAL_DMA_ERROR_NO_XFER)
1492  {
1493  status = HAL_ERROR;
1494  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1495  }
1496  }
1497  }
1498 
1499  /* Abort the SAI Rx DMA Stream */
1500  if ((hsai->State == HAL_SAI_STATE_BUSY_RX) && (hsai->hdmarx != NULL))
1501  {
1502  if (HAL_DMA_Abort(hsai->hdmarx) != HAL_OK)
1503  {
1504  /* If the DMA Rx errorCode is different from DMA No Transfer then return Error */
1505  if (hsai->hdmarx->ErrorCode != HAL_DMA_ERROR_NO_XFER)
1506  {
1507  status = HAL_ERROR;
1508  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1509  }
1510  }
1511  }
1512  }
1513 
1514  /* Disabled All interrupt and clear all the flag */
1515  hsai->Instance->IMR = 0;
1516  hsai->Instance->CLRFR = 0xFFFFFFFFU;
1517 
1518  /* Disable SAI peripheral */
1519  if (SAI_Disable(hsai) != HAL_OK)
1520  {
1521  status = HAL_ERROR;
1522  }
1523 
1524  /* Flush the fifo */
1525  SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH);
1526 
1527  /* Set hsai state to ready */
1528  hsai->State = HAL_SAI_STATE_READY;
1529 
1530  /* Process Unlocked */
1531  __HAL_UNLOCK(hsai);
1532 
1533  return status;
1534 }
DMA_HandleTypeDef * hdmarx
static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai)
Disable the SAI and wait for the disabling.
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
DMA_HandleTypeDef * hdmatx
__IO HAL_SAI_StateTypeDef State
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.

◆ HAL_SAI_DisableRxMuteMode()

HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode ( SAI_HandleTypeDef hsai)

Disable the Rx mute detection.

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

Definition at line 1760 of file stm32l4xx_hal_sai.c.

1761 {
1762  if (hsai->State != HAL_SAI_STATE_RESET)
1763  {
1764  /* set the mutecallback to NULL */
1765  hsai->mutecallback = NULL;
1766  /* enable the IT interrupt */
1767  __HAL_SAI_DISABLE_IT(hsai, SAI_IT_MUTEDET);
1768  return HAL_OK;
1769  }
1770  return HAL_ERROR;
1771 }
__IO HAL_SAI_StateTypeDef State
return HAL_OK

◆ HAL_SAI_DisableTxMuteMode()

HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode ( SAI_HandleTypeDef hsai)

Disable the Tx mute mode.

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

Definition at line 1719 of file stm32l4xx_hal_sai.c.

1720 {
1721  if (hsai->State != HAL_SAI_STATE_RESET)
1722  {
1723  CLEAR_BIT(hsai->Instance->CR2, SAI_xCR2_MUTEVAL | SAI_xCR2_MUTE);
1724  return HAL_OK;
1725  }
1726  return HAL_ERROR;
1727 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
return HAL_OK

◆ HAL_SAI_DMAPause()

HAL_StatusTypeDef HAL_SAI_DMAPause ( SAI_HandleTypeDef hsai)

Pause the audio stream playing from the Media.

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

Definition at line 1363 of file stm32l4xx_hal_sai.c.

1364 {
1365  /* Process Locked */
1366  __HAL_LOCK(hsai);
1367 
1368  /* Pause the audio file playing by disabling the SAI DMA requests */
1369  hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN;
1370 
1371  /* Process Unlocked */
1372  __HAL_UNLOCK(hsai);
1373 
1374  return HAL_OK;
1375 }
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_SAI_DMAResume()

HAL_StatusTypeDef HAL_SAI_DMAResume ( SAI_HandleTypeDef hsai)

Resume the audio stream playing from the Media.

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

Definition at line 1383 of file stm32l4xx_hal_sai.c.

1384 {
1385  /* Process Locked */
1386  __HAL_LOCK(hsai);
1387 
1388  /* Enable the SAI DMA requests */
1389  hsai->Instance->CR1 |= SAI_xCR1_DMAEN;
1390 
1391  /* If the SAI peripheral is still not enabled, enable it */
1392  if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0U)
1393  {
1394  /* Enable SAI peripheral */
1395  __HAL_SAI_ENABLE(hsai);
1396  }
1397 
1398  /* Process Unlocked */
1399  __HAL_UNLOCK(hsai);
1400 
1401  return HAL_OK;
1402 }
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_SAI_DMAStop()

HAL_StatusTypeDef HAL_SAI_DMAStop ( SAI_HandleTypeDef hsai)

Stop the audio stream playing from the Media.

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

Definition at line 1410 of file stm32l4xx_hal_sai.c.

1411 {
1412  HAL_StatusTypeDef status = HAL_OK;
1413 
1414  /* Process Locked */
1415  __HAL_LOCK(hsai);
1416 
1417  /* Disable the SAI DMA request */
1418  hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN;
1419 
1420  /* Abort the SAI Tx DMA Stream */
1421  if ((hsai->State == HAL_SAI_STATE_BUSY_TX) && (hsai->hdmatx != NULL))
1422  {
1423  if (HAL_DMA_Abort(hsai->hdmatx) != HAL_OK)
1424  {
1425  /* If the DMA Tx errorCode is different from DMA No Transfer then return Error */
1426  if (hsai->hdmatx->ErrorCode != HAL_DMA_ERROR_NO_XFER)
1427  {
1428  status = HAL_ERROR;
1429  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1430  }
1431  }
1432  }
1433 
1434  /* Abort the SAI Rx DMA Stream */
1435  if ((hsai->State == HAL_SAI_STATE_BUSY_RX) && (hsai->hdmarx != NULL))
1436  {
1437  if (HAL_DMA_Abort(hsai->hdmarx) != HAL_OK)
1438  {
1439  /* If the DMA Rx errorCode is different from DMA No Transfer then return Error */
1440  if (hsai->hdmarx->ErrorCode != HAL_DMA_ERROR_NO_XFER)
1441  {
1442  status = HAL_ERROR;
1443  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1444  }
1445  }
1446  }
1447 
1448  /* Disable SAI peripheral */
1449  if (SAI_Disable(hsai) != HAL_OK)
1450  {
1451  status = HAL_ERROR;
1452  }
1453 
1454  /* Flush the fifo */
1455  SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH);
1456 
1457  /* Set hsai state to ready */
1458  hsai->State = HAL_SAI_STATE_READY;
1459 
1460  /* Process Unlocked */
1461  __HAL_UNLOCK(hsai);
1462 
1463  return status;
1464 }
DMA_HandleTypeDef * hdmarx
static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai)
Disable the SAI and wait for the disabling.
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
DMA_HandleTypeDef * hdmatx
__IO HAL_SAI_StateTypeDef State
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.

◆ HAL_SAI_EnableRxMuteMode()

HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode ( SAI_HandleTypeDef hsai,
SAIcallback  callback,
uint16_t  counter 
)

Enable the Rx mute detection.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
callbackfunction called when the mute is detected.
counternumber a data before mute detection max 63.
Return values
HALstatus

Definition at line 1737 of file stm32l4xx_hal_sai.c.

1738 {
1739  assert_param(IS_SAI_BLOCK_MUTE_COUNTER(counter));
1740 
1741  if (hsai->State != HAL_SAI_STATE_RESET)
1742  {
1743  /* set the mute counter */
1744  CLEAR_BIT(hsai->Instance->CR2, SAI_xCR2_MUTECNT);
1745  SET_BIT(hsai->Instance->CR2, (uint32_t)((uint32_t)counter << SAI_xCR2_MUTECNT_Pos));
1746  hsai->mutecallback = callback;
1747  /* enable the IT interrupt */
1748  __HAL_SAI_ENABLE_IT(hsai, SAI_IT_MUTEDET);
1749  return HAL_OK;
1750  }
1751  return HAL_ERROR;
1752 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SAI_EnableTxMuteMode()

HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode ( SAI_HandleTypeDef hsai,
uint16_t  val 
)

Enable the Tx mute mode.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
valvalue sent during the mute SAI Block Mute Value
Return values
HALstatus

Definition at line 1700 of file stm32l4xx_hal_sai.c.

1701 {
1702  assert_param(IS_SAI_BLOCK_MUTE_VALUE(val));
1703 
1704  if (hsai->State != HAL_SAI_STATE_RESET)
1705  {
1706  CLEAR_BIT(hsai->Instance->CR2, SAI_xCR2_MUTEVAL | SAI_xCR2_MUTE);
1707  SET_BIT(hsai->Instance->CR2, SAI_xCR2_MUTE | (uint32_t)val);
1708  return HAL_OK;
1709  }
1710  return HAL_ERROR;
1711 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SAI_ErrorCallback()

__weak void HAL_SAI_ErrorCallback ( SAI_HandleTypeDef hsai)

SAI error callback.

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

Definition at line 2107 of file stm32l4xx_hal_sai.c.

2108 {
2109  /* Prevent unused argument(s) compilation warning */
2110  UNUSED(hsai);
2111 
2112  /* NOTE : This function should not be modified, when the callback is needed,
2113  the HAL_SAI_ErrorCallback could be implemented in the user file
2114  */
2115 }

◆ HAL_SAI_IRQHandler()

void HAL_SAI_IRQHandler ( SAI_HandleTypeDef hsai)

Handle SAI interrupt request.

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

Definition at line 1779 of file stm32l4xx_hal_sai.c.

1780 {
1781  if (hsai->State != HAL_SAI_STATE_RESET)
1782  {
1783  uint32_t itflags = hsai->Instance->SR;
1784  uint32_t itsources = hsai->Instance->IMR;
1785  uint32_t cr1config = hsai->Instance->CR1;
1786  uint32_t tmperror;
1787 
1788  /* SAI Fifo request interrupt occurred -----------------------------------*/
1789  if (((itflags & SAI_xSR_FREQ) == SAI_xSR_FREQ) && ((itsources & SAI_IT_FREQ) == SAI_IT_FREQ))
1790  {
1791  hsai->InterruptServiceRoutine(hsai);
1792  }
1793  /* SAI Overrun error interrupt occurred ----------------------------------*/
1794  else if (((itflags & SAI_FLAG_OVRUDR) == SAI_FLAG_OVRUDR) && ((itsources & SAI_IT_OVRUDR) == SAI_IT_OVRUDR))
1795  {
1796  /* Clear the SAI Overrun flag */
1797  __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR);
1798  /* Get the SAI error code */
1799  tmperror = ((hsai->State == HAL_SAI_STATE_BUSY_RX) ? HAL_SAI_ERROR_OVR : HAL_SAI_ERROR_UDR);
1800  /* Change the SAI error code */
1801  hsai->ErrorCode |= tmperror;
1802  /* the transfer is not stopped, we will forward the information to the user and we let the user decide what needs to be done */
1803 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1804  hsai->ErrorCallback(hsai);
1805 #else
1806  HAL_SAI_ErrorCallback(hsai);
1807 #endif
1808  }
1809  /* SAI mutedet interrupt occurred ----------------------------------*/
1810  else if (((itflags & SAI_FLAG_MUTEDET) == SAI_FLAG_MUTEDET) && ((itsources & SAI_IT_MUTEDET) == SAI_IT_MUTEDET))
1811  {
1812  /* Clear the SAI mutedet flag */
1813  __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_MUTEDET);
1814  /* call the call back function */
1815  if (hsai->mutecallback != NULL)
1816  {
1817  /* inform the user that an RX mute event has been detected */
1818  hsai->mutecallback();
1819  }
1820  }
1821  /* SAI AFSDET interrupt occurred ----------------------------------*/
1822  else if (((itflags & SAI_FLAG_AFSDET) == SAI_FLAG_AFSDET) && ((itsources & SAI_IT_AFSDET) == SAI_IT_AFSDET))
1823  {
1824  /* Change the SAI error code */
1825  hsai->ErrorCode |= HAL_SAI_ERROR_AFSDET;
1826 
1827  /* Check SAI DMA is enabled or not */
1828  if ((cr1config & SAI_xCR1_DMAEN) == SAI_xCR1_DMAEN)
1829  {
1830  /* Abort the SAI DMA Streams */
1831  if (hsai->hdmatx != NULL)
1832  {
1833  /* Set the DMA Tx abort callback */
1835 
1836  /* Abort DMA in IT mode */
1837  if (HAL_DMA_Abort_IT(hsai->hdmatx) != HAL_OK)
1838  {
1839  /* Update SAI error code */
1840  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1841 
1842  /* Call SAI error callback */
1843 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1844  hsai->ErrorCallback(hsai);
1845 #else
1846  HAL_SAI_ErrorCallback(hsai);
1847 #endif
1848  }
1849  }
1850  if (hsai->hdmarx != NULL)
1851  {
1852  /* Set the DMA Rx abort callback */
1854 
1855  /* Abort DMA in IT mode */
1856  if (HAL_DMA_Abort_IT(hsai->hdmarx) != HAL_OK)
1857  {
1858  /* Update SAI error code */
1859  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1860 
1861  /* Call SAI error callback */
1862 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1863  hsai->ErrorCallback(hsai);
1864 #else
1865  HAL_SAI_ErrorCallback(hsai);
1866 #endif
1867  }
1868  }
1869  }
1870  else
1871  {
1872  /* Abort SAI */
1873  /* No need to check return value because HAL_SAI_ErrorCallback will be called later */
1874  (void) HAL_SAI_Abort(hsai);
1875 
1876  /* Set error callback */
1877 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1878  hsai->ErrorCallback(hsai);
1879 #else
1880  HAL_SAI_ErrorCallback(hsai);
1881 #endif
1882  }
1883  }
1884  /* SAI LFSDET interrupt occurred ----------------------------------*/
1885  else if (((itflags & SAI_FLAG_LFSDET) == SAI_FLAG_LFSDET) && ((itsources & SAI_IT_LFSDET) == SAI_IT_LFSDET))
1886  {
1887  /* Change the SAI error code */
1888  hsai->ErrorCode |= HAL_SAI_ERROR_LFSDET;
1889 
1890  /* Check SAI DMA is enabled or not */
1891  if ((cr1config & SAI_xCR1_DMAEN) == SAI_xCR1_DMAEN)
1892  {
1893  /* Abort the SAI DMA Streams */
1894  if (hsai->hdmatx != NULL)
1895  {
1896  /* Set the DMA Tx abort callback */
1898 
1899  /* Abort DMA in IT mode */
1900  if (HAL_DMA_Abort_IT(hsai->hdmatx) != HAL_OK)
1901  {
1902  /* Update SAI error code */
1903  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1904 
1905  /* Call SAI error callback */
1906 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1907  hsai->ErrorCallback(hsai);
1908 #else
1909  HAL_SAI_ErrorCallback(hsai);
1910 #endif
1911  }
1912  }
1913  if (hsai->hdmarx != NULL)
1914  {
1915  /* Set the DMA Rx abort callback */
1917 
1918  /* Abort DMA in IT mode */
1919  if (HAL_DMA_Abort_IT(hsai->hdmarx) != HAL_OK)
1920  {
1921  /* Update SAI error code */
1922  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1923 
1924  /* Call SAI error callback */
1925 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1926  hsai->ErrorCallback(hsai);
1927 #else
1928  HAL_SAI_ErrorCallback(hsai);
1929 #endif
1930  }
1931  }
1932  }
1933  else
1934  {
1935  /* Abort SAI */
1936  /* No need to check return value because HAL_SAI_ErrorCallback will be called later */
1937  (void) HAL_SAI_Abort(hsai);
1938 
1939  /* Set error callback */
1940 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1941  hsai->ErrorCallback(hsai);
1942 #else
1943  HAL_SAI_ErrorCallback(hsai);
1944 #endif
1945  }
1946  }
1947  /* SAI WCKCFG interrupt occurred ----------------------------------*/
1948  else if (((itflags & SAI_FLAG_WCKCFG) == SAI_FLAG_WCKCFG) && ((itsources & SAI_IT_WCKCFG) == SAI_IT_WCKCFG))
1949  {
1950  /* Change the SAI error code */
1951  hsai->ErrorCode |= HAL_SAI_ERROR_WCKCFG;
1952 
1953  /* Check SAI DMA is enabled or not */
1954  if ((cr1config & SAI_xCR1_DMAEN) == SAI_xCR1_DMAEN)
1955  {
1956  /* Abort the SAI DMA Streams */
1957  if (hsai->hdmatx != NULL)
1958  {
1959  /* Set the DMA Tx abort callback */
1961 
1962  /* Abort DMA in IT mode */
1963  if (HAL_DMA_Abort_IT(hsai->hdmatx) != HAL_OK)
1964  {
1965  /* Update SAI error code */
1966  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1967 
1968  /* Call SAI error callback */
1969 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1970  hsai->ErrorCallback(hsai);
1971 #else
1972  HAL_SAI_ErrorCallback(hsai);
1973 #endif
1974  }
1975  }
1976  if (hsai->hdmarx != NULL)
1977  {
1978  /* Set the DMA Rx abort callback */
1980 
1981  /* Abort DMA in IT mode */
1982  if (HAL_DMA_Abort_IT(hsai->hdmarx) != HAL_OK)
1983  {
1984  /* Update SAI error code */
1985  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
1986 
1987  /* Call SAI error callback */
1988 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
1989  hsai->ErrorCallback(hsai);
1990 #else
1991  HAL_SAI_ErrorCallback(hsai);
1992 #endif
1993  }
1994  }
1995  }
1996  else
1997  {
1998  /* If WCKCFG occurs, SAI audio block is automatically disabled */
1999  /* Disable all interrupts and clear all flags */
2000  hsai->Instance->IMR = 0U;
2001  hsai->Instance->CLRFR = 0xFFFFFFFFU;
2002  /* Set the SAI state to ready to be able to start again the process */
2003  hsai->State = HAL_SAI_STATE_READY;
2004 
2005  /* Initialize XferCount */
2006  hsai->XferCount = 0U;
2007 
2008  /* SAI error Callback */
2009 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2010  hsai->ErrorCallback(hsai);
2011 #else
2012  HAL_SAI_ErrorCallback(hsai);
2013 #endif
2014  }
2015  }
2016  /* SAI CNRDY interrupt occurred ----------------------------------*/
2017  else if (((itflags & SAI_FLAG_CNRDY) == SAI_FLAG_CNRDY) && ((itsources & SAI_IT_CNRDY) == SAI_IT_CNRDY))
2018  {
2019  /* Clear the SAI CNRDY flag */
2020  __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_CNRDY);
2021  /* Change the SAI error code */
2022  hsai->ErrorCode |= HAL_SAI_ERROR_CNREADY;
2023  /* the transfer is not stopped, we will forward the information to the user and we let the user decide what needs to be done */
2024 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2025  hsai->ErrorCallback(hsai);
2026 #else
2027  HAL_SAI_ErrorCallback(hsai);
2028 #endif
2029  }
2030  else
2031  {
2032  /* Nothing to do */
2033  }
2034  }
2035 }
DMA_HandleTypeDef * hdmarx
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
SAI_Block_TypeDef * Instance
DMA_HandleTypeDef * hdmatx
__IO HAL_SAI_StateTypeDef State
return HAL_OK
void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
SAI error callback.
void(* InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai)
static void SAI_DMAAbort(DMA_HandleTypeDef *hdma)
DMA SAI Abort callback.
HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai)
Abort the current transfer and disable the SAI.
void(* ErrorCallback)(struct __SAI_HandleTypeDef *hsai)

◆ HAL_SAI_Receive()

HAL_StatusTypeDef HAL_SAI_Receive ( SAI_HandleTypeDef hsai,
uint8_t *  pData,
uint16_t  Size,
uint32_t  Timeout 
)

Receive an amount of data in blocking mode.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
pDataPointer to data buffer
SizeAmount of data to be received
TimeoutTimeout duration
Return values
HALstatus

Definition at line 1133 of file stm32l4xx_hal_sai.c.

1134 {
1135  uint32_t tickstart = HAL_GetTick();
1136  uint32_t temp;
1137 
1138  if ((pData == NULL) || (Size == 0U))
1139  {
1140  return HAL_ERROR;
1141  }
1142 
1143  if (hsai->State == HAL_SAI_STATE_READY)
1144  {
1145  /* Process Locked */
1146  __HAL_LOCK(hsai);
1147 
1148  hsai->pBuffPtr = pData;
1149  hsai->XferSize = Size;
1150  hsai->XferCount = Size;
1151  hsai->State = HAL_SAI_STATE_BUSY_RX;
1152  hsai->ErrorCode = HAL_SAI_ERROR_NONE;
1153 
1154  /* Check if the SAI is already enabled */
1155  if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0U)
1156  {
1157  /* Enable SAI peripheral */
1158  __HAL_SAI_ENABLE(hsai);
1159  }
1160 
1161  /* Receive data */
1162  while (hsai->XferCount > 0U)
1163  {
1164  if ((hsai->Instance->SR & SAI_xSR_FLVL) != SAI_FIFOSTATUS_EMPTY)
1165  {
1166  if ((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING))
1167  {
1168  *hsai->pBuffPtr = (uint8_t)hsai->Instance->DR;
1169  hsai->pBuffPtr++;
1170  }
1171  else if (hsai->Init.DataSize <= SAI_DATASIZE_16)
1172  {
1173  temp = hsai->Instance->DR;
1174  *hsai->pBuffPtr = (uint8_t)temp;
1175  hsai->pBuffPtr++;
1176  *hsai->pBuffPtr = (uint8_t)(temp >> 8);
1177  hsai->pBuffPtr++;
1178  }
1179  else
1180  {
1181  temp = hsai->Instance->DR;
1182  *hsai->pBuffPtr = (uint8_t)temp;
1183  hsai->pBuffPtr++;
1184  *hsai->pBuffPtr = (uint8_t)(temp >> 8);
1185  hsai->pBuffPtr++;
1186  *hsai->pBuffPtr = (uint8_t)(temp >> 16);
1187  hsai->pBuffPtr++;
1188  *hsai->pBuffPtr = (uint8_t)(temp >> 24);
1189  hsai->pBuffPtr++;
1190  }
1191  hsai->XferCount--;
1192  }
1193  else
1194  {
1195  /* Check for the Timeout */
1196  if ((((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) && (Timeout != HAL_MAX_DELAY))
1197  {
1198  /* Update error code */
1199  hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT;
1200 
1201  /* Clear all the flags */
1202  hsai->Instance->CLRFR = 0xFFFFFFFFU;
1203 
1204  /* Disable SAI peripheral */
1205  /* No need to check return value because state update, unlock and error return will be performed later */
1206  (void) SAI_Disable(hsai);
1207 
1208  /* Flush the fifo */
1209  SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH);
1210 
1211  /* Change the SAI state */
1212  hsai->State = HAL_SAI_STATE_READY;
1213 
1214  /* Process Unlocked */
1215  __HAL_UNLOCK(hsai);
1216 
1217  return HAL_ERROR;
1218  }
1219  }
1220  }
1221 
1222  hsai->State = HAL_SAI_STATE_READY;
1223 
1224  /* Process Unlocked */
1225  __HAL_UNLOCK(hsai);
1226 
1227  return HAL_OK;
1228  }
1229  else
1230  {
1231  return HAL_BUSY;
1232  }
1233 }
static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai)
Disable the SAI and wait for the disabling.
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
__IO HAL_SAI_StateTypeDef State
return HAL_OK
SAI_InitTypeDef Init

◆ HAL_SAI_Receive_DMA()

HAL_StatusTypeDef HAL_SAI_Receive_DMA ( SAI_HandleTypeDef hsai,
uint8_t *  pData,
uint16_t  Size 
)

Receive an amount of data in non-blocking mode with DMA.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
pDataPointer to data buffer
SizeAmount of data to be received
Return values
HALstatus

Definition at line 1631 of file stm32l4xx_hal_sai.c.

1632 {
1633 
1634  if ((pData == NULL) || (Size == 0U))
1635  {
1636  return HAL_ERROR;
1637  }
1638 
1639  if (hsai->State == HAL_SAI_STATE_READY)
1640  {
1641  /* Process Locked */
1642  __HAL_LOCK(hsai);
1643 
1644  hsai->pBuffPtr = pData;
1645  hsai->XferSize = Size;
1646  hsai->XferCount = Size;
1647  hsai->ErrorCode = HAL_SAI_ERROR_NONE;
1648  hsai->State = HAL_SAI_STATE_BUSY_RX;
1649 
1650  /* Set the SAI Rx DMA Half transfer complete callback */
1652 
1653  /* Set the SAI Rx DMA transfer complete callback */
1655 
1656  /* Set the DMA error callback */
1658 
1659  /* Set the DMA Rx abort callback */
1660  hsai->hdmarx->XferAbortCallback = NULL;
1661 
1662  /* Enable the Rx DMA Stream */
1663  if (HAL_DMA_Start_IT(hsai->hdmarx, (uint32_t)&hsai->Instance->DR, (uint32_t)hsai->pBuffPtr, hsai->XferSize) != HAL_OK)
1664  {
1665  __HAL_UNLOCK(hsai);
1666  return HAL_ERROR;
1667  }
1668 
1669  /* Check if the SAI is already enabled */
1670  if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0U)
1671  {
1672  /* Enable SAI peripheral */
1673  __HAL_SAI_ENABLE(hsai);
1674  }
1675 
1676  /* Enable the interrupts for error handling */
1677  __HAL_SAI_ENABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_DMA));
1678 
1679  /* Enable SAI Rx DMA Request */
1680  hsai->Instance->CR1 |= SAI_xCR1_DMAEN;
1681 
1682  /* Process Unlocked */
1683  __HAL_UNLOCK(hsai);
1684 
1685  return HAL_OK;
1686  }
1687  else
1688  {
1689  return HAL_BUSY;
1690  }
1691 }
DMA_HandleTypeDef * hdmarx
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
static void SAI_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
DMA SAI receive process half complete callback.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__HAL_UNLOCK(hrtc)
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
__IO HAL_SAI_StateTypeDef State
return HAL_OK
static void SAI_DMAError(DMA_HandleTypeDef *hdma)
DMA SAI communication error callback.
static void SAI_DMARxCplt(DMA_HandleTypeDef *hdma)
DMA SAI receive process complete callback.

◆ HAL_SAI_Receive_IT()

HAL_StatusTypeDef HAL_SAI_Receive_IT ( SAI_HandleTypeDef hsai,
uint8_t *  pData,
uint16_t  Size 
)

Receive an amount of data in non-blocking mode with Interrupt.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
pDataPointer to data buffer
SizeAmount of data to be received
Return values
HALstatus

Definition at line 1305 of file stm32l4xx_hal_sai.c.

1306 {
1307  if ((pData == NULL) || (Size == 0U))
1308  {
1309  return HAL_ERROR;
1310  }
1311 
1312  if (hsai->State == HAL_SAI_STATE_READY)
1313  {
1314  /* Process Locked */
1315  __HAL_LOCK(hsai);
1316 
1317  hsai->pBuffPtr = pData;
1318  hsai->XferSize = Size;
1319  hsai->XferCount = Size;
1320  hsai->ErrorCode = HAL_SAI_ERROR_NONE;
1321  hsai->State = HAL_SAI_STATE_BUSY_RX;
1322 
1323  if ((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING))
1324  {
1326  }
1327  else if (hsai->Init.DataSize <= SAI_DATASIZE_16)
1328  {
1330  }
1331  else
1332  {
1334  }
1335 
1336  /* Enable TXE and OVRUDR interrupts */
1337  __HAL_SAI_ENABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT));
1338 
1339  /* Check if the SAI is already enabled */
1340  if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0U)
1341  {
1342  /* Enable SAI peripheral */
1343  __HAL_SAI_ENABLE(hsai);
1344  }
1345 
1346  /* Process Unlocked */
1347  __HAL_UNLOCK(hsai);
1348 
1349  return HAL_OK;
1350  }
1351  else
1352  {
1353  return HAL_BUSY;
1354  }
1355 }
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
__IO HAL_SAI_StateTypeDef State
return HAL_OK
void(* InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai)
SAI_InitTypeDef Init
static void SAI_Receive_IT8Bit(SAI_HandleTypeDef *hsai)
Rx Handler for Receive in Interrupt mode 8-Bit transfer.
static void SAI_Receive_IT32Bit(SAI_HandleTypeDef *hsai)
Rx Handler for Receive in Interrupt mode for 32-Bit transfer.
static void SAI_Receive_IT16Bit(SAI_HandleTypeDef *hsai)
Rx Handler for Receive in Interrupt mode for 16-Bit transfer.

◆ HAL_SAI_RxCpltCallback()

__weak void HAL_SAI_RxCpltCallback ( SAI_HandleTypeDef hsai)

Rx Transfer completed callback.

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

Definition at line 2075 of file stm32l4xx_hal_sai.c.

2076 {
2077  /* Prevent unused argument(s) compilation warning */
2078  UNUSED(hsai);
2079 
2080  /* NOTE : This function should not be modified, when the callback is needed,
2081  the HAL_SAI_RxCpltCallback could be implemented in the user file
2082  */
2083 }

◆ HAL_SAI_RxHalfCpltCallback()

__weak void HAL_SAI_RxHalfCpltCallback ( SAI_HandleTypeDef hsai)

Rx Transfer half completed callback.

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

Definition at line 2091 of file stm32l4xx_hal_sai.c.

2092 {
2093  /* Prevent unused argument(s) compilation warning */
2094  UNUSED(hsai);
2095 
2096  /* NOTE : This function should not be modified, when the callback is needed,
2097  the HAL_SAI_RxHalfCpltCallback could be implemented in the user file
2098  */
2099 }

◆ HAL_SAI_Transmit()

HAL_StatusTypeDef HAL_SAI_Transmit ( SAI_HandleTypeDef hsai,
uint8_t *  pData,
uint16_t  Size,
uint32_t  Timeout 
)

Transmit an amount of data in blocking mode.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
pDataPointer to data buffer
SizeAmount of data to be sent
TimeoutTimeout duration
Return values
HALstatus

Definition at line 1020 of file stm32l4xx_hal_sai.c.

1021 {
1022  uint32_t tickstart = HAL_GetTick();
1023  uint32_t temp;
1024 
1025  if ((pData == NULL) || (Size == 0U))
1026  {
1027  return HAL_ERROR;
1028  }
1029 
1030  if (hsai->State == HAL_SAI_STATE_READY)
1031  {
1032  /* Process Locked */
1033  __HAL_LOCK(hsai);
1034 
1035  hsai->XferSize = Size;
1036  hsai->XferCount = Size;
1037  hsai->pBuffPtr = pData;
1038  hsai->State = HAL_SAI_STATE_BUSY_TX;
1039  hsai->ErrorCode = HAL_SAI_ERROR_NONE;
1040 
1041  /* Check if the SAI is already enabled */
1042  if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0U)
1043  {
1044  /* fill the fifo with data before to enabled the SAI */
1045  SAI_FillFifo(hsai);
1046  /* Enable SAI peripheral */
1047  __HAL_SAI_ENABLE(hsai);
1048  }
1049 
1050  while (hsai->XferCount > 0U)
1051  {
1052  /* Write data if the FIFO is not full */
1053  if ((hsai->Instance->SR & SAI_xSR_FLVL) != SAI_FIFOSTATUS_FULL)
1054  {
1055  if ((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING))
1056  {
1057  hsai->Instance->DR = *hsai->pBuffPtr;
1058  hsai->pBuffPtr++;
1059  }
1060  else if (hsai->Init.DataSize <= SAI_DATASIZE_16)
1061  {
1062  temp = (uint32_t)(*hsai->pBuffPtr);
1063  hsai->pBuffPtr++;
1064  temp |= ((uint32_t)(*hsai->pBuffPtr) << 8);
1065  hsai->pBuffPtr++;
1066  hsai->Instance->DR = temp;
1067  }
1068  else
1069  {
1070  temp = (uint32_t)(*hsai->pBuffPtr);
1071  hsai->pBuffPtr++;
1072  temp |= ((uint32_t)(*hsai->pBuffPtr) << 8);
1073  hsai->pBuffPtr++;
1074  temp |= ((uint32_t)(*hsai->pBuffPtr) << 16);
1075  hsai->pBuffPtr++;
1076  temp |= ((uint32_t)(*hsai->pBuffPtr) << 24);
1077  hsai->pBuffPtr++;
1078  hsai->Instance->DR = temp;
1079  }
1080  hsai->XferCount--;
1081  }
1082  else
1083  {
1084  /* Check for the Timeout */
1085  if ((((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) && (Timeout != HAL_MAX_DELAY))
1086  {
1087  /* Update error code */
1088  hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT;
1089 
1090  /* Clear all the flags */
1091  hsai->Instance->CLRFR = 0xFFFFFFFFU;
1092 
1093  /* Disable SAI peripheral */
1094  /* No need to check return value because state update, unlock and error return will be performed later */
1095  (void) SAI_Disable(hsai);
1096 
1097  /* Flush the fifo */
1098  SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH);
1099 
1100  /* Change the SAI state */
1101  hsai->State = HAL_SAI_STATE_READY;
1102 
1103  /* Process Unlocked */
1104  __HAL_UNLOCK(hsai);
1105 
1106  return HAL_ERROR;
1107  }
1108  }
1109  }
1110 
1111  hsai->State = HAL_SAI_STATE_READY;
1112 
1113  /* Process Unlocked */
1114  __HAL_UNLOCK(hsai);
1115 
1116  return HAL_OK;
1117  }
1118  else
1119  {
1120  return HAL_BUSY;
1121  }
1122 }
static void SAI_FillFifo(SAI_HandleTypeDef *hsai)
Fill the fifo.
static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai)
Disable the SAI and wait for the disabling.
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
__IO HAL_SAI_StateTypeDef State
return HAL_OK
SAI_InitTypeDef Init

◆ HAL_SAI_Transmit_DMA()

HAL_StatusTypeDef HAL_SAI_Transmit_DMA ( SAI_HandleTypeDef hsai,
uint8_t *  pData,
uint16_t  Size 
)

Transmit an amount of data in non-blocking mode with DMA.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
pDataPointer to data buffer
SizeAmount of data to be sent
Return values
HALstatus

Definition at line 1544 of file stm32l4xx_hal_sai.c.

1545 {
1546  uint32_t tickstart = HAL_GetTick();
1547 
1548  if ((pData == NULL) || (Size == 0U))
1549  {
1550  return HAL_ERROR;
1551  }
1552 
1553  if (hsai->State == HAL_SAI_STATE_READY)
1554  {
1555  /* Process Locked */
1556  __HAL_LOCK(hsai);
1557 
1558  hsai->pBuffPtr = pData;
1559  hsai->XferSize = Size;
1560  hsai->XferCount = Size;
1561  hsai->ErrorCode = HAL_SAI_ERROR_NONE;
1562  hsai->State = HAL_SAI_STATE_BUSY_TX;
1563 
1564  /* Set the SAI Tx DMA Half transfer complete callback */
1566 
1567  /* Set the SAI TxDMA transfer complete callback */
1569 
1570  /* Set the DMA error callback */
1572 
1573  /* Set the DMA Tx abort callback */
1574  hsai->hdmatx->XferAbortCallback = NULL;
1575 
1576  /* Enable the Tx DMA Stream */
1577  if (HAL_DMA_Start_IT(hsai->hdmatx, (uint32_t)hsai->pBuffPtr, (uint32_t)&hsai->Instance->DR, hsai->XferSize) != HAL_OK)
1578  {
1579  __HAL_UNLOCK(hsai);
1580  return HAL_ERROR;
1581  }
1582 
1583  /* Enable the interrupts for error handling */
1584  __HAL_SAI_ENABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_DMA));
1585 
1586  /* Enable SAI Tx DMA Request */
1587  hsai->Instance->CR1 |= SAI_xCR1_DMAEN;
1588 
1589  /* Wait untill FIFO is not empty */
1590  while ((hsai->Instance->SR & SAI_xSR_FLVL) == SAI_FIFOSTATUS_EMPTY)
1591  {
1592  /* Check for the Timeout */
1593  if ((HAL_GetTick() - tickstart) > SAI_LONG_TIMEOUT)
1594  {
1595  /* Update error code */
1596  hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT;
1597 
1598  /* Process Unlocked */
1599  __HAL_UNLOCK(hsai);
1600 
1601  return HAL_TIMEOUT;
1602  }
1603  }
1604 
1605  /* Check if the SAI is already enabled */
1606  if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0U)
1607  {
1608  /* Enable SAI peripheral */
1609  __HAL_SAI_ENABLE(hsai);
1610  }
1611 
1612  /* Process Unlocked */
1613  __HAL_UNLOCK(hsai);
1614 
1615  return HAL_OK;
1616  }
1617  else
1618  {
1619  return HAL_BUSY;
1620  }
1621 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
static void SAI_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
DMA SAI transmit process half complete callback.
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__HAL_UNLOCK(hrtc)
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
DMA_HandleTypeDef * hdmatx
__IO HAL_SAI_StateTypeDef State
return HAL_OK
static void SAI_DMAError(DMA_HandleTypeDef *hdma)
DMA SAI communication error callback.
static void SAI_DMATxCplt(DMA_HandleTypeDef *hdma)
DMA SAI transmit process complete callback.

◆ HAL_SAI_Transmit_IT()

HAL_StatusTypeDef HAL_SAI_Transmit_IT ( SAI_HandleTypeDef hsai,
uint8_t *  pData,
uint16_t  Size 
)

Transmit an amount of data in non-blocking mode with Interrupt.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
pDataPointer to data buffer
SizeAmount of data to be sent
Return values
HALstatus

Definition at line 1243 of file stm32l4xx_hal_sai.c.

1244 {
1245  if ((pData == NULL) || (Size == 0U))
1246  {
1247  return HAL_ERROR;
1248  }
1249 
1250  if (hsai->State == HAL_SAI_STATE_READY)
1251  {
1252  /* Process Locked */
1253  __HAL_LOCK(hsai);
1254 
1255  hsai->pBuffPtr = pData;
1256  hsai->XferSize = Size;
1257  hsai->XferCount = Size;
1258  hsai->ErrorCode = HAL_SAI_ERROR_NONE;
1259  hsai->State = HAL_SAI_STATE_BUSY_TX;
1260 
1261  if ((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING))
1262  {
1264  }
1265  else if (hsai->Init.DataSize <= SAI_DATASIZE_16)
1266  {
1268  }
1269  else
1270  {
1272  }
1273 
1274  /* Fill the fifo before starting the communication */
1275  SAI_FillFifo(hsai);
1276 
1277  /* Enable FRQ and OVRUDR interrupts */
1278  __HAL_SAI_ENABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT));
1279 
1280  /* Check if the SAI is already enabled */
1281  if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0U)
1282  {
1283  /* Enable SAI peripheral */
1284  __HAL_SAI_ENABLE(hsai);
1285  }
1286  /* Process Unlocked */
1287  __HAL_UNLOCK(hsai);
1288 
1289  return HAL_OK;
1290  }
1291  else
1292  {
1293  return HAL_BUSY;
1294  }
1295 }
static void SAI_FillFifo(SAI_HandleTypeDef *hsai)
Fill the fifo.
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
__HAL_UNLOCK(hrtc)
static void SAI_Transmit_IT8Bit(SAI_HandleTypeDef *hsai)
Tx Handler for Transmit in Interrupt mode 8-Bit transfer.
SAI_Block_TypeDef * Instance
__HAL_LOCK(hrtc)
__IO HAL_SAI_StateTypeDef State
return HAL_OK
void(* InterruptServiceRoutine)(struct __SAI_HandleTypeDef *hsai)
SAI_InitTypeDef Init
static void SAI_Transmit_IT32Bit(SAI_HandleTypeDef *hsai)
Tx Handler for Transmit in Interrupt mode for 32-Bit transfer.
static void SAI_Transmit_IT16Bit(SAI_HandleTypeDef *hsai)
Tx Handler for Transmit in Interrupt mode for 16-Bit transfer.

◆ HAL_SAI_TxCpltCallback()

__weak void HAL_SAI_TxCpltCallback ( SAI_HandleTypeDef hsai)

Tx Transfer completed callback.

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

Definition at line 2043 of file stm32l4xx_hal_sai.c.

2044 {
2045  /* Prevent unused argument(s) compilation warning */
2046  UNUSED(hsai);
2047 
2048  /* NOTE : This function should not be modified, when the callback is needed,
2049  the HAL_SAI_TxCpltCallback could be implemented in the user file
2050  */
2051 }

◆ HAL_SAI_TxHalfCpltCallback()

__weak void HAL_SAI_TxHalfCpltCallback ( SAI_HandleTypeDef hsai)

Tx Transfer Half completed callback.

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

Definition at line 2059 of file stm32l4xx_hal_sai.c.

2060 {
2061  /* Prevent unused argument(s) compilation warning */
2062  UNUSED(hsai);
2063 
2064  /* NOTE : This function should not be modified, when the callback is needed,
2065  the HAL_SAI_TxHalfCpltCallback could be implemented in the user file
2066  */
2067 }