Skip to content

Don't clock RTC in bootloader #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 4 additions & 48 deletions app/rtc/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,8 @@
RTC_HandleTypeDef RtcHandle;
static int rtc_initialized = 0;


void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;

/*##-1- Configure LSE as RTC clock source ##################################*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
return;
}

PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
return;
}

/*##-2- Enable RTC peripheral Clocks #######################################*/
/* Enable RTC Clock */
__HAL_RCC_RTC_ENABLE();
}

#define RTC_ASYNCH_PREDIV 0x7F /* LSE as RTC clock */
#define RTC_SYNCH_PREDIV 0x00FF /* LSE as RTC clock */

void RTC_CalendarBkupInit(void)
void RTC_Bkp_Init(void)
{

/*##-1- Configure the RTC peripheral #######################################*/
/* Configure RTC prescaler and RTC data registers */
/* RTC configured as follow:
Expand All @@ -68,26 +36,14 @@ void RTC_CalendarBkupInit(void)
- OutPutPolarity = High Polarity
- OutPutType = Open Drain */
RtcHandle.Instance = RTC;
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
{
BOOT_LOG_ERR("HAL_RTC_Init");
return;
}

__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
rtc_initialized = 1;
}

void RTCInit() {
if(!rtc_initialized) {
HAL_RTC_MspInit(&RtcHandle);
RTC_CalendarBkupInit();
RTC_Bkp_Init();
}
}

Expand Down
3 changes: 1 addition & 2 deletions app/rtc/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#define __RTC_H

#include <stdint.h>
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_rtc.h"
#include "rtc_api_hal.h"

#ifdef __cplusplus
extern "C" {
Expand Down