Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
Hosted Weblate 2021-07-31 21:32:57 +02:00
commit 4884c32f08
No known key found for this signature in database
GPG Key ID: A3FAAA06E6569B4C
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;
}