Skip to content

Commit 2df45ce

Browse files
authored
Merge pull request #19 from arduino/rtc-clock
Don't clock RTC in bootloader
2 parents b0d9ab7 + f38f411 commit 2df45ce

File tree

2 files changed

+5
-50
lines changed

2 files changed

+5
-50
lines changed

app/rtc/rtc.c

+4-48
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,8 @@
2424
RTC_HandleTypeDef RtcHandle;
2525
static int rtc_initialized = 0;
2626

27-
28-
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
29-
{
30-
RCC_OscInitTypeDef RCC_OscInitStruct;
31-
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
32-
33-
/*##-1- Configure LSE as RTC clock source ##################################*/
34-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
35-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
36-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
37-
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
38-
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
39-
{
40-
return;
41-
}
42-
43-
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
44-
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
45-
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
46-
{
47-
return;
48-
}
49-
50-
/*##-2- Enable RTC peripheral Clocks #######################################*/
51-
/* Enable RTC Clock */
52-
__HAL_RCC_RTC_ENABLE();
53-
}
54-
55-
#define RTC_ASYNCH_PREDIV 0x7F /* LSE as RTC clock */
56-
#define RTC_SYNCH_PREDIV 0x00FF /* LSE as RTC clock */
57-
58-
void RTC_CalendarBkupInit(void)
27+
void RTC_Bkp_Init(void)
5928
{
60-
6129
/*##-1- Configure the RTC peripheral #######################################*/
6230
/* Configure RTC prescaler and RTC data registers */
6331
/* RTC configured as follow:
@@ -68,26 +36,14 @@ void RTC_CalendarBkupInit(void)
6836
- OutPutPolarity = High Polarity
6937
- OutPutType = Open Drain */
7038
RtcHandle.Instance = RTC;
71-
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
72-
RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
73-
RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
74-
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
75-
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
76-
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
77-
78-
if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
79-
{
80-
BOOT_LOG_ERR("HAL_RTC_Init");
81-
return;
82-
}
83-
39+
__HAL_RCC_PWR_CLK_ENABLE();
40+
HAL_PWR_EnableBkUpAccess();
8441
rtc_initialized = 1;
8542
}
8643

8744
void RTCInit() {
8845
if(!rtc_initialized) {
89-
HAL_RTC_MspInit(&RtcHandle);
90-
RTC_CalendarBkupInit();
46+
RTC_Bkp_Init();
9147
}
9248
}
9349

app/rtc/rtc.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
#define __RTC_H
2121

2222
#include <stdint.h>
23-
#include "stm32h7xx_hal.h"
24-
#include "stm32h7xx_hal_rtc.h"
23+
#include "rtc_api_hal.h"
2524

2625
#ifdef __cplusplus
2726
extern "C" {

0 commit comments

Comments
 (0)