Merge branch 'embassy-rs:master' into qdec
This commit is contained in:
6
examples/boot/stm32f3/.cargo/config.toml
Normal file
6
examples/boot/stm32f3/.cargo/config.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips`
|
||||
runner = "probe-run --chip STM32F303VCTx"
|
||||
|
||||
[build]
|
||||
target = "thumbv7em-none-eabihf"
|
26
examples/boot/stm32f3/Cargo.toml
Normal file
26
examples/boot/stm32f3/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
authors = ["Ulf Lilleengen <lulf@redhat.com>"]
|
||||
edition = "2021"
|
||||
name = "embassy-boot-stm32f3-examples"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" }
|
||||
embassy-traits = { version = "0.1.0", path = "../../../embassy-traits" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.3", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
cortex-m = "0.7.3"
|
||||
cortex-m-rt = "0.7.0"
|
||||
|
||||
[features]
|
||||
defmt = [
|
||||
"dep:defmt",
|
||||
"embassy-stm32/defmt",
|
||||
"embassy-boot-stm32/defmt",
|
||||
]
|
29
examples/boot/stm32f3/README.md
Normal file
29
examples/boot/stm32f3/README.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Examples using bootloader
|
||||
|
||||
Example for STM32F3 demonstrating the bootloader. The example consists of application binaries, 'a'
|
||||
which allows you to press a button to start the DFU process, and 'b' which is the updated
|
||||
application.
|
||||
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* `cargo-binutils`
|
||||
* `cargo-flash`
|
||||
* `embassy-boot-stm32`
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
# Flash bootloader
|
||||
cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f303re --chip STM32F303RETx
|
||||
# Build 'b'
|
||||
cargo build --release --bin b
|
||||
# Generate binary for 'b'
|
||||
cargo objcopy --release --bin b -- -O binary b.bin
|
||||
```
|
||||
|
||||
# Flash `a` (which includes b.bin)
|
||||
|
||||
```
|
||||
cargo flash --release --bin a --chip STM32F303RETx
|
||||
```
|
37
examples/boot/stm32f3/build.rs
Normal file
37
examples/boot/stm32f3/build.rs
Normal file
@ -0,0 +1,37 @@
|
||||
//! This build script copies the `memory.x` file from the crate root into
|
||||
//! a directory where the linker can always find it at build time.
|
||||
//! For many projects this is optional, as the linker always searches the
|
||||
//! project root directory -- wherever `Cargo.toml` is. However, if you
|
||||
//! are using a workspace or have a more complicated build setup, this
|
||||
//! build script becomes required. Additionally, by requesting that
|
||||
//! Cargo re-run the build script whenever `memory.x` is changed,
|
||||
//! updating `memory.x` ensures a rebuild of the application with the
|
||||
//! new memory settings.
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// Put `memory.x` in our output directory and ensure it's
|
||||
// on the linker search path.
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("memory.x"))
|
||||
.unwrap()
|
||||
.write_all(include_bytes!("memory.x"))
|
||||
.unwrap();
|
||||
println!("cargo:rustc-link-search={}", out.display());
|
||||
|
||||
// By default, Cargo will re-run a build script whenever
|
||||
// any file in the project changes. By specifying `memory.x`
|
||||
// here, we ensure the build script is only re-run when
|
||||
// `memory.x` is changed.
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
if env::var("CARGO_FEATURE_DEFMT").is_ok() {
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
}
|
||||
}
|
15
examples/boot/stm32f3/memory.x
Normal file
15
examples/boot/stm32f3/memory.x
Normal file
@ -0,0 +1,15 @@
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
||||
BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
|
||||
FLASH : ORIGIN = 0x08008000, LENGTH = 32K
|
||||
DFU : ORIGIN = 0x08010000, LENGTH = 36K
|
||||
RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K
|
||||
}
|
||||
|
||||
__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
|
||||
__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
|
||||
|
||||
__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
|
||||
__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER);
|
44
examples/boot/stm32f3/src/bin/a.rs
Normal file
44
examples/boot/stm32f3/src/bin/a.rs
Normal file
@ -0,0 +1,44 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use embassy_boot_stm32::FirmwareUpdater;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::flash::Flash;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::adapter::BlockingAsync;
|
||||
use panic_reset as _;
|
||||
|
||||
#[cfg(feature = "defmt-rtt")]
|
||||
use defmt_rtt::*;
|
||||
|
||||
static APP_B: &[u8] = include_bytes!("../../b.bin");
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
|
||||
let flash = Flash::unlock(p.FLASH);
|
||||
let mut flash = BlockingAsync::new(flash);
|
||||
|
||||
let button = Input::new(p.PC13, Pull::Up);
|
||||
let mut button = ExtiInput::new(button, p.EXTI13);
|
||||
|
||||
let mut led = Output::new(p.PA5, Level::Low, Speed::Low);
|
||||
led.set_high();
|
||||
|
||||
let mut updater = FirmwareUpdater::default();
|
||||
button.wait_for_falling_edge().await;
|
||||
let mut offset = 0;
|
||||
for chunk in APP_B.chunks(2048) {
|
||||
let mut buf: [u8; 2048] = [0; 2048];
|
||||
buf[..chunk.len()].copy_from_slice(chunk);
|
||||
updater
|
||||
.write_firmware(offset, &buf, &mut flash, 2048)
|
||||
.await
|
||||
.unwrap();
|
||||
offset += chunk.len();
|
||||
}
|
||||
updater.update(&mut flash).await.unwrap();
|
||||
led.set_low();
|
||||
cortex_m::peripheral::SCB::sys_reset();
|
||||
}
|
25
examples/boot/stm32f3/src/bin/b.rs
Normal file
25
examples/boot/stm32f3/src/bin/b.rs
Normal file
@ -0,0 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use panic_reset as _;
|
||||
|
||||
#[cfg(feature = "defmt-rtt")]
|
||||
use defmt_rtt::*;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut led = Output::new(p.PA5, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
6
examples/boot/stm32f7/.cargo/config.toml
Normal file
6
examples/boot/stm32f7/.cargo/config.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips`
|
||||
runner = "probe-run --chip STM32F767ZITx -v"
|
||||
|
||||
[build]
|
||||
target = "thumbv7em-none-eabihf"
|
26
examples/boot/stm32f7/Cargo.toml
Normal file
26
examples/boot/stm32f7/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
authors = ["Ulf Lilleengen <lulf@redhat.com>"]
|
||||
edition = "2021"
|
||||
name = "embassy-boot-stm32f7-examples"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" }
|
||||
embassy-traits = { version = "0.1.0", path = "../../../embassy-traits" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.3", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
cortex-m = "0.7.3"
|
||||
cortex-m-rt = "0.7.0"
|
||||
|
||||
[features]
|
||||
defmt = [
|
||||
"dep:defmt",
|
||||
"embassy-stm32/defmt",
|
||||
"embassy-boot-stm32/defmt",
|
||||
]
|
29
examples/boot/stm32f7/README.md
Normal file
29
examples/boot/stm32f7/README.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Examples using bootloader
|
||||
|
||||
Example for STM32F7 demonstrating the bootloader. The example consists of application binaries, 'a'
|
||||
which allows you to press a button to start the DFU process, and 'b' which is the updated
|
||||
application.
|
||||
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* `cargo-binutils`
|
||||
* `cargo-flash`
|
||||
* `embassy-boot-stm32`
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
# Flash bootloader
|
||||
./flash-boot.sh
|
||||
# Build 'b'
|
||||
cargo build --release --bin b
|
||||
# Generate binary for 'b'
|
||||
cargo objcopy --release --bin b -- -O binary b.bin
|
||||
```
|
||||
|
||||
# Flash `a` (which includes b.bin)
|
||||
|
||||
```
|
||||
cargo flash --release --bin a --chip STM32F767ZITx
|
||||
```
|
37
examples/boot/stm32f7/build.rs
Normal file
37
examples/boot/stm32f7/build.rs
Normal file
@ -0,0 +1,37 @@
|
||||
//! This build script copies the `memory.x` file from the crate root into
|
||||
//! a directory where the linker can always find it at build time.
|
||||
//! For many projects this is optional, as the linker always searches the
|
||||
//! project root directory -- wherever `Cargo.toml` is. However, if you
|
||||
//! are using a workspace or have a more complicated build setup, this
|
||||
//! build script becomes required. Additionally, by requesting that
|
||||
//! Cargo re-run the build script whenever `memory.x` is changed,
|
||||
//! updating `memory.x` ensures a rebuild of the application with the
|
||||
//! new memory settings.
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// Put `memory.x` in our output directory and ensure it's
|
||||
// on the linker search path.
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("memory.x"))
|
||||
.unwrap()
|
||||
.write_all(include_bytes!("memory.x"))
|
||||
.unwrap();
|
||||
println!("cargo:rustc-link-search={}", out.display());
|
||||
|
||||
// By default, Cargo will re-run a build script whenever
|
||||
// any file in the project changes. By specifying `memory.x`
|
||||
// here, we ensure the build script is only re-run when
|
||||
// `memory.x` is changed.
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
if env::var("CARGO_FEATURE_DEFMT").is_ok() {
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
}
|
||||
}
|
8
examples/boot/stm32f7/flash-boot.sh
Executable file
8
examples/boot/stm32f7/flash-boot.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
mv ../../../embassy-boot/stm32/memory.x ../../../embassy-boot/stm32/memory-old.x
|
||||
cp memory-bl.x ../../../embassy-boot/stm32/memory.x
|
||||
|
||||
cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32F767ZITx --target thumbv7em-none-eabihf
|
||||
|
||||
rm ../../../embassy-boot/stm32/memory.x
|
||||
mv ../../../embassy-boot/stm32/memory-old.x ../../../embassy-boot/stm32/memory.x
|
18
examples/boot/stm32f7/memory-bl.x
Normal file
18
examples/boot/stm32f7/memory-bl.x
Normal file
@ -0,0 +1,18 @@
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K
|
||||
ACTIVE : ORIGIN = 0x08080000, LENGTH = 256K
|
||||
DFU : ORIGIN = 0x080c0000, LENGTH = 512K
|
||||
RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 368K + 16K
|
||||
}
|
||||
|
||||
__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH);
|
||||
__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH);
|
||||
|
||||
__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH);
|
||||
__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH);
|
||||
|
||||
__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH);
|
||||
__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH);
|
15
examples/boot/stm32f7/memory.x
Normal file
15
examples/boot/stm32f7/memory.x
Normal file
@ -0,0 +1,15 @@
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
||||
BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 256K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K
|
||||
FLASH : ORIGIN = 0x08080000, LENGTH = 256K
|
||||
DFU : ORIGIN = 0x080c0000, LENGTH = 512K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 368K + 16K
|
||||
}
|
||||
|
||||
__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
|
||||
__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
|
||||
|
||||
__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
|
||||
__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER);
|
44
examples/boot/stm32f7/src/bin/a.rs
Normal file
44
examples/boot/stm32f7/src/bin/a.rs
Normal file
@ -0,0 +1,44 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use embassy_boot_stm32::FirmwareUpdater;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::flash::Flash;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::adapter::BlockingAsync;
|
||||
use panic_reset as _;
|
||||
|
||||
#[cfg(feature = "defmt-rtt")]
|
||||
use defmt_rtt::*;
|
||||
|
||||
static APP_B: &[u8] = include_bytes!("../../b.bin");
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
|
||||
let flash = Flash::unlock(p.FLASH);
|
||||
let mut flash = BlockingAsync::new(flash);
|
||||
|
||||
let button = Input::new(p.PC13, Pull::Down);
|
||||
let mut button = ExtiInput::new(button, p.EXTI13);
|
||||
|
||||
let mut led = Output::new(p.PB7, Level::Low, Speed::Low);
|
||||
led.set_high();
|
||||
|
||||
let mut updater = FirmwareUpdater::default();
|
||||
button.wait_for_rising_edge().await;
|
||||
let mut offset = 0;
|
||||
let mut buf: [u8; 256 * 1024] = [0; 256 * 1024];
|
||||
for chunk in APP_B.chunks(256 * 1024) {
|
||||
buf[..chunk.len()].copy_from_slice(chunk);
|
||||
updater
|
||||
.write_firmware(offset, &buf, &mut flash, 2048)
|
||||
.await
|
||||
.unwrap();
|
||||
offset += chunk.len();
|
||||
}
|
||||
updater.update(&mut flash).await.unwrap();
|
||||
led.set_low();
|
||||
cortex_m::peripheral::SCB::sys_reset();
|
||||
}
|
27
examples/boot/stm32f7/src/bin/b.rs
Normal file
27
examples/boot/stm32f7/src/bin/b.rs
Normal file
@ -0,0 +1,27 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use panic_reset as _;
|
||||
|
||||
#[cfg(feature = "defmt-rtt")]
|
||||
use defmt_rtt::*;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
let mut led = Output::new(p.PB7, Level::High, Speed::Low);
|
||||
led.set_high();
|
||||
|
||||
loop {
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
6
examples/boot/stm32h7/.cargo/config.toml
Normal file
6
examples/boot/stm32h7/.cargo/config.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips`
|
||||
runner = "probe-run --chip STM32H743ZITx"
|
||||
|
||||
[build]
|
||||
target = "thumbv7em-none-eabihf"
|
26
examples/boot/stm32h7/Cargo.toml
Normal file
26
examples/boot/stm32h7/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
authors = ["Ulf Lilleengen <lulf@redhat.com>"]
|
||||
edition = "2021"
|
||||
name = "embassy-boot-stm32f7-examples"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" }
|
||||
embassy-traits = { version = "0.1.0", path = "../../../embassy-traits" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.3", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
cortex-m = "0.7.3"
|
||||
cortex-m-rt = "0.7.0"
|
||||
|
||||
[features]
|
||||
defmt = [
|
||||
"dep:defmt",
|
||||
"embassy-stm32/defmt",
|
||||
"embassy-boot-stm32/defmt",
|
||||
]
|
29
examples/boot/stm32h7/README.md
Normal file
29
examples/boot/stm32h7/README.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Examples using bootloader
|
||||
|
||||
Example for STM32H7 demonstrating the bootloader. The example consists of application binaries, 'a'
|
||||
which allows you to press a button to start the DFU process, and 'b' which is the updated
|
||||
application.
|
||||
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* `cargo-binutils`
|
||||
* `cargo-flash`
|
||||
* `embassy-boot-stm32`
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
# Flash bootloader
|
||||
./flash-boot.sh
|
||||
# Build 'b'
|
||||
cargo build --release --bin b
|
||||
# Generate binary for 'b'
|
||||
cargo objcopy --release --bin b -- -O binary b.bin
|
||||
```
|
||||
|
||||
# Flash `a` (which includes b.bin)
|
||||
|
||||
```
|
||||
cargo flash --release --bin a --chip STM32H743ZITx
|
||||
```
|
37
examples/boot/stm32h7/build.rs
Normal file
37
examples/boot/stm32h7/build.rs
Normal file
@ -0,0 +1,37 @@
|
||||
//! This build script copies the `memory.x` file from the crate root into
|
||||
//! a directory where the linker can always find it at build time.
|
||||
//! For many projects this is optional, as the linker always searches the
|
||||
//! project root directory -- wherever `Cargo.toml` is. However, if you
|
||||
//! are using a workspace or have a more complicated build setup, this
|
||||
//! build script becomes required. Additionally, by requesting that
|
||||
//! Cargo re-run the build script whenever `memory.x` is changed,
|
||||
//! updating `memory.x` ensures a rebuild of the application with the
|
||||
//! new memory settings.
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// Put `memory.x` in our output directory and ensure it's
|
||||
// on the linker search path.
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("memory.x"))
|
||||
.unwrap()
|
||||
.write_all(include_bytes!("memory.x"))
|
||||
.unwrap();
|
||||
println!("cargo:rustc-link-search={}", out.display());
|
||||
|
||||
// By default, Cargo will re-run a build script whenever
|
||||
// any file in the project changes. By specifying `memory.x`
|
||||
// here, we ensure the build script is only re-run when
|
||||
// `memory.x` is changed.
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
if env::var("CARGO_FEATURE_DEFMT").is_ok() {
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
}
|
||||
}
|
8
examples/boot/stm32h7/flash-boot.sh
Executable file
8
examples/boot/stm32h7/flash-boot.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
mv ../../../embassy-boot/stm32/memory.x ../../../embassy-boot/stm32/memory-old.x
|
||||
cp memory-bl.x ../../../embassy-boot/stm32/memory.x
|
||||
|
||||
cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32H743ZITx --target thumbv7em-none-eabihf
|
||||
|
||||
rm ../../../embassy-boot/stm32/memory.x
|
||||
mv ../../../embassy-boot/stm32/memory-old.x ../../../embassy-boot/stm32/memory.x
|
18
examples/boot/stm32h7/memory-bl.x
Normal file
18
examples/boot/stm32h7/memory-bl.x
Normal file
@ -0,0 +1,18 @@
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K
|
||||
ACTIVE : ORIGIN = 0x08040000, LENGTH = 128K
|
||||
DFU : ORIGIN = 0x08100000, LENGTH = 512K
|
||||
RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K
|
||||
}
|
||||
|
||||
__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH);
|
||||
__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH);
|
||||
|
||||
__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH);
|
||||
__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH);
|
||||
|
||||
__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH);
|
||||
__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH);
|
15
examples/boot/stm32h7/memory.x
Normal file
15
examples/boot/stm32h7/memory.x
Normal file
@ -0,0 +1,15 @@
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
||||
BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K
|
||||
FLASH : ORIGIN = 0x08040000, LENGTH = 256K
|
||||
DFU : ORIGIN = 0x08100000, LENGTH = 512K
|
||||
RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K
|
||||
}
|
||||
|
||||
__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
|
||||
__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
|
||||
|
||||
__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
|
||||
__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER);
|
44
examples/boot/stm32h7/src/bin/a.rs
Normal file
44
examples/boot/stm32h7/src/bin/a.rs
Normal file
@ -0,0 +1,44 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use embassy_boot_stm32::FirmwareUpdater;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::flash::Flash;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::adapter::BlockingAsync;
|
||||
use panic_reset as _;
|
||||
|
||||
#[cfg(feature = "defmt-rtt")]
|
||||
use defmt_rtt::*;
|
||||
|
||||
static APP_B: &[u8] = include_bytes!("../../b.bin");
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
|
||||
let flash = Flash::unlock(p.FLASH);
|
||||
let mut flash = BlockingAsync::new(flash);
|
||||
|
||||
let button = Input::new(p.PC13, Pull::Down);
|
||||
let mut button = ExtiInput::new(button, p.EXTI13);
|
||||
|
||||
let mut led = Output::new(p.PB14, Level::Low, Speed::Low);
|
||||
led.set_high();
|
||||
|
||||
let mut updater = FirmwareUpdater::default();
|
||||
button.wait_for_rising_edge().await;
|
||||
let mut offset = 0;
|
||||
let mut buf: [u8; 128 * 1024] = [0; 128 * 1024];
|
||||
for chunk in APP_B.chunks(128 * 1024) {
|
||||
buf[..chunk.len()].copy_from_slice(chunk);
|
||||
updater
|
||||
.write_firmware(offset, &buf, &mut flash, 2048)
|
||||
.await
|
||||
.unwrap();
|
||||
offset += chunk.len();
|
||||
}
|
||||
updater.update(&mut flash).await.unwrap();
|
||||
led.set_low();
|
||||
cortex_m::peripheral::SCB::sys_reset();
|
||||
}
|
27
examples/boot/stm32h7/src/bin/b.rs
Normal file
27
examples/boot/stm32h7/src/bin/b.rs
Normal file
@ -0,0 +1,27 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use panic_reset as _;
|
||||
|
||||
#[cfg(feature = "defmt-rtt")]
|
||||
use defmt_rtt::*;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
let mut led = Output::new(p.PB14, Level::High, Speed::Low);
|
||||
led.set_high();
|
||||
|
||||
loop {
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ version = "0.1.0"
|
||||
|
||||
[features]
|
||||
default = ["nightly"]
|
||||
nightly = ["embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm"]
|
||||
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"]
|
||||
|
||||
[dependencies]
|
||||
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
|
||||
embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"], optional = true }
|
||||
embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features = ["defmt"], optional = true }
|
||||
embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", features = ["defmt"], optional = true }
|
||||
embedded-io = "0.2.0"
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.3"
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
use defmt::*;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use embassy_nrf::buffered_uarte::State;
|
||||
use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals};
|
||||
use embedded_io::asynch::{Read, Write};
|
||||
use futures::pin_mut;
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
|
@ -10,9 +10,9 @@ use defmt::*;
|
||||
use embassy::blocking_mutex::raw::ThreadModeRawMutex;
|
||||
use embassy::channel::Channel;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use embassy::util::Forever;
|
||||
use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, TcpSocket};
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{PacketBox, PacketBoxExt, PacketBuf};
|
||||
use embassy_nrf::pac;
|
||||
use embassy_nrf::usb::Driver;
|
||||
use embassy_nrf::Peripherals;
|
||||
@ -20,7 +20,9 @@ use embassy_nrf::{interrupt, peripherals};
|
||||
use embassy_usb::{Builder, Config, UsbDevice};
|
||||
use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use defmt_rtt as _;
|
||||
use embedded_io::asynch::{Read, Write};
|
||||
// global logger
|
||||
use panic_probe as _;
|
||||
|
||||
type MyDriver = Driver<'static, peripherals::USBD>;
|
||||
|
@ -6,7 +6,8 @@ version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["log", "std", "time", "nightly"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features=["std", "log", "medium-ethernet", "tcp", "dhcpv4", "pool-16"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features=["nightly", "std", "log", "medium-ethernet", "tcp", "dhcpv4", "pool-16"] }
|
||||
embedded-io = { version = "0.2.0", features = ["async", "std"] }
|
||||
|
||||
async-io = "1.6.0"
|
||||
env_logger = "0.9.0"
|
||||
|
@ -2,12 +2,13 @@
|
||||
|
||||
use clap::Parser;
|
||||
use embassy::executor::{Executor, Spawner};
|
||||
use embassy::io::AsyncWriteExt;
|
||||
use embassy::util::Forever;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{
|
||||
Config, Configurator, DhcpConfigurator, Ipv4Address, Ipv4Cidr, StackResources,
|
||||
StaticConfigurator, TcpSocket,
|
||||
StaticConfigurator,
|
||||
};
|
||||
use embedded_io::asynch::Write;
|
||||
use heapless::Vec;
|
||||
use log::*;
|
||||
|
||||
|
@ -5,8 +5,8 @@ mod serial_port;
|
||||
|
||||
use async_io::Async;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::io::AsyncBufReadExt;
|
||||
use embassy::util::Forever;
|
||||
use embedded_io::asynch::Read;
|
||||
use log::*;
|
||||
use nix::sys::termios;
|
||||
|
||||
@ -24,12 +24,12 @@ async fn run() {
|
||||
// Essentially, async_io::Async converts from AsRawFd+Read+Write to futures's AsyncRead+AsyncWrite
|
||||
let port = Async::new(port).unwrap();
|
||||
|
||||
// This implements futures's AsyncBufRead based on futures's AsyncRead
|
||||
let port = futures::io::BufReader::new(port);
|
||||
|
||||
// We can then use FromStdIo to convert from futures's AsyncBufRead+AsyncWrite
|
||||
// to embassy's AsyncBufRead+AsyncWrite
|
||||
let mut port = embassy::io::FromStdIo::new(port);
|
||||
// We can then use FromStdIo to convert from futures's AsyncRead+AsyncWrite
|
||||
// to embedded_io's async Read+Write.
|
||||
//
|
||||
// This is not really needed, you could write the code below using futures::io directly.
|
||||
// It's useful if you want to have portable code across embedded and std.
|
||||
let mut port = embedded_io::adapters::FromFutures::new(port);
|
||||
|
||||
info!("Serial opened!");
|
||||
|
||||
|
@ -19,3 +19,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
nb = "1.0.0"
|
||||
embedded-storage = "0.3.0"
|
||||
|
@ -15,7 +15,7 @@ use panic_probe as _;
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hello World!");
|
||||
|
||||
let mut led = Output::new(p.PE12, Level::High, Speed::Low);
|
||||
let mut led = Output::new(p.PA5, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
|
43
examples/stm32f3/src/bin/flash.rs
Normal file
43
examples/stm32f3/src/bin/flash.rs
Normal file
@ -0,0 +1,43 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_stm32::flash::Flash;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use panic_probe as _;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hello Flash!");
|
||||
|
||||
const ADDR: u32 = 0x26000;
|
||||
|
||||
let mut f = Flash::unlock(p.FLASH);
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 8];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read: {=[u8]:x}", buf);
|
||||
|
||||
info!("Erasing...");
|
||||
unwrap!(f.erase(ADDR, ADDR + 2048));
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 8];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read after erase: {=[u8]:x}", buf);
|
||||
|
||||
info!("Writing...");
|
||||
unwrap!(f.write(ADDR, &[1, 2, 3, 4, 5, 6, 7, 8]));
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 8];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read: {=[u8]:x}", buf);
|
||||
assert_eq!(&buf[..], &[1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
}
|
@ -8,7 +8,7 @@ resolver = "2"
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits"] }
|
||||
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"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.3"
|
||||
|
@ -1,99 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use panic_probe as _;
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use defmt_rtt as _; // global logger
|
||||
use embassy::interrupt::InterruptExt;
|
||||
use futures::pin_mut;
|
||||
use panic_probe as _; // print out panic messages
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use embassy_stm32::usb_otg::{State, Usb, UsbBus, UsbOtg, UsbSerial};
|
||||
use embassy_stm32::{interrupt, time::Hertz, Config, Peripherals};
|
||||
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
|
||||
|
||||
static mut EP_MEMORY: [u32; 2048] = [0; 2048];
|
||||
|
||||
// USB requires at least 48 MHz clock
|
||||
fn config() -> Config {
|
||||
let mut config = Config::default();
|
||||
config.rcc.sys_ck = Some(Hertz(48_000_000));
|
||||
config
|
||||
}
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut rx_buffer = [0u8; 64];
|
||||
// we send back input + cr + lf
|
||||
let mut tx_buffer = [0u8; 66];
|
||||
|
||||
let peri = UsbOtg::new_fs(p.USB_OTG_FS, p.PA12, p.PA11);
|
||||
let usb_bus = UsbBus::new(peri, unsafe { &mut EP_MEMORY });
|
||||
|
||||
let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer);
|
||||
|
||||
let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
|
||||
.manufacturer("Fake company")
|
||||
.product("Serial port")
|
||||
.serial_number("TEST")
|
||||
.device_class(0x02)
|
||||
.build();
|
||||
|
||||
let irq = interrupt::take!(OTG_FS);
|
||||
irq.set_priority(interrupt::Priority::P3);
|
||||
|
||||
let mut state = State::new();
|
||||
let usb = unsafe { Usb::new(&mut state, device, serial, irq) };
|
||||
pin_mut!(usb);
|
||||
|
||||
let (mut reader, mut writer) = usb.as_ref().take_serial_0();
|
||||
|
||||
info!("usb initialized!");
|
||||
|
||||
unwrap!(
|
||||
writer
|
||||
.write_all(b"\r\nInput returned upper cased on CR+LF\r\n")
|
||||
.await
|
||||
);
|
||||
|
||||
let mut buf = [0u8; 64];
|
||||
loop {
|
||||
let mut n = 0;
|
||||
|
||||
async {
|
||||
loop {
|
||||
let char = unwrap!(reader.read_byte().await);
|
||||
|
||||
if char == b'\r' || char == b'\n' {
|
||||
break;
|
||||
}
|
||||
|
||||
buf[n] = char;
|
||||
n += 1;
|
||||
|
||||
// stop if we're out of room
|
||||
if n == buf.len() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
.await;
|
||||
|
||||
if n > 0 {
|
||||
for char in buf[..n].iter_mut() {
|
||||
// upper case
|
||||
if 0x61 <= *char && *char <= 0x7a {
|
||||
*char &= !0x20;
|
||||
}
|
||||
}
|
||||
unwrap!(writer.write_all(&buf[..n]).await);
|
||||
unwrap!(writer.write_all(b"\r\n").await);
|
||||
unwrap!(writer.flush().await);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use panic_probe as _;
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use defmt_rtt as _; // global logger
|
||||
use embassy::interrupt::InterruptExt;
|
||||
use futures::pin_mut;
|
||||
use panic_probe as _; // print out panic messages
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use embassy_stm32::usb_otg::{State, Usb, UsbBus, UsbOtg, UsbSerial};
|
||||
use embassy_stm32::{interrupt, time::Hertz, Config, Peripherals};
|
||||
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
|
||||
|
||||
static mut EP_MEMORY: [u32; 2048] = [0; 2048];
|
||||
|
||||
// USB requires at least 48 MHz clock
|
||||
fn config() -> Config {
|
||||
let mut config = Config::default();
|
||||
config.rcc.sys_ck = Some(Hertz(48_000_000));
|
||||
config
|
||||
}
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut rx_buffer = [0u8; 64];
|
||||
// we send back input + cr + lf
|
||||
let mut tx_buffer = [0u8; 66];
|
||||
|
||||
// USB with external high-speed PHY
|
||||
let peri = UsbOtg::new_hs_ulpi(
|
||||
p.USB_OTG_HS,
|
||||
p.PA5,
|
||||
p.PC2,
|
||||
p.PC3,
|
||||
p.PC0,
|
||||
p.PA3,
|
||||
p.PB0,
|
||||
p.PB1,
|
||||
p.PB10,
|
||||
p.PB11,
|
||||
p.PB12,
|
||||
p.PB13,
|
||||
p.PB5,
|
||||
);
|
||||
let usb_bus = UsbBus::new(peri, unsafe { &mut EP_MEMORY });
|
||||
|
||||
let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer);
|
||||
|
||||
let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
|
||||
.manufacturer("Fake company")
|
||||
.product("Serial port")
|
||||
.serial_number("TEST")
|
||||
.device_class(0x02)
|
||||
.build();
|
||||
|
||||
let irq = interrupt::take!(OTG_FS);
|
||||
irq.set_priority(interrupt::Priority::P3);
|
||||
|
||||
let mut state = State::new();
|
||||
let usb = unsafe { Usb::new(&mut state, device, serial, irq) };
|
||||
pin_mut!(usb);
|
||||
|
||||
let (mut reader, mut writer) = usb.as_ref().take_serial_0();
|
||||
|
||||
info!("usb initialized!");
|
||||
|
||||
unwrap!(
|
||||
writer
|
||||
.write_all(b"\r\nInput returned upper cased on CR+LF\r\n")
|
||||
.await
|
||||
);
|
||||
|
||||
let mut buf = [0u8; 64];
|
||||
loop {
|
||||
let mut n = 0;
|
||||
|
||||
async {
|
||||
loop {
|
||||
let char = unwrap!(reader.read_byte().await);
|
||||
|
||||
if char == b'\r' || char == b'\n' {
|
||||
break;
|
||||
}
|
||||
|
||||
buf[n] = char;
|
||||
n += 1;
|
||||
|
||||
// stop if we're out of room
|
||||
if n == buf.len() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
.await;
|
||||
|
||||
if n > 0 {
|
||||
for char in buf[..n].iter_mut() {
|
||||
// upper case
|
||||
if 0x61 <= *char && *char <= 0x7a {
|
||||
*char &= !0x20;
|
||||
}
|
||||
}
|
||||
unwrap!(writer.write_all(&buf[..n]).await);
|
||||
unwrap!(writer.write_all(b"\r\n").await);
|
||||
unwrap!(writer.flush().await);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ resolver = "2"
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] }
|
||||
embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "medium-ethernet", "pool-16"] }
|
||||
embedded-io = { version = "0.2.0", features = ["async"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.3"
|
||||
@ -22,6 +23,7 @@ heapless = { version = "0.7.5", default-features = false }
|
||||
nb = "1.0.0"
|
||||
rand_core = "0.6.3"
|
||||
critical-section = "0.2.3"
|
||||
embedded-storage = "0.3.0"
|
||||
|
||||
[dependencies.smoltcp]
|
||||
version = "0.8.0"
|
||||
|
@ -5,12 +5,10 @@
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::*;
|
||||
use embassy::executor::{Executor, Spawner};
|
||||
use embassy::io::AsyncWriteExt;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy::util::Forever;
|
||||
use embassy_net::{
|
||||
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
||||
};
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator};
|
||||
use embassy_stm32::eth::generic_smi::GenericSMI;
|
||||
use embassy_stm32::eth::{Ethernet, State};
|
||||
use embassy_stm32::interrupt;
|
||||
@ -19,6 +17,7 @@ use embassy_stm32::peripherals::RNG;
|
||||
use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::time::U32Ext;
|
||||
use embassy_stm32::Config;
|
||||
use embedded_io::asynch::Write;
|
||||
use heapless::Vec;
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
|
59
examples/stm32f7/src/bin/flash.rs
Normal file
59
examples/stm32f7/src/bin/flash.rs
Normal file
@ -0,0 +1,59 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::flash::Flash;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use panic_probe as _;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hello Flash!");
|
||||
|
||||
const ADDR: u32 = 0x8_0000;
|
||||
|
||||
// wait a bit before accessing the flash
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
let mut f = Flash::unlock(p.FLASH);
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read: {=[u8]:x}", buf);
|
||||
|
||||
info!("Erasing...");
|
||||
unwrap!(f.erase(ADDR, ADDR + 256 * 1024));
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read after erase: {=[u8]:x}", buf);
|
||||
|
||||
info!("Writing...");
|
||||
unwrap!(f.write(
|
||||
ADDR,
|
||||
&[
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32
|
||||
]
|
||||
));
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read: {=[u8]:x}", buf);
|
||||
assert_eq!(
|
||||
&buf[..],
|
||||
&[
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32
|
||||
]
|
||||
);
|
||||
}
|
@ -5,12 +5,11 @@ name = "embassy-stm32h7-examples"
|
||||
version = "0.1.0"
|
||||
resolver = "2"
|
||||
|
||||
[features]
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
|
||||
embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "medium-ethernet", "pool-16"] }
|
||||
embedded-io = { version = "0.2.0", features = ["async"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.3"
|
||||
@ -27,6 +26,7 @@ rand_core = "0.6.3"
|
||||
critical-section = "0.2.5"
|
||||
micromath = "2.0.0"
|
||||
stm32-fmc = "0.2.4"
|
||||
embedded-storage = "0.3.0"
|
||||
|
||||
[dependencies.smoltcp]
|
||||
version = "0.8.0"
|
||||
|
@ -8,12 +8,10 @@ use panic_probe as _;
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::*;
|
||||
use embassy::executor::{Executor, Spawner};
|
||||
use embassy::io::AsyncWriteExt;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy::util::Forever;
|
||||
use embassy_net::{
|
||||
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
||||
};
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator};
|
||||
use embassy_stm32::eth::generic_smi::GenericSMI;
|
||||
use embassy_stm32::eth::{Ethernet, State};
|
||||
use embassy_stm32::interrupt;
|
||||
@ -22,6 +20,7 @@ use embassy_stm32::peripherals::RNG;
|
||||
use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::time::U32Ext;
|
||||
use embassy_stm32::Config;
|
||||
use embedded_io::asynch::Write;
|
||||
use heapless::Vec;
|
||||
|
||||
#[embassy::task]
|
||||
|
58
examples/stm32h7/src/bin/flash.rs
Normal file
58
examples/stm32h7/src/bin/flash.rs
Normal file
@ -0,0 +1,58 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use defmt_rtt as _; // global logger
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::flash::Flash;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
|
||||
use panic_probe as _;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hello Flash!");
|
||||
|
||||
const ADDR: u32 = 0x08_0000;
|
||||
|
||||
// wait a bit before accessing the flash
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
let mut f = Flash::unlock(p.FLASH);
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read: {=[u8]:x}", buf);
|
||||
|
||||
info!("Erasing...");
|
||||
unwrap!(f.erase(ADDR, ADDR + 128 * 1024));
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read after erase: {=[u8]:x}", buf);
|
||||
|
||||
info!("Writing...");
|
||||
unwrap!(f.write(
|
||||
ADDR,
|
||||
&[
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32
|
||||
]
|
||||
));
|
||||
|
||||
info!("Reading...");
|
||||
let mut buf = [0u8; 32];
|
||||
unwrap!(f.read(ADDR, &mut buf));
|
||||
info!("Read: {=[u8]:x}", buf);
|
||||
assert_eq!(
|
||||
&buf[..],
|
||||
&[
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32
|
||||
]
|
||||
);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace your chip as listed in `probe-run --list-chips`
|
||||
runner = "probe-run --chip STM32L072CZTx"
|
||||
runner = "probe-run --chip STM32L053R8Tx"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
||||
|
@ -7,12 +7,11 @@ resolver = "2"
|
||||
|
||||
[features]
|
||||
default = ["nightly"]
|
||||
nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan"]
|
||||
nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan", "embedded-io/async"]
|
||||
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
|
||||
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true}
|
||||
|
||||
lorawan-device = { version = "0.7.1", default-features = false, features = ["async"], optional = true }
|
||||
@ -22,6 +21,7 @@ defmt = "0.3"
|
||||
defmt-rtt = "0.3"
|
||||
|
||||
embedded-storage = "0.3.0"
|
||||
embedded-io = "0.2.0"
|
||||
|
||||
cortex-m = "0.7.3"
|
||||
cortex-m-rt = "0.7.0"
|
||||
|
@ -2,13 +2,14 @@
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use defmt_rtt as _;
|
||||
use embedded_io::asynch::{Read, Write};
|
||||
// global logger
|
||||
use panic_probe as _;
|
||||
|
||||
use defmt::*;
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::interrupt;
|
||||
use embassy_stm32::usart::{BufferedUart, Config, State, Uart};
|
||||
@ -16,19 +17,21 @@ use embassy_stm32::Peripherals;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hi!");
|
||||
|
||||
static mut TX_BUFFER: [u8; 8] = [0; 8];
|
||||
static mut RX_BUFFER: [u8; 256] = [0; 256];
|
||||
|
||||
let mut config = Config::default();
|
||||
config.baudrate = 9600;
|
||||
|
||||
let usart = Uart::new(p.USART1, p.PA10, p.PA9, NoDma, NoDma, config);
|
||||
let usart = Uart::new(p.USART2, p.PA3, p.PA2, NoDma, NoDma, config);
|
||||
let mut state = State::new();
|
||||
let mut usart = unsafe {
|
||||
BufferedUart::new(
|
||||
&mut state,
|
||||
usart,
|
||||
interrupt::take!(USART1),
|
||||
interrupt::take!(USART2),
|
||||
&mut TX_BUFFER,
|
||||
&mut RX_BUFFER,
|
||||
)
|
||||
|
@ -10,7 +10,7 @@ resolver = "2"
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits" }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits", "usb-otg"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.3"
|
||||
|
@ -1,115 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use panic_probe as _;
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use defmt_rtt as _; // global logger
|
||||
use embassy::interrupt::InterruptExt;
|
||||
use futures::pin_mut;
|
||||
use panic_probe as _; // print out panic messages
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use embassy_stm32::pac::pwr::vals::Usv;
|
||||
use embassy_stm32::pac::{PWR, RCC};
|
||||
use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
|
||||
use embassy_stm32::usb_otg::{State, Usb, UsbBus, UsbOtg, UsbSerial};
|
||||
use embassy_stm32::{interrupt, Config, Peripherals};
|
||||
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
|
||||
|
||||
static mut EP_MEMORY: [u32; 2048] = [0; 2048];
|
||||
|
||||
// USB requires at least 48 MHz clock
|
||||
fn config() -> Config {
|
||||
let mut config = Config::default();
|
||||
// set up a 80Mhz clock
|
||||
config.rcc.mux = ClockSrc::PLL(
|
||||
PLLSource::HSI16,
|
||||
PLLClkDiv::Div2,
|
||||
PLLSrcDiv::Div2,
|
||||
PLLMul::Mul20,
|
||||
None,
|
||||
);
|
||||
// enable HSI48 clock for USB
|
||||
config.rcc.hsi48 = true;
|
||||
config
|
||||
}
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
// Enable PWR peripheral
|
||||
unsafe { RCC.apb1enr1().modify(|w| w.set_pwren(true)) };
|
||||
unsafe { PWR.cr2().modify(|w| w.set_usv(Usv::VALID)) }
|
||||
|
||||
let mut rx_buffer = [0u8; 64];
|
||||
// we send back input + cr + lf
|
||||
let mut tx_buffer = [0u8; 66];
|
||||
|
||||
let peri = UsbOtg::new_fs(p.USB_OTG_FS, p.PA12, p.PA11);
|
||||
let usb_bus = UsbBus::new(peri, unsafe { &mut EP_MEMORY });
|
||||
|
||||
let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer);
|
||||
|
||||
let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
|
||||
.manufacturer("Fake company")
|
||||
.product("Serial port")
|
||||
.serial_number("TEST")
|
||||
.device_class(0x02)
|
||||
.build();
|
||||
|
||||
let irq = interrupt::take!(OTG_FS);
|
||||
irq.set_priority(interrupt::Priority::P3);
|
||||
|
||||
let mut state = State::new();
|
||||
let usb = unsafe { Usb::new(&mut state, device, serial, irq) };
|
||||
pin_mut!(usb);
|
||||
|
||||
let (mut reader, mut writer) = usb.as_ref().take_serial_0();
|
||||
|
||||
info!("usb initialized!");
|
||||
|
||||
unwrap!(
|
||||
writer
|
||||
.write_all(b"\r\nInput returned upper cased on CR+LF\r\n")
|
||||
.await
|
||||
);
|
||||
|
||||
let mut buf = [0u8; 64];
|
||||
loop {
|
||||
let mut n = 0;
|
||||
|
||||
async {
|
||||
loop {
|
||||
let char = unwrap!(reader.read_byte().await);
|
||||
|
||||
if char == b'\r' || char == b'\n' {
|
||||
break;
|
||||
}
|
||||
|
||||
buf[n] = char;
|
||||
n += 1;
|
||||
|
||||
// stop if we're out of room
|
||||
if n == buf.len() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
.await;
|
||||
|
||||
if n > 0 {
|
||||
for char in buf[..n].iter_mut() {
|
||||
// upper case
|
||||
if 0x61 <= *char && *char <= 0x7a {
|
||||
*char &= !0x20;
|
||||
}
|
||||
}
|
||||
unwrap!(writer.write_all(&buf[..n]).await);
|
||||
unwrap!(writer.write_all(b"\r\n").await);
|
||||
unwrap!(writer.flush().await);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user