STM32L4xx_HAL_Driver  1.14.0

RTC Alarm functions. More...

Functions

HAL_StatusTypeDef HAL_RTC_SetAlarm (RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
 Set the specified RTC Alarm. More...
 
HAL_StatusTypeDef HAL_RTC_SetAlarm_IT (RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
 Set the specified RTC Alarm with Interrupt. More...
 
HAL_StatusTypeDef HAL_RTC_DeactivateAlarm (RTC_HandleTypeDef *hrtc, uint32_t Alarm)
 Deactivate the specified RTC Alarm. More...
 
HAL_StatusTypeDef HAL_RTC_GetAlarm (RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format)
 Get the RTC Alarm value and masks. More...
 
void HAL_RTC_AlarmIRQHandler (RTC_HandleTypeDef *hrtc)
 Handle Alarm interrupt request. More...
 
void HAL_RTC_AlarmAEventCallback (RTC_HandleTypeDef *hrtc)
 Alarm A callback. More...
 
HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent (RTC_HandleTypeDef *hrtc, uint32_t Timeout)
 Handle AlarmA Polling request. More...
 

Detailed Description

RTC Alarm functions.

 ===============================================================================
                 ##### RTC Alarm functions #####
 ===============================================================================

 [..] This section provides functions allowing to configure Alarm feature

Function Documentation

◆ HAL_RTC_AlarmAEventCallback()

__weak void HAL_RTC_AlarmAEventCallback ( RTC_HandleTypeDef hrtc)

Alarm A callback.

Parameters
hrtcRTC handle
Return values
None

Definition at line 1610 of file stm32l4xx_hal_rtc.c.

1611 {
1612  /* Prevent unused argument(s) compilation warning */
1613  UNUSED(hrtc);
1614 
1615  /* NOTE : This function should not be modified, when the callback is needed,
1616  the HAL_RTC_AlarmAEventCallback could be implemented in the user file
1617  */
1618 }

◆ HAL_RTC_AlarmIRQHandler()

void HAL_RTC_AlarmIRQHandler ( RTC_HandleTypeDef hrtc)

Handle Alarm interrupt request.

Parameters
hrtcRTC handle
Return values
None

Definition at line 1529 of file stm32l4xx_hal_rtc.c.

1530 {
1531  /* Clear the EXTI's line Flag for RTC Alarm */
1532  __HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
1533 
1534 #if defined(STM32L412xx) || defined(STM32L422xx)
1535  /* Get interrupt status */
1536  uint32_t tmp = hrtc->Instance->MISR;
1537 
1538  if ((tmp & RTC_MISR_ALRAMF) != 0u)
1539  {
1540  /* Clear the AlarmA interrupt pending bit */
1541  hrtc->Instance->SCR = RTC_SCR_CALRAF;
1542 
1543 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1544  /* Call Compare Match registered Callback */
1545  hrtc->AlarmAEventCallback(hrtc);
1546 #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1548 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1549  }
1550 
1551  if ((tmp & RTC_MISR_ALRBMF) != 0u)
1552  {
1553  /* Clear the AlarmB interrupt pending bit */
1554  hrtc->Instance->SCR = RTC_SCR_CALRBF;
1555 
1556 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1557  /* Call Compare Match registered Callback */
1558  hrtc->AlarmBEventCallback(hrtc);
1559 #else
1561 #endif
1562  }
1563 
1564 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1565 
1566  /* Get the AlarmA interrupt source enable status */
1567  if (__HAL_RTC_ALARM_GET_IT_SOURCE(hrtc, RTC_IT_ALRA) != 0U)
1568  {
1569  /* Get the pending status of the AlarmA Interrupt */
1570  if (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) != 0U)
1571  {
1572  /* Clear the AlarmA interrupt pending bit */
1573  __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
1574 
1575 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1576  hrtc->AlarmAEventCallback(hrtc);
1577 #else
1579 #endif
1580  }
1581  }
1582 
1583  /* Get the AlarmB interrupt source enable status */
1584  if (__HAL_RTC_ALARM_GET_IT_SOURCE(hrtc, RTC_IT_ALRB) != 0U)
1585  {
1586  /* Get the pending status of the AlarmB Interrupt */
1587  if (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) != 0U)
1588  {
1589  /* Clear the AlarmB interrupt pending bit */
1590  __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
1591 
1592 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1593  hrtc->AlarmBEventCallback(hrtc);
1594 #else
1596 #endif
1597  }
1598  }
1599 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1600 
1601  /* Change RTC state */
1602  hrtc->State = HAL_RTC_STATE_READY;
1603 }
void(* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc)
__IO HAL_RTCStateTypeDef State
void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
Alarm A callback.
void(* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc)

◆ HAL_RTC_DeactivateAlarm()

HAL_StatusTypeDef HAL_RTC_DeactivateAlarm ( RTC_HandleTypeDef hrtc,
uint32_t  Alarm 
)

Deactivate the specified RTC Alarm.

Parameters
hrtcRTC handle
AlarmSpecifies the Alarm. This parameter can be one of the following values:
  • RTC_ALARM_A: AlarmA
  • RTC_ALARM_B: AlarmB
Return values
HALstatus

Definition at line 1375 of file stm32l4xx_hal_rtc.c.

1376 {
1377  /* Check the parameters */
1378  assert_param(IS_RTC_ALARM(Alarm));
1379 
1380  /* Process Locked */
1381  __HAL_LOCK(hrtc);
1382 
1383  hrtc->State = HAL_RTC_STATE_BUSY;
1384 
1385  /* Disable the write protection for RTC registers */
1387 
1388  if (Alarm == RTC_ALARM_A)
1389  {
1390  /* AlarmA */
1391  __HAL_RTC_ALARMA_DISABLE(hrtc);
1392 
1393  /* In case of interrupt mode is used, the interrupt source must disabled */
1394  __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
1395 
1396 #if defined (RTC_FLAG_ALRAWF)
1397  uint32_t tickstart = HAL_GetTick();
1398  /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
1399  while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U)
1400  {
1401  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1402  {
1403  /* Enable the write protection for RTC registers */
1405 
1406  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1407 
1408  /* Process Unlocked */
1409  __HAL_UNLOCK(hrtc);
1410 
1411  return HAL_TIMEOUT;
1412  }
1413  }
1414 #endif
1415  }
1416  else
1417  {
1418  /* AlarmB */
1419  __HAL_RTC_ALARMB_DISABLE(hrtc);
1420 
1421  /* In case of interrupt mode is used, the interrupt source must disabled */
1422  __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB);
1423 
1424 #if defined (RTC_FLAG_ALRBWF)
1425  uint32_t tickstart = HAL_GetTick();
1426  /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
1427  while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U)
1428  {
1429  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1430  {
1431  /* Enable the write protection for RTC registers */
1433 
1434  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1435 
1436  /* Process Unlocked */
1437  __HAL_UNLOCK(hrtc);
1438 
1439  return HAL_TIMEOUT;
1440  }
1441  }
1442 #endif
1443  }
1444  /* Enable the write protection for RTC registers */
1446 
1447  hrtc->State = HAL_RTC_STATE_READY;
1448 
1449  /* Process Unlocked */
1450  __HAL_UNLOCK(hrtc);
1451 
1452  return HAL_OK;
1453 }
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_RTC_GetAlarm()

