Add STM32 sleep memory

This commit is contained in:
Lucian Copeland 2021-06-25 17:43:18 -04:00
parent 372ddfd562
commit 696c035b67

View File

@ -29,21 +29,45 @@
#include "py/runtime.h"
#include "common-hal/alarm/SleepMemory.h"
#include STM32_HAL_H
#define STM_BKPSRAM_SIZE 0x1000
#define STM_BKPSRAM_START BKPSRAM_BASE
STATIC bool initialized = false;
STATIC void lazy_init(void) {
if (!initialized) {
__HAL_RCC_BKPSRAM_CLK_ENABLE();
HAL_PWREx_EnableBkUpReg();
HAL_PWR_EnableBkUpAccess();
initialized = true;
}
}
void alarm_sleep_memory_reset(void) {
}
uint32_t common_hal_alarm_sleep_memory_get_length(alarm_sleep_memory_obj_t *self) {
mp_raise_NotImplementedError(translate("Sleep Memory not available"));
return 0;
lazy_init();
return STM_BKPSRAM_SIZE;
}
bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t *values, uint32_t len) {
mp_raise_NotImplementedError(translate("Sleep Memory not available"));
return false;
if (start_index + len > STM_BKPSRAM_SIZE) {
return false;
}
lazy_init();
memcpy((uint8_t *)(STM_BKPSRAM_START + start_index), values, len);
return true;
}
void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t *values, uint32_t len) {
mp_raise_NotImplementedError(translate("Sleep Memory not available"));
if (start_index + len > STM_BKPSRAM_SIZE) {
return;
}
lazy_init();
memcpy(values, (uint8_t *)(STM_BKPSRAM_START + start_index), len);
return;
}