From 6d56f772e11eaae7495e08ba55d9c98d11e0ac09 Mon Sep 17 00:00:00 2001 From: Matous Hybl Date: Tue, 3 May 2022 16:16:37 +0200 Subject: Add F7 flash and bootloader support --- examples/stm32f7/src/bin/flash.rs | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 examples/stm32f7/src/bin/flash.rs (limited to 'examples/stm32f7/src') diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs new file mode 100644 index 000000000..9eb8e4b94 --- /dev/null +++ b/examples/stm32f7/src/bin/flash.rs @@ -0,0 +1,59 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::{info, unwrap}; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32::flash::Flash; +use embassy_stm32::Peripherals; +use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; + +use defmt_rtt as _; // global logger +use panic_probe as _; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + info!("Hello Flash!"); + + const ADDR: u32 = 0x8_0000; + + // wait a bit before accessing the flash + Timer::after(Duration::from_millis(300)).await; + + let mut f = Flash::unlock(p.FLASH); + + info!("Reading..."); + let mut buf = [0u8; 32]; + unwrap!(f.read(ADDR, &mut buf)); + info!("Read: {=[u8]:x}", buf); + + info!("Erasing..."); + unwrap!(f.erase(ADDR, ADDR + 256 * 1024)); + + info!("Reading..."); + let mut buf = [0u8; 32]; + unwrap!(f.read(ADDR, &mut buf)); + info!("Read after erase: {=[u8]:x}", buf); + + info!("Writing..."); + unwrap!(f.write( + ADDR, + &[ + 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 + ] + )); + + info!("Reading..."); + let mut buf = [0u8; 32]; + unwrap!(f.read(ADDR, &mut buf)); + info!("Read: {=[u8]:x}", buf); + assert_eq!( + &buf[..], + &[ + 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 + ] + ); +} -- cgit From 931a137f8c5a760c2e06c437c98d14eff3e3a587 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 4 May 2022 20:48:37 +0200 Subject: Replace embassy::io with embedded_io. --- examples/stm32f7/src/bin/eth.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'examples/stm32f7/src') diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index 33e41de9c..dca9338b2 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -5,12 +5,10 @@ use cortex_m_rt::entry; use defmt::*; use embassy::executor::{Executor, Spawner}; -use embassy::io::AsyncWriteExt; use embassy::time::{Duration, Timer}; use embassy::util::Forever; -use embassy_net::{ - Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket, -}; +use embassy_net::tcp::TcpSocket; +use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator}; use embassy_stm32::eth::generic_smi::GenericSMI; use embassy_stm32::eth::{Ethernet, State}; use embassy_stm32::interrupt; @@ -19,6 +17,7 @@ use embassy_stm32::peripherals::RNG; use embassy_stm32::rng::Rng; use embassy_stm32::time::U32Ext; use embassy_stm32::Config; +use embedded_io::asynch::Write; use heapless::Vec; use defmt_rtt as _; // global logger -- cgit