aboutsummaryrefslogtreecommitdiff
path: root/imxrt1170evk/examples/smoke.rs
blob: 7a4f1c13d4f42d20a3b6cbf439d7d9f8cd782c9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![no_main]
#![no_std]

use defmt_rtt as _;
use imxrt1170evk::{self, Algorithm};
use panic_probe as _;

const LAST_SECTOR: usize = (128 * 1024 * 1024 / 8) - 4096;

#[imxrt_rt::entry]
fn main() -> ! {
    for _ in 0..5 {
        let mut is25wp = Algorithm::initialize();

        let mut sector = [0_u8; 4096];
        is25wp.flash_read(0x400, &mut sector[..4]);
        if 0x42464346 != u32::from_le_bytes(sector[..4].try_into().unwrap()) {
            defmt::warn!("No FCB found.");
        }

        is25wp.flash_erase_sector(LAST_SECTOR + 256);

        sector.fill(0);
        is25wp.flash_write(LAST_SECTOR, &sector);

        sector.fill(u8::MAX);
        is25wp.flash_read(LAST_SECTOR, &mut sector);
        defmt::assert!(sector.iter().all(|byte| *byte == 0));

        is25wp.flash_erase_sector(LAST_SECTOR + 123);

        is25wp.flash_read(LAST_SECTOR, &mut sector);
        defmt::assert!(sector.iter().all(|byte| *byte == u8::MAX));
    }
    defmt::println!("Pass");
    loop {}
}