Align examples

This commit is contained in:
Rasmus Melchior Jacobsen
2023-05-24 12:41:52 +02:00
parent 0e90e98e9b
commit 7477785bbb
8 changed files with 100 additions and 25 deletions

View File

@ -4,7 +4,7 @@
use defmt::{info, unwrap};
use embassy_executor::Spawner;
use embassy_stm32::flash::Flash;
use embassy_stm32::{flash::Flash, interrupt};
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -14,7 +14,7 @@ async fn main(_spawner: Spawner) {
// Once can also call `into_regions()` to get access to NorFlash implementations
// for each of the unique characteristics.
let mut f = Flash::new(p.FLASH);
let mut f = Flash::new(p.FLASH, interrupt::take!(FLASH));
// Sector 5
test_flash(&mut f, 128 * 1024, 128 * 1024);
@ -31,19 +31,19 @@ fn test_flash(f: &mut Flash, offset: u32, size: u32) {
info!("Reading...");
let mut buf = [0u8; 32];
unwrap!(f.blocking_read(offset, &mut buf));
unwrap!(f.read(offset, &mut buf));
info!("Read: {=[u8]:x}", buf);
info!("Erasing...");
unwrap!(f.blocking_erase(offset, offset + size));
unwrap!(f.erase_blocking(offset, offset + size));
info!("Reading...");
let mut buf = [0u8; 32];
unwrap!(f.blocking_read(offset, &mut buf));
unwrap!(f.read(offset, &mut buf));
info!("Read after erase: {=[u8]:x}", buf);
info!("Writing...");
unwrap!(f.blocking_write(
unwrap!(f.write_blocking(
offset,
&[
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,
@ -53,7 +53,7 @@ fn test_flash(f: &mut Flash, offset: u32, size: u32) {
info!("Reading...");
let mut buf = [0u8; 32];
unwrap!(f.blocking_read(offset, &mut buf));
unwrap!(f.read(offset, &mut buf));
info!("Read: {=[u8]:x}", buf);
assert_eq!(
&buf[..],