Align flash examples
This commit is contained in:
parent
57d3d4d581
commit
2a49e11cb0
@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
const ADDR: u32 = 0x26000;
|
||||
|
||||
let mut f = Flash::new(p.FLASH);
|
||||
let mut f = Flash::new(p.FLASH).into_regions().bank1_region;
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 8];
|
||||
|
@ -5,7 +5,6 @@
|
||||
use defmt::{info, unwrap};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::flash::Flash;
|
||||
use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
@ -13,6 +12,8 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello Flash!");
|
||||
|
||||
// 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);
|
||||
|
||||
// Sector 5
|
||||
@ -30,19 +31,19 @@ fn test_flash(f: &mut Flash, offset: u32, size: u32) {
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(offset, &mut buf));
|
||||
unwrap!(f.blocking_read(offset, &mut buf));
|
||||
info!("Read: {=[u8]:x}", buf);
|
||||
|
||||
info!("Erasing...");
|
||||
unwrap!(f.erase(offset, offset + size));
|
||||
unwrap!(f.blocking_erase(offset, offset + size));
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(offset, &mut buf));
|
||||
unwrap!(f.blocking_read(offset, &mut buf));
|
||||
info!("Read after erase: {=[u8]:x}", buf);
|
||||
|
||||
info!("Writing...");
|
||||
unwrap!(f.write(
|
||||
unwrap!(f.blocking_write(
|
||||
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,
|
||||
@ -52,7 +53,7 @@ fn test_flash(f: &mut Flash, offset: u32, size: u32) {
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(offset, &mut buf));
|
||||
unwrap!(f.blocking_read(offset, &mut buf));
|
||||
info!("Read: {=[u8]:x}", buf);
|
||||
assert_eq!(
|
||||
&buf[..],
|
||||
|
@ -14,12 +14,12 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello Flash!");
|
||||
|
||||
const ADDR: u32 = 0x8_0000;
|
||||
const ADDR: u32 = 0x8_0000; // This is the offset into the third region, the absolute address is 4x32K + 128K + 0x8_0000.
|
||||
|
||||
// wait a bit before accessing the flash
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
let mut f = Flash::new(p.FLASH);
|
||||
let mut f = Flash::new(p.FLASH).into_regions().bank1_region3;
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
|
@ -14,12 +14,12 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello Flash!");
|
||||
|
||||
const ADDR: u32 = 0x08_0000;
|
||||
const ADDR: u32 = 0; // This is the offset into bank 2, the absolute address is 0x8_0000
|
||||
|
||||
// wait a bit before accessing the flash
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
let mut f = Flash::new(p.FLASH);
|
||||
let mut f = Flash::new(p.FLASH).into_regions().bank2_region;
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
|
@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
const ADDR: u32 = 0x26000;
|
||||
|
||||
let mut f = Flash::new(p.FLASH);
|
||||
let mut f = Flash::new(p.FLASH).into_regions().bank1_region;
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 8];
|
||||
|
@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
const ADDR: u32 = 0x26000;
|
||||
|
||||
let mut f = Flash::new(p.FLASH);
|
||||
let mut f = Flash::new(p.FLASH).into_regions().bank1_region;
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 8];
|
||||
|
@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
const ADDR: u32 = 0x36000;
|
||||
|
||||
let mut f = Flash::new(p.FLASH);
|
||||
let mut f = Flash::new(p.FLASH).into_regions().bank1_region;
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 8];
|
||||
|
Loading…
Reference in New Issue
Block a user