HAL_StatusTypeDef HAL_RTC_GetAlarm ( RTC_HandleTypeDef hrtc,
RTC_AlarmTypeDef sAlarm,
uint32_t  Alarm,
uint32_t  Format 
)

Get the RTC Alarm value and masks.

Parameters
hrtcRTC handle
sAlarmPointer to Date structure
AlarmSpecifies the Alarm. This parameter can be one of the following values:
  • RTC_ALARM_A: AlarmA
  • RTC_ALARM_B: AlarmB
FormatSpecifies the format of the entered parameters. This parameter can be one of the following values:
  • RTC_FORMAT_BIN: Binary data format
  • RTC_FORMAT_BCD: BCD data format
Return values
HALstatus

Definition at line 1469 of file stm32l4xx_hal_rtc.c.

1470 {
1471  uint32_t tmpreg, subsecondtmpreg;
1472 
1473  /* Check the parameters */
1474  assert_param(IS_RTC_FORMAT(Format));
1475  assert_param(IS_RTC_ALARM(Alarm));
1476 
1477  if (Alarm == RTC_ALARM_A)
1478  {
1479  /* AlarmA */
1480  sAlarm->Alarm = RTC_ALARM_A;
1481 
1482  tmpreg = (uint32_t)(hrtc->Instance->ALRMAR);
1483  subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR) & RTC_ALRMASSR_SS);
1484 
1485  /* Fill the structure with the read parameters */
1486  sAlarm->AlarmTime.Hours = (uint8_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> RTC_ALRMAR_HU_Pos);
1487  sAlarm->AlarmTime.Minutes = (uint8_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> RTC_ALRMAR_MNU_Pos);
1488  sAlarm->AlarmTime.Seconds = (uint8_t)((tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU)) >> RTC_ALRMAR_SU_Pos);
1489  sAlarm->AlarmTime.TimeFormat = (uint8_t)((tmpreg & RTC_ALRMAR_PM) >> RTC_ALRMAR_PM_Pos);
1490  sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg;
1491  sAlarm->AlarmDateWeekDay = (uint8_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> RTC_ALRMAR_DU_Pos);
1492  sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
1493  sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL);
1494  }
1495  else
1496  {
1497  sAlarm->Alarm = RTC_ALARM_B;
1498 
1499  tmpreg = (uint32_t)(hrtc->Instance->ALRMBR);
1500  subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS);
1501 
1502  /* Fill the structure with the read parameters */
1503  sAlarm->AlarmTime.Hours = (uint8_t)((tmpreg & (RTC_ALRMBR_HT | RTC_ALRMBR_HU)) >> RTC_ALRMBR_HU_Pos);
1504  sAlarm->AlarmTime.Minutes = (uint8_t)((tmpreg & (RTC_ALRMBR_MNT | RTC_ALRMBR_MNU)) >> RTC_ALRMBR_MNU_Pos);
1505  sAlarm->AlarmTime.Seconds = (uint8_t)((tmpreg & (RTC_ALRMBR_ST | RTC_ALRMBR_SU)) >> RTC_ALRMBR_SU_Pos);
1506  sAlarm->AlarmTime.TimeFormat = (uint8_t)((tmpreg & RTC_ALRMBR_PM) >> RTC_ALRMBR_PM_Pos);
1507  sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg;
1508  sAlarm->AlarmDateWeekDay = (uint8_t)((tmpreg & (RTC_ALRMBR_DT | RTC_ALRMBR_DU)) >> RTC_ALRMBR_DU_Pos);
1509  sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMBR_WDSEL);
1510  sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL);
1511  }
1512 
1513  if (Format == RTC_FORMAT_BIN)
1514  {
1515  sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
1516  sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes);
1517  sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds);
1519  }
1520 
1521  return HAL_OK;
1522 }
RTC_TimeTypeDef AlarmTime
return HAL_OK
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
uint32_t AlarmDateWeekDaySel

