Skip to content

Commit 2a033db

Browse files
henrikbrixandersentpambor
authored andcommitted
samples: boards: st: backup_sram: switch to Zephyr cache management API
Switch the STM32 Backup SRAM sample to use the Zephyr cache management API. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent a0aa7d6 commit 2a033db

File tree

1 file changed

+10
-3
lines changed
  • samples/boards/st/backup_sram/src

1 file changed

+10
-3
lines changed

samples/boards/st/backup_sram/src/main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <zephyr/cache.h>
78
#include <zephyr/device.h>
89
#include <zephyr/kernel.h>
910
#include <zephyr/sys/printk.h>
@@ -40,9 +41,15 @@ int main(void)
4041
printk("Current value in backup SRAM (%p): %d\n", &backup.value, backup.value);
4142

4243
backup.value++;
43-
#if __DCACHE_PRESENT
44-
SCB_CleanDCache_by_Addr(&backup, sizeof(backup));
45-
#endif
44+
45+
#if defined(CONFIG_CACHE_MANAGEMENT) && defined(CONFIG_DCACHE)
46+
int err = sys_cache_data_flush_range(&backup, sizeof(backup));
47+
48+
if (err != 0) {
49+
printk("Failed to flush the data cache (err: %d)\n", err);
50+
return 0;
51+
}
52+
#endif /* defined(CONFIG_CACHE_MANAGEMENT) && defined(CONFIG_DCACHE) */
4653

4754
printk("Next reported value should be: %d\n", backup.value);
4855
printk("Keep VBAT power source and reset the board now!\n");

0 commit comments

Comments
 (0)