Skip to content

Commit 52471e2

Browse files
committed
Add missing critical section to flash code
1 parent 6b2a791 commit 52471e2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/flash.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! See STM32L0x2 reference manual, chapter 3.
44
55

6+
use cortex_m::interrupt;
7+
68
use crate::{
79
pac,
810
rcc::Rcc,
@@ -200,9 +202,15 @@ impl FLASH {
200202
w
201203
});
202204

203-
// Safe, because we've verified the valididty of `address` and the
204-
// length `words`.
205-
unsafe { write_half_page(address, words.as_ptr()); }
205+
// We absoluty can't have any access to Flash while preparing the
206+
// write, or the process will be interrupted. This includes any
207+
// access to the vector table or interrupt handlers that might be
208+
// caused by an interrupt.
209+
interrupt::free(|_| {
210+
// Safe, because we've verified the valididty of `address` and
211+
// the length `words`.
212+
unsafe { write_half_page(address, words.as_ptr()); }
213+
});
206214

207215
// Wait for operation to complete
208216
while self_.flash.sr.read().bsy().is_active() {}

0 commit comments

Comments
 (0)