Skip to content

Commit

Permalink
Hack together a 1180EVK board to turn on a LED
Browse files Browse the repository at this point in the history
The hal_led example can turn on the LED. We can't even blink that LED
yet! At least our runtime, build system, and supporting libraries are
working.

Here's how to build and program the example. You'll need a probe-rs
build that supports the 1180.

    cargo build --features=board/imxrt1180evk-cm33 --target=thumbv8m.main-none-eabihf --example=hal_led --release
    probe-rs run --chip=mimxrt1189 target/thumbv8m.main-none-eabihf/release/examples/hal_led
  • Loading branch information
mciantyre committed Nov 29, 2024
1 parent f510333 commit ca25e95
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[target.thumbv7em-none-eabihf]
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
rustflags = [
"-C", "link-arg=-Timxrt-link.x",
"-C", "link-arg=-Tdefmt.x",
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ jobs:
- name: Build examples
run: cargo build ${{ matrix.config }} --target=thumbv7em-none-eabihf --release

# For now, we let the 1180EVK examples build with warnings. It's very WIP.
examples-1180-evk:
needs: lint-hal
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install a stable toolchain for the MCU target
run: rustup toolchain install stable --no-self-update --profile minimal --target thumbv8m.main-none-eabihf
- name: Build examples
run: >
cargo build --features=board/imxrt1180evk-cm33 --target=thumbv8m.main-none-eabihf --release
--example=hal_led
# Run unit, integration tests.
#
# Select just one compatible RAL feature to pair with the HAL. The goal is to
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ imxrt-log = { path = "logging", default-features = false, features = [
"usbd",
] }
imxrt-ral = "0.6"
imxrt-rt = "0.1"
imxrt-rt = "0.1.5"
imxrt-usbd = "0.3"

[workspace.package]
Expand Down
30 changes: 21 additions & 9 deletions board/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ version = "0.7"
features = ["critical-section-single-core"]

# Use existing FCB, instead of defining inline.
[target.thumbv7em-none-eabihf.dependencies.teensy4-fcb]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.teensy4-fcb]
optional = true
version = "0.3"

[target.thumbv7em-none-eabihf.dependencies.teensy4-panic]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.teensy4-panic]
optional = true
version = "0.2"

Expand All @@ -55,35 +55,39 @@ version = "0.3"
optional = true

# knurling-rs style defmt-rtt with panic-probe
[target.thumbv7em-none-eabihf.dependencies.defmt-rtt]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.defmt-rtt]
version = "0.4"
optional = true

[target.thumbv7em-none-eabihf.dependencies.panic-probe]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.panic-probe]
version = "0.3"
features = ["print-defmt"]
optional = true

# alternative rtt target with panic printing
[target.thumbv7em-none-eabihf.dependencies.rtt-target]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.rtt-target]
version = "0.3"
optional = true
features = ["cortex-m"]

[target.thumbv7em-none-eabihf.dependencies.panic-rtt-target]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.panic-rtt-target]
version = "0.1"
optional = true
features = ["cortex-m"]

[target.thumbv7em-none-eabihf.dependencies.imxrt1010evk-fcb]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.imxrt1010evk-fcb]
version = "0.1"
optional = true

[target.thumbv7em-none-eabihf.dependencies.imxrt1060evk-fcb]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.imxrt1060evk-fcb]
version = "0.1"
optional = true

[target.thumbv7em-none-eabihf.dependencies.imxrt1170evk-fcb]
[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.imxrt1170evk-fcb]
version = "0.1"
optional = true

[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies.imxrt1180evk-fcb]
version = "0.1"
optional = true

Expand Down Expand Up @@ -124,6 +128,14 @@ imxrt1170evk-cm7 = [
"panic-probe",
"imxrt-log",
]
imxrt1180evk-cm33 = [
"imxrt-iomuxc/imxrt1180",
"imxrt-ral/imxrt1189_cm33",
"imxrt-hal/imxrt1180",
"imxrt1180evk-fcb",
"defmt-rtt",
"panic-probe",
]
logging-defmt = ["imxrt-log/defmt"]

# Some boards (Teensy 4) require a resource
Expand Down
1 change: 1 addition & 0 deletions board/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BSP.
- the IMXRT1010EVK board with the `imxrt1010evk` feature.
- the IMXRT1060EVK board with the `imxrt1060evk` feature.
- the Cortex M7 on the IMXRT1170EVK board with the `imxrt1170evk-cm7` feature.
- the Cortex M33 on the IMXRT1180EVK board with the `imxrt180evk-cm33` feature.

A board may only support a subset of all examples. To understand which examples
are supported by your board, consult the CI testing matrix.
Expand Down
13 changes: 12 additions & 1 deletion board/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"imxrt1010evk",
"imxrt1170evk-cm7",
"imxrt1060evk",
"imxrt1180evk-cm33",
],
);
emit_cfg_checks("chip", ["imxrt1010", "imxrt1060", "imxrt1170"]);
emit_cfg_checks("chip", ["imxrt1010", "imxrt1060", "imxrt1170", "imxrt1180"]);

