diff options
| author | xoviat <[email protected]> | 2021-01-04 12:52:00 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2021-01-04 12:52:00 -0600 |
| commit | f3676e1eabc4f3079003d8a006d45db7d3afc742 (patch) | |
| tree | a148703627ee398e49fa37b8bc160e5b8fe9a794 /embassy-stm32f4-examples | |
| parent | be541b94aaac92049a9283a44e715322a7653fcf (diff) | |
rename examples
Diffstat (limited to 'embassy-stm32f4-examples')
| -rw-r--r-- | embassy-stm32f4-examples/Cargo.toml | 39 | ||||
| -rw-r--r-- | embassy-stm32f4-examples/src/serial.rs | 64 |
2 files changed, 103 insertions, 0 deletions
diff --git a/embassy-stm32f4-examples/Cargo.toml b/embassy-stm32f4-examples/Cargo.toml new file mode 100644 index 000000000..6502a77a5 --- /dev/null +++ b/embassy-stm32f4-examples/Cargo.toml | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-stm32f4-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | |||
| 7 | [features] | ||
| 8 | default = [ | ||
| 9 | "defmt-default", | ||
| 10 | ] | ||
| 11 | defmt-default = [] | ||
| 12 | defmt-trace = [] | ||
| 13 | defmt-debug = [] | ||
| 14 | defmt-info = [] | ||
| 15 | defmt-warn = [] | ||
| 16 | defmt-error = [] | ||
| 17 | |||
| 18 | |||
| 19 | [dependencies] | ||
| 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } | ||
| 21 | embassy-stm32f4 = { version = "*", path = "../embassy-stm32f4", features = ["stm32f405"] } | ||
| 22 | |||
| 23 | defmt = "0.1.3" | ||
| 24 | defmt-rtt = "0.1.0" | ||
| 25 | |||
| 26 | cortex-m = { version = "0.6.3" } | ||
| 27 | cortex-m-rt = "0.6.13" | ||
| 28 | embedded-hal = { version = "0.2.4" } | ||
| 29 | panic-probe = "0.1.0" | ||
| 30 | stm32f4xx-hal = { version = "0.8.3", features = ["rt", "stm32f405"], git = "https://github.com/stm32-rs/stm32f4xx-hal.git"} | ||
| 31 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } | ||
| 32 | cortex-m-rtic = "0.5" | ||
| 33 | rtt-target = { version = "0.3", features = ["cortex-m"] } | ||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | [[bin]] | ||
| 38 | name = "serial" | ||
| 39 | path = "src/serial.rs" \ No newline at end of file | ||
diff --git a/embassy-stm32f4-examples/src/serial.rs b/embassy-stm32f4-examples/src/serial.rs new file mode 100644 index 000000000..6c757dd2f --- /dev/null +++ b/embassy-stm32f4-examples/src/serial.rs | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | |||
| 6 | // extern crate panic_halt; | ||
| 7 | |||
| 8 | use cortex_m::singleton; | ||
| 9 | use cortex_m_rt::entry; | ||
| 10 | use embassy::executor::{task, Executor}; | ||
| 11 | use embassy::util::Forever; | ||
| 12 | use embassy_stm32f4::interrupt; | ||
| 13 | use embassy_stm32f4::serial; | ||
| 14 | use stm32f4xx_hal::stm32; | ||
| 15 | use stm32f4xx_hal::{prelude::*, serial::config}; | ||
| 16 | |||
| 17 | #[task] | ||
| 18 | async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) { | ||
| 19 | // https://gist.github.com/thalesfragoso/a07340c5df6eee3b04c42fdc69ecdcb1 | ||
| 20 | let gpioa = dp.GPIOA.split(); | ||
| 21 | let rcc = dp.RCC.constrain(); | ||
| 22 | |||
| 23 | let clocks = rcc | ||
| 24 | .cfgr | ||
| 25 | .use_hse(16.mhz()) | ||
| 26 | .sysclk(48.mhz()) | ||
| 27 | .pclk1(24.mhz()) | ||
| 28 | .freeze(); | ||
| 29 | |||
| 30 | let mut serial = serial::Serial::new( | ||
| 31 | gpioa.pa9.into_alternate_af7(), | ||
| 32 | gpioa.pa10.into_alternate_af7(), | ||
| 33 | interrupt::take!(DMA2_STREAM2), | ||
| 34 | interrupt::take!(DMA2_STREAM7), | ||
| 35 | interrupt::take!(USART1), | ||
| 36 | dp.DMA2, | ||
| 37 | dp.USART1, | ||
| 38 | config::Parity::ParityNone, | ||
| 39 | 9600.bps(), | ||
| 40 | clocks, | ||
| 41 | ); | ||
| 42 | |||
| 43 | let buf = singleton!(: [u8; 30] = [0; 30]).unwrap(); | ||
| 44 | |||
| 45 | buf[5] = 0x01; | ||
| 46 | |||
| 47 | serial.send(buf).await; | ||
| 48 | } | ||
| 49 | |||
| 50 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 51 | |||
| 52 | #[entry] | ||
| 53 | fn main() -> ! { | ||
| 54 | let dp = stm32::Peripherals::take().unwrap(); | ||
| 55 | let cp = cortex_m::peripheral::Peripherals::take().unwrap(); | ||
| 56 | |||
| 57 | let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev)); | ||
| 58 | executor.spawn(run(dp, cp)); | ||
| 59 | |||
| 60 | loop { | ||
| 61 | executor.run(); | ||
| 62 | cortex_m::asm::wfe(); | ||
| 63 | } | ||
| 64 | } | ||
