Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCB.ICSR.VECTACTIVE is 9 bits, not 8 #373

Merged
merged 3 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
There is a feature `cm7` to enable access to these.
- Added `delay::Delay::with_source`, a constructor that lets you specify
the SysTick clock source (#374).
- Added the capability for `DWT` to do cycle count comparison (#367).
- Updated `SCB.ICSR.VECTACTIVE`/`SCB::vect_active()` to be 9 bits instead of 8.
Also fixes `VectActive::from` to take a `u16` and subtract `16` for
`VectActive::Interrupt`s to match `SBC::vect_active()` (#373).

### Deprecated

Expand Down
15 changes: 8 additions & 7 deletions src/peripheral/scb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ impl SCB {
/// Returns the active exception number
#[inline]
pub fn vect_active() -> VectActive {
let icsr = unsafe { ptr::read(&(*SCB::ptr()).icsr as *const _ as *const u32) };
let icsr =
unsafe { ptr::read_volatile(&(*SCB::ptr()).icsr as *const _ as *const u32) } & 0x1FF;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to read_volatile like cortex-m-rt did to prevent optimizations here


match icsr as u8 {
match icsr as u16 {
0 => VectActive::ThreadMode,
2 => VectActive::Exception(Exception::NonMaskableInt),
3 => VectActive::Exception(Exception::HardFault),
Expand Down Expand Up @@ -274,15 +275,15 @@ pub enum VectActive {

/// Device specific exception (external interrupts)
Interrupt {
/// Interrupt number. This number is always within half open range `[0, 240)`
irqn: u8,
/// Interrupt number. This number is always within half open range `[0, 512)` (9 bit)
irqn: u16,
},
}

impl VectActive {
/// Converts a `byte` into `VectActive`
/// Converts a vector number into `VectActive`
#[inline]
pub fn from(vect_active: u8) -> Option<Self> {
pub fn from(vect_active: u16) -> Option<Self> {
Some(match vect_active {
0 => VectActive::ThreadMode,
2 => VectActive::Exception(Exception::NonMaskableInt),
Expand All @@ -300,7 +301,7 @@ impl VectActive {
12 => VectActive::Exception(Exception::DebugMonitor),
14 => VectActive::Exception(Exception::PendSV),
15 => VectActive::Exception(Exception::SysTick),
irqn if irqn >= 16 => VectActive::Interrupt { irqn },
irqn if (16..512).contains(&irqn) => VectActive::Interrupt { irqn: irqn - 16 },
_ => return None,
})
}
Expand Down