aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMathias <[email protected]>2023-07-01 12:17:12 +0200
committerMathias <[email protected]>2023-07-03 19:33:26 +0200
commit60b2f075dcd561cdf3ff069c1cfc5d4177c1a133 (patch)
treeb3e285258cade6618d6bb14e826fee9cf0bb284a /examples
parentd372df7ddb381571fd2964e32b486b6d1cd1ad03 (diff)
parentba4344429264fa7beb99ab19c09059c2d531716d (diff)
Merge branch 'main' of https://github.com/embassy-rs/embassy into embassy-stm32/rcc-rtc-l4
Diffstat (limited to 'examples')
-rw-r--r--examples/boot/application/nrf/.cargo/config.toml4
-rw-r--r--examples/boot/application/nrf/Cargo.toml1
-rw-r--r--examples/boot/application/nrf/src/bin/a.rs7
-rw-r--r--examples/boot/application/rp/.cargo/config.toml2
-rw-r--r--examples/boot/application/rp/Cargo.toml1
-rw-r--r--examples/boot/application/rp/src/bin/a.rs6
-rw-r--r--examples/boot/application/stm32f3/.cargo/config.toml4
-rw-r--r--examples/boot/application/stm32f3/Cargo.toml1
-rw-r--r--examples/boot/application/stm32f3/src/bin/a.rs7
-rw-r--r--examples/boot/application/stm32f7/.cargo/config.toml4
-rw-r--r--examples/boot/application/stm32f7/Cargo.toml2
-rw-r--r--examples/boot/application/stm32f7/src/bin/a.rs13
-rw-r--r--examples/boot/application/stm32h7/.cargo/config.toml4
-rw-r--r--examples/boot/application/stm32h7/Cargo.toml2
-rwxr-xr-xexamples/boot/application/stm32h7/flash-boot.sh2
-rw-r--r--examples/boot/application/stm32h7/src/bin/a.rs13
-rw-r--r--examples/boot/application/stm32l0/.cargo/config.toml4
-rw-r--r--examples/boot/application/stm32l0/Cargo.toml1
-rw-r--r--examples/boot/application/stm32l0/src/bin/a.rs17
-rw-r--r--examples/boot/application/stm32l1/.cargo/config.toml4
-rw-r--r--examples/boot/application/stm32l1/Cargo.toml1
-rw-r--r--examples/boot/application/stm32l1/src/bin/a.rs8
-rw-r--r--examples/boot/application/stm32l4/.cargo/config.toml4
-rw-r--r--examples/boot/application/stm32l4/Cargo.toml1
-rw-r--r--examples/boot/application/stm32l4/src/bin/a.rs10
-rw-r--r--examples/boot/application/stm32wl/.cargo/config.toml4
-rw-r--r--examples/boot/application/stm32wl/Cargo.toml1
-rw-r--r--examples/boot/application/stm32wl/src/bin/a.rs12
-rw-r--r--examples/boot/bootloader/nrf/.cargo/config.toml2
-rw-r--r--examples/boot/bootloader/rp/.cargo/config.toml2
-rw-r--r--examples/nrf-rtos-trace/.cargo/config.toml4
-rw-r--r--examples/nrf52840-rtic/.cargo/config.toml9
-rw-r--r--examples/nrf52840-rtic/Cargo.toml21
-rw-r--r--examples/nrf52840-rtic/build.rs35
-rw-r--r--examples/nrf52840-rtic/memory.x7
-rw-r--r--examples/nrf52840-rtic/src/bin/blinky.rs43
-rw-r--r--examples/nrf52840/.cargo/config.toml4
-rw-r--r--examples/nrf52840/Cargo.toml22
-rw-r--r--examples/nrf52840/src/bin/multiprio.rs16
-rw-r--r--examples/nrf52840/src/bin/nvmc.rs2
-rw-r--r--examples/nrf52840/src/bin/self_spawn.rs6
-rw-r--r--examples/nrf52840/src/bin/usb_ethernet.rs6
-rw-r--r--examples/nrf52840/src/bin/wdt.rs2
-rw-r--r--examples/nrf52840/src/bin/wifi_esp_hosted.rs139
-rw-r--r--examples/nrf5340/.cargo/config.toml4
-rw-r--r--examples/rp/.cargo/config.toml2
-rw-r--r--examples/rp/Cargo.toml2
-rw-r--r--examples/rp/src/bin/button.rs5
-rw-r--r--examples/rp/src/bin/ethernet_w5500_multisocket.rs6
-rw-r--r--examples/rp/src/bin/ethernet_w5500_tcp_client.rs6
-rw-r--r--examples/rp/src/bin/ethernet_w5500_tcp_server.rs6
-rw-r--r--examples/rp/src/bin/ethernet_w5500_udp.rs6
-rw-r--r--examples/rp/src/bin/multiprio.rs18
-rw-r--r--examples/rp/src/bin/usb_ethernet.rs4
-rw-r--r--examples/rp/src/bin/wifi_ap_tcp_server.rs6
-rw-r--r--examples/rp/src/bin/wifi_blinky.rs59
-rw-r--r--examples/rp/src/bin/wifi_scan.rs4
-rw-r--r--examples/rp/src/bin/wifi_tcp_server.rs8
-rw-r--r--examples/std/README.md23
-rw-r--r--examples/std/src/bin/net.rs4
-rw-r--r--examples/std/src/bin/net_dns.rs4
-rw-r--r--examples/std/src/bin/net_udp.rs4
-rw-r--r--examples/std/src/bin/tcp_accept.rs4
-rw-r--r--examples/stm32c0/.cargo/config.toml4
-rw-r--r--examples/stm32c0/Cargo.toml2
-rw-r--r--examples/stm32f0/.cargo/config.toml2
-rw-r--r--examples/stm32f0/Cargo.toml2
-rw-r--r--examples/stm32f0/src/bin/multiprio.rs14
-rw-r--r--examples/stm32f0/src/bin/wdg.rs4
-rw-r--r--examples/stm32f1/.cargo/config.toml4
-rw-r--r--examples/stm32f1/Cargo.toml2
-rw-r--r--examples/stm32f2/.cargo/config.toml4
-rw-r--r--examples/stm32f2/Cargo.toml2
-rw-r--r--examples/stm32f3/.cargo/config.toml4
-rw-r--r--examples/stm32f3/Cargo.toml2
-rw-r--r--examples/stm32f3/src/bin/multiprio.rs14
-rw-r--r--examples/stm32f4/.cargo/config.toml4
-rw-r--r--examples/stm32f4/Cargo.toml2
-rw-r--r--examples/stm32f4/src/bin/can.rs13
-rw-r--r--examples/stm32f4/src/bin/dac.rs9
-rw-r--r--examples/stm32f4/src/bin/multiprio.rs14
-rw-r--r--examples/stm32f4/src/bin/usb_ethernet.rs8
-rw-r--r--examples/stm32f4/src/bin/usb_serial.rs4
-rw-r--r--examples/stm32f4/src/bin/wdt.rs8
-rw-r--r--examples/stm32f7/.cargo/config.toml4
-rw-r--r--examples/stm32f7/Cargo.toml2
-rw-r--r--examples/stm32f7/build.rs3
-rw-r--r--examples/stm32f7/src/bin/eth.rs4
-rw-r--r--examples/stm32f7/src/bin/usb_serial.rs4
-rw-r--r--examples/stm32g0/.cargo/config.toml4
-rw-r--r--examples/stm32g0/Cargo.toml2
-rw-r--r--examples/stm32g4/.cargo/config.toml4
-rw-r--r--examples/stm32g4/Cargo.toml3
-rw-r--r--examples/stm32g4/src/bin/pll.rs35
-rw-r--r--examples/stm32g4/src/bin/usb_serial.rs120
-rw-r--r--examples/stm32h5/.cargo/config.toml2
-rw-r--r--examples/stm32h5/Cargo.toml2
-rw-r--r--examples/stm32h5/src/bin/eth.rs4
-rw-r--r--examples/stm32h5/src/bin/usb_serial.rs8
-rw-r--r--examples/stm32h7/.cargo/config.toml2
-rw-r--r--examples/stm32h7/Cargo.toml2
-rw-r--r--examples/stm32h7/src/bin/dac.rs9
-rw-r--r--examples/stm32h7/src/bin/eth.rs4
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs4
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs54
-rw-r--r--examples/stm32h7/src/bin/usb_serial.rs4
-rw-r--r--examples/stm32h7/src/bin/wdg.rs4
-rw-r--r--examples/stm32l0/.cargo/config.toml4
-rw-r--r--examples/stm32l0/Cargo.toml2
-rw-r--r--examples/stm32l1/.cargo/config.toml4
-rw-r--r--examples/stm32l1/Cargo.toml2
-rw-r--r--examples/stm32l4/.cargo/config.toml8
-rw-r--r--examples/stm32l4/Cargo.toml4
-rw-r--r--examples/stm32l4/src/bin/adc.rs10
-rw-r--r--examples/stm32l4/src/bin/dac.rs19
-rw-r--r--examples/stm32l4/src/bin/dac_dma.rs137
-rw-r--r--examples/stm32l4/src/bin/rtc.rs1
-rw-r--r--examples/stm32l4/src/bin/usb_serial.rs4
-rw-r--r--examples/stm32l5/.cargo/config.toml4
-rw-r--r--examples/stm32l5/Cargo.toml2
-rw-r--r--examples/stm32l5/src/bin/usb_ethernet.rs4
-rw-r--r--examples/stm32u5/.cargo/config.toml4
-rw-r--r--examples/stm32u5/Cargo.toml2
-rw-r--r--examples/stm32u5/src/bin/usb_serial.rs4
-rw-r--r--examples/stm32wb/.cargo/config.toml4
-rw-r--r--examples/stm32wb/Cargo.toml24
-rw-r--r--examples/stm32wb/src/bin/eddystone_beacon.rs249
-rw-r--r--examples/stm32wb/src/bin/tl_mbox.rs13
-rw-r--r--examples/stm32wb/src/bin/tl_mbox_ble.rs (renamed from examples/stm32wb/src/bin/tl_mbox_tx_rx.rs)62
-rw-r--r--examples/stm32wb/src/bin/tl_mbox_mac.rs66
-rw-r--r--examples/stm32wl/.cargo/config.toml4
-rw-r--r--examples/stm32wl/Cargo.toml2
-rw-r--r--examples/stm32wl/src/bin/lora_lorawan.rs2
-rw-r--r--examples/stm32wl/src/bin/random.rs8
134 files changed, 1336 insertions, 354 deletions
diff --git a/examples/boot/application/nrf/.cargo/config.toml b/examples/boot/application/nrf/.cargo/config.toml
index 3872e7189..17616a054 100644
--- a/examples/boot/application/nrf/.cargo/config.toml
+++ b/examples/boot/application/nrf/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF82840_xxAA with your chip as listed in `probe-rs-cli chip list` 2# replace nRF82840_xxAA with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip nRF52840_xxAA" 3runner = "probe-rs run --chip nRF52840_xxAA"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabi" 6target = "thumbv7em-none-eabi"
diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml
index 5939a43b1..b98f73f39 100644
--- a/examples/boot/application/nrf/Cargo.toml
+++ b/examples/boot/application/nrf/Cargo.toml
@@ -24,3 +24,4 @@ cortex-m-rt = "0.7.0"
24[features] 24[features]
25ed25519-dalek = ["embassy-boot/ed25519-dalek"] 25ed25519-dalek = ["embassy-boot/ed25519-dalek"]
26ed25519-salty = ["embassy-boot/ed25519-salty"] 26ed25519-salty = ["embassy-boot/ed25519-salty"]
27skip-include = []
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs
index 06c237781..021d77f3b 100644
--- a/examples/boot/application/nrf/src/bin/a.rs
+++ b/examples/boot/application/nrf/src/bin/a.rs
@@ -12,6 +12,9 @@ use embassy_nrf::wdt::{self, Watchdog};
12use embassy_sync::mutex::Mutex; 12use embassy_sync::mutex::Mutex;
13use panic_reset as _; 13use panic_reset as _;
14 14
15#[cfg(feature = "skip-include")]
16static APP_B: &[u8] = &[0, 1, 2, 3];
17#[cfg(not(feature = "skip-include"))]
15static APP_B: &[u8] = include_bytes!("../../b.bin"); 18static APP_B: &[u8] = include_bytes!("../../b.bin");
16 19
17#[embassy_executor::main] 20#[embassy_executor::main]
@@ -55,13 +58,13 @@ async fn main(_spawner: Spawner) {
55 button.wait_for_any_edge().await; 58 button.wait_for_any_edge().await;
56 if button.is_low() { 59 if button.is_low() {
57 let mut offset = 0; 60 let mut offset = 0;
61 let mut magic = [0; 4];
58 for chunk in APP_B.chunks(4096) { 62 for chunk in APP_B.chunks(4096) {
59 let mut buf: [u8; 4096] = [0; 4096]; 63 let mut buf: [u8; 4096] = [0; 4096];
60 buf[..chunk.len()].copy_from_slice(chunk); 64 buf[..chunk.len()].copy_from_slice(chunk);
61 updater.write_firmware(offset, &buf).await.unwrap(); 65 updater.write_firmware(&mut magic, offset, &buf).await.unwrap();
62 offset += chunk.len(); 66 offset += chunk.len();
63 } 67 }
64 let mut magic = [0; 4];
65 updater.mark_updated(&mut magic).await.unwrap(); 68 updater.mark_updated(&mut magic).await.unwrap();
66 led.set_high(); 69 led.set_high();
67 cortex_m::peripheral::SCB::sys_reset(); 70 cortex_m::peripheral::SCB::sys_reset();
diff --git a/examples/boot/application/rp/.cargo/config.toml b/examples/boot/application/rp/.cargo/config.toml
index 278c24a57..cd8d1ef02 100644
--- a/examples/boot/application/rp/.cargo/config.toml
+++ b/examples/boot/application/rp/.cargo/config.toml
@@ -3,7 +3,7 @@ build-std = ["core"]
3build-std-features = ["panic_immediate_abort"] 3build-std-features = ["panic_immediate_abort"]
4 4
5[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 5[target.'cfg(all(target_arch = "arm", target_os = "none"))']
6runner = "probe-rs-cli run --chip RP2040" 6runner = "probe-rs run --chip RP2040"
7 7
8[build] 8[build]
9target = "thumbv6m-none-eabi" 9target = "thumbv6m-none-eabi"
diff --git a/examples/boot/application/rp/Cargo.toml b/examples/boot/application/rp/Cargo.toml
index 4a2c5dd8f..007b6839c 100644
--- a/examples/boot/application/rp/Cargo.toml
+++ b/examples/boot/application/rp/Cargo.toml
@@ -29,6 +29,7 @@ debug = [
29 "embassy-boot-rp/defmt", 29 "embassy-boot-rp/defmt",
30 "panic-probe" 30 "panic-probe"
31] 31]
32skip-include = []
32 33
33[profile.release] 34[profile.release]
34debug = true 35debug = true
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs
index 69850069b..c8497494c 100644
--- a/examples/boot/application/rp/src/bin/a.rs
+++ b/examples/boot/application/rp/src/bin/a.rs
@@ -18,7 +18,11 @@ use panic_probe as _;
18#[cfg(feature = "panic-reset")] 18#[cfg(feature = "panic-reset")]
19use panic_reset as _; 19use panic_reset as _;
20 20
21#[cfg(feature = "skip-include")]
22static APP_B: &[u8] = &[0, 1, 2, 3];
23#[cfg(not(feature = "skip-include"))]
21static APP_B: &[u8] = include_bytes!("../../b.bin"); 24static APP_B: &[u8] = include_bytes!("../../b.bin");
25
22const FLASH_SIZE: usize = 2 * 1024 * 1024; 26const FLASH_SIZE: usize = 2 * 1024 * 1024;
23 27
24#[embassy_executor::main] 28#[embassy_executor::main]
@@ -43,7 +47,7 @@ async fn main(_s: Spawner) {
43 let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]); 47 let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]);
44 defmt::info!("preparing update"); 48 defmt::info!("preparing update");
45 let writer = updater 49 let writer = updater
46 .prepare_update() 50 .prepare_update(&mut buf.0[..1])
47 .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e))) 51 .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e)))
48 .unwrap(); 52 .unwrap();
49 defmt::info!("writer created, starting write"); 53 defmt::info!("writer created, starting write");
diff --git a/examples/boot/application/stm32f3/.cargo/config.toml b/examples/boot/application/stm32f3/.cargo/config.toml
index 9fc2396e8..4a7ec0a5b 100644
--- a/examples/boot/application/stm32f3/.cargo/config.toml
+++ b/examples/boot/application/stm32f3/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F429ZITx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32F303VCTx" 3runner = "probe-rs run --chip STM32F303VCTx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabihf"
diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml
index 24abd90d4..5b3faf8f8 100644
--- a/examples/boot/application/stm32f3/Cargo.toml
+++ b/examples/boot/application/stm32f3/Cargo.toml
@@ -26,3 +26,4 @@ defmt = [
26 "embassy-stm32/defmt", 26 "embassy-stm32/defmt",
27 "embassy-boot-stm32/defmt", 27 "embassy-boot-stm32/defmt",
28] 28]
29skip-include = []
diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs
index c94676f09..c0a11d699 100644
--- a/examples/boot/application/stm32f3/src/bin/a.rs
+++ b/examples/boot/application/stm32f3/src/bin/a.rs
@@ -13,6 +13,9 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_sync::mutex::Mutex; 13use embassy_sync::mutex::Mutex;
14use panic_reset as _; 14use panic_reset as _;
15 15
16#[cfg(feature = "skip-include")]
17static APP_B: &[u8] = &[0, 1, 2, 3];
18#[cfg(not(feature = "skip-include"))]
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 19static APP_B: &[u8] = include_bytes!("../../b.bin");
17 20
18#[embassy_executor::main] 21#[embassy_executor::main]
@@ -31,13 +34,13 @@ async fn main(_spawner: Spawner) {
31 let mut updater = FirmwareUpdater::new(config); 34 let mut updater = FirmwareUpdater::new(config);
32 button.wait_for_falling_edge().await; 35 button.wait_for_falling_edge().await;
33 let mut offset = 0; 36 let mut offset = 0;
37 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
34 for chunk in APP_B.chunks(2048) { 38 for chunk in APP_B.chunks(2048) {
35 let mut buf: [u8; 2048] = [0; 2048]; 39 let mut buf: [u8; 2048] = [0; 2048];
36 buf[..chunk.len()].copy_from_slice(chunk); 40 buf[..chunk.len()].copy_from_slice(chunk);
37 updater.write_firmware(offset, &buf).await.unwrap(); 41 updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap();
38 offset += chunk.len(); 42 offset += chunk.len();
39 } 43 }
40 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
41 updater.mark_updated(magic.as_mut()).await.unwrap(); 44 updater.mark_updated(magic.as_mut()).await.unwrap();
42 led.set_low(); 45 led.set_low();
43 cortex_m::peripheral::SCB::sys_reset(); 46 cortex_m::peripheral::SCB::sys_reset();
diff --git a/examples/boot/application/stm32f7/.cargo/config.toml b/examples/boot/application/stm32f7/.cargo/config.toml
index 7d6c88a99..9088eea6e 100644
--- a/examples/boot/application/stm32f7/.cargo/config.toml
+++ b/examples/boot/application/stm32f7/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F429ZITx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32F767ZITx" 3runner = "probe-rs run --chip STM32F767ZITx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabihf"
diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml
index 529a01aad..b6a6f9cd8 100644
--- a/examples/boot/application/stm32f7/Cargo.toml
+++ b/examples/boot/application/stm32f7/Cargo.toml
@@ -16,6 +16,7 @@ defmt = { version = "0.3", optional = true }
16defmt-rtt = { version = "0.4", optional = true } 16defmt-rtt = { version = "0.4", optional = true }
17panic-reset = { version = "0.1.1" } 17panic-reset = { version = "0.1.1" }
18embedded-hal = { version = "0.2.6" } 18embedded-hal = { version = "0.2.6" }
19embedded-storage = "0.3.0"
19 20
20cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } 21cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
21cortex-m-rt = "0.7.0" 22cortex-m-rt = "0.7.0"
@@ -26,3 +27,4 @@ defmt = [
26 "embassy-stm32/defmt", 27 "embassy-stm32/defmt",
27 "embassy-boot-stm32/defmt", 28 "embassy-boot-stm32/defmt",
28] 29]
30skip-include = []
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs
index fc2702c91..dea682a96 100644
--- a/examples/boot/application/stm32f7/src/bin/a.rs
+++ b/examples/boot/application/stm32f7/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::cell::RefCell;
6
5#[cfg(feature = "defmt-rtt")] 7#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 8use defmt_rtt::*;
7use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; 9use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig};
@@ -9,8 +11,13 @@ use embassy_executor::Spawner;
9use embassy_stm32::exti::ExtiInput; 11use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::{Flash, WRITE_SIZE}; 12use embassy_stm32::flash::{Flash, WRITE_SIZE};
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 13use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
14use embassy_sync::blocking_mutex::Mutex;
15use embedded_storage::nor_flash::NorFlash;
12use panic_reset as _; 16use panic_reset as _;
13 17
18#[cfg(feature = "skip-include")]
19static APP_B: &[u8] = &[0, 1, 2, 3];
20#[cfg(not(feature = "skip-include"))]
14static APP_B: &[u8] = include_bytes!("../../b.bin"); 21static APP_B: &[u8] = include_bytes!("../../b.bin");
15 22
16#[embassy_executor::main] 23#[embassy_executor::main]
@@ -27,16 +34,16 @@ async fn main(_spawner: Spawner) {
27 34
28 let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); 35 let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash);
29 let mut updater = BlockingFirmwareUpdater::new(config); 36 let mut updater = BlockingFirmwareUpdater::new(config);
30 let mut writer = updater.prepare_update().unwrap(); 37 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
38 let writer = updater.prepare_update(magic.as_mut()).unwrap();
31 button.wait_for_rising_edge().await; 39 button.wait_for_rising_edge().await;
32 let mut offset = 0; 40 let mut offset = 0;
33 let mut buf = AlignedBuffer([0; 4096]); 41 let mut buf = AlignedBuffer([0; 4096]);
34 for chunk in APP_B.chunks(4096) { 42 for chunk in APP_B.chunks(4096) {
35 buf.as_mut()[..chunk.len()].copy_from_slice(chunk); 43 buf.as_mut()[..chunk.len()].copy_from_slice(chunk);
36 writer.write(offset, buf.as_ref()).unwrap(); 44 writer.write(offset, buf.as_ref()).unwrap();
37 offset += chunk.len(); 45 offset += chunk.len() as u32;
38 } 46 }
39 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
40 updater.mark_updated(magic.as_mut()).unwrap(); 47 updater.mark_updated(magic.as_mut()).unwrap();
41 led.set_low(); 48 led.set_low();
42 cortex_m::peripheral::SCB::sys_reset(); 49 cortex_m::peripheral::SCB::sys_reset();
diff --git a/examples/boot/application/stm32h7/.cargo/config.toml b/examples/boot/application/stm32h7/.cargo/config.toml
index 067a5c89b..caa0d3a93 100644
--- a/examples/boot/application/stm32h7/.cargo/config.toml
+++ b/examples/boot/application/stm32h7/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F429ZITx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32H743ZITx" 3runner = "probe-rs run --chip STM32H743ZITx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabihf"
diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml
index d7539a53f..0a7e19b1d 100644
--- a/examples/boot/application/stm32h7/Cargo.toml
+++ b/examples/boot/application/stm32h7/Cargo.toml
@@ -16,6 +16,7 @@ defmt = { version = "0.3", optional = true }
16defmt-rtt = { version = "0.4", optional = true } 16defmt-rtt = { version = "0.4", optional = true }
17panic-reset = { version = "0.1.1" } 17panic-reset = { version = "0.1.1" }
18embedded-hal = { version = "0.2.6" } 18embedded-hal = { version = "0.2.6" }
19embedded-storage = "0.3.0"
19 20
20cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } 21cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
21cortex-m-rt = "0.7.0" 22cortex-m-rt = "0.7.0"
@@ -26,3 +27,4 @@ defmt = [
26 "embassy-stm32/defmt", 27 "embassy-stm32/defmt",
27 "embassy-boot-stm32/defmt", 28 "embassy-boot-stm32/defmt",
28] 29]
30skip-include = []
diff --git a/examples/boot/application/stm32h7/flash-boot.sh b/examples/boot/application/stm32h7/flash-boot.sh
index a3003681a..4912a50b7 100755
--- a/examples/boot/application/stm32h7/flash-boot.sh
+++ b/examples/boot/application/stm32h7/flash-boot.sh
@@ -1,5 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2probe-rs-cli erase --chip STM32H743ZITx 2probe-rs erase --chip STM32H743ZITx
3mv ../../bootloader/stm32/memory.x ../../bootloader/stm32/memory-old.x 3mv ../../bootloader/stm32/memory.x ../../bootloader/stm32/memory-old.x
4cp memory-bl.x ../../bootloader/stm32/memory.x 4cp memory-bl.x ../../bootloader/stm32/memory.x
5 5
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs
index 1a54464d0..719176692 100644
--- a/examples/boot/application/stm32h7/src/bin/a.rs
+++ b/examples/boot/application/stm32h7/src/bin/a.rs
@@ -2,6 +2,8 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::cell::RefCell;
6
5#[cfg(feature = "defmt-rtt")] 7#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 8use defmt_rtt::*;
7use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; 9use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig};
@@ -9,8 +11,13 @@ use embassy_executor::Spawner;
9use embassy_stm32::exti::ExtiInput; 11use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::{Flash, WRITE_SIZE}; 12use embassy_stm32::flash::{Flash, WRITE_SIZE};
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 13use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
14use embassy_sync::blocking_mutex::Mutex;
15use embedded_storage::nor_flash::NorFlash;
12use panic_reset as _; 16use panic_reset as _;
13 17
18#[cfg(feature = "skip-include")]
19static APP_B: &[u8] = &[0, 1, 2, 3];
20#[cfg(not(feature = "skip-include"))]
14static APP_B: &[u8] = include_bytes!("../../b.bin"); 21static APP_B: &[u8] = include_bytes!("../../b.bin");
15 22
16#[embassy_executor::main] 23#[embassy_executor::main]
@@ -26,17 +33,17 @@ async fn main(_spawner: Spawner) {
26 led.set_high(); 33 led.set_high();
27 34
28 let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); 35 let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash);
36 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
29 let mut updater = BlockingFirmwareUpdater::new(config); 37 let mut updater = BlockingFirmwareUpdater::new(config);
30 let mut writer = updater.prepare_update().unwrap(); 38 let writer = updater.prepare_update(magic.as_mut()).unwrap();
31 button.wait_for_rising_edge().await; 39 button.wait_for_rising_edge().await;
32 let mut offset = 0; 40 let mut offset = 0;
33 let mut buf = AlignedBuffer([0; 4096]); 41 let mut buf = AlignedBuffer([0; 4096]);
34 for chunk in APP_B.chunks(4096) { 42 for chunk in APP_B.chunks(4096) {
35 buf.as_mut()[..chunk.len()].copy_from_slice(chunk); 43 buf.as_mut()[..chunk.len()].copy_from_slice(chunk);
36 writer.write(offset, buf.as_ref()).unwrap(); 44 writer.write(offset, buf.as_ref()).unwrap();
37 offset += chunk.len(); 45 offset += chunk.len() as u32;
38 } 46 }
39 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
40 updater.mark_updated(magic.as_mut()).unwrap(); 47 updater.mark_updated(magic.as_mut()).unwrap();
41 led.set_low(); 48 led.set_low();
42 cortex_m::peripheral::SCB::sys_reset(); 49 cortex_m::peripheral::SCB::sys_reset();
diff --git a/examples/boot/application/stm32l0/.cargo/config.toml b/examples/boot/application/stm32l0/.cargo/config.toml
index ce0e460bd..6099f015c 100644
--- a/examples/boot/application/stm32l0/.cargo/config.toml
+++ b/examples/boot/application/stm32l0/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-rs-cli chip list` 2# replace your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32L072CZTx" 3runner = "probe-rs run --chip STM32L072CZTx"
4 4
5[build] 5[build]
6target = "thumbv6m-none-eabi" 6target = "thumbv6m-none-eabi"
diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml
index e90da259b..998df4dc0 100644
--- a/examples/boot/application/stm32l0/Cargo.toml
+++ b/examples/boot/application/stm32l0/Cargo.toml
@@ -26,3 +26,4 @@ defmt = [
26 "embassy-stm32/defmt", 26 "embassy-stm32/defmt",
27 "embassy-boot-stm32/defmt", 27 "embassy-boot-stm32/defmt",
28] 28]
29skip-include = []
diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs
index 4033ac590..ce80056e6 100644
--- a/examples/boot/application/stm32l0/src/bin/a.rs
+++ b/examples/boot/application/stm32l0/src/bin/a.rs
@@ -4,22 +4,26 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::{Flash, WRITE_SIZE}; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_sync::mutex::Mutex;
13use embassy_time::{Duration, Timer}; 14use embassy_time::{Duration, Timer};
14use panic_reset as _; 15use panic_reset as _;
15 16
17#[cfg(feature = "skip-include")]
18static APP_B: &[u8] = &[0, 1, 2, 3];
19#[cfg(not(feature = "skip-include"))]
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 20static APP_B: &[u8] = include_bytes!("../../b.bin");
17 21
18#[embassy_executor::main] 22#[embassy_executor::main]
19async fn main(_spawner: Spawner) { 23async fn main(_spawner: Spawner) {
20 let p = embassy_stm32::init(Default::default()); 24 let p = embassy_stm32::init(Default::default());
21 let flash = Flash::new_blocking(p.FLASH); 25 let flash = Flash::new_blocking(p.FLASH);
22 let mut flash = BlockingAsync::new(flash); 26 let flash = Mutex::new(BlockingAsync::new(flash));
23 27
24 let button = Input::new(p.PB2, Pull::Up); 28 let button = Input::new(p.PB2, Pull::Up);
25 let mut button = ExtiInput::new(button, p.EXTI2); 29 let mut button = ExtiInput::new(button, p.EXTI2);
@@ -28,18 +32,19 @@ async fn main(_spawner: Spawner) {
28 32
29 led.set_high(); 33 led.set_high();
30 34
31 let mut updater = FirmwareUpdater::default(); 35 let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
36 let mut updater = FirmwareUpdater::new(config);
32 button.wait_for_falling_edge().await; 37 button.wait_for_falling_edge().await;
33 let mut offset = 0; 38 let mut offset = 0;
39 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
34 for chunk in APP_B.chunks(128) { 40 for chunk in APP_B.chunks(128) {
35 let mut buf: [u8; 128] = [0; 128]; 41 let mut buf: [u8; 128] = [0; 128];
36 buf[..chunk.len()].copy_from_slice(chunk); 42 buf[..chunk.len()].copy_from_slice(chunk);
37 updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); 43 updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap();
38 offset += chunk.len(); 44 offset += chunk.len();
39 } 45 }
40 46
41 let mut magic = AlignedBuffer([0; WRITE_SIZE]); 47 updater.mark_updated(magic.as_mut()).await.unwrap();
42 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
43 led.set_low(); 48 led.set_low();
44 Timer::after(Duration::from_secs(1)).await; 49 Timer::after(Duration::from_secs(1)).await;
45 cortex_m::peripheral::SCB::sys_reset(); 50 cortex_m::peripheral::SCB::sys_reset();
diff --git a/examples/boot/application/stm32l1/.cargo/config.toml b/examples/boot/application/stm32l1/.cargo/config.toml
index 1401500a0..9cabd14ba 100644
--- a/examples/boot/application/stm32l1/.cargo/config.toml
+++ b/examples/boot/application/stm32l1/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-rs-cli chip list` 2# replace your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32L151CBxxA" 3runner = "probe-rs run --chip STM32L151CBxxA"
4 4
5[build] 5[build]
6target = "thumbv7m-none-eabi" 6target = "thumbv7m-none-eabi"
diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml
index 8ac0fac85..10b58c172 100644
--- a/examples/boot/application/stm32l1/Cargo.toml
+++ b/examples/boot/application/stm32l1/Cargo.toml
@@ -26,3 +26,4 @@ defmt = [
26 "embassy-stm32/defmt", 26 "embassy-stm32/defmt",
27 "embassy-boot-stm32/defmt", 27 "embassy-boot-stm32/defmt",
28] 28]
29skip-include = []
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs
index 00ddda636..1e9bf3cb9 100644
--- a/examples/boot/application/stm32l1/src/bin/a.rs
+++ b/examples/boot/application/stm32l1/src/bin/a.rs
@@ -10,9 +10,13 @@ use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::{Flash, WRITE_SIZE}; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_sync::mutex::Mutex;
13use embassy_time::{Duration, Timer}; 14use embassy_time::{Duration, Timer};
14use panic_reset as _; 15use panic_reset as _;
15 16
17#[cfg(feature = "skip-include")]
18static APP_B: &[u8] = &[0, 1, 2, 3];
19#[cfg(not(feature = "skip-include"))]
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 20static APP_B: &[u8] = include_bytes!("../../b.bin");
17 21
18#[embassy_executor::main] 22#[embassy_executor::main]
@@ -31,15 +35,15 @@ async fn main(_spawner: Spawner) {
31 let config = FirmwareUpdaterConfig::from_linkerfile(&flash); 35 let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
32 let mut updater = FirmwareUpdater::new(config); 36 let mut updater = FirmwareUpdater::new(config);
33 button.wait_for_falling_edge().await; 37 button.wait_for_falling_edge().await;
38 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
34 let mut offset = 0; 39 let mut offset = 0;
35 for chunk in APP_B.chunks(128) { 40 for chunk in APP_B.chunks(128) {
36 let mut buf: [u8; 128] = [0; 128]; 41 let mut buf: [u8; 128] = [0; 128];
37 buf[..chunk.len()].copy_from_slice(chunk); 42 buf[..chunk.len()].copy_from_slice(chunk);
38 updater.write_firmware(offset, &buf).await.unwrap(); 43 updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap();
39 offset += chunk.len(); 44 offset += chunk.len();
40 } 45 }
41 46
42 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
43 updater.mark_updated(magic.as_mut()).await.unwrap(); 47 updater.mark_updated(magic.as_mut()).await.unwrap();
44 led.set_low(); 48 led.set_low();
45 Timer::after(Duration::from_secs(1)).await; 49 Timer::after(Duration::from_secs(1)).await;
diff --git a/examples/boot/application/stm32l4/.cargo/config.toml b/examples/boot/application/stm32l4/.cargo/config.toml
index 48ff3734b..c803215f6 100644
--- a/examples/boot/application/stm32l4/.cargo/config.toml
+++ b/examples/boot/application/stm32l4/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-rs-cli chip list` 2# replace your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32L475VG" 3runner = "probe-rs run --chip STM32L475VG"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabihf"
diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml
index ec79acdeb..713a6527e 100644
--- a/examples/boot/application/stm32l4/Cargo.toml
+++ b/examples/boot/application/stm32l4/Cargo.toml
@@ -26,3 +26,4 @@ defmt = [
26 "embassy-stm32/defmt", 26 "embassy-stm32/defmt",
27 "embassy-boot-stm32/defmt", 27 "embassy-boot-stm32/defmt",
28] 28]
29skip-include = []
diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs
index 54579e4ac..a514ab5be 100644
--- a/examples/boot/application/stm32l4/src/bin/a.rs
+++ b/examples/boot/application/stm32l4/src/bin/a.rs
@@ -10,8 +10,12 @@ use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::{Flash, WRITE_SIZE}; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_sync::mutex::Mutex;
13use panic_reset as _; 14use panic_reset as _;
14 15
16#[cfg(feature = "skip-include")]
17static APP_B: &[u8] = &[0, 1, 2, 3];
18#[cfg(not(feature = "skip-include"))]
15static APP_B: &[u8] = include_bytes!("../../b.bin"); 19static APP_B: &[u8] = include_bytes!("../../b.bin");
16 20
17#[embassy_executor::main] 21#[embassy_executor::main]
@@ -29,15 +33,15 @@ async fn main(_spawner: Spawner) {
29 let config = FirmwareUpdaterConfig::from_linkerfile(&flash); 33 let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
30 let mut updater = FirmwareUpdater::new(config); 34 let mut updater = FirmwareUpdater::new(config);
31 button.wait_for_falling_edge().await; 35 button.wait_for_falling_edge().await;
36 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
32 let mut offset = 0; 37 let mut offset = 0;
33 for chunk in APP_B.chunks(2048) { 38 for chunk in APP_B.chunks(2048) {
34 let mut buf: [u8; 2048] = [0; 2048]; 39 let mut buf: [u8; 2048] = [0; 2048];
35 buf[..chunk.len()].copy_from_slice(chunk); 40 buf[..chunk.len()].copy_from_slice(chunk);
36 updater.write_firmware(offset, &buf).await.unwrap(); 41 updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap();
37 offset += chunk.len(); 42 offset += chunk.len();
38 } 43 }
39 let mut magic = AlignedBuffer([0; WRITE_SIZE]); 44 updater.mark_updated(magic.as_mut()).await.unwrap();
40 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
41 led.set_low(); 45 led.set_low();
42 cortex_m::peripheral::SCB::sys_reset(); 46 cortex_m::peripheral::SCB::sys_reset();
43} 47}
diff --git a/examples/boot/application/stm32wl/.cargo/config.toml b/examples/boot/application/stm32wl/.cargo/config.toml
index b49b582e0..4f8094ff2 100644
--- a/examples/boot/application/stm32wl/.cargo/config.toml
+++ b/examples/boot/application/stm32wl/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-rs-cli chip list` 2# replace your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32WLE5JCIx" 3runner = "probe-rs run --chip STM32WLE5JCIx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabihf"
diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml
index dfaece6cf..4c8bbd73f 100644
--- a/examples/boot/application/stm32wl/Cargo.toml
+++ b/examples/boot/application/stm32wl/Cargo.toml
@@ -26,3 +26,4 @@ defmt = [
26 "embassy-stm32/defmt", 26 "embassy-stm32/defmt",
27 "embassy-boot-stm32/defmt", 27 "embassy-boot-stm32/defmt",
28] 28]
29skip-include = []
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs
index 0c6fa05f9..52a197a5c 100644
--- a/examples/boot/application/stm32wl/src/bin/a.rs
+++ b/examples/boot/application/stm32wl/src/bin/a.rs
@@ -4,21 +4,25 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::{Flash, WRITE_SIZE}; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_sync::mutex::Mutex;
13use panic_reset as _; 14use panic_reset as _;
14 15
16#[cfg(feature = "skip-include")]
17static APP_B: &[u8] = &[0, 1, 2, 3];
18#[cfg(not(feature = "skip-include"))]
15static APP_B: &[u8] = include_bytes!("../../b.bin"); 19static APP_B: &[u8] = include_bytes!("../../b.bin");
16 20
17#[embassy_executor::main] 21#[embassy_executor::main]
18async fn main(_spawner: Spawner) { 22async fn main(_spawner: Spawner) {
19 let p = embassy_stm32::init(Default::default()); 23 let p = embassy_stm32::init(Default::default());
20 let flash = Flash::new_blocking(p.FLASH); 24 let flash = Flash::new_blocking(p.FLASH);
21 let mut flash = Mutex::new(BlockingAsync::new(flash)); 25 let flash = Mutex::new(BlockingAsync::new(flash));
22 26
23 let button = Input::new(p.PA0, Pull::Up); 27 let button = Input::new(p.PA0, Pull::Up);
24 let mut button = ExtiInput::new(button, p.EXTI0); 28 let mut button = ExtiInput::new(button, p.EXTI0);
@@ -30,15 +34,15 @@ async fn main(_spawner: Spawner) {
30 let mut updater = FirmwareUpdater::new(config); 34 let mut updater = FirmwareUpdater::new(config);
31 button.wait_for_falling_edge().await; 35 button.wait_for_falling_edge().await;
32 //defmt::info!("Starting update"); 36 //defmt::info!("Starting update");
37 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
33 let mut offset = 0; 38 let mut offset = 0;
34 for chunk in APP_B.chunks(2048) { 39 for chunk in APP_B.chunks(2048) {
35 let mut buf: [u8; 2048] = [0; 2048]; 40 let mut buf: [u8; 2048] = [0; 2048];
36 buf[..chunk.len()].copy_from_slice(chunk); 41 buf[..chunk.len()].copy_from_slice(chunk);
37 // defmt::info!("Writing chunk at 0x{:x}", offset); 42 // defmt::info!("Writing chunk at 0x{:x}", offset);
38 updater.write_firmware(offset, &buf).await.unwrap(); 43 updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap();
39 offset += chunk.len(); 44 offset += chunk.len();
40 } 45 }
41 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
42 updater.mark_updated(magic.as_mut()).await.unwrap(); 46 updater.mark_updated(magic.as_mut()).await.unwrap();
43 //defmt::info!("Marked as updated"); 47 //defmt::info!("Marked as updated");
44 led.set_low(); 48 led.set_low();
diff --git a/examples/boot/bootloader/nrf/.cargo/config.toml b/examples/boot/bootloader/nrf/.cargo/config.toml
index d636b1d23..c292846aa 100644
--- a/examples/boot/bootloader/nrf/.cargo/config.toml
+++ b/examples/boot/bootloader/nrf/.cargo/config.toml
@@ -4,7 +4,7 @@ build-std-features = ["panic_immediate_abort"]
4 4
5[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 5[target.'cfg(all(target_arch = "arm", target_os = "none"))']
6#runner = "./fruitrunner" 6#runner = "./fruitrunner"
7runner = "probe-rs-cli run --chip nrf52840_xxAA" 7runner = "probe-rs run --chip nrf52840_xxAA"
8 8
9rustflags = [ 9rustflags = [
10 # Code-size optimizations. 10 # Code-size optimizations.
diff --git a/examples/boot/bootloader/rp/.cargo/config.toml b/examples/boot/bootloader/rp/.cargo/config.toml
index 795ee043a..9d48ecdc9 100644
--- a/examples/boot/bootloader/rp/.cargo/config.toml
+++ b/examples/boot/bootloader/rp/.cargo/config.toml
@@ -1,5 +1,5 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2runner = "probe-rs-cli run --chip RP2040" 2runner = "probe-rs run --chip RP2040"
3 3
4[build] 4[build]
5target = "thumbv6m-none-eabi" 5target = "thumbv6m-none-eabi"
diff --git a/examples/nrf-rtos-trace/.cargo/config.toml b/examples/nrf-rtos-trace/.cargo/config.toml
index 3872e7189..17616a054 100644
--- a/examples/nrf-rtos-trace/.cargo/config.toml
+++ b/examples/nrf-rtos-trace/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF82840_xxAA with your chip as listed in `probe-rs-cli chip list` 2# replace nRF82840_xxAA with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip nRF52840_xxAA" 3runner = "probe-rs run --chip nRF52840_xxAA"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabi" 6target = "thumbv7em-none-eabi"
diff --git a/examples/nrf52840-rtic/.cargo/config.toml b/examples/nrf52840-rtic/.cargo/config.toml
new file mode 100644
index 000000000..17616a054
--- /dev/null
+++ b/examples/nrf52840-rtic/.cargo/config.toml
@@ -0,0 +1,9 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF82840_xxAA with your chip as listed in `probe-rs chip list`
3runner = "probe-rs run --chip nRF52840_xxAA"
4
5[build]
6target = "thumbv7em-none-eabi"
7
8[env]
9DEFMT_LOG = "trace"
diff --git a/examples/nrf52840-rtic/Cargo.toml b/examples/nrf52840-rtic/Cargo.toml
new file mode 100644
index 000000000..0f9048b0f
--- /dev/null
+++ b/examples/nrf52840-rtic/Cargo.toml
@@ -0,0 +1,21 @@
1[package]
2edition = "2021"
3name = "embassy-nrf52840-rtic-examples"
4version = "0.1.0"
5license = "MIT OR Apache-2.0"
6
7[dependencies]
8rtic = { version = "2", features = ["thumbv7-backend"] }
9
10embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
11embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
12embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "generic-queue"] }
13embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nightly", "unstable-traits", "defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
14
15defmt = "0.3"
16defmt-rtt = "0.4"
17
18cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
19cortex-m-rt = "0.7.0"
20panic-probe = { version = "0.3", features = ["print-defmt"] }
21futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
diff --git a/examples/nrf52840-rtic/build.rs b/examples/nrf52840-rtic/build.rs
new file mode 100644
index 000000000..30691aa97
--- /dev/null
+++ b/examples/nrf52840-rtic/build.rs
@@ -0,0 +1,35 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
35}
diff --git a/examples/nrf52840-rtic/memory.x b/examples/nrf52840-rtic/memory.x
new file mode 100644
index 000000000..9b04edec0
--- /dev/null
+++ b/examples/nrf52840-rtic/memory.x
@@ -0,0 +1,7 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */
5 FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
6 RAM : ORIGIN = 0x20000000, LENGTH = 256K
7}
diff --git a/examples/nrf52840-rtic/src/bin/blinky.rs b/examples/nrf52840-rtic/src/bin/blinky.rs
new file mode 100644
index 000000000..a682c1932
--- /dev/null
+++ b/examples/nrf52840-rtic/src/bin/blinky.rs
@@ -0,0 +1,43 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use {defmt_rtt as _, panic_probe as _};
6
7#[rtic::app(device = embassy_nrf, peripherals = false, dispatchers = [SWI0_EGU0, SWI1_EGU1])]
8mod app {
9 use defmt::info;
10 use embassy_nrf::gpio::{Level, Output, OutputDrive};
11 use embassy_nrf::peripherals;
12 use embassy_time::{Duration, Timer};
13
14 #[shared]
15 struct Shared {}
16
17 #[local]
18 struct Local {}
19
20 #[init]
21 fn init(_: init::Context) -> (Shared, Local) {
22 info!("Hello World!");
23
24 let p = embassy_nrf::init(Default::default());
25 blink::spawn(p.P0_13).map_err(|_| ()).unwrap();
26
27 (Shared {}, Local {})
28 }
29
30 #[task(priority = 1)]
31 async fn blink(_cx: blink::Context, pin: peripherals::P0_13) {
32 let mut led = Output::new(pin, Level::Low, OutputDrive::Standard);
33
34 loop {
35 info!("off!");
36 led.set_high();
37 Timer::after(Duration::from_millis(300)).await;
38 info!("on!");
39 led.set_low();
40 Timer::after(Duration::from_millis(300)).await;
41 }
42 }
43}
diff --git a/examples/nrf52840/.cargo/config.toml b/examples/nrf52840/.cargo/config.toml
index 3872e7189..17616a054 100644
--- a/examples/nrf52840/.cargo/config.toml
+++ b/examples/nrf52840/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF82840_xxAA with your chip as listed in `probe-rs-cli chip list` 2# replace nRF82840_xxAA with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip nRF52840_xxAA" 3runner = "probe-rs run --chip nRF52840_xxAA"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabi" 6target = "thumbv7em-none-eabi"
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml
index 6627b7861..8c4175966 100644
--- a/examples/nrf52840/Cargo.toml
+++ b/examples/nrf52840/Cargo.toml
@@ -6,8 +6,24 @@ license = "MIT OR Apache-2.0"
6 6
7[features] 7[features]
8default = ["nightly"] 8default = ["nightly"]
9nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-time/nightly", "embassy-time/unstable-traits", "static_cell/nightly", 9nightly = [
10 "embassy-usb", "embedded-io/async", "embassy-net", "embassy-lora", "lora-phy", "lorawan-device", "lorawan"] 10 "embedded-hal-async",
11 "embassy-executor/nightly",
12 "embassy-nrf/nightly",
13 "embassy-net/nightly",
14 "embassy-net-esp-hosted",
15 "embassy-nrf/unstable-traits",
16 "embassy-time/nightly",
17 "embassy-time/unstable-traits",
18 "static_cell/nightly",
19 "embassy-usb",
20 "embedded-io/async",
21 "embassy-net",
22 "embassy-lora",
23 "lora-phy",
24 "lorawan-device",
25 "lorawan",
26]
11 27
12[dependencies] 28[dependencies]
13embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 29embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
@@ -22,6 +38,7 @@ embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["ti
22lora-phy = { version = "1", optional = true } 38lora-phy = { version = "1", optional = true }
23lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } 39lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true }
24lorawan = { version = "0.7.3", default-features = false, features = ["default-crypto"], optional = true } 40lorawan = { version = "0.7.3", default-features = false, features = ["default-crypto"], optional = true }
41embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true }
25 42
26defmt = "0.3" 43defmt = "0.3"
27defmt-rtt = "0.4" 44defmt-rtt = "0.4"
@@ -35,3 +52,4 @@ rand = { version = "0.8.4", default-features = false }
35embedded-storage = "0.3.0" 52embedded-storage = "0.3.0"
36usbd-hid = "0.6.0" 53usbd-hid = "0.6.0"
37serde = { version = "1.0.136", default-features = false } 54serde = { version = "1.0.136", default-features = false }
55embedded-hal-async = { version = "0.2.0-alpha.1", optional = true }
diff --git a/examples/nrf52840/src/bin/multiprio.rs b/examples/nrf52840/src/bin/multiprio.rs
index 851e189ea..aab819117 100644
--- a/examples/nrf52840/src/bin/multiprio.rs
+++ b/examples/nrf52840/src/bin/multiprio.rs
@@ -57,14 +57,11 @@
57#![no_main] 57#![no_main]
58#![feature(type_alias_impl_trait)] 58#![feature(type_alias_impl_trait)]
59 59
60use core::mem;
61
62use cortex_m::peripheral::NVIC;
63use cortex_m_rt::entry; 60use cortex_m_rt::entry;
64use defmt::{info, unwrap}; 61use defmt::{info, unwrap};
65use embassy_nrf::executor::{Executor, InterruptExecutor}; 62use embassy_executor::{Executor, InterruptExecutor};
66use embassy_nrf::interrupt; 63use embassy_nrf::interrupt;
67use embassy_nrf::pac::Interrupt; 64use embassy_nrf::interrupt::{InterruptExt, Priority};
68use embassy_time::{Duration, Instant, Timer}; 65use embassy_time::{Duration, Instant, Timer};
69use static_cell::StaticCell; 66use static_cell::StaticCell;
70use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
@@ -130,16 +127,15 @@ fn main() -> ! {
130 info!("Hello World!"); 127 info!("Hello World!");
131 128
132 let _p = embassy_nrf::init(Default::default()); 129 let _p = embassy_nrf::init(Default::default());
133 let mut nvic: NVIC = unsafe { mem::transmute(()) };
134 130
135 // High-priority executor: SWI1_EGU1, priority level 6 131 // High-priority executor: SWI1_EGU1, priority level 6
136 unsafe { nvic.set_priority(Interrupt::SWI1_EGU1, 6 << 5) }; 132 interrupt::SWI1_EGU1.set_priority(Priority::P6);
137 let spawner = EXECUTOR_HIGH.start(Interrupt::SWI1_EGU1); 133 let spawner = EXECUTOR_HIGH.start(interrupt::SWI1_EGU1);
138 unwrap!(spawner.spawn(run_high())); 134 unwrap!(spawner.spawn(run_high()));
139 135
140 // Medium-priority executor: SWI0_EGU0, priority level 7 136 // Medium-priority executor: SWI0_EGU0, priority level 7
141 unsafe { nvic.set_priority(Interrupt::SWI0_EGU0, 7 << 5) }; 137 interrupt::SWI0_EGU0.set_priority(Priority::P7);
142 let spawner = EXECUTOR_MED.start(Interrupt::SWI0_EGU0); 138 let spawner = EXECUTOR_MED.start(interrupt::SWI0_EGU0);
143 unwrap!(spawner.spawn(run_med())); 139 unwrap!(spawner.spawn(run_med()));
144 140
145 // Low priority executor: runs in thread mode, using WFE/SEV 141 // Low priority executor: runs in thread mode, using WFE/SEV
diff --git a/examples/nrf52840/src/bin/nvmc.rs b/examples/nrf52840/src/bin/nvmc.rs
index 33a44516d..31c6fe4b6 100644
--- a/examples/nrf52840/src/bin/nvmc.rs
+++ b/examples/nrf52840/src/bin/nvmc.rs
@@ -14,7 +14,7 @@ async fn main(_spawner: Spawner) {
14 let p = embassy_nrf::init(Default::default()); 14 let p = embassy_nrf::init(Default::default());
15 info!("Hello NVMC!"); 15 info!("Hello NVMC!");
16 16
17 // probe-rs-cli run breaks without this, I'm not sure why. 17 // probe-rs run breaks without this, I'm not sure why.
18 Timer::after(Duration::from_secs(1)).await; 18 Timer::after(Duration::from_secs(1)).await;
19 19
20 let mut f = Nvmc::new(p.NVMC); 20 let mut f = Nvmc::new(p.NVMC);
diff --git a/examples/nrf52840/src/bin/self_spawn.rs b/examples/nrf52840/src/bin/self_spawn.rs
index 196255a52..31ea6c81e 100644
--- a/examples/nrf52840/src/bin/self_spawn.rs
+++ b/examples/nrf52840/src/bin/self_spawn.rs
@@ -7,7 +7,11 @@ use embassy_executor::Spawner;
7use embassy_time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
9 9
10#[embassy_executor::task(pool_size = 2)] 10mod config {
11 pub const MY_TASK_POOL_SIZE: usize = 2;
12}
13
14#[embassy_executor::task(pool_size = config::MY_TASK_POOL_SIZE)]
11async fn my_task(spawner: Spawner, n: u32) { 15async fn my_task(spawner: Spawner, n: u32) {
12 Timer::after(Duration::from_secs(1)).await; 16 Timer::after(Duration::from_secs(1)).await;
13 info!("Spawning self! {}", n); 17 info!("Spawning self! {}", n);
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs
index 1065f5b5d..f527c0d7f 100644
--- a/examples/nrf52840/src/bin/usb_ethernet.rs
+++ b/examples/nrf52840/src/bin/usb_ethernet.rs
@@ -97,12 +97,12 @@ async fn main(spawner: Spawner) {
97 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); 97 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
98 unwrap!(spawner.spawn(usb_ncm_task(runner))); 98 unwrap!(spawner.spawn(usb_ncm_task(runner)));
99 99
100 let config = embassy_net::Config::Dhcp(Default::default()); 100 let config = embassy_net::Config::dhcpv4(Default::default());
101 //let config = embassy_net::Config::Static(embassy_net::StaticConfig { 101 // let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
102 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), 102 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
103 // dns_servers: Vec::new(), 103 // dns_servers: Vec::new(),
104 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), 104 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
105 //}); 105 // });
106 106
107 // Generate random seed 107 // Generate random seed
108 let mut rng = Rng::new(p.RNG, Irqs); 108 let mut rng = Rng::new(p.RNG, Irqs);
diff --git a/examples/nrf52840/src/bin/wdt.rs b/examples/nrf52840/src/bin/wdt.rs
index ccfd0e439..058746518 100644
--- a/examples/nrf52840/src/bin/wdt.rs
+++ b/examples/nrf52840/src/bin/wdt.rs
@@ -16,7 +16,7 @@ async fn main(_spawner: Spawner) {
16 let mut config = Config::default(); 16 let mut config = Config::default();
17 config.timeout_ticks = 32768 * 3; // 3 seconds 17 config.timeout_ticks = 32768 * 3; // 3 seconds
18 18
19 // This is needed for `probe-rs-cli run` to be able to catch the panic message 19 // This is needed for `probe-rs run` to be able to catch the panic message
20 // in the WDT interrupt. The core resets 2 ticks after firing the interrupt. 20 // in the WDT interrupt. The core resets 2 ticks after firing the interrupt.
21 config.run_during_debug_halt = false; 21 config.run_during_debug_halt = false;
22 22
diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs
new file mode 100644
index 000000000..4eb31b105
--- /dev/null
+++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs
@@ -0,0 +1,139 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::{info, unwrap, warn};
6use embassy_executor::Spawner;
7use embassy_net::tcp::TcpSocket;
8use embassy_net::{Stack, StackResources};
9use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pin, Pull};
10use embassy_nrf::rng::Rng;
11use embassy_nrf::spim::{self, Spim};
12use embassy_nrf::{bind_interrupts, peripherals};
13use embedded_hal_async::spi::ExclusiveDevice;
14use embedded_io::asynch::Write;
15use static_cell::make_static;
16use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _};
17
18bind_interrupts!(struct Irqs {
19 SPIM3 => spim::InterruptHandler<peripherals::SPI3>;
20 RNG => embassy_nrf::rng::InterruptHandler<peripherals::RNG>;
21});
22
23#[embassy_executor::task]
24async fn wifi_task(
25 runner: hosted::Runner<
26 'static,
27 ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static, peripherals::P0_31>>,
28 Input<'static, AnyPin>,
29 Output<'static, peripherals::P1_05>,
30 >,
31) -> ! {
32 runner.run().await
33}
34
35#[embassy_executor::task]
36async fn net_task(stack: &'static Stack<hosted::NetDriver<'static>>) -> ! {
37 stack.run().await
38}
39
40#[embassy_executor::main]
41async fn main(spawner: Spawner) {
42 info!("Hello World!");
43
44 let p = embassy_nrf::init(Default::default());
45
46 let miso = p.P0_28;
47 let sck = p.P0_29;
48 let mosi = p.P0_30;
49 let cs = Output::new(p.P0_31, Level::High, OutputDrive::HighDrive);
50 let handshake = Input::new(p.P1_01.degrade(), Pull::Up);
51 let ready = Input::new(p.P1_04.degrade(), Pull::None);
52 let reset = Output::new(p.P1_05, Level::Low, OutputDrive::Standard);
53
54 let mut config = spim::Config::default();
55 config.frequency = spim::Frequency::M32;
56 config.mode = spim::MODE_2; // !!!
57 let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config);
58 let spi = ExclusiveDevice::new(spi, cs);
59
60 let (device, mut control, runner) = embassy_net_esp_hosted::new(
61 make_static!(embassy_net_esp_hosted::State::new()),
62 spi,
63 handshake,
64 ready,
65 reset,
66 )
67 .await;
68
69 unwrap!(spawner.spawn(wifi_task(runner)));
70
71 control.init().await;
72 control.join(env!("WIFI_NETWORK"), env!("WIFI_PASSWORD")).await;
73
74 let config = embassy_net::Config::dhcpv4(Default::default());
75 // let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
76 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
77 // dns_servers: Vec::new(),
78 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
79 // });
80
81 // Generate random seed
82 let mut rng = Rng::new(p.RNG, Irqs);
83 let mut seed = [0; 8];
84 rng.blocking_fill_bytes(&mut seed);
85 let seed = u64::from_le_bytes(seed);
86
87 // Init network stack
88 let stack = &*make_static!(Stack::new(
89 device,
90 config,
91 make_static!(StackResources::<2>::new()),
92 seed
93 ));
94
95 unwrap!(spawner.spawn(net_task(stack)));
96
97 // And now we can use it!
98
99 let mut rx_buffer = [0; 4096];
100 let mut tx_buffer = [0; 4096];
101 let mut buf = [0; 4096];
102
103 loop {
104 let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
105 socket.set_timeout(Some(embassy_time::Duration::from_secs(10)));
106
107 info!("Listening on TCP:1234...");
108 if let Err(e) = socket.accept(1234).await {
109 warn!("accept error: {:?}", e);
110 continue;
111 }
112
113 info!("Received connection from {:?}", socket.remote_endpoint());
114
115 loop {
116 let n = match socket.read(&mut buf).await {
117 Ok(0) => {
118 warn!("read EOF");
119 break;
120 }
121 Ok(n) => n,
122 Err(e) => {
123 warn!("read error: {:?}", e);
124 break;
125 }
126 };
127
128 info!("rxd {:02x}", &buf[..n]);
129
130 match socket.write_all(&buf[..n]).await {
131 Ok(()) => {}
132 Err(e) => {
133 warn!("write error: {:?}", e);
134 break;
135 }
136 };
137 }
138 }
139}
diff --git a/examples/nrf5340/.cargo/config.toml b/examples/nrf5340/.cargo/config.toml
index d25355894..4c3cf3d32 100644
--- a/examples/nrf5340/.cargo/config.toml
+++ b/examples/nrf5340/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF5340_xxAA with your chip as listed in `probe-rs-cli chip list` 2# replace nRF5340_xxAA with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip nRF5340_xxAA" 3runner = "probe-rs run --chip nRF5340_xxAA"
4 4
5[build] 5[build]
6target = "thumbv8m.main-none-eabihf" 6target = "thumbv8m.main-none-eabihf"
diff --git a/examples/rp/.cargo/config.toml b/examples/rp/.cargo/config.toml
index 2ee6fcb00..3d7d61740 100644
--- a/examples/rp/.cargo/config.toml
+++ b/examples/rp/.cargo/config.toml
@@ -1,5 +1,5 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2runner = "probe-rs-cli run --chip RP2040" 2runner = "probe-rs run --chip RP2040"
3 3
4[build] 4[build]
5target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ 5target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml
index e946b481d..48f3a26bb 100644
--- a/examples/rp/Cargo.toml
+++ b/examples/rp/Cargo.toml
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
8[dependencies] 8[dependencies]
9embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal", features = ["defmt"] } 9embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal", features = ["defmt"] }
10embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime"] } 12embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime"] }
13embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "critical-section-impl"] } 13embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "critical-section-impl"] }
14embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 14embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs
index c5422c616..0d246c093 100644
--- a/examples/rp/src/bin/button.rs
+++ b/examples/rp/src/bin/button.rs
@@ -9,9 +9,12 @@ use {defmt_rtt as _, panic_probe as _};
9#[embassy_executor::main] 9#[embassy_executor::main]
10async fn main(_spawner: Spawner) { 10async fn main(_spawner: Spawner) {
11 let p = embassy_rp::init(Default::default()); 11 let p = embassy_rp::init(Default::default());
12 let button = Input::new(p.PIN_28, Pull::Up);
13 let mut led = Output::new(p.PIN_25, Level::Low); 12 let mut led = Output::new(p.PIN_25, Level::Low);
14 13
14 // Use PIN_28, Pin34 on J0 for RP Pico, as a input.
15 // You need to add your own button.
16 let button = Input::new(p.PIN_28, Pull::Up);
17
15 loop { 18 loop {
16 if button.is_high() { 19 if button.is_high() {
17 led.set_high(); 20 led.set_high();
diff --git a/examples/rp/src/bin/ethernet_w5500_multisocket.rs b/examples/rp/src/bin/ethernet_w5500_multisocket.rs
index 63e142e7d..82568254a 100644
--- a/examples/rp/src/bin/ethernet_w5500_multisocket.rs
+++ b/examples/rp/src/bin/ethernet_w5500_multisocket.rs
@@ -64,7 +64,7 @@ async fn main(spawner: Spawner) {
64 // Init network stack 64 // Init network stack
65 let stack = &*make_static!(Stack::new( 65 let stack = &*make_static!(Stack::new(
66 device, 66 device,
67 embassy_net::Config::Dhcp(Default::default()), 67 embassy_net::Config::dhcpv4(Default::default()),
68 make_static!(StackResources::<3>::new()), 68 make_static!(StackResources::<3>::new()),
69 seed 69 seed
70 )); 70 ));
@@ -120,9 +120,9 @@ async fn listen_task(stack: &'static Stack<Device<'static>>, id: u8, port: u16)
120 } 120 }
121} 121}
122 122
123async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { 123async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 {
124 loop { 124 loop {
125 if let Some(config) = stack.config() { 125 if let Some(config) = stack.config_v4() {
126 return config.clone(); 126 return config.clone();
127 } 127 }
128 yield_now().await; 128 yield_now().await;
diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs
index a532de00d..d562defad 100644
--- a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs
+++ b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs
@@ -67,7 +67,7 @@ async fn main(spawner: Spawner) {
67 // Init network stack 67 // Init network stack
68 let stack = &*make_static!(Stack::new( 68 let stack = &*make_static!(Stack::new(
69 device, 69 device,
70 embassy_net::Config::Dhcp(Default::default()), 70 embassy_net::Config::dhcpv4(Default::default()),
71 make_static!(StackResources::<2>::new()), 71 make_static!(StackResources::<2>::new()),
72 seed 72 seed
73 )); 73 ));
@@ -108,9 +108,9 @@ async fn main(spawner: Spawner) {
108 } 108 }
109} 109}
110 110
111async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { 111async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 {
112 loop { 112 loop {
113 if let Some(config) = stack.config() { 113 if let Some(config) = stack.config_v4() {
114 return config.clone(); 114 return config.clone();
115 } 115 }
116 yield_now().await; 116 yield_now().await;
diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs
index 599f6b1e9..7f521cdb4 100644
--- a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs
+++ b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs
@@ -65,7 +65,7 @@ async fn main(spawner: Spawner) {
65 // Init network stack 65 // Init network stack
66 let stack = &*make_static!(Stack::new( 66 let stack = &*make_static!(Stack::new(
67 device, 67 device,
68 embassy_net::Config::Dhcp(Default::default()), 68 embassy_net::Config::dhcpv4(Default::default()),
69 make_static!(StackResources::<2>::new()), 69 make_static!(StackResources::<2>::new()),
70 seed 70 seed
71 )); 71 ));
@@ -116,9 +116,9 @@ async fn main(spawner: Spawner) {
116 } 116 }
117} 117}
118 118
119async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { 119async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 {
120 loop { 120 loop {
121 if let Some(config) = stack.config() { 121 if let Some(config) = stack.config_v4() {
122 return config.clone(); 122 return config.clone();
123 } 123 }
124 yield_now().await; 124 yield_now().await;
diff --git a/examples/rp/src/bin/ethernet_w5500_udp.rs b/examples/rp/src/bin/ethernet_w5500_udp.rs
index ac5a65bb6..ada86ae55 100644
--- a/examples/rp/src/bin/ethernet_w5500_udp.rs
+++ b/examples/rp/src/bin/ethernet_w5500_udp.rs
@@ -62,7 +62,7 @@ async fn main(spawner: Spawner) {
62 // Init network stack 62 // Init network stack
63 let stack = &*make_static!(Stack::new( 63 let stack = &*make_static!(Stack::new(
64 device, 64 device,
65 embassy_net::Config::Dhcp(Default::default()), 65 embassy_net::Config::dhcpv4(Default::default()),
66 make_static!(StackResources::<2>::new()), 66 make_static!(StackResources::<2>::new()),
67 seed 67 seed
68 )); 68 ));
@@ -95,9 +95,9 @@ async fn main(spawner: Spawner) {
95 } 95 }
96} 96}
97 97
98async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { 98async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 {
99 loop { 99 loop {
100 if let Some(config) = stack.config() { 100 if let Some(config) = stack.config_v4() {
101 return config.clone(); 101 return config.clone();
102 } 102 }
103 yield_now().await; 103 yield_now().await;
diff --git a/examples/rp/src/bin/multiprio.rs b/examples/rp/src/bin/multiprio.rs
index 2f79ba49e..9ace4cd68 100644
--- a/examples/rp/src/bin/multiprio.rs
+++ b/examples/rp/src/bin/multiprio.rs
@@ -57,14 +57,11 @@
57#![no_main] 57#![no_main]
58#![feature(type_alias_impl_trait)] 58#![feature(type_alias_impl_trait)]
59 59
60use core::mem;
61
62use cortex_m::peripheral::NVIC;
63use cortex_m_rt::entry; 60use cortex_m_rt::entry;
64use defmt::{info, unwrap}; 61use defmt::{info, unwrap};
65use embassy_rp::executor::{Executor, InterruptExecutor}; 62use embassy_executor::{Executor, InterruptExecutor};
66use embassy_rp::interrupt; 63use embassy_rp::interrupt;
67use embassy_rp::pac::Interrupt; 64use embassy_rp::interrupt::{InterruptExt, Priority};
68use embassy_time::{Duration, Instant, Timer, TICK_HZ}; 65use embassy_time::{Duration, Instant, Timer, TICK_HZ};
69use static_cell::StaticCell; 66use static_cell::StaticCell;
70use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
@@ -130,18 +127,15 @@ fn main() -> ! {
130 info!("Hello World!"); 127 info!("Hello World!");
131 128
132 let _p = embassy_rp::init(Default::default()); 129 let _p = embassy_rp::init(Default::default());
133 let mut nvic: NVIC = unsafe { mem::transmute(()) };
134 130
135 // High-priority executor: SWI_IRQ_1, priority level 2 131 // High-priority executor: SWI_IRQ_1, priority level 2
136 unsafe { nvic.set_priority(Interrupt::SWI_IRQ_1, 2 << 6) }; 132 interrupt::SWI_IRQ_1.set_priority(Priority::P2);
137 info!("bla: {}", NVIC::get_priority(Interrupt::SWI_IRQ_1)); 133 let spawner = EXECUTOR_HIGH.start(interrupt::SWI_IRQ_1);
138 let spawner = EXECUTOR_HIGH.start(Interrupt::SWI_IRQ_1);
139 unwrap!(spawner.spawn(run_high())); 134 unwrap!(spawner.spawn(run_high()));
140 135
141 // Medium-priority executor: SWI_IRQ_0, priority level 3 136 // Medium-priority executor: SWI_IRQ_0, priority level 3
142 unsafe { nvic.set_priority(Interrupt::SWI_IRQ_0, 3 << 6) }; 137 interrupt::SWI_IRQ_0.set_priority(Priority::P3);
143 info!("bla: {}", NVIC::get_priority(Interrupt::SWI_IRQ_0)); 138 let spawner = EXECUTOR_MED.start(interrupt::SWI_IRQ_0);
144 let spawner = EXECUTOR_MED.start(Interrupt::SWI_IRQ_0);
145 unwrap!(spawner.spawn(run_med())); 139 unwrap!(spawner.spawn(run_med()));
146 140
147 // Low priority executor: runs in thread mode, using WFE/SEV 141 // Low priority executor: runs in thread mode, using WFE/SEV
diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs
index 16fbf5e91..91d1ec8e7 100644
--- a/examples/rp/src/bin/usb_ethernet.rs
+++ b/examples/rp/src/bin/usb_ethernet.rs
@@ -86,8 +86,8 @@ async fn main(spawner: Spawner) {
86 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); 86 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
87 unwrap!(spawner.spawn(usb_ncm_task(runner))); 87 unwrap!(spawner.spawn(usb_ncm_task(runner)));
88 88
89 let config = embassy_net::Config::Dhcp(Default::default()); 89 let config = embassy_net::Config::dhcpv4(Default::default());
90 //let config = embassy_net::Config::Static(embassy_net::StaticConfig { 90 //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
91 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), 91 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
92 // dns_servers: Vec::new(), 92 // dns_servers: Vec::new(),
93 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), 93 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs
index b27d3c9f8..310e84d92 100644
--- a/examples/rp/src/bin/wifi_ap_tcp_server.rs
+++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs
@@ -42,8 +42,8 @@ async fn main(spawner: Spawner) {
42 42
43 // To make flashing faster for development, you may want to flash the firmwares independently 43 // To make flashing faster for development, you may want to flash the firmwares independently
44 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: 44 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
45 // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 45 // probe-rs download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
46 // probe-rs-cli download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000 46 // probe-rs download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000
47 //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; 47 //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
48 //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; 48 //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
49 49
@@ -62,7 +62,7 @@ async fn main(spawner: Spawner) {
62 .await; 62 .await;
63 63
64 // Use a link-local address for communication without DHCP server 64 // Use a link-local address for communication without DHCP server
65 let config = Config::Static(embassy_net::StaticConfig { 65 let config = Config::ipv4_static(embassy_net::StaticConfigV4 {
66 address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(169, 254, 1, 1), 16), 66 address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(169, 254, 1, 1), 16),
67 dns_servers: heapless::Vec::new(), 67 dns_servers: heapless::Vec::new(),
68 gateway: None, 68 gateway: None,
diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs
new file mode 100644
index 000000000..bbcb1b5ec
--- /dev/null
+++ b/examples/rp/src/bin/wifi_blinky.rs
@@ -0,0 +1,59 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use cyw43_pio::PioSpi;
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_rp::gpio::{Level, Output};
9use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
10use embassy_rp::pio::Pio;
11use embassy_time::{Duration, Timer};
12use static_cell::make_static;
13use {defmt_rtt as _, panic_probe as _};
14
15#[embassy_executor::task]
16async fn wifi_task(
17 runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
18) -> ! {
19 runner.run().await
20}
21
22#[embassy_executor::main]
23async fn main(spawner: Spawner) {
24 let p = embassy_rp::init(Default::default());
25 let fw = include_bytes!("../../../../cyw43-firmware/43439A0.bin");
26 let clm = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin");
27
28 // To make flashing faster for development, you may want to flash the firmwares independently
29 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
30 // probe-rs download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
31 // probe-rs download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000
32 //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
33 //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
34
35 let pwr = Output::new(p.PIN_23, Level::Low);
36 let cs = Output::new(p.PIN_25, Level::High);
37 let mut pio = Pio::new(p.PIO0);
38 let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
39
40 let state = make_static!(cyw43::State::new());
41 let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
42 unwrap!(spawner.spawn(wifi_task(runner)));
43
44 control.init(clm).await;
45 control
46 .set_power_management(cyw43::PowerManagementMode::PowerSave)
47 .await;
48
49 let delay = Duration::from_secs(1);
50 loop {
51 info!("led on!");
52 control.gpio_set(0, true).await;
53 Timer::after(delay).await;
54
55 info!("led off!");
56 control.gpio_set(0, false).await;
57 Timer::after(delay).await;
58 }
59}
diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs
index 79534f229..391e12282 100644
--- a/examples/rp/src/bin/wifi_scan.rs
+++ b/examples/rp/src/bin/wifi_scan.rs
@@ -39,8 +39,8 @@ async fn main(spawner: Spawner) {
39 39
40 // To make flashing faster for development, you may want to flash the firmwares independently 40 // To make flashing faster for development, you may want to flash the firmwares independently
41 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: 41 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
42 // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 42 // probe-rs download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
43 // probe-rs-cli download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000 43 // probe-rs download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000
44 //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; 44 //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
45 //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; 45 //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
46 46
diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs
index 1a00bca96..e9d1079a6 100644
--- a/examples/rp/src/bin/wifi_tcp_server.rs
+++ b/examples/rp/src/bin/wifi_tcp_server.rs
@@ -42,8 +42,8 @@ async fn main(spawner: Spawner) {
42 42
43 // To make flashing faster for development, you may want to flash the firmwares independently 43 // To make flashing faster for development, you may want to flash the firmwares independently
44 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: 44 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
45 // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 45 // probe-rs download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
46 // probe-rs-cli download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000 46 // probe-rs download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000
47 //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; 47 //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
48 //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; 48 //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
49 49
@@ -61,8 +61,8 @@ async fn main(spawner: Spawner) {
61 .set_power_management(cyw43::PowerManagementMode::PowerSave) 61 .set_power_management(cyw43::PowerManagementMode::PowerSave)
62 .await; 62 .await;
63 63
64 let config = Config::Dhcp(Default::default()); 64 let config = Config::dhcpv4(Default::default());
65 //let config = embassy_net::Config::Static(embassy_net::Config { 65 //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
66 // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), 66 // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
67 // dns_servers: Vec::new(), 67 // dns_servers: Vec::new(),
68 // gateway: Some(Ipv4Address::new(192, 168, 69, 1)), 68 // gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
diff --git a/examples/std/README.md b/examples/std/README.md
new file mode 100644
index 000000000..adc795928
--- /dev/null
+++ b/examples/std/README.md
@@ -0,0 +1,23 @@
1
2## Running the `embassy-net` examples
3
4First, create the tap0 interface. You only need to do this once.
5
6```sh
7sudo ip tuntap add name tap0 mode tap user $USER
8sudo ip link set tap0 up
9sudo ip addr add 192.168.69.100/24 dev tap0
10sudo ip -6 addr add fe80::100/64 dev tap0
11sudo ip -6 addr add fdaa::100/64 dev tap0
12sudo ip -6 route add fe80::/64 dev tap0
13sudo ip -6 route add fdaa::/64 dev tap0
14```
15
16Second, have something listening there. For example `nc -l 8000`
17
18Then run the example located in the `examples` folder:
19
20```sh
21cd $EMBASSY_ROOT/examples/std/
22cargo run --bin net -- --static-ip
23``` \ No newline at end of file
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs
index b42bfc13b..3aadb029d 100644
--- a/examples/std/src/bin/net.rs
+++ b/examples/std/src/bin/net.rs
@@ -42,13 +42,13 @@ async fn main_task(spawner: Spawner) {
42 42
43 // Choose between dhcp or static ip 43 // Choose between dhcp or static ip
44 let config = if opts.static_ip { 44 let config = if opts.static_ip {
45 Config::Static(embassy_net::StaticConfig { 45 Config::ipv4_static(embassy_net::StaticConfigV4 {
46 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), 46 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
47 dns_servers: Vec::new(), 47 dns_servers: Vec::new(),
48 gateway: Some(Ipv4Address::new(192, 168, 69, 1)), 48 gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
49 }) 49 })
50 } else { 50 } else {
51 Config::Dhcp(Default::default()) 51 Config::dhcpv4(Default::default())
52 }; 52 };
53 53
54 // Generate random seed 54 // Generate random seed
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs
index 932ac5831..65b5a2cd9 100644
--- a/examples/std/src/bin/net_dns.rs
+++ b/examples/std/src/bin/net_dns.rs
@@ -40,14 +40,14 @@ async fn main_task(spawner: Spawner) {
40 40
41 // Choose between dhcp or static ip 41 // Choose between dhcp or static ip
42 let config = if opts.static_ip { 42 let config = if opts.static_ip {
43 Config::Static(embassy_net::StaticConfig { 43 Config::ipv4_static(embassy_net::StaticConfigV4 {
44 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24), 44 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24),
45 dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()]) 45 dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()])
46 .unwrap(), 46 .unwrap(),
47 gateway: Some(Ipv4Address::new(192, 168, 69, 100)), 47 gateway: Some(Ipv4Address::new(192, 168, 69, 100)),
48 }) 48 })
49 } else { 49 } else {
50 Config::Dhcp(Default::default()) 50 Config::dhcpv4(Default::default())
51 }; 51 };
52 52
53 // Generate random seed 53 // Generate random seed
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs
index d89ec7643..3fc46156c 100644
--- a/examples/std/src/bin/net_udp.rs
+++ b/examples/std/src/bin/net_udp.rs
@@ -38,13 +38,13 @@ async fn main_task(spawner: Spawner) {
38 38
39 // Choose between dhcp or static ip 39 // Choose between dhcp or static ip
40 let config = if opts.static_ip { 40 let config = if opts.static_ip {
41 Config::Static(embassy_net::StaticConfig { 41 Config::ipv4_static(embassy_net::StaticConfigV4 {
42 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), 42 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
43 dns_servers: Vec::new(), 43 dns_servers: Vec::new(),
44 gateway: Some(Ipv4Address::new(192, 168, 69, 1)), 44 gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
45 }) 45 })
46 } else { 46 } else {
47 Config::Dhcp(Default::default()) 47 Config::dhcpv4(Default::default())
48 }; 48 };
49 49
50 // Generate random seed 50 // Generate random seed
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs
index 01695baea..df09986ac 100644
--- a/examples/std/src/bin/tcp_accept.rs
+++ b/examples/std/src/bin/tcp_accept.rs
@@ -53,13 +53,13 @@ async fn main_task(spawner: Spawner) {
53 53
54 // Choose between dhcp or static ip 54 // Choose between dhcp or static ip
55 let config = if opts.static_ip { 55 let config = if opts.static_ip {
56 Config::Static(embassy_net::StaticConfig { 56 Config::ipv4_static(embassy_net::StaticConfigV4 {
57 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), 57 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
58 dns_servers: Vec::new(), 58 dns_servers: Vec::new(),
59 gateway: Some(Ipv4Address::new(192, 168, 69, 1)), 59 gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
60 }) 60 })
61 } else { 61 } else {
62 Config::Dhcp(Default::default()) 62 Config::dhcpv4(Default::default())
63 }; 63 };
64 64
65 // Generate random seed 65 // Generate random seed
diff --git a/examples/stm32c0/.cargo/config.toml b/examples/stm32c0/.cargo/config.toml
index 517101fae..29a8be7e1 100644
--- a/examples/stm32c0/.cargo/config.toml
+++ b/examples/stm32c0/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32G071C8Rx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32G071C8Rx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --speed 100 --chip STM32c031c6tx" 3runner = "probe-rs run --speed 100 --chip STM32c031c6tx"
4 4
5[build] 5[build]
6target = "thumbv6m-none-eabi" 6target = "thumbv6m-none-eabi"
diff --git a/examples/stm32c0/Cargo.toml b/examples/stm32c0/Cargo.toml
index ad11fbd1c..43f432520 100644
--- a/examples/stm32c0/Cargo.toml
+++ b/examples/stm32c0/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] }
12 12
diff --git a/examples/stm32f0/.cargo/config.toml b/examples/stm32f0/.cargo/config.toml
index bd0c0cd97..def4c8c92 100644
--- a/examples/stm32f0/.cargo/config.toml
+++ b/examples/stm32f0/.cargo/config.toml
@@ -1,5 +1,5 @@
1[target.thumbv6m-none-eabi] 1[target.thumbv6m-none-eabi]
2runner = 'probe-rs-cli run --chip STM32F091RCTX' 2runner = 'probe-rs run --chip STM32F091RCTX'
3 3
4[build] 4[build]
5target = "thumbv6m-none-eabi" 5target = "thumbv6m-none-eabi"
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml
index ff134bb0e..8d2248ed0 100644
--- a/examples/stm32f0/Cargo.toml
+++ b/examples/stm32f0/Cargo.toml
@@ -13,7 +13,7 @@ defmt = "0.3"
13defmt-rtt = "0.4" 13defmt-rtt = "0.4"
14panic-probe = "0.3" 14panic-probe = "0.3"
15embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 15embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
16embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 16embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
17embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 17embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
18embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] } 18embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] }
19static_cell = { version = "1.1", features = ["nightly"]} 19static_cell = { version = "1.1", features = ["nightly"]}
diff --git a/examples/stm32f0/src/bin/multiprio.rs b/examples/stm32f0/src/bin/multiprio.rs
index 430a805fc..988ffeef1 100644
--- a/examples/stm32f0/src/bin/multiprio.rs
+++ b/examples/stm32f0/src/bin/multiprio.rs
@@ -57,14 +57,11 @@
57#![no_main] 57#![no_main]
58#![feature(type_alias_impl_trait)] 58#![feature(type_alias_impl_trait)]
59 59
60use core::mem;
61
62use cortex_m::peripheral::NVIC;
63use cortex_m_rt::entry; 60use cortex_m_rt::entry;
64use defmt::*; 61use defmt::*;
65use embassy_executor::{Executor, InterruptExecutor}; 62use embassy_executor::{Executor, InterruptExecutor};
66use embassy_stm32::interrupt; 63use embassy_stm32::interrupt;
67use embassy_stm32::pac::Interrupt; 64use embassy_stm32::interrupt::{InterruptExt, Priority};
68use embassy_time::{Duration, Instant, Timer}; 65use embassy_time::{Duration, Instant, Timer};
69use static_cell::StaticCell; 66use static_cell::StaticCell;
70use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
@@ -129,16 +126,15 @@ unsafe fn USART2() {
129fn main() -> ! { 126fn main() -> ! {
130 // Initialize and create handle for devicer peripherals 127 // Initialize and create handle for devicer peripherals
131 let _p = embassy_stm32::init(Default::default()); 128 let _p = embassy_stm32::init(Default::default());
132 let mut nvic: NVIC = unsafe { mem::transmute(()) };
133 129
134 // High-priority executor: USART1, priority level 6 130 // High-priority executor: USART1, priority level 6
135 unsafe { nvic.set_priority(Interrupt::USART1, 6 << 4) }; 131 interrupt::USART1.set_priority(Priority::P6);
136 let spawner = EXECUTOR_HIGH.start(Interrupt::USART1); 132 let spawner = EXECUTOR_HIGH.start(interrupt::USART1);
137 unwrap!(spawner.spawn(run_high())); 133 unwrap!(spawner.spawn(run_high()));
138 134
139 // Medium-priority executor: USART2, priority level 7 135 // Medium-priority executor: USART2, priority level 7
140 unsafe { nvic.set_priority(Interrupt::USART2, 7 << 4) }; 136 interrupt::USART2.set_priority(Priority::P7);
141 let spawner = EXECUTOR_MED.start(Interrupt::USART2); 137 let spawner = EXECUTOR_MED.start(interrupt::USART2);
142 unwrap!(spawner.spawn(run_med())); 138 unwrap!(spawner.spawn(run_med()));
143 139
144 // Low priority executor: runs in thread mode, using WFE/SEV 140 // Low priority executor: runs in thread mode, using WFE/SEV
diff --git a/examples/stm32f0/src/bin/wdg.rs b/examples/stm32f0/src/bin/wdg.rs
index 80e76f901..a44b17528 100644
--- a/examples/stm32f0/src/bin/wdg.rs
+++ b/examples/stm32f0/src/bin/wdg.rs
@@ -16,10 +16,10 @@ async fn main(_spawner: Spawner) {
16 let mut wdg = IndependentWatchdog::new(p.IWDG, 20_000_00); 16 let mut wdg = IndependentWatchdog::new(p.IWDG, 20_000_00);
17 17
18 info!("Watchdog start"); 18 info!("Watchdog start");
19 unsafe { wdg.unleash() }; 19 wdg.unleash();
20 20
21 loop { 21 loop {
22 Timer::after(Duration::from_secs(1)).await; 22 Timer::after(Duration::from_secs(1)).await;
23 unsafe { wdg.pet() }; 23 wdg.pet();
24 } 24 }
25} 25}
diff --git a/examples/stm32f1/.cargo/config.toml b/examples/stm32f1/.cargo/config.toml
index 81199c5aa..ce6fef11b 100644
--- a/examples/stm32f1/.cargo/config.toml
+++ b/examples/stm32f1/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F103C8 with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F103C8 with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32F103C8" 3runner = "probe-rs run --chip STM32F103C8"
4 4
5[build] 5[build]
6target = "thumbv7m-none-eabi" 6target = "thumbv7m-none-eabi"
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml
index 345e948a6..d34fd439a 100644
--- a/examples/stm32f1/Cargo.toml
+++ b/examples/stm32f1/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
diff --git a/examples/stm32f2/.cargo/config.toml b/examples/stm32f2/.cargo/config.toml
index 5532779c8..1198fcab8 100644
--- a/examples/stm32f2/.cargo/config.toml
+++ b/examples/stm32f2/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F207ZGTx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F207ZGTx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32F207ZGTx" 3runner = "probe-rs run --chip STM32F207ZGTx"
4 4
5[build] 5[build]
6target = "thumbv7m-none-eabi" 6target = "thumbv7m-none-eabi"
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml
index e4f97a589..5e3e0d0f7 100644
--- a/examples/stm32f2/Cargo.toml
+++ b/examples/stm32f2/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
12 12
diff --git a/examples/stm32f3/.cargo/config.toml b/examples/stm32f3/.cargo/config.toml
index 7f3fda529..cb8a7c5af 100644
--- a/examples/stm32f3/.cargo/config.toml
+++ b/examples/stm32f3/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F429ZITx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32F303ZETx" 3runner = "probe-rs run --chip STM32F303ZETx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabihf"
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml
index 0fe9cb122..29ab2009c 100644
--- a/examples/stm32f3/Cargo.toml
+++ b/examples/stm32f3/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs
index 5d010f799..80bf59deb 100644
--- a/examples/stm32f3/src/bin/multiprio.rs
+++ b/examples/stm32f3/src/bin/multiprio.rs
@@ -57,14 +57,11 @@
57#![no_main] 57#![no_main]
58#![feature(type_alias_impl_trait)] 58#![feature(type_alias_impl_trait)]
59 59
60use core::mem;
61
62use cortex_m::peripheral::NVIC;
63use cortex_m_rt::entry; 60use cortex_m_rt::entry;
64use defmt::*; 61use defmt::*;
65use embassy_executor::{Executor, InterruptExecutor}; 62use embassy_executor::{Executor, InterruptExecutor};
66use embassy_stm32::interrupt; 63use embassy_stm32::interrupt;
67use embassy_stm32::pac::Interrupt; 64use embassy_stm32::interrupt::{InterruptExt, Priority};
68use embassy_time::{Duration, Instant, Timer}; 65use embassy_time::{Duration, Instant, Timer};
69use static_cell::StaticCell; 66use static_cell::StaticCell;
70use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
@@ -130,16 +127,15 @@ fn main() -> ! {
130 info!("Hello World!"); 127 info!("Hello World!");
131 128
132 let _p = embassy_stm32::init(Default::default()); 129 let _p = embassy_stm32::init(Default::default());
133 let mut nvic: NVIC = unsafe { mem::transmute(()) };
134 130
135 // High-priority executor: UART4, priority level 6 131 // High-priority executor: UART4, priority level 6
136 unsafe { nvic.set_priority(Interrupt::UART4, 6 << 4) }; 132 interrupt::UART4.set_priority(Priority::P6);
137 let spawner = EXECUTOR_HIGH.start(Interrupt::UART4); 133 let spawner = EXECUTOR_HIGH.start(interrupt::UART4);
138 unwrap!(spawner.spawn(run_high())); 134 unwrap!(spawner.spawn(run_high()));
139 135
140 // Medium-priority executor: UART5, priority level 7 136 // Medium-priority executor: UART5, priority level 7
141 unsafe { nvic.set_priority(Interrupt::UART5, 7 << 4) }; 137 interrupt::UART5.set_priority(Priority::P7);
142 let spawner = EXECUTOR_MED.start(Interrupt::UART5); 138 let spawner = EXECUTOR_MED.start(interrupt::UART5);
143 unwrap!(spawner.spawn(run_med())); 139 unwrap!(spawner.spawn(run_med()));
144 140
145 // Low priority executor: runs in thread mode, using WFE/SEV 141 // Low priority executor: runs in thread mode, using WFE/SEV
diff --git a/examples/stm32f4/.cargo/config.toml b/examples/stm32f4/.cargo/config.toml
index bed04b68f..16efa8e6f 100644
--- a/examples/stm32f4/.cargo/config.toml
+++ b/examples/stm32f4/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F429ZITx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32F429ZITx" 3runner = "probe-rs run --chip STM32F429ZITx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabi" 6target = "thumbv7em-none-eabi"
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index 3a8efdd06..7ecb64fce 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs
index e8377b9a1..da8955053 100644
--- a/examples/stm32f4/src/bin/can.rs
+++ b/examples/stm32f4/src/bin/can.rs
@@ -4,12 +4,21 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use embassy_stm32::bind_interrupts;
7use embassy_stm32::can::bxcan::filter::Mask32; 8use embassy_stm32::can::bxcan::filter::Mask32;
8use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId}; 9use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId};
9use embassy_stm32::can::Can; 10use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler};
10use embassy_stm32::gpio::{Input, Pull}; 11use embassy_stm32::gpio::{Input, Pull};
12use embassy_stm32::peripherals::CAN1;
11use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
12 14
15bind_interrupts!(struct Irqs {
16 CAN1_RX0 => Rx0InterruptHandler<CAN1>;
17 CAN1_RX1 => Rx1InterruptHandler<CAN1>;
18 CAN1_SCE => SceInterruptHandler<CAN1>;
19 CAN1_TX => TxInterruptHandler<CAN1>;
20});
21
13#[entry] 22#[entry]
14fn main() -> ! { 23fn main() -> ! {
15 info!("Hello World!"); 24 info!("Hello World!");
@@ -23,7 +32,7 @@ fn main() -> ! {
23 let rx_pin = Input::new(&mut p.PA11, Pull::Up); 32 let rx_pin = Input::new(&mut p.PA11, Pull::Up);
24 core::mem::forget(rx_pin); 33 core::mem::forget(rx_pin);
25 34
26 let mut can = Can::new(p.CAN1, p.PA11, p.PA12); 35 let mut can = Can::new(p.CAN1, p.PA11, p.PA12, Irqs);
27 36
28 can.modify_filters().enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); 37 can.modify_filters().enable_bank(0, Fifo::Fifo0, Mask32::accept_all());
29 38
diff --git a/examples/stm32f4/src/bin/dac.rs b/examples/stm32f4/src/bin/dac.rs
index d97ae7082..3a6216712 100644
--- a/examples/stm32f4/src/bin/dac.rs
+++ b/examples/stm32f4/src/bin/dac.rs
@@ -4,7 +4,8 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dac::{Channel, Dac, Value}; 7use embassy_stm32::dac::{DacCh1, DacChannel, Value};
8use embassy_stm32::dma::NoDma;
8use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
9 10
10#[embassy_executor::main] 11#[embassy_executor::main]
@@ -12,12 +13,12 @@ async fn main(_spawner: Spawner) -> ! {
12 let p = embassy_stm32::init(Default::default()); 13 let p = embassy_stm32::init(Default::default());
13 info!("Hello World, dude!"); 14 info!("Hello World, dude!");
14 15
15 let mut dac = Dac::new_1ch(p.DAC, p.PA4); 16 let mut dac = DacCh1::new(p.DAC, NoDma, p.PA4);
16 17
17 loop { 18 loop {
18 for v in 0..=255 { 19 for v in 0..=255 {
19 unwrap!(dac.set(Channel::Ch1, Value::Bit8(to_sine_wave(v)))); 20 unwrap!(dac.set(Value::Bit8(to_sine_wave(v))));
20 unwrap!(dac.trigger(Channel::Ch1)); 21 dac.trigger();
21 } 22 }
22 } 23 }
23} 24}
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs
index 5d010f799..80bf59deb 100644
--- a/examples/stm32f4/src/bin/multiprio.rs
+++ b/examples/stm32f4/src/bin/multiprio.rs
@@ -57,14 +57,11 @@
57#![no_main] 57#![no_main]
58#![feature(type_alias_impl_trait)] 58#![feature(type_alias_impl_trait)]
59 59
60use core::mem;
61
62use cortex_m::peripheral::NVIC;
63use cortex_m_rt::entry; 60use cortex_m_rt::entry;
64use defmt::*; 61use defmt::*;
65use embassy_executor::{Executor, InterruptExecutor}; 62use embassy_executor::{Executor, InterruptExecutor};
66use embassy_stm32::interrupt; 63use embassy_stm32::interrupt;
67use embassy_stm32::pac::Interrupt; 64use embassy_stm32::interrupt::{InterruptExt, Priority};
68use embassy_time::{Duration, Instant, Timer}; 65use embassy_time::{Duration, Instant, Timer};
69use static_cell::StaticCell; 66use static_cell::StaticCell;
70use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
@@ -130,16 +127,15 @@ fn main() -> ! {
130 info!("Hello World!"); 127 info!("Hello World!");
131 128
132 let _p = embassy_stm32::init(Default::default()); 129 let _p = embassy_stm32::init(Default::default());
133 let mut nvic: NVIC = unsafe { mem::transmute(()) };
134 130
135 // High-priority executor: UART4, priority level 6 131 // High-priority executor: UART4, priority level 6
136 unsafe { nvic.set_priority(Interrupt::UART4, 6 << 4) }; 132 interrupt::UART4.set_priority(Priority::P6);
137 let spawner = EXECUTOR_HIGH.start(Interrupt::UART4); 133 let spawner = EXECUTOR_HIGH.start(interrupt::UART4);
138 unwrap!(spawner.spawn(run_high())); 134 unwrap!(spawner.spawn(run_high()));
139 135
140 // Medium-priority executor: UART5, priority level 7 136 // Medium-priority executor: UART5, priority level 7
141 unsafe { nvic.set_priority(Interrupt::UART5, 7 << 4) }; 137 interrupt::UART5.set_priority(Priority::P7);
142 let spawner = EXECUTOR_MED.start(Interrupt::UART5); 138 let spawner = EXECUTOR_MED.start(interrupt::UART5);
143 unwrap!(spawner.spawn(run_med())); 139 unwrap!(spawner.spawn(run_med()));
144 140
145 // Low priority executor: runs in thread mode, using WFE/SEV 141 // Low priority executor: runs in thread mode, using WFE/SEV
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs
index d229cc3ef..b1f01417c 100644
--- a/examples/stm32f4/src/bin/usb_ethernet.rs
+++ b/examples/stm32f4/src/bin/usb_ethernet.rs
@@ -52,7 +52,9 @@ async fn main(spawner: Spawner) {
52 52
53 // Create the driver, from the HAL. 53 // Create the driver, from the HAL.
54 let ep_out_buffer = &mut make_static!([0; 256])[..]; 54 let ep_out_buffer = &mut make_static!([0; 256])[..];
55 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer); 55 let mut config = embassy_stm32::usb_otg::Config::default();
56 config.vbus_detection = true;
57 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer, config);
56 58
57 // Create embassy-usb Config 59 // Create embassy-usb Config
58 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); 60 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
@@ -94,8 +96,8 @@ async fn main(spawner: Spawner) {
94 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); 96 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
95 unwrap!(spawner.spawn(usb_ncm_task(runner))); 97 unwrap!(spawner.spawn(usb_ncm_task(runner)));
96 98
97 let config = embassy_net::Config::Dhcp(Default::default()); 99 let config = embassy_net::Config::dhcpv4(Default::default());
98 //let config = embassy_net::Config::Static(embassy_net::StaticConfig { 100 //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
99 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), 101 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
100 // dns_servers: Vec::new(), 102 // dns_servers: Vec::new(),
101 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), 103 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
diff --git a/examples/stm32f4/src/bin/usb_serial.rs b/examples/stm32f4/src/bin/usb_serial.rs
index f8f5940a7..4ff6452ef 100644
--- a/examples/stm32f4/src/bin/usb_serial.rs
+++ b/examples/stm32f4/src/bin/usb_serial.rs
@@ -29,7 +29,9 @@ async fn main(_spawner: Spawner) {
29 29
30 // Create the driver, from the HAL. 30 // Create the driver, from the HAL.
31 let mut ep_out_buffer = [0u8; 256]; 31 let mut ep_out_buffer = [0u8; 256];
32 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer); 32 let mut config = embassy_stm32::usb_otg::Config::default();
33 config.vbus_detection = true;
34 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
33 35
34 // Create embassy-usb Config 36 // Create embassy-usb Config
35 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); 37 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs
index b2c587fa1..e5d122af7 100644
--- a/examples/stm32f4/src/bin/wdt.rs
+++ b/examples/stm32f4/src/bin/wdt.rs
@@ -17,9 +17,7 @@ async fn main(_spawner: Spawner) {
17 let mut led = Output::new(p.PB7, Level::High, Speed::Low); 17 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
18 18
19 let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000); 19 let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000);
20 unsafe { 20 wdt.unleash();
21 wdt.unleash();
22 }
23 21
24 let mut i = 0; 22 let mut i = 0;
25 23
@@ -36,9 +34,7 @@ async fn main(_spawner: Spawner) {
36 // MCU should restart in 1 second after the last pet. 34 // MCU should restart in 1 second after the last pet.
37 if i < 5 { 35 if i < 5 {
38 info!("Petting watchdog"); 36 info!("Petting watchdog");
39 unsafe { 37 wdt.pet();
40 wdt.pet();
41 }
42 } 38 }
43 39
44 i += 1; 40 i += 1;
diff --git a/examples/stm32f7/.cargo/config.toml b/examples/stm32f7/.cargo/config.toml
index 7d6c88a99..9088eea6e 100644
--- a/examples/stm32f7/.cargo/config.toml
+++ b/examples/stm32f7/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F429ZITx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32F767ZITx" 3runner = "probe-rs run --chip STM32F767ZITx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabihf"
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml
index 7a650067c..657251c50 100644
--- a/examples/stm32f7/Cargo.toml
+++ b/examples/stm32f7/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] }
12embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } 12embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] }
diff --git a/examples/stm32f7/build.rs b/examples/stm32f7/build.rs
index c4e15f19c..2b5d412a9 100644
--- a/examples/stm32f7/build.rs
+++ b/examples/stm32f7/build.rs
@@ -1,9 +1,8 @@
1//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs 1//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs
2use std::env;
3use std::fs::File; 2use std::fs::File;
4use std::io::prelude::*; 3use std::io::prelude::*;
5use std::io::{self};
6use std::path::PathBuf; 4use std::path::PathBuf;
5use std::{env, io};
7 6
8#[derive(Debug)] 7#[derive(Debug)]
9enum Error { 8enum Error {
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs
index d8438241c..fde6a7576 100644
--- a/examples/stm32f7/src/bin/eth.rs
+++ b/examples/stm32f7/src/bin/eth.rs
@@ -62,8 +62,8 @@ async fn main(spawner: Spawner) -> ! {
62 0, 62 0,
63 ); 63 );
64 64
65 let config = embassy_net::Config::Dhcp(Default::default()); 65 let config = embassy_net::Config::dhcpv4(Default::default());
66 //let config = embassy_net::Config::Static(embassy_net::StaticConfig { 66 //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
67 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), 67 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
68 // dns_servers: Vec::new(), 68 // dns_servers: Vec::new(),
69 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), 69 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
diff --git a/examples/stm32f7/src/bin/usb_serial.rs b/examples/stm32f7/src/bin/usb_serial.rs
index 763309ce2..a2c76178b 100644
--- a/examples/stm32f7/src/bin/usb_serial.rs
+++ b/examples/stm32f7/src/bin/usb_serial.rs
@@ -30,7 +30,9 @@ async fn main(_spawner: Spawner) {
30 30
31 // Create the driver, from the HAL. 31 // Create the driver, from the HAL.
32 let mut ep_out_buffer = [0u8; 256]; 32 let mut ep_out_buffer = [0u8; 256];
33 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer); 33 let mut config = embassy_stm32::usb_otg::Config::default();
34 config.vbus_detection = true;
35 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
34 36
35 // Create embassy-usb Config 37 // Create embassy-usb Config
36 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); 38 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
diff --git a/examples/stm32g0/.cargo/config.toml b/examples/stm32g0/.cargo/config.toml
index a7a5fbd84..35cca5412 100644
--- a/examples/stm32g0/.cargo/config.toml
+++ b/examples/stm32g0/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32G071C8Rx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32G071C8Rx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32G071RBTx" 3runner = "probe-rs run --chip STM32G071RBTx"
4 4
5[build] 5[build]
6target = "thumbv6m-none-eabi" 6target = "thumbv6m-none-eabi"
diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml
index 4d7fc4548..c5245757b 100644
--- a/examples/stm32g0/Cargo.toml
+++ b/examples/stm32g0/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] }
12 12
diff --git a/examples/stm32g4/.cargo/config.toml b/examples/stm32g4/.cargo/config.toml
index 606d7d5a3..d28ad069e 100644
--- a/examples/stm32g4/.cargo/config.toml
+++ b/examples/stm32g4/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32G071C8Rx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32G071C8Rx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32G484VETx" 3runner = "probe-rs run --chip STM32G484VETx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabi" 6target = "thumbv7em-none-eabi"
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml
index 00e2dae4c..fbfbc6408 100644
--- a/examples/stm32g4/Cargo.toml
+++ b/examples/stm32g4/Cargo.toml
@@ -6,10 +6,11 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] }
12embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } 12embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
13 14
14defmt = "0.3" 15defmt = "0.3"
15defmt-rtt = "0.4" 16defmt-rtt = "0.4"
diff --git a/examples/stm32g4/src/bin/pll.rs b/examples/stm32g4/src/bin/pll.rs
new file mode 100644
index 000000000..ef7d4800c
--- /dev/null
+++ b/examples/stm32g4/src/bin/pll.rs
@@ -0,0 +1,35 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{ClockSrc, Pll, PllM, PllN, PllR, PllSrc};
8use embassy_stm32::Config;
9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let mut config = Config::default();
15
16 config.rcc.pll = Some(Pll {
17 source: PllSrc::HSI16,
18 prediv_m: PllM::Div4,
19 mul_n: PllN::Mul85,
20 div_p: None,
21 div_q: None,
22 // Main system clock at 170 MHz
23 div_r: Some(PllR::Div2),
24 });
25
26 config.rcc.mux = ClockSrc::PLL;
27
28 let _p = embassy_stm32::init(config);
29 info!("Hello World!");
30
31 loop {
32 Timer::after(Duration::from_millis(1000)).await;
33 info!("1s elapsed");
34 }
35}
diff --git a/examples/stm32g4/src/bin/usb_serial.rs b/examples/stm32g4/src/bin/usb_serial.rs
new file mode 100644
index 000000000..77cfa67d3
--- /dev/null
+++ b/examples/stm32g4/src/bin/usb_serial.rs
@@ -0,0 +1,120 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::{panic, *};
6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{Clock48MhzSrc, ClockSrc, CrsConfig, CrsSyncSource, Pll, PllM, PllN, PllQ, PllR, PllSrc};
8use embassy_stm32::time::Hertz;
9use embassy_stm32::usb::{self, Driver, Instance};
10use embassy_stm32::{bind_interrupts, peripherals, Config};
11use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
12use embassy_usb::driver::EndpointError;
13use embassy_usb::Builder;
14use futures::future::join;
15use {defmt_rtt as _, panic_probe as _};
16
17bind_interrupts!(struct Irqs {
18 USB_LP => usb::InterruptHandler<peripherals::USB>;
19});
20
21#[embassy_executor::main]
22async fn main(_spawner: Spawner) {
23 let mut config = Config::default();
24
25 // Change this to `false` to use the HSE clock source for the USB. This example assumes an 8MHz HSE.
26 const USE_HSI48: bool = true;
27
28 let pllq_div = if USE_HSI48 { None } else { Some(PllQ::Div6) };
29
30 config.rcc.pll = Some(Pll {
31 source: PllSrc::HSE(Hertz(8_000_000)),
32 prediv_m: PllM::Div2,
33 mul_n: PllN::Mul72,
34 div_p: None,
35 div_q: pllq_div,
36 // Main system clock at 144 MHz
37 div_r: Some(PllR::Div2),
38 });
39
40 config.rcc.mux = ClockSrc::PLL;
41
42 if USE_HSI48 {
43 // Sets up the Clock Recovery System (CRS) to use the USB SOF to trim the HSI48 oscillator.
44 config.rcc.clock_48mhz_src = Some(Clock48MhzSrc::Hsi48(Some(CrsConfig {
45 sync_src: CrsSyncSource::Usb,
46 })));
47 } else {
48 config.rcc.clock_48mhz_src = Some(Clock48MhzSrc::PllQ);
49 }
50
51 let p = embassy_stm32::init(config);
52
53 info!("Hello World!");
54
55 let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11);
56
57 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
58 config.manufacturer = Some("Embassy");
59 config.product = Some("USB-Serial Example");
60 config.serial_number = Some("123456");
61
62 config.device_class = 0xEF;
63 config.device_sub_class = 0x02;
64 config.device_protocol = 0x01;
65 config.composite_with_iads = true;
66
67 let mut device_descriptor = [0; 256];
68 let mut config_descriptor = [0; 256];
69 let mut bos_descriptor = [0; 256];
70 let mut control_buf = [0; 64];
71
72 let mut state = State::new();
73
74 let mut builder = Builder::new(
75 driver,
76 config,
77 &mut device_descriptor,
78 &mut config_descriptor,
79 &mut bos_descriptor,
80 &mut control_buf,
81 );
82
83 let mut class = CdcAcmClass::new(&mut builder, &mut state, 64);
84
85 let mut usb = builder.build();
86
87 let usb_fut = usb.run();
88
89 let echo_fut = async {
90 loop {
91 class.wait_connection().await;
92 info!("Connected");
93 let _ = echo(&mut class).await;
94 info!("Disconnected");
95 }
96 };
97
98 join(usb_fut, echo_fut).await;
99}
100
101struct Disconnected {}
102
103impl From<EndpointError> for Disconnected {
104 fn from(val: EndpointError) -> Self {
105 match val {
106 EndpointError::BufferOverflow => panic!("Buffer overflow"),
107 EndpointError::Disabled => Disconnected {},
108 }
109 }
110}
111
112async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> {
113 let mut buf = [0; 64];
114 loop {
115 let n = class.read_packet(&mut buf).await?;
116 let data = &buf[..n];
117 info!("data: {:x}", data);
118 class.write_packet(data).await?;
119 }
120}
diff --git a/examples/stm32h5/.cargo/config.toml b/examples/stm32h5/.cargo/config.toml
index c8b864b6c..478146142 100644
--- a/examples/stm32h5/.cargo/config.toml
+++ b/examples/stm32h5/.cargo/config.toml
@@ -1,5 +1,5 @@
1[target.thumbv8m.main-none-eabihf] 1[target.thumbv8m.main-none-eabihf]
2runner = 'probe-rs-cli run --chip STM32H563ZITx' 2runner = 'probe-rs run --chip STM32H563ZITx'
3 3
4[build] 4[build]
5target = "thumbv8m.main-none-eabihf" 5target = "thumbv8m.main-none-eabihf"
diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml
index d49a0dde7..ebe511347 100644
--- a/examples/stm32h5/Cargo.toml
+++ b/examples/stm32h5/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
12embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } 12embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] }
diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs
index 5d1eadf4b..78c8282a6 100644
--- a/examples/stm32h5/src/bin/eth.rs
+++ b/examples/stm32h5/src/bin/eth.rs
@@ -81,8 +81,8 @@ async fn main(spawner: Spawner) -> ! {
81 0, 81 0,
82 ); 82 );
83 83
84 let config = embassy_net::Config::Dhcp(Default::default()); 84 let config = embassy_net::Config::dhcpv4(Default::default());
85 //let config = embassy_net::Config::Static(embassy_net::StaticConfig { 85 //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
86 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), 86 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
87 // dns_servers: Vec::new(), 87 // dns_servers: Vec::new(),
88 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), 88 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
diff --git a/examples/stm32h5/src/bin/usb_serial.rs b/examples/stm32h5/src/bin/usb_serial.rs
index 3912327e2..336eed644 100644
--- a/examples/stm32h5/src/bin/usb_serial.rs
+++ b/examples/stm32h5/src/bin/usb_serial.rs
@@ -45,11 +45,9 @@ async fn main(_spawner: Spawner) {
45 45
46 info!("Hello World!"); 46 info!("Hello World!");
47 47
48 unsafe { 48 pac::RCC.ccipr4().write(|w| {
49 pac::RCC.ccipr4().write(|w| { 49 w.set_usbsel(pac::rcc::vals::Usbsel::HSI48);
50 w.set_usbsel(pac::rcc::vals::Usbsel::HSI48); 50 });
51 });
52 }
53 51
54 // Create the driver, from the HAL. 52 // Create the driver, from the HAL.
55 let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); 53 let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11);
diff --git a/examples/stm32h7/.cargo/config.toml b/examples/stm32h7/.cargo/config.toml
index f08f57a54..5f680dbce 100644
--- a/examples/stm32h7/.cargo/config.toml
+++ b/examples/stm32h7/.cargo/config.toml
@@ -1,5 +1,5 @@
1[target.thumbv7em-none-eabihf] 1[target.thumbv7em-none-eabihf]
2runner = 'probe-rs-cli run --chip STM32H743ZITx' 2runner = 'probe-rs run --chip STM32H743ZITx'
3 3
4[build] 4[build]
5target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) 5target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
index 08b57f988..62ef5e9e4 100644
--- a/examples/stm32h7/Cargo.toml
+++ b/examples/stm32h7/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
12embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } 12embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] }
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs
index f12716370..586b4154b 100644
--- a/examples/stm32h7/src/bin/dac.rs
+++ b/examples/stm32h7/src/bin/dac.rs
@@ -4,7 +4,8 @@
4 4
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use embassy_stm32::dac::{Channel, Dac, Value}; 7use embassy_stm32::dac::{DacCh1, DacChannel, Value};
8use embassy_stm32::dma::NoDma;
8use embassy_stm32::time::mhz; 9use embassy_stm32::time::mhz;
9use embassy_stm32::Config; 10use embassy_stm32::Config;
10use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
@@ -19,12 +20,12 @@ fn main() -> ! {
19 config.rcc.pll1.q_ck = Some(mhz(100)); 20 config.rcc.pll1.q_ck = Some(mhz(100));
20 let p = embassy_stm32::init(config); 21 let p = embassy_stm32::init(config);
21 22
22 let mut dac = Dac::new_1ch(p.DAC1, p.PA4); 23 let mut dac = DacCh1::new(p.DAC1, NoDma, p.PA4);
23 24
24 loop { 25 loop {
25 for v in 0..=255 { 26 for v in 0..=255 {
26 unwrap!(dac.set(Channel::Ch1, Value::Bit8(to_sine_wave(v)))); 27 unwrap!(dac.set(Value::Bit8(to_sine_wave(v))));
27 unwrap!(dac.trigger(Channel::Ch1)); 28 dac.trigger();
28 } 29 }
29 } 30 }
30} 31}
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index 3aa7b2271..12d37f7a4 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -63,8 +63,8 @@ async fn main(spawner: Spawner) -> ! {
63 0, 63 0,
64 ); 64 );
65 65
66 let config = embassy_net::Config::Dhcp(Default::default()); 66 let config = embassy_net::Config::dhcpv4(Default::default());
67 //let config = embassy_net::Config::Static(embassy_net::StaticConfig { 67 //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
68 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), 68 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
69 // dns_servers: Vec::new(), 69 // dns_servers: Vec::new(),
70 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), 70 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
index 575c716b6..6078fc3fe 100644
--- a/examples/stm32h7/src/bin/eth_client.rs
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -64,8 +64,8 @@ async fn main(spawner: Spawner) -> ! {
64 0, 64 0,
65 ); 65 );
66 66
67 let config = embassy_net::Config::Dhcp(Default::default()); 67 let config = embassy_net::Config::dhcpv4(Default::default());
68 //let config = embassy_net::Config::StaticConfig(embassy_net::Config { 68 //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
69 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), 69 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
70 // dns_servers: Vec::new(), 70 // dns_servers: Vec::new(),
71 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), 71 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index 1972f8ff2..d360df085 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -62,49 +62,39 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
62 T::enable(); 62 T::enable();
63 <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); 63 <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset();
64 64
65 unsafe { 65 ch1.set_speed(Speed::VeryHigh);
66 ch1.set_speed(Speed::VeryHigh); 66 ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull);
67 ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); 67 ch2.set_speed(Speed::VeryHigh);
68 ch2.set_speed(Speed::VeryHigh); 68 ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull);
69 ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); 69 ch3.set_speed(Speed::VeryHigh);
70 ch3.set_speed(Speed::VeryHigh); 70 ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull);
71 ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); 71 ch4.set_speed(Speed::VeryHigh);
72 ch4.set_speed(Speed::VeryHigh); 72 ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull);
73 ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull);
74 }
75 73
76 let mut this = Self { inner: tim }; 74 let mut this = Self { inner: tim };
77 75
78 this.set_freq(freq); 76 this.set_freq(freq);
79 this.inner.start(); 77 this.inner.start();
80 78
81 unsafe { 79 let r = T::regs_gp32();
82 T::regs_gp32() 80 r.ccmr_output(0)
83 .ccmr_output(0) 81 .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into()));
84 .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); 82 r.ccmr_output(0)
85 T::regs_gp32() 83 .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into()));
86 .ccmr_output(0) 84 r.ccmr_output(1)
87 .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); 85 .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into()));
88 T::regs_gp32() 86 r.ccmr_output(1)
89 .ccmr_output(1) 87 .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into()));
90 .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); 88
91 T::regs_gp32()
92 .ccmr_output(1)
93 .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into()));
94 }
95 this 89 this
96 } 90 }
97 91
98 pub fn enable(&mut self, channel: Channel) { 92 pub fn enable(&mut self, channel: Channel) {
99 unsafe { 93 T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true));
100 T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true));
101 }
102 } 94 }
103 95
104 pub fn disable(&mut self, channel: Channel) { 96 pub fn disable(&mut self, channel: Channel) {
105 unsafe { 97 T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false));
106 T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false));
107 }
108 } 98 }
109 99
110 pub fn set_freq(&mut self, freq: Hertz) { 100 pub fn set_freq(&mut self, freq: Hertz) {
@@ -112,11 +102,11 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
112 } 102 }
113 103
114 pub fn get_max_duty(&self) -> u32 { 104 pub fn get_max_duty(&self) -> u32 {
115 unsafe { T::regs_gp32().arr().read().arr() } 105 T::regs_gp32().arr().read().arr()
116 } 106 }
117 107
118 pub fn set_duty(&mut self, channel: Channel, duty: u32) { 108 pub fn set_duty(&mut self, channel: Channel, duty: u32) {
119 defmt::assert!(duty < self.get_max_duty()); 109 defmt::assert!(duty < self.get_max_duty());
120 unsafe { T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) } 110 T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty))
121 } 111 }
122} 112}
diff --git a/examples/stm32h7/src/bin/usb_serial.rs b/examples/stm32h7/src/bin/usb_serial.rs
index c622f19f7..97291f60c 100644
--- a/examples/stm32h7/src/bin/usb_serial.rs
+++ b/examples/stm32h7/src/bin/usb_serial.rs
@@ -29,7 +29,9 @@ async fn main(_spawner: Spawner) {
29 29
30 // Create the driver, from the HAL. 30 // Create the driver, from the HAL.
31 let mut ep_out_buffer = [0u8; 256]; 31 let mut ep_out_buffer = [0u8; 256];
32 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer); 32 let mut config = embassy_stm32::usb_otg::Config::default();
33 config.vbus_detection = true;
34 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
33 35
34 // Create embassy-usb Config 36 // Create embassy-usb Config
35 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); 37 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
diff --git a/examples/stm32h7/src/bin/wdg.rs b/examples/stm32h7/src/bin/wdg.rs
index 2b0301aad..9181dfd67 100644
--- a/examples/stm32h7/src/bin/wdg.rs
+++ b/examples/stm32h7/src/bin/wdg.rs
@@ -15,10 +15,10 @@ async fn main(_spawner: Spawner) {
15 15
16 let mut wdg = IndependentWatchdog::new(p.IWDG1, 20_000_000); 16 let mut wdg = IndependentWatchdog::new(p.IWDG1, 20_000_000);
17 17
18 unsafe { wdg.unleash() }; 18 wdg.unleash();
19 19
20 loop { 20 loop {
21 Timer::after(Duration::from_secs(1)).await; 21 Timer::after(Duration::from_secs(1)).await;
22 unsafe { wdg.pet() }; 22 wdg.pet();
23 } 23 }
24} 24}
diff --git a/examples/stm32l0/.cargo/config.toml b/examples/stm32l0/.cargo/config.toml
index 526f5a1f7..b050334b2 100644
--- a/examples/stm32l0/.cargo/config.toml
+++ b/examples/stm32l0/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-rs-cli chip list` 2# replace your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32L053R8Tx" 3runner = "probe-rs run --chip STM32L053R8Tx"
4 4
5[build] 5[build]
6target = "thumbv6m-none-eabi" 6target = "thumbv6m-none-eabi"
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index 235f1b0b3..2ead714e4 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[features] 7[features]
8default = ["nightly"] 8default = ["nightly"]
9nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", 9nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", "embassy-executor/nightly",
10 "embassy-lora", "lora-phy", "lorawan-device", "lorawan", "embedded-io/async"] 10 "embassy-lora", "lora-phy", "lorawan-device", "lorawan", "embedded-io/async"]
11 11
12[dependencies] 12[dependencies]
diff --git a/examples/stm32l1/.cargo/config.toml b/examples/stm32l1/.cargo/config.toml
index 1401500a0..9cabd14ba 100644
--- a/examples/stm32l1/.cargo/config.toml
+++ b/examples/stm32l1/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-rs-cli chip list` 2# replace your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32L151CBxxA" 3runner = "probe-rs run --chip STM32L151CBxxA"
4 4
5[build] 5[build]
6target = "thumbv7m-none-eabi" 6target = "thumbv7m-none-eabi"
diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml
index 8b6508c87..93d48abeb 100644
--- a/examples/stm32l1/Cargo.toml
+++ b/examples/stm32l1/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] }
12 12
diff --git a/examples/stm32l4/.cargo/config.toml b/examples/stm32l4/.cargo/config.toml
index abf55eb2e..36e74e5a5 100644
--- a/examples/stm32l4/.cargo/config.toml
+++ b/examples/stm32l4/.cargo/config.toml
@@ -1,8 +1,8 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32F429ZITx with your chip as listed in `probe-rs chip list`
3#runner = "probe-rs-cli run --chip STM32L475VGT6" 3#runner = "probe-rs run --chip STM32L475VGT6"
4#runner = "probe-rs-cli run --chip STM32L475VG" 4#runner = "probe-rs run --chip STM32L475VG"
5runner = "probe-rs-cli run --chip STM32L4S5VI" 5runner = "probe-rs run --chip STM32L4S5VI"
6 6
7[build] 7[build]
8target = "thumbv7em-none-eabi" 8target = "thumbv7em-none-eabi"
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml
index 29d091f94..780256cc2 100644
--- a/examples/stm32l4/Cargo.toml
+++ b/examples/stm32l4/Cargo.toml
@@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } 11embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
12embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] } 12embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits", "chrono"] }
13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
14 14
15defmt = "0.3" 15defmt = "0.3"
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs
index 281346e5f..1771e5202 100644
--- a/examples/stm32l4/src/bin/adc.rs
+++ b/examples/stm32l4/src/bin/adc.rs
@@ -12,12 +12,10 @@ use {defmt_rtt as _, panic_probe as _};
12fn main() -> ! { 12fn main() -> ! {
13 info!("Hello World!"); 13 info!("Hello World!");
14 14
15 unsafe { 15 pac::RCC.ccipr().modify(|w| {
16 pac::RCC.ccipr().modify(|w| { 16 w.set_adcsel(0b11);
17 w.set_adcsel(0b11); 17 });
18 }); 18 pac::RCC.ahb2enr().modify(|w| w.set_adcen(true));
19 pac::RCC.ahb2enr().modify(|w| w.set_adcen(true));
20 }
21 19
22 let p = embassy_stm32::init(Default::default()); 20 let p = embassy_stm32::init(Default::default());
23 21
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs
index d6e744aa6..ade43eb35 100644
--- a/examples/stm32l4/src/bin/dac.rs
+++ b/examples/stm32l4/src/bin/dac.rs
@@ -3,28 +3,21 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy_stm32::dac::{Channel, Dac, Value}; 6use embassy_stm32::dac::{DacCh1, DacChannel, Value};
7use embassy_stm32::pac; 7use embassy_stm32::dma::NoDma;
8use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
9 9
10#[cortex_m_rt::entry] 10#[cortex_m_rt::entry]
11fn main() -> ! { 11fn main() -> ! {
12 info!("Hello World!");
13
14 unsafe {
15 pac::RCC.apb1enr1().modify(|w| {
16 w.set_dac1en(true);
17 });
18 }
19
20 let p = embassy_stm32::init(Default::default()); 12 let p = embassy_stm32::init(Default::default());
13 info!("Hello World!");
21 14
22 let mut dac = Dac::new_1ch(p.DAC1, p.PA4); 15 let mut dac = DacCh1::new(p.DAC1, NoDma, p.PA4);
23 16
24 loop { 17 loop {
25 for v in 0..=255 { 18 for v in 0..=255 {
26 unwrap!(dac.set(Channel::Ch1, Value::Bit8(to_sine_wave(v)))); 19 unwrap!(dac.set(Value::Bit8(to_sine_wave(v))));
27 unwrap!(dac.trigger(Channel::Ch1)); 20 dac.trigger();
28 } 21 }
29 } 22 }
30} 23}
diff --git a/examples/stm32l4/src/bin/dac_dma.rs b/examples/stm32l4/src/bin/dac_dma.rs
new file mode 100644
index 000000000..c27cc03e1
--- /dev/null
+++ b/examples/stm32l4/src/bin/dac_dma.rs
@@ -0,0 +1,137 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::dac::{DacChannel, ValueArray};
8use embassy_stm32::pac::timer::vals::{Mms, Opm};
9use embassy_stm32::peripherals::{TIM6, TIM7};
10use embassy_stm32::rcc::low_level::RccPeripheral;
11use embassy_stm32::time::Hertz;
12use embassy_stm32::timer::low_level::Basic16bitInstance;
13use micromath::F32Ext;
14use {defmt_rtt as _, panic_probe as _};
15
16pub type Dac1Type =
17 embassy_stm32::dac::DacCh1<'static, embassy_stm32::peripherals::DAC1, embassy_stm32::peripherals::DMA1_CH3>;
18
19pub type Dac2Type =
20 embassy_stm32::dac::DacCh2<'static, embassy_stm32::peripherals::DAC1, embassy_stm32::peripherals::DMA1_CH4>;
21
22#[embassy_executor::main]
23async fn main(spawner: Spawner) {
24 let config = embassy_stm32::Config::default();
25
26 // Initialize the board and obtain a Peripherals instance
27 let p: embassy_stm32::Peripherals = embassy_stm32::init(config);
28
29 // Obtain two independent channels (p.DAC1 can only be consumed once, though!)
30 let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC1, p.DMA1_CH3, p.DMA1_CH4, p.PA4, p.PA5).split();
31
32 spawner.spawn(dac_task1(dac_ch1)).ok();
33 spawner.spawn(dac_task2(dac_ch2)).ok();
34}
35
36#[embassy_executor::task]
37async fn dac_task1(mut dac: Dac1Type) {
38 let data: &[u8; 256] = &calculate_array::<256>();
39
40 info!("TIM6 frequency is {}", TIM6::frequency());
41 const FREQUENCY: Hertz = Hertz::hz(200);
42
43 // Compute the reload value such that we obtain the FREQUENCY for the sine
44 let reload: u32 = (TIM6::frequency().0 / FREQUENCY.0) / data.len() as u32;
45
46 // Depends on your clock and on the specific chip used, you may need higher or lower values here
47 if reload < 10 {
48 error!("Reload value {} below threshold!", reload);
49 }
50
51 dac.select_trigger(embassy_stm32::dac::Ch1Trigger::Tim6).unwrap();
52 dac.enable_channel().unwrap();
53
54 TIM6::enable();
55 TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1));
56 TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE));
57 TIM6::regs().cr1().modify(|w| {
58 w.set_opm(Opm::DISABLED);
59 w.set_cen(true);
60 });
61
62 debug!(
63 "TIM6 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}",
64 TIM6::frequency(),
65 FREQUENCY,
66 reload,
67 reload as u16,
68 data.len()
69 );
70
71 // Loop technically not necessary if DMA circular mode is enabled
72 loop {
73 info!("Loop DAC1");
74 if let Err(e) = dac.write(ValueArray::Bit8(data), true).await {
75 error!("Could not write to dac: {}", e);
76 }
77 }
78}
79
80#[embassy_executor::task]
81async fn dac_task2(mut dac: Dac2Type) {
82 let data: &[u8; 256] = &calculate_array::<256>();
83
84 info!("TIM7 frequency is {}", TIM7::frequency());
85
86 const FREQUENCY: Hertz = Hertz::hz(600);
87 let reload: u32 = (TIM7::frequency().0 / FREQUENCY.0) / data.len() as u32;
88
89 if reload < 10 {
90 error!("Reload value {} below threshold!", reload);
91 }
92
93 TIM7::enable();
94 TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1));
95 TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE));
96 TIM7::regs().cr1().modify(|w| {
97 w.set_opm(Opm::DISABLED);
98 w.set_cen(true);
99 });
100
101 dac.select_trigger(embassy_stm32::dac::Ch2Trigger::Tim7).unwrap();
102
103 debug!(
104 "TIM7 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}",
105 TIM7::frequency(),
106 FREQUENCY,
107 reload,
108 reload as u16,
109 data.len()
110 );
111
112 if let Err(e) = dac.write(ValueArray::Bit8(data), true).await {
113 error!("Could not write to dac: {}", e);
114 }
115}
116
117fn to_sine_wave(v: u8) -> u8 {
118 if v >= 128 {
119 // top half
120 let r = 3.14 * ((v - 128) as f32 / 128.0);
121 (r.sin() * 128.0 + 127.0) as u8
122 } else {
123 // bottom half
124 let r = 3.14 + 3.14 * (v as f32 / 128.0);
125 (r.sin() * 128.0 + 127.0) as u8
126 }
127}
128
129fn calculate_array<const N: usize>() -> [u8; N] {
130 let mut res = [0; N];
131 let mut i = 0;
132 while i < N {
133 res[i] = to_sine_wave(i as u8);
134 i += 1;
135 }
136 res
137}
diff --git a/examples/stm32l4/src/bin/rtc.rs b/examples/stm32l4/src/bin/rtc.rs
index 0de708950..d72d5ddb6 100644
--- a/examples/stm32l4/src/bin/rtc.rs
+++ b/examples/stm32l4/src/bin/rtc.rs
@@ -46,5 +46,4 @@ async fn main(_spawner: Spawner) {
46 46
47 let then: NaiveDateTime = rtc.now().unwrap().into(); 47 let then: NaiveDateTime = rtc.now().unwrap().into();
48 info!("Got RTC! {:?}", then.timestamp()); 48 info!("Got RTC! {:?}", then.timestamp());
49
50} 49}
diff --git a/examples/stm32l4/src/bin/usb_serial.rs b/examples/stm32l4/src/bin/usb_serial.rs
index 80811a43e..410d6891b 100644
--- a/examples/stm32l4/src/bin/usb_serial.rs
+++ b/examples/stm32l4/src/bin/usb_serial.rs
@@ -30,7 +30,9 @@ async fn main(_spawner: Spawner) {
30 30
31 // Create the driver, from the HAL. 31 // Create the driver, from the HAL.
32 let mut ep_out_buffer = [0u8; 256]; 32 let mut ep_out_buffer = [0u8; 256];
33 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer); 33 let mut config = embassy_stm32::usb_otg::Config::default();
34 config.vbus_detection = true;
35 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
34 36
35 // Create embassy-usb Config 37 // Create embassy-usb Config
36 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); 38 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
diff --git a/examples/stm32l5/.cargo/config.toml b/examples/stm32l5/.cargo/config.toml
index 1dc3a6fb7..86a145a27 100644
--- a/examples/stm32l5/.cargo/config.toml
+++ b/examples/stm32l5/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32L552ZETxQ with your chip as listed in `probe-rs-cli chip list` 2# replace STM32L552ZETxQ with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32L552ZETxQ" 3runner = "probe-rs run --chip STM32L552ZETxQ"
4 4
5[build] 5[build]
6target = "thumbv8m.main-none-eabihf" 6target = "thumbv8m.main-none-eabihf"
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml
index 2ac9c180d..6035c291f 100644
--- a/examples/stm32l5/Cargo.toml
+++ b/examples/stm32l5/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs
index 6163e0709..32eba4277 100644
--- a/examples/stm32l5/src/bin/usb_ethernet.rs
+++ b/examples/stm32l5/src/bin/usb_ethernet.rs
@@ -91,8 +91,8 @@ async fn main(spawner: Spawner) {
91 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); 91 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
92 unwrap!(spawner.spawn(usb_ncm_task(runner))); 92 unwrap!(spawner.spawn(usb_ncm_task(runner)));
93 93
94 let config = embassy_net::Config::Dhcp(Default::default()); 94 let config = embassy_net::Config::dhcpv4(Default::default());
95 //let config = embassy_net::Config::Static(embassy_net::StaticConfig { 95 //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
96 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), 96 // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
97 // dns_servers: Vec::new(), 97 // dns_servers: Vec::new(),
98 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), 98 // gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
diff --git a/examples/stm32u5/.cargo/config.toml b/examples/stm32u5/.cargo/config.toml
index cecd01938..36c5b63a6 100644
--- a/examples/stm32u5/.cargo/config.toml
+++ b/examples/stm32u5/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32U585AIIx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32U585AIIx with your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32U585AIIx" 3runner = "probe-rs run --chip STM32U585AIIx"
4 4
5[build] 5[build]
6target = "thumbv8m.main-none-eabihf" 6target = "thumbv8m.main-none-eabihf"
diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml
index be205f880..e2318c3d6 100644
--- a/examples/stm32u5/Cargo.toml
+++ b/examples/stm32u5/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
diff --git a/examples/stm32u5/src/bin/usb_serial.rs b/examples/stm32u5/src/bin/usb_serial.rs
index f36daf91b..9e47fb18a 100644
--- a/examples/stm32u5/src/bin/usb_serial.rs
+++ b/examples/stm32u5/src/bin/usb_serial.rs
@@ -31,7 +31,9 @@ async fn main(_spawner: Spawner) {
31 31
32 // Create the driver, from the HAL. 32 // Create the driver, from the HAL.
33 let mut ep_out_buffer = [0u8; 256]; 33 let mut ep_out_buffer = [0u8; 256];
34 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer); 34 let mut config = embassy_stm32::usb_otg::Config::default();
35 config.vbus_detection = true;
36 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
35 37
36 // Create embassy-usb Config 38 // Create embassy-usb Config
37 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); 39 let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
diff --git a/examples/stm32wb/.cargo/config.toml b/examples/stm32wb/.cargo/config.toml
index d23fdc513..8b6d6d754 100644
--- a/examples/stm32wb/.cargo/config.toml
+++ b/examples/stm32wb/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32WB55CCUx with your chip as listed in `probe-rs-cli chip list` 2# replace STM32WB55CCUx with your chip as listed in `probe-rs chip list`
3# runner = "probe-rs-cli run --chip STM32WB55CCUx --speed 1000 --connect-under-reset" 3# runner = "probe-rs run --chip STM32WB55RGVx --speed 1000 --connect-under-reset"
4runner = "teleprobe local run --chip STM32WB55RG --elf" 4runner = "teleprobe local run --chip STM32WB55RG --elf"
5 5
6[build] 6[build]
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml
index 8cfac772a..fbb2d918b 100644
--- a/examples/stm32wb/Cargo.toml
+++ b/examples/stm32wb/Cargo.toml
@@ -6,9 +6,10 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] }
12embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] }
12 13
13defmt = "0.3" 14defmt = "0.3"
14defmt-rtt = "0.4" 15defmt-rtt = "0.4"
@@ -19,3 +20,24 @@ embedded-hal = "0.2.6"
19panic-probe = { version = "0.3", features = ["print-defmt"] } 20panic-probe = { version = "0.3", features = ["print-defmt"] }
20futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 21futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
21heapless = { version = "0.7.5", default-features = false } 22heapless = { version = "0.7.5", default-features = false }
23
24
25[features]
26default = ["ble"]
27mac = ["embassy-stm32-wpan/mac"]
28ble = ["embassy-stm32-wpan/ble"]
29
30[[bin]]
31name = "tl_mbox_ble"
32required-features = ["ble"]
33
34[[bin]]
35name = "tl_mbox_mac"
36required-features = ["mac"]
37
38[[bin]]
39name = "eddystone_beacon"
40required-features = ["ble"]
41
42[patch.crates-io]
43stm32wb-hci = { git = "https://github.com/OueslatiGhaith/stm32wb-hci", rev = "9f663be"} \ No newline at end of file
diff --git a/examples/stm32wb/src/bin/eddystone_beacon.rs b/examples/stm32wb/src/bin/eddystone_beacon.rs
new file mode 100644
index 000000000..b99f8cb2e
--- /dev/null
+++ b/examples/stm32wb/src/bin/eddystone_beacon.rs
@@ -0,0 +1,249 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use core::time::Duration;
6
7use defmt::*;
8use embassy_executor::Spawner;
9use embassy_stm32::bind_interrupts;
10use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
11use embassy_stm32_wpan::hci::host::uart::UartHci;
12use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType};
13use embassy_stm32_wpan::hci::types::AdvertisingType;
14use embassy_stm32_wpan::hci::vendor::stm32wb::command::gap::{
15 AdvertisingDataType, DiscoverableParameters, GapCommands, Role,
16};
17use embassy_stm32_wpan::hci::vendor::stm32wb::command::gatt::GattCommands;
18use embassy_stm32_wpan::hci::vendor::stm32wb::command::hal::{ConfigData, HalCommands, PowerLevel};
19use embassy_stm32_wpan::hci::BdAddr;
20use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp;
21use embassy_stm32_wpan::TlMbox;
22use {defmt_rtt as _, panic_probe as _};
23
24bind_interrupts!(struct Irqs{
25 IPCC_C1_RX => ReceiveInterruptHandler;
26 IPCC_C1_TX => TransmitInterruptHandler;
27});
28
29const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7;
30
31#[embassy_executor::main]
32async fn main(_spawner: Spawner) {
33 /*
34 How to make this work:
35
36 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
37 - Download and Install STM32CubeProgrammer.
38 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
39 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
40 - Open STM32CubeProgrammer
41 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
42 - Once complete, click connect to connect to the device.
43 - On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
44 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
45 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
46 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
47 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
48 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
49 - Select "Start Wireless Stack".
50 - Disconnect from the device.
51 - In the examples folder for stm32wb, modify the memory.x file to match your target device.
52 - Run this example.
53
54 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
55 */
56
57 let p = embassy_stm32::init(Default::default());
58 info!("Hello World!");
59
60 let config = Config::default();
61 let mut mbox = TlMbox::init(p.IPCC, Irqs, config);
62
63 let sys_event = mbox.sys_subsystem.read().await;
64 info!("sys event: {}", sys_event.payload());
65
66 mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
67
68 info!("resetting BLE...");
69 mbox.ble_subsystem.reset().await;
70 let response = mbox.ble_subsystem.read().await.unwrap();
71 defmt::info!("{}", response);
72
73 info!("config public address...");
74 mbox.ble_subsystem
75 .write_config_data(&ConfigData::public_address(get_bd_addr()).build())
76 .await;
77 let response = mbox.ble_subsystem.read().await.unwrap();
78 defmt::info!("{}", response);
79
80 info!("config random address...");
81 mbox.ble_subsystem
82 .write_config_data(&ConfigData::random_address(get_random_addr()).build())
83 .await;
84 let response = mbox.ble_subsystem.read().await.unwrap();
85 defmt::info!("{}", response);
86
87 info!("config identity root...");
88 mbox.ble_subsystem
89 .write_config_data(&ConfigData::identity_root(&get_irk()).build())
90 .await;
91 let response = mbox.ble_subsystem.read().await.unwrap();
92 defmt::info!("{}", response);
93
94 info!("config encryption root...");
95 mbox.ble_subsystem
96 .write_config_data(&ConfigData::encryption_root(&get_erk()).build())
97 .await;
98 let response = mbox.ble_subsystem.read().await.unwrap();
99 defmt::info!("{}", response);
100
101 info!("config tx power level...");
102 mbox.ble_subsystem.set_tx_power_level(PowerLevel::ZerodBm).await;
103 let response = mbox.ble_subsystem.read().await.unwrap();
104 defmt::info!("{}", response);
105
106 info!("GATT init...");
107 mbox.ble_subsystem.init_gatt().await;
108 let response = mbox.ble_subsystem.read().await.unwrap();
109 defmt::info!("{}", response);
110
111 info!("GAP init...");
112 mbox.ble_subsystem
113 .init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH)
114 .await;
115 let response = mbox.ble_subsystem.read().await.unwrap();
116 defmt::info!("{}", response);
117
118 // info!("set scan response...");
119 // mbox.ble_subsystem.le_set_scan_response_data(&[]).await.unwrap();
120 // let response = mbox.ble_subsystem.read().await.unwrap();
121 // defmt::info!("{}", response);
122
123 info!("set discoverable...");
124 mbox.ble_subsystem
125 .set_discoverable(&DiscoverableParameters {
126 advertising_type: AdvertisingType::NonConnectableUndirected,
127 advertising_interval: Some((Duration::from_millis(250), Duration::from_millis(250))),
128 address_type: OwnAddressType::Public,
129 filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan,
130 local_name: None,
131 advertising_data: &[],
132 conn_interval: (None, None),
133 })
134 .await
135 .unwrap();
136
137 let response = mbox.ble_subsystem.read().await;
138 defmt::info!("{}", response);
139
140 // remove some advertisement to decrease the packet size
141 info!("delete tx power ad type...");
142 mbox.ble_subsystem
143 .delete_ad_type(AdvertisingDataType::TxPowerLevel)
144 .await;
145 let response = mbox.ble_subsystem.read().await.unwrap();
146 defmt::info!("{}", response);
147
148 info!("delete conn interval ad type...");
149 mbox.ble_subsystem
150 .delete_ad_type(AdvertisingDataType::PeripheralConnectionInterval)
151 .await;
152 let response = mbox.ble_subsystem.read().await.unwrap();
153 defmt::info!("{}", response);
154
155 info!("update advertising data...");
156 mbox.ble_subsystem
157 .update_advertising_data(&eddystone_advertising_data())
158 .await
159 .unwrap();
160 let response = mbox.ble_subsystem.read().await.unwrap();
161 defmt::info!("{}", response);
162
163 info!("update advertising data type...");
164 mbox.ble_subsystem
165 .update_advertising_data(&[3, AdvertisingDataType::UuidCompleteList16 as u8, 0xaa, 0xfe])
166 .await
167 .unwrap();
168 let response = mbox.ble_subsystem.read().await.unwrap();
169 defmt::info!("{}", response);
170
171 info!("update advertising data flags...");
172 mbox.ble_subsystem
173 .update_advertising_data(&[
174 2,
175 AdvertisingDataType::Flags as u8,
176 (0x02 | 0x04) as u8, // BLE general discoverable, without BR/EDR support
177 ])
178 .await
179 .unwrap();
180 let response = mbox.ble_subsystem.read().await.unwrap();
181 defmt::info!("{}", response);
182
183 cortex_m::asm::wfi();
184}
185
186fn get_bd_addr() -> BdAddr {
187 let mut bytes = [0u8; 6];
188
189 let lhci_info = LhciC1DeviceInformationCcrp::new();
190 bytes[0] = (lhci_info.uid64 & 0xff) as u8;
191 bytes[1] = ((lhci_info.uid64 >> 8) & 0xff) as u8;
192 bytes[2] = ((lhci_info.uid64 >> 16) & 0xff) as u8;
193 bytes[3] = lhci_info.device_type_id;
194 bytes[4] = (lhci_info.st_company_id & 0xff) as u8;
195 bytes[5] = (lhci_info.st_company_id >> 8 & 0xff) as u8;
196
197 BdAddr(bytes)
198}
199
200fn get_random_addr() -> BdAddr {
201 let mut bytes = [0u8; 6];
202
203 let lhci_info = LhciC1DeviceInformationCcrp::new();
204 bytes[0] = (lhci_info.uid64 & 0xff) as u8;
205 bytes[1] = ((lhci_info.uid64 >> 8) & 0xff) as u8;
206 bytes[2] = ((lhci_info.uid64 >> 16) & 0xff) as u8;
207 bytes[3] = 0;
208 bytes[4] = 0x6E;
209 bytes[5] = 0xED;
210
211 BdAddr(bytes)
212}
213
214const BLE_CFG_IRK: [u8; 16] = [
215 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
216];
217const BLE_CFG_ERK: [u8; 16] = [
218 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21, 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21,
219];
220
221fn get_irk() -> EncryptionKey {
222 EncryptionKey(BLE_CFG_IRK)
223}
224
225fn get_erk() -> EncryptionKey {
226 EncryptionKey(BLE_CFG_ERK)
227}
228
229fn eddystone_advertising_data() -> [u8; 24] {
230 const EDDYSTONE_URL: &[u8] = b"www.rust-lang.com";
231
232 let mut service_data = [0u8; 24];
233 let url_len = EDDYSTONE_URL.len();
234
235 service_data[0] = 6 + url_len as u8;
236 service_data[1] = AdvertisingDataType::ServiceData as u8;
237
238 // 16-bit eddystone uuid
239 service_data[2] = 0xaa;
240 service_data[3] = 0xFE;
241
242 service_data[4] = 0x10; // URL frame type
243 service_data[5] = 22_i8 as u8; // calibrated TX power at 0m
244 service_data[6] = 0x03; // eddystone url prefix = https
245
246 service_data[7..(7 + url_len)].copy_from_slice(EDDYSTONE_URL);
247
248 service_data
249}
diff --git a/examples/stm32wb/src/bin/tl_mbox.rs b/examples/stm32wb/src/bin/tl_mbox.rs
index 8f4e70af0..9fc4b8aac 100644
--- a/examples/stm32wb/src/bin/tl_mbox.rs
+++ b/examples/stm32wb/src/bin/tl_mbox.rs
@@ -4,14 +4,15 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::tl_mbox::{Config, TlMbox}; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::{bind_interrupts, tl_mbox}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32_wpan::TlMbox;
9use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
11 12
12bind_interrupts!(struct Irqs{ 13bind_interrupts!(struct Irqs{
13 IPCC_C1_RX => tl_mbox::ReceiveInterruptHandler; 14 IPCC_C1_RX => ReceiveInterruptHandler;
14 IPCC_C1_TX => tl_mbox::TransmitInterruptHandler; 15 IPCC_C1_TX => TransmitInterruptHandler;
15}); 16});
16 17
17#[embassy_executor::main] 18#[embassy_executor::main]
@@ -44,10 +45,10 @@ async fn main(_spawner: Spawner) {
44 info!("Hello World!"); 45 info!("Hello World!");
45 46
46 let config = Config::default(); 47 let config = Config::default();
47 let mbox = TlMbox::new(p.IPCC, Irqs, config); 48 let mbox = TlMbox::init(p.IPCC, Irqs, config);
48 49
49 loop { 50 loop {
50 let wireless_fw_info = mbox.wireless_fw_info(); 51 let wireless_fw_info = mbox.sys_subsystem.wireless_fw_info();
51 match wireless_fw_info { 52 match wireless_fw_info {
52 None => info!("not yet initialized"), 53 None => info!("not yet initialized"),
53 Some(fw_info) => { 54 Some(fw_info) => {
diff --git a/examples/stm32wb/src/bin/tl_mbox_tx_rx.rs b/examples/stm32wb/src/bin/tl_mbox_ble.rs
index 1724d946f..a511e89aa 100644
--- a/examples/stm32wb/src/bin/tl_mbox_tx_rx.rs
+++ b/examples/stm32wb/src/bin/tl_mbox_ble.rs
@@ -4,13 +4,14 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::tl_mbox::{Config, TlMbox}; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::{bind_interrupts, tl_mbox}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32_wpan::TlMbox;
9use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
10 11
11bind_interrupts!(struct Irqs{ 12bind_interrupts!(struct Irqs{
12 IPCC_C1_RX => tl_mbox::ReceiveInterruptHandler; 13 IPCC_C1_RX => ReceiveInterruptHandler;
13 IPCC_C1_TX => tl_mbox::TransmitInterruptHandler; 14 IPCC_C1_TX => TransmitInterruptHandler;
14}); 15});
15 16
16#[embassy_executor::main] 17#[embassy_executor::main]
@@ -43,55 +44,20 @@ async fn main(_spawner: Spawner) {
43 info!("Hello World!"); 44 info!("Hello World!");
44 45
45 let config = Config::default(); 46 let config = Config::default();
46 let mbox = TlMbox::new(p.IPCC, Irqs, config); 47 let mbox = TlMbox::init(p.IPCC, Irqs, config);
47 48
48 info!("waiting for coprocessor to boot"); 49 let sys_event = mbox.sys_subsystem.read().await;
49 let event_box = mbox.read().await; 50 info!("sys event: {}", sys_event.payload());
50 51
51 let mut payload = [0u8; 6]; 52 mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
52 event_box.copy_into_slice(&mut payload).unwrap();
53 53
54 let event_packet = event_box.evt(); 54 info!("starting ble...");
55 let kind = event_packet.evt_serial.kind; 55 mbox.ble_subsystem.tl_write(0x0c, &[]).await;
56 56
57 // means recieved SYS event, which indicates in this case that the coprocessor is ready 57 info!("waiting for ble...");
58 if kind == 0x12 { 58 let ble_event = mbox.ble_subsystem.tl_read().await;
59 let code = event_packet.evt_serial.evt.evt_code;
60 let payload_len = event_packet.evt_serial.evt.payload_len;
61 59
62 info!( 60 info!("ble event: {}", ble_event.payload());
63 "==> kind: {:#04x}, code: {:#04x}, payload_length: {}, payload: {:#04x}",
64 kind,
65 code,
66 payload_len,
67 payload[3..]
68 );
69 }
70
71 // initialize ble stack, does not return a response
72 mbox.shci_ble_init(Default::default());
73
74 info!("resetting BLE");
75 mbox.send_ble_cmd(&[0x01, 0x03, 0x0c, 0x00, 0x00]);
76
77 let event_box = mbox.read().await;
78
79 let mut payload = [0u8; 7];
80 event_box.copy_into_slice(&mut payload).unwrap();
81
82 let event_packet = event_box.evt();
83 let kind = event_packet.evt_serial.kind;
84
85 let code = event_packet.evt_serial.evt.evt_code;
86 let payload_len = event_packet.evt_serial.evt.payload_len;
87
88 info!(
89 "==> kind: {:#04x}, code: {:#04x}, payload_length: {}, payload: {:#04x}",
90 kind,
91 code,
92 payload_len,
93 payload[3..]
94 );
95 61
96 info!("Test OK"); 62 info!("Test OK");
97 cortex_m::asm::bkpt(); 63 cortex_m::asm::bkpt();
diff --git a/examples/stm32wb/src/bin/tl_mbox_mac.rs b/examples/stm32wb/src/bin/tl_mbox_mac.rs
new file mode 100644
index 000000000..f67be4682
--- /dev/null
+++ b/examples/stm32wb/src/bin/tl_mbox_mac.rs
@@ -0,0 +1,66 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32_wpan::TlMbox;
10use {defmt_rtt as _, panic_probe as _};
11
12bind_interrupts!(struct Irqs{
13 IPCC_C1_RX => ReceiveInterruptHandler;
14 IPCC_C1_TX => TransmitInterruptHandler;
15});
16
17#[embassy_executor::main]
18async fn main(_spawner: Spawner) {
19 /*
20 How to make this work:
21
22 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
23 - Download and Install STM32CubeProgrammer.
24 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
25 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
26 - Open STM32CubeProgrammer
27 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
28 - Once complete, click connect to connect to the device.
29 - On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
30 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
31 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
32 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
33 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
34 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
35 - Select "Start Wireless Stack".
36 - Disconnect from the device.
37 - In the examples folder for stm32wb, modify the memory.x file to match your target device.
38 - Run this example.
39
40 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
41 */
42
43 let p = embassy_stm32::init(Default::default());
44 info!("Hello World!");
45
46 let config = Config::default();
47 let mbox = TlMbox::init(p.IPCC, Irqs, config);
48
49 let sys_event = mbox.sys_subsystem.read().await;
50 info!("sys event: {}", sys_event.payload());
51
52 let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
53 info!("initialized mac: {}", result);
54
55 //
56 // info!("starting ble...");
57 // mbox.ble_subsystem.t_write(0x0c, &[]).await;
58 //
59 // info!("waiting for ble...");
60 // let ble_event = mbox.ble_subsystem.tl_read().await;
61 //
62 // info!("ble event: {}", ble_event.payload());
63
64 info!("Test OK");
65 cortex_m::asm::bkpt();
66}
diff --git a/examples/stm32wl/.cargo/config.toml b/examples/stm32wl/.cargo/config.toml
index b49b582e0..4f8094ff2 100644
--- a/examples/stm32wl/.cargo/config.toml
+++ b/examples/stm32wl/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-rs-cli chip list` 2# replace your chip as listed in `probe-rs chip list`
3runner = "probe-rs-cli run --chip STM32WLE5JCIx" 3runner = "probe-rs run --chip STM32WLE5JCIx"
4 4
5[build] 5[build]
6target = "thumbv7em-none-eabihf" 6target = "thumbv7em-none-eabihf"
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml
index 6191d01e9..260f9afa1 100644
--- a/examples/stm32wl/Cargo.toml
+++ b/examples/stm32wl/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] }
12embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" } 12embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" }
diff --git a/examples/stm32wl/src/bin/lora_lorawan.rs b/examples/stm32wl/src/bin/lora_lorawan.rs
index e179c5ca1..805d21418 100644
--- a/examples/stm32wl/src/bin/lora_lorawan.rs
+++ b/examples/stm32wl/src/bin/lora_lorawan.rs
@@ -35,7 +35,7 @@ async fn main(_spawner: Spawner) {
35 config.rcc.enable_lsi = true; // enable RNG 35 config.rcc.enable_lsi = true; // enable RNG
36 let p = embassy_stm32::init(config); 36 let p = embassy_stm32::init(config);
37 37
38 unsafe { pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)) } 38 pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01));
39 39
40 let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); 40 let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2);
41 41
diff --git a/examples/stm32wl/src/bin/random.rs b/examples/stm32wl/src/bin/random.rs
index 182c607f9..d8562fca5 100644
--- a/examples/stm32wl/src/bin/random.rs
+++ b/examples/stm32wl/src/bin/random.rs
@@ -15,11 +15,9 @@ async fn main(_spawner: Spawner) {
15 config.rcc.enable_lsi = true; //Needed for RNG to work 15 config.rcc.enable_lsi = true; //Needed for RNG to work
16 16
17 let p = embassy_stm32::init(config); 17 let p = embassy_stm32::init(config);
18 unsafe { 18 pac::RCC.ccipr().modify(|w| {
19 pac::RCC.ccipr().modify(|w| { 19 w.set_rngsel(0b01);
20 w.set_rngsel(0b01); 20 });
21 });
22 }
23 21
24 info!("Hello World!"); 22 info!("Hello World!");
25 23