Skip to content

cortex-m-pac crate: standard traits and result handling for Cortex-M targets #560

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

romancardenas
Copy link
Contributor

This PR ports some of the ongoing work in the RISC-V ecosystem to Cortex-M targets. Namely, I adapted the riscv-pac crate to the new cortex-m-pac crate.

The main purpose of this crate is to isolate fundamental traits and data types from potential breaking changes in cortex-m. Namely, it currently contains traits for enumerating exceptions, interrupts, priorities, and core IDs. It also provides a basic fallible function support for Cortex-M devices, with an error enum with some of the most typical issues developers may face.

Related PRs in RISC-V: #222 and #223

Related PRs in Cortex-M: #488

Once this is merged, I plan to continue porting new functionalities from RISC-V to Cortex-M (e.g., new syntax for interrupt and exception macros)

@romancardenas romancardenas requested a review from a team as a code owner October 9, 2024 21:11

/// Represents error variants for the library.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Error {

Choose a reason for hiding this comment

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

since core::error::Error is now stable it might make sense to impl it here? since you already have impl core::fmt::Display this should be straight-forward?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@romancardenas
Copy link
Contributor Author

Implementing core::error::Error implies bumping MSRV to 1.81. Let me know what you think and if it is worth it such a change

@jannic
Copy link
Member

jannic commented Oct 18, 2024

CI failed because the ubuntu-latest label migrated to ubuntu 24.04 (https://github.blog/changelog/2024-09-25-actions-new-images-and-ubuntu-latest-changes/), and it looks like there the qemu package is no longer available.

A quick fix would be to change the runner image to ubuntu-22.04.

Alternatively, CI could use qemu-system-x86-64 instead of qemu. However this might need some tweaking of command lines.

@jannic
Copy link
Member

jannic commented Oct 18, 2024

Alternatively, CI could use qemu-system-x86-64 instead of qemu. However this might need some tweaking of command lines.

That was easier than I had expected: #562

@romancardenas
Copy link
Contributor Author

Rebased and added #[non_exhaustive] to Error


## Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
Copy link
Member

Choose a reason for hiding this comment

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

Cargo.toml says 1.81

/// * `MAX_EXCEPTION_NUMBER` must coincide with the highest allowed exception number.
pub unsafe trait ExceptionNumber: Copy {
/// Highest number assigned to an exception.
const MAX_EXCEPTION_NUMBER: usize;
Copy link
Member

@jannic jannic Jun 3, 2025

Choose a reason for hiding this comment

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

It seems strange to define MAX_EXCEPTION_NUMBER on each instance of ExceptionNumber.

Sorry, I misunderstood the purpose. There should only be one enum implementing this trait, right?


## License

Copyright 2024 [Cortex-M team][team]
Copy link
Contributor

Choose a reason for hiding this comment

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

It's the Arm team now

@thalesfragoso
Copy link
Member

CC @adamgreig Since this is replacing a previous PR from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants