STM32L4xx_HAL_Driver  1.14.0
RTC Private Functions

Functions

HAL_StatusTypeDef RTC_EnterInitMode (RTC_HandleTypeDef *hrtc)
 Enter the RTC Initialization mode. More...
 
HAL_StatusTypeDef RTC_ExitInitMode (RTC_HandleTypeDef *hrtc)
 Exit the RTC Initialization mode. More...
 
uint8_t RTC_ByteToBcd2 (uint8_t Value)
 Convert a 2 digit decimal to BCD format. More...
 
uint8_t RTC_Bcd2ToByte (uint8_t Value)
 Convert from 2 digit BCD to Binary. More...
 

Detailed Description

Function Documentation

◆ RTC_Bcd2ToByte()

uint8_t RTC_Bcd2ToByte ( uint8_t  Value)

Convert from 2 digit BCD to Binary.

Parameters
ValueBCD value to be converted
Return values
Convertedword

Definition at line 1874 of file stm32l4xx_hal_rtc.c.

1875 {
1876  uint8_t tmp;
1877  tmp = ((Value & 0xF0U) >> 4U) * 10U;
1878  return (tmp + (Value & 0x0FU));
1879 }

◆ RTC_ByteToBcd2()

uint8_t RTC_ByteToBcd2 ( uint8_t  Value)

Convert a 2 digit decimal to BCD format.

Parameters
ValueByte to be converted
Return values
Convertedbyte

Definition at line 1855 of file stm32l4xx_hal_rtc.c.

1856 {
1857  uint32_t bcdhigh = 0U;
1858  uint8_t temp = Value;
1859 
1860  while (temp >= 10U)
1861  {
1862  bcdhigh++;
1863  temp -= 10U;
1864  }
1865 
1866  return ((uint8_t)(bcdhigh << 4U) | temp);
1867 }

◆ RTC_EnterInitMode()

HAL_StatusTypeDef RTC_EnterInitMode ( RTC_HandleTypeDef hrtc)

Enter the RTC Initialization mode.

Note
The RTC Initialization mode is write protected, use the __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
Parameters
hrtcRTC handle
Return values
HALstatus

Definition at line 1761 of file stm32l4xx_hal_rtc.c.

1762 {
1763  uint32_t tickstart;
1764  HAL_StatusTypeDef status = HAL_OK;
1765 
1766  /* Check if the Initialization mode is set */
1767 #if defined(STM32L412xx) || defined(STM32L422xx)
1768  if ((hrtc->Instance->ICSR & RTC_ICSR_INITF) == 0U)
1769  {
1770  /* Set the Initialization mode */
1771  SET_BIT(hrtc->Instance->ICSR, RTC_ICSR_INIT);
1772 
1773  tickstart = HAL_GetTick();
1774  /* Wait till RTC is in INIT state and if Time out is reached exit */
1775  while ((READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_INITF) == 0U) && (status != HAL_TIMEOUT))
1776  {
1777  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1778  {
1779  status = HAL_TIMEOUT;
1780  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1781  }
1782  }
1783  }
1784 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1785  if ((hrtc->Instance->ISR & RTC_ISR_INITF) == 0U)
1786  {
1787  /* Set the Initialization mode */
1788  hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
1789 
1790  tickstart = HAL_GetTick();
1791  /* Wait till RTC is in INIT state and if Time out is reached exit */
1792  while ((READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U) && (status != HAL_TIMEOUT))
1793  {
1794  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1795  {
1796  status = HAL_TIMEOUT;
1797  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1798  }
1799  }
1800  }
1801 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1802 
1803  return status;
1804 }
__IO HAL_RTCStateTypeDef State
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK

◆ RTC_ExitInitMode()

HAL_StatusTypeDef RTC_ExitInitMode ( RTC_HandleTypeDef hrtc)

Exit the RTC Initialization mode.

Parameters
hrtcRTC handle
Return values
HALstatus

Definition at line 1811 of file stm32l4xx_hal_rtc.c.

1812 {
1813  HAL_StatusTypeDef status = HAL_OK;
1814 
1815  /* Exit Initialization mode */
1816 #if defined(STM32L412xx) || defined(STM32L422xx)
1817  CLEAR_BIT(RTC->ICSR, RTC_ICSR_INIT);
1818 #else
1819  /* Exit Initialization mode */
1820  CLEAR_BIT(RTC->ISR, RTC_ISR_INIT);
1821 #endif
1822 
1823  /* If CR_BYPSHAD bit = 0, wait for synchro */
1824  if (READ_BIT(RTC->CR, RTC_CR_BYPSHAD) == 0U)
1825  {
1826  if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
1827  {
1828  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1829  status = HAL_TIMEOUT;
1830  }
1831  }
1832  else /* WA 2.9.6 Calendar initialization may fail in case of consecutive INIT mode entry */
1833  {
1834  /* Clear BYPSHAD bit */
1835  CLEAR_BIT(RTC->CR, RTC_CR_BYPSHAD);
1836  if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
1837  {
1838  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1839  status = HAL_TIMEOUT;
1840  }
1841  /* Restore BYPSHAD bit */
1842  SET_BIT(RTC->CR, RTC_CR_BYPSHAD);
1843  }
1844 
1845  return status;
1846 }
HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc)
Wait until the RTC Time and Date registers (RTC_TR and RTC_DR) are synchronized with RTC APB clock...
__IO HAL_RTCStateTypeDef State
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK