From ca25e95fa08acafcce7273eda03f214144c18dce Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Thu, 28 Nov 2024 16:51:07 -0500 Subject: [PATCH] Hack together a 1180EVK board to turn on a LED 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 --- .cargo/config.toml | 2 +- .github/workflows/rust.yml | 13 +++++++++ Cargo.toml | 2 +- board/Cargo.toml | 30 ++++++++++++++------- board/README.md | 1 + board/build.rs | 13 ++++++++- board/src/imxrt1180evk-cm33.rs | 49 ++++++++++++++++++++++++++++++++++ board/src/lib.rs | 19 +++++++++++++ 8 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 board/src/imxrt1180evk-cm33.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index a95af8f3..9d639a51 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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", diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2ebdcc61..92c3e3dc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 8bd2e375..8b5a6e5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/board/Cargo.toml b/board/Cargo.toml index 53d2e3b8..3c9b0a77 100644 --- a/board/Cargo.toml +++ b/board/Cargo.toml @@ -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" @@ -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 @@ -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 diff --git a/board/README.md b/board/README.md index 5b39cb33..84aaf3a7 100644 --- a/board/README.md +++ b/board/README.md @@ -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. diff --git a/board/build.rs b/board/build.rs index 9468bbaa..a0089e2a 100644 --- a/board/build.rs +++ b/board/build.rs @@ -35,9 +35,10 @@ fn main() -> Result<(), Box> { "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 { @@ -84,6 +85,16 @@ fn main() -> Result<(), Box> { 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(()); diff --git a/board/src/imxrt1180evk-cm33.rs b/board/src/imxrt1180evk-cm33.rs new file mode 100644 index 00000000..dc42fa14 --- /dev/null +++ b/board/src/imxrt1180evk-cm33.rs @@ -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; + +#[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)] = &[]; +} diff --git a/board/src/lib.rs b/board/src/lib.rs index 044c6dbd..8973ee99 100644 --- a/board/src/lib.rs +++ b/board/src/lib.rs @@ -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; @@ -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, @@ -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 { @@ -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. @@ -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