Skip to content
Snippets Groups Projects
Commit 4cd62a9f authored by Jorge Aparicio's avatar Jorge Aparicio
Browse files

add a Cargo feature, cm7-r0p1, to fix a Cortex-M7 BASEPRI erratum

parent bdc7ca96
Branches
Tags
No related merge requests found
...@@ -13,3 +13,6 @@ version = "0.3.1" ...@@ -13,3 +13,6 @@ version = "0.3.1"
aligned = "0.1.1" aligned = "0.1.1"
bare-metal = "0.1.0" bare-metal = "0.1.0"
volatile-register = "0.2.0" volatile-register = "0.2.0"
[features]
cm7-r0p1 = []
\ No newline at end of file
...@@ -2,6 +2,10 @@ set -euxo pipefail ...@@ -2,6 +2,10 @@ set -euxo pipefail
main() { main() {
case $TARGET in case $TARGET in
thumbv7em-none-eabi*)
xargo check --target $TARGET --features cm7-r0p1
xargo check --target $TARGET
;;
thumbv*-none-eabi*) thumbv*-none-eabi*)
xargo check --target $TARGET xargo check --target $TARGET
;; ;;
......
...@@ -18,11 +18,22 @@ pub fn read() -> u8 { ...@@ -18,11 +18,22 @@ pub fn read() -> u8 {
} }
/// Writes to the CPU register /// Writes to the CPU register
///
/// **IMPORTANT** If you are using a Cortex-M7 device with revision r0p1 you MUST enable the
/// `cm7-r0p1` Cargo feature or this function WILL misbehave.
#[cfg_attr(not(target_arch = "arm"), allow(unused_variables))]
#[inline] #[inline]
pub unsafe fn write(_basepri: u8) { pub unsafe fn write(basepri: u8) {
match () { match () {
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
() => asm!("msr BASEPRI, $0" :: "r"(_basepri) : "memory" : "volatile"), () => match () {
#[cfg(not(feature = "cm7-r0p1"))]
() => asm!("msr BASEPRI, $0" :: "r"(basepri) : "memory" : "volatile"),
#[cfg(feature = "cm7-r0p1")]
() => asm!("cpsid i
msr BASEPRI, $0
cpsie i" :: "r"(basepri) : "memory" : "volatile"),
},
#[cfg(not(target_arch = "arm"))] #[cfg(not(target_arch = "arm"))]
() => unimplemented!(), () => unimplemented!(),
} }
......
...@@ -4,12 +4,23 @@ ...@@ -4,12 +4,23 @@
/// ///
/// - `basepri != 0` AND `basepri::read() == 0`, OR /// - `basepri != 0` AND `basepri::read() == 0`, OR
/// - `basepri != 0` AND `basepri < basepri::read()` /// - `basepri != 0` AND `basepri < basepri::read()`
///
/// **IMPORTANT** If you are using a Cortex-M7 device with revision r0p1 you MUST enable the
/// `cm7-r0p1` Cargo feature or this function WILL misbehave.
#[cfg_attr(not(target_arch = "arm"), allow(unused_variables))]
#[inline] #[inline]
pub fn write(_basepri: u8) { pub fn write(basepri: u8) {
match () { match () {
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
() => unsafe { () => unsafe {
asm!("msr BASEPRI_MAX, $0" :: "r"(_basepri) : "memory" : "volatile"); match () {
#[cfg(not(feature = "cm7-r0p1"))]
() => asm!("msr BASEPRI_MAX, $0" :: "r"(basepri) : "memory" : "volatile"),
#[cfg(feature = "cm7-r0p1")]
() => asm!("cpsid i
msr BASEPRI_MAX, $0
cpsie i" :: "r"(basepri) : "memory" : "volatile"),
}
}, },
#[cfg(not(target_arch = "arm"))] #[cfg(not(target_arch = "arm"))]
() => unimplemented!(), () => unimplemented!(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment