Skip to content

File tree

9 files changed

+71
-20
lines changed

9 files changed

+71
-20
lines changed

cortex-m/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ readme = "README.md"
1313
repository = "https://github.com/rust-embedded/cortex-m"
1414
version = "0.7.7"
1515
edition = "2018"
16-
links = "cortex-m" # prevent multiple versions of this crate to be linked together
16+
links = "cortex-m" # prevent multiple versions of this crate to be linked together
1717
rust-version = "1.61"
1818

1919
[dependencies]
2020
bare-metal = { version = "0.2.4", features = ["const-fn"] }
2121
critical-section = { version = "1.0.0", optional = true }
22-
volatile-register = "0.2.0"
22+
volatile-register = "0.2.2"
2323
bitfield = "0.13.2"
2424
embedded-hal = "0.2.4"
2525

2626
[dependencies.serde]
2727
version = "1"
28-
features = [ "derive" ]
28+
features = ["derive"]
2929
optional = true
3030

3131
[dependencies.serde_json]
@@ -48,5 +48,5 @@ targets = [
4848
"thumbv7em-none-eabihf",
4949
"thumbv7m-none-eabi",
5050
"thumbv8m.base-none-eabi",
51-
"thumbv8m.main-none-eabi"
51+
"thumbv8m.main-none-eabi",
5252
]

cortex-m/asm/inline.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ pub unsafe fn __delay(cyc: u32) {
6060
// Add 1 to prevent an integer underflow which would cause a long freeze
6161
let real_cyc = 1 + cyc / 2;
6262
asm!(
63+
// The `bne` on some cores (eg Cortex-M4) will take a different number of instructions
64+
// depending on the alignment of the branch target. Set the alignment of the top of the
65+
// loop to prevent surprising timing changes when the alignment of the delay() changes.
66+
".p2align 3",
6367
// Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m.
6468
"1:",
6569
"subs {}, #1",

cortex-m/src/asm.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ pub fn bkpt() {
1717

1818
/// Blocks the program for *at least* `cycles` CPU cycles.
1919
///
20-
/// This is implemented in assembly so its execution time is independent of the optimization
21-
/// level, however it is dependent on the specific architecture and core configuration.
22-
///
23-
/// NOTE that the delay can take much longer if interrupts are serviced during its execution
24-
/// and the execution time may vary with other factors. This delay is mainly useful for simple
25-
/// timer-less initialization of peripherals if and only if accurate timing is not essential. In
26-
/// any other case please use a more accurate method to produce a delay.
20+
/// This is implemented in assembly as a fixed number of iterations of a loop, so that execution
21+
/// time is independent of the optimization level.
22+
///
23+
/// The loop code is the same for all architectures, however the number of CPU cycles required for
24+
/// one iteration varies substantially between architectures. This means that with a 48MHz CPU
25+
/// clock, a call to `delay(48_000_000)` is guaranteed to take at least 1 second, but for example
26+
/// could take 2 seconds.
27+
///
28+
/// NOTE that the delay can take much longer if interrupts are serviced during its execution and the
29+
/// execution time may vary with other factors. This delay is mainly useful for simple timer-less
30+
/// initialization of peripherals if and only if accurate timing is not essential. In any other case
31+
/// please use a more accurate method to produce a delay.
2732
#[inline]
2833
pub fn delay(cycles: u32) {
2934
call_asm!(__delay(cycles: u32));

cortex-m/src/cmse.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ impl TestTarget {
174174
/// * the TT instruction was executed from an unprivileged mode and the A flag was not specified.
175175
#[inline]
176176
pub fn mpu_region(self) -> Option<u8> {
177-
if self.tt_resp.srvalid() {
178-
// Cast is safe as SREGION field is defined on 8 bits.
179-
Some(self.tt_resp.sregion() as u8)
177+
if self.tt_resp.mrvalid() {
178+
// Cast is safe as MREGION field is defined on 8 bits.
179+
Some(self.tt_resp.mregion() as u8)
180180
} else {
181181
None
182182
}

cortex-m/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//! implementation suitable for single-core targets, based on disabling interrupts globally.
3232
//!
3333
//! It is **unsound** to enable it on multi-core targets or for code running in unprivileged mode,
34-
//! and may cause functional problems in systems where some interrupts must be not be disabled
34+
//! and may cause functional problems in systems where some interrupts must not be disabled
3535
//! or critical sections are managed as part of an RTOS. In these cases, you should use
3636
//! a target-specific implementation instead, typically provided by a HAL or RTOS crate.
3737
//!

cortex-m/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ macro_rules! iprintln {
3333
/// # Notes
3434
/// This macro is unsound on multi core systems.
3535
///
36-
/// For debuggability, you can set an explicit name for a singleton. This name only shows up the
37-
/// the debugger and is not referencable from other code. See example below.
36+
/// For debuggability, you can set an explicit name for a singleton. This name only shows up the
37+
/// debugger and is not referenceable from other code. See example below.
3838
///
3939
/// # Example
4040
///

cortex-m/src/peripheral/nvic.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ pub struct RegisterBlock {
3636
#[cfg(armv6m)]
3737
_reserved4: [u32; 16],
3838

39-
_reserved5: [u32; 48],
39+
_reserved5: [u32; 16],
40+
41+
#[cfg(armv8m)]
42+
/// Interrupt Target Non-secure (only present on Arm v8-M)
43+
pub itns: [RW<u32>; 16],
44+
#[cfg(not(armv8m))]
45+
_reserved6: [u32; 16],
46+
47+
_reserved7: [u32; 16],
4048

4149
/// Interrupt Priority
4250
///
@@ -67,7 +75,7 @@ pub struct RegisterBlock {
6775
pub ipr: [RW<u32>; 8],
6876

6977
#[cfg(not(armv6m))]
70-
_reserved6: [u32; 580],
78+
_reserved8: [u32; 580],
7179

7280
/// Software Trigger Interrupt
7381
#[cfg(not(armv6m))]

cortex-m/src/peripheral/scb.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,26 @@ impl SCB {
820820
}
821821
}
822822

823+
const SCB_SCR_SEVONPEND: u32 = 0x1 << 4;
824+
825+
impl SCB {
826+
/// Set the SEVONPEND bit in the SCR register
827+
#[inline]
828+
pub fn set_sevonpend(&mut self) {
829+
unsafe {
830+
self.scr.modify(|scr| scr | SCB_SCR_SEVONPEND);
831+
}
832+
}
833+
834+
/// Clear the SEVONPEND bit in the SCR register
835+
#[inline]
836+
pub fn clear_sevonpend(&mut self) {
837+
unsafe {
838+
self.scr.modify(|scr| scr & !SCB_SCR_SEVONPEND);
839+
}
840+
}
841+
}
842+
823843
const SCB_AIRCR_VECTKEY: u32 = 0x05FA << 16;
824844
const SCB_AIRCR_PRIGROUP_MASK: u32 = 0x7 << 8;
825845
const SCB_AIRCR_SYSRESETREQ: u32 = 1 << 2;

cortex-m/src/peripheral/syst.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
//! SysTick: System Timer
2+
//!
3+
//! # Example
4+
//!
5+
//! ```no_run
6+
//! use cortex_m::peripheral::{Peripherals, SYST};
7+
//!
8+
//! let core_periph = cortex_m::peripheral::Peripherals::take().unwrap();
9+
//! let mut syst = core_periph.SYST;
10+
//! syst.set_reload(0xffffff);
11+
//! syst.clear_current();
12+
//! syst.enable_counter();
13+
//!
14+
//! let syst_value: u32 = SYST::get_current();
15+
//! ```
216
317
use volatile_register::{RO, RW};
418

@@ -39,7 +53,7 @@ const SYST_CALIB_NOREF: u32 = 1 << 31;
3953
impl SYST {
4054
/// Clears current value to 0
4155
///
42-
/// After calling `clear_current()`, the next call to `has_wrapped()` will return `false`.
56+
/// After calling `clear_current()`, the next call to `has_wrapped()`, unless called after the reload time (if the counter is enabled), will return `false`.
4357
#[inline]
4458
pub fn clear_current(&mut self) {
4559
unsafe { self.cvr.write(0) }

0 commit comments

Comments
 (0)