1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/stm32: Consider VBAT on CPU init

This commit is contained in:
Fabian Hüßler 2021-10-07 21:08:27 +02:00
parent 9163d78910
commit fa52f1e986
2 changed files with 27 additions and 4 deletions

View File

@ -38,6 +38,7 @@
#include "periph_cpu.h"
#include "periph/init.h"
#include "periph/gpio.h"
#include "periph/vbat.h"
#include "board.h"
#include "pm_layered.h"
@ -395,14 +396,29 @@ void backup_ram_init(void)
#define BACKUP_RAM_MAGIC {'R', 'I', 'O', 'T'}
#endif
bool cpu_woke_from_backup(void)
{
static inline bool _backup_battery_connected(void) {
#if IS_USED(MODULE_PERIPH_VBAT)
vbat_init(); /* early use of VBAT requires init() */
return !vbat_is_empty();
#endif
return false;
}
bool cpu_woke_from_backup(void) {
#if IS_ACTIVE(CPU_HAS_BACKUP_RAM)
static const char _signature[] BACKUP_RAM_DATA = BACKUP_RAM_MAGIC;
/* switch off regulator to save power */
if (_backup_battery_connected()) {
/* in case the board has a backup battery the regulator must be on
to mitigate (unexpected) outage of VDD, so RTC register and
backup domain register contents are not lost */
pm_backup_regulator_on();
}
else {
#ifndef RIOTBOOT
pm_backup_regulator_off();
/* switch off regulator to save power */
pm_backup_regulator_off();
#endif
}
for (unsigned i = 0; i < sizeof(_signature); i++) {
if (_signature[i] != ((char[])BACKUP_RAM_MAGIC)[i]) {
return false;

View File

@ -50,6 +50,9 @@
#ifdef MODULE_PERIPH_INIT_PTP
#include "periph/ptp.h"
#endif
#ifdef MODULE_PERIPH_INIT_VBAT
#include "periph/vbat.h"
#endif
#endif /* MODULE_PERIPH_INIT */
void periph_init(void)
@ -105,5 +108,9 @@ void periph_init(void)
ptp_init();
#endif
#if defined(MODULE_PERIPH_INIT_VBAT)
vbat_init();
#endif
#endif /* MODULE_PERIPH_INIT */
}