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

Fix AIRCR PRIGROUP mask #339

Merged
merged 1 commit into from
Sep 5, 2021

Conversation

msamsonoff
Copy link
Contributor

Closes #338

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thalesfragoso (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m labels Apr 19, 2021
@msamsonoff
Copy link
Contributor Author

I wonder if it's worth trying to save the PRIGROUP bits at all. They are set to 0b000 during the reset anyway.

[a] aircr: 0xfa050000
[b] aircr: 0xfa050300
sys_reset
[a] aircr: 0xfa050000
[b] aircr: 0xfa050300
sys_reset

That output was generated by this short example program:

#![no_main]
#![no_std]

use cortex_m::asm;
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use panic_semihosting as _;
use stm32h7 as _;

const SCB_AIRCR_VECTKEY: u32 = 0x05FA << 16;
const SCB_AIRCR_PRIGROUP_MASK: u32 = 0x7 << 8;
const SCB_AIRCR_PRIGROUP: u32 = 0x03 << 8;

#[entry]
fn main() -> ! {
    let p = cortex_m::Peripherals::take().unwrap();
    let scb = p.SCB;

    hprintln!("[a] aircr: 0x{:08x}", scb.aircr.read()).unwrap();

    asm::dsb();
    unsafe {
        scb.aircr.modify(
            |r| {
                SCB_AIRCR_VECTKEY | (r & SCB_AIRCR_PRIGROUP_MASK) | SCB_AIRCR_PRIGROUP
            }
        )
    }
    asm::dsb();

    hprintln!("[b] aircr: 0x{:08x}", scb.aircr.read()).unwrap();
    hprintln!("sys_reset").unwrap();

    cortex_m::peripheral::SCB::sys_reset();
}

@thejpster
Copy link
Contributor

I guess someone might change them? Anyway, 0x05 looks wrong and 0x07 looks right, so I'm happy with this after looking at section B3.2.6 of the Arm Armv7-M ARM.

@thejpster
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Sep 5, 2021

👎 Rejected by too few approved reviews

@thejpster
Copy link
Contributor

bors retry

@bors
Copy link
Contributor

bors bot commented Sep 5, 2021

Build succeeded:

@bors bors bot merged commit bb49576 into rust-embedded:master Sep 5, 2021
@adamgreig adamgreig mentioned this pull request Dec 31, 2021
bors bot added a commit that referenced this pull request Jan 2, 2022
375: Prepare v0.7.4 r=thejpster a=adamgreig

I've created a new branch, `v0.7.x`, which is currently at the latest non-breaking commit (so includes #346 #349 #347 #351 #339 #352 #348 #363 #362 #361 but does not include #342), to track the 0.7 series since master now contains breaking changes for v0.8.

This PR (which targets the new branch) cherry-picks #372 #369 #374 and bumps the version to v0.7.4 (and updates CHANGELOG) ready for a new v0.7.4 release. Once complete I'll also backport the changelog entries and bump the version in master to 0.7.4.

I think this is everything that should be in 0.7 -- the only excluded PRs from master are #342 and #367 I believe, and I don't think we have any open PRs targeting 0.7 either.

Any other thoughts on items for inclusion in 0.7.4 (or other changelog entries I missed)?

Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Co-authored-by: Adam Greig <adam@adamgreig.com>
adamgreig pushed a commit that referenced this pull request Jan 12, 2022
339: Release 0.7.1 r=adamgreig a=jonathanpallant

Includes stack unwinding through Reset fix #337.

Co-authored-by: Jonathan Pallant (Ferrous Systems) <jonathan.pallant@ferrous-systems.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SCB::sys_reset() has the wrong mask for AIRCR PRIGROUP
4 participants