◆ HAL_RTC_PollForAlarmAEvent()

HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent ( RTC_HandleTypeDef hrtc,
uint32_t  Timeout 
)

Handle AlarmA Polling request.

Parameters
hrtcRTC handle
TimeoutTimeout duration
Return values
HALstatus

Definition at line 1626 of file stm32l4xx_hal_rtc.c.

1627 {
1628 
1629  uint32_t tickstart = HAL_GetTick();
1630 
1631  while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == 0U)
1632  {
1633  if (Timeout != HAL_MAX_DELAY)
1634  {
1635  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1636  {
1637  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1638  return HAL_TIMEOUT;
1639  }
1640  }
1641  }
1642 
1643  /* Clear the Alarm interrupt pending bit */
1644  __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
1645 
1646  /* Change RTC state */
1647  hrtc->State = HAL_RTC_STATE_READY;
1648 
1649  return HAL_OK;
1650 }
__IO HAL_RTCStateTypeDef State
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK

◆ HAL_RTC_SetAlarm()

HAL_StatusTypeDef HAL_RTC_SetAlarm ( RTC_HandleTypeDef hrtc,
RTC_AlarmTypeDef sAlarm,
uint32_t  Format 
)

Set the specified RTC Alarm.

Parameters
hrtcRTC handle
sAlarmPointer to Alarm structure
FormatSpecifies the format of the entered parameters. This parameter can be one of the following values:
  • RTC_FORMAT_BIN: Binary data format
  • RTC_FORMAT_BCD: BCD data format
