stm32f4/examples: add config and linker script so they're runnable.
This commit is contained in:
59
embassy-stm32f4-examples/src/bin/exti.rs
Normal file
59
embassy-stm32f4-examples/src/bin/exti.rs
Normal file
@ -0,0 +1,59 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(trait_alias)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use example_common::{panic, *};
|
||||
|
||||
use cortex_m::singleton;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::gpio::*;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32f4::exti;
|
||||
use embassy_stm32f4::exti::*;
|
||||
use embassy_stm32f4::interrupt;
|
||||
use embassy_stm32f4::serial;
|
||||
use futures::pin_mut;
|
||||
use stm32f4xx_hal::serial::config::Config;
|
||||
use stm32f4xx_hal::stm32;
|
||||
use stm32f4xx_hal::syscfg;
|
||||
use stm32f4xx_hal::{prelude::*, serial::config};
|
||||
|
||||
static EXTI: Forever<exti::ExtiManager> = Forever::new();
|
||||
|
||||
#[task]
|
||||
async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) {
|
||||
let gpioa = dp.GPIOA.split();
|
||||
|
||||
let button = gpioa.pa0.into_pull_up_input();
|
||||
|
||||
let exti = EXTI.put(exti::ExtiManager::new(dp.EXTI, dp.SYSCFG.constrain()));
|
||||
let pin = exti.new_pin(button, interrupt::take!(EXTI0));
|
||||
pin_mut!(pin);
|
||||
|
||||
info!("Starting loop");
|
||||
|
||||
loop {
|
||||
pin.as_mut().wait_for_rising_edge().await;
|
||||
info!("edge detected!");
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let dp = stm32::Peripherals::take().unwrap();
|
||||
let cp = cortex_m::peripheral::Peripherals::take().unwrap();
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
|
||||
executor.spawn(run(dp, cp)).unwrap();
|
||||
|
||||
loop {
|
||||
executor.run();
|
||||
//cortex_m::asm::wfe(); // wfe causes RTT to stop working on stm32
|
||||
}
|
||||
}
|
40
embassy-stm32f4-examples/src/bin/hello.rs
Normal file
40
embassy-stm32f4-examples/src/bin/hello.rs
Normal file
@ -0,0 +1,40 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(trait_alias)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use example_common::{panic, *};
|
||||
|
||||
use cortex_m::singleton;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::uart::Uart;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32f4::interrupt;
|
||||
use embassy_stm32f4::serial;
|
||||
use stm32f4xx_hal::serial::config::Config;
|
||||
use stm32f4xx_hal::stm32;
|
||||
use stm32f4xx_hal::{prelude::*, serial::config};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = stm32f4xx_hal::stm32::Peripherals::take().unwrap();
|
||||
let gpioa = p.GPIOA.split();
|
||||
let gpioc = p.GPIOC.split();
|
||||
|
||||
let mut led = gpioc.pc13.into_push_pull_output();
|
||||
let button = gpioa.pa0.into_pull_up_input();
|
||||
led.set_low().unwrap();
|
||||
|
||||
loop {
|
||||
if button.is_high().unwrap() {
|
||||
led.set_low().unwrap();
|
||||
} else {
|
||||
led.set_high().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
@ -64,6 +64,6 @@ fn main() -> ! {
|
||||
|
||||
loop {
|
||||
executor.run();
|
||||
cortex_m::asm::wfe();
|
||||
//cortex_m::asm::wfe(); // wfe causes RTT to stop working on stm32
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user