From 80cb2caa093a40fbcba163aa2830d51c902df98a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 24 Jun 2020 17:20:42 +0200 Subject: [PATCH] add a compiler fence before exiting the rtt-target implementation is light on compiler fences so the compiler could be doing unwanted reordering of memory operations. At least patch up a place where these orderings may result in an observable change of behavior --- boards/dk/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/boards/dk/src/lib.rs b/boards/dk/src/lib.rs index f080c5d..4c7c3df 100644 --- a/boards/dk/src/lib.rs +++ b/boards/dk/src/lib.rs @@ -6,7 +6,7 @@ use core::{ ops, - sync::atomic::{AtomicU32, Ordering}, + sync::atomic::{self, AtomicU32, Ordering}, time::Duration, }; @@ -302,6 +302,8 @@ fn RTC0() { /// Cargo runner pub fn exit() -> ! { log::info!("`dk::exit() called; exiting ...`"); + // force any pending memory operation to complete before the BKPT instruction that follows + atomic::compiler_fence(Ordering::SeqCst); loop { asm::bkpt() }