STM32L4xx_HAL_Driver  1.14.0

Data transfers Private functions. More...

Functions

static HAL_StatusTypeDef SMBUS_WaitOnFlagUntilTimeout (struct __SMBUS_HandleTypeDef *hsmbus, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
 Handle SMBUS Communication Timeout. More...
 
static void SMBUS_Enable_IRQ (struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
 Manage the enabling of Interrupts. More...
 
static void SMBUS_Disable_IRQ (struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
 Manage the disabling of Interrupts. More...
 
static HAL_StatusTypeDef SMBUS_Master_ISR (struct __SMBUS_HandleTypeDef *hsmbus, uint32_t StatusFlags)
 Interrupt Sub-Routine which handle the Interrupt Flags Master Mode. More...
 
static HAL_StatusTypeDef SMBUS_Slave_ISR (struct __SMBUS_HandleTypeDef *hsmbus, uint32_t StatusFlags)
 Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode. More...
 
static void SMBUS_ConvertOtherXferOptions (struct __SMBUS_HandleTypeDef *hsmbus)
 Convert SMBUSx OTHER_xxx XferOptions to functionnal XferOptions. More...
 
static void SMBUS_ITErrorHandler (struct __SMBUS_HandleTypeDef *hsmbus)
 SMBUS interrupts error handler. More...
 
static void SMBUS_TransferConfig (struct __SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
 Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set). More...
 

Detailed Description

Data transfers Private functions.

Function Documentation

◆ SMBUS_ConvertOtherXferOptions()

static void SMBUS_ConvertOtherXferOptions ( struct __SMBUS_HandleTypeDef hsmbus)
static

Convert SMBUSx OTHER_xxx XferOptions to functionnal XferOptions.

Parameters
hsmbusSMBUS handle.
Return values
None

Definition at line 2623 of file stm32l4xx_hal_smbus.c.

2624 {
2625  /* if user set XferOptions to SMBUS_OTHER_FRAME_NO_PEC */
2626  /* it request implicitly to generate a restart condition */
2627  /* set XferOptions to SMBUS_FIRST_FRAME */
2628  if (hsmbus->XferOptions == SMBUS_OTHER_FRAME_NO_PEC)
2629  {
2630  hsmbus->XferOptions = SMBUS_FIRST_FRAME;
2631  }
2632  /* else if user set XferOptions to SMBUS_OTHER_FRAME_WITH_PEC */
2633  /* it request implicitly to generate a restart condition */
2634  /* set XferOptions to SMBUS_FIRST_FRAME | SMBUS_SENDPEC_MODE */
2635  else if (hsmbus->XferOptions == SMBUS_OTHER_FRAME_WITH_PEC)
2636  {
2637  hsmbus->XferOptions = SMBUS_FIRST_FRAME | SMBUS_SENDPEC_MODE;
2638  }
2639  /* else if user set XferOptions to SMBUS_OTHER_AND_LAST_FRAME_NO_PEC */
2640  /* it request implicitly to generate a restart condition */
2641  /* then generate a stop condition at the end of transfer */
2642  /* set XferOptions to SMBUS_FIRST_AND_LAST_FRAME_NO_PEC */
2643  else if (hsmbus->XferOptions == SMBUS_OTHER_AND_LAST_FRAME_NO_PEC)
2644  {
2645  hsmbus->XferOptions = SMBUS_FIRST_AND_LAST_FRAME_NO_PEC;
2646  }
2647  /* else if user set XferOptions to SMBUS_OTHER_AND_LAST_FRAME_WITH_PEC */
2648  /* it request implicitly to generate a restart condition */
2649  /* then generate a stop condition at the end of transfer */
2650  /* set XferOptions to SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC */
2651  else if (hsmbus->XferOptions == SMBUS_OTHER_AND_LAST_FRAME_WITH_PEC)
2652  {
2653  hsmbus->XferOptions = SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC;
2654  }
2655  else
2656  {
2657  /* Nothing to do */
2658  }
2659 }

◆ SMBUS_Disable_IRQ()

static void SMBUS_Disable_IRQ ( struct __SMBUS_HandleTypeDef hsmbus,
uint32_t  InterruptRequest 
)
static

Manage the disabling of Interrupts.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
InterruptRequestValue of SMBUS Interrupt configuration definition.
Return values
HALstatus

Definition at line 2384 of file stm32l4xx_hal_smbus.c.

2385 {
2386  uint32_t tmpisr = 0UL;
2387  uint32_t tmpstate = hsmbus->State;
2388 
2389  if ((tmpstate == HAL_SMBUS_STATE_READY) && ((InterruptRequest & SMBUS_IT_ALERT) == SMBUS_IT_ALERT))
2390  {
2391  /* Disable ERR interrupt */
2392  tmpisr |= SMBUS_IT_ERRI;
2393  }
2394 
2395  if ((InterruptRequest & SMBUS_IT_TX) == SMBUS_IT_TX)
2396  {
2397  /* Disable TC, STOP, NACK and TXI interrupt */
2398  tmpisr |= SMBUS_IT_TCI | SMBUS_IT_TXI;
2399 
2400  if ((SMBUS_GET_ALERT_ENABLED(hsmbus) == 0UL)
2401  && ((tmpstate & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN))
2402  {
2403  /* Disable ERR interrupt */
2404  tmpisr |= SMBUS_IT_ERRI;
2405  }
2406 
2407  if ((tmpstate & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN)
2408  {
2409  /* Disable STOP and NACK interrupt */
2410  tmpisr |= SMBUS_IT_STOPI | SMBUS_IT_NACKI;
2411  }
2412  }
2413 
2414  if ((InterruptRequest & SMBUS_IT_RX) == SMBUS_IT_RX)
2415  {
2416  /* Disable TC, STOP, NACK and RXI interrupt */
2417  tmpisr |= SMBUS_IT_TCI | SMBUS_IT_RXI;
2418 
2419  if ((SMBUS_GET_ALERT_ENABLED(hsmbus) == 0UL)
2420  && ((tmpstate & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN))
2421  {
2422  /* Disable ERR interrupt */
2423  tmpisr |= SMBUS_IT_ERRI;
2424  }
2425 
2426  if ((tmpstate & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN)
2427  {
2428  /* Disable STOP and NACK interrupt */
2429  tmpisr |= SMBUS_IT_STOPI | SMBUS_IT_NACKI;
2430  }
2431  }
2432 
2433  if ((InterruptRequest & SMBUS_IT_ADDR) == SMBUS_IT_ADDR)
2434  {
2435  /* Disable ADDR, STOP and NACK interrupt */
2436  tmpisr |= SMBUS_IT_ADDRI | SMBUS_IT_STOPI | SMBUS_IT_NACKI;
2437 
2438  if (SMBUS_GET_ALERT_ENABLED(hsmbus) == 0UL)
2439  {
2440  /* Disable ERR interrupt */
2441  tmpisr |= SMBUS_IT_ERRI;
2442  }
2443  }
2444 
2445  /* Disable interrupts only at the end */
2446  /* to avoid a breaking situation like at "t" time */
2447  /* all disable interrupts request are not done */
2448  __HAL_SMBUS_DISABLE_IT(hsmbus, tmpisr);
2449 }

◆ SMBUS_Enable_IRQ()

static void SMBUS_Enable_IRQ ( struct __SMBUS_HandleTypeDef hsmbus,
uint32_t  InterruptRequest 
)
static

Manage the enabling of Interrupts.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
InterruptRequestValue of SMBUS Interrupt configuration definition.
Return values
HALstatus

Definition at line 2344 of file stm32l4xx_hal_smbus.c.

2345 {
2346  uint32_t tmpisr = 0UL;
2347 
2348  if ((InterruptRequest & SMBUS_IT_ALERT) == SMBUS_IT_ALERT)
2349  {
2350  /* Enable ERR interrupt */
2351  tmpisr |= SMBUS_IT_ERRI;
2352  }
2353 
2354  if ((InterruptRequest & SMBUS_IT_ADDR) == SMBUS_IT_ADDR)
2355  {
2356  /* Enable ADDR, STOP interrupt */
2357  tmpisr |= SMBUS_IT_ADDRI | SMBUS_IT_STOPI | SMBUS_IT_NACKI | SMBUS_IT_ERRI;
2358  }
2359 
2360  if ((InterruptRequest & SMBUS_IT_TX) == SMBUS_IT_TX)
2361  {
2362  /* Enable ERR, TC, STOP, NACK, RXI interrupt */
2363  tmpisr |= SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_STOPI | SMBUS_IT_NACKI | SMBUS_IT_TXI;
2364  }
2365 
2366  if ((InterruptRequest & SMBUS_IT_RX) == SMBUS_IT_RX)
2367  {
2368  /* Enable ERR, TC, STOP, NACK, TXI interrupt */
2369  tmpisr |= SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_STOPI | SMBUS_IT_NACKI | SMBUS_IT_RXI;
2370  }
2371 
2372  /* Enable interrupts only at the end */
2373  /* to avoid the risk of SMBUS interrupt handle execution before */
2374  /* all interrupts requested done */
2375  __HAL_SMBUS_ENABLE_IT(hsmbus, tmpisr);
2376 }

◆ SMBUS_ITErrorHandler()

static void SMBUS_ITErrorHandler ( struct __SMBUS_HandleTypeDef hsmbus)
static

SMBUS interrupts error handler.

Parameters
hsmbusSMBUS handle.
Return values
None

Definition at line 2456 of file stm32l4xx_hal_smbus.c.

2457 {
2458  uint32_t itflags = READ_REG(hsmbus->Instance->ISR);
2459  uint32_t itsources = READ_REG(hsmbus->Instance->CR1);
2460  uint32_t tmpstate;
2461  uint32_t tmperror;
2462 
2463  /* SMBUS Bus error interrupt occurred ------------------------------------*/
2464  if (((itflags & SMBUS_FLAG_BERR) == SMBUS_FLAG_BERR) && ((itsources & SMBUS_IT_ERRI) == SMBUS_IT_ERRI))
2465  {
2466  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_BERR;
2467 
2468  /* Clear BERR flag */
2469  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_BERR);
2470  }
2471 
2472  /* SMBUS Over-Run/Under-Run interrupt occurred ----------------------------------------*/
2473  if (((itflags & SMBUS_FLAG_OVR) == SMBUS_FLAG_OVR) && ((itsources & SMBUS_IT_ERRI) == SMBUS_IT_ERRI))
2474  {
2475  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_OVR;
2476 
2477  /* Clear OVR flag */
2478  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_OVR);
2479  }
2480 
2481  /* SMBUS Arbitration Loss error interrupt occurred ------------------------------------*/
2482  if (((itflags & SMBUS_FLAG_ARLO) == SMBUS_FLAG_ARLO) && ((itsources & SMBUS_IT_ERRI) == SMBUS_IT_ERRI))
2483  {
2484  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_ARLO;
2485 
2486  /* Clear ARLO flag */
2487  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ARLO);
2488  }
2489 
2490  /* SMBUS Timeout error interrupt occurred ---------------------------------------------*/
2491  if (((itflags & SMBUS_FLAG_TIMEOUT) == SMBUS_FLAG_TIMEOUT) && ((itsources & SMBUS_IT_ERRI) == SMBUS_IT_ERRI))
2492  {
2493  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_BUSTIMEOUT;
2494 
2495  /* Clear TIMEOUT flag */
2496  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_TIMEOUT);
2497  }
2498 
2499  /* SMBUS Alert error interrupt occurred -----------------------------------------------*/
2500  if (((itflags & SMBUS_FLAG_ALERT) == SMBUS_FLAG_ALERT) && ((itsources & SMBUS_IT_ERRI) == SMBUS_IT_ERRI))
2501  {
2502  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_ALERT;
2503 
2504  /* Clear ALERT flag */
2505  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ALERT);
2506  }
2507 
2508  /* SMBUS Packet Error Check error interrupt occurred ----------------------------------*/
2509  if (((itflags & SMBUS_FLAG_PECERR) == SMBUS_FLAG_PECERR) && ((itsources & SMBUS_IT_ERRI) == SMBUS_IT_ERRI))
2510  {
2511  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_PECERR;
2512 
2513  /* Clear PEC error flag */
2514  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_PECERR);
2515  }
2516 
2517  /* Store current volatile hsmbus->State, misra rule */
2518  tmperror = hsmbus->ErrorCode;
2519 
2520  /* Call the Error Callback in case of Error detected */
2521  if ((tmperror != HAL_SMBUS_ERROR_NONE) && (tmperror != HAL_SMBUS_ERROR_ACKF))
2522  {
2523  /* Do not Reset the HAL state in case of ALERT error */
2524  if ((tmperror & HAL_SMBUS_ERROR_ALERT) != HAL_SMBUS_ERROR_ALERT)
2525  {
2526  /* Store current volatile hsmbus->State, misra rule */
2527  tmpstate = hsmbus->State;
2528 
2529  if (((tmpstate & HAL_SMBUS_STATE_SLAVE_BUSY_TX) == HAL_SMBUS_STATE_SLAVE_BUSY_TX)
2530  || ((tmpstate & HAL_SMBUS_STATE_SLAVE_BUSY_RX) == HAL_SMBUS_STATE_SLAVE_BUSY_RX))
2531  {
2532  /* Reset only HAL_SMBUS_STATE_SLAVE_BUSY_XX */
2533  /* keep HAL_SMBUS_STATE_LISTEN if set */
2534  hsmbus->PreviousState = HAL_SMBUS_STATE_READY;
2535  hsmbus->State = HAL_SMBUS_STATE_LISTEN;
2536  }
2537  }
2538 
2539  /* Call the Error callback to inform upper layer */
2540 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
2541  hsmbus->ErrorCallback(hsmbus);
2542 #else
2543  HAL_SMBUS_ErrorCallback(hsmbus);
2544 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
2545  }
2546 }
void(* ErrorCallback)(struct __SMBUS_HandleTypeDef *hsmbus)
void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *hsmbus)
SMBUS error callback.

