merge new embassy changes
This commit is contained in:
@@ -5,16 +5,16 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-16384", "arch-cortex-m", "executor-thread", "integrated-timers", "arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [] }
|
||||
embassy-nrf = { version = "0.2.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] }
|
||||
embassy-boot = { version = "0.3.0", path = "../../../../embassy-boot", features = [] }
|
||||
embassy-boot-nrf = { version = "0.3.0", path = "../../../../embassy-boot-nrf", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [] }
|
||||
embassy-nrf = { version = "0.3.1", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] }
|
||||
embassy-boot = { version = "0.4.0", path = "../../../../embassy-boot", features = [] }
|
||||
embassy-boot-nrf = { version = "0.4.0", path = "../../../../embassy-boot-nrf", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
|
||||
@@ -31,4 +31,7 @@ fn main() {
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
|
||||
#[cfg(feature = "defmt")]
|
||||
use defmt_rtt as _;
|
||||
use embassy_boot::State;
|
||||
use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig};
|
||||
use embassy_embedded_hal::adapter::BlockingAsync;
|
||||
use embassy_executor::Spawner;
|
||||
@@ -22,6 +25,7 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
let mut button = Input::new(p.P0_11, Pull::Up);
|
||||
let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
|
||||
let mut led_reverted = Output::new(p.P0_14, Level::High, OutputDrive::Standard);
|
||||
|
||||
//let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
|
||||
//let mut button = Input::new(p.P1_02, Pull::Up);
|
||||
@@ -53,6 +57,13 @@ async fn main(_spawner: Spawner) {
|
||||
let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc, &nvmc);
|
||||
let mut magic = [0; 4];
|
||||
let mut updater = FirmwareUpdater::new(config, &mut magic);
|
||||
let state = updater.get_state().await.unwrap();
|
||||
if state == State::Revert {
|
||||
led_reverted.set_low();
|
||||
} else {
|
||||
led_reverted.set_high();
|
||||
}
|
||||
|
||||
loop {
|
||||
led.set_low();
|
||||
button.wait_for_any_edge().await;
|
||||
|
||||
@@ -5,16 +5,16 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-16384", "arch-cortex-m", "executor-thread", "integrated-timers", "arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [] }
|
||||
embassy-rp = { version = "0.2.0", path = "../../../../embassy-rp", features = ["time-driver", "rp2040"] }
|
||||
embassy-boot-rp = { version = "0.3.0", path = "../../../../embassy-boot-rp", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [] }
|
||||
embassy-rp = { version = "0.4.0", path = "../../../../embassy-rp", features = ["time-driver", "rp2040"] }
|
||||
embassy-boot-rp = { version = "0.5.0", path = "../../../../embassy-boot-rp", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"], optional = true }
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"], optional = true }
|
||||
panic-reset = { version = "0.1.1", optional = true }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32f303re", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32" }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32f303re", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.3.0", path = "../../../../embassy-boot-stm32" }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32f767zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32f767zi", "time-driver-any", "exti", "single-bank"] }
|
||||
embassy-boot-stm32 = { version = "0.3.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
embedded-storage = "0.3.1"
|
||||
|
||||
@@ -5,15 +5,15 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32h743zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32h743zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.3.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
embedded-storage = "0.3.1"
|
||||
|
||||
@@ -5,15 +5,15 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l072cz", "time-driver-any", "exti", "memory-x"] }
|
||||
embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32l072cz", "time-driver-any", "exti", "memory-x"] }
|
||||
embassy-boot-stm32 = { version = "0.3.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l151cb-a", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32l151cb-a", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.3.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.3.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32wb55rg", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-usb = { version = "0.3.0", path = "../../../../embassy-usb" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32wb55rg", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.3.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-usb = { version = "0.4.0", path = "../../../../embassy-usb" }
|
||||
embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["application", "cortex-m"] }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
||||
BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
|
||||
FLASH : ORIGIN = 0x08008000, LENGTH = 128K
|
||||
DFU : ORIGIN = 0x08028000, LENGTH = 132K
|
||||
BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 48K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x0800C000, LENGTH = 4K
|
||||
FLASH : ORIGIN = 0x0800D000, LENGTH = 120K
|
||||
DFU : ORIGIN = 0x0802B000, LENGTH = 120K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
}
|
||||
|
||||
|
||||
2
examples/boot/application/stm32wb-dfu/secrets/key.sec
Normal file
2
examples/boot/application/stm32wb-dfu/secrets/key.sec
Normal file
@@ -0,0 +1,2 @@
|
||||
untrusted comment: signify secret key
|
||||
RWRCSwAAAAATdHQF3B4jEIoNZrjADRp2LbjJjNdNNzKwTCe4IB6mDNq96pe53nbNxwbdCc/T4hrz7W+Kx1MwrZ0Yz5xebSK5Z0Kh/3Cdf039U5f+eoTDS2fIGbohyUbrtwKzjyE0qXI=
|
||||
@@ -13,7 +13,7 @@ use embassy_stm32::usb::{self, Driver};
|
||||
use embassy_stm32::{bind_interrupts, peripherals};
|
||||
use embassy_sync::blocking_mutex::Mutex;
|
||||
use embassy_time::Duration;
|
||||
use embassy_usb::Builder;
|
||||
use embassy_usb::{msos, Builder};
|
||||
use embassy_usb_dfu::consts::DfuAttributes;
|
||||
use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate};
|
||||
use panic_reset as _;
|
||||
@@ -22,6 +22,11 @@ bind_interrupts!(struct Irqs {
|
||||
USB_LP => usb::InterruptHandler<peripherals::USB>;
|
||||
});
|
||||
|
||||
// This is a randomly generated GUID to allow clients on Windows to find your device.
|
||||
//
|
||||
// N.B. update to a custom GUID for your own device!
|
||||
const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"];
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
@@ -44,7 +49,7 @@ async fn main(_spawner: Spawner) {
|
||||
let mut config_descriptor = [0; 256];
|
||||
let mut bos_descriptor = [0; 256];
|
||||
let mut control_buf = [0; 64];
|
||||
let mut state = Control::new(firmware_state, DfuAttributes::CAN_DOWNLOAD);
|
||||
let mut state = Control::new(firmware_state, DfuAttributes::CAN_DOWNLOAD, ResetImmediate);
|
||||
let mut builder = Builder::new(
|
||||
driver,
|
||||
config,
|
||||
@@ -54,7 +59,28 @@ async fn main(_spawner: Spawner) {
|
||||
&mut control_buf,
|
||||
);
|
||||
|
||||
usb_dfu::<_, _, ResetImmediate>(&mut builder, &mut state, Duration::from_millis(2500));
|
||||
// We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows.
|
||||
// Otherwise users need to do this manually using a tool like Zadig.
|
||||
//
|
||||
// It seems these always need to be at added at the device level for this to work and for
|
||||
// composite devices they also need to be added on the function level (as shown later).
|
||||
//
|
||||
builder.msos_descriptor(msos::windows_version::WIN8_1, 2);
|
||||
builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
|
||||
builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
|
||||
"DeviceInterfaceGUIDs",
|
||||
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
|
||||
));
|
||||
|
||||
usb_dfu(&mut builder, &mut state, Duration::from_millis(2500), |func| {
|
||||
// You likely don't have to add these function level headers if your USB device is not composite
|
||||
// (i.e. if your device does not expose another interface in addition to DFU)
|
||||
func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
|
||||
func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
|
||||
"DeviceInterfaceGUIDs",
|
||||
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
|
||||
));
|
||||
});
|
||||
|
||||
let mut dev = builder.build();
|
||||
dev.run().await
|
||||
|
||||
@@ -5,15 +5,15 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32wl55jc-cm4", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.2.0", path = "../../../../embassy-embedded-hal" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.2.0", path = "../../../../embassy-stm32", features = ["stm32wl55jc-cm4", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.3.0", path = "../../../../embassy-boot-stm32", features = [] }
|
||||
embassy-embedded-hal = { version = "0.3.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
panic-reset = { version = "0.1.1" }
|
||||
embedded-hal = { version = "0.2.6" }
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ MEMORY
|
||||
BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
|
||||
FLASH : ORIGIN = 0x08008000, LENGTH = 64K
|
||||
DFU : ORIGIN = 0x08018000, LENGTH = 68K
|
||||
SHARED_RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64
|
||||
RAM (rwx) : ORIGIN = 0x20000040, LENGTH = 32K - 64
|
||||
SHARED_RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128
|
||||
RAM (rwx) : ORIGIN = 0x20000080, LENGTH = 32K - 128
|
||||
}
|
||||
|
||||
__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
|
||||
@@ -21,4 +21,4 @@ SECTIONS
|
||||
{
|
||||
*(.shared_data)
|
||||
} > SHARED_RAM
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ static APP_B: &[u8] = &[0, 1, 2, 3];
|
||||
#[cfg(not(feature = "skip-include"))]
|
||||
static APP_B: &[u8] = include_bytes!("../../b.bin");
|
||||
|
||||
#[link_section = ".shared_data"]
|
||||
#[unsafe(link_section = ".shared_data")]
|
||||
static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit();
|
||||
|
||||
#[embassy_executor::main]
|
||||
|
||||
@@ -11,7 +11,7 @@ use embassy_stm32::SharedData;
|
||||
use embassy_time::Timer;
|
||||
use panic_reset as _;
|
||||
|
||||
#[link_section = ".shared_data"]
|
||||
#[unsafe(link_section = ".shared_data")]
|
||||
static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit();
|
||||
|
||||
#[embassy_executor::main]
|
||||
|
||||
@@ -6,13 +6,13 @@ description = "Bootloader for nRF chips"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
|
||||
embassy-nrf = { path = "../../../../embassy-nrf", features = [] }
|
||||
embassy-boot-nrf = { path = "../../../../embassy-boot-nrf" }
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
cortex-m-rt = { version = "0.7" }
|
||||
cfg-if = "1.0.0"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use cortex_m_rt::{entry, exception};
|
||||
use defmt_rtt as _;
|
||||
use embassy_boot_nrf::*;
|
||||
use embassy_nrf::nvmc::Nvmc;
|
||||
use embassy_nrf::wdt;
|
||||
use embassy_nrf::wdt::{self, HaltConfig, SleepConfig};
|
||||
use embassy_sync::blocking_mutex::Mutex;
|
||||
|
||||
#[entry]
|
||||
@@ -25,8 +25,8 @@ fn main() -> ! {
|
||||
|
||||
let mut wdt_config = wdt::Config::default();
|
||||
wdt_config.timeout_ticks = 32768 * 5; // timeout seconds
|
||||
wdt_config.run_during_sleep = true;
|
||||
wdt_config.run_during_debug_halt = false;
|
||||
wdt_config.action_during_sleep = SleepConfig::RUN;
|
||||
wdt_config.action_during_debug_halt = HaltConfig::PAUSE;
|
||||
|
||||
let flash = WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config);
|
||||
let flash = Mutex::new(RefCell::new(flash));
|
||||
|
||||
@@ -6,12 +6,12 @@ description = "Example bootloader for RP2040 chips"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
|
||||
embassy-rp = { path = "../../../../embassy-rp", features = ["rp2040"] }
|
||||
embassy-boot-rp = { path = "../../../../embassy-boot-rp" }
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
embassy-time = { path = "../../../../embassy-time", features = [] }
|
||||
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
|
||||
@@ -6,8 +6,8 @@ description = "Example bootloader for dual-bank flash STM32 chips"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
|
||||
embassy-stm32 = { path = "../../../../embassy-stm32", features = [] }
|
||||
embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" }
|
||||
@@ -15,7 +15,7 @@ cortex-m = { version = "0.7.6", features = [
|
||||
"inline-asm",
|
||||
"critical-section-single-core",
|
||||
] }
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
cortex-m-rt = { version = "0.7" }
|
||||
embedded-storage = "0.3.1"
|
||||
embedded-storage-async = "0.4.0"
|
||||
|
||||
@@ -6,13 +6,13 @@ description = "Example bootloader for STM32 chips"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
|
||||
embassy-stm32 = { path = "../../../../embassy-stm32", features = [] }
|
||||
embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" }
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
cortex-m-rt = { version = "0.7" }
|
||||
embedded-storage = "0.3.1"
|
||||
embedded-storage-async = "0.4.0"
|
||||
|
||||
@@ -6,19 +6,19 @@ description = "Example USB DFUbootloader for the STM32WB series of chips"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
defmt = { version = "0.3", optional = true }
|
||||
defmt-rtt = { version = "0.4", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.0.0", optional = true }
|
||||
|
||||
embassy-stm32 = { path = "../../../../embassy-stm32", features = [] }
|
||||
embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" }
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" }
|
||||
embassy-sync = { version = "0.7.0", path = "../../../../embassy-sync" }
|
||||
cortex-m-rt = { version = "0.7" }
|
||||
embedded-storage = "0.3.1"
|
||||
embedded-storage-async = "0.4.0"
|
||||
cfg-if = "1.0.0"
|
||||
embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["dfu", "cortex-m"] }
|
||||
embassy-usb = { version = "0.3.0", path = "../../../../embassy-usb", default-features = false }
|
||||
embassy-usb = { version = "0.4.0", path = "../../../../embassy-usb", default-features = false }
|
||||
embassy-futures = { version = "0.1.1", path = "../../../../embassy-futures" }
|
||||
|
||||
[features]
|
||||
@@ -30,6 +30,7 @@ defmt = [
|
||||
"embassy-usb/defmt",
|
||||
"embassy-usb-dfu/defmt"
|
||||
]
|
||||
verify = ["embassy-usb-dfu/ed25519-salty"]
|
||||
|
||||
[profile.dev]
|
||||
debug = 2
|
||||
|
||||
@@ -1,11 +1,63 @@
|
||||
# Bootloader for STM32
|
||||
|
||||
The bootloader uses `embassy-boot` to interact with the flash.
|
||||
This bootloader implementation uses `embassy-boot` and `embassy-usb-dfu` to manage firmware updates and interact with the flash memory on STM32WB55 devices.
|
||||
|
||||
# Usage
|
||||
## Prerequisites
|
||||
|
||||
Flash the bootloader
|
||||
- Rust toolchain with `cargo` installed
|
||||
- `cargo-flash` for flashing the bootloader
|
||||
- `dfu-util` for firmware updates
|
||||
- `cargo-binutils` for binary generation
|
||||
|
||||
## Usage
|
||||
|
||||
### 1. Flash the Bootloader
|
||||
|
||||
First, flash the bootloader to your device:
|
||||
|
||||
```
|
||||
cargo flash --features embassy-stm32/stm32wb55rg --release --chip STM32WB55RGVx
|
||||
```
|
||||
|
||||
### 2. Build and Flash Application
|
||||
|
||||
Generate your application binary and flash it using DFU:
|
||||
|
||||
```
|
||||
cargo objcopy --release -- -O binary fw.bin
|
||||
dfu-util -d c0de:cafe -w -D fw.bin
|
||||
```
|
||||
|
||||
### 3. Sign Updates Before Flashing (Optional)
|
||||
|
||||
Currently, embassy-usb-dfu only supports a limited implementation of the generic support for ed25519-based update verfication in embassy-boot. This implementation assumes that a signature is simply concatenated to the end of an update binary. For more details, please see https://embassy.dev/book/#_verification and/or refer to the documentation for embassy-boot-dfu.
|
||||
|
||||
To sign (and then verify) application updates, you will first need to generate a key pair:
|
||||
|
||||
```
|
||||
signify-openbsd -G -n -p secrets/key.pub -s secrets/key.sec
|
||||
tail -n1 secrets/key.pub | base64 -d -i - | dd ibs=10 skip=1 > secrets/key.pub.short
|
||||
```
|
||||
|
||||
Then you will need to sign all you binaries with the private key:
|
||||
|
||||
```
|
||||
cargo objcopy --release -- -O binary fw.bin
|
||||
shasum -a 512 -b fw.bin | head -c128 | xxd -p -r > target/fw-hash.txt
|
||||
signify-openbsd -S -s secrets/key.sec -m target/fw-hash.txt -x target/fw-hash.sig
|
||||
cp fw.bin fw-signed.bin
|
||||
tail -n1 target/fw-hash.sig | base64 -d -i - | dd ibs=10 skip=1 >> fw-signed.bin
|
||||
dfu-util -d c0de:cafe -w -D fw-signed.bin
|
||||
```
|
||||
|
||||
Finally, as shown in this example with the `verify` feature flag enabled, you then need to embed the public key into your bootloader so that it can verify update signatures.
|
||||
|
||||
N.B. Please note that the exact steps above are NOT a good example of how to manage your keys securely. In a production environment, you should take great care to ensure that (at least the private key) is protected and not leaked into your version control system.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- Make sure your device is in DFU mode before flashing
|
||||
- Verify the USB VID:PID matches your device (c0de:cafe)
|
||||
- Check USB connections if the device is not detected
|
||||
- Make sure the transfer size option of `dfu-util` matches the bootloader configuration. By default, `dfu-util` will use the transfer size reported by the device, but you can override it with the `-t` option if needed.
|
||||
- Make sure `control_buf` size is larger than or equal to the `usb_dfu` `BLOCK_SIZE` parameter (in this example, both are set to 4096 bytes).
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 24K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
|
||||
ACTIVE : ORIGIN = 0x08008000, LENGTH = 128K
|
||||
DFU : ORIGIN = 0x08028000, LENGTH = 132K
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 48K
|
||||
BOOTLOADER_STATE : ORIGIN = 0x0800C000, LENGTH = 4K
|
||||
ACTIVE : ORIGIN = 0x0800D000, LENGTH = 120K
|
||||
DFU : ORIGIN = 0x0802B000, LENGTH = 120K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
gB<EFBFBD><EFBFBD>p<EFBFBD>M<EFBFBD>S<EFBFBD><EFBFBD>z<EFBFBD><EFBFBD>Kg<EFBFBD><19>!<21>F<EFBFBD><46><02><>!4<>r
|
||||
@@ -12,7 +12,7 @@ use embassy_stm32::rcc::WPAN_DEFAULT;
|
||||
use embassy_stm32::usb::Driver;
|
||||
use embassy_stm32::{bind_interrupts, peripherals, usb};
|
||||
use embassy_sync::blocking_mutex::Mutex;
|
||||
use embassy_usb::Builder;
|
||||
use embassy_usb::{msos, Builder};
|
||||
use embassy_usb_dfu::consts::DfuAttributes;
|
||||
use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate};
|
||||
|
||||
@@ -20,6 +20,17 @@ bind_interrupts!(struct Irqs {
|
||||
USB_LP => usb::InterruptHandler<peripherals::USB>;
|
||||
});
|
||||
|
||||
// This is a randomly generated GUID to allow clients on Windows to find your device.
|
||||
//
|
||||
// N.B. update to a custom GUID for your own device!
|
||||
const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"];
|
||||
|
||||
// This is a randomly generated example key.
|
||||
//
|
||||
// N.B. Please replace with your own!
|
||||
#[cfg(feature = "verify")]
|
||||
static PUBLIC_SIGNING_KEY: &[u8; 32] = include_bytes!("../secrets/key.pub.short");
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
@@ -52,7 +63,13 @@ fn main() -> ! {
|
||||
let mut config_descriptor = [0; 256];
|
||||
let mut bos_descriptor = [0; 256];
|
||||
let mut control_buf = [0; 4096];
|
||||
let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD);
|
||||
|
||||
#[cfg(not(feature = "verify"))]
|
||||
let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate);
|
||||
|
||||
#[cfg(feature = "verify")]
|
||||
let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate, PUBLIC_SIGNING_KEY);
|
||||
|
||||
let mut builder = Builder::new(
|
||||
driver,
|
||||
config,
|
||||
@@ -62,7 +79,28 @@ fn main() -> ! {
|
||||
&mut control_buf,
|
||||
);
|
||||
|
||||
usb_dfu::<_, _, _, ResetImmediate, 4096>(&mut builder, &mut state);
|
||||
// We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows.
|
||||
// Otherwise users need to do this manually using a tool like Zadig.
|
||||
//
|
||||
// It seems these always need to be at added at the device level for this to work and for
|
||||
// composite devices they also need to be added on the function level (as shown later).
|
||||
//
|
||||
builder.msos_descriptor(msos::windows_version::WIN8_1, 2);
|
||||
builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
|
||||
builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
|
||||
"DeviceInterfaceGUIDs",
|
||||
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
|
||||
));
|
||||
|
||||
usb_dfu::<_, _, _, _, 4096>(&mut builder, &mut state, |func| {
|
||||
// You likely don't have to add these function level headers if your USB device is not composite
|
||||
// (i.e. if your device does not expose another interface in addition to DFU)
|
||||
func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
|
||||
func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
|
||||
"DeviceInterfaceGUIDs",
|
||||
msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS),
|
||||
));
|
||||
});
|
||||
|
||||
let mut dev = builder.build();
|
||||
embassy_futures::block_on(dev.run());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
#runner = "probe-rs run --chip RP2040"
|
||||
runner = "elf2uf2-rs -d"
|
||||
runner = "probe-rs run --chip LPC55S69JBD100"
|
||||
|
||||
[build]
|
||||
target = "thumbv8m.main-none-eabihf"
|
||||
22
examples/lpc55s69/Cargo.toml
Normal file
22
examples/lpc55s69/Cargo.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "embassy-nxp-lpc55s69-examples"
|
||||
version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
|
||||
[dependencies]
|
||||
embassy-nxp = { version = "0.1.0", path = "../../embassy-nxp", features = ["rt"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] }
|
||||
panic-halt = "1.0.0"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = { version = "0.7.0"}
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
panic-semihosting = "0.6.0"
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
28
examples/lpc55s69/memory.x
Normal file
28
examples/lpc55s69/memory.x
Normal file
@@ -0,0 +1,28 @@
|
||||
/* File originally from lpc55-hal repo: https://github.com/lpc55/lpc55-hal/blob/main/memory.x */
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x00000000, LENGTH = 512K
|
||||
|
||||
/* for use with standard link.x */
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 256K
|
||||
|
||||
/* would be used with proper link.x */
|
||||
/* needs changes to r0 (initialization code) */
|
||||
/* SRAM0 : ORIGIN = 0x20000000, LENGTH = 64K */
|
||||
/* SRAM1 : ORIGIN = 0x20010000, LENGTH = 64K */
|
||||
/* SRAM2 : ORIGIN = 0x20020000, LENGTH = 64K */
|
||||
/* SRAM3 : ORIGIN = 0x20030000, LENGTH = 64K */
|
||||
|
||||
/* CASPER SRAM regions */
|
||||
/* SRAMX0: ORIGIN = 0x1400_0000, LENGTH = 4K /1* to 0x1400_0FFF *1/ */
|
||||
/* SRAMX1: ORIGIN = 0x1400_4000, LENGTH = 4K /1* to 0x1400_4FFF *1/ */
|
||||
|
||||
/* USB1 SRAM regin */
|
||||
/* USB1_SRAM : ORIGIN = 0x40100000, LENGTH = 16K */
|
||||
|
||||
/* To define our own USB RAM section in one regular */
|
||||
/* RAM, probably easiest to shorten length of RAM */
|
||||
/* above, and use this freed RAM section */
|
||||
|
||||
}
|
||||
|
||||
33
examples/lpc55s69/src/bin/blinky_nop.rs
Normal file
33
examples/lpc55s69/src/bin/blinky_nop.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
//! This example has been made with the LPCXpresso55S69 board in mind, which has a built-in LED on PIO1_6.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m::asm::nop;
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nxp::gpio::{Level, Output};
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nxp::init(Default::default());
|
||||
|
||||
let mut led = Output::new(p.PIO1_6, Level::Low);
|
||||
|
||||
loop {
|
||||
info!("led off!");
|
||||
led.set_high();
|
||||
|
||||
for _ in 0..200_000 {
|
||||
nop();
|
||||
}
|
||||
|
||||
info!("led on!");
|
||||
led.set_low();
|
||||
|
||||
for _ in 0..200_000 {
|
||||
nop();
|
||||
}
|
||||
}
|
||||
}
|
||||
25
examples/lpc55s69/src/bin/button_executor.rs
Normal file
25
examples/lpc55s69/src/bin/button_executor.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
//! This example has been made with the LPCXpresso55S69 board in mind, which has a built-in LED on
|
||||
//! PIO1_6 and a button (labeled "user") on PIO1_9.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nxp::gpio::{Input, Level, Output, Pull};
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
let p = embassy_nxp::init(Default::default());
|
||||
|
||||
let mut led = Output::new(p.PIO1_6, Level::Low);
|
||||
let mut button = Input::new(p.PIO1_9, Pull::Up);
|
||||
|
||||
info!("Entered main loop");
|
||||
loop {
|
||||
button.wait_for_rising_edge().await;
|
||||
info!("Button pressed");
|
||||
led.toggle();
|
||||
}
|
||||
}
|
||||
17
examples/mimxrt6/.cargo/config.toml
Normal file
17
examples/mimxrt6/.cargo/config.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
[target.thumbv8m.main-none-eabihf]
|
||||
runner = 'probe-rs run --chip MIMXRT685SFVKB'
|
||||
|
||||
rustflags = [
|
||||
"-C", "linker=flip-link",
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
"-C", "link-arg=-Tdefmt.x",
|
||||
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
|
||||
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
|
||||
"-C", "link-arg=--nmagic",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "thumbv8m.main-none-eabihf" # Cortex-M33
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "trace"
|
||||
14
examples/mimxrt6/.gitignore
vendored
Normal file
14
examples/mimxrt6/.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/debug
|
||||
/target
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
60
examples/mimxrt6/Cargo.toml
Normal file
60
examples/mimxrt6/Cargo.toml
Normal file
@@ -0,0 +1,60 @@
|
||||
[package]
|
||||
name = "embassy-imxrt-examples"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MIT or Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.3"
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
|
||||
embassy-futures = { version = "0.1.1", path = "../../embassy-futures" }
|
||||
embassy-imxrt = { version = "0.1.0", path = "../../embassy-imxrt", features = ["defmt", "mimxrt685s", "unstable-pac", "time", "time-driver-os-timer"] }
|
||||
embassy-time = { version = "0.4", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
|
||||
embedded-hal-async = "1.0.0"
|
||||
|
||||
mimxrt600-fcb = "0.2.2"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
|
||||
# cargo build/run
|
||||
[profile.dev]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = true # <-
|
||||
incremental = false
|
||||
opt-level = 3 # <-
|
||||
overflow-checks = true # <-
|
||||
|
||||
# cargo test
|
||||
[profile.test]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = true # <-
|
||||
incremental = false
|
||||
opt-level = 3 # <-
|
||||
overflow-checks = true # <-
|
||||
|
||||
# cargo build/run --release
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = false # <-
|
||||
incremental = false
|
||||
lto = 'fat'
|
||||
opt-level = 3 # <-
|
||||
overflow-checks = false # <-
|
||||
|
||||
# cargo test --release
|
||||
[profile.bench]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = false # <-
|
||||
incremental = false
|
||||
lto = 'fat'
|
||||
opt-level = 3 # <-
|
||||
overflow-checks = false # <-
|
||||
18
examples/mimxrt6/README.md
Normal file
18
examples/mimxrt6/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# embassy-imxrt-examples
|
||||
|
||||
## Introduction
|
||||
|
||||
These examples illustrates how to use the embassy-imxrt HAL.
|
||||
|
||||
## Adding Examples
|
||||
Add uniquely named example to `src/bin` like `adc.rs`
|
||||
|
||||
## Build
|
||||
`cd` to examples folder
|
||||
`cargo build --bin <example_name>` for example, `cargo build --bin adc`
|
||||
|
||||
## Run
|
||||
Assuming RT685 is powered and connected to Jlink debug probe and the latest probe-rs is installed via
|
||||
`$ cargo install probe-rs-tools --git https://github.com/probe-rs/probe-rs --locked`
|
||||
`cd` to examples folder
|
||||
`cargo run --bin <example_name>` for example, `cargo run --bin adc`
|
||||
45
examples/mimxrt6/build.rs
Normal file
45
examples/mimxrt6/build.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
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");
|
||||
|
||||
// Inject crate version into the .biv section.
|
||||
File::create(out.join("biv.rs"))
|
||||
.unwrap()
|
||||
.write_all(
|
||||
format!(
|
||||
r##"
|
||||
#[unsafe(link_section = ".biv")]
|
||||
#[used]
|
||||
static BOOT_IMAGE_VERSION: u32 = 0x{:02x}{:02x}{:02x}00;
|
||||
"##,
|
||||
env!("CARGO_PKG_VERSION_MAJOR")
|
||||
.parse::<u8>()
|
||||
.expect("should have major version"),
|
||||
env!("CARGO_PKG_VERSION_MINOR")
|
||||
.parse::<u8>()
|
||||
.expect("should have minor version"),
|
||||
env!("CARGO_PKG_VERSION_PATCH")
|
||||
.parse::<u8>()
|
||||
.expect("should have patch version"),
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
34
examples/mimxrt6/memory.x
Normal file
34
examples/mimxrt6/memory.x
Normal file
@@ -0,0 +1,34 @@
|
||||
MEMORY {
|
||||
OTFAD : ORIGIN = 0x08000000, LENGTH = 256
|
||||
FCB : ORIGIN = 0x08000400, LENGTH = 512
|
||||
BIV : ORIGIN = 0x08000600, LENGTH = 4
|
||||
KEYSTORE : ORIGIN = 0x08000800, LENGTH = 2K
|
||||
FLASH : ORIGIN = 0x08001000, LENGTH = 1M
|
||||
RAM : ORIGIN = 0x20080000, LENGTH = 1536K
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
.otfad : {
|
||||
. = ALIGN(4);
|
||||
KEEP(* (.otfad))
|
||||
. = ALIGN(4);
|
||||
} > OTFAD
|
||||
|
||||
.fcb : {
|
||||
. = ALIGN(4);
|
||||
KEEP(* (.fcb))
|
||||
. = ALIGN(4);
|
||||
} > FCB
|
||||
|
||||
.biv : {
|
||||
. = ALIGN(4);
|
||||
KEEP(* (.biv))
|
||||
. = ALIGN(4);
|
||||
} > BIV
|
||||
|
||||
.keystore : {
|
||||
. = ALIGN(4);
|
||||
KEEP(* (.keystore))
|
||||
. = ALIGN(4);
|
||||
} > KEYSTORE
|
||||
}
|
||||
30
examples/mimxrt6/src/bin/blinky.rs
Normal file
30
examples/mimxrt6/src/bin/blinky.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate embassy_imxrt_examples;
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_imxrt::gpio;
|
||||
use embassy_time::Timer;
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_imxrt::init(Default::default());
|
||||
|
||||
info!("Initializing GPIO");
|
||||
|
||||
let mut led = gpio::Output::new(
|
||||
p.PIO0_26,
|
||||
gpio::Level::Low,
|
||||
gpio::DriveMode::PushPull,
|
||||
gpio::DriveStrength::Normal,
|
||||
gpio::SlewRate::Standard,
|
||||
);
|
||||
|
||||
loop {
|
||||
info!("Toggling LED");
|
||||
led.toggle();
|
||||
Timer::after_secs(1).await;
|
||||
}
|
||||
}
|
||||
29
examples/mimxrt6/src/bin/button.rs
Normal file
29
examples/mimxrt6/src/bin/button.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::select::{select, Either};
|
||||
use embassy_imxrt::gpio;
|
||||
use {defmt_rtt as _, embassy_imxrt_examples as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_imxrt::init(Default::default());
|
||||
|
||||
let mut user1 = gpio::Input::new(p.PIO1_1, gpio::Pull::None, gpio::Inverter::Disabled);
|
||||
let mut user2 = gpio::Input::new(p.PIO0_10, gpio::Pull::None, gpio::Inverter::Disabled);
|
||||
|
||||
loop {
|
||||
let res = select(user1.wait_for_falling_edge(), user2.wait_for_falling_edge()).await;
|
||||
|
||||
match res {
|
||||
Either::First(()) => {
|
||||
info!("Button `USER1' pressed");
|
||||
}
|
||||
Either::Second(()) => {
|
||||
info!("Button `USER2' pressed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
175
examples/mimxrt6/src/bin/crc.rs
Normal file
175
examples/mimxrt6/src/bin/crc.rs
Normal file
@@ -0,0 +1,175 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate embassy_imxrt_examples;
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_imxrt::crc::{Config, Crc, Polynomial};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut p = embassy_imxrt::init(Default::default());
|
||||
let data = b"123456789";
|
||||
|
||||
info!("Initializing CRC");
|
||||
|
||||
// CRC-CCITT
|
||||
let mut crc = Crc::new(p.CRC.reborrow(), Default::default());
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x29b1);
|
||||
|
||||
// CRC16-ARC
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: false,
|
||||
seed: 0,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0xbb3d);
|
||||
|
||||
// CRC16-CMS
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: false,
|
||||
seed: 0xffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0xaee7);
|
||||
|
||||
// CRC16-DDS-110
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: false,
|
||||
seed: 0x800d,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x9ecf);
|
||||
|
||||
// CRC16-MAXIM-DOW
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: true,
|
||||
seed: 0,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x44c2);
|
||||
|
||||
// CRC16-MODBUS
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc16,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: false,
|
||||
seed: 0xffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x4b37);
|
||||
|
||||
// CRC32-BZIP2
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: true,
|
||||
seed: 0xffff_ffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0xfc89_1918);
|
||||
|
||||
// CRC32-CKSUM
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: true,
|
||||
seed: 0,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x765e_7680);
|
||||
|
||||
// CRC32-ISO-HDLC
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: true,
|
||||
seed: 0xffff_ffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0xcbf4_3926);
|
||||
|
||||
// CRC32-JAMCRC
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: true,
|
||||
reverse_out: true,
|
||||
complement_out: false,
|
||||
seed: 0xffff_ffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x340b_c6d9);
|
||||
|
||||
// CRC32-MPEG-2
|
||||
let mut crc = Crc::new(
|
||||
p.CRC.reborrow(),
|
||||
Config {
|
||||
polynomial: Polynomial::Crc32,
|
||||
reverse_in: false,
|
||||
reverse_out: false,
|
||||
complement_out: false,
|
||||
seed: 0xffff_ffff,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let output = crc.feed_bytes(data);
|
||||
defmt::assert_eq!(output, 0x0376_e6e7);
|
||||
|
||||
info!("end program");
|
||||
cortex_m::asm::bkpt();
|
||||
}
|
||||
17
examples/mimxrt6/src/bin/hello.rs
Normal file
17
examples/mimxrt6/src/bin/hello.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate embassy_imxrt_examples;
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
let _p = embassy_imxrt::init(Default::default());
|
||||
loop {
|
||||
info!("Hello");
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
}
|
||||
}
|
||||
39
examples/mimxrt6/src/bin/rng.rs
Normal file
39
examples/mimxrt6/src/bin/rng.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate embassy_imxrt_examples;
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_imxrt::rng::Rng;
|
||||
use embassy_imxrt::{bind_interrupts, peripherals, rng};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
RNG => rng::InterruptHandler<peripherals::RNG>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_imxrt::init(Default::default());
|
||||
|
||||
info!("Initializing RNG");
|
||||
let mut rng = Rng::new(p.RNG, Irqs);
|
||||
let mut buf = [0u8; 65];
|
||||
|
||||
// Async interface
|
||||
unwrap!(rng.async_fill_bytes(&mut buf).await);
|
||||
info!("random bytes: {:02x}", buf);
|
||||
|
||||
// RngCore interface
|
||||
let mut random_bytes = [0; 16];
|
||||
|
||||
let random_u32 = rng.blocking_next_u32();
|
||||
let random_u64 = rng.blocking_next_u64();
|
||||
|
||||
rng.blocking_fill_bytes(&mut random_bytes);
|
||||
|
||||
info!("random_u32 {}", random_u32);
|
||||
info!("random_u64 {}", random_u64);
|
||||
info!("random_bytes {}", random_bytes);
|
||||
}
|
||||
87
examples/mimxrt6/src/bin/uart-async.rs
Normal file
87
examples/mimxrt6/src/bin/uart-async.rs
Normal file
@@ -0,0 +1,87 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate embassy_imxrt_examples;
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_imxrt::flexcomm::uart::{self, Async, Uart};
|
||||
use embassy_imxrt::{bind_interrupts, peripherals};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
FLEXCOMM2 => uart::InterruptHandler<peripherals::FLEXCOMM2>;
|
||||
FLEXCOMM4 => uart::InterruptHandler<peripherals::FLEXCOMM4>;
|
||||
});
|
||||
|
||||
const BUFLEN: usize = 16;
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn usart4_task(mut uart: Uart<'static, Async>) {
|
||||
info!("RX Task");
|
||||
|
||||
loop {
|
||||
let mut rx_buf = [0; BUFLEN];
|
||||
uart.read(&mut rx_buf).await.unwrap();
|
||||
info!("usart4: rx_buf {:02x}", rx_buf);
|
||||
|
||||
Timer::after_millis(10).await;
|
||||
|
||||
let tx_buf = [0xaa; BUFLEN];
|
||||
uart.write(&tx_buf).await.unwrap();
|
||||
info!("usart4: tx_buf {:02x}", tx_buf);
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn usart2_task(mut uart: Uart<'static, Async>) {
|
||||
info!("TX Task");
|
||||
|
||||
loop {
|
||||
let tx_buf = [0x55; BUFLEN];
|
||||
uart.write(&tx_buf).await.unwrap();
|
||||
info!("usart2: tx_buf {:02x}", tx_buf);
|
||||
|
||||
Timer::after_millis(10).await;
|
||||
|
||||
let mut rx_buf = [0x00; BUFLEN];
|
||||
uart.read(&mut rx_buf).await.unwrap();
|
||||
info!("usart2: rx_buf {:02x}", rx_buf);
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_imxrt::init(Default::default());
|
||||
|
||||
info!("UART test start");
|
||||
|
||||
let usart4 = Uart::new_with_rtscts(
|
||||
p.FLEXCOMM4,
|
||||
p.PIO0_29,
|
||||
p.PIO0_30,
|
||||
p.PIO1_0,
|
||||
p.PIO0_31,
|
||||
Irqs,
|
||||
p.DMA0_CH9,
|
||||
p.DMA0_CH8,
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
spawner.must_spawn(usart4_task(usart4));
|
||||
|
||||
let usart2 = Uart::new_with_rtscts(
|
||||
p.FLEXCOMM2,
|
||||
p.PIO0_15,
|
||||
p.PIO0_16,
|
||||
p.PIO0_18,
|
||||
p.PIO0_17,
|
||||
Irqs,
|
||||
p.DMA0_CH5,
|
||||
p.DMA0_CH4,
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
spawner.must_spawn(usart2_task(usart2));
|
||||
}
|
||||
55
examples/mimxrt6/src/bin/uart.rs
Normal file
55
examples/mimxrt6/src/bin/uart.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate embassy_imxrt_examples;
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_imxrt::flexcomm::uart::{Blocking, Uart, UartRx, UartTx};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn usart4_task(mut uart: UartRx<'static, Blocking>) {
|
||||
info!("RX Task");
|
||||
|
||||
loop {
|
||||
let mut buf = [0; 8];
|
||||
|
||||
Timer::after_millis(10).await;
|
||||
|
||||
uart.blocking_read(&mut buf).unwrap();
|
||||
|
||||
let s = core::str::from_utf8(&buf).unwrap();
|
||||
|
||||
info!("Received '{}'", s);
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn usart2_task(mut uart: UartTx<'static, Blocking>) {
|
||||
info!("TX Task");
|
||||
|
||||
loop {
|
||||
let buf = "Testing\0".as_bytes();
|
||||
|
||||
uart.blocking_write(buf).unwrap();
|
||||
|
||||
Timer::after_millis(10).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_imxrt::init(Default::default());
|
||||
|
||||
info!("UART test start");
|
||||
|
||||
let usart4 = Uart::new_blocking(p.FLEXCOMM4, p.PIO0_29, p.PIO0_30, Default::default()).unwrap();
|
||||
|
||||
let (_, usart4) = usart4.split();
|
||||
spawner.must_spawn(usart4_task(usart4));
|
||||
|
||||
let usart2 = UartTx::new_blocking(p.FLEXCOMM2, p.PIO0_15, Default::default()).unwrap();
|
||||
spawner.must_spawn(usart2_task(usart2));
|
||||
}
|
||||
20
examples/mimxrt6/src/lib.rs
Normal file
20
examples/mimxrt6/src/lib.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
#![no_std]
|
||||
|
||||
use mimxrt600_fcb::FlexSPIFlashConfigurationBlock;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
// auto-generated version information from Cargo.toml
|
||||
include!(concat!(env!("OUT_DIR"), "/biv.rs"));
|
||||
|
||||
#[unsafe(link_section = ".otfad")]
|
||||
#[used]
|
||||
static OTFAD: [u8; 256] = [0; 256];
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[unsafe(link_section = ".fcb")]
|
||||
#[used]
|
||||
static FCB: FlexSPIFlashConfigurationBlock = FlexSPIFlashConfigurationBlock::build();
|
||||
|
||||
#[unsafe(link_section = ".keystore")]
|
||||
#[used]
|
||||
static KEYSTORE: [u8; 2048] = [0; 2048];
|
||||
11
examples/mspm0c1104/.cargo/config.toml
Normal file
11
examples/mspm0c1104/.cargo/config.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace MSPM0C1104 with your chip as listed in `probe-rs chip list`
|
||||
runner = "probe-rs run --chip MSPM0C1104 --protocol=swd"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "debug"
|
||||
# defmt's buffer needs to be shrunk since the MSPM0C1104 only has 1KB of ram.
|
||||
DEFMT_RTT_BUFFER_SIZE = "72"
|
||||
32
examples/mspm0c1104/Cargo.toml
Normal file
32
examples/mspm0c1104/Cargo.toml
Normal file
@@ -0,0 +1,32 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "embassy-mspm0-c1104-examples"
|
||||
version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0c1104dgs20", "defmt", "rt", "time-driver-any"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] }
|
||||
panic-halt = "1.0.0"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = { version = "0.7.0"}
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
panic-semihosting = "0.6.0"
|
||||
|
||||
# The chip only has 1KB of ram, so we must optimize binaries regardless
|
||||
[profile.dev]
|
||||
debug = 0
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
# strip = true
|
||||
|
||||
[profile.release]
|
||||
debug = 0
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
27
examples/mspm0c1104/README.md
Normal file
27
examples/mspm0c1104/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Examples for MSPM0C1104
|
||||
|
||||
Run individual examples with
|
||||
```
|
||||
cargo run --bin <module-name>
|
||||
```
|
||||
for example
|
||||
```
|
||||
cargo run --bin blinky
|
||||
```
|
||||
|
||||
## Checklist before running examples
|
||||
A large number of the examples are written for the [LP-MSPM0C1104](https://www.ti.com/tool/LP-MSPM0C1104) board.
|
||||
|
||||
You might need to adjust `.cargo/config.toml`, `Cargo.toml` and possibly update pin numbers or peripherals to match the specific MCU or board you are using.
|
||||
|
||||
* [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for C1104 it should be `probe-rs run --chip MSPM0C1104`. (use `probe-rs chip list` to find your chip)
|
||||
* [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For the LP-MSPM0C1104 it should be `mspm0c1104dgs20`. Look in the `Cargo.toml` file of the `embassy-mspm0` project to find the correct feature flag for your chip.
|
||||
* [ ] If your board has a special clock or power configuration, make sure that it is set up appropriately.
|
||||
* [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic
|
||||
|
||||
If you are unsure, please drop by the Embassy Matrix chat for support, and let us know:
|
||||
|
||||
* Which example you are trying to run
|
||||
* Which chip and board you are using
|
||||
|
||||
Embassy Chat: https://matrix.to/#/#embassy-rs:matrix.org
|
||||
37
examples/mspm0c1104/build.rs
Normal file
37
examples/mspm0c1104/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");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
5
examples/mspm0c1104/memory.x
Normal file
5
examples/mspm0c1104/memory.x
Normal file
@@ -0,0 +1,5 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x00000000, LENGTH = 16K
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 1K
|
||||
}
|
||||
25
examples/mspm0c1104/src/bin/blinky.rs
Normal file
25
examples/mspm0c1104/src/bin/blinky.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::Config;
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let mut led1 = Output::new(p.PA22, Level::Low);
|
||||
led1.set_inversion(true);
|
||||
|
||||
loop {
|
||||
Timer::after_millis(400).await;
|
||||
|
||||
info!("Toggle");
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
33
examples/mspm0c1104/src/bin/button.rs
Normal file
33
examples/mspm0c1104/src/bin/button.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_mspm0::Config;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let led1 = p.PA22;
|
||||
let s2 = p.PA16;
|
||||
|
||||
let mut led1 = Output::new(led1, Level::Low);
|
||||
|
||||
let mut s2 = Input::new(s2, Pull::Up);
|
||||
|
||||
// led1 is active low
|
||||
led1.set_high();
|
||||
|
||||
loop {
|
||||
s2.wait_for_falling_edge().await;
|
||||
|
||||
info!("Switch 2 was pressed");
|
||||
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
35
examples/mspm0c1104/src/bin/uart.rs
Normal file
35
examples/mspm0c1104/src/bin/uart.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
//! Example of using blocking uart
|
||||
//!
|
||||
//! This uses the virtual COM port provided on the LP-MSPM0C1104 board.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::uart::{Config, Uart};
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
|
||||
let instance = p.UART0;
|
||||
let tx = p.PA27;
|
||||
let rx = p.PA26;
|
||||
|
||||
let config = Config::default();
|
||||
let mut uart = unwrap!(Uart::new_blocking(instance, rx, tx, config));
|
||||
|
||||
unwrap!(uart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
|
||||
loop {
|
||||
unwrap!(uart.blocking_read(&mut buf));
|
||||
unwrap!(uart.blocking_write(&buf));
|
||||
}
|
||||
}
|
||||
9
examples/mspm0g3507/.cargo/config.toml
Normal file
9
examples/mspm0g3507/.cargo/config.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace MSPM0G3507 with your chip as listed in `probe-rs chip list`
|
||||
runner = "probe-rs run --chip MSPM0G3507 --protocol=swd"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "debug"
|
||||
21
examples/mspm0g3507/Cargo.toml
Normal file
21
examples/mspm0g3507/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "embassy-mspm0-g3507-examples"
|
||||
version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0g3507pm", "defmt", "rt", "time-driver-any"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] }
|
||||
panic-halt = "1.0.0"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = { version = "0.7.0"}
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
panic-semihosting = "0.6.0"
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
27
examples/mspm0g3507/README.md
Normal file
27
examples/mspm0g3507/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Examples for MSPM0M3507
|
||||
|
||||
Run individual examples with
|
||||
```
|
||||
cargo run --bin <module-name>
|
||||
```
|
||||
for example
|
||||
```
|
||||
cargo run --bin blinky
|
||||
```
|
||||
|
||||
## Checklist before running examples
|
||||
A large number of the examples are written for the [LP-MSPM0G3507](https://www.ti.com/tool/LP-MSPM0G3507) board.
|
||||
|
||||
You might need to adjust `.cargo/config.toml`, `Cargo.toml` and possibly update pin numbers or peripherals to match the specific MCU or board you are using.
|
||||
|
||||
* [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for G3507 it should be `probe-rs run --chip MSPM0G3507`. (use `probe-rs chip list` to find your chip)
|
||||
* [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For the LP-MSPM0G3507 it should be `mspm0g3507pm`. Look in the `Cargo.toml` file of the `embassy-mspm0` project to find the correct feature flag for your chip.
|
||||
* [ ] If your board has a special clock or power configuration, make sure that it is set up appropriately.
|
||||
* [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic
|
||||
|
||||
If you are unsure, please drop by the Embassy Matrix chat for support, and let us know:
|
||||
|
||||
* Which example you are trying to run
|
||||
* Which chip and board you are using
|
||||
|
||||
Embassy Chat: https://matrix.to/#/#embassy-rs:matrix.org
|
||||
37
examples/mspm0g3507/build.rs
Normal file
37
examples/mspm0g3507/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");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
6
examples/mspm0g3507/memory.x
Normal file
6
examples/mspm0g3507/memory.x
Normal file
@@ -0,0 +1,6 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x00000000, LENGTH = 128K
|
||||
/* Select non-parity range of SRAM due to SRAM_ERR_01 errata in SLAZ758 */
|
||||
RAM : ORIGIN = 0x20200000, LENGTH = 32K
|
||||
}
|
||||
25
examples/mspm0g3507/src/bin/blinky.rs
Normal file
25
examples/mspm0g3507/src/bin/blinky.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::Config;
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::Low);
|
||||
led1.set_inversion(true);
|
||||
|
||||
loop {
|
||||
Timer::after_millis(400).await;
|
||||
|
||||
info!("Toggle");
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
33
examples/mspm0g3507/src/bin/button.rs
Normal file
33
examples/mspm0g3507/src/bin/button.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_mspm0::Config;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let led1 = p.PA0;
|
||||
let s2 = p.PB21;
|
||||
|
||||
let mut led1 = Output::new(led1, Level::Low);
|
||||
|
||||
let mut s2 = Input::new(s2, Pull::Up);
|
||||
|
||||
// led1 is active low
|
||||
led1.set_high();
|
||||
|
||||
loop {
|
||||
s2.wait_for_falling_edge().await;
|
||||
|
||||
info!("Switch 2 was pressed");
|
||||
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
35
examples/mspm0g3507/src/bin/uart.rs
Normal file
35
examples/mspm0g3507/src/bin/uart.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
//! Example of using blocking uart
|
||||
//!
|
||||
//! This uses the virtual COM port provided on the LP-MSPM0G3507 board.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::uart::{Config, Uart};
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
|
||||
let instance = p.UART0;
|
||||
let tx = p.PA10;
|
||||
let rx = p.PA11;
|
||||
|
||||
let config = Config::default();
|
||||
let mut uart = unwrap!(Uart::new_blocking(instance, rx, tx, config));
|
||||
|
||||
unwrap!(uart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
|
||||
loop {
|
||||
unwrap!(uart.blocking_read(&mut buf));
|
||||
unwrap!(uart.blocking_write(&buf));
|
||||
}
|
||||
}
|
||||
9
examples/mspm0g3519/.cargo/config.toml
Normal file
9
examples/mspm0g3519/.cargo/config.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace MSPM0G3519 with your chip as listed in `probe-rs chip list`
|
||||
runner = "probe-rs run --restore-unwritten --verify --chip MSPM0G3519 --protocol=swd"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "trace"
|
||||
21
examples/mspm0g3519/Cargo.toml
Normal file
21
examples/mspm0g3519/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "embassy-mspm0-g3519-examples"
|
||||
version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0g3519pz", "defmt", "rt", "time-driver-any"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] }
|
||||
panic-halt = "1.0.0"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = { version = "0.7.0"}
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
panic-semihosting = "0.6.0"
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
27
examples/mspm0g3519/README.md
Normal file
27
examples/mspm0g3519/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Examples for MSPM0G3519
|
||||
|
||||
Run individual examples with
|
||||
```
|
||||
cargo run --bin <module-name>
|
||||
```
|
||||
for example
|
||||
```
|
||||
cargo run --bin blinky
|
||||
```
|
||||
|
||||
## Checklist before running examples
|
||||
A large number of the examples are written for the [LP-MSPM0G3519](https://www.ti.com/tool/LP-MSPM0G3519) board.
|
||||
|
||||
You might need to adjust `.cargo/config.toml`, `Cargo.toml` and possibly update pin numbers or peripherals to match the specific MCU or board you are using.
|
||||
|
||||
* [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for G3519 it should be `probe-rs run --chip MSPM0G3519`. (use `probe-rs chip list` to find your chip)
|
||||
* [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For the LP-MSPM0G3519 it should be `mspm0g3519pz`. Look in the `Cargo.toml` file of the `embassy-mspm0` project to find the correct feature flag for your chip.
|
||||
* [ ] If your board has a special clock or power configuration, make sure that it is set up appropriately.
|
||||
* [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic
|
||||
|
||||
If you are unsure, please drop by the Embassy Matrix chat for support, and let us know:
|
||||
|
||||
* Which example you are trying to run
|
||||
* Which chip and board you are using
|
||||
|
||||
Embassy Chat: https://matrix.to/#/#embassy-rs:matrix.org
|
||||
37
examples/mspm0g3519/build.rs
Normal file
37
examples/mspm0g3519/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");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
6
examples/mspm0g3519/memory.x
Normal file
6
examples/mspm0g3519/memory.x
Normal file
@@ -0,0 +1,6 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x00000000, LENGTH = 512K
|
||||
/* Select non-parity range of SRAM due to SRAM_ERR_01 errata in SLAZ758 */
|
||||
RAM : ORIGIN = 0x20200000, LENGTH = 128K
|
||||
}
|
||||
25
examples/mspm0g3519/src/bin/blinky.rs
Normal file
25
examples/mspm0g3519/src/bin/blinky.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::Config;
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::Low);
|
||||
led1.set_inversion(true);
|
||||
|
||||
loop {
|
||||
Timer::after_millis(400).await;
|
||||
|
||||
info!("Toggle");
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
33
examples/mspm0g3519/src/bin/button.rs
Normal file
33
examples/mspm0g3519/src/bin/button.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_mspm0::Config;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let led1 = p.PA0;
|
||||
let s2 = p.PB3;
|
||||
|
||||
let mut led1 = Output::new(led1, Level::Low);
|
||||
|
||||
let mut s2 = Input::new(s2, Pull::Up);
|
||||
|
||||
// led1 is active low
|
||||
led1.set_high();
|
||||
|
||||
loop {
|
||||
s2.wait_for_falling_edge().await;
|
||||
|
||||
info!("Switch 2 was pressed");
|
||||
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
35
examples/mspm0g3519/src/bin/uart.rs
Normal file
35
examples/mspm0g3519/src/bin/uart.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
//! Example of using blocking uart
|
||||
//!
|
||||
//! This uses the virtual COM port provided on the LP-MSPM0G3519 board.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::uart::{Config, Uart};
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
|
||||
let instance = p.UART0;
|
||||
let tx = p.PA10;
|
||||
let rx = p.PA11;
|
||||
|
||||
let config = Config::default();
|
||||
let mut uart = unwrap!(Uart::new_blocking(instance, rx, tx, config));
|
||||
|
||||
unwrap!(uart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
|
||||
loop {
|
||||
unwrap!(uart.blocking_read(&mut buf));
|
||||
unwrap!(uart.blocking_write(&buf));
|
||||
}
|
||||
}
|
||||
9
examples/mspm0l1306/.cargo/config.toml
Normal file
9
examples/mspm0l1306/.cargo/config.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace MSPM0L1306 with your chip as listed in `probe-rs chip list`
|
||||
runner = "probe-rs run --chip MSPM0L1306 --protocol=swd"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "trace"
|
||||
21
examples/mspm0l1306/Cargo.toml
Normal file
21
examples/mspm0l1306/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "embassy-mspm0-l1306-examples"
|
||||
version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0l1306rhb", "defmt", "rt", "time-driver-any"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] }
|
||||
panic-halt = "1.0.0"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = { version = "0.7.0"}
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
panic-semihosting = "0.6.0"
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
27
examples/mspm0l1306/README.md
Normal file
27
examples/mspm0l1306/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Examples for MSPM0L1306
|
||||
|
||||
Run individual examples with
|
||||
```
|
||||
cargo run --bin <module-name>
|
||||
```
|
||||
for example
|
||||
```
|
||||
cargo run --bin blinky
|
||||
```
|
||||
|
||||
## Checklist before running examples
|
||||
A large number of the examples are written for the [LP-MSPM0L1306](https://www.ti.com/tool/LP-MSPM0L1306) board.
|
||||
|
||||
You might need to adjust `.cargo/config.toml`, `Cargo.toml` and possibly update pin numbers or peripherals to match the specific MCU or board you are using.
|
||||
|
||||
* [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for L1306 it should be `probe-rs run --chip MSPM0L1306`. (use `probe-rs chip list` to find your chip)
|
||||
* [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For the LP-MSPM0L1306 it should be `mspm0l1306rhb`. Look in the `Cargo.toml` file of the `embassy-mspm0` project to find the correct feature flag for your chip.
|
||||
* [ ] If your board has a special clock or power configuration, make sure that it is set up appropriately.
|
||||
* [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic
|
||||
|
||||
If you are unsure, please drop by the Embassy Matrix chat for support, and let us know:
|
||||
|
||||
* Which example you are trying to run
|
||||
* Which chip and board you are using
|
||||
|
||||
Embassy Chat: https://matrix.to/#/#embassy-rs:matrix.org
|
||||
37
examples/mspm0l1306/build.rs
Normal file
37
examples/mspm0l1306/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");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
5
examples/mspm0l1306/memory.x
Normal file
5
examples/mspm0l1306/memory.x
Normal file
@@ -0,0 +1,5 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x00000000, LENGTH = 64K
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 4K
|
||||
}
|
||||
25
examples/mspm0l1306/src/bin/blinky.rs
Normal file
25
examples/mspm0l1306/src/bin/blinky.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::Config;
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::Low);
|
||||
led1.set_inversion(true);
|
||||
|
||||
loop {
|
||||
Timer::after_millis(400).await;
|
||||
|
||||
info!("Toggle");
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
33
examples/mspm0l1306/src/bin/button.rs
Normal file
33
examples/mspm0l1306/src/bin/button.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_mspm0::Config;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let led1 = p.PA0;
|
||||
let s2 = p.PA14;
|
||||
|
||||
let mut led1 = Output::new(led1, Level::Low);
|
||||
|
||||
let mut s2 = Input::new(s2, Pull::Up);
|
||||
|
||||
// led1 is active low
|
||||
led1.set_high();
|
||||
|
||||
loop {
|
||||
s2.wait_for_falling_edge().await;
|
||||
|
||||
info!("Switch 2 was pressed");
|
||||
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
35
examples/mspm0l1306/src/bin/uart.rs
Normal file
35
examples/mspm0l1306/src/bin/uart.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
//! Example of using blocking uart
|
||||
//!
|
||||
//! This uses the virtual COM port provided on the LP-MSPM0L1306 board.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::uart::{Config, Uart};
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
|
||||
let instance = p.UART0;
|
||||
let tx = p.PA8;
|
||||
let rx = p.PA9;
|
||||
|
||||
let config = Config::default();
|
||||
let mut uart = unwrap!(Uart::new_blocking(instance, rx, tx, config));
|
||||
|
||||
unwrap!(uart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
|
||||
loop {
|
||||
unwrap!(uart.blocking_read(&mut buf));
|
||||
unwrap!(uart.blocking_write(&buf));
|
||||
}
|
||||
}
|
||||
9
examples/mspm0l2228/.cargo/config.toml
Normal file
9
examples/mspm0l2228/.cargo/config.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace MSPM0L2228 with your chip as listed in `probe-rs chip list`
|
||||
runner = "probe-rs run --restore-unwritten --verify --chip MSPM0L2228 --protocol=swd"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "trace"
|
||||
21
examples/mspm0l2228/Cargo.toml
Normal file
21
examples/mspm0l2228/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "embassy-mspm0-l2228-examples"
|
||||
version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0l2228pn", "defmt", "rt", "time-driver-any"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] }
|
||||
panic-halt = "1.0.0"
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = { version = "0.7.0"}
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
panic-semihosting = "0.6.0"
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
27
examples/mspm0l2228/README.md
Normal file
27
examples/mspm0l2228/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Examples for MSPM0L2228
|
||||
|
||||
Run individual examples with
|
||||
```
|
||||
cargo run --bin <module-name>
|
||||
```
|
||||
for example
|
||||
```
|
||||
cargo run --bin blinky
|
||||
```
|
||||
|
||||
## Checklist before running examples
|
||||
A large number of the examples are written for the [LP-MSPM0L2228](https://www.ti.com/tool/LP-MSPM0L2228) board.
|
||||
|
||||
You might need to adjust `.cargo/config.toml`, `Cargo.toml` and possibly update pin numbers or peripherals to match the specific MCU or board you are using.
|
||||
|
||||
* [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for L2228 it should be `probe-rs run --chip MSPM0L2228`. (use `probe-rs chip list` to find your chip)
|
||||
* [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For example for LP-MSPM0L2228 it should be `mspm0l2228pn`. Look in the `Cargo.toml` file of the `embassy-mspm0` project to find the correct feature flag for your chip.
|
||||
* [ ] If your board has a special clock or power configuration, make sure that it is set up appropriately.
|
||||
* [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic
|
||||
|
||||
If you are unsure, please drop by the Embassy Matrix chat for support, and let us know:
|
||||
|
||||
* Which example you are trying to run
|
||||
* Which chip and board you are using
|
||||
|
||||
Embassy Chat: https://matrix.to/#/#embassy-rs:matrix.org
|
||||
37
examples/mspm0l2228/build.rs
Normal file
37
examples/mspm0l2228/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");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
6
examples/mspm0l2228/memory.x
Normal file
6
examples/mspm0l2228/memory.x
Normal file
@@ -0,0 +1,6 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x00000000, LENGTH = 256K
|
||||
/* Select non-parity range of SRAM due to SRAM_ERR_01 errata in SLAZ758 */
|
||||
RAM : ORIGIN = 0x20200000, LENGTH = 32K
|
||||
}
|
||||
25
examples/mspm0l2228/src/bin/blinky.rs
Normal file
25
examples/mspm0l2228/src/bin/blinky.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::Config;
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::Low);
|
||||
led1.set_inversion(true);
|
||||
|
||||
loop {
|
||||
Timer::after_millis(400).await;
|
||||
|
||||
info!("Toggle");
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
33
examples/mspm0l2228/src/bin/button.rs
Normal file
33
examples/mspm0l2228/src/bin/button.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Input, Level, Output, Pull};
|
||||
use embassy_mspm0::Config;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Config::default());
|
||||
|
||||
let led1 = p.PA0;
|
||||
let s2 = p.PB8;
|
||||
|
||||
let mut led1 = Output::new(led1, Level::Low);
|
||||
|
||||
let mut s2 = Input::new(s2, Pull::Up);
|
||||
|
||||
// led1 is active low
|
||||
led1.set_high();
|
||||
|
||||
loop {
|
||||
s2.wait_for_falling_edge().await;
|
||||
|
||||
info!("Switch 2 was pressed");
|
||||
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
35
examples/mspm0l2228/src/bin/uart.rs
Normal file
35
examples/mspm0l2228/src/bin/uart.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
//! Example of using blocking uart
|
||||
//!
|
||||
//! This uses the virtual COM port provided on the LP-MSPM0L2228 board.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::uart::{Config, Uart};
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
|
||||
let instance = p.UART0;
|
||||
let tx = p.PA10;
|
||||
let rx = p.PA11;
|
||||
|
||||
let config = Config::default();
|
||||
let mut uart = unwrap!(Uart::new_blocking(instance, rx, tx, config));
|
||||
|
||||
unwrap!(uart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
|
||||
loop {
|
||||
unwrap!(uart.blocking_read(&mut buf));
|
||||
unwrap!(uart.blocking_write(&buf));
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,14 @@ log = [
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.6.0", path = "../../embassy-sync" }
|
||||
embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "rtos-trace", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../embassy-time" }
|
||||
embassy-nrf = { version = "0.2.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync" }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "rtos-trace"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time" }
|
||||
embassy-nrf = { version = "0.3.1", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
|
||||
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
panic-probe = { version = "0.3" }
|
||||
rand = { version = "0.8.4", default-features = false }
|
||||
panic-probe = "1.0.0"
|
||||
serde = { version = "1.0.136", default-features = false }
|
||||
rtos-trace = "0.1.3"
|
||||
systemview-target = { version = "0.1.2", features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] }
|
||||
|
||||
@@ -5,16 +5,16 @@ version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["task-arena-size-4096", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.2.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "gpiote", "time-driver-rtc1", "unstable-pac", "time", "rt"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.3.1", path = "../../embassy-nrf", features = ["defmt", "nrf51", "gpiote", "time-driver-rtc1", "unstable-pac", "time", "rt"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
|
||||
@@ -6,19 +6,19 @@ license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.2.0", path = "../../embassy-nrf", features = ["defmt", "nrf52810", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.3.1", path = "../../embassy-nrf", features = ["defmt", "nrf52810", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
|
||||
fixed = "1.10.0"
|
||||
static_cell = { version = "2" }
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
|
||||
@@ -8,16 +8,17 @@ license = "MIT OR Apache-2.0"
|
||||
rtic = { version = "2", features = ["thumbv7-backend"] }
|
||||
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../embassy-time", features = [ "defmt", "defmt-timestamp-uptime", "generic-queue"] }
|
||||
embassy-nrf = { version = "0.2.0", path = "../../embassy-nrf", features = [ "defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = [ "defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-time-queue-utils = { version = "0.1", path = "../../embassy-time-queue-utils", features = ["generic-queue-8"] }
|
||||
embassy-nrf = { version = "0.3.1", path = "../../embassy-nrf", features = [ "defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[rtic::app(device = embassy_nrf, peripherals = false, dispatchers = [SWI0_EGU0, SWI1_EGU1])]
|
||||
#[rtic::app(device = embassy_nrf, peripherals = false, dispatchers = [EGU0_SWI0, EGU1_SWI1])]
|
||||
mod app {
|
||||
use defmt::info;
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::peripherals;
|
||||
use embassy_nrf::{peripherals, Peri};
|
||||
use embassy_time::Timer;
|
||||
|
||||
#[shared]
|
||||
@@ -28,7 +28,7 @@ mod app {
|
||||
}
|
||||
|
||||
#[task(priority = 1)]
|
||||
async fn blink(_cx: blink::Context, pin: peripherals::P0_13) {
|
||||
async fn blink(_cx: blink::Context, pin: Peri<'static, peripherals::P0_13>) {
|
||||
let mut led = Output::new(pin, Level::Low, OutputDrive::Standard);
|
||||
|
||||
loop {
|
||||
|
||||
@@ -6,26 +6,26 @@ license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.2.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
embassy-net = { version = "0.4.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] }
|
||||
embassy-usb = { version = "0.3.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
|
||||
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.3.1", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
embassy-net = { version = "0.7.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] }
|
||||
embassy-usb = { version = "0.4.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embedded-io = { version = "0.6.0", features = ["defmt-03"] }
|
||||
embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
|
||||
embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] }
|
||||
embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] }
|
||||
embassy-net-esp-hosted = { version = "0.2.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] }
|
||||
embassy-net-enc28j60 = { version = "0.2.0", path = "../../embassy-net-enc28j60", features = ["defmt"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.0.0"
|
||||
|
||||
fixed = "1.10.0"
|
||||
static_cell = { version = "2" }
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
rand = { version = "0.8.4", default-features = false }
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"] }
|
||||
rand = { version = "0.9.0", default-features = false }
|
||||
embedded-storage = "0.3.1"
|
||||
usbd-hid = "0.8.1"
|
||||
serde = { version = "1.0.136", default-features = false }
|
||||
|
||||
@@ -9,7 +9,7 @@ use embedded_io_async::Write;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;
|
||||
UARTE0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
@@ -28,9 +28,9 @@ async fn main(_spawner: Spawner) {
|
||||
p.PPI_CH0,
|
||||
p.PPI_CH1,
|
||||
p.PPI_GROUP0,
|
||||
Irqs,
|
||||
p.P0_08,
|
||||
p.P0_06,
|
||||
Irqs,
|
||||
config,
|
||||
&mut rx_buffer,
|
||||
&mut tx_buffer,
|
||||
|
||||
@@ -35,8 +35,8 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
loop {
|
||||
match CHANNEL.receive().await {
|
||||
LedState::On => led.set_high(),
|
||||
LedState::Off => led.set_low(),
|
||||
LedState::On => led.set_low(),
|
||||
LedState::Off => led.set_high(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
use defmt::unwrap;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
|
||||
use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive};
|
||||
use embassy_nrf::Peri;
|
||||
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
|
||||
use embassy_sync::channel::{Channel, Receiver, Sender};
|
||||
use embassy_time::Timer;
|
||||
@@ -28,13 +29,13 @@ async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedState, 1>) {
|
||||
async fn recv_task(led: Peri<'static, AnyPin>, receiver: Receiver<'static, NoopRawMutex, LedState, 1>) {
|
||||
let mut led = Output::new(led, Level::Low, OutputDrive::Standard);
|
||||
|
||||
loop {
|
||||
match receiver.receive().await {
|
||||
LedState::On => led.set_high(),
|
||||
LedState::Off => led.set_low(),
|
||||
LedState::On => led.set_low(),
|
||||
LedState::Off => led.set_high(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,5 +46,5 @@ async fn main(spawner: Spawner) {
|
||||
let channel = CHANNEL.init(Channel::new());
|
||||
|
||||
unwrap!(spawner.spawn(send_task(channel.sender())));
|
||||
unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver())));
|
||||
unwrap!(spawner.spawn(recv_task(p.P0_13.into(), channel.receiver())));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Stack, StackResources};
|
||||
use embassy_net::StackResources;
|
||||
use embassy_net_enc28j60::Enc28j60;
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::rng::Rng;
|
||||
@@ -23,11 +23,12 @@ bind_interrupts!(struct Irqs {
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(
|
||||
stack: &'static Stack<
|
||||
mut runner: embassy_net::Runner<
|
||||
'static,
|
||||
Enc28j60<ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, Output<'static>>,
|
||||
>,
|
||||
) -> ! {
|
||||
stack.run().await
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
@@ -67,12 +68,9 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
// Init network stack
|
||||
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
|
||||
static STACK: StaticCell<
|
||||
Stack<Enc28j60<ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, Output<'static>>>,
|
||||
> = StaticCell::new();
|
||||
let stack = STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
|
||||
let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed);
|
||||
|
||||
unwrap!(spawner.spawn(net_task(stack)));
|
||||
unwrap!(spawner.spawn(net_task(runner)));
|
||||
|
||||
// And now we can use it!
|
||||
|
||||
|
||||
38
examples/nrf52840/src/bin/ieee802154_receive.rs
Normal file
38
examples/nrf52840/src/bin/ieee802154_receive.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::config::{Config, HfclkSource};
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::radio::ieee802154::{self, Packet};
|
||||
use embassy_nrf::{peripherals, radio};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
embassy_nrf::bind_interrupts!(struct Irqs {
|
||||
RADIO => radio::InterruptHandler<peripherals::RADIO>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = Config::default();
|
||||
config.hfclk_source = HfclkSource::ExternalXtal;
|
||||
let peripherals = embassy_nrf::init(config);
|
||||
|
||||
// assumes LED on P0_15 with active-high polarity
|
||||
let mut gpo_led = Output::new(peripherals.P0_15, Level::Low, OutputDrive::Standard);
|
||||
|
||||
let mut radio = ieee802154::Radio::new(peripherals.RADIO, Irqs);
|
||||
let mut packet = Packet::new();
|
||||
|
||||
loop {
|
||||
gpo_led.set_low();
|
||||
let rv = radio.receive(&mut packet).await;
|
||||
gpo_led.set_high();
|
||||
match rv {
|
||||
Err(_) => defmt::error!("receive() Err"),
|
||||
Ok(_) => defmt::info!("receive() {:?}", *packet),
|
||||
}
|
||||
Timer::after_millis(100u64).await;
|
||||
}
|
||||
}
|
||||
39
examples/nrf52840/src/bin/ieee802154_send.rs
Normal file
39
examples/nrf52840/src/bin/ieee802154_send.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::config::{Config, HfclkSource};
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::radio::ieee802154::{self, Packet};
|
||||
use embassy_nrf::{peripherals, radio};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
embassy_nrf::bind_interrupts!(struct Irqs {
|
||||
RADIO => radio::InterruptHandler<peripherals::RADIO>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = Config::default();
|
||||
config.hfclk_source = HfclkSource::ExternalXtal;
|
||||
let peripherals = embassy_nrf::init(config);
|
||||
|
||||
// assumes LED on P0_15 with active-high polarity
|
||||
let mut gpo_led = Output::new(peripherals.P0_15, Level::Low, OutputDrive::Standard);
|
||||
|
||||
let mut radio = ieee802154::Radio::new(peripherals.RADIO, Irqs);
|
||||
let mut packet = Packet::new();
|
||||
|
||||
loop {
|
||||
packet.copy_from_slice(&[0_u8; 16]);
|
||||
gpo_led.set_high();
|
||||
let rv = radio.try_send(&mut packet).await;
|
||||
gpo_led.set_low();
|
||||
match rv {
|
||||
Err(_) => defmt::error!("try_send() Err"),
|
||||
Ok(_) => defmt::info!("try_send() {:?}", *packet),
|
||||
}
|
||||
Timer::after_millis(1000u64).await;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user