diff options
| author | Ulf Lilleengen <[email protected]> | 2021-12-10 12:27:44 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2021-12-10 12:27:44 +0100 |
| commit | e93f2679b1edbedd83e09fbc3b7a07dbf1ef80a4 (patch) | |
| tree | aff850c0df6739881abe25171509694f9e0ac962 | |
| parent | b48fcd9229b40800cc96ff3157d8b36057dc2047 (diff) | |
More content
| -rw-r--r-- | docs/modules/ROOT/pages/basic_application.adoc | 15 | ||||
| -rw-r--r-- | docs/modules/ROOT/pages/stm32.adoc | 23 | ||||
| -rw-r--r-- | examples/nrf/src/bin/blinky.rs | 19 |
3 files changed, 46 insertions, 11 deletions
diff --git a/docs/modules/ROOT/pages/basic_application.adoc b/docs/modules/ROOT/pages/basic_application.adoc index d56cb5e1d..53aaa3d7d 100644 --- a/docs/modules/ROOT/pages/basic_application.adoc +++ b/docs/modules/ROOT/pages/basic_application.adoc | |||
| @@ -3,8 +3,6 @@ | |||
| 3 | So you've got one of the xref:examples.adoc[examples] running, but what now? Let's go through a simple Embassy application for the nRF52 DK to understand it better. | 3 | So you've got one of the xref:examples.adoc[examples] running, but what now? Let's go through a simple Embassy application for the nRF52 DK to understand it better. |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | == The Cargo.toml | ||
| 7 | |||
| 8 | == The main | 6 | == The main |
| 9 | 7 | ||
| 10 | === Rust Nightly | 8 | === Rust Nightly |
| @@ -73,3 +71,16 @@ What happens when the `blinker` task have been spawned and main returns? Well, t | |||
| 73 | . Runs the executor spawning the main task | 71 | . Runs the executor spawning the main task |
| 74 | 72 | ||
| 75 | There is also a way to run the executor without using the macro, in which case you have to create the `Executor` instance yourself. | 73 | There is also a way to run the executor without using the macro, in which case you have to create the `Executor` instance yourself. |
| 74 | |||
| 75 | == The Cargo.toml | ||
| 76 | |||
| 77 | The project definition needs to contain the embassy dependencies: | ||
| 78 | |||
| 79 | [source,toml] | ||
| 80 | ---- | ||
| 81 | include::example$examples/nrf/Cargo.toml[lines="9..11"] | ||
| 82 | ---- | ||
| 83 | |||
| 84 | Depending on your microcontroller, you may need to replace `embassy-nrf` with something else (`embassy-stm32` for STM32. Remember to update feature flags as well). | ||
| 85 | |||
| 86 | In this particular case, the nrf52840 chip is selected, and the RTC1 peripheral is used as the time driver. | ||
diff --git a/docs/modules/ROOT/pages/stm32.adoc b/docs/modules/ROOT/pages/stm32.adoc index 328f69e2a..3d1fbfc8f 100644 --- a/docs/modules/ROOT/pages/stm32.adoc +++ b/docs/modules/ROOT/pages/stm32.adoc | |||
| @@ -1,3 +1,24 @@ | |||
| 1 | = Embassy STM32 HAL | 1 | = Embassy STM32 HAL |
| 2 | 2 | ||
| 3 | TODO | 3 | The link:https://github.com/embassy-rs/embassy/tree/master/embassy-stm32[Embassy STM32 HAL] is based on the `stm32-metapac` project. |
| 4 | |||
| 5 | == The infinite variant problem | ||
| 6 | |||
| 7 | STM32 microcontrollers comes in many families and flavors, and supporting all of them is a big undertaking. Embassy has taken advantage of the fact | ||
| 8 | that the STM32 peripheral versions are shared across chip families. Instead of re-implementing the SPI | ||
| 9 | peripheral for every STM32 chip family, embassy have a single SPI implementation that depends on | ||
| 10 | code-generated register types that are identical for STM32 families with the same version of a given peripheral. | ||
| 11 | |||
| 12 | === The metapac | ||
| 13 | |||
| 14 | The `stm32-metapac` module uses pre-generated chip and register definitions for STM32 chip families to generate register types. This is done at compile time based on Cargo feataure flags. | ||
| 15 | |||
| 16 | The chip and register definitions are located in a separate module, `stm32-data`, which is modified whenever a bug is found in the definitions, or when adding support for new chip families. | ||
| 17 | |||
| 18 | === The HAL | ||
| 19 | |||
| 20 | The `embassy-stm32` module contains the HAL implementation for all STM32 families. The implementation uses automatically derived feature flags to support the correct version of a given peripheral for a given chip family. | ||
| 21 | |||
| 22 | == Timer driver | ||
| 23 | |||
| 24 | The STM32 timer driver operates at 32768 Hz by default. | ||
diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs index a12fe58ff..3a1440684 100644 --- a/examples/nrf/src/bin/blinky.rs +++ b/examples/nrf/src/bin/blinky.rs | |||
| @@ -8,18 +8,21 @@ mod example_common; | |||
| 8 | use defmt::unwrap; | 8 | use defmt::unwrap; |
| 9 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 10 | use embassy::time::{Duration, Timer}; | 10 | use embassy::time::{Duration, Timer}; |
| 11 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 11 | use embassy_nrf::{Peripherals, peripherals::P0_13, gpio::{Level, Output, OutputDrive}; |
| 12 | use embassy_nrf::Peripherals; | ||
| 13 | use embedded_hal::digital::v2::OutputPin; | 12 | use embedded_hal::digital::v2::OutputPin; |
| 14 | 13 | ||
| 15 | #[embassy::main] | 14 | #[embassh::task] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 15 | async fn blinker(led: Output<'static, P0_13>, interval: Duration) { |
| 17 | let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); | ||
| 18 | |||
| 19 | loop { | 16 | loop { |
| 20 | unwrap!(led.set_high()); | 17 | unwrap!(led.set_high()); |
| 21 | Timer::after(Duration::from_millis(300)).await; | 18 | Timer::after(interval).await; |
| 22 | unwrap!(led.set_low()); | 19 | unwrap!(led.set_low()); |
| 23 | Timer::after(Duration::from_millis(300)).await; | 20 | Timer::after(interval).await; |
| 24 | } | 21 | } |
| 25 | } | 22 | } |
| 23 | |||
| 24 | #[embassy::main] | ||
| 25 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 26 | let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); | ||
| 27 | unwrap!(spawner.spawn(blinker(led, Duration::from_millis(300)))); | ||
| 28 | } | ||
