Skip to content

Commit baca4c0

Browse files
authored
Merge pull request #43 from adafruit/fence-cache-operations
Add memory fences when disabling cache
2 parents 57133ee + 72c42f8 commit baca4c0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

samd/sam_d5x_e5x/cache.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@
2828

2929
// Turn off cache and invalidate all data in it.
3030
void samd_peripherals_disable_and_clear_cache(void) {
31+
// Memory fence for hardware and compiler reasons. If this routine is inlined, the compiler
32+
// needs to know that everything written out be stored before this is called.
33+
// -O2 optimization showed this was necessary.
34+
__sync_synchronize();
35+
3136
CMCC->CTRL.bit.CEN = 0;
3237
while (CMCC->SR.bit.CSTS) {}
3338
CMCC->MAINT0.bit.INVALL = 1;
39+
40+
// Memory fence for hardware and compiler reasons. Testing showed this second one is also
41+
// necessary when compiled with -O2.
42+
__sync_synchronize();
3443
}
3544

3645
// Enable cache

0 commit comments

Comments
 (0)