samples: boards: stm32: backup_sram: add magic value
Stores a magic value togetter with the counter value, and resets the counter in case that magic does not match. A small magic value is not ideal, but should be good enough for the sample and avoids pulling in a additional dependency e.g. on crc. Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
This commit is contained in:
parent
cc36e40357
commit
d09e1d6e8f
1 changed files with 18 additions and 5 deletions
|
@ -12,8 +12,15 @@
|
||||||
#define BACKUP_DEV_COMPAT st_stm32_backup_sram
|
#define BACKUP_DEV_COMPAT st_stm32_backup_sram
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define BACKUP_MAGIC 0x600DCE11
|
||||||
|
|
||||||
|
struct backup_store {
|
||||||
|
uint32_t value;
|
||||||
|
uint32_t magic;
|
||||||
|
};
|
||||||
|
|
||||||
/** Value stored in backup SRAM. */
|
/** Value stored in backup SRAM. */
|
||||||
__stm32_backup_sram_section uint32_t backup_value;
|
__stm32_backup_sram_section struct backup_store backup;
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
@ -24,14 +31,20 @@ int main(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("Current value in backup SRAM (%p): %d\n", &backup_value, backup_value);
|
if (backup.magic != BACKUP_MAGIC) {
|
||||||
|
backup.magic = BACKUP_MAGIC;
|
||||||
|
backup.value = 0;
|
||||||
|
printk("Invalid magic in backup SRAM structure - resetting value.\n");
|
||||||
|
}
|
||||||
|
|
||||||
backup_value++;
|
printk("Current value in backup SRAM (%p): %d\n", &backup.value, backup.value);
|
||||||
|
|
||||||
|
backup.value++;
|
||||||
#if __DCACHE_PRESENT
|
#if __DCACHE_PRESENT
|
||||||
SCB_CleanDCache_by_Addr(&backup_value, sizeof(backup_value));
|
SCB_CleanDCache_by_Addr(&backup, sizeof(backup));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printk("Next reported value should be: %d\n", backup_value);
|
printk("Next reported value should be: %d\n", backup.value);
|
||||||
printk("Keep VBAT power source and reset the board now!\n");
|
printk("Keep VBAT power source and reset the board now!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue