diff options
| author | Henrik Alsér <[email protected]> | 2022-05-07 09:47:29 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-07 09:47:29 +0200 |
| commit | 1ca5475010a1cae6ebc55a27948ca4320decd5cd (patch) | |
| tree | 2484384d601823b4dfe96c2bc4bf2d260b34c5f1 /examples | |
| parent | 108a98136096f8b530266aa6687bdbbed4a6a382 (diff) | |
| parent | a4bf190f2f0ce28a298626de6de1c8059269cedc (diff) | |
Merge branch 'embassy-rs:master' into qdec
Diffstat (limited to 'examples')
48 files changed, 806 insertions, 363 deletions
diff --git a/examples/boot/stm32f3/.cargo/config.toml b/examples/boot/stm32f3/.cargo/config.toml new file mode 100644 index 000000000..eb8a8b335 --- /dev/null +++ b/examples/boot/stm32f3/.cargo/config.toml | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip STM32F303VCTx" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabihf" | ||
diff --git a/examples/boot/stm32f3/Cargo.toml b/examples/boot/stm32f3/Cargo.toml new file mode 100644 index 000000000..d4ca600f8 --- /dev/null +++ b/examples/boot/stm32f3/Cargo.toml | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Ulf Lilleengen <[email protected]>"] | ||
| 3 | edition = "2021" | ||
| 4 | name = "embassy-boot-stm32f3-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly"] } | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } | ||
| 10 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } | ||
| 11 | embassy-traits = { version = "0.1.0", path = "../../../embassy-traits" } | ||
| 12 | |||
| 13 | defmt = { version = "0.3", optional = true } | ||
| 14 | defmt-rtt = { version = "0.3", optional = true } | ||
| 15 | panic-reset = { version = "0.1.1" } | ||
| 16 | embedded-hal = { version = "0.2.6" } | ||
| 17 | |||
| 18 | cortex-m = "0.7.3" | ||
| 19 | cortex-m-rt = "0.7.0" | ||
| 20 | |||
| 21 | [features] | ||
| 22 | defmt = [ | ||
| 23 | "dep:defmt", | ||
| 24 | "embassy-stm32/defmt", | ||
| 25 | "embassy-boot-stm32/defmt", | ||
| 26 | ] | ||
diff --git a/examples/boot/stm32f3/README.md b/examples/boot/stm32f3/README.md new file mode 100644 index 000000000..e92ffb692 --- /dev/null +++ b/examples/boot/stm32f3/README.md | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | # Examples using bootloader | ||
| 2 | |||
| 3 | Example for STM32F3 demonstrating the bootloader. The example consists of application binaries, 'a' | ||
| 4 | which allows you to press a button to start the DFU process, and 'b' which is the updated | ||
| 5 | application. | ||
| 6 | |||
| 7 | |||
| 8 | ## Prerequisites | ||
| 9 | |||
| 10 | * `cargo-binutils` | ||
| 11 | * `cargo-flash` | ||
| 12 | * `embassy-boot-stm32` | ||
| 13 | |||
| 14 | ## Usage | ||
| 15 | |||
| 16 | ``` | ||
| 17 | # Flash bootloader | ||
| 18 | cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f303re --chip STM32F303RETx | ||
| 19 | # Build 'b' | ||
| 20 | cargo build --release --bin b | ||
| 21 | # Generate binary for 'b' | ||
| 22 | cargo objcopy --release --bin b -- -O binary b.bin | ||
| 23 | ``` | ||
| 24 | |||
| 25 | # Flash `a` (which includes b.bin) | ||
| 26 | |||
| 27 | ``` | ||
| 28 | cargo flash --release --bin a --chip STM32F303RETx | ||
| 29 | ``` | ||
diff --git a/examples/boot/stm32f3/build.rs b/examples/boot/stm32f3/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/stm32f3/build.rs | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | if env::var("CARGO_FEATURE_DEFMT").is_ok() { | ||
| 35 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 36 | } | ||
| 37 | } | ||
diff --git a/examples/boot/stm32f3/memory.x b/examples/boot/stm32f3/memory.x new file mode 100644 index 000000000..14b2a2c9f --- /dev/null +++ b/examples/boot/stm32f3/memory.x | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | ||
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | ||
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | ||
| 13 | |||
| 14 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); | ||
| 15 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); | ||
diff --git a/examples/boot/stm32f3/src/bin/a.rs b/examples/boot/stm32f3/src/bin/a.rs new file mode 100644 index 000000000..db9262f43 --- /dev/null +++ b/examples/boot/stm32f3/src/bin/a.rs | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use embassy_boot_stm32::FirmwareUpdater; | ||
| 6 | use embassy_stm32::exti::ExtiInput; | ||
| 7 | use embassy_stm32::flash::Flash; | ||
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | ||
| 9 | use embassy_stm32::Peripherals; | ||
| 10 | use embassy_traits::adapter::BlockingAsync; | ||
| 11 | use panic_reset as _; | ||
| 12 | |||
| 13 | #[cfg(feature = "defmt-rtt")] | ||
| 14 | use defmt_rtt::*; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | ||
| 17 | |||
| 18 | #[embassy::main] | ||
| 19 | async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | ||
| 20 | let flash = Flash::unlock(p.FLASH); | ||
| 21 | let mut flash = BlockingAsync::new(flash); | ||
| 22 | |||
| 23 | let button = Input::new(p.PC13, Pull::Up); | ||
| 24 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 25 | |||
| 26 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); | ||
| 27 | led.set_high(); | ||
| 28 | |||
| 29 | let mut updater = FirmwareUpdater::default(); | ||
| 30 | button.wait_for_falling_edge().await; | ||
| 31 | let mut offset = 0; | ||
| 32 | for chunk in APP_B.chunks(2048) { | ||
| 33 | let mut buf: [u8; 2048] = [0; 2048]; | ||
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | ||
| 35 | updater | ||
| 36 | .write_firmware(offset, &buf, &mut flash, 2048) | ||
| 37 | .await | ||
| 38 | .unwrap(); | ||
| 39 | offset += chunk.len(); | ||
| 40 | } | ||
| 41 | updater.update(&mut flash).await.unwrap(); | ||
| 42 | led.set_low(); | ||
| 43 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 44 | } | ||
diff --git a/examples/boot/stm32f3/src/bin/b.rs b/examples/boot/stm32f3/src/bin/b.rs new file mode 100644 index 000000000..814275988 --- /dev/null +++ b/examples/boot/stm32f3/src/bin/b.rs | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use embassy::executor::Spawner; | ||
| 6 | use embassy::time::{Duration, Timer}; | ||
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 8 | use embassy_stm32::Peripherals; | ||
| 9 | use panic_reset as _; | ||
| 10 | |||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | let mut led = Output::new(p.PA5, Level::High, Speed::Low); | ||
| 17 | |||
| 18 | loop { | ||
| 19 | led.set_high(); | ||
| 20 | Timer::after(Duration::from_millis(500)).await; | ||
| 21 | |||
| 22 | led.set_low(); | ||
| 23 | Timer::after(Duration::from_millis(500)).await; | ||
| 24 | } | ||
| 25 | } | ||
diff --git a/examples/boot/stm32f7/.cargo/config.toml b/examples/boot/stm32f7/.cargo/config.toml new file mode 100644 index 000000000..df5114520 --- /dev/null +++ b/examples/boot/stm32f7/.cargo/config.toml | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip STM32F767ZITx -v" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabihf" | ||
diff --git a/examples/boot/stm32f7/Cargo.toml b/examples/boot/stm32f7/Cargo.toml new file mode 100644 index 000000000..857b287d5 --- /dev/null +++ b/examples/boot/stm32f7/Cargo.toml | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Ulf Lilleengen <[email protected]>"] | ||
| 3 | edition = "2021" | ||
| 4 | name = "embassy-boot-stm32f7-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly"] } | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } | ||
| 10 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } | ||
| 11 | embassy-traits = { version = "0.1.0", path = "../../../embassy-traits" } | ||
| 12 | |||
| 13 | defmt = { version = "0.3", optional = true } | ||
| 14 | defmt-rtt = { version = "0.3", optional = true } | ||
| 15 | panic-reset = { version = "0.1.1" } | ||
| 16 | embedded-hal = { version = "0.2.6" } | ||
| 17 | |||
| 18 | cortex-m = "0.7.3" | ||
| 19 | cortex-m-rt = "0.7.0" | ||
| 20 | |||
| 21 | [features] | ||
| 22 | defmt = [ | ||
| 23 | "dep:defmt", | ||
| 24 | "embassy-stm32/defmt", | ||
| 25 | "embassy-boot-stm32/defmt", | ||
| 26 | ] | ||
diff --git a/examples/boot/stm32f7/README.md b/examples/boot/stm32f7/README.md new file mode 100644 index 000000000..bf9142a1c --- /dev/null +++ b/examples/boot/stm32f7/README.md | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | # Examples using bootloader | ||
| 2 | |||
| 3 | Example for STM32F7 demonstrating the bootloader. The example consists of application binaries, 'a' | ||
| 4 | which allows you to press a button to start the DFU process, and 'b' which is the updated | ||
| 5 | application. | ||
| 6 | |||
| 7 | |||
| 8 | ## Prerequisites | ||
| 9 | |||
| 10 | * `cargo-binutils` | ||
| 11 | * `cargo-flash` | ||
| 12 | * `embassy-boot-stm32` | ||
| 13 | |||
| 14 | ## Usage | ||
| 15 | |||
| 16 | ``` | ||
| 17 | # Flash bootloader | ||
| 18 | ./flash-boot.sh | ||
| 19 | # Build 'b' | ||
| 20 | cargo build --release --bin b | ||
| 21 | # Generate binary for 'b' | ||
| 22 | cargo objcopy --release --bin b -- -O binary b.bin | ||
| 23 | ``` | ||
| 24 | |||
| 25 | # Flash `a` (which includes b.bin) | ||
| 26 | |||
| 27 | ``` | ||
| 28 | cargo flash --release --bin a --chip STM32F767ZITx | ||
| 29 | ``` | ||
diff --git a/examples/boot/stm32f7/build.rs b/examples/boot/stm32f7/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/stm32f7/build.rs | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | if env::var("CARGO_FEATURE_DEFMT").is_ok() { | ||
| 35 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 36 | } | ||
| 37 | } | ||
diff --git a/examples/boot/stm32f7/flash-boot.sh b/examples/boot/stm32f7/flash-boot.sh new file mode 100755 index 000000000..86074ffa3 --- /dev/null +++ b/examples/boot/stm32f7/flash-boot.sh | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | mv ../../../embassy-boot/stm32/memory.x ../../../embassy-boot/stm32/memory-old.x | ||
| 3 | cp memory-bl.x ../../../embassy-boot/stm32/memory.x | ||
| 4 | |||
| 5 | cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32F767ZITx --target thumbv7em-none-eabihf | ||
| 6 | |||
| 7 | rm ../../../embassy-boot/stm32/memory.x | ||
| 8 | mv ../../../embassy-boot/stm32/memory-old.x ../../../embassy-boot/stm32/memory.x | ||
diff --git a/examples/boot/stm32f7/memory-bl.x b/examples/boot/stm32f7/memory-bl.x new file mode 100644 index 000000000..47f3f4d9b --- /dev/null +++ b/examples/boot/stm32f7/memory-bl.x | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 256K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K | ||
| 6 | ACTIVE : ORIGIN = 0x08080000, LENGTH = 256K | ||
| 7 | DFU : ORIGIN = 0x080c0000, LENGTH = 512K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 368K + 16K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 13 | |||
| 14 | __bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); | ||
| 15 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); | ||
| 16 | |||
| 17 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); | ||
| 18 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); | ||
diff --git a/examples/boot/stm32f7/memory.x b/examples/boot/stm32f7/memory.x new file mode 100644 index 000000000..1c5537d17 --- /dev/null +++ b/examples/boot/stm32f7/memory.x | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 256K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K | ||
| 6 | FLASH : ORIGIN = 0x08080000, LENGTH = 256K | ||
| 7 | DFU : ORIGIN = 0x080c0000, LENGTH = 512K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 368K + 16K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | ||
| 13 | |||
| 14 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); | ||
| 15 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); | ||
diff --git a/examples/boot/stm32f7/src/bin/a.rs b/examples/boot/stm32f7/src/bin/a.rs new file mode 100644 index 000000000..ca154f0af --- /dev/null +++ b/examples/boot/stm32f7/src/bin/a.rs | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use embassy_boot_stm32::FirmwareUpdater; | ||
| 6 | use embassy_stm32::exti::ExtiInput; | ||
| 7 | use embassy_stm32::flash::Flash; | ||
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | ||
| 9 | use embassy_stm32::Peripherals; | ||
| 10 | use embassy_traits::adapter::BlockingAsync; | ||
| 11 | use panic_reset as _; | ||
| 12 | |||
| 13 | #[cfg(feature = "defmt-rtt")] | ||
| 14 | use defmt_rtt::*; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | ||
| 17 | |||
| 18 | #[embassy::main] | ||
| 19 | async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | ||
| 20 | let flash = Flash::unlock(p.FLASH); | ||
| 21 | let mut flash = BlockingAsync::new(flash); | ||
| 22 | |||
| 23 | let button = Input::new(p.PC13, Pull::Down); | ||
| 24 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 25 | |||
| 26 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); | ||
| 27 | led.set_high(); | ||
| 28 | |||
| 29 | let mut updater = FirmwareUpdater::default(); | ||
| 30 | button.wait_for_rising_edge().await; | ||
| 31 | let mut offset = 0; | ||
| 32 | let mut buf: [u8; 256 * 1024] = [0; 256 * 1024]; | ||
| 33 | for chunk in APP_B.chunks(256 * 1024) { | ||
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | ||
| 35 | updater | ||
| 36 | .write_firmware(offset, &buf, &mut flash, 2048) | ||
| 37 | .await | ||
| 38 | .unwrap(); | ||
| 39 | offset += chunk.len(); | ||
| 40 | } | ||
| 41 | updater.update(&mut flash).await.unwrap(); | ||
| 42 | led.set_low(); | ||
| 43 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 44 | } | ||
diff --git a/examples/boot/stm32f7/src/bin/b.rs b/examples/boot/stm32f7/src/bin/b.rs new file mode 100644 index 000000000..ed37137f5 --- /dev/null +++ b/examples/boot/stm32f7/src/bin/b.rs | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use embassy::executor::Spawner; | ||
| 6 | use embassy::time::{Duration, Timer}; | ||
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 8 | use embassy_stm32::Peripherals; | ||
| 9 | use panic_reset as _; | ||
| 10 | |||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | Timer::after(Duration::from_millis(300)).await; | ||
| 17 | let mut led = Output::new(p.PB7, Level::High, Speed::Low); | ||
| 18 | led.set_high(); | ||
| 19 | |||
| 20 | loop { | ||
| 21 | led.set_high(); | ||
| 22 | Timer::after(Duration::from_millis(500)).await; | ||
| 23 | |||
| 24 | led.set_low(); | ||
| 25 | Timer::after(Duration::from_millis(500)).await; | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/examples/boot/stm32h7/.cargo/config.toml b/examples/boot/stm32h7/.cargo/config.toml new file mode 100644 index 000000000..8475e7f66 --- /dev/null +++ b/examples/boot/stm32h7/.cargo/config.toml | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip STM32H743ZITx" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabihf" | ||
diff --git a/examples/boot/stm32h7/Cargo.toml b/examples/boot/stm32h7/Cargo.toml new file mode 100644 index 000000000..1fd03906f --- /dev/null +++ b/examples/boot/stm32h7/Cargo.toml | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Ulf Lilleengen <[email protected]>"] | ||
| 3 | edition = "2021" | ||
| 4 | name = "embassy-boot-stm32f7-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly"] } | ||
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } | ||
| 10 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } | ||
| 11 | embassy-traits = { version = "0.1.0", path = "../../../embassy-traits" } | ||
| 12 | |||
| 13 | defmt = { version = "0.3", optional = true } | ||
| 14 | defmt-rtt = { version = "0.3", optional = true } | ||
| 15 | panic-reset = { version = "0.1.1" } | ||
| 16 | embedded-hal = { version = "0.2.6" } | ||
| 17 | |||
| 18 | cortex-m = "0.7.3" | ||
| 19 | cortex-m-rt = "0.7.0" | ||
| 20 | |||
| 21 | [features] | ||
| 22 | defmt = [ | ||
| 23 | "dep:defmt", | ||
| 24 | "embassy-stm32/defmt", | ||
| 25 | "embassy-boot-stm32/defmt", | ||
| 26 | ] | ||
diff --git a/examples/boot/stm32h7/README.md b/examples/boot/stm32h7/README.md new file mode 100644 index 000000000..1fdc305e6 --- /dev/null +++ b/examples/boot/stm32h7/README.md | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | # Examples using bootloader | ||
| 2 | |||
| 3 | Example for STM32H7 demonstrating the bootloader. The example consists of application binaries, 'a' | ||
| 4 | which allows you to press a button to start the DFU process, and 'b' which is the updated | ||
| 5 | application. | ||
| 6 | |||
| 7 | |||
| 8 | ## Prerequisites | ||
| 9 | |||
| 10 | * `cargo-binutils` | ||
| 11 | * `cargo-flash` | ||
| 12 | * `embassy-boot-stm32` | ||
| 13 | |||
| 14 | ## Usage | ||
| 15 | |||
| 16 | ``` | ||
| 17 | # Flash bootloader | ||
| 18 | ./flash-boot.sh | ||
| 19 | # Build 'b' | ||
| 20 | cargo build --release --bin b | ||
| 21 | # Generate binary for 'b' | ||
| 22 | cargo objcopy --release --bin b -- -O binary b.bin | ||
| 23 | ``` | ||
| 24 | |||
| 25 | # Flash `a` (which includes b.bin) | ||
| 26 | |||
| 27 | ``` | ||
| 28 | cargo flash --release --bin a --chip STM32H743ZITx | ||
| 29 | ``` | ||
diff --git a/examples/boot/stm32h7/build.rs b/examples/boot/stm32h7/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/stm32h7/build.rs | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | if env::var("CARGO_FEATURE_DEFMT").is_ok() { | ||
| 35 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 36 | } | ||
| 37 | } | ||
diff --git a/examples/boot/stm32h7/flash-boot.sh b/examples/boot/stm32h7/flash-boot.sh new file mode 100755 index 000000000..a910b7312 --- /dev/null +++ b/examples/boot/stm32h7/flash-boot.sh | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | mv ../../../embassy-boot/stm32/memory.x ../../../embassy-boot/stm32/memory-old.x | ||
| 3 | cp memory-bl.x ../../../embassy-boot/stm32/memory.x | ||
| 4 | |||
| 5 | cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32H743ZITx --target thumbv7em-none-eabihf | ||
| 6 | |||
| 7 | rm ../../../embassy-boot/stm32/memory.x | ||
| 8 | mv ../../../embassy-boot/stm32/memory-old.x ../../../embassy-boot/stm32/memory.x | ||
diff --git a/examples/boot/stm32h7/memory-bl.x b/examples/boot/stm32h7/memory-bl.x new file mode 100644 index 000000000..c6f447d8b --- /dev/null +++ b/examples/boot/stm32h7/memory-bl.x | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 128K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K | ||
| 6 | ACTIVE : ORIGIN = 0x08040000, LENGTH = 128K | ||
| 7 | DFU : ORIGIN = 0x08100000, LENGTH = 512K | ||
| 8 | RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 13 | |||
| 14 | __bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); | ||
| 15 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); | ||
| 16 | |||
| 17 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); | ||
| 18 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); | ||
diff --git a/examples/boot/stm32h7/memory.x b/examples/boot/stm32h7/memory.x new file mode 100644 index 000000000..497a09e41 --- /dev/null +++ b/examples/boot/stm32h7/memory.x | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 128K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K | ||
| 6 | FLASH : ORIGIN = 0x08040000, LENGTH = 256K | ||
| 7 | DFU : ORIGIN = 0x08100000, LENGTH = 512K | ||
| 8 | RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | ||
| 13 | |||
| 14 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); | ||
| 15 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); | ||
diff --git a/examples/boot/stm32h7/src/bin/a.rs b/examples/boot/stm32h7/src/bin/a.rs new file mode 100644 index 000000000..1f23a8bc2 --- /dev/null +++ b/examples/boot/stm32h7/src/bin/a.rs | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use embassy_boot_stm32::FirmwareUpdater; | ||
| 6 | use embassy_stm32::exti::ExtiInput; | ||
| 7 | use embassy_stm32::flash::Flash; | ||
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | ||
| 9 | use embassy_stm32::Peripherals; | ||
| 10 | use embassy_traits::adapter::BlockingAsync; | ||
| 11 | use panic_reset as _; | ||
| 12 | |||
| 13 | #[cfg(feature = "defmt-rtt")] | ||
| 14 | use defmt_rtt::*; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | ||
| 17 | |||
| 18 | #[embassy::main] | ||
| 19 | async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | ||
| 20 | let flash = Flash::unlock(p.FLASH); | ||
| 21 | let mut flash = BlockingAsync::new(flash); | ||
| 22 | |||
| 23 | let button = Input::new(p.PC13, Pull::Down); | ||
| 24 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 25 | |||
| 26 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | ||
| 27 | led.set_high(); | ||
| 28 | |||
| 29 | let mut updater = FirmwareUpdater::default(); | ||
| 30 | button.wait_for_rising_edge().await; | ||
| 31 | let mut offset = 0; | ||
| 32 | let mut buf: [u8; 128 * 1024] = [0; 128 * 1024]; | ||
| 33 | for chunk in APP_B.chunks(128 * 1024) { | ||
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | ||
| 35 | updater | ||
| 36 | .write_firmware(offset, &buf, &mut flash, 2048) | ||
| 37 | .await | ||
| 38 | .unwrap(); | ||
| 39 | offset += chunk.len(); | ||
| 40 | } | ||
| 41 | updater.update(&mut flash).await.unwrap(); | ||
| 42 | led.set_low(); | ||
| 43 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 44 | } | ||
diff --git a/examples/boot/stm32h7/src/bin/b.rs b/examples/boot/stm32h7/src/bin/b.rs new file mode 100644 index 000000000..233b93e1a --- /dev/null +++ b/examples/boot/stm32h7/src/bin/b.rs | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use embassy::executor::Spawner; | ||
| 6 | use embassy::time::{Duration, Timer}; | ||
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 8 | use embassy_stm32::Peripherals; | ||
| 9 | use panic_reset as _; | ||
| 10 | |||
| 11 | #[cfg(feature = "defmt-rtt")] | ||
| 12 | use defmt_rtt::*; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | Timer::after(Duration::from_millis(300)).await; | ||
| 17 | let mut led = Output::new(p.PB14, Level::High, Speed::Low); | ||
| 18 | led.set_high(); | ||
| 19 | |||
| 20 | loop { | ||
| 21 | led.set_high(); | ||
| 22 | Timer::after(Duration::from_millis(500)).await; | ||
| 23 | |||
| 24 | led.set_low(); | ||
| 25 | Timer::after(Duration::from_millis(500)).await; | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 4258544f0..ffac0a769 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -6,7 +6,7 @@ version = "0.1.0" | |||
| 6 | 6 | ||
| 7 | [features] | 7 | [features] |
| 8 | default = ["nightly"] | 8 | default = ["nightly"] |
| 9 | nightly = ["embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm"] | 9 | nightly = ["embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm", "embedded-io/async", "embassy-net/nightly"] |
| 10 | 10 | ||
| 11 | [dependencies] | 11 | [dependencies] |
| 12 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } | 12 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } |
| @@ -16,6 +16,7 @@ embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defm | |||
| 16 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"], optional = true } | 16 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"], optional = true } |
| 17 | embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features = ["defmt"], optional = true } | 17 | embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features = ["defmt"], optional = true } |
| 18 | embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", features = ["defmt"], optional = true } | 18 | embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", features = ["defmt"], optional = true } |
| 19 | embedded-io = "0.2.0" | ||
| 19 | 20 | ||
| 20 | defmt = "0.3" | 21 | defmt = "0.3" |
| 21 | defmt-rtt = "0.3" | 22 | defmt-rtt = "0.3" |
diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs index 2cd163a9f..a64c5821b 100644 --- a/examples/nrf/src/bin/buffered_uart.rs +++ b/examples/nrf/src/bin/buffered_uart.rs | |||
| @@ -4,9 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | ||
| 8 | use embassy_nrf::buffered_uarte::State; | 7 | use embassy_nrf::buffered_uarte::State; |
| 9 | use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; | 8 | use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; |
| 9 | use embedded_io::asynch::{Read, Write}; | ||
| 10 | use futures::pin_mut; | 10 | use futures::pin_mut; |
| 11 | 11 | ||
| 12 | use defmt_rtt as _; // global logger | 12 | use defmt_rtt as _; // global logger |
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index f14a29c49..843487c03 100644 --- a/examples/nrf/src/bin/usb_ethernet.rs +++ b/examples/nrf/src/bin/usb_ethernet.rs | |||
| @@ -10,9 +10,9 @@ use defmt::*; | |||
| 10 | use embassy::blocking_mutex::raw::ThreadModeRawMutex; | 10 | use embassy::blocking_mutex::raw::ThreadModeRawMutex; |
| 11 | use embassy::channel::Channel; | 11 | use embassy::channel::Channel; |
| 12 | use embassy::executor::Spawner; | 12 | use embassy::executor::Spawner; |
| 13 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | ||
| 14 | use embassy::util::Forever; | 13 | use embassy::util::Forever; |
| 15 | use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, TcpSocket}; | 14 | use embassy_net::tcp::TcpSocket; |
| 15 | use embassy_net::{PacketBox, PacketBoxExt, PacketBuf}; | ||
| 16 | use embassy_nrf::pac; | 16 | use embassy_nrf::pac; |
| 17 | use embassy_nrf::usb::Driver; | 17 | use embassy_nrf::usb::Driver; |
| 18 | use embassy_nrf::Peripherals; | 18 | use embassy_nrf::Peripherals; |
| @@ -20,7 +20,9 @@ use embassy_nrf::{interrupt, peripherals}; | |||
| 20 | use embassy_usb::{Builder, Config, UsbDevice}; | 20 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 21 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | 21 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; |
| 22 | 22 | ||
| 23 | use defmt_rtt as _; // global logger | 23 | use defmt_rtt as _; |
| 24 | use embedded_io::asynch::{Read, Write}; | ||
| 25 | // global logger | ||
| 24 | use panic_probe as _; | 26 | use panic_probe as _; |
| 25 | 27 | ||
| 26 | type MyDriver = Driver<'static, peripherals::USBD>; | 28 | type MyDriver = Driver<'static, peripherals::USBD>; |
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 0853c323e..fa2a98a49 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml | |||
| @@ -6,7 +6,8 @@ version = "0.1.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy = { version = "0.1.0", path = "../../embassy", features = ["log", "std", "time", "nightly"] } | 8 | embassy = { version = "0.1.0", path = "../../embassy", features = ["log", "std", "time", "nightly"] } |
| 9 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features=["std", "log", "medium-ethernet", "tcp", "dhcpv4", "pool-16"] } | 9 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features=["nightly", "std", "log", "medium-ethernet", "tcp", "dhcpv4", "pool-16"] } |
| 10 | embedded-io = { version = "0.2.0", features = ["async", "std"] } | ||
| 10 | 11 | ||
| 11 | async-io = "1.6.0" | 12 | async-io = "1.6.0" |
| 12 | env_logger = "0.9.0" | 13 | env_logger = "0.9.0" |
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 3b4bc6fea..daedffb0f 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -2,12 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | use clap::Parser; | 3 | use clap::Parser; |
| 4 | use embassy::executor::{Executor, Spawner}; | 4 | use embassy::executor::{Executor, Spawner}; |
| 5 | use embassy::io::AsyncWriteExt; | ||
| 6 | use embassy::util::Forever; | 5 | use embassy::util::Forever; |
| 6 | use embassy_net::tcp::TcpSocket; | ||
| 7 | use embassy_net::{ | 7 | use embassy_net::{ |
| 8 | Config, Configurator, DhcpConfigurator, Ipv4Address, Ipv4Cidr, StackResources, | 8 | Config, Configurator, DhcpConfigurator, Ipv4Address, Ipv4Cidr, StackResources, |
| 9 | StaticConfigurator, TcpSocket, | 9 | StaticConfigurator, |
| 10 | }; | 10 | }; |
| 11 | use embedded_io::asynch::Write; | ||
| 11 | use heapless::Vec; | 12 | use heapless::Vec; |
| 12 | use log::*; | 13 | use log::*; |
| 13 | 14 | ||
diff --git a/examples/std/src/bin/serial.rs b/examples/std/src/bin/serial.rs index 129dc2090..b1e5b0142 100644 --- a/examples/std/src/bin/serial.rs +++ b/examples/std/src/bin/serial.rs | |||
| @@ -5,8 +5,8 @@ mod serial_port; | |||
| 5 | 5 | ||
| 6 | use async_io::Async; | 6 | use async_io::Async; |
| 7 | use embassy::executor::Executor; | 7 | use embassy::executor::Executor; |
| 8 | use embassy::io::AsyncBufReadExt; | ||
| 9 | use embassy::util::Forever; | 8 | use embassy::util::Forever; |
| 9 | use embedded_io::asynch::Read; | ||
| 10 | use log::*; | 10 | use log::*; |
| 11 | use nix::sys::termios; | 11 | use nix::sys::termios; |
| 12 | 12 | ||
| @@ -24,12 +24,12 @@ async fn run() { | |||
| 24 | // Essentially, async_io::Async converts from AsRawFd+Read+Write to futures's AsyncRead+AsyncWrite | 24 | // Essentially, async_io::Async converts from AsRawFd+Read+Write to futures's AsyncRead+AsyncWrite |
| 25 | let port = Async::new(port).unwrap(); | 25 | let port = Async::new(port).unwrap(); |
| 26 | 26 | ||
| 27 | // This implements futures's AsyncBufRead based on futures's AsyncRead | 27 | // We can then use FromStdIo to convert from futures's AsyncRead+AsyncWrite |
| 28 | let port = futures::io::BufReader::new(port); | 28 | // to embedded_io's async Read+Write. |
| 29 | 29 | // | |
| 30 | // We can then use FromStdIo to convert from futures's AsyncBufRead+AsyncWrite | 30 | // This is not really needed, you could write the code below using futures::io directly. |
| 31 | // to embassy's AsyncBufRead+AsyncWrite | 31 | // It's useful if you want to have portable code across embedded and std. |
| 32 | let mut port = embassy::io::FromStdIo::new(port); | 32 | let mut port = embedded_io::adapters::FromFutures::new(port); |
| 33 | 33 | ||
| 34 | info!("Serial opened!"); | 34 | info!("Serial opened!"); |
| 35 | 35 | ||
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index 37f99fea2..e7a44c11e 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml | |||
| @@ -19,3 +19,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } | |||
| 19 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 19 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 20 | heapless = { version = "0.7.5", default-features = false } | 20 | heapless = { version = "0.7.5", default-features = false } |
| 21 | nb = "1.0.0" | 21 | nb = "1.0.0" |
| 22 | embedded-storage = "0.3.0" | ||
diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs index b3643a26f..4b181a784 100644 --- a/examples/stm32f3/src/bin/blinky.rs +++ b/examples/stm32f3/src/bin/blinky.rs | |||
| @@ -15,7 +15,7 @@ use panic_probe as _; | |||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 15 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | info!("Hello World!"); | 16 | info!("Hello World!"); |
| 17 | 17 | ||
| 18 | let mut led = Output::new(p.PE12, Level::High, Speed::Low); | 18 | let mut led = Output::new(p.PA5, Level::High, Speed::Low); |
| 19 | 19 | ||
| 20 | loop { | 20 | loop { |
| 21 | info!("high"); | 21 | info!("high"); |
diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs new file mode 100644 index 000000000..3890f0514 --- /dev/null +++ b/examples/stm32f3/src/bin/flash.rs | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{info, unwrap}; | ||
| 6 | use embassy::executor::Spawner; | ||
| 7 | use embassy_stm32::flash::Flash; | ||
| 8 | use embassy_stm32::Peripherals; | ||
| 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | ||
| 10 | |||
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | info!("Hello Flash!"); | ||
| 17 | |||
| 18 | const ADDR: u32 = 0x26000; | ||
| 19 | |||
| 20 | let mut f = Flash::unlock(p.FLASH); | ||
| 21 | |||
| 22 | info!("Reading..."); | ||
| 23 | let mut buf = [0u8; 8]; | ||
| 24 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 25 | info!("Read: {=[u8]:x}", buf); | ||
| 26 | |||
| 27 | info!("Erasing..."); | ||
| 28 | unwrap!(f.erase(ADDR, ADDR + 2048)); | ||
| 29 | |||
| 30 | info!("Reading..."); | ||
| 31 | let mut buf = [0u8; 8]; | ||
| 32 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 33 | info!("Read after erase: {=[u8]:x}", buf); | ||
| 34 | |||
| 35 | info!("Writing..."); | ||
| 36 | unwrap!(f.write(ADDR, &[1, 2, 3, 4, 5, 6, 7, 8])); | ||
| 37 | |||
| 38 | info!("Reading..."); | ||
| 39 | let mut buf = [0u8; 8]; | ||
| 40 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 41 | info!("Read: {=[u8]:x}", buf); | ||
| 42 | assert_eq!(&buf[..], &[1, 2, 3, 4, 5, 6, 7, 8]); | ||
| 43 | } | ||
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 1bc406495..e2065bed9 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -8,7 +8,7 @@ resolver = "2" | |||
| 8 | 8 | ||
| 9 | [dependencies] | 9 | [dependencies] |
| 10 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits"] } | 10 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "usb-otg"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } |
| 12 | 12 | ||
| 13 | defmt = "0.3" | 13 | defmt = "0.3" |
| 14 | defmt-rtt = "0.3" | 14 | defmt-rtt = "0.3" |
diff --git a/examples/stm32f4/src/bin/usb_uart.rs b/examples/stm32f4/src/bin/usb_uart.rs deleted file mode 100644 index 251ed1eb0..000000000 --- a/examples/stm32f4/src/bin/usb_uart.rs +++ /dev/null | |||
| @@ -1,99 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::{info, unwrap}; | ||
| 9 | use defmt_rtt as _; // global logger | ||
| 10 | use embassy::interrupt::InterruptExt; | ||
| 11 | use futures::pin_mut; | ||
| 12 | use panic_probe as _; // print out panic messages | ||
| 13 | |||
| 14 | use embassy::executor::Spawner; | ||
| 15 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | ||
| 16 | use embassy_stm32::usb_otg::{State, Usb, UsbBus, UsbOtg, UsbSerial}; | ||
| 17 | use embassy_stm32::{interrupt, time::Hertz, Config, Peripherals}; | ||
| 18 | use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; | ||
| 19 | |||
| 20 | static mut EP_MEMORY: [u32; 2048] = [0; 2048]; | ||
| 21 | |||
| 22 | // USB requires at least 48 MHz clock | ||
| 23 | fn config() -> Config { | ||
| 24 | let mut config = Config::default(); | ||
| 25 | config.rcc.sys_ck = Some(Hertz(48_000_000)); | ||
| 26 | config | ||
| 27 | } | ||
| 28 | |||
| 29 | #[embassy::main(config = "config()")] | ||
| 30 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 31 | let mut rx_buffer = [0u8; 64]; | ||
| 32 | // we send back input + cr + lf | ||
| 33 | let mut tx_buffer = [0u8; 66]; | ||
| 34 | |||
| 35 | let peri = UsbOtg::new_fs(p.USB_OTG_FS, p.PA12, p.PA11); | ||
| 36 | let usb_bus = UsbBus::new(peri, unsafe { &mut EP_MEMORY }); | ||
| 37 | |||
| 38 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); | ||
| 39 | |||
| 40 | let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) | ||
| 41 | .manufacturer("Fake company") | ||
| 42 | .product("Serial port") | ||
| 43 | .serial_number("TEST") | ||
| 44 | .device_class(0x02) | ||
| 45 | .build(); | ||
| 46 | |||
| 47 | let irq = interrupt::take!(OTG_FS); | ||
| 48 | irq.set_priority(interrupt::Priority::P3); | ||
| 49 | |||
| 50 | let mut state = State::new(); | ||
| 51 | let usb = unsafe { Usb::new(&mut state, device, serial, irq) }; | ||
| 52 | pin_mut!(usb); | ||
| 53 | |||
| 54 | let (mut reader, mut writer) = usb.as_ref().take_serial_0(); | ||
| 55 | |||
| 56 | info!("usb initialized!"); | ||
| 57 | |||
| 58 | unwrap!( | ||
| 59 | writer | ||
| 60 | .write_all(b"\r\nInput returned upper cased on CR+LF\r\n") | ||
| 61 | .await | ||
| 62 | ); | ||
| 63 | |||
| 64 | let mut buf = [0u8; 64]; | ||
| 65 | loop { | ||
| 66 | let mut n = 0; | ||
| 67 | |||
| 68 | async { | ||
| 69 | loop { | ||
| 70 | let char = unwrap!(reader.read_byte().await); | ||
| 71 | |||
| 72 | if char == b'\r' || char == b'\n' { | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | |||
| 76 | buf[n] = char; | ||
| 77 | n += 1; | ||
| 78 | |||
| 79 | // stop if we're out of room | ||
| 80 | if n == buf.len() { | ||
| 81 | break; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | .await; | ||
| 86 | |||
| 87 | if n > 0 { | ||
| 88 | for char in buf[..n].iter_mut() { | ||
| 89 | // upper case | ||
| 90 | if 0x61 <= *char && *char <= 0x7a { | ||
| 91 | *char &= !0x20; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | unwrap!(writer.write_all(&buf[..n]).await); | ||
| 95 | unwrap!(writer.write_all(b"\r\n").await); | ||
| 96 | unwrap!(writer.flush().await); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
diff --git a/examples/stm32f4/src/bin/usb_uart_ulpi.rs b/examples/stm32f4/src/bin/usb_uart_ulpi.rs deleted file mode 100644 index f6c373602..000000000 --- a/examples/stm32f4/src/bin/usb_uart_ulpi.rs +++ /dev/null | |||
| @@ -1,114 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::{info, unwrap}; | ||
| 9 | use defmt_rtt as _; // global logger | ||
| 10 | use embassy::interrupt::InterruptExt; | ||
| 11 | use futures::pin_mut; | ||
| 12 | use panic_probe as _; // print out panic messages | ||
| 13 | |||
| 14 | use embassy::executor::Spawner; | ||
| 15 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | ||
| 16 | use embassy_stm32::usb_otg::{State, Usb, UsbBus, UsbOtg, UsbSerial}; | ||
| 17 | use embassy_stm32::{interrupt, time::Hertz, Config, Peripherals}; | ||
| 18 | use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; | ||
| 19 | |||
| 20 | static mut EP_MEMORY: [u32; 2048] = [0; 2048]; | ||
| 21 | |||
| 22 | // USB requires at least 48 MHz clock | ||
| 23 | fn config() -> Config { | ||
| 24 | let mut config = Config::default(); | ||
| 25 | config.rcc.sys_ck = Some(Hertz(48_000_000)); | ||
| 26 | config | ||
| 27 | } | ||
| 28 | |||
| 29 | #[embassy::main(config = "config()")] | ||
| 30 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 31 | let mut rx_buffer = [0u8; 64]; | ||
| 32 | // we send back input + cr + lf | ||
| 33 | let mut tx_buffer = [0u8; 66]; | ||
| 34 | |||
| 35 | // USB with external high-speed PHY | ||
| 36 | let peri = UsbOtg::new_hs_ulpi( | ||
| 37 | p.USB_OTG_HS, | ||
| 38 | p.PA5, | ||
| 39 | p.PC2, | ||
| 40 | p.PC3, | ||
| 41 | p.PC0, | ||
| 42 | p.PA3, | ||
| 43 | p.PB0, | ||
| 44 | p.PB1, | ||
| 45 | p.PB10, | ||
| 46 | p.PB11, | ||
| 47 | p.PB12, | ||
| 48 | p.PB13, | ||
| 49 | p.PB5, | ||
| 50 | ); | ||
| 51 | let usb_bus = UsbBus::new(peri, unsafe { &mut EP_MEMORY }); | ||
| 52 | |||
| 53 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); | ||
| 54 | |||
| 55 | let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) | ||
| 56 | .manufacturer("Fake company") | ||
| 57 | .product("Serial port") | ||
| 58 | .serial_number("TEST") | ||
| 59 | .device_class(0x02) | ||
| 60 | .build(); | ||
| 61 | |||
| 62 | let irq = interrupt::take!(OTG_FS); | ||
| 63 | irq.set_priority(interrupt::Priority::P3); | ||
| 64 | |||
| 65 | let mut state = State::new(); | ||
| 66 | let usb = unsafe { Usb::new(&mut state, device, serial, irq) }; | ||
| 67 | pin_mut!(usb); | ||
| 68 | |||
| 69 | let (mut reader, mut writer) = usb.as_ref().take_serial_0(); | ||
| 70 | |||
| 71 | info!("usb initialized!"); | ||
| 72 | |||
| 73 | unwrap!( | ||
| 74 | writer | ||
| 75 | .write_all(b"\r\nInput returned upper cased on CR+LF\r\n") | ||
| 76 | .await | ||
| 77 | ); | ||
| 78 | |||
| 79 | let mut buf = [0u8; 64]; | ||
| 80 | loop { | ||
| 81 | let mut n = 0; | ||
| 82 | |||
| 83 | async { | ||
| 84 | loop { | ||
| 85 | let char = unwrap!(reader.read_byte().await); | ||
| 86 | |||
| 87 | if char == b'\r' || char == b'\n' { | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | |||
| 91 | buf[n] = char; | ||
| 92 | n += 1; | ||
| 93 | |||
| 94 | // stop if we're out of room | ||
| 95 | if n == buf.len() { | ||
| 96 | break; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 | .await; | ||
| 101 | |||
| 102 | if n > 0 { | ||
| 103 | for char in buf[..n].iter_mut() { | ||
| 104 | // upper case | ||
| 105 | if 0x61 <= *char && *char <= 0x7a { | ||
| 106 | *char &= !0x20; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | unwrap!(writer.write_all(&buf[..n]).await); | ||
| 110 | unwrap!(writer.write_all(b"\r\n").await); | ||
| 111 | unwrap!(writer.flush().await); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | } | ||
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 09a06aa7f..f7af77da4 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml | |||
| @@ -9,6 +9,7 @@ resolver = "2" | |||
| 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } | 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } |
| 11 | embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "medium-ethernet", "pool-16"] } | 11 | embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "medium-ethernet", "pool-16"] } |
| 12 | embedded-io = { version = "0.2.0", features = ["async"] } | ||
| 12 | 13 | ||
| 13 | defmt = "0.3" | 14 | defmt = "0.3" |
| 14 | defmt-rtt = "0.3" | 15 | defmt-rtt = "0.3" |
| @@ -22,6 +23,7 @@ heapless = { version = "0.7.5", default-features = false } | |||
| 22 | nb = "1.0.0" | 23 | nb = "1.0.0" |
| 23 | rand_core = "0.6.3" | 24 | rand_core = "0.6.3" |
| 24 | critical-section = "0.2.3" | 25 | critical-section = "0.2.3" |
| 26 | embedded-storage = "0.3.0" | ||
| 25 | 27 | ||
| 26 | [dependencies.smoltcp] | 28 | [dependencies.smoltcp] |
| 27 | version = "0.8.0" | 29 | version = "0.8.0" |
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index 33e41de9c..dca9338b2 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -5,12 +5,10 @@ | |||
| 5 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use embassy::executor::{Executor, Spawner}; | 7 | use embassy::executor::{Executor, Spawner}; |
| 8 | use embassy::io::AsyncWriteExt; | ||
| 9 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy::util::Forever; | 9 | use embassy::util::Forever; |
| 11 | use embassy_net::{ | 10 | use embassy_net::tcp::TcpSocket; |
| 12 | Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket, | 11 | use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator}; |
| 13 | }; | ||
| 14 | use embassy_stm32::eth::generic_smi::GenericSMI; | 12 | use embassy_stm32::eth::generic_smi::GenericSMI; |
| 15 | use embassy_stm32::eth::{Ethernet, State}; | 13 | use embassy_stm32::eth::{Ethernet, State}; |
| 16 | use embassy_stm32::interrupt; | 14 | use embassy_stm32::interrupt; |
| @@ -19,6 +17,7 @@ use embassy_stm32::peripherals::RNG; | |||
| 19 | use embassy_stm32::rng::Rng; | 17 | use embassy_stm32::rng::Rng; |
| 20 | use embassy_stm32::time::U32Ext; | 18 | use embassy_stm32::time::U32Ext; |
| 21 | use embassy_stm32::Config; | 19 | use embassy_stm32::Config; |
| 20 | use embedded_io::asynch::Write; | ||
| 22 | use heapless::Vec; | 21 | use heapless::Vec; |
| 23 | 22 | ||
| 24 | use defmt_rtt as _; // global logger | 23 | use defmt_rtt as _; // global logger |
diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs new file mode 100644 index 000000000..9eb8e4b94 --- /dev/null +++ b/examples/stm32f7/src/bin/flash.rs | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{info, unwrap}; | ||
| 6 | use embassy::executor::Spawner; | ||
| 7 | use embassy::time::{Duration, Timer}; | ||
| 8 | use embassy_stm32::flash::Flash; | ||
| 9 | use embassy_stm32::Peripherals; | ||
| 10 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | ||
| 11 | |||
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | |||
| 15 | #[embassy::main] | ||
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 17 | info!("Hello Flash!"); | ||
| 18 | |||
| 19 | const ADDR: u32 = 0x8_0000; | ||
| 20 | |||
| 21 | // wait a bit before accessing the flash | ||
| 22 | Timer::after(Duration::from_millis(300)).await; | ||
| 23 | |||
| 24 | let mut f = Flash::unlock(p.FLASH); | ||
| 25 | |||
| 26 | info!("Reading..."); | ||
| 27 | let mut buf = [0u8; 32]; | ||
| 28 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 29 | info!("Read: {=[u8]:x}", buf); | ||
| 30 | |||
| 31 | info!("Erasing..."); | ||
| 32 | unwrap!(f.erase(ADDR, ADDR + 256 * 1024)); | ||
| 33 | |||
| 34 | info!("Reading..."); | ||
| 35 | let mut buf = [0u8; 32]; | ||
| 36 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 37 | info!("Read after erase: {=[u8]:x}", buf); | ||
| 38 | |||
| 39 | info!("Writing..."); | ||
| 40 | unwrap!(f.write( | ||
| 41 | ADDR, | ||
| 42 | &[ | ||
| 43 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | ||
| 44 | 25, 26, 27, 28, 29, 30, 31, 32 | ||
| 45 | ] | ||
| 46 | )); | ||
| 47 | |||
| 48 | info!("Reading..."); | ||
| 49 | let mut buf = [0u8; 32]; | ||
| 50 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 51 | info!("Read: {=[u8]:x}", buf); | ||
| 52 | assert_eq!( | ||
| 53 | &buf[..], | ||
| 54 | &[ | ||
| 55 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | ||
| 56 | 25, 26, 27, 28, 29, 30, 31, 32 | ||
| 57 | ] | ||
| 58 | ); | ||
| 59 | } | ||
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index 419bbec31..9c1569dd3 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml | |||
| @@ -5,12 +5,11 @@ name = "embassy-stm32h7-examples" | |||
| 5 | version = "0.1.0" | 5 | version = "0.1.0" |
| 6 | resolver = "2" | 6 | resolver = "2" |
| 7 | 7 | ||
| 8 | [features] | ||
| 9 | |||
| 10 | [dependencies] | 8 | [dependencies] |
| 11 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits"] } | 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits"] } |
| 12 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } |
| 13 | embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "medium-ethernet", "pool-16"] } | 11 | embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "medium-ethernet", "pool-16"] } |
| 12 | embedded-io = { version = "0.2.0", features = ["async"] } | ||
| 14 | 13 | ||
| 15 | defmt = "0.3" | 14 | defmt = "0.3" |
| 16 | defmt-rtt = "0.3" | 15 | defmt-rtt = "0.3" |
| @@ -27,6 +26,7 @@ rand_core = "0.6.3" | |||
| 27 | critical-section = "0.2.5" | 26 | critical-section = "0.2.5" |
| 28 | micromath = "2.0.0" | 27 | micromath = "2.0.0" |
| 29 | stm32-fmc = "0.2.4" | 28 | stm32-fmc = "0.2.4" |
| 29 | embedded-storage = "0.3.0" | ||
| 30 | 30 | ||
| 31 | [dependencies.smoltcp] | 31 | [dependencies.smoltcp] |
| 32 | version = "0.8.0" | 32 | version = "0.8.0" |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 9a2e7a33d..8ece29403 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -8,12 +8,10 @@ use panic_probe as _; | |||
| 8 | use cortex_m_rt::entry; | 8 | use cortex_m_rt::entry; |
| 9 | use defmt::*; | 9 | use defmt::*; |
| 10 | use embassy::executor::{Executor, Spawner}; | 10 | use embassy::executor::{Executor, Spawner}; |
| 11 | use embassy::io::AsyncWriteExt; | ||
| 12 | use embassy::time::{Duration, Timer}; | 11 | use embassy::time::{Duration, Timer}; |
| 13 | use embassy::util::Forever; | 12 | use embassy::util::Forever; |
| 14 | use embassy_net::{ | 13 | use embassy_net::tcp::TcpSocket; |
| 15 | Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket, | 14 | use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator}; |
| 16 | }; | ||
| 17 | use embassy_stm32::eth::generic_smi::GenericSMI; | 15 | use embassy_stm32::eth::generic_smi::GenericSMI; |
| 18 | use embassy_stm32::eth::{Ethernet, State}; | 16 | use embassy_stm32::eth::{Ethernet, State}; |
| 19 | use embassy_stm32::interrupt; | 17 | use embassy_stm32::interrupt; |
| @@ -22,6 +20,7 @@ use embassy_stm32::peripherals::RNG; | |||
| 22 | use embassy_stm32::rng::Rng; | 20 | use embassy_stm32::rng::Rng; |
| 23 | use embassy_stm32::time::U32Ext; | 21 | use embassy_stm32::time::U32Ext; |
| 24 | use embassy_stm32::Config; | 22 | use embassy_stm32::Config; |
| 23 | use embedded_io::asynch::Write; | ||
| 25 | use heapless::Vec; | 24 | use heapless::Vec; |
| 26 | 25 | ||
| 27 | #[embassy::task] | 26 | #[embassy::task] |
diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs new file mode 100644 index 000000000..b008c0884 --- /dev/null +++ b/examples/stm32h7/src/bin/flash.rs | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{info, unwrap}; | ||
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | ||
| 8 | use embassy::time::{Duration, Timer}; | ||
| 9 | use embassy_stm32::flash::Flash; | ||
| 10 | use embassy_stm32::Peripherals; | ||
| 11 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | ||
| 12 | use panic_probe as _; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | info!("Hello Flash!"); | ||
| 17 | |||
| 18 | const ADDR: u32 = 0x08_0000; | ||
| 19 | |||
| 20 | // wait a bit before accessing the flash | ||
| 21 | Timer::after(Duration::from_millis(300)).await; | ||
| 22 | |||
| 23 | let mut f = Flash::unlock(p.FLASH); | ||
| 24 | |||
| 25 | info!("Reading..."); | ||
| 26 | let mut buf = [0u8; 32]; | ||
| 27 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 28 | info!("Read: {=[u8]:x}", buf); | ||
| 29 | |||
| 30 | info!("Erasing..."); | ||
| 31 | unwrap!(f.erase(ADDR, ADDR + 128 * 1024)); | ||
| 32 | |||
| 33 | info!("Reading..."); | ||
| 34 | let mut buf = [0u8; 32]; | ||
| 35 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 36 | info!("Read after erase: {=[u8]:x}", buf); | ||
| 37 | |||
| 38 | info!("Writing..."); | ||
| 39 | unwrap!(f.write( | ||
| 40 | ADDR, | ||
| 41 | &[ | ||
| 42 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | ||
| 43 | 25, 26, 27, 28, 29, 30, 31, 32 | ||
| 44 | ] | ||
| 45 | )); | ||
| 46 | |||
| 47 | info!("Reading..."); | ||
| 48 | let mut buf = [0u8; 32]; | ||
| 49 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 50 | info!("Read: {=[u8]:x}", buf); | ||
| 51 | assert_eq!( | ||
| 52 | &buf[..], | ||
| 53 | &[ | ||
| 54 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | ||
| 55 | 25, 26, 27, 28, 29, 30, 31, 32 | ||
| 56 | ] | ||
| 57 | ); | ||
| 58 | } | ||
diff --git a/examples/stm32l0/.cargo/config.toml b/examples/stm32l0/.cargo/config.toml index 840faa62e..ec0b931f2 100644 --- a/examples/stm32l0/.cargo/config.toml +++ b/examples/stm32l0/.cargo/config.toml | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 2 | # replace your chip as listed in `probe-run --list-chips` | 2 | # replace your chip as listed in `probe-run --list-chips` |
| 3 | runner = "probe-run --chip STM32L072CZTx" | 3 | runner = "probe-run --chip STM32L053R8Tx" |
| 4 | 4 | ||
| 5 | [build] | 5 | [build] |
| 6 | target = "thumbv6m-none-eabi" | 6 | target = "thumbv6m-none-eabi" |
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 1cdb2f374..d6848c27a 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml | |||
| @@ -7,12 +7,11 @@ resolver = "2" | |||
| 7 | 7 | ||
| 8 | [features] | 8 | [features] |
| 9 | default = ["nightly"] | 9 | default = ["nightly"] |
| 10 | nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan"] | 10 | nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan", "embedded-io/async"] |
| 11 | 11 | ||
| 12 | [dependencies] | 12 | [dependencies] |
| 13 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } | 13 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } |
| 14 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | 14 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } |
| 15 | |||
| 16 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true} | 15 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true} |
| 17 | 16 | ||
| 18 | lorawan-device = { version = "0.7.1", default-features = false, features = ["async"], optional = true } | 17 | lorawan-device = { version = "0.7.1", default-features = false, features = ["async"], optional = true } |
| @@ -22,6 +21,7 @@ defmt = "0.3" | |||
| 22 | defmt-rtt = "0.3" | 21 | defmt-rtt = "0.3" |
| 23 | 22 | ||
| 24 | embedded-storage = "0.3.0" | 23 | embedded-storage = "0.3.0" |
| 24 | embedded-io = "0.2.0" | ||
| 25 | 25 | ||
| 26 | cortex-m = "0.7.3" | 26 | cortex-m = "0.7.3" |
| 27 | cortex-m-rt = "0.7.0" | 27 | cortex-m-rt = "0.7.0" |
diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs index abb27fa4f..4413a2945 100644 --- a/examples/stm32l0/src/bin/usart_irq.rs +++ b/examples/stm32l0/src/bin/usart_irq.rs | |||
| @@ -2,13 +2,14 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt_rtt as _; // global logger | 5 | use defmt_rtt as _; |
| 6 | use embedded_io::asynch::{Read, Write}; | ||
| 7 | // global logger | ||
| 6 | use panic_probe as _; | 8 | use panic_probe as _; |
| 7 | 9 | ||
| 8 | use defmt::*; | 10 | use defmt::*; |
| 9 | 11 | ||
| 10 | use embassy::executor::Spawner; | 12 | use embassy::executor::Spawner; |
| 11 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | ||
| 12 | use embassy_stm32::dma::NoDma; | 13 | use embassy_stm32::dma::NoDma; |
| 13 | use embassy_stm32::interrupt; | 14 | use embassy_stm32::interrupt; |
| 14 | use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; | 15 | use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; |
| @@ -16,19 +17,21 @@ use embassy_stm32::Peripherals; | |||
| 16 | 17 | ||
| 17 | #[embassy::main] | 18 | #[embassy::main] |
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | 19 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 20 | info!("Hi!"); | ||
| 21 | |||
| 19 | static mut TX_BUFFER: [u8; 8] = [0; 8]; | 22 | static mut TX_BUFFER: [u8; 8] = [0; 8]; |
| 20 | static mut RX_BUFFER: [u8; 256] = [0; 256]; | 23 | static mut RX_BUFFER: [u8; 256] = [0; 256]; |
| 21 | 24 | ||
| 22 | let mut config = Config::default(); | 25 | let mut config = Config::default(); |
| 23 | config.baudrate = 9600; | 26 | config.baudrate = 9600; |
| 24 | 27 | ||
| 25 | let usart = Uart::new(p.USART1, p.PA10, p.PA9, NoDma, NoDma, config); | 28 | let usart = Uart::new(p.USART2, p.PA3, p.PA2, NoDma, NoDma, config); |
| 26 | let mut state = State::new(); | 29 | let mut state = State::new(); |
| 27 | let mut usart = unsafe { | 30 | let mut usart = unsafe { |
| 28 | BufferedUart::new( | 31 | BufferedUart::new( |
| 29 | &mut state, | 32 | &mut state, |
| 30 | usart, | 33 | usart, |
| 31 | interrupt::take!(USART1), | 34 | interrupt::take!(USART2), |
| 32 | &mut TX_BUFFER, | 35 | &mut TX_BUFFER, |
| 33 | &mut RX_BUFFER, | 36 | &mut RX_BUFFER, |
| 34 | ) | 37 | ) |
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 2da549bb2..b3478f74e 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml | |||
| @@ -10,7 +10,7 @@ resolver = "2" | |||
| 10 | [dependencies] | 10 | [dependencies] |
| 11 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } | 11 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] } |
| 12 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits" } | 12 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits" } |
| 13 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits", "usb-otg"] } | 13 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] } |
| 14 | 14 | ||
| 15 | defmt = "0.3" | 15 | defmt = "0.3" |
| 16 | defmt-rtt = "0.3" | 16 | defmt-rtt = "0.3" |
diff --git a/examples/stm32l4/src/bin/usb_uart.rs b/examples/stm32l4/src/bin/usb_uart.rs deleted file mode 100644 index 878309550..000000000 --- a/examples/stm32l4/src/bin/usb_uart.rs +++ /dev/null | |||
| @@ -1,115 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::{info, unwrap}; | ||
| 9 | use defmt_rtt as _; // global logger | ||
| 10 | use embassy::interrupt::InterruptExt; | ||
| 11 | use futures::pin_mut; | ||
| 12 | use panic_probe as _; // print out panic messages | ||
| 13 | |||
| 14 | use embassy::executor::Spawner; | ||
| 15 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | ||
| 16 | use embassy_stm32::pac::pwr::vals::Usv; | ||
| 17 | use embassy_stm32::pac::{PWR, RCC}; | ||
| 18 | use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; | ||
| 19 | use embassy_stm32::usb_otg::{State, Usb, UsbBus, UsbOtg, UsbSerial}; | ||
| 20 | use embassy_stm32::{interrupt, Config, Peripherals}; | ||
| 21 | use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; | ||
| 22 | |||
| 23 | static mut EP_MEMORY: [u32; 2048] = [0; 2048]; | ||
| 24 | |||
| 25 | // USB requires at least 48 MHz clock | ||
| 26 | fn config() -> Config { | ||
| 27 | let mut config = Config::default(); | ||
| 28 | // set up a 80Mhz clock | ||
| 29 | config.rcc.mux = ClockSrc::PLL( | ||
| 30 | PLLSource::HSI16, | ||
| 31 | PLLClkDiv::Div2, | ||
| 32 | PLLSrcDiv::Div2, | ||
| 33 | PLLMul::Mul20, | ||
| 34 | None, | ||
| 35 | ); | ||
| 36 | // enable HSI48 clock for USB | ||
| 37 | config.rcc.hsi48 = true; | ||
| 38 | config | ||
| 39 | } | ||
| 40 | |||
| 41 | #[embassy::main(config = "config()")] | ||
| 42 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 43 | // Enable PWR peripheral | ||
| 44 | unsafe { RCC.apb1enr1().modify(|w| w.set_pwren(true)) }; | ||
| 45 | unsafe { PWR.cr2().modify(|w| w.set_usv(Usv::VALID)) } | ||
| 46 | |||
| 47 | let mut rx_buffer = [0u8; 64]; | ||
| 48 | // we send back input + cr + lf | ||
| 49 | let mut tx_buffer = [0u8; 66]; | ||
| 50 | |||
| 51 | let peri = UsbOtg::new_fs(p.USB_OTG_FS, p.PA12, p.PA11); | ||
| 52 | let usb_bus = UsbBus::new(peri, unsafe { &mut EP_MEMORY }); | ||
| 53 | |||
| 54 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); | ||
| 55 | |||
| 56 | let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) | ||
| 57 | .manufacturer("Fake company") | ||
| 58 | .product("Serial port") | ||
| 59 | .serial_number("TEST") | ||
| 60 | .device_class(0x02) | ||
| 61 | .build(); | ||
| 62 | |||
| 63 | let irq = interrupt::take!(OTG_FS); | ||
| 64 | irq.set_priority(interrupt::Priority::P3); | ||
| 65 | |||
| 66 | let mut state = State::new(); | ||
| 67 | let usb = unsafe { Usb::new(&mut state, device, serial, irq) }; | ||
| 68 | pin_mut!(usb); | ||
| 69 | |||
| 70 | let (mut reader, mut writer) = usb.as_ref().take_serial_0(); | ||
| 71 | |||
| 72 | info!("usb initialized!"); | ||
| 73 | |||
| 74 | unwrap!( | ||
| 75 | writer | ||
| 76 | .write_all(b"\r\nInput returned upper cased on CR+LF\r\n") | ||
| 77 | .await | ||
| 78 | ); | ||
| 79 | |||
| 80 | let mut buf = [0u8; 64]; | ||
| 81 | loop { | ||
| 82 | let mut n = 0; | ||
| 83 | |||
| 84 | async { | ||
| 85 | loop { | ||
| 86 | let char = unwrap!(reader.read_byte().await); | ||
| 87 | |||
| 88 | if char == b'\r' || char == b'\n' { | ||
| 89 | break; | ||
| 90 | } | ||
| 91 | |||
| 92 | buf[n] = char; | ||
| 93 | n += 1; | ||
| 94 | |||
| 95 | // stop if we're out of room | ||
| 96 | if n == buf.len() { | ||
| 97 | break; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | .await; | ||
| 102 | |||
| 103 | if n > 0 { | ||
| 104 | for char in buf[..n].iter_mut() { | ||
| 105 | // upper case | ||
| 106 | if 0x61 <= *char && *char <= 0x7a { | ||
| 107 | *char &= !0x20; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | unwrap!(writer.write_all(&buf[..n]).await); | ||
| 111 | unwrap!(writer.write_all(b"\r\n").await); | ||
| 112 | unwrap!(writer.flush().await); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | } | ||