◆ SMBUS_Master_ISR()

static HAL_StatusTypeDef SMBUS_Master_ISR ( struct __SMBUS_HandleTypeDef hsmbus,
uint32_t  StatusFlags 
)
static

Interrupt Sub-Routine which handle the Interrupt Flags Master Mode.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
StatusFlagsValue of Interrupt Flags.
Return values
HALstatus

Definition at line 1804 of file stm32l4xx_hal_smbus.c.

1805 {
1806  uint16_t DevAddress;
1807 
1808  /* Process Locked */
1809  __HAL_LOCK(hsmbus);
1810 
1811  if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_AF) != RESET)
1812  {
1813  /* Clear NACK Flag */
1814  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_AF);
1815 
1816  /* Set corresponding Error Code */
1817  /* No need to generate STOP, it is automatically done */
1818  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_ACKF;
1819 
1820  /* Process Unlocked */
1821  __HAL_UNLOCK(hsmbus);
1822 
1823  /* Call the Error callback to inform upper layer */
1824 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
1825  hsmbus->ErrorCallback(hsmbus);
1826 #else
1827  HAL_SMBUS_ErrorCallback(hsmbus);
1828 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
1829  }
1830  else if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_STOPF) != RESET)
1831  {
1832  /* Check and treat errors if errors occurs during STOP process */
1833  SMBUS_ITErrorHandler(hsmbus);
1834 
1835  /* Call the corresponding callback to inform upper layer of End of Transfer */
1836  if (hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX)
1837  {
1838  /* Disable Interrupt */
1839  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_TX);
1840 
1841  /* Clear STOP Flag */
1842  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF);
1843 
1844  /* Clear Configuration Register 2 */
1845  SMBUS_RESET_CR2(hsmbus);
1846 
1847  /* Flush remaining data in Fifo register in case of error occurs before TXEmpty */
1848  /* Disable the selected SMBUS peripheral */
1849  __HAL_SMBUS_DISABLE(hsmbus);
1850 
1851  hsmbus->PreviousState = HAL_SMBUS_STATE_READY;
1852  hsmbus->State = HAL_SMBUS_STATE_READY;
1853 
1854  /* Process Unlocked */
1855  __HAL_UNLOCK(hsmbus);
1856 
1857  /* REenable the selected SMBUS peripheral */
1858  __HAL_SMBUS_ENABLE(hsmbus);
1859 
1860  /* Call the corresponding callback to inform upper layer of End of Transfer */
1861 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
1862  hsmbus->MasterTxCpltCallback(hsmbus);
1863 #else
1865 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
1866  }
1867  else if (hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_RX)
1868  {
1869  /* Store Last receive data if any */
1870  if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_RXNE) != RESET)
1871  {
1872  /* Read data from RXDR */
1873  *hsmbus->pBuffPtr = (uint8_t)(hsmbus->Instance->RXDR);
1874 
1875  /* Increment Buffer pointer */
1876  hsmbus->pBuffPtr++;
1877 
1878  if ((hsmbus->XferSize > 0U))
1879  {
1880  hsmbus->XferSize--;
1881  hsmbus->XferCount--;
1882  }
1883  }
1884 
1885  /* Disable Interrupt */
1886  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX);
1887 
1888  /* Clear STOP Flag */
1889  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF);
1890 
1891  /* Clear Configuration Register 2 */
1892  SMBUS_RESET_CR2(hsmbus);
1893 
1894  hsmbus->PreviousState = HAL_SMBUS_STATE_READY;
1895  hsmbus->State = HAL_SMBUS_STATE_READY;
1896 
1897  /* Process Unlocked */
1898  __HAL_UNLOCK(hsmbus);
1899 
1900  /* Call the corresponding callback to inform upper layer of End of Transfer */
1901 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
1902  hsmbus->MasterRxCpltCallback(hsmbus);
1903 #else
1905 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
1906  }
1907  else
1908  {
1909  /* Nothing to do */
1910  }
1911  }
1912  else if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_RXNE) != RESET)
1913  {
1914  /* Read data from RXDR */
1915  *hsmbus->pBuffPtr = (uint8_t)(hsmbus->Instance->RXDR);
1916 
1917  /* Increment Buffer pointer */
1918  hsmbus->pBuffPtr++;
1919 
1920  /* Increment Size counter */
1921  hsmbus->XferSize--;
1922  hsmbus->XferCount--;
1923  }
1924  else if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_TXIS) != RESET)
1925  {
1926  /* Write data to TXDR */
1927  hsmbus->Instance->TXDR = *hsmbus->pBuffPtr;
1928 
1929  /* Increment Buffer pointer */
1930  hsmbus->pBuffPtr++;
1931 
1932  /* Increment Size counter */
1933  hsmbus->XferSize--;
1934  hsmbus->XferCount--;
1935  }
1936  else if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_TCR) != RESET)
1937  {
1938  if ((hsmbus->XferCount != 0U) && (hsmbus->XferSize == 0U))
1939  {
1940  DevAddress = (uint16_t)(hsmbus->Instance->CR2 & I2C_CR2_SADD);
1941 
1942  if (hsmbus->XferCount > MAX_NBYTE_SIZE)
1943  {
1944  SMBUS_TransferConfig(hsmbus, DevAddress, MAX_NBYTE_SIZE, (SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE)), SMBUS_NO_STARTSTOP);
1945  hsmbus->XferSize = MAX_NBYTE_SIZE;
1946  }
1947  else
1948  {
1949  hsmbus->XferSize = hsmbus->XferCount;
1950  SMBUS_TransferConfig(hsmbus, DevAddress, (uint8_t)hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP);
1951  /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */
1952  /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */
1953  if (SMBUS_GET_PEC_MODE(hsmbus) != 0UL)
1954  {
1955  hsmbus->XferSize--;
1956  hsmbus->XferCount--;
1957  }
1958  }
1959  }
1960  else if ((hsmbus->XferCount == 0U) && (hsmbus->XferSize == 0U))
1961  {
1962  /* Call TxCpltCallback() if no stop mode is set */
1963  if (SMBUS_GET_STOP_MODE(hsmbus) != SMBUS_AUTOEND_MODE)
1964  {
1965  /* Call the corresponding callback to inform upper layer of End of Transfer */
1966  if (hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX)
1967  {
1968  /* Disable Interrupt */
1969  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_TX);
1970  hsmbus->PreviousState = hsmbus->State;
1971  hsmbus->State = HAL_SMBUS_STATE_READY;
1972 
1973  /* Process Unlocked */
1974  __HAL_UNLOCK(hsmbus);
1975 
1976  /* Call the corresponding callback to inform upper layer of End of Transfer */
1977 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
1978  hsmbus->MasterTxCpltCallback(hsmbus);
1979 #else
1981 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
1982  }
1983  else if (hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_RX)
1984  {
1985  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX);
1986  hsmbus->PreviousState = hsmbus->State;
1987  hsmbus->State = HAL_SMBUS_STATE_READY;
1988 
1989  /* Process Unlocked */
1990  __HAL_UNLOCK(hsmbus);
1991 
1992  /* Call the corresponding callback to inform upper layer of End of Transfer */
1993 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
1994  hsmbus->MasterRxCpltCallback(hsmbus);
1995 #else
1997 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
1998  }
1999  else
2000  {
2001  /* Nothing to do */
2002  }
2003  }
2004  }
2005  else
2006  {
2007  /* Nothing to do */
2008  }
2009  }
2010  else if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_TC) != RESET)
2011  {
2012  if (hsmbus->XferCount == 0U)
2013  {
2014  /* Specific use case for Quick command */
2015  if (hsmbus->pBuffPtr == NULL)
2016  {
2017  /* Generate a Stop command */
2018  hsmbus->Instance->CR2 |= I2C_CR2_STOP;
2019  }
2020  /* Call TxCpltCallback() if no stop mode is set */
2021  else if (SMBUS_GET_STOP_MODE(hsmbus) != SMBUS_AUTOEND_MODE)
2022  {
2023  /* No Generate Stop, to permit restart mode */
2024  /* The stop will be done at the end of transfer, when SMBUS_AUTOEND_MODE enable */
2025 
2026  /* Call the corresponding callback to inform upper layer of End of Transfer */
2027  if (hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX)
2028  {
2029  /* Disable Interrupt */
2030  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_TX);
2031  hsmbus->PreviousState = hsmbus->State;
2032  hsmbus->State = HAL_SMBUS_STATE_READY;
2033 
2034  /* Process Unlocked */
2035  __HAL_UNLOCK(hsmbus);
2036 
2037  /* Call the corresponding callback to inform upper layer of End of Transfer */
2038 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
2039  hsmbus->MasterTxCpltCallback(hsmbus);
2040 #else
2042 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
2043  }
2044  else if (hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_RX)
2045  {
2046  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX);
2047  hsmbus->PreviousState = hsmbus->State;
2048  hsmbus->State = HAL_SMBUS_STATE_READY;
2049 
2050  /* Process Unlocked */
2051  __HAL_UNLOCK(hsmbus);
2052 
2053  /* Call the corresponding callback to inform upper layer of End of Transfer */
2054 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
2055  hsmbus->MasterRxCpltCallback(hsmbus);
2056 #else
2058 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
2059  }
2060  else
2061  {
2062  /* Nothing to do */
2063  }
2064  }
2065  else
2066  {
2067  /* Nothing to do */
2068  }
2069  }
2070  }
2071  else
2072  {
2073  /* Nothing to do */
2074  }
2075 
2076  /* Process Unlocked */
2077  __HAL_UNLOCK(hsmbus);
2078 
2079  return HAL_OK;
2080 }
static void SMBUS_ITErrorHandler(struct __SMBUS_HandleTypeDef *hsmbus)
SMBUS interrupts error handler.
static void SMBUS_TransferConfig(struct __SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set)...
void HAL_SMBUS_MasterTxCpltCallback(SMBUS_HandleTypeDef *hsmbus)
Master Tx Transfer completed callback.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
void HAL_SMBUS_MasterRxCpltCallback(SMBUS_HandleTypeDef *hsmbus)
Master Rx Transfer completed callback.
return HAL_OK
void(* ErrorCallback)(struct __SMBUS_HandleTypeDef *hsmbus)
void(* MasterTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus)
static void SMBUS_Disable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the disabling of Interrupts.
void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *hsmbus)
SMBUS error callback.
void(* MasterRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus)

