Skip to content

Commit

Permalink
Init FlexCAN1 and FlexCAN2 periph addition
Browse files Browse the repository at this point in the history
updates

Update mod.rs

Update mod.rs

Update mod.rs

Update mod.rs

Update mod.rs

Update mod.rs

Update mod.rs

Update mod.rs

Update mod.rs

Update mod.rs

update

update

Update mod.rs

Update mod.rs

update

Update isotp.rs

update

update

Update id.rs

update

update

Update mod.rs

update

Update mod.rs

update

mask update

update

init refactor

updates

update

Update frame.rs

update

rename package

package update

resolve PR Issues

- remove artifacts of non-existent feature: imxrt-rs#122 (comment)

- remove constrain function and use core::cmp::Ordering::clamp trait: imxrt-rs#122 (comment)

- fix to add Can to ccm mod

- remove const def of base registers

- fix to hard code Can clock source to OSC

see: imxrt-rs#122 (comment)

- update to add new iomuxc crate
  • Loading branch information
dstric-aqueduct committed Dec 14, 2022
1 parent dc9581c commit 5aad21d
Show file tree
Hide file tree
Showing 36 changed files with 3,136 additions and 560 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ jobs:
target: thumbv7em-none-eabihf
override: true
profile: minimal
- name: Check imxrt1060-hal with features '${{ matrix.features }}'
- name: Check imxrt-hal with features '${{ matrix.features }}'
uses: actions-rs/cargo@v1
with:
command: check
args: >
--features=${{ matrix.features }}
--manifest-path=imxrt1060-hal/Cargo.toml
--manifest-path=imxrt-hal/Cargo.toml
--target=thumbv7em-none-eabihf
--verbose
41 changes: 32 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Thanks for helping us build embedded Rust support for NXP's i.MX RT processors! Please open an issue if

- you find a bug in any chip HAL
- you find a bug in the HAL, RAL, or IOMUXC crates
- you have an idea for a feature
- something isn't clear in our documentation

Expand All @@ -20,22 +20,45 @@ You'll need
```bash
rustup target add thumbv7em-none-eabihf
```
### Chip-specific HAL(s)

