Merge pull request #5083 from hierophect/stm32-sleepmem
STM32: add SleepMemory
This commit is contained in:
commit
98cd989c16
|
@ -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"));
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue