Compare commits
No commits in common. "8616e14d29d439fa2eb9bd78fee033b53c73d96d" and "de588fbb927a71d6309e5ab6e0340a879f9135e5" have entirely different histories.
8616e14d29
...
de588fbb92
3 changed files with 62 additions and 42 deletions
|
|
@ -11,7 +11,6 @@ default-run = "treatbot-5k"
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "treatbot-5k"
|
name = "treatbot-5k"
|
||||||
test = false
|
test = false
|
||||||
bench = false
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
harness = false
|
harness = false
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ fn panic() -> ! {
|
||||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||||
/// with status code 0.
|
/// with status code 0.
|
||||||
pub fn exit() -> ! {
|
pub fn exit() -> ! {
|
||||||
defmt::info!("goodbye");
|
|
||||||
semihosting::process::exit(0);
|
semihosting::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
102
src/main.rs
102
src/main.rs
|
|
@ -1,67 +1,89 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use defmt::unwrap;
|
use defmt::{info, unwrap};
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::{
|
use embassy_stm32::flash::{Flash, InterruptHandler};
|
||||||
adc::{Adc, SampleTime},
|
use embassy_stm32::gpio::{AnyPin, Level, Output, Speed};
|
||||||
gpio::{AnyPin, Level, Output, Speed},
|
use embassy_stm32::{bind_interrupts, Peri};
|
||||||
peripherals::{ADC1, PA0},
|
|
||||||
Config, Peri,
|
|
||||||
};
|
|
||||||
use embassy_time::Timer;
|
use embassy_time::Timer;
|
||||||
use {defmt_rtt as _, panic_probe as _};
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
bind_interrupts!(struct Irqs {
|
||||||
|
FLASH => InterruptHandler;
|
||||||
|
});
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(spawner: Spawner) {
|
async fn main(spawner: Spawner) {
|
||||||
let mut config = Config::default();
|
let p = embassy_stm32::init(Default::default());
|
||||||
|
info!("Hello Flash!");
|
||||||
config.rcc.mux.adc12sel = embassy_stm32::rcc::mux::Adcsel::SYS;
|
|
||||||
|
|
||||||
let p = embassy_stm32::init(config);
|
|
||||||
|
|
||||||
let a = Adc::new(p.ADC1, Default::default());
|
|
||||||
let channel = p.PA0.into();
|
|
||||||
spawner.spawn(unwrap!(read_adc1_pa0(a, channel)));
|
|
||||||
|
|
||||||
|
// Led should blink uninterrupted during erase operation
|
||||||
spawner.spawn(unwrap!(blinky(p.PA5.into())));
|
spawner.spawn(unwrap!(blinky(p.PA5.into())));
|
||||||
|
|
||||||
Timer::after_secs(20).await;
|
// let mut f = Flash::new(p.FLASH, Irqs);
|
||||||
treatbot_5k::exit()
|
// // Test on bank 2 so the CPU doesn't stall (code runs from bank 1).
|
||||||
}
|
// // G474RE in dual-bank mode: bank 2 starts at 256KB offset.
|
||||||
|
// // Erase 4KB (2 pages at 2KB each in dual-bank mode).
|
||||||
|
// test_flash(&mut f, 256 * 1024, 4 * 1024).await;
|
||||||
|
|
||||||
#[embassy_executor::task]
|
//treatbot_5k::exit()
|
||||||
async fn read_adc1_pa0(mut a: Adc<'static, ADC1>, mut channel: Peri<'static, PA0>) {
|
|
||||||
loop {
|
|
||||||
let val = a.blocking_read(&mut channel, SampleTime::CYCLES12_5);
|
|
||||||
defmt::info!("read {}", val);
|
|
||||||
Timer::after_secs(1).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
async fn blinky(p: Peri<'static, AnyPin>) {
|
async fn blinky(p: Peri<'static, AnyPin>) {
|
||||||
let mut led = Output::new(p, Level::High, Speed::Low);
|
let mut led = Output::new(p, Level::High, Speed::Low);
|
||||||
|
|
||||||
led.set_low();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
info!("high");
|
||||||
led.set_high();
|
led.set_high();
|
||||||
Timer::after_millis(300).await;
|
Timer::after_millis(300).await;
|
||||||
|
|
||||||
led.set_low();
|
info!("low");
|
||||||
Timer::after_millis(300).await;
|
|
||||||
|
|
||||||
led.set_high();
|
|
||||||
Timer::after_millis(300).await;
|
|
||||||
|
|
||||||
led.set_low();
|
|
||||||
Timer::after_millis(300).await;
|
|
||||||
|
|
||||||
led.set_high();
|
|
||||||
Timer::after_millis(600).await;
|
|
||||||
|
|
||||||
led.set_low();
|
led.set_low();
|
||||||
Timer::after_millis(300).await;
|
Timer::after_millis(300).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn _test_flash(f: &mut Flash<'_>, offset: u32, size: u32) {
|
||||||
|
info!("Testing offset: {=u32:#X}, size: {=u32:#X}", offset, size);
|
||||||
|
|
||||||
|
info!("Reading...");
|
||||||
|
let mut buf = [0u8; 32];
|
||||||
|
unwrap!(f.blocking_read(offset, &mut buf));
|
||||||
|
info!("Read: {=[u8]:x}", buf);
|
||||||
|
|
||||||
|
info!("Erasing...");
|
||||||
|
unwrap!(f.erase(offset, offset + size).await);
|
||||||
|
|
||||||
|
info!("Reading...");
|
||||||
|
let mut buf = [0u8; 32];
|
||||||
|
unwrap!(f.blocking_read(offset, &mut buf));
|
||||||
|
info!("Read after erase: {=[u8]:x}", buf);
|
||||||
|
|
||||||
|
info!("Writing...");
|
||||||
|
unwrap!(
|
||||||
|
f.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, 30, 31, 32
|
||||||
|
]
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
);
|
||||||
|
|
||||||
|
info!("Reading...");
|
||||||
|
let mut buf = [0u8; 32];
|
||||||
|
unwrap!(f.blocking_read(offset, &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
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
info!("Flash async test passed!");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue