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