Skip to content

Commit cdc02c6

Browse files
committed
Add barriers after FPU enabling
1 parent fbcfff1 commit cdc02c6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

cortex-m-rt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ links = "cortex-m-rt" # Prevent multiple versions of cortex-m-rt being linked
1919
[dependencies]
2020
r0 = "1.0"
2121
cortex-m-rt-macros = { path = "macros", version = "=0.6.11" }
22+
cortex-m = "0.6"
2223

2324
[dev-dependencies]
24-
cortex-m = "0.6"
2525
panic-halt = "0.2.0"
2626
cortex-m-semihosting = "0.3"
2727

cortex-m-rt/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,12 @@ pub unsafe extern "C" fn Reset() -> ! {
916916
r0::zero_bss(&mut __sbss, &mut __ebss);
917917
r0::init_data(&mut __sdata, &mut __edata, &__sidata);
918918

919+
#[allow(clippy::match_single_binding)]
919920
match () {
920921
#[cfg(not(has_fpu))]
921922
() => main(),
922923
#[cfg(has_fpu)]
923924
() => {
924-
// We redefine these here to avoid pulling the `cortex-m` crate as a dependency
925925
const SCB_CPACR: *mut u32 = 0xE000_ED88 as *mut u32;
926926
const SCB_CPACR_FPU_ENABLE: u32 = 0b01_01 << 20;
927927
const SCB_CPACR_FPU_USER: u32 = 0b10_10 << 20;
@@ -932,6 +932,9 @@ pub unsafe extern "C" fn Reset() -> ! {
932932
*SCB_CPACR | SCB_CPACR_FPU_ENABLE | SCB_CPACR_FPU_USER,
933933
);
934934

935+
cortex_m::asm::dsb();
936+
cortex_m::asm::isb();
937+
935938
// this is used to prevent the compiler from inlining the user `main` into the reset
936939
// handler. Inlining can cause the FPU instructions in the user `main` to be executed
937940
// before enabling the FPU, and that would produce a hard to diagnose hard fault at

0 commit comments

Comments
 (0)