Hardware abstraction layer

The imxrt-hal crate provides the hardware abstraction layer (HAL) for i.MX RT microcontrollers. The HAL includes re-usable hardware drivers for 10xx and 11xx MCUs. Most of the HAL's drivers implement their corresponding traits from embedded-hal, allowing you to pair the hardware driver with third-party sensor, actuator, and device drivers.

imxrt-hal drivers adapt the low-level peripheral instances provided by imxrt-ral, so you can use the HAL by adding it as another package in your project. Unlike the previous example, this new example use imxrt-hal APIs to access pads and prepare a GPIO output.

# Cargo.toml

[dependencies]
imxrt-hal = { version = "0.5", features = ["imxrt1010"] }

# As before...
imxrt-ral = { version = "0.5", features = ["imxrt1011", "rt"] }
imxrt-rt = { version = "0.1", features = ["device"] }
imxrt1010evk-fcb = "0.1"
panic-halt = "0.2"

[build-dependencies]
imxrt-rt = { version = "0.1", features = ["device"] }
//! build.rs (unchanged)

use imxrt_rt::{Family, RuntimeBuilder};

fn main() {
    RuntimeBuilder::from_flexspi(Family::Imxrt1010, 16 * 1024 * 1024)
        .build()
        .unwrap();
}
//! main.rs

#![no_main]
#![no_std]

use imxrt_hal as hal;
use imxrt_ral as ral;

use imxrt1010evk_fcb as _;
use imxrt_rt::entry;
use panic_halt as _;

#[entry]
fn main() -> ! {
    // Safety: we're the only code that "owns" the IOMUXC and GPIO1 peripherals.
    let iomuxc = unsafe { ral::iomuxc::IOMUXC::instance() };
    let gpio1 = unsafe { ral::gpio::GPIO1::instance() };

    let mut gpio1 = hal::gpio::Port::new(gpio1);
    let pads = hal::iomuxc::into_pads(iomuxc);

    // Configures the pad named "GPIO_11" as a GPIO output.
    let led = gpio1.output(pads.gpio.p11);
    // Turn on the LED.
    led.set();

    loop {}
}

Try the HAL

The imxrt-hal repository includes a collection of hardware examples that work on various boards listed in the repository.

You can use these examples to try the HAL on your hardware. See the repository documentation for more information.