aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorchemicstry <[email protected]>2023-07-31 10:29:20 +0300
committerchemicstry <[email protected]>2023-07-31 10:29:20 +0300
commit780569c08ab089dae67c5d57dd1852d5419d4577 (patch)
tree021965b7c9ac34fb33507c3998b3a6b6e7cecae7 /examples
parenta56ef685f3bfd9148a79c9dbbdde83a2c1642ba5 (diff)
parent6c6bd11c1a28eb8985518a10bd723c622d82f4b6 (diff)
Merge remote-tracking branch 'origin/main' into bxcan_timestamp
Diffstat (limited to 'examples')
-rw-r--r--examples/boot/application/rp/src/bin/a.rs4
-rw-r--r--examples/nrf-rtos-trace/Cargo.toml3
-rw-r--r--examples/nrf52840-rtic/Cargo.toml3
-rw-r--r--examples/nrf52840/Cargo.toml4
-rw-r--r--examples/nrf5340/Cargo.toml3
-rw-r--r--examples/rp/Cargo.toml5
-rw-r--r--examples/rp/src/bin/flash.rs42
-rw-r--r--examples/rp/src/bin/pio_async.rs10
-rw-r--r--examples/rp/src/bin/pio_dma.rs4
-rw-r--r--examples/rp/src/bin/pio_hd44780.rs7
-rw-r--r--examples/rp/src/bin/pio_uart.rs394
-rw-r--r--examples/rp/src/bin/pio_ws2812.rs4
-rw-r--r--examples/std/Cargo.toml3
-rw-r--r--examples/stm32c0/Cargo.toml3
-rw-r--r--examples/stm32f0/Cargo.toml3
-rw-r--r--examples/stm32f1/Cargo.toml3
-rw-r--r--examples/stm32f2/Cargo.toml3
-rw-r--r--examples/stm32f3/Cargo.toml3
-rw-r--r--examples/stm32f3/src/bin/spi_dma.rs14
-rw-r--r--examples/stm32f334/.cargo/config.toml9
-rw-r--r--examples/stm32f334/Cargo.toml26
-rw-r--r--examples/stm32f334/build.rs5
-rw-r--r--examples/stm32f334/src/bin/button.rs27
-rw-r--r--examples/stm32f334/src/bin/hello.rs23
-rw-r--r--examples/stm32f334/src/bin/pwm.rs71
-rw-r--r--examples/stm32f4/src/bin/eth.rs6
-rw-r--r--examples/stm32f4/src/bin/pwm.rs7
-rw-r--r--examples/stm32f4/src/bin/pwm_complementary.rs11
-rw-r--r--examples/stm32f4/src/bin/spi.rs14
-rw-r--r--examples/stm32f4/src/bin/spi_dma.rs14
-rw-r--r--examples/stm32f4/src/bin/usb_ethernet.rs5
-rw-r--r--examples/stm32f7/Cargo.toml5
-rw-r--r--examples/stm32f7/build.rs40
-rw-r--r--examples/stm32f7/memory.x12
-rw-r--r--examples/stm32f7/src/bin/eth.rs6
-rw-r--r--examples/stm32g0/Cargo.toml3
-rw-r--r--examples/stm32g0/src/bin/spi_neopixel.rs4
-rw-r--r--examples/stm32g4/Cargo.toml4
-rw-r--r--examples/stm32g4/src/bin/pwm.rs7
-rw-r--r--examples/stm32h5/Cargo.toml2
-rw-r--r--examples/stm32h5/memory.x5
-rw-r--r--examples/stm32h5/src/bin/eth.rs6
-rw-r--r--examples/stm32h5/src/bin/rng.rs7
-rw-r--r--examples/stm32h7/.cargo/config.toml2
-rw-r--r--examples/stm32h7/Cargo.toml2
-rw-r--r--examples/stm32h7/memory.x5
-rw-r--r--examples/stm32h7/src/bin/dac_dma.rs140
-rw-r--r--examples/stm32h7/src/bin/eth.rs6
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs6
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs2
-rw-r--r--examples/stm32h7/src/bin/pwm.rs7
-rw-r--r--examples/stm32h7/src/bin/rng.rs7
-rw-r--r--examples/stm32h7/src/bin/spi.rs14
-rw-r--r--examples/stm32h7/src/bin/spi_dma.rs14
-rw-r--r--examples/stm32l0/Cargo.toml4
-rw-r--r--examples/stm32l0/src/bin/lora_cad.rs14
-rw-r--r--examples/stm32l0/src/bin/lora_lorawan.rs22
-rw-r--r--examples/stm32l0/src/bin/lora_p2p_receive.rs14
-rw-r--r--examples/stm32l0/src/bin/lora_p2p_send.rs14
-rw-r--r--examples/stm32l0/src/bin/spi.rs14
-rw-r--r--examples/stm32l1/Cargo.toml3
-rw-r--r--examples/stm32l1/src/bin/spi.rs14
-rw-r--r--examples/stm32l4/Cargo.toml5
-rw-r--r--examples/stm32l4/build.rs30
-rw-r--r--examples/stm32l4/memory.x7
-rw-r--r--examples/stm32l4/src/bin/rng.rs8
-rw-r--r--examples/stm32l4/src/bin/spi.rs14
-rw-r--r--examples/stm32l4/src/bin/spi_blocking_async.rs14
-rw-r--r--examples/stm32l4/src/bin/spi_dma.rs14
-rw-r--r--examples/stm32l5/Cargo.toml3
-rw-r--r--examples/stm32l5/src/bin/rng.rs8
-rw-r--r--examples/stm32l5/src/bin/usb_ethernet.rs5
-rw-r--r--examples/stm32u5/Cargo.toml3
-rw-r--r--examples/stm32wb/Cargo.toml3
-rw-r--r--examples/stm32wb/src/bin/eddystone_beacon.rs5
-rw-r--r--examples/stm32wb/src/bin/gatt_server.rs5
-rw-r--r--examples/stm32wb/src/bin/mac_ffd.rs9
-rw-r--r--examples/stm32wb/src/bin/mac_ffd_net.rs9
-rw-r--r--examples/stm32wb/src/bin/mac_rfd.rs9
-rw-r--r--examples/stm32wb/src/bin/tl_mbox.rs5
-rw-r--r--examples/stm32wb/src/bin/tl_mbox_ble.rs5
-rw-r--r--examples/stm32wb/src/bin/tl_mbox_mac.rs9
-rw-r--r--examples/stm32wl/Cargo.toml4
-rw-r--r--examples/stm32wl/src/bin/lora_lorawan.rs7
-rw-r--r--examples/stm32wl/src/bin/random.rs10
-rw-r--r--examples/wasm/Cargo.toml3
86 files changed, 994 insertions, 338 deletions
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs
index c8497494c..b5e1950cc 100644
--- a/examples/boot/application/rp/src/bin/a.rs
+++ b/examples/boot/application/rp/src/bin/a.rs
@@ -7,7 +7,7 @@ use core::cell::RefCell;
7use defmt_rtt as _; 7use defmt_rtt as _;
8use embassy_boot_rp::*; 8use embassy_boot_rp::*;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_rp::flash::Flash; 10use embassy_rp::flash::{self, Flash};
11use embassy_rp::gpio::{Level, Output}; 11use embassy_rp::gpio::{Level, Output};
12use embassy_rp::watchdog::Watchdog; 12use embassy_rp::watchdog::Watchdog;
13use embassy_sync::blocking_mutex::Mutex; 13use embassy_sync::blocking_mutex::Mutex;
@@ -34,7 +34,7 @@ async fn main(_s: Spawner) {
34 let mut watchdog = Watchdog::new(p.WATCHDOG); 34 let mut watchdog = Watchdog::new(p.WATCHDOG);
35 watchdog.start(Duration::from_secs(8)); 35 watchdog.start(Duration::from_secs(8));
36 36
37 let flash: Flash<_, FLASH_SIZE> = Flash::new(p.FLASH); 37 let flash = Flash::<_, flash::Blocking, FLASH_SIZE>::new(p.FLASH);
38 let flash = Mutex::new(RefCell::new(flash)); 38 let flash = Mutex::new(RefCell::new(flash));
39 39
40 let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); 40 let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash);
diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml
index 30b67b7b2..068474e7a 100644
--- a/examples/nrf-rtos-trace/Cargo.toml
+++ b/examples/nrf-rtos-trace/Cargo.toml
@@ -34,3 +34,6 @@ log = { version = "0.4.17", optional = true }
34[[bin]] 34[[bin]]
35name = "rtos_trace" 35name = "rtos_trace"
36required-features = ["nightly"] 36required-features = ["nightly"]
37
38[profile.release]
39debug = 2
diff --git a/examples/nrf52840-rtic/Cargo.toml b/examples/nrf52840-rtic/Cargo.toml
index ded3b7db8..715f1ecfe 100644
--- a/examples/nrf52840-rtic/Cargo.toml
+++ b/examples/nrf52840-rtic/Cargo.toml
@@ -19,3 +19,6 @@ cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-sing
19cortex-m-rt = "0.7.0" 19cortex-m-rt = "0.7.0"
20panic-probe = { version = "0.3", features = ["print-defmt"] } 20panic-probe = { version = "0.3", features = ["print-defmt"] }
21futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 21futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
22
23[profile.release]
24debug = 2
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml
index 9b41ec5ab..780aaeac2 100644
--- a/examples/nrf52840/Cargo.toml
+++ b/examples/nrf52840/Cargo.toml
@@ -57,5 +57,5 @@ embedded-hal-async = { version = "0.2.0-alpha.2", optional = true }
57num-integer = { version = "0.1.45", default-features = false } 57num-integer = { version = "0.1.45", default-features = false }
58microfft = "0.5.0" 58microfft = "0.5.0"
59 59
60[patch.crates-io] 60[profile.release]
61lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } 61debug = 2
diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml
index f1d45f336..b0e51dcf4 100644
--- a/examples/nrf5340/Cargo.toml
+++ b/examples/nrf5340/Cargo.toml
@@ -53,3 +53,6 @@ rand = { version = "0.8.4", default-features = false }
53embedded-storage = "0.3.0" 53embedded-storage = "0.3.0"
54usbd-hid = "0.6.0" 54usbd-hid = "0.6.0"
55serde = { version = "1.0.136", default-features = false } 55serde = { version = "1.0.136", default-features = false }
56
57[profile.release]
58debug = 2
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml
index c812cb3ee..8c61dc5e1 100644
--- a/examples/rp/Cargo.toml
+++ b/examples/rp/Cargo.toml
@@ -53,7 +53,4 @@ pio = "0.2.1"
53rand = { version = "0.8.5", default-features = false } 53rand = { version = "0.8.5", default-features = false }
54 54
55[profile.release] 55[profile.release]
56debug = true 56debug = 2
57
58[patch.crates-io]
59lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" }
diff --git a/examples/rp/src/bin/flash.rs b/examples/rp/src/bin/flash.rs
index 4c4982acc..88bb931d2 100644
--- a/examples/rp/src/bin/flash.rs
+++ b/examples/rp/src/bin/flash.rs
@@ -6,7 +6,7 @@
6 6
7use defmt::*; 7use defmt::*;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_rp::flash::{ERASE_SIZE, FLASH_BASE}; 9use embassy_rp::flash::{Async, ERASE_SIZE, FLASH_BASE};
10use embassy_rp::peripherals::FLASH; 10use embassy_rp::peripherals::FLASH;
11use embassy_time::{Duration, Timer}; 11use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
25 // https://github.com/knurling-rs/defmt/pull/683 25 // https://github.com/knurling-rs/defmt/pull/683
26 Timer::after(Duration::from_millis(10)).await; 26 Timer::after(Duration::from_millis(10)).await;
27 27
28 let mut flash = embassy_rp::flash::Flash::<_, FLASH_SIZE>::new(p.FLASH); 28 let mut flash = embassy_rp::flash::Flash::<_, Async, FLASH_SIZE>::new(p.FLASH, p.DMA_CH0);
29 29
30 // Get JEDEC id 30 // Get JEDEC id
31 let jedec = flash.jedec_id().unwrap(); 31 let jedec = flash.jedec_id().unwrap();
@@ -40,10 +40,12 @@ async fn main(_spawner: Spawner) {
40 40
41 multiwrite_bytes(&mut flash, ERASE_SIZE as u32); 41 multiwrite_bytes(&mut flash, ERASE_SIZE as u32);
42 42
43 background_read(&mut flash, (ERASE_SIZE * 2) as u32).await;
44
43 loop {} 45 loop {}
44} 46}
45 47
46fn multiwrite_bytes(flash: &mut embassy_rp::flash::Flash<'_, FLASH, FLASH_SIZE>, offset: u32) { 48fn multiwrite_bytes(flash: &mut embassy_rp::flash::Flash<'_, FLASH, Async, FLASH_SIZE>, offset: u32) {
47 info!(">>>> [multiwrite_bytes]"); 49 info!(">>>> [multiwrite_bytes]");
48 let mut read_buf = [0u8; ERASE_SIZE]; 50 let mut read_buf = [0u8; ERASE_SIZE];
49 defmt::unwrap!(flash.read(ADDR_OFFSET + offset, &mut read_buf)); 51 defmt::unwrap!(flash.read(ADDR_OFFSET + offset, &mut read_buf));
@@ -71,7 +73,7 @@ fn multiwrite_bytes(flash: &mut embassy_rp::flash::Flash<'_, FLASH, FLASH_SIZE>,
71 } 73 }
72} 74}
73 75
74fn erase_write_sector(flash: &mut embassy_rp::flash::Flash<'_, FLASH, FLASH_SIZE>, offset: u32) { 76fn erase_write_sector(flash: &mut embassy_rp::flash::Flash<'_, FLASH, Async, FLASH_SIZE>, offset: u32) {
75 info!(">>>> [erase_write_sector]"); 77 info!(">>>> [erase_write_sector]");
76 let mut buf = [0u8; ERASE_SIZE]; 78 let mut buf = [0u8; ERASE_SIZE];
77 defmt::unwrap!(flash.read(ADDR_OFFSET + offset, &mut buf)); 79 defmt::unwrap!(flash.read(ADDR_OFFSET + offset, &mut buf));
@@ -99,3 +101,35 @@ fn erase_write_sector(flash: &mut embassy_rp::flash::Flash<'_, FLASH, FLASH_SIZE
99 defmt::panic!("unexpected"); 101 defmt::panic!("unexpected");
100 } 102 }
101} 103}
104
105async fn background_read(flash: &mut embassy_rp::flash::Flash<'_, FLASH, Async, FLASH_SIZE>, offset: u32) {
106 info!(">>>> [background_read]");
107
108 let mut buf = [0u32; 8];
109 defmt::unwrap!(flash.background_read(ADDR_OFFSET + offset, &mut buf)).await;
110
111 info!("Addr of flash block is {:x}", ADDR_OFFSET + offset + FLASH_BASE as u32);
112 info!("Contents start with {=u32:x}", buf[0]);
113
114 defmt::unwrap!(flash.erase(ADDR_OFFSET + offset, ADDR_OFFSET + offset + ERASE_SIZE as u32));
115
116 defmt::unwrap!(flash.background_read(ADDR_OFFSET + offset, &mut buf)).await;
117 info!("Contents after erase starts with {=u32:x}", buf[0]);
118 if buf.iter().any(|x| *x != 0xFFFFFFFF) {
119 defmt::panic!("unexpected");
120 }
121
122 for b in buf.iter_mut() {
123 *b = 0xDABA1234;
124 }
125
126 defmt::unwrap!(flash.write(ADDR_OFFSET + offset, unsafe {
127 core::slice::from_raw_parts(buf.as_ptr() as *const u8, buf.len() * 4)
128 }));
129
130 defmt::unwrap!(flash.background_read(ADDR_OFFSET + offset, &mut buf)).await;
131 info!("Contents after write starts with {=u32:x}", buf[0]);
132 if buf.iter().any(|x| *x != 0xDABA1234) {
133 defmt::panic!("unexpected");
134 }
135}
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs
index c001d6440..a6d6144be 100644
--- a/examples/rp/src/bin/pio_async.rs
+++ b/examples/rp/src/bin/pio_async.rs
@@ -8,7 +8,6 @@ use embassy_executor::Spawner;
8use embassy_rp::bind_interrupts; 8use embassy_rp::bind_interrupts;
9use embassy_rp::peripherals::PIO0; 9use embassy_rp::peripherals::PIO0;
10use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; 10use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine};
11use embassy_rp::relocate::RelocatedProgram;
12use fixed::traits::ToFixed; 11use fixed::traits::ToFixed;
13use fixed_macro::types::U56F8; 12use fixed_macro::types::U56F8;
14use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
@@ -29,9 +28,8 @@ fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
29 ".wrap", 28 ".wrap",
30 ); 29 );
31 30
32 let relocated = RelocatedProgram::new(&prg.program);
33 let mut cfg = Config::default(); 31 let mut cfg = Config::default();
34 cfg.use_program(&pio.load_program(&relocated), &[]); 32 cfg.use_program(&pio.load_program(&prg.program), &[]);
35 let out_pin = pio.make_pio_pin(pin); 33 let out_pin = pio.make_pio_pin(pin);
36 cfg.set_out_pins(&[&out_pin]); 34 cfg.set_out_pins(&[&out_pin]);
37 cfg.set_set_pins(&[&out_pin]); 35 cfg.set_set_pins(&[&out_pin]);
@@ -65,9 +63,8 @@ fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
65 ".wrap", 63 ".wrap",
66 ); 64 );
67 65
68 let relocated = RelocatedProgram::new(&prg.program);
69 let mut cfg = Config::default(); 66 let mut cfg = Config::default();
70 cfg.use_program(&pio.load_program(&relocated), &[]); 67 cfg.use_program(&pio.load_program(&prg.program), &[]);
71 cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed(); 68 cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed();
72 cfg.shift_in.auto_fill = true; 69 cfg.shift_in.auto_fill = true;
73 cfg.shift_in.direction = ShiftDirection::Right; 70 cfg.shift_in.direction = ShiftDirection::Right;
@@ -96,9 +93,8 @@ fn setup_pio_task_sm2<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
96 "irq 3 [15]", 93 "irq 3 [15]",
97 ".wrap", 94 ".wrap",
98 ); 95 );
99 let relocated = RelocatedProgram::new(&prg.program);
100 let mut cfg = Config::default(); 96 let mut cfg = Config::default();
101 cfg.use_program(&pio.load_program(&relocated), &[]); 97 cfg.use_program(&pio.load_program(&prg.program), &[]);
102 cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed(); 98 cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed();
103 sm.set_config(&cfg); 99 sm.set_config(&cfg);
104} 100}
diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs
index 9ab72e1f3..86e5017ac 100644
--- a/examples/rp/src/bin/pio_dma.rs
+++ b/examples/rp/src/bin/pio_dma.rs
@@ -8,7 +8,6 @@ use embassy_executor::Spawner;
8use embassy_futures::join::join; 8use embassy_futures::join::join;
9use embassy_rp::peripherals::PIO0; 9use embassy_rp::peripherals::PIO0;
10use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; 10use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection};
11use embassy_rp::relocate::RelocatedProgram;
12use embassy_rp::{bind_interrupts, Peripheral}; 11use embassy_rp::{bind_interrupts, Peripheral};
13use fixed::traits::ToFixed; 12use fixed::traits::ToFixed;
14use fixed_macro::types::U56F8; 13use fixed_macro::types::U56F8;
@@ -46,9 +45,8 @@ async fn main(_spawner: Spawner) {
46 ".wrap", 45 ".wrap",
47 ); 46 );
48 47
49 let relocated = RelocatedProgram::new(&prg.program);
50 let mut cfg = Config::default(); 48 let mut cfg = Config::default();
51 cfg.use_program(&common.load_program(&relocated), &[]); 49 cfg.use_program(&common.load_program(&prg.program), &[]);
52 cfg.clock_divider = (U56F8!(125_000_000) / U56F8!(10_000)).to_fixed(); 50 cfg.clock_divider = (U56F8!(125_000_000) / U56F8!(10_000)).to_fixed();
53 cfg.shift_in = ShiftConfig { 51 cfg.shift_in = ShiftConfig {
54 auto_fill: true, 52 auto_fill: true,
diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs
index 8aedd24b6..d80c5c24b 100644
--- a/examples/rp/src/bin/pio_hd44780.rs
+++ b/examples/rp/src/bin/pio_hd44780.rs
@@ -14,7 +14,6 @@ use embassy_rp::pio::{
14 Config, Direction, FifoJoin, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine, 14 Config, Direction, FifoJoin, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine,
15}; 15};
16use embassy_rp::pwm::{self, Pwm}; 16use embassy_rp::pwm::{self, Pwm};
17use embassy_rp::relocate::RelocatedProgram;
18use embassy_rp::{bind_interrupts, into_ref, Peripheral, PeripheralRef}; 17use embassy_rp::{bind_interrupts, into_ref, Peripheral, PeripheralRef};
19use embassy_time::{Duration, Instant, Timer}; 18use embassy_time::{Duration, Instant, Timer};
20use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
@@ -127,9 +126,8 @@ impl<'l> HD44780<'l> {
127 126
128 sm0.set_pin_dirs(Direction::Out, &[&rs, &rw, &e, &db4, &db5, &db6, &db7]); 127 sm0.set_pin_dirs(Direction::Out, &[&rs, &rw, &e, &db4, &db5, &db6, &db7]);
129 128
130 let relocated = RelocatedProgram::new(&prg.program);
131 let mut cfg = Config::default(); 129 let mut cfg = Config::default();
132 cfg.use_program(&common.load_program(&relocated), &[&e]); 130 cfg.use_program(&common.load_program(&prg.program), &[&e]);
133 cfg.clock_divider = 125u8.into(); 131 cfg.clock_divider = 125u8.into();
134 cfg.set_out_pins(&[&db4, &db5, &db6, &db7]); 132 cfg.set_out_pins(&[&db4, &db5, &db6, &db7]);
135 cfg.shift_out = ShiftConfig { 133 cfg.shift_out = ShiftConfig {
@@ -201,9 +199,8 @@ impl<'l> HD44780<'l> {
201 "# 199 "#
202 ); 200 );
203 201
204 let relocated = RelocatedProgram::new(&prg.program);
205 let mut cfg = Config::default(); 202 let mut cfg = Config::default();
206 cfg.use_program(&common.load_program(&relocated), &[&e]); 203 cfg.use_program(&common.load_program(&prg.program), &[&e]);
207 cfg.clock_divider = 8u8.into(); // ~64ns/insn 204 cfg.clock_divider = 8u8.into(); // ~64ns/insn
208 cfg.set_jmp_pin(&db7); 205 cfg.set_jmp_pin(&db7);
209 cfg.set_set_pins(&[&rs, &rw]); 206 cfg.set_set_pins(&[&rs, &rw]);
diff --git a/examples/rp/src/bin/pio_uart.rs b/examples/rp/src/bin/pio_uart.rs
new file mode 100644
index 000000000..4c382c2ee
--- /dev/null
+++ b/examples/rp/src/bin/pio_uart.rs
@@ -0,0 +1,394 @@
1//! This example shows how to use the PIO module in the RP2040 chip to implement a duplex UART.
2//! The PIO module is a very powerful peripheral that can be used to implement many different
3//! protocols. It is a very flexible state machine that can be programmed to do almost anything.
4//!
5//! This example opens up a USB device that implements a CDC ACM serial port. It then uses the
6//! PIO module to implement a UART that is connected to the USB serial port. This allows you to
7//! communicate with a device connected to the RP2040 over USB serial.
8
9#![no_std]
10#![no_main]
11#![feature(type_alias_impl_trait)]
12#![feature(async_fn_in_trait)]
13
14use defmt::{info, panic, trace};
15use embassy_executor::Spawner;
16use embassy_futures::join::{join, join3};
17use embassy_rp::bind_interrupts;
18use embassy_rp::peripherals::{PIO0, USB};
19use embassy_rp::pio::InterruptHandler as PioInterruptHandler;
20use embassy_rp::usb::{Driver, Instance, InterruptHandler};
21use embassy_sync::blocking_mutex::raw::NoopRawMutex;
22use embassy_sync::pipe::Pipe;
23use embassy_usb::class::cdc_acm::{CdcAcmClass, Receiver, Sender, State};
24use embassy_usb::driver::EndpointError;
25use embassy_usb::{Builder, Config};
26use embedded_io::asynch::{Read, Write};
27use {defmt_rtt as _, panic_probe as _};
28
29use crate::uart::PioUart;
30use crate::uart_rx::PioUartRx;
31use crate::uart_tx::PioUartTx;
32
33bind_interrupts!(struct Irqs {
34 USBCTRL_IRQ => InterruptHandler<USB>;
35 PIO0_IRQ_0 => PioInterruptHandler<PIO0>;
36});
37
38#[embassy_executor::main]
39async fn main(_spawner: Spawner) {
40 info!("Hello there!");
41
42 let p = embassy_rp::init(Default::default());
43
44 // Create the driver, from the HAL.
45 let driver = Driver::new(p.USB, Irqs);
46
47 // Create embassy-usb Config
48 let mut config = Config::new(0xc0de, 0xcafe);
49 config.manufacturer = Some("Embassy");
50 config.product = Some("PIO UART example");
51 config.serial_number = Some("12345678");
52 config.max_power = 100;
53 config.max_packet_size_0 = 64;
54
55 // Required for windows compatibility.
56 // https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_CDC_ACM_IAD.html#help
57 config.device_class = 0xEF;
58 config.device_sub_class = 0x02;
59 config.device_protocol = 0x01;
60 config.composite_with_iads = true;
61
62 // Create embassy-usb DeviceBuilder using the driver and config.
63 // It needs some buffers for building the descriptors.
64 let mut device_descriptor = [0; 256];
65 let mut config_descriptor = [0; 256];
66 let mut bos_descriptor = [0; 256];
67 let mut control_buf = [0; 64];
68
69 let mut state = State::new();
70
71 let mut builder = Builder::new(
72 driver,
73 config,
74 &mut device_descriptor,
75 &mut config_descriptor,
76 &mut bos_descriptor,
77 &mut control_buf,
78 );
79
80 // Create classes on the builder.
81 let class = CdcAcmClass::new(&mut builder, &mut state, 64);
82
83 // Build the builder.
84 let mut usb = builder.build();
85
86 // Run the USB device.
87 let usb_fut = usb.run();
88
89 // PIO UART setup
90 let uart = PioUart::new(9600, p.PIO0, p.PIN_4, p.PIN_5);
91 let (mut uart_tx, mut uart_rx) = uart.split();
92
93 // Pipe setup
94 let usb_pipe: Pipe<NoopRawMutex, 20> = Pipe::new();
95 let mut usb_pipe_writer = usb_pipe.writer();
96 let mut usb_pipe_reader = usb_pipe.reader();
97
98 let uart_pipe: Pipe<NoopRawMutex, 20> = Pipe::new();
99 let mut uart_pipe_writer = uart_pipe.writer();
100 let mut uart_pipe_reader = uart_pipe.reader();
101
102 let (mut usb_tx, mut usb_rx) = class.split();
103
104 // Read + write from USB
105 let usb_future = async {
106 loop {
107 info!("Wait for USB connection");
108 usb_rx.wait_connection().await;
109 info!("Connected");
110 let _ = join(
111 usb_read(&mut usb_rx, &mut uart_pipe_writer),
112 usb_write(&mut usb_tx, &mut usb_pipe_reader),
113 )
114 .await;
115 info!("Disconnected");
116 }
117 };
118
119 // Read + write from UART
120 let uart_future = join(
121 uart_read(&mut uart_rx, &mut usb_pipe_writer),
122 uart_write(&mut uart_tx, &mut uart_pipe_reader),
123 );
124
125 // Run everything concurrently.
126 // If we had made everything `'static` above instead, we could do this using separate tasks instead.
127 join3(usb_fut, usb_future, uart_future).await;
128}
129
130struct Disconnected {}
131
132impl From<EndpointError> for Disconnected {
133 fn from(val: EndpointError) -> Self {
134 match val {
135 EndpointError::BufferOverflow => panic!("Buffer overflow"),
136 EndpointError::Disabled => Disconnected {},
137 }
138 }
139}
140
141/// Read from the USB and write it to the UART TX pipe
142async fn usb_read<'d, T: Instance + 'd>(
143 usb_rx: &mut Receiver<'d, Driver<'d, T>>,
144 uart_pipe_writer: &mut embassy_sync::pipe::Writer<'_, NoopRawMutex, 20>,
145) -> Result<(), Disconnected> {
146 let mut buf = [0; 64];
147 loop {
148 let n = usb_rx.read_packet(&mut buf).await?;
149 let data = &buf[..n];
150 trace!("USB IN: {:x}", data);
151 uart_pipe_writer.write(data).await;
152 }
153}
154
155/// Read from the USB TX pipe and write it to the USB
156async fn usb_write<'d, T: Instance + 'd>(
157 usb_tx: &mut Sender<'d, Driver<'d, T>>,
158 usb_pipe_reader: &mut embassy_sync::pipe::Reader<'_, NoopRawMutex, 20>,
159) -> Result<(), Disconnected> {
160 let mut buf = [0; 64];
161 loop {
162 let n = usb_pipe_reader.read(&mut buf).await;
163 let data = &buf[..n];
164 trace!("USB OUT: {:x}", data);
165 usb_tx.write_packet(&data).await?;
166 }
167}
168
169/// Read from the UART and write it to the USB TX pipe
170async fn uart_read(
171 uart_rx: &mut PioUartRx<'_>,
172 usb_pipe_writer: &mut embassy_sync::pipe::Writer<'_, NoopRawMutex, 20>,
173) -> ! {
174 let mut buf = [0; 64];
175 loop {
176 let n = uart_rx.read(&mut buf).await.expect("UART read error");
177 if n == 0 {
178 continue;
179 }
180 let data = &buf[..n];
181 trace!("UART IN: {:x}", buf);
182 usb_pipe_writer.write(data).await;
183 }
184}
185
186/// Read from the UART TX pipe and write it to the UART
187async fn uart_write(
188 uart_tx: &mut PioUartTx<'_>,
189 uart_pipe_reader: &mut embassy_sync::pipe::Reader<'_, NoopRawMutex, 20>,
190) -> ! {
191 let mut buf = [0; 64];
192 loop {
193 let n = uart_pipe_reader.read(&mut buf).await;
194 let data = &buf[..n];
195 trace!("UART OUT: {:x}", data);
196 let _ = uart_tx.write(&data).await;
197 }
198}
199
200mod uart {
201 use embassy_rp::peripherals::PIO0;
202 use embassy_rp::pio::{Pio, PioPin};
203 use embassy_rp::Peripheral;
204
205 use crate::uart_rx::PioUartRx;
206 use crate::uart_tx::PioUartTx;
207 use crate::Irqs;
208
209 pub struct PioUart<'a> {
210 tx: PioUartTx<'a>,
211 rx: PioUartRx<'a>,
212 }
213
214 impl<'a> PioUart<'a> {
215 pub fn new(
216 baud: u64,
217 pio: impl Peripheral<P = PIO0> + 'a,
218 tx_pin: impl PioPin,
219 rx_pin: impl PioPin,
220 ) -> PioUart<'a> {
221 let Pio {
222 mut common, sm0, sm1, ..
223 } = Pio::new(pio, Irqs);
224
225 let tx = PioUartTx::new(&mut common, sm0, tx_pin, baud);
226 let rx = PioUartRx::new(&mut common, sm1, rx_pin, baud);
227
228 PioUart { tx, rx }
229 }
230
231 pub fn split(self) -> (PioUartTx<'a>, PioUartRx<'a>) {
232 (self.tx, self.rx)
233 }
234 }
235}
236
237mod uart_tx {
238 use core::convert::Infallible;
239
240 use embassy_rp::gpio::Level;
241 use embassy_rp::peripherals::PIO0;
242 use embassy_rp::pio::{Common, Config, Direction, FifoJoin, PioPin, ShiftDirection, StateMachine};
243 use embedded_io::asynch::Write;
244 use embedded_io::Io;
245 use fixed::traits::ToFixed;
246 use fixed_macro::types::U56F8;
247
248 pub struct PioUartTx<'a> {
249 sm_tx: StateMachine<'a, PIO0, 0>,
250 }
251
252 impl<'a> PioUartTx<'a> {
253 pub fn new(
254 common: &mut Common<'a, PIO0>,
255 mut sm_tx: StateMachine<'a, PIO0, 0>,
256 tx_pin: impl PioPin,
257 baud: u64,
258 ) -> Self {
259 let prg = pio_proc::pio_asm!(
260 r#"
261 .side_set 1 opt
262
263 ; An 8n1 UART transmit program.
264 ; OUT pin 0 and side-set pin 0 are both mapped to UART TX pin.
265
266 pull side 1 [7] ; Assert stop bit, or stall with line in idle state
267 set x, 7 side 0 [7] ; Preload bit counter, assert start bit for 8 clocks
268 bitloop: ; This loop will run 8 times (8n1 UART)
269 out pins, 1 ; Shift 1 bit from OSR to the first OUT pin
270 jmp x-- bitloop [6] ; Each loop iteration is 8 cycles.
271 "#
272 );
273 let tx_pin = common.make_pio_pin(tx_pin);
274 sm_tx.set_pins(Level::High, &[&tx_pin]);
275 sm_tx.set_pin_dirs(Direction::Out, &[&tx_pin]);
276
277 let mut cfg = Config::default();
278
279 cfg.set_out_pins(&[&tx_pin]);
280 cfg.use_program(&common.load_program(&prg.program), &[&tx_pin]);
281 cfg.shift_out.auto_fill = false;
282 cfg.shift_out.direction = ShiftDirection::Right;
283 cfg.fifo_join = FifoJoin::TxOnly;
284 cfg.clock_divider = (U56F8!(125_000_000) / (8 * baud)).to_fixed();
285 sm_tx.set_config(&cfg);
286 sm_tx.set_enable(true);
287
288 Self { sm_tx }
289 }
290
291 pub async fn write_u8(&mut self, data: u8) {
292 self.sm_tx.tx().wait_push(data as u32).await;
293 }
294 }
295
296 impl Io for PioUartTx<'_> {
297 type Error = Infallible;
298 }
299
300 impl Write for PioUartTx<'_> {
301 async fn write(&mut self, buf: &[u8]) -> Result<usize, Infallible> {
302 for byte in buf {
303 self.write_u8(*byte).await;
304 }
305 Ok(buf.len())
306 }
307 }
308}
309
310mod uart_rx {
311 use core::convert::Infallible;
312
313 use embassy_rp::gpio::Level;
314 use embassy_rp::peripherals::PIO0;
315 use embassy_rp::pio::{Common, Config, Direction, FifoJoin, PioPin, ShiftDirection, StateMachine};
316 use embedded_io::asynch::Read;
317 use embedded_io::Io;
318 use fixed::traits::ToFixed;
319 use fixed_macro::types::U56F8;
320
321 pub struct PioUartRx<'a> {
322 sm_rx: StateMachine<'a, PIO0, 1>,
323 }
324
325 impl<'a> PioUartRx<'a> {
326 pub fn new(
327 common: &mut Common<'a, PIO0>,
328 mut sm_rx: StateMachine<'a, PIO0, 1>,
329 rx_pin: impl PioPin,
330 baud: u64,
331 ) -> Self {
332 let prg = pio_proc::pio_asm!(
333 r#"
334 ; Slightly more fleshed-out 8n1 UART receiver which handles framing errors and
335 ; break conditions more gracefully.
336 ; IN pin 0 and JMP pin are both mapped to the GPIO used as UART RX.
337
338 start:
339 wait 0 pin 0 ; Stall until start bit is asserted
340 set x, 7 [10] ; Preload bit counter, then delay until halfway through
341 rx_bitloop: ; the first data bit (12 cycles incl wait, set).
342 in pins, 1 ; Shift data bit into ISR
343 jmp x-- rx_bitloop [6] ; Loop 8 times, each loop iteration is 8 cycles
344 jmp pin good_rx_stop ; Check stop bit (should be high)
345
346 irq 4 rel ; Either a framing error or a break. Set a sticky flag,
347 wait 1 pin 0 ; and wait for line to return to idle state.
348 jmp start ; Don't push data if we didn't see good framing.
349
350 good_rx_stop: ; No delay before returning to start; a little slack is
351 in null 24
352 push ; important in case the TX clock is slightly too fast.
353 "#
354 );
355 let mut cfg = Config::default();
356 cfg.use_program(&common.load_program(&prg.program), &[]);
357
358 let rx_pin = common.make_pio_pin(rx_pin);
359 sm_rx.set_pins(Level::High, &[&rx_pin]);
360 cfg.set_in_pins(&[&rx_pin]);
361 cfg.set_jmp_pin(&rx_pin);
362 sm_rx.set_pin_dirs(Direction::In, &[&rx_pin]);
363
364 cfg.clock_divider = (U56F8!(125_000_000) / (8 * baud)).to_fixed();
365 cfg.shift_in.auto_fill = false;
366 cfg.shift_in.direction = ShiftDirection::Right;
367 cfg.shift_in.threshold = 32;
368 cfg.fifo_join = FifoJoin::RxOnly;
369 sm_rx.set_config(&cfg);
370 sm_rx.set_enable(true);
371
372 Self { sm_rx }
373 }
374
375 pub async fn read_u8(&mut self) -> u8 {
376 self.sm_rx.rx().wait_pull().await as u8
377 }
378 }
379
380 impl Io for PioUartRx<'_> {
381 type Error = Infallible;
382 }
383
384 impl Read for PioUartRx<'_> {
385 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Infallible> {
386 let mut i = 0;
387 while i < buf.len() {
388 buf[i] = self.read_u8().await;
389 i += 1;
390 }
391 Ok(i)
392 }
393 }
394}
diff --git a/examples/rp/src/bin/pio_ws2812.rs b/examples/rp/src/bin/pio_ws2812.rs
index 3de2bd48d..bc87016ec 100644
--- a/examples/rp/src/bin/pio_ws2812.rs
+++ b/examples/rp/src/bin/pio_ws2812.rs
@@ -12,7 +12,6 @@ use embassy_rp::peripherals::PIO0;
12use embassy_rp::pio::{ 12use embassy_rp::pio::{
13 Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine, 13 Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine,
14}; 14};
15use embassy_rp::relocate::RelocatedProgram;
16use embassy_rp::{bind_interrupts, clocks, into_ref, Peripheral, PeripheralRef}; 15use embassy_rp::{bind_interrupts, clocks, into_ref, Peripheral, PeripheralRef};
17use embassy_time::{Duration, Timer}; 16use embassy_time::{Duration, Timer};
18use fixed::types::U24F8; 17use fixed::types::U24F8;
@@ -73,8 +72,7 @@ impl<'d, P: Instance, const S: usize, const N: usize> Ws2812<'d, P, S, N> {
73 cfg.set_out_pins(&[&out_pin]); 72 cfg.set_out_pins(&[&out_pin]);
74 cfg.set_set_pins(&[&out_pin]); 73 cfg.set_set_pins(&[&out_pin]);
75 74
76 let relocated = RelocatedProgram::new(&prg); 75 cfg.use_program(&pio.load_program(&prg), &[&out_pin]);
77 cfg.use_program(&pio.load_program(&relocated), &[&out_pin]);
78 76
79 // Clock config, measured in kHz to avoid overflows 77 // Clock config, measured in kHz to avoid overflows
80 // TODO CLOCK_FREQ should come from embassy_rp 78 // TODO CLOCK_FREQ should come from embassy_rp
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml
index 92933ab50..42adede10 100644
--- a/examples/std/Cargo.toml
+++ b/examples/std/Cargo.toml
@@ -23,3 +23,6 @@ clap = { version = "3.0.0-beta.5", features = ["derive"] }
23rand_core = { version = "0.6.3", features = ["std"] } 23rand_core = { version = "0.6.3", features = ["std"] }
24heapless = { version = "0.7.5", default-features = false } 24heapless = { version = "0.7.5", default-features = false }
25static_cell = { version = "1.1", features = ["nightly"]} 25static_cell = { version = "1.1", features = ["nightly"]}
26
27[profile.release]
28debug = 2
diff --git a/examples/stm32c0/Cargo.toml b/examples/stm32c0/Cargo.toml
index e74c5357b..8534921ab 100644
--- a/examples/stm32c0/Cargo.toml
+++ b/examples/stm32c0/Cargo.toml
@@ -20,3 +20,6 @@ embedded-hal = "0.2.6"
20panic-probe = { version = "0.3", features = ["print-defmt"] } 20panic-probe = { version = "0.3", features = ["print-defmt"] }
21futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 21futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
22heapless = { version = "0.7.5", default-features = false } 22heapless = { version = "0.7.5", default-features = false }
23
24[profile.release]
25debug = 2
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml
index 620a139ae..46b6db45c 100644
--- a/examples/stm32f0/Cargo.toml
+++ b/examples/stm32f0/Cargo.toml
@@ -18,3 +18,6 @@ embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["de
18embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 18embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
19embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 19embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
20static_cell = { version = "1.1", features = ["nightly"]} 20static_cell = { version = "1.1", features = ["nightly"]}
21
22[profile.release]
23debug = 2
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml
index 8450c541f..5d32992cd 100644
--- a/examples/stm32f1/Cargo.toml
+++ b/examples/stm32f1/Cargo.toml
@@ -26,3 +26,6 @@ nb = "1.0.0"
26 26
27[profile.dev] 27[profile.dev]
28opt-level = "s" 28opt-level = "s"
29
30[profile.release]
31debug = 2
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml
index 147e2ecbf..9857fb631 100644
--- a/examples/stm32f2/Cargo.toml
+++ b/examples/stm32f2/Cargo.toml
@@ -21,3 +21,6 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
21futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 21futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
22heapless = { version = "0.7.5", default-features = false } 22heapless = { version = "0.7.5", default-features = false }
23nb = "1.0.0" 23nb = "1.0.0"
24
25[profile.release]
26debug = 2
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml
index 6ac5d57e9..bd594d16a 100644
--- a/examples/stm32f3/Cargo.toml
+++ b/examples/stm32f3/Cargo.toml
@@ -25,3 +25,6 @@ heapless = { version = "0.7.5", default-features = false }
25nb = "1.0.0" 25nb = "1.0.0"
26embedded-storage = "0.3.0" 26embedded-storage = "0.3.0"
27static_cell = { version = "1.1", features = ["nightly"]} 27static_cell = { version = "1.1", features = ["nightly"]}
28
29[profile.release]
30debug = 2
diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs
index 95b2b6865..a27c1d547 100644
--- a/examples/stm32f3/src/bin/spi_dma.rs
+++ b/examples/stm32f3/src/bin/spi_dma.rs
@@ -17,16 +17,10 @@ async fn main(_spawner: Spawner) {
17 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
18 info!("Hello World!"); 18 info!("Hello World!");
19 19
20 let mut spi = Spi::new( 20 let mut spi_config = Config::default();
21 p.SPI1, 21 spi_config.frequency = Hertz(1_000_000);
22 p.PB3, 22
23 p.PB5, 23 let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH2, spi_config);
24 p.PB4,
25 p.DMA1_CH3,
26 p.DMA1_CH2,
27 Hertz(1_000_000),
28 Config::default(),
29 );
30 24
31 for n in 0u32.. { 25 for n in 0u32.. {
32 let mut write: String<128> = String::new(); 26 let mut write: String<128> = String::new();
diff --git a/examples/stm32f334/.cargo/config.toml b/examples/stm32f334/.cargo/config.toml
new file mode 100644
index 000000000..caf947be6
--- /dev/null
+++ b/examples/stm32f334/.cargo/config.toml
@@ -0,0 +1,9 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-rs-cli chip list`
3runner = "probe-run --chip STM32F334R8"
4
5[build]
6target = "thumbv7em-none-eabihf"
7
8[env]
9DEFMT_LOG = "trace"
diff --git a/examples/stm32f334/Cargo.toml b/examples/stm32f334/Cargo.toml
new file mode 100644
index 000000000..6410891a1
--- /dev/null
+++ b/examples/stm32f334/Cargo.toml
@@ -0,0 +1,26 @@
1[package]
2edition = "2021"
3name = "embassy-stm32f3-examples"
4version = "0.1.0"
5license = "MIT OR Apache-2.0"
6
7[dependencies]
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
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"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f334r8", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
13embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
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"
20embedded-hal = "0.2.6"
21panic-probe = { version = "0.3", features = ["print-defmt"] }
22futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
23heapless = { version = "0.7.5", default-features = false }
24nb = "1.0.0"
25embedded-storage = "0.3.0"
26static_cell = { version = "1.1", features = ["nightly"]}
diff --git a/examples/stm32f334/build.rs b/examples/stm32f334/build.rs
new file mode 100644
index 000000000..8cd32d7ed
--- /dev/null
+++ b/examples/stm32f334/build.rs
@@ -0,0 +1,5 @@
1fn main() {
2 println!("cargo:rustc-link-arg-bins=--nmagic");
3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
5}
diff --git a/examples/stm32f334/src/bin/button.rs b/examples/stm32f334/src/bin/button.rs
new file mode 100644
index 000000000..599c0f27d
--- /dev/null
+++ b/examples/stm32f334/src/bin/button.rs
@@ -0,0 +1,27 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::gpio::{Level, Output, Speed};
8use embassy_time::{Duration, Timer};
9use {defmt_rtt as _, panic_probe as _};
10
11#[embassy_executor::main]
12async fn main(_spawner: Spawner) {
13 info!("Hello World!");
14
15 let p = embassy_stm32::init(Default::default());
16
17 let mut out1 = Output::new(p.PA8, Level::Low, Speed::High);
18
19 out1.set_high();
20 Timer::after(Duration::from_millis(500)).await;
21 out1.set_low();
22
23 Timer::after(Duration::from_millis(500)).await;
24 info!("end program");
25
26 cortex_m::asm::bkpt();
27}
diff --git a/examples/stm32f334/src/bin/hello.rs b/examples/stm32f334/src/bin/hello.rs
new file mode 100644
index 000000000..65773210d
--- /dev/null
+++ b/examples/stm32f334/src/bin/hello.rs
@@ -0,0 +1,23 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::info;
6use embassy_executor::Spawner;
7use embassy_stm32::time::Hertz;
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 config.rcc.hse = Some(Hertz(8_000_000));
16 config.rcc.sysclk = Some(Hertz(16_000_000));
17 let _p = embassy_stm32::init(config);
18
19 loop {
20 info!("Hello World!");
21 Timer::after(Duration::from_secs(1)).await;
22 }
23}
diff --git a/examples/stm32f334/src/bin/pwm.rs b/examples/stm32f334/src/bin/pwm.rs
new file mode 100644
index 000000000..2660b10c5
--- /dev/null
+++ b/examples/stm32f334/src/bin/pwm.rs
@@ -0,0 +1,71 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::hrtim::*;
8use embassy_stm32::time::{khz, mhz};
9use embassy_stm32::Config;
10use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
15 let mut config: Config = Default::default();
16 config.rcc.sysclk = Some(mhz(64));
17 config.rcc.hclk = Some(mhz(64));
18 config.rcc.pclk1 = Some(mhz(32));
19 config.rcc.pclk2 = Some(mhz(64));
20
21 let p = embassy_stm32::init(config);
22 info!("Hello World!");
23
24 let ch1 = PwmPin::new_cha(p.PA8);
25 let ch1n = ComplementaryPwmPin::new_cha(p.PA9);
26 let pwm = AdvancedPwm::new(
27 p.HRTIM1,
28 Some(ch1),
29 Some(ch1n),
30 None,
31 None,
32 None,
33 None,
34 None,
35 None,
36 None,
37 None,
38 );
39
40 info!("pwm constructed");
41
42 let mut buck_converter = BridgeConverter::new(pwm.ch_a, khz(5));
43
44 // embassy_stm32::pac::HRTIM1
45 // .tim(0)
46 // .setr(0)
47 // .modify(|w| w.set_sst(Activeeffect::SETACTIVE));
48 //
49 // Timer::after(Duration::from_millis(500)).await;
50 //
51 // embassy_stm32::pac::HRTIM1
52 // .tim(0)
53 // .rstr(0)
54 // .modify(|w| w.set_srt(Inactiveeffect::SETINACTIVE));
55
56 let max_duty = buck_converter.get_max_compare_value();
57
58 info!("max compare value: {}", max_duty);
59
60 buck_converter.set_dead_time(max_duty / 20);
61 buck_converter.set_primary_duty(max_duty / 2);
62 buck_converter.set_secondary_duty(3 * max_duty / 4);
63
64 buck_converter.start();
65
66 Timer::after(Duration::from_millis(500)).await;
67
68 info!("end program");
69
70 cortex_m::asm::bkpt();
71}
diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs
index d0b164393..496016687 100644
--- a/examples/stm32f4/src/bin/eth.rs
+++ b/examples/stm32f4/src/bin/eth.rs
@@ -11,13 +11,15 @@ use embassy_stm32::eth::{Ethernet, PacketQueue};
11use embassy_stm32::peripherals::ETH; 11use embassy_stm32::peripherals::ETH;
12use embassy_stm32::rng::Rng; 12use embassy_stm32::rng::Rng;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{bind_interrupts, eth, Config}; 14use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use static_cell::make_static; 17use static_cell::make_static;
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19
19bind_interrupts!(struct Irqs { 20bind_interrupts!(struct Irqs {
20 ETH => eth::InterruptHandler; 21 ETH => eth::InterruptHandler;
22 HASH_RNG => rng::InterruptHandler<peripherals::RNG>;
21}); 23});
22 24
23type Device = Ethernet<'static, ETH, GenericSMI>; 25type Device = Ethernet<'static, ETH, GenericSMI>;
@@ -36,7 +38,7 @@ async fn main(spawner: Spawner) -> ! {
36 info!("Hello World!"); 38 info!("Hello World!");
37 39
38 // Generate random seed. 40 // Generate random seed.
39 let mut rng = Rng::new(p.RNG); 41 let mut rng = Rng::new(p.RNG, Irqs);
40 let mut seed = [0; 8]; 42 let mut seed = [0; 8];
41 let _ = rng.async_fill_bytes(&mut seed).await; 43 let _ = rng.async_fill_bytes(&mut seed).await;
42 let seed = u64::from_le_bytes(seed); 44 let seed = u64::from_le_bytes(seed);
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs
index 7c5902052..1013a844e 100644
--- a/examples/stm32f4/src/bin/pwm.rs
+++ b/examples/stm32f4/src/bin/pwm.rs
@@ -4,9 +4,10 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; 7use embassy_stm32::gpio::OutputType;
8use embassy_stm32::pwm::Channel;
9use embassy_stm32::time::khz; 8use embassy_stm32::time::khz;
9use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
10use embassy_stm32::timer::Channel;
10use embassy_time::{Duration, Timer}; 11use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
12 13
@@ -15,7 +16,7 @@ async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default()); 16 let p = embassy_stm32::init(Default::default());
16 info!("Hello World!"); 17 info!("Hello World!");
17 18
18 let ch1 = PwmPin::new_ch1(p.PE9); 19 let ch1 = PwmPin::new_ch1(p.PE9, OutputType::PushPull);
19 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10)); 20 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10));
20 let max = pwm.get_max_duty(); 21 let max = pwm.get_max_duty();
21 pwm.enable(Channel::Ch1); 22 pwm.enable(Channel::Ch1);
diff --git a/examples/stm32f4/src/bin/pwm_complementary.rs b/examples/stm32f4/src/bin/pwm_complementary.rs
index a8a68ed6e..83a3c7537 100644
--- a/examples/stm32f4/src/bin/pwm_complementary.rs
+++ b/examples/stm32f4/src/bin/pwm_complementary.rs
@@ -4,10 +4,11 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::pwm::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin}; 7use embassy_stm32::gpio::OutputType;
8use embassy_stm32::pwm::simple_pwm::PwmPin;
9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::khz; 8use embassy_stm32::time::khz;
9use embassy_stm32::timer::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin};
10use embassy_stm32::timer::simple_pwm::PwmPin;
11use embassy_stm32::timer::Channel;
11use embassy_time::{Duration, Timer}; 12use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
13 14
@@ -16,8 +17,8 @@ async fn main(_spawner: Spawner) {
16 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
17 info!("Hello World!"); 18 info!("Hello World!");
18 19
19 let ch1 = PwmPin::new_ch1(p.PE9); 20 let ch1 = PwmPin::new_ch1(p.PE9, OutputType::PushPull);
20 let ch1n = ComplementaryPwmPin::new_ch1(p.PA7); 21 let ch1n = ComplementaryPwmPin::new_ch1(p.PA7, OutputType::PushPull);
21 let mut pwm = ComplementaryPwm::new( 22 let mut pwm = ComplementaryPwm::new(
22 p.TIM1, 23 p.TIM1,
23 Some(ch1), 24 Some(ch1),
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index 05b48f478..0919e9874 100644
--- a/examples/stm32f4/src/bin/spi.rs
+++ b/examples/stm32f4/src/bin/spi.rs
@@ -16,16 +16,10 @@ fn main() -> ! {
16 16
17 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
18 18
19 let mut spi = Spi::new( 19 let mut spi_config = Config::default();
20 p.SPI3, 20 spi_config.frequency = Hertz(1_000_000);
21 p.PC10, 21
22 p.PC12, 22 let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
23 p.PC11,
24 NoDma,
25 NoDma,
26 Hertz(1_000_000),
27 Config::default(),
28 );
29 23
30 let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh); 24 let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
31 25
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs
index 3d2a1a1ae..f291f7dba 100644
--- a/examples/stm32f4/src/bin/spi_dma.rs
+++ b/examples/stm32f4/src/bin/spi_dma.rs
@@ -17,16 +17,10 @@ async fn main(_spawner: Spawner) {
17 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
18 info!("Hello World!"); 18 info!("Hello World!");
19 19
20 let mut spi = Spi::new( 20 let mut spi_config = Config::default();
21 p.SPI1, 21 spi_config.frequency = Hertz(1_000_000);
22 p.PB3, 22
23 p.PB5, 23 let mut spi = Spi::new(p.SPI1, p.PB3, p.PB5, p.PB4, p.DMA2_CH3, p.DMA2_CH2, spi_config);
24 p.PB4,
25 p.DMA2_CH3,
26 p.DMA2_CH2,
27 Hertz(1_000_000),
28 Config::default(),
29 );
30 24
31 for n in 0u32.. { 25 for n in 0u32.. {
32 let mut write: String<128> = String::new(); 26 let mut write: String<128> = String::new();
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs
index b1f01417c..740d3018e 100644
--- a/examples/stm32f4/src/bin/usb_ethernet.rs
+++ b/examples/stm32f4/src/bin/usb_ethernet.rs
@@ -6,7 +6,7 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_net::tcp::TcpSocket; 7use embassy_net::tcp::TcpSocket;
8use embassy_net::{Stack, StackResources}; 8use embassy_net::{Stack, StackResources};
9use embassy_stm32::rng::Rng; 9use embassy_stm32::rng::{self, Rng};
10use embassy_stm32::time::mhz; 10use embassy_stm32::time::mhz;
11use embassy_stm32::usb_otg::Driver; 11use embassy_stm32::usb_otg::Driver;
12use embassy_stm32::{bind_interrupts, peripherals, usb_otg, Config}; 12use embassy_stm32::{bind_interrupts, peripherals, usb_otg, Config};
@@ -38,6 +38,7 @@ async fn net_task(stack: &'static Stack<Device<'static, MTU>>) -> ! {
38 38
39bind_interrupts!(struct Irqs { 39bind_interrupts!(struct Irqs {
40 OTG_FS => usb_otg::InterruptHandler<peripherals::USB_OTG_FS>; 40 OTG_FS => usb_otg::InterruptHandler<peripherals::USB_OTG_FS>;
41 HASH_RNG => rng::InterruptHandler<peripherals::RNG>;
41}); 42});
42 43
43#[embassy_executor::main] 44#[embassy_executor::main]
@@ -104,7 +105,7 @@ async fn main(spawner: Spawner) {
104 //}); 105 //});
105 106
106 // Generate random seed 107 // Generate random seed
107 let mut rng = Rng::new(p.RNG); 108 let mut rng = Rng::new(p.RNG, Irqs);
108 let mut seed = [0; 8]; 109 let mut seed = [0; 8];
109 unwrap!(rng.async_fill_bytes(&mut seed).await); 110 unwrap!(rng.async_fill_bytes(&mut seed).await);
110 let seed = u64::from_le_bytes(seed); 111 let seed = u64::from_le_bytes(seed);
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml
index bbc99fee0..a379cbbe3 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]
8# Change stm32f767zi to your chip name, if necessary. 8# Change stm32f767zi to your chip name, if necessary.
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } 9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] }
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 = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
@@ -28,3 +28,6 @@ rand_core = "0.6.3"
28critical-section = "1.1" 28critical-section = "1.1"
29embedded-storage = "0.3.0" 29embedded-storage = "0.3.0"
30static_cell = { version = "1.1", features = ["nightly"]} 30static_cell = { version = "1.1", features = ["nightly"]}
31
32[profile.release]
33debug = 2
diff --git a/examples/stm32f7/build.rs b/examples/stm32f7/build.rs
index 2b5d412a9..8cd32d7ed 100644
--- a/examples/stm32f7/build.rs
+++ b/examples/stm32f7/build.rs
@@ -1,43 +1,5 @@
1//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs 1fn main() {
2use std::fs::File;
3use std::io::prelude::*;
4use std::path::PathBuf;
5use std::{env, io};
6
7#[derive(Debug)]
8enum Error {
9 Env(env::VarError),
10 Io(io::Error),
11}
12
13impl From<env::VarError> for Error {
14 fn from(error: env::VarError) -> Self {
15 Self::Env(error)
16 }
17}
18
19impl From<io::Error> for Error {
20 fn from(error: io::Error) -> Self {
21 Self::Io(error)
22 }
23}
24
25fn main() -> Result<(), Error> {
26 println!("cargo:rerun-if-changed=build.rs");
27 println!("cargo:rerun-if-changed=memory.x");
28
29 let out_dir = env::var("OUT_DIR")?;
30 let out_dir = PathBuf::from(out_dir);
31
32 let memory_x = include_bytes!("memory.x").as_ref();
33 File::create(out_dir.join("memory.x"))?.write_all(memory_x)?;
34
35 // Tell Cargo where to find the file.
36 println!("cargo:rustc-link-search={}", out_dir.display());
37
38 println!("cargo:rustc-link-arg-bins=--nmagic"); 2 println!("cargo:rustc-link-arg-bins=--nmagic");
39 println!("cargo:rustc-link-arg-bins=-Tlink.x"); 3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
40 println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); 4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
41
42 Ok(())
43} 5}
diff --git a/examples/stm32f7/memory.x b/examples/stm32f7/memory.x
deleted file mode 100644
index 899f7a4b8..000000000
--- a/examples/stm32f7/memory.x
+++ /dev/null
@@ -1,12 +0,0 @@
1/* For STM32F765,767,768,769,777,778,779 devices */
2MEMORY
3{
4 /* NOTE K = KiBi = 1024 bytes */
5 FLASH : ORIGIN = 0x08000000, LENGTH = 2M
6 RAM : ORIGIN = 0x20000000, LENGTH = 368K + 16K
7}
8
9/* This is where the call stack will be allocated. */
10/* The stack is of the full descending type. */
11/* NOTE Do NOT modify `_stack_start` unless you know what you are doing */
12_stack_start = ORIGIN(RAM) + LENGTH(RAM);
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs
index c6b2ba45c..e5abf52bc 100644
--- a/examples/stm32f7/src/bin/eth.rs
+++ b/examples/stm32f7/src/bin/eth.rs
@@ -11,14 +11,16 @@ use embassy_stm32::eth::{Ethernet, PacketQueue};
11use embassy_stm32::peripherals::ETH; 11use embassy_stm32::peripherals::ETH;
12use embassy_stm32::rng::Rng; 12use embassy_stm32::rng::Rng;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{bind_interrupts, eth, Config}; 14use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use rand_core::RngCore; 17use rand_core::RngCore;
18use static_cell::make_static; 18use static_cell::make_static;
19use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
20
20bind_interrupts!(struct Irqs { 21bind_interrupts!(struct Irqs {
21 ETH => eth::InterruptHandler; 22 ETH => eth::InterruptHandler;
23 RNG => rng::InterruptHandler<peripherals::RNG>;
22}); 24});
23 25
24type Device = Ethernet<'static, ETH, GenericSMI>; 26type Device = Ethernet<'static, ETH, GenericSMI>;
@@ -37,7 +39,7 @@ async fn main(spawner: Spawner) -> ! {
37 info!("Hello World!"); 39 info!("Hello World!");
38 40
39 // Generate random seed. 41 // Generate random seed.
40 let mut rng = Rng::new(p.RNG); 42 let mut rng = Rng::new(p.RNG, Irqs);
41 let mut seed = [0; 8]; 43 let mut seed = [0; 8];
42 rng.fill_bytes(&mut seed); 44 rng.fill_bytes(&mut seed);
43 let seed = u64::from_le_bytes(seed); 45 let seed = u64::from_le_bytes(seed);
diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml
index 4a14568ac..b4dfe3c6b 100644
--- a/examples/stm32g0/Cargo.toml
+++ b/examples/stm32g0/Cargo.toml
@@ -20,3 +20,6 @@ embedded-hal = "0.2.6"
20panic-probe = { version = "0.3", features = ["print-defmt"] } 20panic-probe = { version = "0.3", features = ["print-defmt"] }
21futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 21futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
22heapless = { version = "0.7.5", default-features = false } 22heapless = { version = "0.7.5", default-features = false }
23
24[profile.release]
25debug = 2
diff --git a/examples/stm32g0/src/bin/spi_neopixel.rs b/examples/stm32g0/src/bin/spi_neopixel.rs
index 81fdd15cb..ee7aaf33f 100644
--- a/examples/stm32g0/src/bin/spi_neopixel.rs
+++ b/examples/stm32g0/src/bin/spi_neopixel.rs
@@ -76,7 +76,9 @@ async fn main(_spawner: Spawner) {
76 let p = embassy_stm32::init(Default::default()); 76 let p = embassy_stm32::init(Default::default());
77 info!("Start test using spi as neopixel driver"); 77 info!("Start test using spi as neopixel driver");
78 78
79 let mut spi = Spi::new_txonly_nosck(p.SPI1, p.PB5, p.DMA1_CH3, NoDma, Hertz(4_000_000), Config::default()); 79 let mut config = Config::default();
80 config.frequency = Hertz(4_000_000);
81 let mut spi = Spi::new_txonly_nosck(p.SPI1, p.PB5, p.DMA1_CH3, NoDma, config);
80 82
81 let mut neopixels = Ws2812::new(); 83 let mut neopixels = Ws2812::new();
82 84
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml
index 935997a74..cf3e2ce9b 100644
--- a/examples/stm32g4/Cargo.toml
+++ b/examples/stm32g4/Cargo.toml
@@ -10,7 +10,6 @@ embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["
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 = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
13embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
14embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
15 14
16defmt = "0.3" 15defmt = "0.3"
@@ -22,3 +21,6 @@ embedded-hal = "0.2.6"
22panic-probe = { version = "0.3", features = ["print-defmt"] } 21panic-probe = { version = "0.3", features = ["print-defmt"] }
23futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 22futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
24heapless = { version = "0.7.5", default-features = false } 23heapless = { version = "0.7.5", default-features = false }
24
25[profile.release]
26debug = 2
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs
index 8f7842ed7..01e9cb476 100644
--- a/examples/stm32g4/src/bin/pwm.rs
+++ b/examples/stm32g4/src/bin/pwm.rs
@@ -4,9 +4,10 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; 7use embassy_stm32::gpio::OutputType;
8use embassy_stm32::pwm::Channel;
9use embassy_stm32::time::khz; 8use embassy_stm32::time::khz;
9use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
10use embassy_stm32::timer::Channel;
10use embassy_time::{Duration, Timer}; 11use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
12 13
@@ -15,7 +16,7 @@ async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default()); 16 let p = embassy_stm32::init(Default::default());
16 info!("Hello World!"); 17 info!("Hello World!");
17 18
18 let ch1 = PwmPin::new_ch1(p.PC0); 19 let ch1 = PwmPin::new_ch1(p.PC0, OutputType::PushPull);
19 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10)); 20 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10));
20 let max = pwm.get_max_duty(); 21 let max = pwm.get_max_duty();
21 pwm.enable(Channel::Ch1); 22 pwm.enable(Channel::Ch1);
diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml
index aebc795c1..51d3bad1f 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]
8# Change stm32h563zi to your chip name, if necessary. 8# Change stm32h563zi to your chip name, if necessary.
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } 9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "memory-x", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
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 = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
diff --git a/examples/stm32h5/memory.x b/examples/stm32h5/memory.x
deleted file mode 100644
index 456061509..000000000
--- a/examples/stm32h5/memory.x
+++ /dev/null
@@ -1,5 +0,0 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x08000000, LENGTH = 0x200000
4 RAM : ORIGIN = 0x20000000, LENGTH = 0x50000
5}
diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs
index 0bff85ed8..2aa2ab62b 100644
--- a/examples/stm32h5/src/bin/eth.rs
+++ b/examples/stm32h5/src/bin/eth.rs
@@ -12,14 +12,16 @@ use embassy_stm32::peripherals::ETH;
12use embassy_stm32::rcc::{AHBPrescaler, APBPrescaler, Hse, HseMode, Pll, PllSource, Sysclk, VoltageScale}; 12use embassy_stm32::rcc::{AHBPrescaler, APBPrescaler, Hse, HseMode, Pll, PllSource, Sysclk, VoltageScale};
13use embassy_stm32::rng::Rng; 13use embassy_stm32::rng::Rng;
14use embassy_stm32::time::Hertz; 14use embassy_stm32::time::Hertz;
15use embassy_stm32::{bind_interrupts, eth, Config}; 15use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config};
16use embassy_time::{Duration, Timer}; 16use embassy_time::{Duration, Timer};
17use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
18use rand_core::RngCore; 18use rand_core::RngCore;
19use static_cell::make_static; 19use static_cell::make_static;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21
21bind_interrupts!(struct Irqs { 22bind_interrupts!(struct Irqs {
22 ETH => eth::InterruptHandler; 23 ETH => eth::InterruptHandler;
24 RNG => rng::InterruptHandler<peripherals::RNG>;
23}); 25});
24 26
25type Device = Ethernet<'static, ETH, GenericSMI>; 27type Device = Ethernet<'static, ETH, GenericSMI>;
@@ -56,7 +58,7 @@ async fn main(spawner: Spawner) -> ! {
56 info!("Hello World!"); 58 info!("Hello World!");
57 59
58 // Generate random seed. 60 // Generate random seed.
59 let mut rng = Rng::new(p.RNG); 61 let mut rng = Rng::new(p.RNG, Irqs);
60 let mut seed = [0; 8]; 62 let mut seed = [0; 8];
61 rng.fill_bytes(&mut seed); 63 rng.fill_bytes(&mut seed);
62 let seed = u64::from_le_bytes(seed); 64 let seed = u64::from_le_bytes(seed);
diff --git a/examples/stm32h5/src/bin/rng.rs b/examples/stm32h5/src/bin/rng.rs
index af9be0b62..7c8c50eca 100644
--- a/examples/stm32h5/src/bin/rng.rs
+++ b/examples/stm32h5/src/bin/rng.rs
@@ -5,14 +5,19 @@
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rng::Rng; 7use embassy_stm32::rng::Rng;
8use embassy_stm32::{bind_interrupts, peripherals, rng};
8use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
9 10
11bind_interrupts!(struct Irqs {
12 RNG => rng::InterruptHandler<peripherals::RNG>;
13});
14
10#[embassy_executor::main] 15#[embassy_executor::main]
11async fn main(_spawner: Spawner) { 16async fn main(_spawner: Spawner) {
12 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
13 info!("Hello World!"); 18 info!("Hello World!");
14 19
15 let mut rng = Rng::new(p.RNG); 20 let mut rng = Rng::new(p.RNG, Irqs);
16 21
17 let mut buf = [0u8; 16]; 22 let mut buf = [0u8; 16];
18 unwrap!(rng.async_fill_bytes(&mut buf).await); 23 unwrap!(rng.async_fill_bytes(&mut buf).await);
diff --git a/examples/stm32h7/.cargo/config.toml b/examples/stm32h7/.cargo/config.toml
index 5f680dbce..4160bf855 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 run --chip STM32H743ZITx' 2runner = 'probe-rs run --chip STM32H7A3ZITxQ'
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 2d82c0d0d..3c1232e67 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]
8# Change stm32h743bi to your chip name, if necessary. 8# Change stm32h743bi to your chip name, if necessary.
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } 9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "memory-x", "unstable-pac", "unstable-traits"] }
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 = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
diff --git a/examples/stm32h7/memory.x b/examples/stm32h7/memory.x
deleted file mode 100644
index 026b14b9b..000000000
--- a/examples/stm32h7/memory.x
+++ /dev/null
@@ -1,5 +0,0 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x8000000, LENGTH = 1024K
4 RAM : ORIGIN = 0x24000000, LENGTH = 384K
5}
diff --git a/examples/stm32h7/src/bin/dac_dma.rs b/examples/stm32h7/src/bin/dac_dma.rs
new file mode 100644
index 000000000..a9cb5d1ed
--- /dev/null
+++ b/examples/stm32h7/src/bin/dac_dma.rs
@@ -0,0 +1,140 @@
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::{mhz, 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 mut config = embassy_stm32::Config::default();
25 config.rcc.sys_ck = Some(mhz(400));
26 config.rcc.hclk = Some(mhz(100));
27 config.rcc.pll1.q_ck = Some(mhz(100));
28
29 // Initialize the board and obtain a Peripherals instance
30 let p: embassy_stm32::Peripherals = embassy_stm32::init(config);
31
32 // Obtain two independent channels (p.DAC1 can only be consumed once, though!)
33 let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC1, p.DMA1_CH3, p.DMA1_CH4, p.PA4, p.PA5).split();
34
35 spawner.spawn(dac_task1(dac_ch1)).ok();
36 spawner.spawn(dac_task2(dac_ch2)).ok();
37}
38
39#[embassy_executor::task]
40async fn dac_task1(mut dac: Dac1Type) {
41 let data: &[u8; 256] = &calculate_array::<256>();
42
43 info!("TIM6 frequency is {}", TIM6::frequency());
44 const FREQUENCY: Hertz = Hertz::hz(200);
45
46 // Compute the reload value such that we obtain the FREQUENCY for the sine
47 let reload: u32 = (TIM6::frequency().0 / FREQUENCY.0) / data.len() as u32;
48
49 // Depends on your clock and on the specific chip used, you may need higher or lower values here
50 if reload < 10 {
51 error!("Reload value {} below threshold!", reload);
52 }
53
54 dac.select_trigger(embassy_stm32::dac::Ch1Trigger::Tim6).unwrap();
55 dac.enable_channel().unwrap();
56
57 TIM6::enable();
58 TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1));
59 TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE));
60 TIM6::regs().cr1().modify(|w| {
61 w.set_opm(Opm::DISABLED);
62 w.set_cen(true);
63 });
64
65 debug!(
66 "TIM6 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}",
67 TIM6::frequency(),
68 FREQUENCY,
69 reload,
70 reload as u16,
71 data.len()
72 );
73
74 // Loop technically not necessary if DMA circular mode is enabled
75 loop {
76 info!("Loop DAC1");
77 if let Err(e) = dac.write(ValueArray::Bit8(data), true).await {
78 error!("Could not write to dac: {}", e);
79 }
80 }
81}
82
83#[embassy_executor::task]
84async fn dac_task2(mut dac: Dac2Type) {
85 let data: &[u8; 256] = &calculate_array::<256>();
86
87 info!("TIM7 frequency is {}", TIM7::frequency());
88
89 const FREQUENCY: Hertz = Hertz::hz(600);
90 let reload: u32 = (TIM7::frequency().0 / FREQUENCY.0) / data.len() as u32;
91
92 if reload < 10 {
93 error!("Reload value {} below threshold!", reload);
94 }
95
96 TIM7::enable();
97 TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1));
98 TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE));
99 TIM7::regs().cr1().modify(|w| {
100 w.set_opm(Opm::DISABLED);
101 w.set_cen(true);
102 });
103
104 dac.select_trigger(embassy_stm32::dac::Ch2Trigger::Tim7).unwrap();
105
106 debug!(
107 "TIM7 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}",
108 TIM7::frequency(),
109 FREQUENCY,
110 reload,
111 reload as u16,
112 data.len()
113 );
114
115 if let Err(e) = dac.write(ValueArray::Bit8(data), true).await {
116 error!("Could not write to dac: {}", e);
117 }
118}
119
120fn to_sine_wave(v: u8) -> u8 {
121 if v >= 128 {
122 // top half
123 let r = 3.14 * ((v - 128) as f32 / 128.0);
124 (r.sin() * 128.0 + 127.0) as u8
125 } else {
126 // bottom half
127 let r = 3.14 + 3.14 * (v as f32 / 128.0);
128 (r.sin() * 128.0 + 127.0) as u8
129 }
130}
131
132fn calculate_array<const N: usize>() -> [u8; N] {
133 let mut res = [0; N];
134 let mut i = 0;
135 while i < N {
136 res[i] = to_sine_wave(i as u8);
137 i += 1;
138 }
139 res
140}
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index cfafcaed1..c93be9f00 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -11,14 +11,16 @@ use embassy_stm32::eth::{Ethernet, PacketQueue};
11use embassy_stm32::peripherals::ETH; 11use embassy_stm32::peripherals::ETH;
12use embassy_stm32::rng::Rng; 12use embassy_stm32::rng::Rng;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{bind_interrupts, eth, Config}; 14use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use rand_core::RngCore; 17use rand_core::RngCore;
18use static_cell::make_static; 18use static_cell::make_static;
19use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
20
20bind_interrupts!(struct Irqs { 21bind_interrupts!(struct Irqs {
21 ETH => eth::InterruptHandler; 22 ETH => eth::InterruptHandler;
23 RNG => rng::InterruptHandler<peripherals::RNG>;
22}); 24});
23 25
24type Device = Ethernet<'static, ETH, GenericSMI>; 26type Device = Ethernet<'static, ETH, GenericSMI>;
@@ -38,7 +40,7 @@ async fn main(spawner: Spawner) -> ! {
38 info!("Hello World!"); 40 info!("Hello World!");
39 41
40 // Generate random seed. 42 // Generate random seed.
41 let mut rng = Rng::new(p.RNG); 43 let mut rng = Rng::new(p.RNG, Irqs);
42 let mut seed = [0; 8]; 44 let mut seed = [0; 8];
43 rng.fill_bytes(&mut seed); 45 rng.fill_bytes(&mut seed);
44 let seed = u64::from_le_bytes(seed); 46 let seed = u64::from_le_bytes(seed);
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
index 4ed737578..78005e91f 100644
--- a/examples/stm32h7/src/bin/eth_client.rs
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -11,15 +11,17 @@ use embassy_stm32::eth::{Ethernet, PacketQueue};
11use embassy_stm32::peripherals::ETH; 11use embassy_stm32::peripherals::ETH;
12use embassy_stm32::rng::Rng; 12use embassy_stm32::rng::Rng;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{bind_interrupts, eth, Config}; 14use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; 17use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect};
18use rand_core::RngCore; 18use rand_core::RngCore;
19use static_cell::make_static; 19use static_cell::make_static;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21
21bind_interrupts!(struct Irqs { 22bind_interrupts!(struct Irqs {
22 ETH => eth::InterruptHandler; 23 ETH => eth::InterruptHandler;
24 RNG => rng::InterruptHandler<peripherals::RNG>;
23}); 25});
24 26
25type Device = Ethernet<'static, ETH, GenericSMI>; 27type Device = Ethernet<'static, ETH, GenericSMI>;
@@ -39,7 +41,7 @@ async fn main(spawner: Spawner) -> ! {
39 info!("Hello World!"); 41 info!("Hello World!");
40 42
41 // Generate random seed. 43 // Generate random seed.
42 let mut rng = Rng::new(p.RNG); 44 let mut rng = Rng::new(p.RNG, Irqs);
43 let mut seed = [0; 8]; 45 let mut seed = [0; 8];
44 rng.fill_bytes(&mut seed); 46 rng.fill_bytes(&mut seed);
45 let seed = u64::from_le_bytes(seed); 47 let seed = u64::from_le_bytes(seed);
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index d360df085..45b0872b5 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -6,8 +6,8 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::gpio::low_level::AFType; 7use embassy_stm32::gpio::low_level::AFType;
8use embassy_stm32::gpio::Speed; 8use embassy_stm32::gpio::Speed;
9use embassy_stm32::pwm::*;
10use embassy_stm32::time::{khz, mhz, Hertz}; 9use embassy_stm32::time::{khz, mhz, Hertz};
10use embassy_stm32::timer::*;
11use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef}; 11use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef};
12use embassy_time::{Duration, Timer}; 12use embassy_time::{Duration, Timer};
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs
index c5c0dd290..aa5ec1bcf 100644
--- a/examples/stm32h7/src/bin/pwm.rs
+++ b/examples/stm32h7/src/bin/pwm.rs
@@ -4,9 +4,10 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; 7use embassy_stm32::gpio::OutputType;
8use embassy_stm32::pwm::Channel;
9use embassy_stm32::time::{khz, mhz}; 8use embassy_stm32::time::{khz, mhz};
9use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
10use embassy_stm32::timer::Channel;
10use embassy_stm32::Config; 11use embassy_stm32::Config;
11use embassy_time::{Duration, Timer}; 12use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
@@ -24,7 +25,7 @@ async fn main(_spawner: Spawner) {
24 let p = embassy_stm32::init(config); 25 let p = embassy_stm32::init(config);
25 info!("Hello World!"); 26 info!("Hello World!");
26 27
27 let ch1 = PwmPin::new_ch1(p.PA6); 28 let ch1 = PwmPin::new_ch1(p.PA6, OutputType::PushPull);
28 let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10)); 29 let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10));
29 let max = pwm.get_max_duty(); 30 let max = pwm.get_max_duty();
30 pwm.enable(Channel::Ch1); 31 pwm.enable(Channel::Ch1);
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs
index af9be0b62..7c8c50eca 100644
--- a/examples/stm32h7/src/bin/rng.rs
+++ b/examples/stm32h7/src/bin/rng.rs
@@ -5,14 +5,19 @@
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rng::Rng; 7use embassy_stm32::rng::Rng;
8use embassy_stm32::{bind_interrupts, peripherals, rng};
8use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
9 10
11bind_interrupts!(struct Irqs {
12 RNG => rng::InterruptHandler<peripherals::RNG>;
13});
14
10#[embassy_executor::main] 15#[embassy_executor::main]
11async fn main(_spawner: Spawner) { 16async fn main(_spawner: Spawner) {
12 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
13 info!("Hello World!"); 18 info!("Hello World!");
14 19
15 let mut rng = Rng::new(p.RNG); 20 let mut rng = Rng::new(p.RNG, Irqs);
16 21
17 let mut buf = [0u8; 16]; 22 let mut buf = [0u8; 16];
18 unwrap!(rng.async_fill_bytes(&mut buf).await); 23 unwrap!(rng.async_fill_bytes(&mut buf).await);
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index 1f407f002..28bba2b8d 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -43,16 +43,10 @@ fn main() -> ! {
43 config.rcc.pll1.q_ck = Some(mhz(100)); 43 config.rcc.pll1.q_ck = Some(mhz(100));
44 let p = embassy_stm32::init(config); 44 let p = embassy_stm32::init(config);
45 45
46 let spi = spi::Spi::new( 46 let mut spi_config = spi::Config::default();
47 p.SPI3, 47 spi_config.frequency = mhz(1);
48 p.PB3, 48
49 p.PB5, 49 let spi = spi::Spi::new(p.SPI3, p.PB3, p.PB5, p.PB4, NoDma, NoDma, spi_config);
50 p.PB4,
51 NoDma,
52 NoDma,
53 mhz(1),
54 spi::Config::default(),
55 );
56 50
57 let executor = EXECUTOR.init(Executor::new()); 51 let executor = EXECUTOR.init(Executor::new());
58 52
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 53004fc9b..f6e30cfa5 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -39,16 +39,10 @@ fn main() -> ! {
39 config.rcc.pll1.q_ck = Some(mhz(100)); 39 config.rcc.pll1.q_ck = Some(mhz(100));
40 let p = embassy_stm32::init(config); 40 let p = embassy_stm32::init(config);
41 41
42 let spi = spi::Spi::new( 42 let mut spi_config = spi::Config::default();
43 p.SPI3, 43 spi_config.frequency = mhz(1);
44 p.PB3, 44
45 p.PB5, 45 let spi = spi::Spi::new(p.SPI3, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH4, spi_config);
46 p.PB4,
47 p.DMA1_CH3,
48 p.DMA1_CH4,
49 mhz(1),
50 spi::Config::default(),
51 );
52 46
53 let executor = EXECUTOR.init(Executor::new()); 47 let executor = EXECUTOR.init(Executor::new());
54 48
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index e6a5a4c14..c325751c6 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -34,5 +34,5 @@ heapless = { version = "0.7.5", default-features = false }
34embedded-hal = "0.2.6" 34embedded-hal = "0.2.6"
35static_cell = "1.1" 35static_cell = "1.1"
36 36
37[patch.crates-io] 37[profile.release]
38lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } 38debug = 2
diff --git a/examples/stm32l0/src/bin/lora_cad.rs b/examples/stm32l0/src/bin/lora_cad.rs
index 588cea1e5..7729b4163 100644
--- a/examples/stm32l0/src/bin/lora_cad.rs
+++ b/examples/stm32l0/src/bin/lora_cad.rs
@@ -27,17 +27,11 @@ async fn main(_spawner: Spawner) {
27 config.rcc.enable_hsi48 = true; 27 config.rcc.enable_hsi48 = true;
28 let p = embassy_stm32::init(config); 28 let p = embassy_stm32::init(config);
29 29
30 let mut spi_config = spi::Config::default();
31 spi_config.frequency = khz(200);
32
30 // SPI for sx1276 33 // SPI for sx1276
31 let spi = spi::Spi::new( 34 let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
32 p.SPI1,
33 p.PB3,
34 p.PA7,
35 p.PA6,
36 p.DMA1_CH3,
37 p.DMA1_CH2,
38 khz(200),
39 spi::Config::default(),
40 );
41 35
42 let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); 36 let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
43 let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); 37 let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/lora_lorawan.rs b/examples/stm32l0/src/bin/lora_lorawan.rs
index c397edd58..10608aebf 100644
--- a/examples/stm32l0/src/bin/lora_lorawan.rs
+++ b/examples/stm32l0/src/bin/lora_lorawan.rs
@@ -12,8 +12,8 @@ use embassy_lora::LoraTimer;
12use embassy_stm32::exti::{Channel, ExtiInput}; 12use embassy_stm32::exti::{Channel, ExtiInput};
13use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; 13use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed};
14use embassy_stm32::rng::Rng; 14use embassy_stm32::rng::Rng;
15use embassy_stm32::spi;
16use embassy_stm32::time::khz; 15use embassy_stm32::time::khz;
16use embassy_stm32::{bind_interrupts, peripherals, rng, spi};
17use embassy_time::Delay; 17use embassy_time::Delay;
18use lora_phy::mod_params::*; 18use lora_phy::mod_params::*;
19use lora_phy::sx1276_7_8_9::SX1276_7_8_9; 19use lora_phy::sx1276_7_8_9::SX1276_7_8_9;
@@ -23,6 +23,10 @@ use lorawan_device::async_device::lora_radio::LoRaRadio;
23use lorawan_device::async_device::{region, Device, JoinMode}; 23use lorawan_device::async_device::{region, Device, JoinMode};
24use {defmt_rtt as _, panic_probe as _}; 24use {defmt_rtt as _, panic_probe as _};
25 25
26bind_interrupts!(struct Irqs {
27 RNG_LPUART1 => rng::InterruptHandler<peripherals::RNG>;
28});
29
26const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region 30const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region
27 31
28#[embassy_executor::main] 32#[embassy_executor::main]
@@ -32,17 +36,11 @@ async fn main(_spawner: Spawner) {
32 config.rcc.enable_hsi48 = true; 36 config.rcc.enable_hsi48 = true;
33 let p = embassy_stm32::init(config); 37 let p = embassy_stm32::init(config);
34 38
39 let mut spi_config = spi::Config::default();
40 spi_config.frequency = khz(200);
41
35 // SPI for sx1276 42 // SPI for sx1276
36 let spi = spi::Spi::new( 43 let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
37 p.SPI1,
38 p.PB3,
39 p.PA7,
40 p.PA6,
41 p.DMA1_CH3,
42 p.DMA1_CH2,
43 khz(200),
44 spi::Config::default(),
45 );
46 44
47 let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); 45 let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
48 let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); 46 let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
@@ -66,7 +64,7 @@ async fn main(_spawner: Spawner) {
66 64
67 let radio = LoRaRadio::new(lora); 65 let radio = LoRaRadio::new(lora);
68 let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); 66 let region: region::Configuration = region::Configuration::new(LORAWAN_REGION);
69 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG)); 67 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs));
70 68
71 defmt::info!("Joining LoRaWAN network"); 69 defmt::info!("Joining LoRaWAN network");
72 70
diff --git a/examples/stm32l0/src/bin/lora_p2p_receive.rs b/examples/stm32l0/src/bin/lora_p2p_receive.rs
index bb7509509..0f9f60952 100644
--- a/examples/stm32l0/src/bin/lora_p2p_receive.rs
+++ b/examples/stm32l0/src/bin/lora_p2p_receive.rs
@@ -27,17 +27,11 @@ async fn main(_spawner: Spawner) {
27 config.rcc.enable_hsi48 = true; 27 config.rcc.enable_hsi48 = true;
28 let p = embassy_stm32::init(config); 28 let p = embassy_stm32::init(config);
29 29
30 let mut spi_config = spi::Config::default();
31 spi_config.frequency = khz(200);
32
30 // SPI for sx1276 33 // SPI for sx1276
31 let spi = spi::Spi::new( 34 let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
32 p.SPI1,
33 p.PB3,
34 p.PA7,
35 p.PA6,
36 p.DMA1_CH3,
37 p.DMA1_CH2,
38 khz(200),
39 spi::Config::default(),
40 );
41 35
42 let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); 36 let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
43 let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); 37 let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/lora_p2p_send.rs b/examples/stm32l0/src/bin/lora_p2p_send.rs
index e6fadc01d..c85c3c2b6 100644
--- a/examples/stm32l0/src/bin/lora_p2p_send.rs
+++ b/examples/stm32l0/src/bin/lora_p2p_send.rs
@@ -27,17 +27,11 @@ async fn main(_spawner: Spawner) {
27 config.rcc.enable_hsi48 = true; 27 config.rcc.enable_hsi48 = true;
28 let p = embassy_stm32::init(config); 28 let p = embassy_stm32::init(config);
29 29
30 let mut spi_config = spi::Config::default();
31 spi_config.frequency = khz(200);
32
30 // SPI for sx1276 33 // SPI for sx1276
31 let spi = spi::Spi::new( 34 let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
32 p.SPI1,
33 p.PB3,
34 p.PA7,
35 p.PA6,
36 p.DMA1_CH3,
37 p.DMA1_CH2,
38 khz(200),
39 spi::Config::default(),
40 );
41 35
42 let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); 36 let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
43 let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); 37 let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index 9b5b3e27d..583e3d127 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -15,16 +15,10 @@ async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default()); 15 let p = embassy_stm32::init(Default::default());
16 info!("Hello World, folks!"); 16 info!("Hello World, folks!");
17 17
18 let mut spi = Spi::new( 18 let mut spi_config = Config::default();
19 p.SPI1, 19 spi_config.frequency = Hertz(1_000_000);
20 p.PB3, 20
21 p.PA7, 21 let mut spi = Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, NoDma, NoDma, spi_config);
22 p.PA6,
23 NoDma,
24 NoDma,
25 Hertz(1_000_000),
26 Config::default(),
27 );
28 22
29 let mut cs = Output::new(p.PA15, Level::High, Speed::VeryHigh); 23 let mut cs = Output::new(p.PA15, Level::High, Speed::VeryHigh);
30 24
diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml
index dcca1cc3d..329d44cac 100644
--- a/examples/stm32l1/Cargo.toml
+++ b/examples/stm32l1/Cargo.toml
@@ -20,3 +20,6 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
20futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 20futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
21heapless = { version = "0.7.5", default-features = false } 21heapless = { version = "0.7.5", default-features = false }
22embedded-storage = "0.3.0" 22embedded-storage = "0.3.0"
23
24[profile.release]
25debug = 2
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index 0a532e8e3..905b4d75c 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -15,16 +15,10 @@ async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default()); 15 let p = embassy_stm32::init(Default::default());
16 info!("Hello World, folks!"); 16 info!("Hello World, folks!");
17 17
18 let mut spi = Spi::new( 18 let mut spi_config = Config::default();
19 p.SPI1, 19 spi_config.frequency = Hertz(1_000_000);
20 p.PA5, 20
21 p.PA7, 21 let mut spi = Spi::new(p.SPI1, p.PA5, p.PA7, p.PA6, NoDma, NoDma, spi_config);
22 p.PA6,
23 NoDma,
24 NoDma,
25 Hertz(1_000_000),
26 Config::default(),
27 );
28 22
29 let mut cs = Output::new(p.PA4, Level::High, Speed::VeryHigh); 23 let mut cs = Output::new(p.PA4, Level::High, Speed::VeryHigh);
30 24
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml
index 41c9869bf..3b27d8e81 100644
--- a/examples/stm32l4/Cargo.toml
+++ b/examples/stm32l4/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8# Change stm32l4s5vi to your chip name, if necessary. 8# Change stm32l4s5vi to your chip name, if necessary.
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits", "chrono"] } 9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "memory-x", "time-driver-any", "exti", "unstable-traits", "chrono"] }
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 = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 12embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
@@ -27,3 +27,6 @@ heapless = { version = "0.7.5", default-features = false }
27chrono = { version = "^0.4", default-features = false } 27chrono = { version = "^0.4", default-features = false }
28 28
29micromath = "2.0.0" 29micromath = "2.0.0"
30
31[profile.release]
32debug = 2
diff --git a/examples/stm32l4/build.rs b/examples/stm32l4/build.rs
index 30691aa97..8cd32d7ed 100644
--- a/examples/stm32l4/build.rs
+++ b/examples/stm32l4/build.rs
@@ -1,34 +1,4 @@
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() { 1fn 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"); 2 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x"); 3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); 4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
diff --git a/examples/stm32l4/memory.x b/examples/stm32l4/memory.x
deleted file mode 100644
index eb87d1b54..000000000
--- a/examples/stm32l4/memory.x
+++ /dev/null
@@ -1,7 +0,0 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 /* These values correspond to the STM32L4S5 */
5 FLASH : ORIGIN = 0x08000000, LENGTH = 1024K
6 RAM : ORIGIN = 0x20000000, LENGTH = 128K
7}
diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs
index c9302bb99..806e49f59 100644
--- a/examples/stm32l4/src/bin/rng.rs
+++ b/examples/stm32l4/src/bin/rng.rs
@@ -6,9 +6,13 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; 7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
8use embassy_stm32::rng::Rng; 8use embassy_stm32::rng::Rng;
9use embassy_stm32::Config; 9use embassy_stm32::{bind_interrupts, peripherals, rng, Config};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12bind_interrupts!(struct Irqs {
13 RNG => rng::InterruptHandler<peripherals::RNG>;
14});
15
12#[embassy_executor::main] 16#[embassy_executor::main]
13async fn main(_spawner: Spawner) { 17async fn main(_spawner: Spawner) {
14 let mut config = Config::default(); 18 let mut config = Config::default();
@@ -24,7 +28,7 @@ async fn main(_spawner: Spawner) {
24 28
25 info!("Hello World!"); 29 info!("Hello World!");
26 30
27 let mut rng = Rng::new(p.RNG); 31 let mut rng = Rng::new(p.RNG, Irqs);
28 32
29 let mut buf = [0u8; 16]; 33 let mut buf = [0u8; 16];
30 unwrap!(rng.async_fill_bytes(&mut buf).await); 34 unwrap!(rng.async_fill_bytes(&mut buf).await);
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index 76e316a25..54cf68f7b 100644
--- a/examples/stm32l4/src/bin/spi.rs
+++ b/examples/stm32l4/src/bin/spi.rs
@@ -15,16 +15,10 @@ fn main() -> ! {
15 15
16 let p = embassy_stm32::init(Default::default()); 16 let p = embassy_stm32::init(Default::default());
17 17
18 let mut spi = Spi::new( 18 let mut spi_config = Config::default();
19 p.SPI3, 19 spi_config.frequency = Hertz(1_000_000);
20 p.PC10, 20
21 p.PC12, 21 let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
22 p.PC11,
23 NoDma,
24 NoDma,
25 Hertz(1_000_000),
26 Config::default(),
27 );
28 22
29 let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh); 23 let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh);
30 24
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index 62ef0130e..f1b80087c 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -17,16 +17,10 @@ async fn main(_spawner: Spawner) {
17 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
18 info!("Hello World!"); 18 info!("Hello World!");
19 19
20 let spi = Spi::new( 20 let mut spi_config = Config::default();
21 p.SPI3, 21 spi_config.frequency = Hertz(1_000_000);
22 p.PC10, 22
23 p.PC12, 23 let spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, NoDma, NoDma, spi_config);
24 p.PC11,
25 NoDma,
26 NoDma,
27 Hertz(1_000_000),
28 Config::default(),
29 );
30 24
31 let mut spi = BlockingAsync::new(spi); 25 let mut spi = BlockingAsync::new(spi);
32 26
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 89471db5a..ff9b5b43b 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -14,16 +14,10 @@ async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default()); 14 let p = embassy_stm32::init(Default::default());
15 info!("Hello World!"); 15 info!("Hello World!");
16 16
17 let mut spi = Spi::new( 17 let mut spi_config = Config::default();
18 p.SPI3, 18 spi_config.frequency = Hertz(1_000_000);
19 p.PC10, 19
20 p.PC12, 20 let mut spi = Spi::new(p.SPI3, p.PC10, p.PC12, p.PC11, p.DMA1_CH1, p.DMA1_CH2, spi_config);
21 p.PC11,
22 p.DMA1_CH1,
23 p.DMA1_CH2,
24 Hertz(1_000_000),
25 Config::default(),
26 );
27 21
28 // These are the pins for the Inventek eS-Wifi SPI Wifi Adapter. 22 // These are the pins for the Inventek eS-Wifi SPI Wifi Adapter.
29 23
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml
index 5d66c59c3..1afd00398 100644
--- a/examples/stm32l5/Cargo.toml
+++ b/examples/stm32l5/Cargo.toml
@@ -27,3 +27,6 @@ heapless = { version = "0.7.5", default-features = false }
27rand_core = { version = "0.6.3", default-features = false } 27rand_core = { version = "0.6.3", default-features = false }
28embedded-io = { version = "0.4.0", features = ["async"] } 28embedded-io = { version = "0.4.0", features = ["async"] }
29static_cell = { version = "1.1", features = ["nightly"]} 29static_cell = { version = "1.1", features = ["nightly"]}
30
31[profile.release]
32debug = 2
diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs
index d359847e8..9549d64d8 100644
--- a/examples/stm32l5/src/bin/rng.rs
+++ b/examples/stm32l5/src/bin/rng.rs
@@ -6,9 +6,13 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; 7use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
8use embassy_stm32::rng::Rng; 8use embassy_stm32::rng::Rng;
9use embassy_stm32::Config; 9use embassy_stm32::{bind_interrupts, peripherals, rng, Config};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12bind_interrupts!(struct Irqs {
13 RNG => rng::InterruptHandler<peripherals::RNG>;
14});
15
12#[embassy_executor::main] 16#[embassy_executor::main]
13async fn main(_spawner: Spawner) { 17async fn main(_spawner: Spawner) {
14 let mut config = Config::default(); 18 let mut config = Config::default();
@@ -23,7 +27,7 @@ async fn main(_spawner: Spawner) {
23 27
24 info!("Hello World!"); 28 info!("Hello World!");
25 29
26 let mut rng = Rng::new(p.RNG); 30 let mut rng = Rng::new(p.RNG, Irqs);
27 31
28 let mut buf = [0u8; 16]; 32 let mut buf = [0u8; 16];
29 unwrap!(rng.async_fill_bytes(&mut buf).await); 33 unwrap!(rng.async_fill_bytes(&mut buf).await);
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs
index 32eba4277..5e75b21c9 100644
--- a/examples/stm32l5/src/bin/usb_ethernet.rs
+++ b/examples/stm32l5/src/bin/usb_ethernet.rs
@@ -9,7 +9,7 @@ use embassy_net::{Stack, StackResources};
9use embassy_stm32::rcc::*; 9use embassy_stm32::rcc::*;
10use embassy_stm32::rng::Rng; 10use embassy_stm32::rng::Rng;
11use embassy_stm32::usb::Driver; 11use embassy_stm32::usb::Driver;
12use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; 12use embassy_stm32::{bind_interrupts, peripherals, rng, usb, Config};
13use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState}; 13use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState};
14use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; 14use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
15use embassy_usb::{Builder, UsbDevice}; 15use embassy_usb::{Builder, UsbDevice};
@@ -24,6 +24,7 @@ const MTU: usize = 1514;
24 24
25bind_interrupts!(struct Irqs { 25bind_interrupts!(struct Irqs {
26 USB_FS => usb::InterruptHandler<peripherals::USB>; 26 USB_FS => usb::InterruptHandler<peripherals::USB>;
27 RNG => rng::InterruptHandler<peripherals::RNG>;
27}); 28});
28 29
29#[embassy_executor::task] 30#[embassy_executor::task]
@@ -99,7 +100,7 @@ async fn main(spawner: Spawner) {
99 //}); 100 //});
100 101
101 // Generate random seed 102 // Generate random seed
102 let mut rng = Rng::new(p.RNG); 103 let mut rng = Rng::new(p.RNG, Irqs);
103 let seed = rng.next_u64(); 104 let seed = rng.next_u64();
104 105
105 // Init network stack 106 // Init network stack
diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml
index a43a55909..db251eafe 100644
--- a/examples/stm32u5/Cargo.toml
+++ b/examples/stm32u5/Cargo.toml
@@ -23,3 +23,6 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
23heapless = { version = "0.7.5", default-features = false } 23heapless = { version = "0.7.5", default-features = false }
24 24
25micromath = "2.0.0" 25micromath = "2.0.0"
26
27[profile.release]
28debug = 2
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml
index 48e340264..1a5aff352 100644
--- a/examples/stm32wb/Cargo.toml
+++ b/examples/stm32wb/Cargo.toml
@@ -52,3 +52,6 @@ required-features = ["ble"]
52[[bin]] 52[[bin]]
53name = "gatt_server" 53name = "gatt_server"
54required-features = ["ble"] 54required-features = ["ble"]
55
56[profile.release]
57debug = 2
diff --git a/examples/stm32wb/src/bin/eddystone_beacon.rs b/examples/stm32wb/src/bin/eddystone_beacon.rs
index 451bd7d29..ea150c67e 100644
--- a/examples/stm32wb/src/bin/eddystone_beacon.rs
+++ b/examples/stm32wb/src/bin/eddystone_beacon.rs
@@ -8,6 +8,7 @@ use defmt::*;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::bind_interrupts; 9use embassy_stm32::bind_interrupts;
10use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 10use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
11use embassy_stm32::rcc::WPAN_DEFAULT;
11use embassy_stm32_wpan::hci::host::uart::UartHci; 12use embassy_stm32_wpan::hci::host::uart::UartHci;
12use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType}; 13use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType};
13use embassy_stm32_wpan::hci::types::AdvertisingType; 14use embassy_stm32_wpan::hci::types::AdvertisingType;
@@ -54,7 +55,9 @@ async fn main(_spawner: Spawner) {
54 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. 55 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
55 */ 56 */
56 57
57 let p = embassy_stm32::init(Default::default()); 58 let mut config = embassy_stm32::Config::default();
59 config.rcc = WPAN_DEFAULT;
60 let p = embassy_stm32::init(config);
58 info!("Hello World!"); 61 info!("Hello World!");
59 62
60 let config = Config::default(); 63 let config = Config::default();
diff --git a/examples/stm32wb/src/bin/gatt_server.rs b/examples/stm32wb/src/bin/gatt_server.rs
index 0f6419d45..dd67249c7 100644
--- a/examples/stm32wb/src/bin/gatt_server.rs
+++ b/examples/stm32wb/src/bin/gatt_server.rs
@@ -8,6 +8,7 @@ use defmt::*;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::bind_interrupts; 9use embassy_stm32::bind_interrupts;
10use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 10use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
11use embassy_stm32::rcc::WPAN_DEFAULT;
11use embassy_stm32_wpan::hci::event::command::{CommandComplete, ReturnParameters}; 12use embassy_stm32_wpan::hci::event::command::{CommandComplete, ReturnParameters};
12use embassy_stm32_wpan::hci::host::uart::{Packet, UartHci}; 13use embassy_stm32_wpan::hci::host::uart::{Packet, UartHci};
13use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType}; 14use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType};
@@ -62,7 +63,9 @@ async fn main(_spawner: Spawner) {
62 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. 63 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
63 */ 64 */
64 65
65 let p = embassy_stm32::init(Default::default()); 66 let mut config = embassy_stm32::Config::default();
67 config.rcc = WPAN_DEFAULT;
68 let p = embassy_stm32::init(config);
66 info!("Hello World!"); 69 info!("Hello World!");
67 70
68 let config = Config::default(); 71 let config = Config::default();
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs
index 1379ac6ba..881dc488d 100644
--- a/examples/stm32wb/src/bin/mac_ffd.rs
+++ b/examples/stm32wb/src/bin/mac_ffd.rs
@@ -6,6 +6,7 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32::rcc::WPAN_DEFAULT;
9use embassy_stm32_wpan::mac::commands::{AssociateResponse, ResetRequest, SetRequest, StartRequest}; 10use embassy_stm32_wpan::mac::commands::{AssociateResponse, ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::mac::event::MacEvent; 11use embassy_stm32_wpan::mac::event::MacEvent;
11use embassy_stm32_wpan::mac::typedefs::{MacChannel, MacStatus, PanId, PibId, SecurityLevel}; 12use embassy_stm32_wpan::mac::typedefs::{MacChannel, MacStatus, PanId, PibId, SecurityLevel};
@@ -30,7 +31,7 @@ async fn main(spawner: Spawner) {
30 31
31 - Obtain a NUCLEO-STM32WB55 from your preferred supplier. 32 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
32 - Download and Install STM32CubeProgrammer. 33 - Download and Install STM32CubeProgrammer.
33 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from 34 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Mac_802_15_4_fw.bin, and Release_Notes.html from
34 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x 35 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
35 - Open STM32CubeProgrammer 36 - Open STM32CubeProgrammer
36 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware. 37 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
@@ -39,7 +40,7 @@ async fn main(spawner: Spawner) {
39 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file 40 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
40 - Select that file, the memory address, "verify download", and then "Firmware Upgrade". 41 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
41 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the 42 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
42 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address. 43 stm32wb5x_BLE_Mac_802_15_4_fw.bin file. It should not be the same memory address.
43 - Select that file, the memory address, "verify download", and then "Firmware Upgrade". 44 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
44 - Select "Start Wireless Stack". 45 - Select "Start Wireless Stack".
45 - Disconnect from the device. 46 - Disconnect from the device.
@@ -49,7 +50,9 @@ async fn main(spawner: Spawner) {
49 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. 50 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
50 */ 51 */
51 52
52 let p = embassy_stm32::init(Default::default()); 53 let mut config = embassy_stm32::Config::default();
54 config.rcc = WPAN_DEFAULT;
55 let p = embassy_stm32::init(config);
53 info!("Hello World!"); 56 info!("Hello World!");
54 57
55 let config = Config::default(); 58 let config = Config::default();
diff --git a/examples/stm32wb/src/bin/mac_ffd_net.rs b/examples/stm32wb/src/bin/mac_ffd_net.rs
index bbcd0a70f..f8c76b5a4 100644
--- a/examples/stm32wb/src/bin/mac_ffd_net.rs
+++ b/examples/stm32wb/src/bin/mac_ffd_net.rs
@@ -6,6 +6,7 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32::rcc::WPAN_DEFAULT;
9use embassy_stm32_wpan::mac::commands::{ResetRequest, SetRequest, StartRequest}; 10use embassy_stm32_wpan::mac::commands::{ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::mac::typedefs::{MacChannel, PanId, PibId}; 11use embassy_stm32_wpan::mac::typedefs::{MacChannel, PanId, PibId};
11use embassy_stm32_wpan::mac::{self, Runner}; 12use embassy_stm32_wpan::mac::{self, Runner};
@@ -36,7 +37,7 @@ async fn main(spawner: Spawner) {
36 37
37 - Obtain a NUCLEO-STM32WB55 from your preferred supplier. 38 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
38 - Download and Install STM32CubeProgrammer. 39 - Download and Install STM32CubeProgrammer.
39 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from 40 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Mac_802_15_4_fw.bin, and Release_Notes.html from
40 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x 41 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
41 - Open STM32CubeProgrammer 42 - Open STM32CubeProgrammer
42 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware. 43 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
@@ -45,7 +46,7 @@ async fn main(spawner: Spawner) {
45 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file 46 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
46 - Select that file, the memory address, "verify download", and then "Firmware Upgrade". 47 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
47 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the 48 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
48 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address. 49 stm32wb5x_BLE_Mac_802_15_4_fw.bin file. It should not be the same memory address.
49 - Select that file, the memory address, "verify download", and then "Firmware Upgrade". 50 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
50 - Select "Start Wireless Stack". 51 - Select "Start Wireless Stack".
51 - Disconnect from the device. 52 - Disconnect from the device.
@@ -55,7 +56,9 @@ async fn main(spawner: Spawner) {
55 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. 56 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
56 */ 57 */
57 58
58 let p = embassy_stm32::init(Default::default()); 59 let mut config = embassy_stm32::Config::default();
60 config.rcc = WPAN_DEFAULT;
61 let p = embassy_stm32::init(config);
59 info!("Hello World!"); 62 info!("Hello World!");
60 63
61 let config = Config::default(); 64 let config = Config::default();
diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs
index 4d8b6601a..000355de6 100644
--- a/examples/stm32wb/src/bin/mac_rfd.rs
+++ b/examples/stm32wb/src/bin/mac_rfd.rs
@@ -6,6 +6,7 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32::rcc::WPAN_DEFAULT;
9use embassy_stm32_wpan::mac::commands::{AssociateRequest, DataRequest, GetRequest, ResetRequest, SetRequest}; 10use embassy_stm32_wpan::mac::commands::{AssociateRequest, DataRequest, GetRequest, ResetRequest, SetRequest};
10use embassy_stm32_wpan::mac::event::MacEvent; 11use embassy_stm32_wpan::mac::event::MacEvent;
11use embassy_stm32_wpan::mac::typedefs::{ 12use embassy_stm32_wpan::mac::typedefs::{
@@ -32,7 +33,7 @@ async fn main(spawner: Spawner) {
32 33
33 - Obtain a NUCLEO-STM32WB55 from your preferred supplier. 34 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
34 - Download and Install STM32CubeProgrammer. 35 - Download and Install STM32CubeProgrammer.
35 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from 36 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Mac_802_15_4_fw.bin, and Release_Notes.html from
36 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x 37 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
37 - Open STM32CubeProgrammer 38 - Open STM32CubeProgrammer
38 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware. 39 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
@@ -41,7 +42,7 @@ async fn main(spawner: Spawner) {
41 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file 42 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
42 - Select that file, the memory address, "verify download", and then "Firmware Upgrade". 43 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
43 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the 44 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
44 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address. 45 stm32wb5x_BLE_Mac_802_15_4_fw.bin file. It should not be the same memory address.
45 - Select that file, the memory address, "verify download", and then "Firmware Upgrade". 46 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
46 - Select "Start Wireless Stack". 47 - Select "Start Wireless Stack".
47 - Disconnect from the device. 48 - Disconnect from the device.
@@ -51,7 +52,9 @@ async fn main(spawner: Spawner) {
51 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. 52 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
52 */ 53 */
53 54
54 let p = embassy_stm32::init(Default::default()); 55 let mut config = embassy_stm32::Config::default();
56 config.rcc = WPAN_DEFAULT;
57 let p = embassy_stm32::init(config);
55 info!("Hello World!"); 58 info!("Hello World!");
56 59
57 let config = Config::default(); 60 let config = Config::default();
diff --git a/examples/stm32wb/src/bin/tl_mbox.rs b/examples/stm32wb/src/bin/tl_mbox.rs
index 9fc4b8aac..fc49c3c4a 100644
--- a/examples/stm32wb/src/bin/tl_mbox.rs
+++ b/examples/stm32wb/src/bin/tl_mbox.rs
@@ -6,6 +6,7 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32::rcc::WPAN_DEFAULT;
9use embassy_stm32_wpan::TlMbox; 10use embassy_stm32_wpan::TlMbox;
10use embassy_time::{Duration, Timer}; 11use embassy_time::{Duration, Timer};
11use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
@@ -41,7 +42,9 @@ async fn main(_spawner: Spawner) {
41 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. 42 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
42 */ 43 */
43 44
44 let p = embassy_stm32::init(Default::default()); 45 let mut config = embassy_stm32::Config::default();
46 config.rcc = WPAN_DEFAULT;
47 let p = embassy_stm32::init(config);
45 info!("Hello World!"); 48 info!("Hello World!");
46 49
47 let config = Config::default(); 50 let config = Config::default();
diff --git a/examples/stm32wb/src/bin/tl_mbox_ble.rs b/examples/stm32wb/src/bin/tl_mbox_ble.rs
index 90349422e..5745ebd02 100644
--- a/examples/stm32wb/src/bin/tl_mbox_ble.rs
+++ b/examples/stm32wb/src/bin/tl_mbox_ble.rs
@@ -6,6 +6,7 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32::rcc::WPAN_DEFAULT;
9use embassy_stm32_wpan::TlMbox; 10use embassy_stm32_wpan::TlMbox;
10use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
11 12
@@ -40,7 +41,9 @@ async fn main(_spawner: Spawner) {
40 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. 41 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
41 */ 42 */
42 43
43 let p = embassy_stm32::init(Default::default()); 44 let mut config = embassy_stm32::Config::default();
45 config.rcc = WPAN_DEFAULT;
46 let p = embassy_stm32::init(config);
44 info!("Hello World!"); 47 info!("Hello World!");
45 48
46 let config = Config::default(); 49 let config = Config::default();
diff --git a/examples/stm32wb/src/bin/tl_mbox_mac.rs b/examples/stm32wb/src/bin/tl_mbox_mac.rs
index 5931c392b..f32e07d96 100644
--- a/examples/stm32wb/src/bin/tl_mbox_mac.rs
+++ b/examples/stm32wb/src/bin/tl_mbox_mac.rs
@@ -6,6 +6,7 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32::rcc::WPAN_DEFAULT;
9use embassy_stm32_wpan::sub::mm; 10use embassy_stm32_wpan::sub::mm;
10use embassy_stm32_wpan::TlMbox; 11use embassy_stm32_wpan::TlMbox;
11use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
@@ -27,7 +28,7 @@ async fn main(spawner: Spawner) {
27 28
28 - Obtain a NUCLEO-STM32WB55 from your preferred supplier. 29 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
29 - Download and Install STM32CubeProgrammer. 30 - Download and Install STM32CubeProgrammer.
30 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from 31 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Mac_802_15_4_fw.bin, and Release_Notes.html from
31 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x 32 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
32 - Open STM32CubeProgrammer 33 - Open STM32CubeProgrammer
33 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware. 34 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
@@ -36,7 +37,7 @@ async fn main(spawner: Spawner) {
36 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file 37 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
37 - Select that file, the memory address, "verify download", and then "Firmware Upgrade". 38 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
38 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the 39 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
39 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address. 40 stm32wb5x_BLE_Mac_802_15_4_fw.bin file. It should not be the same memory address.
40 - Select that file, the memory address, "verify download", and then "Firmware Upgrade". 41 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
41 - Select "Start Wireless Stack". 42 - Select "Start Wireless Stack".
42 - Disconnect from the device. 43 - Disconnect from the device.
@@ -46,7 +47,9 @@ async fn main(spawner: Spawner) {
46 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. 47 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
47 */ 48 */
48 49
49 let p = embassy_stm32::init(Default::default()); 50 let mut config = embassy_stm32::Config::default();
51 config.rcc = WPAN_DEFAULT;
52 let p = embassy_stm32::init(config);
50 info!("Hello World!"); 53 info!("Hello World!");
51 54
52 let config = Config::default(); 55 let config = Config::default();
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml
index 6e6f269aa..48b69c8d0 100644
--- a/examples/stm32wl/Cargo.toml
+++ b/examples/stm32wl/Cargo.toml
@@ -28,5 +28,5 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
28heapless = { version = "0.7.5", default-features = false } 28heapless = { version = "0.7.5", default-features = false }
29chrono = { version = "^0.4", default-features = false } 29chrono = { version = "^0.4", default-features = false }
30 30
31[patch.crates-io] 31[profile.release]
32lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } 32debug = 2
diff --git a/examples/stm32wl/src/bin/lora_lorawan.rs b/examples/stm32wl/src/bin/lora_lorawan.rs
index 805d21418..2c9c98861 100644
--- a/examples/stm32wl/src/bin/lora_lorawan.rs
+++ b/examples/stm32wl/src/bin/lora_lorawan.rs
@@ -10,9 +10,9 @@ use embassy_executor::Spawner;
10use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; 10use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant};
11use embassy_lora::LoraTimer; 11use embassy_lora::LoraTimer;
12use embassy_stm32::gpio::{Level, Output, Pin, Speed}; 12use embassy_stm32::gpio::{Level, Output, Pin, Speed};
13use embassy_stm32::rng::Rng; 13use embassy_stm32::rng::{self, Rng};
14use embassy_stm32::spi::Spi; 14use embassy_stm32::spi::Spi;
15use embassy_stm32::{bind_interrupts, pac}; 15use embassy_stm32::{bind_interrupts, pac, peripherals};
16use embassy_time::Delay; 16use embassy_time::Delay;
17use lora_phy::mod_params::*; 17use lora_phy::mod_params::*;
18use lora_phy::sx1261_2::SX1261_2; 18use lora_phy::sx1261_2::SX1261_2;
@@ -26,6 +26,7 @@ const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set th
26 26
27bind_interrupts!(struct Irqs{ 27bind_interrupts!(struct Irqs{
28 SUBGHZ_RADIO => InterruptHandler; 28 SUBGHZ_RADIO => InterruptHandler;
29 RNG => rng::InterruptHandler<peripherals::RNG>;
29}); 30});
30 31
31#[embassy_executor::main] 32#[embassy_executor::main]
@@ -58,7 +59,7 @@ async fn main(_spawner: Spawner) {
58 }; 59 };
59 let radio = LoRaRadio::new(lora); 60 let radio = LoRaRadio::new(lora);
60 let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); 61 let region: region::Configuration = region::Configuration::new(LORAWAN_REGION);
61 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG)); 62 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs));
62 63
63 defmt::info!("Joining LoRaWAN network"); 64 defmt::info!("Joining LoRaWAN network");
64 65
diff --git a/examples/stm32wl/src/bin/random.rs b/examples/stm32wl/src/bin/random.rs
index d8562fca5..592e65f40 100644
--- a/examples/stm32wl/src/bin/random.rs
+++ b/examples/stm32wl/src/bin/random.rs
@@ -4,10 +4,14 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::pac; 7use embassy_stm32::rng::{self, Rng};
8use embassy_stm32::rng::Rng; 8use embassy_stm32::{bind_interrupts, pac, peripherals};
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
11bind_interrupts!(struct Irqs{
12 RNG => rng::InterruptHandler<peripherals::RNG>;
13});
14
11#[embassy_executor::main] 15#[embassy_executor::main]
12async fn main(_spawner: Spawner) { 16async fn main(_spawner: Spawner) {
13 let mut config = embassy_stm32::Config::default(); 17 let mut config = embassy_stm32::Config::default();
@@ -21,7 +25,7 @@ async fn main(_spawner: Spawner) {
21 25
22 info!("Hello World!"); 26 info!("Hello World!");
23 27
24 let mut rng = Rng::new(p.RNG); 28 let mut rng = Rng::new(p.RNG, Irqs);
25 29
26 let mut buf = [0u8; 16]; 30 let mut buf = [0u8; 16];
27 unwrap!(rng.async_fill_bytes(&mut buf).await); 31 unwrap!(rng.async_fill_bytes(&mut buf).await);
diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml
index 3679e3857..2791cc341 100644
--- a/examples/wasm/Cargo.toml
+++ b/examples/wasm/Cargo.toml
@@ -17,3 +17,6 @@ wasm-bindgen = "0.2"
17web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } 17web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] }
18log = "0.4.11" 18log = "0.4.11"
19critical-section = { version = "1.1", features = ["std"] } 19critical-section = { version = "1.1", features = ["std"] }
20
21[profile.release]
22debug = 2