◆ SMBUS_Slave_ISR()

static HAL_StatusTypeDef SMBUS_Slave_ISR ( struct __SMBUS_HandleTypeDef hsmbus,
uint32_t  StatusFlags 
)
static

Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
StatusFlagsValue of Interrupt Flags.
Return values
HALstatus

Definition at line 2088 of file stm32l4xx_hal_smbus.c.

2089 {
2090  uint8_t TransferDirection;
2091  uint16_t SlaveAddrCode;
2092 
2093  /* Process Locked */
2094  __HAL_LOCK(hsmbus);
2095 
2096  if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_AF) != RESET)
2097  {
2098  /* Check that SMBUS transfer finished */
2099  /* if yes, normal usecase, a NACK is sent by the HOST when Transfer is finished */
2100  /* Mean XferCount == 0*/
2101  /* So clear Flag NACKF only */
2102  if (hsmbus->XferCount == 0U)
2103  {
2104  /* Clear NACK Flag */
2105  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_AF);
2106 
2107  /* Process Unlocked */
2108  __HAL_UNLOCK(hsmbus);
2109  }
2110  else
2111  {
2112  /* if no, error usecase, a Non-Acknowledge of last Data is generated by the HOST*/
2113  /* Clear NACK Flag */
2114  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_AF);
2115 
2116  /* Set HAL State to "Idle" State, mean to LISTEN state */
2117  /* So reset Slave Busy state */
2118  hsmbus->PreviousState = hsmbus->State;
2119  hsmbus->State &= ~((uint32_t)HAL_SMBUS_STATE_SLAVE_BUSY_TX);
2120  hsmbus->State &= ~((uint32_t)HAL_SMBUS_STATE_SLAVE_BUSY_RX);
2121 
2122  /* Disable RX/TX Interrupts, keep only ADDR Interrupt */
2123  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX | SMBUS_IT_TX);
2124 
2125  /* Set ErrorCode corresponding to a Non-Acknowledge */
2126  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_ACKF;
2127 
2128  /* Process Unlocked */
2129  __HAL_UNLOCK(hsmbus);
2130 
2131  /* Call the Error callback to inform upper layer */
2132 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
2133  hsmbus->ErrorCallback(hsmbus);
2134 #else
2135  HAL_SMBUS_ErrorCallback(hsmbus);
2136 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
2137  }
2138  }
2139  else if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_ADDR) != RESET)
2140  {
2141  TransferDirection = (uint8_t)(SMBUS_GET_DIR(hsmbus));
2142  SlaveAddrCode = (uint16_t)(SMBUS_GET_ADDR_MATCH(hsmbus));
2143 
2144  /* Disable ADDR interrupt to prevent multiple ADDRInterrupt*/
2145  /* Other ADDRInterrupt will be treat in next Listen usecase */
2146  __HAL_SMBUS_DISABLE_IT(hsmbus, SMBUS_IT_ADDRI);
2147 
2148  /* Process Unlocked */
2149  __HAL_UNLOCK(hsmbus);
2150 
2151  /* Call Slave Addr callback */
2152 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
2153  hsmbus->AddrCallback(hsmbus, TransferDirection, SlaveAddrCode);
2154 #else
2155  HAL_SMBUS_AddrCallback(hsmbus, TransferDirection, SlaveAddrCode);
2156 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
2157  }
2158  else if ((SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_RXNE) != RESET) || (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_TCR) != RESET))
2159  {
2160  if ((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_RX) == HAL_SMBUS_STATE_SLAVE_BUSY_RX)
2161  {
2162  /* Read data from RXDR */
2163  *hsmbus->pBuffPtr = (uint8_t)(hsmbus->Instance->RXDR);
2164 
2165  /* Increment Buffer pointer */
2166  hsmbus->pBuffPtr++;
2167 
2168  hsmbus->XferSize--;
2169  hsmbus->XferCount--;
2170 
2171  if (hsmbus->XferCount == 1U)
2172  {
2173  /* Receive last Byte, can be PEC byte in case of PEC BYTE enabled */
2174  /* or only the last Byte of Transfer */
2175  /* So reset the RELOAD bit mode */
2176  hsmbus->XferOptions &= ~SMBUS_RELOAD_MODE;
2177  SMBUS_TransferConfig(hsmbus, 0, 1, hsmbus->XferOptions, SMBUS_NO_STARTSTOP);
2178  }
2179  else if (hsmbus->XferCount == 0U)
2180  {
2181  /* Last Byte is received, disable Interrupt */
2182  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX);
2183 
2184  /* Remove HAL_SMBUS_STATE_SLAVE_BUSY_RX, keep only HAL_SMBUS_STATE_LISTEN */
2185  hsmbus->PreviousState = hsmbus->State;
2186  hsmbus->State &= ~((uint32_t)HAL_SMBUS_STATE_SLAVE_BUSY_RX);
2187 
2188  /* Process Unlocked */
2189  __HAL_UNLOCK(hsmbus);
2190 
2191  /* Call the corresponding callback to inform upper layer of End of Transfer */
2192 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
2193  hsmbus->SlaveRxCpltCallback(hsmbus);
2194 #else
2196 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
2197  }
2198  else
2199  {
2200  /* Set Reload for next Bytes */
2201  SMBUS_TransferConfig(hsmbus, 0, 1, SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE), SMBUS_NO_STARTSTOP);
2202 
2203  /* Ack last Byte Read */
2204  hsmbus->Instance->CR2 &= ~I2C_CR2_NACK;
2205  }
2206  }
2207  else if ((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_TX) == HAL_SMBUS_STATE_SLAVE_BUSY_TX)
2208  {
2209  if ((hsmbus->XferCount != 0U) && (hsmbus->XferSize == 0U))
2210  {
2211  if (hsmbus->XferCount > MAX_NBYTE_SIZE)
2212  {
2213  SMBUS_TransferConfig(hsmbus, 0, MAX_NBYTE_SIZE, (SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE)), SMBUS_NO_STARTSTOP);
2214  hsmbus->XferSize = MAX_NBYTE_SIZE;
2215  }
2216  else
2217  {
2218  hsmbus->XferSize = hsmbus->XferCount;
2219  SMBUS_TransferConfig(hsmbus, 0, (uint8_t)hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP);
2220  /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */
2221  /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */
2222  if (SMBUS_GET_PEC_MODE(hsmbus) != 0UL)
2223  {
2224  hsmbus->XferSize--;
2225  hsmbus->XferCount--;
2226  }
2227  }
2228  }
2229  }
2230  else
2231  {
2232  /* Nothing to do */
2233  }
2234  }
2235  else if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_TXIS) != RESET)
2236  {
2237  /* Write data to TXDR only if XferCount not reach "0" */
2238  /* A TXIS flag can be set, during STOP treatment */
2239  /* Check if all Data have already been sent */
2240  /* If it is the case, this last write in TXDR is not sent, correspond to a dummy TXIS event */
2241  if (hsmbus->XferCount > 0U)
2242  {
2243  /* Write data to TXDR */
2244  hsmbus->Instance->TXDR = *hsmbus->pBuffPtr;
2245 
2246  /* Increment Buffer pointer */
2247  hsmbus->pBuffPtr++;
2248 
2249  hsmbus->XferCount--;
2250  hsmbus->XferSize--;
2251  }
2252 
2253  if (hsmbus->XferCount == 0U)
2254  {
2255  /* Last Byte is Transmitted */
2256  /* Remove HAL_SMBUS_STATE_SLAVE_BUSY_TX, keep only HAL_SMBUS_STATE_LISTEN */
2257  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_TX);
2258  hsmbus->PreviousState = hsmbus->State;
2259  hsmbus->State &= ~((uint32_t)HAL_SMBUS_STATE_SLAVE_BUSY_TX);
2260 
2261  /* Process Unlocked */
2262  __HAL_UNLOCK(hsmbus);
2263 
2264  /* Call the corresponding callback to inform upper layer of End of Transfer */
2265 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
2266  hsmbus->SlaveTxCpltCallback(hsmbus);
2267 #else
2269 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
2270  }
2271  }
2272  else
2273  {
2274  /* Nothing to do */
2275  }
2276 
2277  /* Check if STOPF is set */
2278  if (SMBUS_CHECK_FLAG(StatusFlags, SMBUS_FLAG_STOPF) != RESET)
2279  {
2280  if ((hsmbus->State & HAL_SMBUS_STATE_LISTEN) == HAL_SMBUS_STATE_LISTEN)
2281  {
2282  /* Store Last receive data if any */
2283  if (__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_RXNE) != RESET)
2284  {
2285  /* Read data from RXDR */
2286  *hsmbus->pBuffPtr = (uint8_t)(hsmbus->Instance->RXDR);
2287 
2288  /* Increment Buffer pointer */
2289  hsmbus->pBuffPtr++;
2290 
2291  if ((hsmbus->XferSize > 0U))
2292  {
2293  hsmbus->XferSize--;
2294  hsmbus->XferCount--;
2295  }
2296  }
2297 
2298  /* Disable RX and TX Interrupts */
2299  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX | SMBUS_IT_TX);
2300 
2301  /* Disable ADDR Interrupt */
2302  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ADDR);
2303 
2304  /* Disable Address Acknowledge */
2305  hsmbus->Instance->CR2 |= I2C_CR2_NACK;
2306 
2307  /* Clear Configuration Register 2 */
2308  SMBUS_RESET_CR2(hsmbus);
2309 
2310  /* Clear STOP Flag */
2311  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF);
2312 
2313  /* Clear ADDR flag */
2314  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ADDR);
2315 
2316  hsmbus->XferOptions = 0;
2317  hsmbus->PreviousState = hsmbus->State;
2318  hsmbus->State = HAL_SMBUS_STATE_READY;
2319 
2320  /* Process Unlocked */
2321  __HAL_UNLOCK(hsmbus);
2322 
2323  /* Call the Listen Complete callback, to inform upper layer of the end of Listen usecase */
2324 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
2325  hsmbus->ListenCpltCallback(hsmbus);
2326 #else
2328 #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
2329  }
2330  }
2331 
2332  /* Process Unlocked */
2333  __HAL_UNLOCK(hsmbus);
2334 
2335  return HAL_OK;
2336 }
void HAL_SMBUS_SlaveTxCpltCallback(SMBUS_HandleTypeDef *hsmbus)
Slave Tx Transfer completed callback.
static void SMBUS_TransferConfig(struct __SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set)...
__HAL_UNLOCK(hrtc)
void(* ListenCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus)
void HAL_SMBUS_AddrCallback(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode)
Slave Address Match callback.
__HAL_LOCK(hrtc)
void HAL_SMBUS_ListenCpltCallback(SMBUS_HandleTypeDef *hsmbus)
Listen Complete callback.
return HAL_OK
void(* SlaveTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus)
void(* ErrorCallback)(struct __SMBUS_HandleTypeDef *hsmbus)
void HAL_SMBUS_SlaveRxCpltCallback(SMBUS_HandleTypeDef *hsmbus)
Slave Rx Transfer completed callback.
static void SMBUS_Disable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the disabling of Interrupts.
void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *hsmbus)
SMBUS error callback.
void(* SlaveRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus)
void(* AddrCallback)(struct __SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode)

