Compare commits
3 commits
de588fbb92
...
8616e14d29
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8616e14d29 | ||
|
|
b08e04eaa5 | ||
|
|
1892056ea8 |
3 changed files with 42 additions and 62 deletions
|
|
@ -11,6 +11,7 @@ default-run = "treatbot-5k"
|
|||
[[bin]]
|
||||
name = "treatbot-5k"
|
||||
test = false
|
||||
bench = false
|
||||
|
||||
[lib]
|
||||
harness = false
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ fn panic() -> ! {
|
|||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||
/// with status code 0.
|
||||
pub fn exit() -> ! {
|
||||
defmt::info!("goodbye");
|
||||
semihosting::process::exit(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
102
src/main.rs
102
src/main.rs
|
|
@ -1,89 +1,67 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use defmt::unwrap;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::flash::{Flash, InterruptHandler};
|
||||
use embassy_stm32::gpio::{AnyPin, Level, Output, Speed};
|
||||
use embassy_stm32::{bind_interrupts, Peri};
|
||||
use embassy_stm32::{
|
||||
adc::{Adc, SampleTime},
|
||||
gpio::{AnyPin, Level, Output, Speed},
|
||||
peripherals::{ADC1, PA0},
|
||||
Config, Peri,
|
||||
};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
FLASH => InterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello Flash!");
|
||||
let mut config = Config::default();
|
||||
|
||||
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())));
|
||||
|
||||
// let mut f = Flash::new(p.FLASH, Irqs);
|
||||
// // 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;
|
||||
Timer::after_secs(20).await;
|
||||
treatbot_5k::exit()
|
||||
}
|
||||
|
||||
//treatbot_5k::exit()
|
||||
#[embassy_executor::task]
|
||||
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]
|
||||
async fn blinky(p: Peri<'static, AnyPin>) {
|
||||
let mut led = Output::new(p, Level::High, Speed::Low);
|
||||
|
||||
led.set_low();
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
led.set_high();
|
||||
Timer::after_millis(300).await;
|
||||
|
||||
info!("low");
|
||||
led.set_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();
|
||||
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