source: trunk/fw_g473rct/Core/Src/rtc.c

Last change on this file was 25, checked in by f.jahn, 8 weeks ago

RTC implementiert

File size: 2.7 KB
Line 
1/* USER CODE BEGIN Header */
2/**
3  ******************************************************************************
4  * @file    rtc.c
5  * @brief   This file provides code for the configuration
6  *          of the RTC instances.
7  ******************************************************************************
8  * @attention
9  *
10  * Copyright (c) 2025 STMicroelectronics.
11  * All rights reserved.
12  *
13  * This software is licensed under terms that can be found in the LICENSE file
14  * in the root directory of this software component.
15  * If no LICENSE file comes with this software, it is provided AS-IS.
16  *
17  ******************************************************************************
18  */
19/* USER CODE END Header */
20/* Includes ------------------------------------------------------------------*/
21#include "rtc.h"
22
23/* USER CODE BEGIN 0 */
24
25/* USER CODE END 0 */
26
27RTC_HandleTypeDef hrtc;
28
29/* RTC init function */
30void MX_RTC_Init(void)
31{
32
33  /* USER CODE BEGIN RTC_Init 0 */
34
35  /* USER CODE END RTC_Init 0 */
36
37  /* USER CODE BEGIN RTC_Init 1 */
38
39  /* USER CODE END RTC_Init 1 */
40
41  /** Initialize RTC Only
42  */
43  hrtc.Instance = RTC;
44  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
45  hrtc.Init.AsynchPrediv = 127;
46  hrtc.Init.SynchPrediv = 255;
47  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
48  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
49  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
50  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
51  hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
52  if (HAL_RTC_Init(&hrtc) != HAL_OK)
53  {
54    Error_Handler();
55  }
56  /* USER CODE BEGIN RTC_Init 2 */
57
58  /* USER CODE END RTC_Init 2 */
59
60}
61
62void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
63{
64
65  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
66  if(rtcHandle->Instance==RTC)
67  {
68  /* USER CODE BEGIN RTC_MspInit 0 */
69
70  /* USER CODE END RTC_MspInit 0 */
71
72  /** Initializes the peripherals clocks
73  */
74    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
75    PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
76    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
77    {
78      Error_Handler();
79    }
80
81    /* RTC clock enable */
82    __HAL_RCC_RTC_ENABLE();
83    __HAL_RCC_RTCAPB_CLK_ENABLE();
84  /* USER CODE BEGIN RTC_MspInit 1 */
85
86  /* USER CODE END RTC_MspInit 1 */
87  }
88}
89
90void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
91{
92
93  if(rtcHandle->Instance==RTC)
94  {
95  /* USER CODE BEGIN RTC_MspDeInit 0 */
96
97  /* USER CODE END RTC_MspDeInit 0 */
98    /* Peripheral clock disable */
99    __HAL_RCC_RTC_DISABLE();
100    __HAL_RCC_RTCAPB_CLK_DISABLE();
101  /* USER CODE BEGIN RTC_MspDeInit 1 */
102
103  /* USER CODE END RTC_MspDeInit 1 */
104  }
105}
106
107/* USER CODE BEGIN 1 */
108
109/* USER CODE END 1 */
Note: See TracBrowser for help on using the repository browser.