◆ SMBUS_TransferConfig()

static void SMBUS_TransferConfig ( struct __SMBUS_HandleTypeDef hsmbus,
uint16_t  DevAddress,
uint8_t  Size,
uint32_t  Mode,
uint32_t  Request 
)
static

Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set).

Parameters
hsmbusSMBUS handle.
DevAddressspecifies the slave address to be programmed.
Sizespecifies the number of bytes to be programmed. This parameter must be a value between 0 and 255.
ModeNew state of the SMBUS START condition generation. This parameter can be one or a combination of the following values:
  • SMBUS_RELOAD_MODE Enable Reload mode.
  • SMBUS_AUTOEND_MODE Enable Automatic end mode.
  • SMBUS_SOFTEND_MODE Enable Software end mode and Reload mode.
  • SMBUS_SENDPEC_MODE Enable Packet Error Calculation mode.
RequestNew state of the SMBUS START condition generation. This parameter can be one of the following values:
  • SMBUS_NO_STARTSTOP Don't Generate stop and start condition.
  • SMBUS_GENERATE_STOP Generate stop condition (Size should be set to 0).
  • SMBUS_GENERATE_START_READ Generate Restart for read request.
  • SMBUS_GENERATE_START_WRITE Generate Restart for write request.
Return values
None

Definition at line 2606 of file stm32l4xx_hal_smbus.c.

