Merge pull request #314 from embassy-rs/example-cleanup-l4

stm32/examples: cleanup L4
This commit is contained in:
Dario Nieuwenhuis 2021-07-24 14:03:42 +02:00 committed by GitHub
commit 495d977b03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 100 additions and 279 deletions

View file

@ -21,7 +21,6 @@ embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "def
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "unstable-pac", "stm32l4s5vi"] }
embassy-extras = {version = "0.1.0", path = "../../embassy-extras" }
stm32l4xx-hal = { version = "0.6.0", features = ["stm32l4x5"] }
defmt = "0.2.0"
defmt-rtt = "0.2.0"

View file

@ -9,35 +9,16 @@
#[path = "../example_common.rs"]
mod example_common;
use defmt::panic;
use embassy::executor::Spawner;
use embassy::time::Delay;
use embassy_stm32::adc::{Adc, Resolution};
use embassy_stm32::{pac, Peripherals};
use example_common::*;
use cortex_m::delay::Delay;
use cortex_m_rt::entry;
use embassy_stm32::adc::{Adc, Resolution};
use embassy_stm32::pac;
use stm32l4xx_hal::prelude::*;
use stm32l4xx_hal::rcc::PllSource;
#[entry]
fn main() -> ! {
info!("Hello World, dude!");
//let pp = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
let pp = stm32l4xx_hal::stm32::Peripherals::take().unwrap();
let mut flash = pp.FLASH.constrain();
let mut rcc = pp.RCC.constrain();
let mut pwr = pp.PWR.constrain(&mut rcc.apb1r1);
let mut delay = Delay::new(cp.SYST, 80_000_000);
// TRY the other clock configuration
// let clocks = rcc.cfgr.freeze(&mut flash.acr);
rcc.cfgr
.sysclk(80.mhz())
.pclk1(80.mhz())
.pclk2(80.mhz())
.pll_source(PllSource::HSI16)
.freeze(&mut flash.acr, &mut pwr);
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
pac::RCC.ccipr().modify(|w| {
@ -48,11 +29,10 @@ fn main() -> ! {
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
pac::RCC.ahb2enr().modify(|w| w.set_adcen(true));
}
let p = embassy_stm32::init(Default::default());
let mut adc = Adc::new(p.ADC1, &mut delay);
let mut adc = Adc::new(p.ADC1, &mut Delay);
//adc.enable_vref();
adc.set_resolution(Resolution::EightBit);
let mut channel = p.PC0;

View file

@ -8,14 +8,16 @@
#[path = "../example_common.rs"]
mod example_common;
use cortex_m_rt::entry;
use defmt::panic;
use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::pac;
use embassy_stm32::{pac, Peripherals};
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[entry]
fn main() -> ! {
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
@ -26,17 +28,12 @@ fn main() -> ! {
});
}
let p = embassy_stm32::init(Default::default());
let mut led = Output::new(p.PB14, Level::High, Speed::Low);
loop {
info!("high");
led.set_high().unwrap();
cortex_m::asm::delay(10_000_000);
info!("low");
Timer::after(Duration::from_millis(300)).await;
led.set_low().unwrap();
cortex_m::asm::delay(10_000_000);
Timer::after(Duration::from_millis(300)).await;
}
}

View file

@ -8,14 +8,15 @@
#[path = "../example_common.rs"]
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::pac;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use defmt::panic;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::{pac, Peripherals};
use embedded_hal::digital::v2::InputPin;
use example_common::*;
#[entry]
fn main() -> ! {
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
@ -26,21 +27,13 @@ fn main() -> ! {
});
}
let p = embassy_stm32::init(Default::default());
let button = Input::new(p.PC13, Pull::Up);
let mut led1 = Output::new(p.PA5, Level::High, Speed::Low);
let mut led2 = Output::new(p.PB14, Level::High, Speed::Low);
loop {
if button.is_high().unwrap() {
info!("high");
led1.set_high().unwrap();
led2.set_low().unwrap();
} else {
info!("low");
led1.set_low().unwrap();
led2.set_high().unwrap();
}
}
}

View file