We support one HAL crate per i.MX RT processor family. A "processor family" is described by an NXP datasheet and reference manual. For example, the `imxrt1060-hal` supports the [i.MX RT1060 Crossover Processors](https://www.nxp.com/docs/en/nxp/data-sheets/IMXRT1060CEC.pdf), which includes the following processors:
### RAL

- i.MX RT 1061
- i.MX RT 1062
The `imxrt-ral` crate is auto-generated from the checked-in SVD files, available in `imxrt-ral/svd`. It's checked into git, and you should always have whatever represents the latest auto-generated RAL. Generally, you should **not** manually change RAL source files; rather, you should describe changes in `imxrtral.py`, the Python script that auto-generates the RAL.

When developing the HAL(s) a quick way to check everything compiles, in the project root
To generate the RAL,

- Install Python 3. You'll need at least Python 3.6.
- Install the Python dependencies needed to generate the RAL: `pip3 install --user svdtools`. Alternatively, use the rules in the RAL's `Makefile` to create a virtual environment with the necessary dependencies: `make venv update-venv && source venv/bin/activate`.
- Run `make` in the `imxrt-ral` directory: `make -C imxrt-ral`. The auto-generation script might generate warnings; that's OK.

If everything went well, you should find that the `imxrt-ral/src` directory is populated with Rust files. If you made changes in `imxrtral.py`, you should see those changes reflected in the Rust files. The RAL can build by itself: `cd imxrt-ral && cargo check --features imxrt1062 --target thumbv7em-none-eabihf`.

If you add a SVD patch, or if you change something in `imxrtral.py`, you'll need to re-generate the RAL to realize the change.

### HAL

Make sure you've generated the RAL (see above). When developing the HAL, specify a feature flag from the command line. To check the HAL for `imxrt1062` processors, `cd imxrt-hal`, then

```
cargo check --features imxrt1062 --target thumbv7em-none-eabihf
```
cargo check --target thumbv7em-none-eabihf

### IOMUXC

The `imxrt-iomuxc` crate family does not require any feature flags, and it will build for your host. Consider using `--package` flags to build and test the crate family in one command:

```
cargo build --package=imxrt-iomuxc --package=imxrt-iomuxc-build
cargo test -p imxrt-iomuxc -p imxrt-iomuxc-build
```

### SVD Patches

To modify the RAL, you'll need to describe your change as an SVD patch. If you'd like to add patches to the i.MX RT SVD files, learn about [svdtools](https://github.com/stm32-rs/svdtools). Use some of the existing SVD patches as a guide.

### Testing

Our CI system ensures that the RAL and HAL(s) build for all processor variants. But, we can't automatically test against hardware! To test your changes on hardware, you'll need to test the RAL and the HAL(s) using another project, like a Rust BSP crate. Some BSP crates that use the `imxrt1060-hal` include
Our CI system ensures that the RAL and HAL builds for all processor variants. But, we can't automatically test against hardware! To test your changes on hardware, you'll need to test the RAL and the HAL using another project, like a Rust BSP crate. Some BSP crates that use the `imxrt-hal` include

- [the `imxrt1060evk-bsp` crate](https://github.com/imxrt-rs/imxrt1060evk-bsp)
- [the `teensy4-bsp` crate](https://github.com/mciantyre/teensy4-rs)
Expand All @@ -53,4 +76,4 @@ Follow the instructions in those projects to prepare an environment for testing

## Release Steps

To create a release of the RAL and HAL crates, see [RELEASE.md](docs/RELEASE.md).
To create a release of the RAL and HAL crates, see [RELEASE.md](docs/RELEASE.md).
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[workspace]
members = [
"imxrt1060-hal",
"imxrt-hal",
]
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions imxrt-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[package]
name = "imxrt-hal"
authors = ["Tom Burdick <tom.burdick@electromatic.us>", "Ian McIntyre <ianpmcintyre@gmail.com>"]
description = "Hardware abstraction layer for all NXP i.MX RT microcontrollers"
repository = "https://github.com/imxrt-rs/imxrt-rs"
readme = "README.md"
keywords = ["imxrt", "nxp", "embedded", "no_std"]
categories = ["embedded", "no-std"]
license = "MIT/Apache-2.0"
edition = "2018"
version = "0.4.5"

[dependencies]
as-slice = "0.1.3"
cortex-m = { version = "0.6" }
imxrt-ral = "0.4.0"
bitflags = "1.2.1"
embedded-hal = "0.2.3"
nb = "0.1.2"
void = { version = "1.0.2", default-features = false }
log = "0.4.8"
rand_core = { version = "0.5", default-features = false, optional = true }

[dependencies.imxrt-iomuxc]
version = "0.1.2"
git = "https://github.com/dstric-aqueduct/imxrt-iomuxc.git"
branch = "v0.1.2/can"

[dev-dependencies.cortex-m-rt]
version = "0.6"
features = ["device"]

[lib]
bench = false

[features]
default = ["embedded-hal/unproven"] # Allows us to access the new digital pin traits

# Device specific feature flags
# these need fixes and conditional sections in CCM
#imxrt1011 = ["imxrt-ral/imxrt1011"]
#imxrt1015 = ["imxrt-ral/imxrt1015"]
#imxrt1021 = ["imxrt-ral/imxrt1021"]
#imxrt1051 = ["imxrt-ral/imxrt1051"]
#imxrt1052 = ["imxrt-ral/imxrt1052"]
imxrt1061 = ["imxrt-ral/imxrt1061", "imxrt-iomuxc/imxrt106x"]
imxrt1062 = ["imxrt-ral/imxrt1062", "imxrt-iomuxc/imxrt106x"]
imxrt1064 = ["imxrt-ral/imxrt1064", "imxrt-iomuxc/imxrt106x"]
rtic = ["imxrt-ral/rtic"]
rt = ["imxrt-ral/rt"]
nosync = ["imxrt-ral/nosync"]

[package.metadata.docs.rs]
features = ["imxrt1062"]
File renamed without changes.
22 changes: 22 additions & 0 deletions imxrt-hal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# imxrt-hal

This project provides a Rust HAL (hardware abstraction layer) for all NXP i.MX RT
microcontrollers based on the imxrt-ral crate.

A feature flag needs to be set for any of the supported i.MX RT SoC.

## What is it?

imxrt-hal is an experiment into a lightweight hardware abstraction layer. It
provides access to some of the peripherals of the i.MX RT series processors
from NXP using embedded-hal and other community driven hardware APIs.

The main aims are fast compilation, compactness, and simplicity.

Please consider trying it out and contributing or leaving feedback!

## Goals

* Simple to use and hard to use incorrectly
* All peripherals and busses supported
* Support the entire i.MX RT Series with a single crate to maximize code reuse
File renamed without changes.
104 changes: 104 additions & 0 deletions imxrt-hal/src/can/embedded_hal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//! `embedded_hal` trait impls.

use super::{Data, ExtendedId, Frame, Id, OverrunError, StandardId, CAN};

use crate::iomuxc::consts::Unsigned;
use embedded_hal::can;

impl<M> can::Can for CAN<M>
where
M: Unsigned,
{
type Frame = Frame;

type Error = OverrunError;

fn transmit(&mut self, frame: &Self::Frame) -> nb::Result<Option<Self::Frame>, Self::Error> {
match self.transmit(frame) {
Ok(_status) => Ok(Some(frame.clone())),
Err(nb::Error::WouldBlock) => Err(nb::Error::WouldBlock),
Err(nb::Error::Other(e)) => match e {},
}
}

fn receive(&mut self) -> nb::Result<Self::Frame, Self::Error> {
let data: [u8; 8] = [255, 255, 255, 255, 255, 255, 255, 255];
let id = StandardId::new(0).unwrap();

Ok(Frame::new_data(id, Data::new(&data).unwrap()))
}
}

impl can::Error for OverrunError {
fn kind(&self) -> can::ErrorKind {
can::ErrorKind::Overrun
}
}

impl can::Frame for Frame {
fn new(id: impl Into<can::Id>, data: &[u8]) -> Option<Self> {
let id = match id.into() {
can::Id::Standard(id) => unsafe {
Id::Standard(StandardId::new_unchecked(id.as_raw()))
},
can::Id::Extended(id) => unsafe {
Id::Extended(ExtendedId::new_unchecked(id.as_raw()))
},
};

let data = Data::new(data)?;
Some(Frame::new_data(id, data))
}

fn new_remote(id: impl Into<can::Id>, dlc: usize) -> Option<Self> {
let id = match id.into() {
can::Id::Standard(id) => unsafe {
Id::Standard(StandardId::new_unchecked(id.as_raw()))
},
can::Id::Extended(id) => unsafe {
Id::Extended(ExtendedId::new_unchecked(id.as_raw()))
},
};

if dlc <= 8 {
Some(Frame::new_remote(id, dlc as u8))
} else {
None
}
}

#[inline]
fn is_extended(&self) -> bool {
self.is_extended()
}

#[inline]
fn is_remote_frame(&self) -> bool {
self.is_remote_frame()
}

#[inline]
fn id(&self) -> can::Id {
match self.id() {
Id::Standard(id) => unsafe {
can::Id::Standard(can::StandardId::new_unchecked(id.as_raw()))
},
Id::Extended(id) => unsafe {
can::Id::Extended(can::ExtendedId::new_unchecked(id.as_raw()))
},
}
}

#[inline]
fn dlc(&self) -> usize {
self.dlc().into()
}

fn data(&self) -> &[u8] {
if let Some(data) = self.data() {
data
} else {
&[]
}
}
}
27 changes: 27 additions & 0 deletions imxrt-hal/src/can/filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Filter bank API.

#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum FlexCanIde {
#[default]
None = 0,
Ext = 1,
Rtr = 2,
Std = 3,
Inactive
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum FlexCanFlten {
AcceptAll = 0,
#[default]
RejectAll = 1,
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub struct FlexCanFilter {
pub filter_id: u8,
pub id: u32,
pub ide: FlexCanIde,
pub remote: FlexCanIde
}

0 comments on commit 5aad21d

Please sign in to comment.