forked from stm32duino/Arduino_Core_STM32
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackup.h
136 lines (122 loc) · 3.45 KB
/
backup.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
******************************************************************************
* @file backup.h
* @author fpistm
* @brief Header for backup domain driver
******************************************************************************
* @attention
*
* Copyright (c) 2017 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BACKUP_H
#define __BACKUP_H
/* Includes ------------------------------------------------------------------*/
#include "stm32_def.h"
#include "stm32yyxx_ll_rtc.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported macro ------------------------------------------------------------*/
#if (!defined(STM32F0xx) && !defined(STM32F3xx) && !defined(STM32L0xx) &&\
!defined(STM32L1xx) && !defined(STM32L4xx)) || defined(RTC_BACKUP_SUPPORT)
#if !defined(STM32L412xx) && !defined(STM32L422xx)
#define ENABLE_BACKUP_SUPPORT
#endif
#endif
#if !defined(RTC_BKP_INDEX) && defined(ENABLE_BACKUP_SUPPORT)
#define RTC_BKP_INDEX LL_RTC_BKP_DR1
#else
#define RTC_BKP_INDEX 0
#endif
#ifndef RTC_BKP_VALUE
#define RTC_BKP_VALUE 0x32F2
#endif
/* Exported functions ------------------------------------------------------- */
static inline void resetBackupRegister(void)
{
#ifdef HAL_PWR_MODULE_ENABLED
/* Enable access to the RTC registers */
HAL_PWR_EnableBkUpAccess();
/**
* Write twice the value to flush the APB-AHB bridge
* This bit shall be written in the register before writing the next one
*/
HAL_PWR_EnableBkUpAccess();
#endif
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();
}
static inline void enableBackupRegister(void)
{
/* Enable Power Clock */
#ifdef __HAL_RCC_PWR_IS_CLK_DISABLED
if (__HAL_RCC_PWR_IS_CLK_DISABLED()) {
__HAL_RCC_PWR_CLK_ENABLE();
}
#endif
#ifdef HAL_PWR_MODULE_ENABLED
/* Allow access to Backup domain */
HAL_PWR_EnableBkUpAccess();
#endif
#ifdef __HAL_RCC_BKP_CLK_ENABLE
/* Enable BKP CLK enable for backup registers */
__HAL_RCC_BKP_CLK_ENABLE();
#endif
}
static inline void disableBackupRegister(void)
{
#ifdef HAL_PWR_MODULE_ENABLED
/* Forbid access to Backup domain */
HAL_PWR_DisableBkUpAccess();
#endif
#ifdef __HAL_RCC_BKP_CLK_DISABLE
/* Disable BKP CLK enable for backup registers */
__HAL_RCC_BKP_CLK_DISABLE();
#endif
/* Disable Power Clock */
#ifdef __HAL_RCC_PWR_IS_CLK_DISABLED
if (!__HAL_RCC_PWR_IS_CLK_DISABLED()) {
__HAL_RCC_PWR_CLK_DISABLE();
}
#endif
}
static inline void setBackupRegister(uint32_t index, uint32_t value)
{
#if defined(STM32F1xx)
LL_RTC_BKP_SetRegister(BKP, index, value);
#else
#ifdef ENABLE_BACKUP_SUPPORT
LL_RTC_BAK_SetRegister(RTC, index, value);
#else
UNUSED(index);
UNUSED(value);
#endif
#endif
}
static inline uint32_t getBackupRegister(uint32_t index)
{
#if defined(STM32F1xx)
return LL_RTC_BKP_GetRegister(BKP, index);
#else
#ifdef ENABLE_BACKUP_SUPPORT
return LL_RTC_BAK_GetRegister(RTC, index);
#else
UNUSED(index);
return 0;
#endif
#endif
}
#ifdef __cplusplus
}
#endif
#endif /* __BACKUP_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/