aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/mimxrt1062-evk/.cargo/config.toml8
-rw-r--r--examples/mimxrt1062-evk/Cargo.toml29
-rw-r--r--examples/mimxrt1062-evk/build.rs12
-rw-r--r--examples/mimxrt1062-evk/src/bin/blinky.rs25
-rw-r--r--examples/mimxrt1062-evk/src/bin/button.rs36
-rw-r--r--examples/mimxrt1062-evk/src/lib.rs60
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]
2runner = 'probe-rs run --chip MIMXRT1060'
3
4[build]
5target = "thumbv7em-none-eabihf" # Cortex-M7
6
7[env]
8DEFMT_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]
2name = "embassy-imxrt1062-evk-examples"
3version = "0.1.0"
4edition = "2021"
5license = "MIT or Apache-2.0"
6
7[dependencies]
8cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
9cortex-m-rt = "0.7.3"
10defmt = "1.0.1"
11defmt-rtt = "1.0.0"
12
13embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
14embassy-futures = { version = "0.1.1", path = "../../embassy-futures" }
15embassy-nxp = { version = "0.1.0", path = "../../embassy-nxp", features = ["defmt", "mimxrt1062", "unstable-pac", "time-driver-pit"] }
16embassy-time = { version = "0.4", path = "../../embassy-time", features = ["defmt", ] } # "defmt-timestamp-uptime"
17embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
18embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
19embedded-hal-async = "1.0.0"
20
21imxrt-boot-gen = { version = "0.3.4", features = ["imxrt1060"] }
22panic-probe = { version = "1.0.0", features = ["print-defmt"] }
23panic-semihosting = "0.6.0"
24
25[build-dependencies]
26imxrt-rt = { version = "0.1.7", features = ["device"] }
27
28[profile.release]
29debug = 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 @@
1use imxrt_rt::{Family, RuntimeBuilder};
2
3fn 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
4use defmt::info;
5use embassy_executor::Spawner;
6use embassy_nxp::gpio::{Level, Output};
7use embassy_time::Timer;
8// Must include `embassy_imxrt1062_evk_examples` to ensure the FCB gets linked.
9use {defmt_rtt as _, embassy_imxrt1062_evk_examples as _, panic_probe as _};
10
11#[embassy_executor::main]
12async 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
4use defmt::info;
5use embassy_executor::Spawner;
6use embassy_nxp::gpio::{Input, Level, Output, Pull};
7use {defmt_rtt as _, embassy_imxrt1062_evk_examples as _, panic_probe as _};
8
9#[embassy_executor::main]
10async 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
7use imxrt_boot_gen::flexspi::opcodes::sdr::*;
8use imxrt_boot_gen::flexspi::{self, FlashPadType, ReadSampleClockSource, SerialClockFrequency, SerialFlashRegion, *};
9use imxrt_boot_gen::serial_flash::*;
10pub use nor::ConfigurationBlock;
11
12const 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();
18const SEQ_READ_STATUS: Sequence = SequenceBuilder::new()
19 .instr(Instr::new(CMD, Pads::One, 0x05))
20 .instr(Instr::new(READ, Pads::One, 0x04))
21 .build();
22const SEQ_WRITE_ENABLE: Sequence = SequenceBuilder::new().instr(Instr::new(CMD, Pads::One, 0x06)).build();
23const SEQ_ERASE_SECTOR: Sequence = SequenceBuilder::new()
24 .instr(Instr::new(CMD, Pads::One, 0x20))
25 .instr(Instr::new(RADDR, Pads::One, 0x18))
26 .build();
27const 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();
32const SEQ_CHIP_ERASE: Sequence = SequenceBuilder::new().instr(Instr::new(CMD, Pads::One, 0x60)).build();
33
34const 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
42const 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
52pub 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")]
60pub static FLEXSPI_CONFIGURATION_BLOCK: nor::ConfigurationBlock = SERIAL_NOR_CONFIGURATION_BLOCK;