2607 {
2608  /* Check the parameters */
2609  assert_param(IS_SMBUS_ALL_INSTANCE(hsmbus->Instance));
2610  assert_param(IS_SMBUS_TRANSFER_MODE(Mode));
2611  assert_param(IS_SMBUS_TRANSFER_REQUEST(Request));
2612 
2613  /* update CR2 register */
2614  MODIFY_REG(hsmbus->Instance->CR2, ((I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | (I2C_CR2_RD_WRN & (uint32_t)(Request >> (31UL - I2C_CR2_RD_WRN_Pos))) | I2C_CR2_START | I2C_CR2_STOP | I2C_CR2_PECBYTE)), \
2615  (uint32_t)(((uint32_t)DevAddress & I2C_CR2_SADD) | (((uint32_t)Size << I2C_CR2_NBYTES_Pos) & I2C_CR2_NBYTES) | (uint32_t)Mode | (uint32_t)Request));
2616 }
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ SMBUS_WaitOnFlagUntilTimeout()

static HAL_StatusTypeDef SMBUS_WaitOnFlagUntilTimeout ( struct __SMBUS_HandleTypeDef hsmbus,
uint32_t  Flag,
FlagStatus  Status,
uint32_t  Timeout 
)
static

Handle SMBUS Communication Timeout.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
FlagSpecifies the SMBUS flag to check.
StatusThe new Flag status (SET or RESET).
TimeoutTimeout duration
Return values
HALstatus

Definition at line 2557 of file stm32l4xx_hal_smbus.c.

2558 {
2559  uint32_t tickstart = HAL_GetTick();
2560 
2561  /* Wait until flag is set */
2562  while ((FlagStatus)(__HAL_SMBUS_GET_FLAG(hsmbus, Flag)) == Status)
2563  {
2564  /* Check for the Timeout */
2565  if (Timeout != HAL_MAX_DELAY)
2566  {
2567  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
2568  {
2569  hsmbus->PreviousState = hsmbus->State;
2570  hsmbus->State = HAL_SMBUS_STATE_READY;
2571 
2572  /* Update SMBUS error code */
2573  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_HALTIMEOUT;
2574 
2575  /* Process Unlocked */
2576  __HAL_UNLOCK(hsmbus);
2577 
2578  return HAL_ERROR;
2579  }
2580  }
2581  }
2582 
2583  return HAL_OK;
2584 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
return HAL_OK