Return values
HALstatus

Definition at line 1000 of file stm32l4xx_hal_rtc.c.

1001 {
1002  uint32_t tmpreg, subsecondtmpreg;
1003 
1004  /* Check the parameters */
1005  assert_param(IS_RTC_FORMAT(Format));
1006  assert_param(IS_RTC_ALARM(sAlarm->Alarm));
1007  assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
1008  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
1009  assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
1010  assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
1011 
1012  /* Process Locked */
1013  __HAL_LOCK(hrtc);
1014 
1015  hrtc->State = HAL_RTC_STATE_BUSY;
1016 
1017  if (Format == RTC_FORMAT_BIN)
1018  {
1019  if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U)
1020  {
1021  assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
1022  assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
1023  }
1024  else
1025  {
1026  sAlarm->AlarmTime.TimeFormat = 0x00U;
1027  assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
1028  }
1029  assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
1030  assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
1031 
1032  if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
1033  {
1034  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
1035  }
1036  else
1037  {
1038  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
1039  }
1040  tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << RTC_ALRMAR_HU_Pos) | \
1041  ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << RTC_ALRMAR_MNU_Pos) | \
1042  ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds) << RTC_ALRMAR_SU_Pos) | \
1043  ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << RTC_ALRMAR_PM_Pos) | \
1044  ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << RTC_ALRMAR_DU_Pos) | \
1045  ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
1046  ((uint32_t)sAlarm->AlarmMask));
1047  }
1048  else
1049  {
1050  if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U)
1051  {
1052  assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
1053  assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
1054  }
1055  else
1056  {
1057  sAlarm->AlarmTime.TimeFormat = 0x00U;
1058  assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
1059  }
1060 
1061  assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
1062  assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
1063 
1064 #ifdef USE_FULL_ASSERT
1065  if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
1066  {
1067  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay)));
1068  }
1069  else
1070  {
1071  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay)));
1072  }
1073 
1074 #endif /* USE_FULL_ASSERT */
1075  tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << RTC_ALRMAR_HU_Pos) | \
1076  ((uint32_t)(sAlarm->AlarmTime.Minutes) << RTC_ALRMAR_MNU_Pos) | \
1077  ((uint32_t)(sAlarm->AlarmTime.Seconds) << RTC_ALRMAR_SU_Pos) | \
1078  ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << RTC_ALRMAR_PM_Pos) | \
1079  ((uint32_t)(sAlarm->AlarmDateWeekDay) << RTC_ALRMAR_DU_Pos) | \
1080  ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
1081  ((uint32_t)sAlarm->AlarmMask));
1082  }
1083 
1084  /* Configure the Alarm A or Alarm B Sub Second registers */
1085  subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
1086 
1087  /* Disable the write protection for RTC registers */
1089 
1090  /* Configure the Alarm register */
1091  if (sAlarm->Alarm == RTC_ALARM_A)
1092  {
1093  /* Disable the Alarm A interrupt */
1094  __HAL_RTC_ALARMA_DISABLE(hrtc);
1095  /* Clear flag alarm A */
1096  __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
1097  /* In case of interrupt mode is used, the interrupt source must disabled */
1098  __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
1099 
1100 #if defined (RTC_FLAG_ALRAWF)
1101  uint32_t tickstart = HAL_GetTick();
1102  /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
1103  while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U)
1104  {
1105  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1106  {
1107  /* Enable the write protection for RTC registers */
1109 
1110  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1111 
1112  /* Process Unlocked */
1113  __HAL_UNLOCK(hrtc);
1114 
1115  return HAL_TIMEOUT;
1116  }
1117  }
1118 #endif
1119 
1120  hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
1121  /* Configure the Alarm A Sub Second register */
1122  hrtc->Instance->ALRMASSR = subsecondtmpreg;
1123  /* Configure the Alarm state: Enable Alarm */
1124  __HAL_RTC_ALARMA_ENABLE(hrtc);
1125  }
1126  else
1127  {
1128  /* Disable the Alarm B interrupt */
1129  __HAL_RTC_ALARMB_DISABLE(hrtc);
1130  /* Clear flag alarm B */
1131  __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
1132  /* In case of interrupt mode is used, the interrupt source must disabled */
1133  __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB);
1134 
1135 #if defined (RTC_FLAG_ALRBWF)
1136  uint32_t tickstart = HAL_GetTick();
1137  /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
1138  while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U)
1139  {
1140  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1141  {
1142  /* Enable the write protection for RTC registers */
1144 
1145  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1146 
1147  /* Process Unlocked */
1148  __HAL_UNLOCK(hrtc);
1149 
1150  return HAL_TIMEOUT;
1151  }
1152  }
1153 #endif
1154 
1155  hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
1156  /* Configure the Alarm B Sub Second register */
1157  hrtc->Instance->ALRMBSSR = subsecondtmpreg;
1158  /* Configure the Alarm state: Enable Alarm */
1159  __HAL_RTC_ALARMB_ENABLE(hrtc);
1160  }
1161 
1162  /* Enable the write protection for RTC registers */
1164 
1165  /* Change RTC state */
1166  hrtc->State = HAL_RTC_STATE_READY;
1167 
1168  /* Process Unlocked */
1169  __HAL_UNLOCK(hrtc);
1170 
1171  return HAL_OK;
1172 }
RTC_TimeTypeDef AlarmTime
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
uint8_t RTC_ByteToBcd2(uint8_t Value)
Convert a 2 digit decimal to BCD format.
__HAL_LOCK(hrtc)
return HAL_OK
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
uint32_t AlarmDateWeekDaySel

