Skip to content

Commit f88cff1

Browse files
committed
[Backup] Extend to manage backup SRAM
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent ba6c824 commit f88cff1

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

Diff for: cores/arduino/stm32/backup.h

+43-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern "C" {
4848

4949

5050
/* Exported functions ------------------------------------------------------- */
51-
static inline void resetBackupRegister(void)
51+
static inline void resetBackupDomain(void)
5252
{
5353
#ifdef HAL_PWR_MODULE_ENABLED
5454
/* Enable access to the RTC registers */
@@ -63,7 +63,7 @@ static inline void resetBackupRegister(void)
6363
__HAL_RCC_BACKUPRESET_RELEASE();
6464
}
6565

66-
static inline void enableBackupRegister(void)
66+
static inline void enableBackupDomain(void)
6767
{
6868
/* Enable Power Clock */
6969
#ifdef __HAL_RCC_PWR_IS_CLK_DISABLED
@@ -76,19 +76,27 @@ static inline void enableBackupRegister(void)
7676
HAL_PWR_EnableBkUpAccess();
7777
#endif
7878
#ifdef __HAL_RCC_BKP_CLK_ENABLE
79-
/* Enable BKP CLK enable for backup registers */
79+
/* Enable BKP CLK for backup registers */
8080
__HAL_RCC_BKP_CLK_ENABLE();
8181
#endif
82+
#ifdef __HAL_RCC_BKPSRAM_CLK_ENABLE
83+
/* Enable BKPSRAM CLK for backup SRAM */
84+
__HAL_RCC_BKPSRAM_CLK_ENABLE();
85+
#endif
8286
}
8387

84-
static inline void disableBackupRegister(void)
88+
static inline void disableBackupDomain(void)
8589
{
8690
#ifdef HAL_PWR_MODULE_ENABLED
8791
/* Forbid access to Backup domain */
8892
HAL_PWR_DisableBkUpAccess();
8993
#endif
94+
#ifdef __HAL_RCC_BKPSRAM_CLK_DISABLE
95+
/* Disnable BKPSRAM CLK for backup SRAM */
96+
__HAL_RCC_BKPSRAM_CLK_DISABLE();
97+
#endif
9098
#ifdef __HAL_RCC_BKP_CLK_DISABLE
91-
/* Disable BKP CLK enable for backup registers */
99+
/* Disable BKP CLK for backup registers */
92100
__HAL_RCC_BKP_CLK_DISABLE();
93101
#endif
94102
/* Disable Power Clock */
@@ -131,6 +139,36 @@ static inline uint32_t getBackupRegister(uint32_t index)
131139
#endif
132140
}
133141

142+
static inline void writeBackupSRAM(uint32_t offset, uint32_t *data, uint32_t length)
143+
{
144+
#if defined(BKPSRAM_BASE)
145+
uint32_t i = 0;
146+
/* Write 32-Bit data to Backup SRAM */
147+
for (i = 0; i < length; i++) {
148+
*(__IO uint32_t *)(BKPSRAM_BASE + (offset + i) * 4) = data[i];
149+
}
150+
#else
151+
UNUSED(offset);
152+
UNUSED(data);
153+
UNUSED(length);
154+
#endif
155+
}
156+
157+
static inline void readBackupSRAM(uint32_t offset, uint32_t *data, uint32_t length)
158+
{
159+
#if defined(BKPSRAM_BASE)
160+
uint32_t i = 0;
161+
/* Read 32-Bit data from Backup SRAM */
162+
for (i = 0; i < length; i++) {
163+
data[i] = *(__IO uint32_t *)(BKPSRAM_BASE + (offset + i) * 4);
164+
}
165+
#else
166+
UNUSED(offset);
167+
UNUSED(data);
168+
UNUSED(length);
169+
#endif
170+
}
171+
134172
#ifdef __cplusplus
135173
}
136174
#endif

Diff for: cores/arduino/stm32/clock.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void enableClock(sourceClock_t source)
9999
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
100100
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
101101

102-
enableBackupRegister();
102+
enableBackupDomain();
103103

104104
switch (source) {
105105
case LSI_CLOCK:

Diff for: cores/arduino/stm32/rtc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void RTC_init(hourFormat_t format, sourceClock_t source, bool reset)
300300
initFormat = format;
301301

302302
if (reset) {
303-
resetBackupRegister();
303+
resetBackupDomain();
304304
}
305305

306306
/* Init RTC clock */
@@ -338,7 +338,7 @@ void RTC_init(hourFormat_t format, sourceClock_t source, bool reset)
338338
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, RTC_IRQ_PRIO, RTC_IRQ_SUBPRIO);
339339
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
340340
/* Ensure backup domain is enabled */
341-
enableBackupRegister();
341+
enableBackupDomain();
342342
}
343343

344344
/**

0 commit comments

Comments
 (0)