let features = extract_features();
for feature in features {
Expand Down Expand Up @@ -84,6 +85,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rustc-cfg=board=\"imxrt1170evk-cm7\"");
println!("cargo:rustc-cfg=chip=\"imxrt1170\"");
}
"imxrt1180evk_cm33" => {
imxrt_rt::RuntimeBuilder::from_flexspi(
imxrt_rt::Family::Imxrt1180,
16 * 1024 * 1024,
)
.rodata(imxrt_rt::Memory::Dtcm)
.build()?;
println!("cargo:rustc-cfg=board=\"imxrt1180evk-cm33\"");
println!("cargo:rustc-cfg=chip=\"imxrt1180\"");
}
_ => continue,
}
return Ok(());
Expand Down
49 changes: 49 additions & 0 deletions board/src/imxrt1180evk-cm33.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! i.MX RT 1180 EVK, supporting the Cortex-M33.
use imxrt_iomuxc::imxrt1180::gpio_ad::*;
use imxrt_ral as ral;

#[cfg(target_arch = "arm")]
use defmt_rtt as _;
#[cfg(target_arch = "arm")]
use imxrt1180evk_fcb as _;

use panic_probe as _;

pub unsafe fn configure() {}

/// TODO: I'm making this up. Don't make it up.
pub const UART_CLK_FREQUENCY: u32 = 24_000_000;
/// TODO: I'm making this up. Don't make it up.
pub const LPI2C_CLK_FREQUENCY: u32 = 24_000_000;

/// USER_LED1 on the board.
///
/// Managed through GPIO4_27.
pub type Led = imxrt_hal::rgpio::Output<GPIO_AD_27>;

#[non_exhaustive]
pub struct Specifics {
pub led: Led,
}

impl Specifics {
pub(crate) fn new(_: &mut crate::Common) -> Self {
let iomuxc = unsafe { ral::iomuxc::IOMUXC::instance() };
let iomuxc_aon = unsafe { ral::iomuxc_aon::IOMUXC_AON::instance() };
let pads = imxrt_hal::iomuxc::into_pads(iomuxc, iomuxc_aon);

let gpio4 = unsafe { ral::rgpio::RGPIO4::instance() };
let mut gpio4 = imxrt_hal::rgpio::Port::new(gpio4);
let led = gpio4.output(pads.gpio_ad.p27);

Specifics { led }
}
}

pub mod interrupt {
use crate::board_interrupts as syms;
use crate::ral::Interrupt;

pub const INTERRUPTS: &[(Interrupt, syms::Vector)] = &[];
}
19 changes: 19 additions & 0 deletions board/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ mod board_impl;
#[path = "imxrt1170evk-cm7.rs"]
mod board_impl;

#[cfg(board = "imxrt1180evk-cm33")]
#[path = "imxrt1180evk-cm33.rs"]
mod board_impl;

#[cfg(feature = "lcd1602")]
pub use lcd_1602_i2c as lcd1602;

Expand All @@ -58,6 +62,7 @@ pub use board_impl::*;
///
/// This includes timers, DMA channels, and things
/// that don't necessarily depend on a pinout.
#[cfg(any(chip = "imxrt1010", chip = "imxrt1060", chip = "imxrt1170"))]
pub struct Common {
/// PIT channels.
pub pit: hal::pit::Channels,
Expand Down Expand Up @@ -87,6 +92,7 @@ pub struct Common {
pub usbphy1: UsbPhy1,
}

#[cfg(any(chip = "imxrt1010", chip = "imxrt1060", chip = "imxrt1170"))]
impl Common {
/// Prepares common resources.
fn new() -> Self {
Expand Down Expand Up @@ -126,6 +132,16 @@ impl Common {
}
}

#[cfg(chip = "imxrt1180")]
#[non_exhaustive]
pub struct Common {}

#[cfg(chip = "imxrt1180")]
impl Common {
fn new() -> Self {
Self {}
}
}
/// Board entrypoint.
///
/// Use this to configure the hardware and acquire peripherals.
Expand Down Expand Up @@ -173,6 +189,9 @@ use iomuxc::imxrt1060::Pads;
#[cfg(chip = "imxrt1170")]
use iomuxc::imxrt1170::Pads;

#[cfg(chip = "imxrt1180")]
use iomuxc::imxrt1180::Pads;

/// Convert the IOMUXC peripheral into pad objects.
fn convert_iomuxc(_: ral::iomuxc::IOMUXC) -> Pads {
// Safety: acquired IOMUXC peripheral, so no one else is safely
Expand Down

0 comments on commit ca25e95

Please sign in to comment.