◆ HAL_RTC_SetAlarm_IT()

HAL_StatusTypeDef HAL_RTC_SetAlarm_IT ( RTC_HandleTypeDef hrtc,
RTC_AlarmTypeDef sAlarm,
uint32_t  Format 
)

Set the specified RTC Alarm with Interrupt.

Note
The Alarm register can only be written when the corresponding Alarm is disabled (Use the HAL_RTC_DeactivateAlarm()).
The HAL_RTC_SetTime() must be called before enabling the Alarm feature.
Parameters
hrtcRTC handle
sAlarmPointer to Alarm structure
FormatSpecifies the format of the entered parameters. This parameter can be one of the following values:
  • RTC_FORMAT_BIN: Binary data format
  • RTC_FORMAT_BCD: BCD data format
Return values
HALstatus

Definition at line 1187 of file stm32l4xx_hal_rtc.c.

1188 {
1189  uint32_t tmpreg, subsecondtmpreg;
1190 
1191  /* Check the parameters */
1192  assert_param(IS_RTC_FORMAT(Format));
1193  assert_param(IS_RTC_ALARM(sAlarm->Alarm));
1194  assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
1195  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
1196  assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
1197  assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
1198 
1199  /* Process Locked */
1200  __HAL_LOCK(hrtc);
1201 
1202  hrtc->State = HAL_RTC_STATE_BUSY;
1203 
1204  if (Format == RTC_FORMAT_BIN)
1205  {
1206  if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U)
1207  {
1208  assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
1209  assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
1210  }
1211  else
1212  {
1213  sAlarm->AlarmTime.TimeFormat = 0x00U;
1214  assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
1215  }
1216  assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
1217  assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
1218 
1219  if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
1220  {
1221  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
1222  }
1223  else
1224  {
1225  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
1226  }
1227 
1228  tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << RTC_ALRMAR_HU_Pos) | \
1229  ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << RTC_ALRMAR_MNU_Pos) | \
1230  ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds) << RTC_ALRMAR_SU_Pos) | \
1231  ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << RTC_ALRMAR_PM_Pos) | \
1232  ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << RTC_ALRMAR_DU_Pos) | \
1233  ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
1234  ((uint32_t)sAlarm->AlarmMask));
1235  }
1236  else
1237  {
1238  if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U)
1239  {
1240  assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
1241  assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
1242  }
1243  else
1244  {
1245  sAlarm->AlarmTime.TimeFormat = 0x00U;
1246  assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
1247  }
1248 
1249  assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
1250  assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
1251 
1252 #ifdef USE_FULL_ASSERT
1253  if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
1254  {
1255  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay)));
1256  }
1257  else
1258  {
1259  assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay)));
1260  }
1261 
1262 #endif /* USE_FULL_ASSERT */
1263  tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << RTC_ALRMAR_HU_Pos) | \
1264  ((uint32_t)(sAlarm->AlarmTime.Minutes) << RTC_ALRMAR_MNU_Pos) | \
1265  ((uint32_t)(sAlarm->AlarmTime.Seconds) << RTC_ALRMAR_SU_Pos) | \
1266  ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << RTC_ALRMAR_PM_Pos) | \
1267  ((uint32_t)(sAlarm->AlarmDateWeekDay) << RTC_ALRMAR_DU_Pos) | \
1268  ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
1269  ((uint32_t)sAlarm->AlarmMask));
1270  }
1271  /* Configure the Alarm A or Alarm B Sub Second registers */
1272  subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
1273 
1274  /* Disable the write protection for RTC registers */
1276 
1277  /* Configure the Alarm register */
1278  if (sAlarm->Alarm == RTC_ALARM_A)
1279  {
1280  /* Disable the Alarm A interrupt */
1281  __HAL_RTC_ALARMA_DISABLE(hrtc);
1282 
1283  /* Clear flag alarm A */
1284  __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
1285 
1286 #if defined (RTC_FLAG_ALRAWF)
1287  uint32_t tickstart = HAL_GetTick();
1288  /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
1289  while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U)
1290  {
1291  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1292  {
1293  /* Enable the write protection for RTC registers */
1295 
1296  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1297 
1298  /* Process Unlocked */
1299  __HAL_UNLOCK(hrtc);
1300 
1301  return HAL_TIMEOUT;
1302  }
1303  }
1304 #endif
1305 
1306  hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
1307  /* Configure the Alarm A Sub Second register */
1308  hrtc->Instance->ALRMASSR = subsecondtmpreg;
1309  /* Configure the Alarm state: Enable Alarm */
1310  __HAL_RTC_ALARMA_ENABLE(hrtc);
1311  /* Configure the Alarm interrupt */
1312  __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRA);
1313  }
1314  else
1315  {
1316  /* Disable the Alarm B interrupt */
1317  __HAL_RTC_ALARMB_DISABLE(hrtc);
1318 
1319  /* Clear flag alarm B */
1320  __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
1321 
1322 #if defined (RTC_FLAG_ALRBWF)
1323  uint32_t tickstart = HAL_GetTick();
1324  /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
1325  while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U)
1326  {
1327  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1328  {
1329  /* Enable the write protection for RTC registers */
1331 
1332  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1333 
1334  /* Process Unlocked */
1335  __HAL_UNLOCK(hrtc);
1336 
1337  return HAL_TIMEOUT;
1338  }
1339  }
1340 #endif
1341 
1342  hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
1343  /* Configure the Alarm B Sub Second register */
1344  hrtc->Instance->ALRMBSSR = subsecondtmpreg;
1345  /* Configure the Alarm state: Enable Alarm */
1346  __HAL_RTC_ALARMB_ENABLE(hrtc);
1347  /* Configure the Alarm interrupt */
1348  __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB);
1349  }
1350 
1351  /* RTC Alarm Interrupt Configuration: EXTI configuration */
1352  __HAL_RTC_ALARM_EXTI_ENABLE_IT();
1353  __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();
1354 
1355  /* Enable the write protection for RTC registers */
1357 
1358  hrtc->State = HAL_RTC_STATE_READY;
1359 
1360  /* Process Unlocked */
1361  __HAL_UNLOCK(hrtc);
1362 
1363  return HAL_OK;
1364 }
RTC_TimeTypeDef AlarmTime
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
uint8_t RTC_ByteToBcd2(uint8_t Value)
Convert a 2 digit decimal to BCD format.
__HAL_LOCK(hrtc)
return HAL_OK
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
uint32_t AlarmDateWeekDaySel