Skip to content

Commit

Permalink
export the RTC Handle as a global
Browse files Browse the repository at this point in the history
Set the subsecond for the alarm value.
Add the HAL_MSP_Init/DeInit function from the rtc library.

Signed-off-by: Francois Ramu <[email protected]>
  • Loading branch information
FRASTM committed Sep 19, 2023
1 parent 95a80b0 commit fb6eb16
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ extern "C" {
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static RTC_HandleTypeDef RtcHandle = {0};
static voidCallbackPtr RTCUserCallback = NULL;
static void *callbackUserData = NULL;
#ifdef RTC_ALARM_B
Expand Down Expand Up @@ -96,8 +95,58 @@ static inline int _log2(int x)
return (x > 0) ? (sizeof(int) * 8 - __builtin_clz(x) - 1) : 0;
}

/* Exported variable --------------------------------------------------------*/
RTC_HandleTypeDef RtcHandle = {0};

/* Exported functions --------------------------------------------------------*/

/* HAL MSP function used for RTC_Init */
void HAL_RTC_MspInit(RTC_HandleTypeDef *rtcHandle)
{
#if defined(RTC_SCR_CSSRUF)
if (rtcHandle->Instance == RTC) {
/* In BINARY mode (MIX or ONLY), set the SSR Underflow interrupt */
if (rtcHandle->Init.BinMode != RTC_BINARY_NONE) {
#if defined(STM32WLxx)
/* Only the STM32WLxx series has a TAMP_STAMP_LSECSS_SSRU_IRQn */
if (HAL_RTCEx_SetSSRU_IT(rtcHandle) != HAL_OK) {
Error_Handler();
}
/* Give init value for the RtcFeatures enable */
rtcHandle->IsEnabled.RtcFeatures = 0;

/* RTC interrupt Init */
HAL_NVIC_SetPriority(TAMP_STAMP_LSECSS_SSRU_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TAMP_STAMP_LSECSS_SSRU_IRQn);
#else
/* The STM32U5, STM32H5, STM32L4plus have common RTC interrupt and a SSRU flag */
__HAL_RTC_SSRU_ENABLE_IT(rtcHandle, RTC_IT_SSRU);
#endif /* STM32WLxx */
}
}
#else /* RTC_SCR_CSSRUF */
UNUSED(rtcHandle);
#endif /* RTC_SCR_CSSRUF */
/* RTC_Alarm_IRQn is enabled when enabling Alarm */
}

void HAL_RTC_MspDeInit(RTC_HandleTypeDef *rtcHandle)
{

if (rtcHandle->Instance == RTC) {
/* Peripheral clock disable */
__HAL_RCC_RTC_DISABLE();
__HAL_RCC_RTCAPB_CLK_DISABLE();

/* RTC interrupt Deinit */
#if defined(STM32WLxx)
/* Only the STM32WLxx series has a TAMP_STAMP_LSECSS_SSRU_IRQn */
HAL_NVIC_DisableIRQ(TAMP_STAMP_LSECSS_SSRU_IRQn);
#endif /* STM32WLxx */
HAL_NVIC_DisableIRQ(RTC_Alarm_IRQn);
}
}

/**
* @brief Set RTC clock source
* @param source: RTC clock source: LSE, LSI or HSE
Expand Down Expand Up @@ -746,7 +795,7 @@ void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *wday)
*/
void RTC_StartAlarm(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t period, uint8_t mask)
{
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_AlarmTypeDef RTC_AlarmStructure = {0};

/* Ignore time AM PM configuration if in 24 hours format */
if (initFormat == HOUR_FORMAT_24) {
Expand Down

0 comments on commit fb6eb16

Please sign in to comment.