Merge pull request #5083 from hierophect/stm32-sleepmem

STM32: add SleepMemory
This commit is contained in:
microDev 2021-07-31 08:48:25 +05:30 committed by GitHub
commit 98cd989c16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 5 deletions

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;
}