Skip to content

Commit 2dc17d2

Browse files
committed
stm32h7-startup: reorder AXI erratum and cache setup
@mkeeter noticed nondeterminism in the delay loop for measurement handoff, which caused us to realize that it was being performed _before_ the caches were set up ... which means small alignment changes in flash can have huge impact on the execution time of a tight loop. While considering fixes, I noticed that the fix for the AXI SRAM read erratum had gradually drifted below other code. This was safe when I initially implemented it, because we weren't using AXI SRAM for kernel stack etc. at the time. We are now! This commit moves the AXI SRAM erratum fix into pre_init where it runs before most RAM accesses, and moves cache setup earlier in system_init_custom to ensure that caches are on for the rest of the process, including measurement handoff.
1 parent c205809 commit 2dc17d2

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

drv/stm32h7-startup/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ unsafe fn system_pre_init() {
5252

5353
// Okay, yay, we can use some RAMs now.
5454

55+
#[cfg(any(feature = "h743", feature = "h753"))]
56+
{
57+
// Workaround for erratum 2.2.9 "Reading from AXI SRAM may lead to data
58+
// read corruption" - limits AXI SRAM read concurrency.
59+
let axi = &*device::AXI::ptr();
60+
axi.targ7_fn_mod
61+
.modify(|_, w| w.read_iss_override().set_bit());
62+
}
63+
5564
// We'll do the rest in system_init.
5665
}
5766

@@ -96,6 +105,11 @@ pub fn system_init_custom(
96105
// static variables.
97106
//
98107
// We are running at 64MHz on the HSI oscillator at voltage scale VOS3.
108+
//
109+
// Turn on CPU I/D caches to improve performance. This has a significant
110+
// impact on the delay loop a few lines below.
111+
cp.SCB.enable_icache();
112+
cp.SCB.enable_dcache(&mut cp.CPUID);
99113

100114
// Before doing anything else, check for a measurement handoff token
101115
#[cfg(feature = "measurement-handoff")]
@@ -107,15 +121,6 @@ pub fn system_init_custom(
107121
});
108122
}
109123

110-
#[cfg(any(feature = "h743", feature = "h753"))]
111-
{
112-
// Workaround for erratum 2.2.9 "Reading from AXI SRAM may lead to data
113-
// read corruption" - limits AXI SRAM read concurrency.
114-
p.AXI
115-
.targ7_fn_mod
116-
.modify(|_, w| w.read_iss_override().set_bit());
117-
}
118-
119124
// The H7 -- and perhaps the Cortex-M7 -- has the somewhat annoying
120125
// property that any attempt to use ITM without having TRCENA set in
121126
// DBGMCU results in the FIFO never being ready (that is, ITM writes
@@ -161,11 +166,6 @@ pub fn system_init_custom(
161166
// Ethernet is on RMII, not MII.
162167
p.SYSCFG.pmcr.modify(|_, w| unsafe { w.epis().bits(0b100) });
163168

164-
// Turn on CPU I/D caches to improve performance at the higher clock speeds
165-
// we're about to enable.
166-
cp.SCB.enable_icache();
167-
cp.SCB.enable_dcache(&mut cp.CPUID);
168-
169169
// The Flash controller comes out of reset configured for 3 wait states.
170170
// That's approximately correct for 64MHz at VOS3, which is fortunate, since
171171
// we've been executing instructions out of flash _the whole time._

0 commit comments

Comments
 (0)