diff options
| author | i509VCB <[email protected]> | 2025-07-21 20:29:34 -0500 |
|---|---|---|
| committer | i509VCB <[email protected]> | 2025-07-22 11:25:45 -0500 |
| commit | 1d46f55bddf402c33143959e1ad26af59bb15855 (patch) | |
| tree | 2239a545303c4df4cfc1d9ff4aec7069e006babe /examples | |
| parent | 908e016524e1802b736664d84ca2da6ea908444d (diff) | |
nxp: Add mimxrt1062 support
The examples in this case are designed for the IMXRT1060-EVK. The same chip is used in the Teensy 4.0/1, but that will probably get its own set of examples due to some differences such as the FCB.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/mimxrt1062-evk/.cargo/config.toml | 8 | ||||
| -rw-r--r-- | examples/mimxrt1062-evk/Cargo.toml | 29 | ||||
| -rw-r--r-- | examples/mimxrt1062-evk/build.rs | 12 | ||||
| -rw-r--r-- | examples/mimxrt1062-evk/src/bin/blinky.rs | 25 | ||||
| -rw-r--r-- | examples/mimxrt1062-evk/src/bin/button.rs | 36 | ||||
| -rw-r--r-- | examples/mimxrt1062-evk/src/lib.rs | 60 |
6 files changed, 170 insertions, 0 deletions
diff --git a/examples/mimxrt1062-evk/.cargo/config.toml b/examples/mimxrt1062-evk/.cargo/config.toml new file mode 100644 index 000000000..ca4c606dc --- /dev/null +++ b/examples/mimxrt1062-evk/.cargo/config.toml | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | [target.thumbv7em-none-eabihf] | ||
| 2 | runner = 'probe-rs run --chip MIMXRT1060' | ||
| 3 | |||
| 4 | [build] | ||
| 5 | target = "thumbv7em-none-eabihf" # Cortex-M7 | ||
| 6 | |||
| 7 | [env] | ||
| 8 | DEFMT_LOG = "trace" | ||
diff --git a/examples/mimxrt1062-evk/Cargo.toml b/examples/mimxrt1062-evk/Cargo.toml new file mode 100644 index 000000000..430a26b41 --- /dev/null +++ b/examples/mimxrt1062-evk/Cargo.toml | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-imxrt1062-evk-examples" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | license = "MIT or Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] } | ||
| 9 | cortex-m-rt = "0.7.3" | ||
| 10 | defmt = "1.0.1" | ||
| 11 | defmt-rtt = "1.0.0" | ||
| 12 | |||
| 13 | embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } | ||
| 14 | embassy-futures = { version = "0.1.1", path = "../../embassy-futures" } | ||
| 15 | embassy-nxp = { version = "0.1.0", path = "../../embassy-nxp", features = ["defmt", "mimxrt1062", "unstable-pac", "time-driver-pit"] } | ||
| 16 | embassy-time = { version = "0.4", path = "../../embassy-time", features = ["defmt", ] } # "defmt-timestamp-uptime" | ||
| 17 | embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] } | ||
| 18 | embedded-hal-1 = { package = "embedded-hal", version = "1.0" } | ||
| 19 | embedded-hal-async = "1.0.0" | ||
| 20 | |||
| 21 | imxrt-boot-gen = { version = "0.3.4", features = ["imxrt1060"] } | ||
| 22 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } | ||
| 23 | panic-semihosting = "0.6.0" | ||
| 24 | |||
| 25 | [build-dependencies] | ||
| 26 | imxrt-rt = { version = "0.1.7", features = ["device"] } | ||
| 27 | |||
| 28 | [profile.release] | ||
| 29 | debug = 2 | ||
diff --git a/examples/mimxrt1062-evk/build.rs b/examples/mimxrt1062-evk/build.rs new file mode 100644 index 000000000..e0e0d547e --- /dev/null +++ b/examples/mimxrt1062-evk/build.rs | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | use imxrt_rt::{Family, RuntimeBuilder}; | ||
| 2 | |||
| 3 | fn main() { | ||
| 4 | RuntimeBuilder::from_flexspi(Family::Imxrt1060, 8 * 1024 * 1024) | ||
| 5 | .build() | ||
| 6 | .unwrap(); | ||
| 7 | |||
| 8 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 9 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 10 | // Not link.x, as imxrt-rt needs to do some special things | ||
| 11 | println!("cargo:rustc-link-arg-bins=-Timxrt-link.x"); | ||
| 12 | } | ||
diff --git a/examples/mimxrt1062-evk/src/bin/blinky.rs b/examples/mimxrt1062-evk/src/bin/blinky.rs new file mode 100644 index 000000000..b6d90d94d --- /dev/null +++ b/examples/mimxrt1062-evk/src/bin/blinky.rs | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::info; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_nxp::gpio::{Level, Output}; | ||
| 7 | use embassy_time::Timer; | ||
| 8 | // Must include `embassy_imxrt1062_evk_examples` to ensure the FCB gets linked. | ||
| 9 | use {defmt_rtt as _, embassy_imxrt1062_evk_examples as _, panic_probe as _}; | ||
| 10 | |||
| 11 | #[embassy_executor::main] | ||
| 12 | async fn main(_spawner: Spawner) -> ! { | ||
| 13 | let p = embassy_nxp::init(Default::default()); | ||
| 14 | info!("Hello world!"); | ||
| 15 | |||
| 16 | let led = p.GPIO_AD_B0_08; | ||
| 17 | let mut led = Output::new(led, Level::Low); | ||
| 18 | |||
| 19 | loop { | ||
| 20 | Timer::after_millis(500).await; | ||
| 21 | |||
| 22 | info!("Toggle"); | ||
| 23 | led.toggle(); | ||
| 24 | } | ||
| 25 | } | ||
diff --git a/examples/mimxrt1062-evk/src/bin/button.rs b/examples/mimxrt1062-evk/src/bin/button.rs new file mode 100644 index 000000000..d60fa3dac --- /dev/null +++ b/examples/mimxrt1062-evk/src/bin/button.rs | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::info; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_nxp::gpio::{Input, Level, Output, Pull}; | ||
| 7 | use {defmt_rtt as _, embassy_imxrt1062_evk_examples as _, panic_probe as _}; | ||
| 8 | |||
| 9 | #[embassy_executor::main] | ||
| 10 | async fn main(_spawner: Spawner) -> ! { | ||
| 11 | let p = embassy_nxp::init(Default::default()); | ||
| 12 | info!("Hello world!"); | ||
| 13 | |||
| 14 | // User LED (D8) | ||
| 15 | let led = p.GPIO_AD_B0_08; | ||
| 16 | // User button (SW5) | ||
| 17 | let button = p.WAKEUP; | ||
| 18 | let mut button = Input::new(button, Pull::Up100K); | ||
| 19 | let mut led = Output::new(led, Level::Low); | ||
| 20 | led.set_high(); | ||
| 21 | |||
| 22 | loop { | ||
| 23 | button.wait_for_falling_edge().await; | ||
| 24 | |||
| 25 | info!("Toggled"); | ||
| 26 | led.toggle(); | ||
| 27 | |||
| 28 | // Software debounce. | ||
| 29 | button.wait_for_rising_edge().await; | ||
| 30 | |||
| 31 | // Stabilization. | ||
| 32 | for _ in 0..100_000 { | ||
| 33 | cortex_m::asm::nop(); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
diff --git a/examples/mimxrt1062-evk/src/lib.rs b/examples/mimxrt1062-evk/src/lib.rs new file mode 100644 index 000000000..3f99f9db3 --- /dev/null +++ b/examples/mimxrt1062-evk/src/lib.rs | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | //! FlexSPI configuration block (FCB) for the iMXRT1060-EVK | ||
| 2 | //! | ||
| 3 | //! This uses IS25WP QuadSPI flash. | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | |||
| 7 | use imxrt_boot_gen::flexspi::opcodes::sdr::*; | ||
| 8 | use imxrt_boot_gen::flexspi::{self, FlashPadType, ReadSampleClockSource, SerialClockFrequency, SerialFlashRegion, *}; | ||
| 9 | use imxrt_boot_gen::serial_flash::*; | ||
| 10 | pub use nor::ConfigurationBlock; | ||
| 11 | |||
| 12 | const SEQ_READ: Sequence = SequenceBuilder::new() | ||
| 13 | .instr(Instr::new(CMD, Pads::One, 0xEB)) | ||
| 14 | .instr(Instr::new(RADDR, Pads::Four, 0x18)) | ||
| 15 | .instr(Instr::new(DUMMY, Pads::Four, 0x06)) | ||
| 16 | .instr(Instr::new(READ, Pads::Four, 0x04)) | ||
| 17 | .build(); | ||
| 18 | const SEQ_READ_STATUS: Sequence = SequenceBuilder::new() | ||
| 19 | .instr(Instr::new(CMD, Pads::One, 0x05)) | ||
| 20 | .instr(Instr::new(READ, Pads::One, 0x04)) | ||
| 21 | .build(); | ||
| 22 | const SEQ_WRITE_ENABLE: Sequence = SequenceBuilder::new().instr(Instr::new(CMD, Pads::One, 0x06)).build(); | ||
| 23 | const SEQ_ERASE_SECTOR: Sequence = SequenceBuilder::new() | ||
| 24 | .instr(Instr::new(CMD, Pads::One, 0x20)) | ||
| 25 | .instr(Instr::new(RADDR, Pads::One, 0x18)) | ||
| 26 | .build(); | ||
| 27 | const SEQ_PAGE_PROGRAM: Sequence = SequenceBuilder::new() | ||
| 28 | .instr(Instr::new(CMD, Pads::One, 0x02)) | ||
| 29 | .instr(Instr::new(RADDR, Pads::One, 0x18)) | ||
| 30 | .instr(Instr::new(WRITE, Pads::One, 0x04)) | ||
| 31 | .build(); | ||
| 32 | const SEQ_CHIP_ERASE: Sequence = SequenceBuilder::new().instr(Instr::new(CMD, Pads::One, 0x60)).build(); | ||
| 33 | |||
| 34 | const LUT: LookupTable = LookupTable::new() | ||
| 35 | .command(Command::Read, SEQ_READ) | ||
| 36 | .command(Command::ReadStatus, SEQ_READ_STATUS) | ||
| 37 | .command(Command::WriteEnable, SEQ_WRITE_ENABLE) | ||
| 38 | .command(Command::EraseSector, SEQ_ERASE_SECTOR) | ||
| 39 | .command(Command::PageProgram, SEQ_PAGE_PROGRAM) | ||
| 40 | .command(Command::ChipErase, SEQ_CHIP_ERASE); | ||
| 41 | |||
| 42 | const COMMON_CONFIGURATION_BLOCK: flexspi::ConfigurationBlock = flexspi::ConfigurationBlock::new(LUT) | ||
| 43 | .version(Version::new(1, 4, 0)) | ||
| 44 | .read_sample_clk_src(ReadSampleClockSource::LoopbackFromDQSPad) | ||
| 45 | .cs_hold_time(3) | ||
| 46 | .cs_setup_time(3) | ||
| 47 | .controller_misc_options(0x10) | ||
| 48 | .serial_flash_pad_type(FlashPadType::Quad) | ||
| 49 | .serial_clk_freq(SerialClockFrequency::MHz133) | ||
| 50 | .flash_size(SerialFlashRegion::A1, 8 * 1024 * 1024); | ||
| 51 | |||
| 52 | pub const SERIAL_NOR_CONFIGURATION_BLOCK: nor::ConfigurationBlock = | ||
| 53 | nor::ConfigurationBlock::new(COMMON_CONFIGURATION_BLOCK) | ||
| 54 | .page_size(256) | ||
| 55 | .sector_size(4096) | ||
| 56 | .ip_cmd_serial_clk_freq(nor::SerialClockFrequency::MHz30); | ||
| 57 | |||
| 58 | #[no_mangle] | ||
| 59 | #[cfg_attr(all(target_arch = "arm", target_os = "none"), link_section = ".fcb")] | ||
| 60 | pub static FLEXSPI_CONFIGURATION_BLOCK: nor::ConfigurationBlock = SERIAL_NOR_CONFIGURATION_BLOCK; | ||