@ -8,19 +8,25 @@
#[path = "../example_common.rs"]
mod example_common;
use cortex_m_rt::entry;
use embassy::executor::Executor;
use embassy::time::Clock;
use embassy::util::Forever;
use defmt::panic;
use embassy::executor::Spawner;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_stm32::pac;
use embassy_stm32::{pac, Peripherals};
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
use example_common::*;
#[embassy::task]
async fn main_task() {
let p = embassy_stm32::init(Default::default());
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
pac::DBGMCU.cr().modify(|w| {
w.set_dbg_sleep(true);
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
}
let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13);
@ -34,34 +40,3 @@ async fn main_task() {
info!("Released!");
}
}
struct ZeroClock;
impl Clock for ZeroClock {
fn now(&self) -> u64 {
0
}
}
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
unsafe {
pac::DBGMCU.cr().modify(|w| {
w.set_dbg_sleep(true);
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
}
unsafe { embassy::time::set_clock(&ZeroClock) };
let executor = EXECUTOR.put(Executor::new());
executor.run(|spawner| {
unwrap!(spawner.spawn(main_task()));
})
}

View file

@ -9,32 +9,16 @@
#[path = "../example_common.rs"]
mod example_common;
use defmt::panic;
use embassy::executor::Spawner;
use embassy_stm32::dac::{Channel, Dac, Value};
use embassy_stm32::gpio::NoPin;
use embassy_stm32::{pac, Peripherals};
use example_common::*;
use cortex_m_rt::entry;
use embassy_stm32::dac::{Channel, Dac, Value};
use embassy_stm32::pac;
use stm32l4xx_hal::prelude::*;
use stm32l4xx_hal::rcc::PllSource;
#[entry]
fn main() -> ! {
info!("Hello World, dude!");
//let pp = pac::Peripherals::take().unwrap();
let pp = stm32l4xx_hal::stm32::Peripherals::take().unwrap();
let mut flash = pp.FLASH.constrain();
let mut rcc = pp.RCC.constrain();
let mut pwr = pp.PWR.constrain(&mut rcc.apb1r1);
// TRY the other clock configuration
// let clocks = rcc.cfgr.freeze(&mut flash.acr);
rcc.cfgr
.sysclk(80.mhz())
.pclk1(80.mhz())
.pclk2(80.mhz())
.pll_source(PllSource::HSI16)
.freeze(&mut flash.acr, &mut pwr);
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
pac::DBGMCU.cr().modify(|w| {
@ -47,8 +31,6 @@ fn main() -> ! {
});
}
let p = embassy_stm32::init(Default::default());
let mut dac = Dac::new(p.DAC1, p.PA4, NoPin);
loop {

View file

@ -9,19 +9,20 @@
#[path = "../example_common.rs"]
mod example_common;
use cortex_m_rt::entry;
use defmt::panic;
use embassy::executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::pac;
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embassy_stm32::{pac, Peripherals};
use embedded_hal::blocking::spi::Transfer;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[entry]
fn main() -> ! {
info!("Hello World, dude!");
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
pac::DBGMCU.cr().modify(|w| {
@ -31,8 +32,6 @@ fn main() -> ! {
});
}
let p = embassy_stm32::init(Default::default());
let mut spi = Spi::new(
p.SPI3,
p.PC10,

View file

@ -9,21 +9,27 @@
#[path = "../example_common.rs"]
mod example_common;
use cortex_m_rt::entry;
use embassy::executor::Executor;
use embassy::time::Clock;
use embassy::util::Forever;
use embassy_stm32::pac;
use example_common::*;
use embassy_stm32::spi::{Spi, Config};
use embassy_traits::spi::FullDuplex;
use defmt::panic;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embassy_stm32::gpio::{Output, Level, Speed, Input, Pull};
use embedded_hal::digital::v2::{OutputPin, InputPin};
use embassy_stm32::{pac, Peripherals};
use embassy_traits::spi::FullDuplex;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[embassy::task]
async fn main_task() {
let p = embassy_stm32::init(Default::default());
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
pac::DBGMCU.cr().modify(|w| {
w.set_dbg_sleep(true);
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
}
let mut spi = Spi::new(
p.SPI3,
@ -36,7 +42,6 @@ async fn main_task() {
Config::default(),
);
// These are the pins for the Inventek eS-Wifi SPI Wifi Adapter.
let _boot = Output::new(p.PB12, Level::Low, Speed::VeryHigh);
@ -60,49 +65,3 @@ async fn main_task() {
unwrap!(cs.set_high());
info!("xfer {=[u8]:x}", read);
}
struct ZeroClock;
impl Clock for ZeroClock {
fn now(&self) -> u64 {
0
}
}
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
unsafe {
pac::DBGMCU.cr().modify(|w| {
w.set_dbg_sleep(true);
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
pac::RCC.ahb1enr().modify(|w| {
w.set_dmamux1en(true);
w.set_dma1en(true);
w.set_dma2en(true);
});
pac::RCC.ahb2enr().modify(|w| {
w.set_gpioaen(true);
w.set_gpioben(true);
w.set_gpiocen(true);
w.set_gpioden(true);
w.set_gpioeen(true);
w.set_gpiofen(true);
});
}
unsafe { embassy::time::set_clock(&ZeroClock) };
let executor = EXECUTOR.put(Executor::new());
executor.run(|spawner| {
unwrap!(spawner.spawn(main_task()));
})
}

View file

@ -9,18 +9,24 @@
#[path = "../example_common.rs"]
mod example_common;
use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
use cortex_m_rt::entry;
use embassy::executor::Executor;
use embassy::time::Clock;
use embassy::util::Forever;
use defmt::panic;
use embassy::executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::pac;
use embassy_stm32::usart::{Config, Uart};
use embassy_stm32::{pac, Peripherals};
use example_common::*;
#[embassy::task]
async fn main_task() {
let p = embassy_stm32::init(Default::default());
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
pac::DBGMCU.cr().modify(|w| {
w.set_dbg_sleep(true);
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
}
let config = Config::default();
let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config);
@ -34,42 +40,3 @@ async fn main_task() {
usart.bwrite_all(&buf).unwrap();
}
}
struct ZeroClock;
impl Clock for ZeroClock {
fn now(&self) -> u64 {
0
}
}
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
unsafe {
pac::DBGMCU.cr().modify(|w| {
w.set_dbg_sleep(true);
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
pac::RCC.ahb1enr().modify(|w| {
w.set_dma1en(true);
});
pac::RCC.apb1enr1().modify(|w| {
w.set_uart4en(true);
});
}
unsafe { embassy::time::set_clock(&ZeroClock) };
let executor = EXECUTOR.put(Executor::new());
executor.run(|spawner| {
unwrap!(spawner.spawn(main_task()));
})
}

View file

@ -9,46 +9,17 @@
#[path = "../example_common.rs"]
mod example_common;
use core::fmt::Write;
use cortex_m_rt::entry;
use embassy::executor::Executor;
use embassy::time::Clock;
use embassy::util::Forever;
use defmt::panic;
use embassy::executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::pac;
use embassy_stm32::usart::{Config, Uart};
use embassy_stm32::{pac, Peripherals};
use embassy_traits::uart::Write as _;
use example_common::*;
use heapless::String;
#[embassy::task]
async fn main_task() {
let p = embassy_stm32::init(Default::default());
let config = Config::default();
let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, p.DMA1_CH3, NoDma, config);
for n in 0u32.. {
let mut s: String<128> = String::new();
core::write!(&mut s, "Hello DMA World {}!\r\n", n).unwrap();
usart.write(s.as_bytes()).await.ok();
info!("wrote DMA");
}
}
struct ZeroClock;
impl Clock for ZeroClock {
fn now(&self) -> u64 {
0
}
}
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
@ -57,19 +28,18 @@ fn main() -> ! {
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
pac::RCC.ahb1enr().modify(|w| {
w.set_dmamux1en(true);
w.set_dma1en(true);
w.set_dma2en(true);
});
}
unsafe { embassy::time::set_clock(&ZeroClock) };
let config = Config::default();
let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, p.DMA1_CH3, NoDma, config);
let executor = EXECUTOR.put(Executor::new());
for n in 0u32.. {
let mut s: String<128> = String::new();
core::write!(&mut s, "Hello DMA World {}!\r\n", n).unwrap();
executor.run(|spawner| {
unwrap!(spawner.spawn(main_task()));
})
info!("Writing...");
usart.write(s.as_bytes()).await.ok();
info!("wrote DMA");
}
}