diff options
Diffstat (limited to 'examples')
72 files changed, 640 insertions, 527 deletions
diff --git a/examples/boot/bootloader/rp/Cargo.toml b/examples/boot/bootloader/rp/Cargo.toml index 8d60f18be..c1dc99eec 100644 --- a/examples/boot/bootloader/rp/Cargo.toml +++ b/examples/boot/bootloader/rp/Cargo.toml | |||
| @@ -30,3 +30,4 @@ debug = ["defmt-rtt", "defmt"] | |||
| 30 | 30 | ||
| 31 | [profile.release] | 31 | [profile.release] |
| 32 | debug = true | 32 | debug = true |
| 33 | opt-level = 's' | ||
diff --git a/examples/nrf52840-rtic/.cargo/config.toml b/examples/nrf52840-rtic/.cargo/config.toml new file mode 100644 index 000000000..3872e7189 --- /dev/null +++ b/examples/nrf52840-rtic/.cargo/config.toml | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace nRF82840_xxAA with your chip as listed in `probe-rs-cli chip list` | ||
| 3 | runner = "probe-rs-cli run --chip nRF52840_xxAA" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabi" | ||
| 7 | |||
| 8 | [env] | ||
| 9 | DEFMT_LOG = "trace" | ||
diff --git a/examples/nrf52840-rtic/Cargo.toml b/examples/nrf52840-rtic/Cargo.toml new file mode 100644 index 000000000..0f9048b0f --- /dev/null +++ b/examples/nrf52840-rtic/Cargo.toml | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "embassy-nrf52840-rtic-examples" | ||
| 4 | version = "0.1.0" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | rtic = { version = "2", features = ["thumbv7-backend"] } | ||
| 9 | |||
| 10 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | ||
| 11 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | ||
| 12 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "generic-queue"] } | ||
| 13 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nightly", "unstable-traits", "defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } | ||
| 14 | |||
| 15 | defmt = "0.3" | ||
| 16 | defmt-rtt = "0.4" | ||
| 17 | |||
| 18 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | ||
| 19 | cortex-m-rt = "0.7.0" | ||
| 20 | panic-probe = { version = "0.3", features = ["print-defmt"] } | ||
| 21 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | ||
diff --git a/examples/nrf52840-rtic/build.rs b/examples/nrf52840-rtic/build.rs new file mode 100644 index 000000000..30691aa97 --- /dev/null +++ b/examples/nrf52840-rtic/build.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 35 | } | ||
diff --git a/examples/nrf52840-rtic/memory.x b/examples/nrf52840-rtic/memory.x new file mode 100644 index 000000000..9b04edec0 --- /dev/null +++ b/examples/nrf52840-rtic/memory.x | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */ | ||
| 5 | FLASH : ORIGIN = 0x00000000, LENGTH = 1024K | ||
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
| 7 | } | ||
diff --git a/examples/nrf52840-rtic/src/bin/blinky.rs b/examples/nrf52840-rtic/src/bin/blinky.rs new file mode 100644 index 000000000..a682c1932 --- /dev/null +++ b/examples/nrf52840-rtic/src/bin/blinky.rs | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use {defmt_rtt as _, panic_probe as _}; | ||
| 6 | |||
| 7 | #[rtic::app(device = embassy_nrf, peripherals = false, dispatchers = [SWI0_EGU0, SWI1_EGU1])] | ||
| 8 | mod app { | ||
| 9 | use defmt::info; | ||
| 10 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | ||
| 11 | use embassy_nrf::peripherals; | ||
| 12 | use embassy_time::{Duration, Timer}; | ||
| 13 | |||
| 14 | #[shared] | ||
| 15 | struct Shared {} | ||
| 16 | |||
| 17 | #[local] | ||
| 18 | struct Local {} | ||
| 19 | |||
| 20 | #[init] | ||
| 21 | fn init(_: init::Context) -> (Shared, Local) { | ||
| 22 | info!("Hello World!"); | ||
| 23 | |||
| 24 | let p = embassy_nrf::init(Default::default()); | ||
| 25 | blink::spawn(p.P0_13).map_err(|_| ()).unwrap(); | ||
| 26 | |||
| 27 | (Shared {}, Local {}) | ||
| 28 | } | ||
| 29 | |||
| 30 | #[task(priority = 1)] | ||
| 31 | async fn blink(_cx: blink::Context, pin: peripherals::P0_13) { | ||
| 32 | let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); | ||
| 33 | |||
| 34 | loop { | ||
| 35 | info!("off!"); | ||
| 36 | led.set_high(); | ||
| 37 | Timer::after(Duration::from_millis(300)).await; | ||
| 38 | info!("on!"); | ||
| 39 | led.set_low(); | ||
| 40 | Timer::after(Duration::from_millis(300)).await; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index 0f75b3ab7..6627b7861 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [features] | 7 | [features] |
| 8 | default = ["nightly"] | 8 | default = ["nightly"] |
| 9 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-time/nightly", "embassy-time/unstable-traits", | 9 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-time/nightly", "embassy-time/unstable-traits", "static_cell/nightly", |
| 10 | "embassy-usb", "embedded-io/async", "embassy-net", "embassy-lora", "lora-phy", "lorawan-device", "lorawan"] | 10 | "embassy-usb", "embedded-io/async", "embassy-net", "embassy-lora", "lora-phy", "lorawan-device", "lorawan"] |
| 11 | 11 | ||
| 12 | [dependencies] | 12 | [dependencies] |
| @@ -26,7 +26,7 @@ lorawan = { version = "0.7.3", default-features = false, features = ["default-cr | |||
| 26 | defmt = "0.3" | 26 | defmt = "0.3" |
| 27 | defmt-rtt = "0.4" | 27 | defmt-rtt = "0.4" |
| 28 | 28 | ||
| 29 | static_cell = "1.0" | 29 | static_cell = "1.1" |
| 30 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 30 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 31 | cortex-m-rt = "0.7.0" | 31 | cortex-m-rt = "0.7.0" |
| 32 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 32 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
diff --git a/examples/nrf52840/src/bin/multiprio.rs b/examples/nrf52840/src/bin/multiprio.rs index 851e189ea..aab819117 100644 --- a/examples/nrf52840/src/bin/multiprio.rs +++ b/examples/nrf52840/src/bin/multiprio.rs | |||
| @@ -57,14 +57,11 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 63 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 64 | use defmt::{info, unwrap}; | 61 | use defmt::{info, unwrap}; |
| 65 | use embassy_nrf::executor::{Executor, InterruptExecutor}; | 62 | use embassy_executor::{Executor, InterruptExecutor}; |
| 66 | use embassy_nrf::interrupt; | 63 | use embassy_nrf::interrupt; |
| 67 | use embassy_nrf::pac::Interrupt; | 64 | use embassy_nrf::interrupt::{InterruptExt, Priority}; |
| 68 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 69 | use static_cell::StaticCell; | 66 | use static_cell::StaticCell; |
| 70 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -130,16 +127,15 @@ fn main() -> ! { | |||
| 130 | info!("Hello World!"); | 127 | info!("Hello World!"); |
| 131 | 128 | ||
| 132 | let _p = embassy_nrf::init(Default::default()); | 129 | let _p = embassy_nrf::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 134 | 130 | ||
| 135 | // High-priority executor: SWI1_EGU1, priority level 6 | 131 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 136 | unsafe { nvic.set_priority(Interrupt::SWI1_EGU1, 6 << 5) }; | 132 | interrupt::SWI1_EGU1.set_priority(Priority::P6); |
| 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::SWI1_EGU1); | 133 | let spawner = EXECUTOR_HIGH.start(interrupt::SWI1_EGU1); |
| 138 | unwrap!(spawner.spawn(run_high())); | 134 | unwrap!(spawner.spawn(run_high())); |
| 139 | 135 | ||
| 140 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 136 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 141 | unsafe { nvic.set_priority(Interrupt::SWI0_EGU0, 7 << 5) }; | 137 | interrupt::SWI0_EGU0.set_priority(Priority::P7); |
| 142 | let spawner = EXECUTOR_MED.start(Interrupt::SWI0_EGU0); | 138 | let spawner = EXECUTOR_MED.start(interrupt::SWI0_EGU0); |
| 143 | unwrap!(spawner.spawn(run_med())); | 139 | unwrap!(spawner.spawn(run_med())); |
| 144 | 140 | ||
| 145 | // Low priority executor: runs in thread mode, using WFE/SEV | 141 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs index 786025c43..f527c0d7f 100644 --- a/examples/nrf52840/src/bin/usb_ethernet.rs +++ b/examples/nrf52840/src/bin/usb_ethernet.rs | |||
| @@ -16,7 +16,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState | |||
| 16 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; | 16 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; |
| 17 | use embassy_usb::{Builder, Config, UsbDevice}; | 17 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 18 | use embedded_io::asynch::Write; | 18 | use embedded_io::asynch::Write; |
| 19 | use static_cell::StaticCell; | 19 | use static_cell::make_static; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | 21 | ||
| 22 | bind_interrupts!(struct Irqs { | 22 | bind_interrupts!(struct Irqs { |
| @@ -27,15 +27,6 @@ bind_interrupts!(struct Irqs { | |||
| 27 | 27 | ||
| 28 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; | 28 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; |
| 29 | 29 | ||
| 30 | macro_rules! singleton { | ||
| 31 | ($val:expr) => {{ | ||
| 32 | type T = impl Sized; | ||
| 33 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 34 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 35 | x | ||
| 36 | }}; | ||
| 37 | } | ||
| 38 | |||
| 39 | const MTU: usize = 1514; | 30 | const MTU: usize = 1514; |
| 40 | 31 | ||
| 41 | #[embassy_executor::task] | 32 | #[embassy_executor::task] |
| @@ -83,11 +74,11 @@ async fn main(spawner: Spawner) { | |||
| 83 | let mut builder = Builder::new( | 74 | let mut builder = Builder::new( |
| 84 | driver, | 75 | driver, |
| 85 | config, | 76 | config, |
| 86 | &mut singleton!([0; 256])[..], | 77 | &mut make_static!([0; 256])[..], |
| 87 | &mut singleton!([0; 256])[..], | 78 | &mut make_static!([0; 256])[..], |
| 88 | &mut singleton!([0; 256])[..], | 79 | &mut make_static!([0; 256])[..], |
| 89 | &mut singleton!([0; 128])[..], | 80 | &mut make_static!([0; 128])[..], |
| 90 | &mut singleton!([0; 128])[..], | 81 | &mut make_static!([0; 128])[..], |
| 91 | ); | 82 | ); |
| 92 | 83 | ||
| 93 | // Our MAC addr. | 84 | // Our MAC addr. |
| @@ -96,22 +87,22 @@ async fn main(spawner: Spawner) { | |||
| 96 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; | 87 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; |
| 97 | 88 | ||
| 98 | // Create classes on the builder. | 89 | // Create classes on the builder. |
| 99 | let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); | 90 | let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); |
| 100 | 91 | ||
| 101 | // Build the builder. | 92 | // Build the builder. |
| 102 | let usb = builder.build(); | 93 | let usb = builder.build(); |
| 103 | 94 | ||
| 104 | unwrap!(spawner.spawn(usb_task(usb))); | 95 | unwrap!(spawner.spawn(usb_task(usb))); |
| 105 | 96 | ||
| 106 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); | 97 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); |
| 107 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 98 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 108 | 99 | ||
| 109 | let config = embassy_net::Config::Dhcp(Default::default()); | 100 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 110 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 101 | // let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 111 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 102 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 112 | // dns_servers: Vec::new(), | 103 | // dns_servers: Vec::new(), |
| 113 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 104 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| 114 | //}); | 105 | // }); |
| 115 | 106 | ||
| 116 | // Generate random seed | 107 | // Generate random seed |
| 117 | let mut rng = Rng::new(p.RNG, Irqs); | 108 | let mut rng = Rng::new(p.RNG, Irqs); |
| @@ -120,7 +111,12 @@ async fn main(spawner: Spawner) { | |||
| 120 | let seed = u64::from_le_bytes(seed); | 111 | let seed = u64::from_le_bytes(seed); |
| 121 | 112 | ||
| 122 | // Init network stack | 113 | // Init network stack |
| 123 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 114 | let stack = &*make_static!(Stack::new( |
| 115 | device, | ||
| 116 | config, | ||
| 117 | make_static!(StackResources::<2>::new()), | ||
| 118 | seed | ||
| 119 | )); | ||
| 124 | 120 | ||
| 125 | unwrap!(spawner.spawn(net_task(stack))); | 121 | unwrap!(spawner.spawn(net_task(stack))); |
| 126 | 122 | ||
diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs index ac22d9499..cd4392903 100644 --- a/examples/nrf52840/src/bin/usb_serial_multitask.rs +++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs | |||
| @@ -12,7 +12,7 @@ use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | |||
| 12 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 12 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 13 | use embassy_usb::driver::EndpointError; | 13 | use embassy_usb::driver::EndpointError; |
| 14 | use embassy_usb::{Builder, Config, UsbDevice}; | 14 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 15 | use static_cell::StaticCell; | 15 | use static_cell::make_static; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | bind_interrupts!(struct Irqs { | 18 | bind_interrupts!(struct Irqs { |
| @@ -20,15 +20,6 @@ bind_interrupts!(struct Irqs { | |||
| 20 | POWER_CLOCK => usb::vbus_detect::InterruptHandler; | 20 | POWER_CLOCK => usb::vbus_detect::InterruptHandler; |
| 21 | }); | 21 | }); |
| 22 | 22 | ||
| 23 | macro_rules! singleton { | ||
| 24 | ($val:expr) => {{ | ||
| 25 | type T = impl Sized; | ||
| 26 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 27 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 28 | x | ||
| 29 | }}; | ||
| 30 | } | ||
| 31 | |||
| 32 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; | 23 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; |
| 33 | 24 | ||
| 34 | #[embassy_executor::task] | 25 | #[embassy_executor::task] |
| @@ -73,17 +64,17 @@ async fn main(spawner: Spawner) { | |||
| 73 | config.device_protocol = 0x01; | 64 | config.device_protocol = 0x01; |
| 74 | config.composite_with_iads = true; | 65 | config.composite_with_iads = true; |
| 75 | 66 | ||
| 76 | let state = singleton!(State::new()); | 67 | let state = make_static!(State::new()); |
| 77 | 68 | ||
| 78 | // Create embassy-usb DeviceBuilder using the driver and config. | 69 | // Create embassy-usb DeviceBuilder using the driver and config. |
| 79 | let mut builder = Builder::new( | 70 | let mut builder = Builder::new( |
| 80 | driver, | 71 | driver, |
| 81 | config, | 72 | config, |
| 82 | &mut singleton!([0; 256])[..], | 73 | &mut make_static!([0; 256])[..], |
| 83 | &mut singleton!([0; 256])[..], | 74 | &mut make_static!([0; 256])[..], |
| 84 | &mut singleton!([0; 256])[..], | 75 | &mut make_static!([0; 256])[..], |
| 85 | &mut singleton!([0; 128])[..], | 76 | &mut make_static!([0; 128])[..], |
| 86 | &mut singleton!([0; 128])[..], | 77 | &mut make_static!([0; 128])[..], |
| 87 | ); | 78 | ); |
| 88 | 79 | ||
| 89 | // Create classes on the builder. | 80 | // Create classes on the builder. |
diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml index 40422e7df..efb66bae6 100644 --- a/examples/nrf5340/Cargo.toml +++ b/examples/nrf5340/Cargo.toml | |||
| @@ -42,7 +42,7 @@ embedded-io = { version = "0.4.0", features = [ "async" ]} | |||
| 42 | defmt = "0.3" | 42 | defmt = "0.3" |
| 43 | defmt-rtt = "0.4" | 43 | defmt-rtt = "0.4" |
| 44 | 44 | ||
| 45 | static_cell = "1.0" | 45 | static_cell = { version = "1.1", features = ["nightly"]} |
| 46 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 46 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 47 | cortex-m-rt = "0.7.0" | 47 | cortex-m-rt = "0.7.0" |
| 48 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 48 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 58b701915..48f3a26bb 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml | |||
| @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" | |||
| 8 | [dependencies] | 8 | [dependencies] |
| 9 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal", features = ["defmt"] } | 9 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal", features = ["defmt"] } |
| 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime"] } | 12 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime"] } |
| 13 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "critical-section-impl"] } | 13 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "critical-section-impl"] } |
| 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 14 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| @@ -45,7 +45,7 @@ embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" } | |||
| 45 | embedded-hal-async = "0.2.0-alpha.1" | 45 | embedded-hal-async = "0.2.0-alpha.1" |
| 46 | embedded-io = { version = "0.4.0", features = ["async", "defmt"] } | 46 | embedded-io = { version = "0.4.0", features = ["async", "defmt"] } |
| 47 | embedded-storage = { version = "0.3" } | 47 | embedded-storage = { version = "0.3" } |
| 48 | static_cell = "1.0.0" | 48 | static_cell = { version = "1.1", features = ["nightly"]} |
| 49 | log = "0.4" | 49 | log = "0.4" |
| 50 | pio-proc = "0.2" | 50 | pio-proc = "0.2" |
| 51 | pio = "0.2.1" | 51 | pio = "0.2.1" |
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs index c5422c616..0d246c093 100644 --- a/examples/rp/src/bin/button.rs +++ b/examples/rp/src/bin/button.rs | |||
| @@ -9,9 +9,12 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 9 | #[embassy_executor::main] | 9 | #[embassy_executor::main] |
| 10 | async fn main(_spawner: Spawner) { | 10 | async fn main(_spawner: Spawner) { |
| 11 | let p = embassy_rp::init(Default::default()); | 11 | let p = embassy_rp::init(Default::default()); |
| 12 | let button = Input::new(p.PIN_28, Pull::Up); | ||
| 13 | let mut led = Output::new(p.PIN_25, Level::Low); | 12 | let mut led = Output::new(p.PIN_25, Level::Low); |
| 14 | 13 | ||
| 14 | // Use PIN_28, Pin34 on J0 for RP Pico, as a input. | ||
| 15 | // You need to add your own button. | ||
| 16 | let button = Input::new(p.PIN_28, Pull::Up); | ||
| 17 | |||
| 15 | loop { | 18 | loop { |
| 16 | if button.is_high() { | 19 | if button.is_high() { |
| 17 | led.set_high(); | 20 | led.set_high(); |
diff --git a/examples/rp/src/bin/ethernet_w5500_multisocket.rs b/examples/rp/src/bin/ethernet_w5500_multisocket.rs index c8e6d46a6..82568254a 100644 --- a/examples/rp/src/bin/ethernet_w5500_multisocket.rs +++ b/examples/rp/src/bin/ethernet_w5500_multisocket.rs | |||
| @@ -19,18 +19,9 @@ use embassy_time::Duration; | |||
| 19 | use embedded_hal_async::spi::ExclusiveDevice; | 19 | use embedded_hal_async::spi::ExclusiveDevice; |
| 20 | use embedded_io::asynch::Write; | 20 | use embedded_io::asynch::Write; |
| 21 | use rand::RngCore; | 21 | use rand::RngCore; |
| 22 | use static_cell::StaticCell; | 22 | use static_cell::make_static; |
| 23 | use {defmt_rtt as _, panic_probe as _}; | 23 | use {defmt_rtt as _, panic_probe as _}; |
| 24 | 24 | ||
| 25 | macro_rules! singleton { | ||
| 26 | ($val:expr) => {{ | ||
| 27 | type T = impl Sized; | ||
| 28 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 29 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 30 | x | ||
| 31 | }}; | ||
| 32 | } | ||
| 33 | |||
| 34 | #[embassy_executor::task] | 25 | #[embassy_executor::task] |
| 35 | async fn ethernet_task( | 26 | async fn ethernet_task( |
| 36 | runner: Runner< | 27 | runner: Runner< |
| @@ -62,7 +53,7 @@ async fn main(spawner: Spawner) { | |||
| 62 | let w5500_reset = Output::new(p.PIN_20, Level::High); | 53 | let w5500_reset = Output::new(p.PIN_20, Level::High); |
| 63 | 54 | ||
| 64 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; | 55 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 65 | let state = singleton!(State::<8, 8>::new()); | 56 | let state = make_static!(State::<8, 8>::new()); |
| 66 | let (device, runner) = | 57 | let (device, runner) = |
| 67 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; | 58 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; |
| 68 | unwrap!(spawner.spawn(ethernet_task(runner))); | 59 | unwrap!(spawner.spawn(ethernet_task(runner))); |
| @@ -71,10 +62,10 @@ async fn main(spawner: Spawner) { | |||
| 71 | let seed = rng.next_u64(); | 62 | let seed = rng.next_u64(); |
| 72 | 63 | ||
| 73 | // Init network stack | 64 | // Init network stack |
| 74 | let stack = &*singleton!(Stack::new( | 65 | let stack = &*make_static!(Stack::new( |
| 75 | device, | 66 | device, |
| 76 | embassy_net::Config::Dhcp(Default::default()), | 67 | embassy_net::Config::dhcpv4(Default::default()), |
| 77 | singleton!(StackResources::<3>::new()), | 68 | make_static!(StackResources::<3>::new()), |
| 78 | seed | 69 | seed |
| 79 | )); | 70 | )); |
| 80 | 71 | ||
| @@ -129,9 +120,9 @@ async fn listen_task(stack: &'static Stack<Device<'static>>, id: u8, port: u16) | |||
| 129 | } | 120 | } |
| 130 | } | 121 | } |
| 131 | 122 | ||
| 132 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { | 123 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 { |
| 133 | loop { | 124 | loop { |
| 134 | if let Some(config) = stack.config() { | 125 | if let Some(config) = stack.config_v4() { |
| 135 | return config.clone(); | 126 | return config.clone(); |
| 136 | } | 127 | } |
| 137 | yield_now().await; | 128 | yield_now().await; |
diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs index 9a7c3ad19..d562defad 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs | |||
| @@ -21,18 +21,9 @@ use embassy_time::{Duration, Timer}; | |||
| 21 | use embedded_hal_async::spi::ExclusiveDevice; | 21 | use embedded_hal_async::spi::ExclusiveDevice; |
| 22 | use embedded_io::asynch::Write; | 22 | use embedded_io::asynch::Write; |
| 23 | use rand::RngCore; | 23 | use rand::RngCore; |
| 24 | use static_cell::StaticCell; | 24 | use static_cell::make_static; |
| 25 | use {defmt_rtt as _, panic_probe as _}; | 25 | use {defmt_rtt as _, panic_probe as _}; |
| 26 | 26 | ||
| 27 | macro_rules! singleton { | ||
| 28 | ($val:expr) => {{ | ||
| 29 | type T = impl Sized; | ||
| 30 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 31 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 32 | x | ||
| 33 | }}; | ||
| 34 | } | ||
| 35 | |||
| 36 | #[embassy_executor::task] | 27 | #[embassy_executor::task] |
| 37 | async fn ethernet_task( | 28 | async fn ethernet_task( |
| 38 | runner: Runner< | 29 | runner: Runner< |
| @@ -65,7 +56,7 @@ async fn main(spawner: Spawner) { | |||
| 65 | let w5500_reset = Output::new(p.PIN_20, Level::High); | 56 | let w5500_reset = Output::new(p.PIN_20, Level::High); |
| 66 | 57 | ||
| 67 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; | 58 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 68 | let state = singleton!(State::<8, 8>::new()); | 59 | let state = make_static!(State::<8, 8>::new()); |
| 69 | let (device, runner) = | 60 | let (device, runner) = |
| 70 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; | 61 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; |
| 71 | unwrap!(spawner.spawn(ethernet_task(runner))); | 62 | unwrap!(spawner.spawn(ethernet_task(runner))); |
| @@ -74,10 +65,10 @@ async fn main(spawner: Spawner) { | |||
| 74 | let seed = rng.next_u64(); | 65 | let seed = rng.next_u64(); |
| 75 | 66 | ||
| 76 | // Init network stack | 67 | // Init network stack |
| 77 | let stack = &*singleton!(Stack::new( | 68 | let stack = &*make_static!(Stack::new( |
| 78 | device, | 69 | device, |
| 79 | embassy_net::Config::Dhcp(Default::default()), | 70 | embassy_net::Config::dhcpv4(Default::default()), |
| 80 | singleton!(StackResources::<2>::new()), | 71 | make_static!(StackResources::<2>::new()), |
| 81 | seed | 72 | seed |
| 82 | )); | 73 | )); |
| 83 | 74 | ||
| @@ -117,9 +108,9 @@ async fn main(spawner: Spawner) { | |||
| 117 | } | 108 | } |
| 118 | } | 109 | } |
| 119 | 110 | ||
| 120 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { | 111 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 { |
| 121 | loop { | 112 | loop { |
| 122 | if let Some(config) = stack.config() { | 113 | if let Some(config) = stack.config_v4() { |
| 123 | return config.clone(); | 114 | return config.clone(); |
| 124 | } | 115 | } |
| 125 | yield_now().await; | 116 | yield_now().await; |
diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs index f02543246..7f521cdb4 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs | |||
| @@ -20,18 +20,8 @@ use embassy_time::Duration; | |||
| 20 | use embedded_hal_async::spi::ExclusiveDevice; | 20 | use embedded_hal_async::spi::ExclusiveDevice; |
| 21 | use embedded_io::asynch::Write; | 21 | use embedded_io::asynch::Write; |
| 22 | use rand::RngCore; | 22 | use rand::RngCore; |
| 23 | use static_cell::StaticCell; | 23 | use static_cell::make_static; |
| 24 | use {defmt_rtt as _, panic_probe as _}; | 24 | use {defmt_rtt as _, panic_probe as _}; |
| 25 | |||
| 26 | macro_rules! singleton { | ||
| 27 | ($val:expr) => {{ | ||
| 28 | type T = impl Sized; | ||
| 29 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 30 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 31 | x | ||
| 32 | }}; | ||
| 33 | } | ||
| 34 | |||
| 35 | #[embassy_executor::task] | 25 | #[embassy_executor::task] |
| 36 | async fn ethernet_task( | 26 | async fn ethernet_task( |
| 37 | runner: Runner< | 27 | runner: Runner< |
| @@ -64,7 +54,7 @@ async fn main(spawner: Spawner) { | |||
| 64 | let w5500_reset = Output::new(p.PIN_20, Level::High); | 54 | let w5500_reset = Output::new(p.PIN_20, Level::High); |
| 65 | 55 | ||
| 66 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; | 56 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 67 | let state = singleton!(State::<8, 8>::new()); | 57 | let state = make_static!(State::<8, 8>::new()); |
| 68 | let (device, runner) = | 58 | let (device, runner) = |
| 69 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; | 59 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; |
| 70 | unwrap!(spawner.spawn(ethernet_task(runner))); | 60 | unwrap!(spawner.spawn(ethernet_task(runner))); |
| @@ -73,10 +63,10 @@ async fn main(spawner: Spawner) { | |||
| 73 | let seed = rng.next_u64(); | 63 | let seed = rng.next_u64(); |
| 74 | 64 | ||
| 75 | // Init network stack | 65 | // Init network stack |
| 76 | let stack = &*singleton!(Stack::new( | 66 | let stack = &*make_static!(Stack::new( |
| 77 | device, | 67 | device, |
| 78 | embassy_net::Config::Dhcp(Default::default()), | 68 | embassy_net::Config::dhcpv4(Default::default()), |
| 79 | singleton!(StackResources::<2>::new()), | 69 | make_static!(StackResources::<2>::new()), |
| 80 | seed | 70 | seed |
| 81 | )); | 71 | )); |
| 82 | 72 | ||
| @@ -126,9 +116,9 @@ async fn main(spawner: Spawner) { | |||
| 126 | } | 116 | } |
| 127 | } | 117 | } |
| 128 | 118 | ||
| 129 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { | 119 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 { |
| 130 | loop { | 120 | loop { |
| 131 | if let Some(config) = stack.config() { | 121 | if let Some(config) = stack.config_v4() { |
| 132 | return config.clone(); | 122 | return config.clone(); |
| 133 | } | 123 | } |
| 134 | yield_now().await; | 124 | yield_now().await; |
diff --git a/examples/rp/src/bin/ethernet_w5500_udp.rs b/examples/rp/src/bin/ethernet_w5500_udp.rs index 2c54f711e..ada86ae55 100644 --- a/examples/rp/src/bin/ethernet_w5500_udp.rs +++ b/examples/rp/src/bin/ethernet_w5500_udp.rs | |||
| @@ -18,18 +18,8 @@ use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0}; | |||
| 18 | use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; | 18 | use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; |
| 19 | use embedded_hal_async::spi::ExclusiveDevice; | 19 | use embedded_hal_async::spi::ExclusiveDevice; |
| 20 | use rand::RngCore; | 20 | use rand::RngCore; |
| 21 | use static_cell::StaticCell; | 21 | use static_cell::make_static; |
| 22 | use {defmt_rtt as _, panic_probe as _}; | 22 | use {defmt_rtt as _, panic_probe as _}; |
| 23 | |||
| 24 | macro_rules! singleton { | ||
| 25 | ($val:expr) => {{ | ||
| 26 | type T = impl Sized; | ||
| 27 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 28 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 29 | x | ||
| 30 | }}; | ||
| 31 | } | ||
| 32 | |||
| 33 | #[embassy_executor::task] | 23 | #[embassy_executor::task] |
| 34 | async fn ethernet_task( | 24 | async fn ethernet_task( |
| 35 | runner: Runner< | 25 | runner: Runner< |
| @@ -61,7 +51,7 @@ async fn main(spawner: Spawner) { | |||
| 61 | let w5500_reset = Output::new(p.PIN_20, Level::High); | 51 | let w5500_reset = Output::new(p.PIN_20, Level::High); |
| 62 | 52 | ||
| 63 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; | 53 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 64 | let state = singleton!(State::<8, 8>::new()); | 54 | let state = make_static!(State::<8, 8>::new()); |
| 65 | let (device, runner) = | 55 | let (device, runner) = |
| 66 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; | 56 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; |
| 67 | unwrap!(spawner.spawn(ethernet_task(runner))); | 57 | unwrap!(spawner.spawn(ethernet_task(runner))); |
| @@ -70,10 +60,10 @@ async fn main(spawner: Spawner) { | |||
| 70 | let seed = rng.next_u64(); | 60 | let seed = rng.next_u64(); |
| 71 | 61 | ||
| 72 | // Init network stack | 62 | // Init network stack |
| 73 | let stack = &*singleton!(Stack::new( | 63 | let stack = &*make_static!(Stack::new( |
| 74 | device, | 64 | device, |
| 75 | embassy_net::Config::Dhcp(Default::default()), | 65 | embassy_net::Config::dhcpv4(Default::default()), |
| 76 | singleton!(StackResources::<2>::new()), | 66 | make_static!(StackResources::<2>::new()), |
| 77 | seed | 67 | seed |
| 78 | )); | 68 | )); |
| 79 | 69 | ||
| @@ -105,9 +95,9 @@ async fn main(spawner: Spawner) { | |||
| 105 | } | 95 | } |
| 106 | } | 96 | } |
| 107 | 97 | ||
| 108 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { | 98 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 { |
| 109 | loop { | 99 | loop { |
| 110 | if let Some(config) = stack.config() { | 100 | if let Some(config) = stack.config_v4() { |
| 111 | return config.clone(); | 101 | return config.clone(); |
| 112 | } | 102 | } |
| 113 | yield_now().await; | 103 | yield_now().await; |
diff --git a/examples/rp/src/bin/lora_p2p_send_multicore.rs b/examples/rp/src/bin/lora_p2p_send_multicore.rs index 5585606d8..eef2f7a53 100644 --- a/examples/rp/src/bin/lora_p2p_send_multicore.rs +++ b/examples/rp/src/bin/lora_p2p_send_multicore.rs | |||
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | use defmt::*; | 8 | use defmt::*; |
| 9 | use embassy_executor::Executor; | 9 | use embassy_executor::Executor; |
| 10 | use embassy_executor::_export::StaticCell; | ||
| 11 | use embassy_lora::iv::GenericSx126xInterfaceVariant; | 10 | use embassy_lora::iv::GenericSx126xInterfaceVariant; |
| 12 | use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pin, Pull}; | 11 | use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pin, Pull}; |
| 13 | use embassy_rp::multicore::{spawn_core1, Stack}; | 12 | use embassy_rp::multicore::{spawn_core1, Stack}; |
| @@ -19,6 +18,7 @@ use embassy_time::{Delay, Duration, Timer}; | |||
| 19 | use lora_phy::mod_params::*; | 18 | use lora_phy::mod_params::*; |
| 20 | use lora_phy::sx1261_2::SX1261_2; | 19 | use lora_phy::sx1261_2::SX1261_2; |
| 21 | use lora_phy::LoRa; | 20 | use lora_phy::LoRa; |
| 21 | use static_cell::StaticCell; | ||
| 22 | use {defmt_rtt as _, panic_probe as _}; | 22 | use {defmt_rtt as _, panic_probe as _}; |
| 23 | 23 | ||
| 24 | static mut CORE1_STACK: Stack<4096> = Stack::new(); | 24 | static mut CORE1_STACK: Stack<4096> = Stack::new(); |
diff --git a/examples/rp/src/bin/multicore.rs b/examples/rp/src/bin/multicore.rs index 376b2b61e..57278dd6c 100644 --- a/examples/rp/src/bin/multicore.rs +++ b/examples/rp/src/bin/multicore.rs | |||
| @@ -4,13 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Executor; | 6 | use embassy_executor::Executor; |
| 7 | use embassy_executor::_export::StaticCell; | ||
| 8 | use embassy_rp::gpio::{Level, Output}; | 7 | use embassy_rp::gpio::{Level, Output}; |
| 9 | use embassy_rp::multicore::{spawn_core1, Stack}; | 8 | use embassy_rp::multicore::{spawn_core1, Stack}; |
| 10 | use embassy_rp::peripherals::PIN_25; | 9 | use embassy_rp::peripherals::PIN_25; |
| 11 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 10 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 12 | use embassy_sync::channel::Channel; | 11 | use embassy_sync::channel::Channel; |
| 13 | use embassy_time::{Duration, Timer}; | 12 | use embassy_time::{Duration, Timer}; |
| 13 | use static_cell::StaticCell; | ||
| 14 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 15 | ||
| 16 | static mut CORE1_STACK: Stack<4096> = Stack::new(); | 16 | static mut CORE1_STACK: Stack<4096> = Stack::new(); |
diff --git a/examples/rp/src/bin/multiprio.rs b/examples/rp/src/bin/multiprio.rs index 2f79ba49e..9ace4cd68 100644 --- a/examples/rp/src/bin/multiprio.rs +++ b/examples/rp/src/bin/multiprio.rs | |||
| @@ -57,14 +57,11 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 63 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 64 | use defmt::{info, unwrap}; | 61 | use defmt::{info, unwrap}; |
| 65 | use embassy_rp::executor::{Executor, InterruptExecutor}; | 62 | use embassy_executor::{Executor, InterruptExecutor}; |
| 66 | use embassy_rp::interrupt; | 63 | use embassy_rp::interrupt; |
| 67 | use embassy_rp::pac::Interrupt; | 64 | use embassy_rp::interrupt::{InterruptExt, Priority}; |
| 68 | use embassy_time::{Duration, Instant, Timer, TICK_HZ}; | 65 | use embassy_time::{Duration, Instant, Timer, TICK_HZ}; |
| 69 | use static_cell::StaticCell; | 66 | use static_cell::StaticCell; |
| 70 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -130,18 +127,15 @@ fn main() -> ! { | |||
| 130 | info!("Hello World!"); | 127 | info!("Hello World!"); |
| 131 | 128 | ||
| 132 | let _p = embassy_rp::init(Default::default()); | 129 | let _p = embassy_rp::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 134 | 130 | ||
| 135 | // High-priority executor: SWI_IRQ_1, priority level 2 | 131 | // High-priority executor: SWI_IRQ_1, priority level 2 |
| 136 | unsafe { nvic.set_priority(Interrupt::SWI_IRQ_1, 2 << 6) }; | 132 | interrupt::SWI_IRQ_1.set_priority(Priority::P2); |
| 137 | info!("bla: {}", NVIC::get_priority(Interrupt::SWI_IRQ_1)); | 133 | let spawner = EXECUTOR_HIGH.start(interrupt::SWI_IRQ_1); |
| 138 | let spawner = EXECUTOR_HIGH.start(Interrupt::SWI_IRQ_1); | ||
| 139 | unwrap!(spawner.spawn(run_high())); | 134 | unwrap!(spawner.spawn(run_high())); |
| 140 | 135 | ||
| 141 | // Medium-priority executor: SWI_IRQ_0, priority level 3 | 136 | // Medium-priority executor: SWI_IRQ_0, priority level 3 |
| 142 | unsafe { nvic.set_priority(Interrupt::SWI_IRQ_0, 3 << 6) }; | 137 | interrupt::SWI_IRQ_0.set_priority(Priority::P3); |
| 143 | info!("bla: {}", NVIC::get_priority(Interrupt::SWI_IRQ_0)); | 138 | let spawner = EXECUTOR_MED.start(interrupt::SWI_IRQ_0); |
| 144 | let spawner = EXECUTOR_MED.start(Interrupt::SWI_IRQ_0); | ||
| 145 | unwrap!(spawner.spawn(run_med())); | 139 | unwrap!(spawner.spawn(run_med())); |
| 146 | 140 | ||
| 147 | // Low priority executor: runs in thread mode, using WFE/SEV | 141 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs index d6f01b4de..9df99bd58 100644 --- a/examples/rp/src/bin/uart_buffered_split.rs +++ b/examples/rp/src/bin/uart_buffered_split.rs | |||
| @@ -4,34 +4,25 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_executor::_export::StaticCell; | ||
| 8 | use embassy_rp::bind_interrupts; | 7 | use embassy_rp::bind_interrupts; |
| 9 | use embassy_rp::peripherals::UART0; | 8 | use embassy_rp::peripherals::UART0; |
| 10 | use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config}; | 9 | use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config}; |
| 11 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 12 | use embedded_io::asynch::{Read, Write}; | 11 | use embedded_io::asynch::{Read, Write}; |
| 12 | use static_cell::make_static; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | bind_interrupts!(struct Irqs { | 15 | bind_interrupts!(struct Irqs { |
| 16 | UART0_IRQ => BufferedInterruptHandler<UART0>; | 16 | UART0_IRQ => BufferedInterruptHandler<UART0>; |
| 17 | }); | 17 | }); |
| 18 | 18 | ||
| 19 | macro_rules! singleton { | ||
| 20 | ($val:expr) => {{ | ||
| 21 | type T = impl Sized; | ||
| 22 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 23 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 24 | x | ||
| 25 | }}; | ||
| 26 | } | ||
| 27 | |||
| 28 | #[embassy_executor::main] | 19 | #[embassy_executor::main] |
| 29 | async fn main(spawner: Spawner) { | 20 | async fn main(spawner: Spawner) { |
| 30 | let p = embassy_rp::init(Default::default()); | 21 | let p = embassy_rp::init(Default::default()); |
| 31 | let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0); | 22 | let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0); |
| 32 | 23 | ||
| 33 | let tx_buf = &mut singleton!([0u8; 16])[..]; | 24 | let tx_buf = &mut make_static!([0u8; 16])[..]; |
| 34 | let rx_buf = &mut singleton!([0u8; 16])[..]; | 25 | let rx_buf = &mut make_static!([0u8; 16])[..]; |
| 35 | let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default()); | 26 | let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default()); |
| 36 | let (rx, mut tx) = uart.split(); | 27 | let (rx, mut tx) = uart.split(); |
| 37 | 28 | ||
diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs index 38ff1620d..91d1ec8e7 100644 --- a/examples/rp/src/bin/usb_ethernet.rs +++ b/examples/rp/src/bin/usb_ethernet.rs | |||
| @@ -13,7 +13,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState | |||
| 13 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; | 13 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; |
| 14 | use embassy_usb::{Builder, Config, UsbDevice}; | 14 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 15 | use embedded_io::asynch::Write; | 15 | use embedded_io::asynch::Write; |
| 16 | use static_cell::StaticCell; | 16 | use static_cell::make_static; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 18 | ||
| 19 | bind_interrupts!(struct Irqs { | 19 | bind_interrupts!(struct Irqs { |
| @@ -22,15 +22,6 @@ bind_interrupts!(struct Irqs { | |||
| 22 | 22 | ||
| 23 | type MyDriver = Driver<'static, peripherals::USB>; | 23 | type MyDriver = Driver<'static, peripherals::USB>; |
| 24 | 24 | ||
| 25 | macro_rules! singleton { | ||
| 26 | ($val:expr) => {{ | ||
| 27 | type T = impl Sized; | ||
| 28 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 29 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 30 | x | ||
| 31 | }}; | ||
| 32 | } | ||
| 33 | |||
| 34 | const MTU: usize = 1514; | 25 | const MTU: usize = 1514; |
| 35 | 26 | ||
| 36 | #[embassy_executor::task] | 27 | #[embassy_executor::task] |
| @@ -73,10 +64,10 @@ async fn main(spawner: Spawner) { | |||
| 73 | let mut builder = Builder::new( | 64 | let mut builder = Builder::new( |
| 74 | driver, | 65 | driver, |
| 75 | config, | 66 | config, |
| 76 | &mut singleton!([0; 256])[..], | 67 | &mut make_static!([0; 256])[..], |
| 77 | &mut singleton!([0; 256])[..], | 68 | &mut make_static!([0; 256])[..], |
| 78 | &mut singleton!([0; 256])[..], | 69 | &mut make_static!([0; 256])[..], |
| 79 | &mut singleton!([0; 128])[..], | 70 | &mut make_static!([0; 128])[..], |
| 80 | ); | 71 | ); |
| 81 | 72 | ||
| 82 | // Our MAC addr. | 73 | // Our MAC addr. |
| @@ -85,18 +76,18 @@ async fn main(spawner: Spawner) { | |||
| 85 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; | 76 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; |
| 86 | 77 | ||
| 87 | // Create classes on the builder. | 78 | // Create classes on the builder. |
| 88 | let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); | 79 | let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); |
| 89 | 80 | ||
| 90 | // Build the builder. | 81 | // Build the builder. |
| 91 | let usb = builder.build(); | 82 | let usb = builder.build(); |
| 92 | 83 | ||
| 93 | unwrap!(spawner.spawn(usb_task(usb))); | 84 | unwrap!(spawner.spawn(usb_task(usb))); |
| 94 | 85 | ||
| 95 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); | 86 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); |
| 96 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 87 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 97 | 88 | ||
| 98 | let config = embassy_net::Config::Dhcp(Default::default()); | 89 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 99 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 90 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 100 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 91 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 101 | // dns_servers: Vec::new(), | 92 | // dns_servers: Vec::new(), |
| 102 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 93 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| @@ -106,7 +97,12 @@ async fn main(spawner: Spawner) { | |||
| 106 | let seed = 1234; // guaranteed random, chosen by a fair dice roll | 97 | let seed = 1234; // guaranteed random, chosen by a fair dice roll |
| 107 | 98 | ||
| 108 | // Init network stack | 99 | // Init network stack |
| 109 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 100 | let stack = &*make_static!(Stack::new( |
| 101 | device, | ||
| 102 | config, | ||
| 103 | make_static!(StackResources::<2>::new()), | ||
| 104 | seed | ||
| 105 | )); | ||
| 110 | 106 | ||
| 111 | unwrap!(spawner.spawn(net_task(stack))); | 107 | unwrap!(spawner.spawn(net_task(stack))); |
| 112 | 108 | ||
diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs index 15264524e..e8197390c 100644 --- a/examples/rp/src/bin/wifi_ap_tcp_server.rs +++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs | |||
| @@ -16,17 +16,9 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; | |||
| 16 | use embassy_rp::pio::Pio; | 16 | use embassy_rp::pio::Pio; |
| 17 | use embassy_time::Duration; | 17 | use embassy_time::Duration; |
| 18 | use embedded_io::asynch::Write; | 18 | use embedded_io::asynch::Write; |
| 19 | use static_cell::StaticCell; | 19 | use static_cell::make_static; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | 21 | ||
| 22 | macro_rules! singleton { | ||
| 23 | ($val:expr) => {{ | ||
| 24 | type T = impl Sized; | ||
| 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 26 | STATIC_CELL.init_with(move || $val) | ||
| 27 | }}; | ||
| 28 | } | ||
| 29 | |||
| 30 | #[embassy_executor::task] | 22 | #[embassy_executor::task] |
| 31 | async fn wifi_task( | 23 | async fn wifi_task( |
| 32 | runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, | 24 | runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, |
| @@ -60,7 +52,7 @@ async fn main(spawner: Spawner) { | |||
| 60 | let mut pio = Pio::new(p.PIO0); | 52 | let mut pio = Pio::new(p.PIO0); |
| 61 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); | 53 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); |
| 62 | 54 | ||
| 63 | let state = singleton!(cyw43::State::new()); | 55 | let state = make_static!(cyw43::State::new()); |
| 64 | let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; | 56 | let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; |
| 65 | unwrap!(spawner.spawn(wifi_task(runner))); | 57 | unwrap!(spawner.spawn(wifi_task(runner))); |
| 66 | 58 | ||
| @@ -70,7 +62,7 @@ async fn main(spawner: Spawner) { | |||
| 70 | .await; | 62 | .await; |
| 71 | 63 | ||
| 72 | // Use a link-local address for communication without DHCP server | 64 | // Use a link-local address for communication without DHCP server |
| 73 | let config = Config::Static(embassy_net::StaticConfig { | 65 | let config = Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 74 | address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(169, 254, 1, 1), 16), | 66 | address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(169, 254, 1, 1), 16), |
| 75 | dns_servers: heapless::Vec::new(), | 67 | dns_servers: heapless::Vec::new(), |
| 76 | gateway: None, | 68 | gateway: None, |
| @@ -80,10 +72,10 @@ async fn main(spawner: Spawner) { | |||
| 80 | let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. | 72 | let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. |
| 81 | 73 | ||
| 82 | // Init network stack | 74 | // Init network stack |
| 83 | let stack = &*singleton!(Stack::new( | 75 | let stack = &*make_static!(Stack::new( |
| 84 | net_device, | 76 | net_device, |
| 85 | config, | 77 | config, |
| 86 | singleton!(StackResources::<2>::new()), | 78 | make_static!(StackResources::<2>::new()), |
| 87 | seed | 79 | seed |
| 88 | )); | 80 | )); |
| 89 | 81 | ||
diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs new file mode 100644 index 000000000..be965807b --- /dev/null +++ b/examples/rp/src/bin/wifi_blinky.rs | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use cyw43_pio::PioSpi; | ||
| 6 | use defmt::*; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_rp::gpio::{Level, Output}; | ||
| 9 | use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; | ||
| 10 | use embassy_rp::pio::Pio; | ||
| 11 | use embassy_time::{Duration, Timer}; | ||
| 12 | use static_cell::make_static; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | |||
| 15 | #[embassy_executor::task] | ||
| 16 | async fn wifi_task( | ||
| 17 | runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, | ||
| 18 | ) -> ! { | ||
| 19 | runner.run().await | ||
| 20 | } | ||
| 21 | |||
| 22 | #[embassy_executor::main] | ||
| 23 | async fn main(spawner: Spawner) { | ||
| 24 | let p = embassy_rp::init(Default::default()); | ||
| 25 | let fw = include_bytes!("../../../../cyw43-firmware/43439A0.bin"); | ||
| 26 | let clm = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin"); | ||
| 27 | |||
| 28 | // To make flashing faster for development, you may want to flash the firmwares independently | ||
| 29 | // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: | ||
| 30 | // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 | ||
| 31 | // probe-rs-cli download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000 | ||
| 32 | //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; | ||
| 33 | //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; | ||
| 34 | |||
| 35 | let pwr = Output::new(p.PIN_23, Level::Low); | ||
| 36 | let cs = Output::new(p.PIN_25, Level::High); | ||
| 37 | let mut pio = Pio::new(p.PIO0); | ||
| 38 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); | ||
| 39 | |||
| 40 | let state = make_static!(cyw43::State::new()); | ||
| 41 | let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; | ||
| 42 | unwrap!(spawner.spawn(wifi_task(runner))); | ||
| 43 | |||
| 44 | control.init(clm).await; | ||
| 45 | control | ||
| 46 | .set_power_management(cyw43::PowerManagementMode::PowerSave) | ||
| 47 | .await; | ||
| 48 | |||
| 49 | let delay = Duration::from_secs(1); | ||
| 50 | loop { | ||
| 51 | info!("led on!"); | ||
| 52 | control.gpio_set(0, true).await; | ||
| 53 | Timer::after(delay).await; | ||
| 54 | |||
| 55 | info!("led off!"); | ||
| 56 | control.gpio_set(0, false).await; | ||
| 57 | Timer::after(delay).await; | ||
| 58 | } | ||
| 59 | } | ||
diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs index aa5e5a399..79534f229 100644 --- a/examples/rp/src/bin/wifi_scan.rs +++ b/examples/rp/src/bin/wifi_scan.rs | |||
| @@ -13,17 +13,9 @@ use embassy_net::Stack; | |||
| 13 | use embassy_rp::gpio::{Level, Output}; | 13 | use embassy_rp::gpio::{Level, Output}; |
| 14 | use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; | 14 | use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; |
| 15 | use embassy_rp::pio::Pio; | 15 | use embassy_rp::pio::Pio; |
| 16 | use static_cell::StaticCell; | 16 | use static_cell::make_static; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 18 | ||
| 19 | macro_rules! singleton { | ||
| 20 | ($val:expr) => {{ | ||
| 21 | type T = impl Sized; | ||
| 22 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 23 | STATIC_CELL.init_with(move || $val) | ||
| 24 | }}; | ||
| 25 | } | ||
| 26 | |||
| 27 | #[embassy_executor::task] | 19 | #[embassy_executor::task] |
| 28 | async fn wifi_task( | 20 | async fn wifi_task( |
| 29 | runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, | 21 | runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, |
| @@ -57,7 +49,7 @@ async fn main(spawner: Spawner) { | |||
| 57 | let mut pio = Pio::new(p.PIO0); | 49 | let mut pio = Pio::new(p.PIO0); |
| 58 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); | 50 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); |
| 59 | 51 | ||
| 60 | let state = singleton!(cyw43::State::new()); | 52 | let state = make_static!(cyw43::State::new()); |
| 61 | let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; | 53 | let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; |
| 62 | unwrap!(spawner.spawn(wifi_task(runner))); | 54 | unwrap!(spawner.spawn(wifi_task(runner))); |
| 63 | 55 | ||
diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs index eafa25f68..026e056fa 100644 --- a/examples/rp/src/bin/wifi_tcp_server.rs +++ b/examples/rp/src/bin/wifi_tcp_server.rs | |||
| @@ -16,17 +16,9 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; | |||
| 16 | use embassy_rp::pio::Pio; | 16 | use embassy_rp::pio::Pio; |
| 17 | use embassy_time::Duration; | 17 | use embassy_time::Duration; |
| 18 | use embedded_io::asynch::Write; | 18 | use embedded_io::asynch::Write; |
| 19 | use static_cell::StaticCell; | 19 | use static_cell::make_static; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | 21 | ||
| 22 | macro_rules! singleton { | ||
| 23 | ($val:expr) => {{ | ||
| 24 | type T = impl Sized; | ||
| 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 26 | STATIC_CELL.init_with(move || $val) | ||
| 27 | }}; | ||
| 28 | } | ||
| 29 | |||
| 30 | #[embassy_executor::task] | 22 | #[embassy_executor::task] |
| 31 | async fn wifi_task( | 23 | async fn wifi_task( |
| 32 | runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, | 24 | runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, |
| @@ -60,7 +52,7 @@ async fn main(spawner: Spawner) { | |||
| 60 | let mut pio = Pio::new(p.PIO0); | 52 | let mut pio = Pio::new(p.PIO0); |
| 61 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); | 53 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); |
| 62 | 54 | ||
| 63 | let state = singleton!(cyw43::State::new()); | 55 | let state = make_static!(cyw43::State::new()); |
| 64 | let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; | 56 | let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; |
| 65 | unwrap!(spawner.spawn(wifi_task(runner))); | 57 | unwrap!(spawner.spawn(wifi_task(runner))); |
| 66 | 58 | ||
| @@ -69,8 +61,8 @@ async fn main(spawner: Spawner) { | |||
| 69 | .set_power_management(cyw43::PowerManagementMode::PowerSave) | 61 | .set_power_management(cyw43::PowerManagementMode::PowerSave) |
| 70 | .await; | 62 | .await; |
| 71 | 63 | ||
| 72 | let config = Config::Dhcp(Default::default()); | 64 | let config = Config::dhcpv4(Default::default()); |
| 73 | //let config = embassy_net::Config::Static(embassy_net::Config { | 65 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 74 | // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 66 | // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 75 | // dns_servers: Vec::new(), | 67 | // dns_servers: Vec::new(), |
| 76 | // gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | 68 | // gateway: Some(Ipv4Address::new(192, 168, 69, 1)), |
| @@ -80,10 +72,10 @@ async fn main(spawner: Spawner) { | |||
| 80 | let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. | 72 | let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. |
| 81 | 73 | ||
| 82 | // Init network stack | 74 | // Init network stack |
| 83 | let stack = &*singleton!(Stack::new( | 75 | let stack = &*make_static!(Stack::new( |
| 84 | net_device, | 76 | net_device, |
| 85 | config, | 77 | config, |
| 86 | singleton!(StackResources::<2>::new()), | 78 | make_static!(StackResources::<2>::new()), |
| 87 | seed | 79 | seed |
| 88 | )); | 80 | )); |
| 89 | 81 | ||
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 36770ca9c..878ad8c5a 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml | |||
| @@ -22,4 +22,4 @@ libc = "0.2.101" | |||
| 22 | clap = { version = "3.0.0-beta.5", features = ["derive"] } | 22 | clap = { version = "3.0.0-beta.5", features = ["derive"] } |
| 23 | rand_core = { version = "0.6.3", features = ["std"] } | 23 | rand_core = { version = "0.6.3", features = ["std"] } |
| 24 | heapless = { version = "0.7.5", default-features = false } | 24 | heapless = { version = "0.7.5", default-features = false } |
| 25 | static_cell = "1.0" | 25 | static_cell = { version = "1.1", features = ["nightly"]} |
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index d93616254..3aadb029d 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -11,21 +11,12 @@ use embedded_io::asynch::Write; | |||
| 11 | use heapless::Vec; | 11 | use heapless::Vec; |
| 12 | use log::*; | 12 | use log::*; |
| 13 | use rand_core::{OsRng, RngCore}; | 13 | use rand_core::{OsRng, RngCore}; |
| 14 | use static_cell::StaticCell; | 14 | use static_cell::{make_static, StaticCell}; |
| 15 | 15 | ||
| 16 | #[path = "../tuntap.rs"] | 16 | #[path = "../tuntap.rs"] |
| 17 | mod tuntap; | 17 | mod tuntap; |
| 18 | 18 | ||
| 19 | use crate::tuntap::TunTapDevice; | 19 | use crate::tuntap::TunTapDevice; |
| 20 | |||
| 21 | macro_rules! singleton { | ||
| 22 | ($val:expr) => {{ | ||
| 23 | type T = impl Sized; | ||
| 24 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 25 | STATIC_CELL.init_with(move || $val) | ||
| 26 | }}; | ||
| 27 | } | ||
| 28 | |||
| 29 | #[derive(Parser)] | 20 | #[derive(Parser)] |
| 30 | #[clap(version = "1.0")] | 21 | #[clap(version = "1.0")] |
| 31 | struct Opts { | 22 | struct Opts { |
| @@ -51,13 +42,13 @@ async fn main_task(spawner: Spawner) { | |||
| 51 | 42 | ||
| 52 | // Choose between dhcp or static ip | 43 | // Choose between dhcp or static ip |
| 53 | let config = if opts.static_ip { | 44 | let config = if opts.static_ip { |
| 54 | Config::Static(embassy_net::StaticConfig { | 45 | Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 55 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 46 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 56 | dns_servers: Vec::new(), | 47 | dns_servers: Vec::new(), |
| 57 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | 48 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), |
| 58 | }) | 49 | }) |
| 59 | } else { | 50 | } else { |
| 60 | Config::Dhcp(Default::default()) | 51 | Config::dhcpv4(Default::default()) |
| 61 | }; | 52 | }; |
| 62 | 53 | ||
| 63 | // Generate random seed | 54 | // Generate random seed |
| @@ -66,7 +57,12 @@ async fn main_task(spawner: Spawner) { | |||
| 66 | let seed = u64::from_le_bytes(seed); | 57 | let seed = u64::from_le_bytes(seed); |
| 67 | 58 | ||
| 68 | // Init network stack | 59 | // Init network stack |
| 69 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); | 60 | let stack = &*make_static!(Stack::new( |
| 61 | device, | ||
| 62 | config, | ||
| 63 | make_static!(StackResources::<3>::new()), | ||
| 64 | seed | ||
| 65 | )); | ||
| 70 | 66 | ||
| 71 | // Launch network task | 67 | // Launch network task |
| 72 | spawner.spawn(net_task(stack)).unwrap(); | 68 | spawner.spawn(net_task(stack)).unwrap(); |
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index d1e1f8212..65b5a2cd9 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs | |||
| @@ -9,21 +9,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | |||
| 9 | use heapless::Vec; | 9 | use heapless::Vec; |
| 10 | use log::*; | 10 | use log::*; |
| 11 | use rand_core::{OsRng, RngCore}; | 11 | use rand_core::{OsRng, RngCore}; |
| 12 | use static_cell::StaticCell; | 12 | use static_cell::{make_static, StaticCell}; |
| 13 | 13 | ||
| 14 | #[path = "../tuntap.rs"] | 14 | #[path = "../tuntap.rs"] |
| 15 | mod tuntap; | 15 | mod tuntap; |
| 16 | 16 | ||
| 17 | use crate::tuntap::TunTapDevice; | 17 | use crate::tuntap::TunTapDevice; |
| 18 | |||
| 19 | macro_rules! singleton { | ||
| 20 | ($val:expr) => {{ | ||
| 21 | type T = impl Sized; | ||
| 22 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 23 | STATIC_CELL.init_with(move || $val) | ||
| 24 | }}; | ||
| 25 | } | ||
| 26 | |||
| 27 | #[derive(Parser)] | 18 | #[derive(Parser)] |
| 28 | #[clap(version = "1.0")] | 19 | #[clap(version = "1.0")] |
| 29 | struct Opts { | 20 | struct Opts { |
| @@ -49,14 +40,14 @@ async fn main_task(spawner: Spawner) { | |||
| 49 | 40 | ||
| 50 | // Choose between dhcp or static ip | 41 | // Choose between dhcp or static ip |
| 51 | let config = if opts.static_ip { | 42 | let config = if opts.static_ip { |
| 52 | Config::Static(embassy_net::StaticConfig { | 43 | Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 53 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24), | 44 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24), |
| 54 | dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()]) | 45 | dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()]) |
| 55 | .unwrap(), | 46 | .unwrap(), |
| 56 | gateway: Some(Ipv4Address::new(192, 168, 69, 100)), | 47 | gateway: Some(Ipv4Address::new(192, 168, 69, 100)), |
| 57 | }) | 48 | }) |
| 58 | } else { | 49 | } else { |
| 59 | Config::Dhcp(Default::default()) | 50 | Config::dhcpv4(Default::default()) |
| 60 | }; | 51 | }; |
| 61 | 52 | ||
| 62 | // Generate random seed | 53 | // Generate random seed |
| @@ -65,7 +56,12 @@ async fn main_task(spawner: Spawner) { | |||
| 65 | let seed = u64::from_le_bytes(seed); | 56 | let seed = u64::from_le_bytes(seed); |
| 66 | 57 | ||
| 67 | // Init network stack | 58 | // Init network stack |
| 68 | let stack: &Stack<_> = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); | 59 | let stack: &Stack<_> = &*make_static!(Stack::new( |
| 60 | device, | ||
| 61 | config, | ||
| 62 | make_static!(StackResources::<3>::new()), | ||
| 63 | seed | ||
| 64 | )); | ||
| 69 | 65 | ||
| 70 | // Launch network task | 66 | // Launch network task |
| 71 | spawner.spawn(net_task(stack)).unwrap(); | 67 | spawner.spawn(net_task(stack)).unwrap(); |
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index 4df23edf6..3fc46156c 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -7,21 +7,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | |||
| 7 | use heapless::Vec; | 7 | use heapless::Vec; |
| 8 | use log::*; | 8 | use log::*; |
| 9 | use rand_core::{OsRng, RngCore}; | 9 | use rand_core::{OsRng, RngCore}; |
| 10 | use static_cell::StaticCell; | 10 | use static_cell::{make_static, StaticCell}; |
| 11 | 11 | ||
| 12 | #[path = "../tuntap.rs"] | 12 | #[path = "../tuntap.rs"] |
| 13 | mod tuntap; | 13 | mod tuntap; |
| 14 | 14 | ||
| 15 | use crate::tuntap::TunTapDevice; | 15 | use crate::tuntap::TunTapDevice; |
| 16 | |||
| 17 | macro_rules! singleton { | ||
| 18 | ($val:expr) => {{ | ||
| 19 | type T = impl Sized; | ||
| 20 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 21 | STATIC_CELL.init_with(move || $val) | ||
| 22 | }}; | ||
| 23 | } | ||
| 24 | |||
| 25 | #[derive(Parser)] | 16 | #[derive(Parser)] |
| 26 | #[clap(version = "1.0")] | 17 | #[clap(version = "1.0")] |
| 27 | struct Opts { | 18 | struct Opts { |
| @@ -47,13 +38,13 @@ async fn main_task(spawner: Spawner) { | |||
| 47 | 38 | ||
| 48 | // Choose between dhcp or static ip | 39 | // Choose between dhcp or static ip |
| 49 | let config = if opts.static_ip { | 40 | let config = if opts.static_ip { |
| 50 | Config::Static(embassy_net::StaticConfig { | 41 | Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 51 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 42 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 52 | dns_servers: Vec::new(), | 43 | dns_servers: Vec::new(), |
| 53 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | 44 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), |
| 54 | }) | 45 | }) |
| 55 | } else { | 46 | } else { |
| 56 | Config::Dhcp(Default::default()) | 47 | Config::dhcpv4(Default::default()) |
| 57 | }; | 48 | }; |
| 58 | 49 | ||
| 59 | // Generate random seed | 50 | // Generate random seed |
| @@ -62,7 +53,12 @@ async fn main_task(spawner: Spawner) { | |||
| 62 | let seed = u64::from_le_bytes(seed); | 53 | let seed = u64::from_le_bytes(seed); |
| 63 | 54 | ||
| 64 | // Init network stack | 55 | // Init network stack |
| 65 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); | 56 | let stack = &*make_static!(Stack::new( |
| 57 | device, | ||
| 58 | config, | ||
| 59 | make_static!(StackResources::<3>::new()), | ||
| 60 | seed | ||
| 61 | )); | ||
| 66 | 62 | ||
| 67 | // Launch network task | 63 | // Launch network task |
| 68 | spawner.spawn(net_task(stack)).unwrap(); | 64 | spawner.spawn(net_task(stack)).unwrap(); |
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index 97ce77f42..df09986ac 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs | |||
| @@ -12,21 +12,12 @@ use embedded_io::asynch::Write as _; | |||
| 12 | use heapless::Vec; | 12 | use heapless::Vec; |
| 13 | use log::*; | 13 | use log::*; |
| 14 | use rand_core::{OsRng, RngCore}; | 14 | use rand_core::{OsRng, RngCore}; |
| 15 | use static_cell::StaticCell; | 15 | use static_cell::{make_static, StaticCell}; |
| 16 | 16 | ||
| 17 | #[path = "../tuntap.rs"] | 17 | #[path = "../tuntap.rs"] |
| 18 | mod tuntap; | 18 | mod tuntap; |
| 19 | 19 | ||
| 20 | use crate::tuntap::TunTapDevice; | 20 | use crate::tuntap::TunTapDevice; |
| 21 | |||
| 22 | macro_rules! singleton { | ||
| 23 | ($val:expr) => {{ | ||
| 24 | type T = impl Sized; | ||
| 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 26 | STATIC_CELL.init_with(move || $val) | ||
| 27 | }}; | ||
| 28 | } | ||
| 29 | |||
| 30 | #[derive(Parser)] | 21 | #[derive(Parser)] |
| 31 | #[clap(version = "1.0")] | 22 | #[clap(version = "1.0")] |
| 32 | struct Opts { | 23 | struct Opts { |
| @@ -62,13 +53,13 @@ async fn main_task(spawner: Spawner) { | |||
| 62 | 53 | ||
| 63 | // Choose between dhcp or static ip | 54 | // Choose between dhcp or static ip |
| 64 | let config = if opts.static_ip { | 55 | let config = if opts.static_ip { |
| 65 | Config::Static(embassy_net::StaticConfig { | 56 | Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 66 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 57 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 67 | dns_servers: Vec::new(), | 58 | dns_servers: Vec::new(), |
| 68 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | 59 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), |
| 69 | }) | 60 | }) |
| 70 | } else { | 61 | } else { |
| 71 | Config::Dhcp(Default::default()) | 62 | Config::dhcpv4(Default::default()) |
| 72 | }; | 63 | }; |
| 73 | 64 | ||
| 74 | // Generate random seed | 65 | // Generate random seed |
| @@ -77,7 +68,12 @@ async fn main_task(spawner: Spawner) { | |||
| 77 | let seed = u64::from_le_bytes(seed); | 68 | let seed = u64::from_le_bytes(seed); |
| 78 | 69 | ||
| 79 | // Init network stack | 70 | // Init network stack |
| 80 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); | 71 | let stack = &*make_static!(Stack::new( |
| 72 | device, | ||
| 73 | config, | ||
| 74 | make_static!(StackResources::<3>::new()), | ||
| 75 | seed | ||
| 76 | )); | ||
| 81 | 77 | ||
| 82 | // Launch network task | 78 | // Launch network task |
| 83 | spawner.spawn(net_task(stack)).unwrap(); | 79 | spawner.spawn(net_task(stack)).unwrap(); |
| @@ -112,7 +108,7 @@ async fn main_task(spawner: Spawner) { | |||
| 112 | info!("Closing the connection"); | 108 | info!("Closing the connection"); |
| 113 | socket.abort(); | 109 | socket.abort(); |
| 114 | info!("Flushing the RST out..."); | 110 | info!("Flushing the RST out..."); |
| 115 | socket.flush().await; | 111 | _ = socket.flush().await; |
| 116 | info!("Finished with the socket"); | 112 | info!("Finished with the socket"); |
| 117 | } | 113 | } |
| 118 | } | 114 | } |
diff --git a/examples/stm32c0/Cargo.toml b/examples/stm32c0/Cargo.toml index ad11fbd1c..43f432520 100644 --- a/examples/stm32c0/Cargo.toml +++ b/examples/stm32c0/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] } |
| 12 | 12 | ||
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index 9c59c45c6..8d2248ed0 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml | |||
| @@ -13,7 +13,7 @@ defmt = "0.3" | |||
| 13 | defmt-rtt = "0.4" | 13 | defmt-rtt = "0.4" |
| 14 | panic-probe = "0.3" | 14 | panic-probe = "0.3" |
| 15 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 15 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 16 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | 16 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 17 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 17 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 18 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] } | 18 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] } |
| 19 | static_cell = "1.0" | 19 | static_cell = { version = "1.1", features = ["nightly"]} |
diff --git a/examples/stm32f0/src/bin/multiprio.rs b/examples/stm32f0/src/bin/multiprio.rs index 430a805fc..988ffeef1 100644 --- a/examples/stm32f0/src/bin/multiprio.rs +++ b/examples/stm32f0/src/bin/multiprio.rs | |||
| @@ -57,14 +57,11 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 63 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 64 | use defmt::*; | 61 | use defmt::*; |
| 65 | use embassy_executor::{Executor, InterruptExecutor}; | 62 | use embassy_executor::{Executor, InterruptExecutor}; |
| 66 | use embassy_stm32::interrupt; | 63 | use embassy_stm32::interrupt; |
| 67 | use embassy_stm32::pac::Interrupt; | 64 | use embassy_stm32::interrupt::{InterruptExt, Priority}; |
| 68 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 69 | use static_cell::StaticCell; | 66 | use static_cell::StaticCell; |
| 70 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -129,16 +126,15 @@ unsafe fn USART2() { | |||
| 129 | fn main() -> ! { | 126 | fn main() -> ! { |
| 130 | // Initialize and create handle for devicer peripherals | 127 | // Initialize and create handle for devicer peripherals |
| 131 | let _p = embassy_stm32::init(Default::default()); | 128 | let _p = embassy_stm32::init(Default::default()); |
| 132 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 133 | 129 | ||
| 134 | // High-priority executor: USART1, priority level 6 | 130 | // High-priority executor: USART1, priority level 6 |
| 135 | unsafe { nvic.set_priority(Interrupt::USART1, 6 << 4) }; | 131 | interrupt::USART1.set_priority(Priority::P6); |
| 136 | let spawner = EXECUTOR_HIGH.start(Interrupt::USART1); | 132 | let spawner = EXECUTOR_HIGH.start(interrupt::USART1); |
| 137 | unwrap!(spawner.spawn(run_high())); | 133 | unwrap!(spawner.spawn(run_high())); |
| 138 | 134 | ||
| 139 | // Medium-priority executor: USART2, priority level 7 | 135 | // Medium-priority executor: USART2, priority level 7 |
| 140 | unsafe { nvic.set_priority(Interrupt::USART2, 7 << 4) }; | 136 | interrupt::USART2.set_priority(Priority::P7); |
| 141 | let spawner = EXECUTOR_MED.start(Interrupt::USART2); | 137 | let spawner = EXECUTOR_MED.start(interrupt::USART2); |
| 142 | unwrap!(spawner.spawn(run_med())); | 138 | unwrap!(spawner.spawn(run_med())); |
| 143 | 139 | ||
| 144 | // Low priority executor: runs in thread mode, using WFE/SEV | 140 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f0/src/bin/wdg.rs b/examples/stm32f0/src/bin/wdg.rs index 80e76f901..a44b17528 100644 --- a/examples/stm32f0/src/bin/wdg.rs +++ b/examples/stm32f0/src/bin/wdg.rs | |||
| @@ -16,10 +16,10 @@ async fn main(_spawner: Spawner) { | |||
| 16 | let mut wdg = IndependentWatchdog::new(p.IWDG, 20_000_00); | 16 | let mut wdg = IndependentWatchdog::new(p.IWDG, 20_000_00); |
| 17 | 17 | ||
| 18 | info!("Watchdog start"); | 18 | info!("Watchdog start"); |
| 19 | unsafe { wdg.unleash() }; | 19 | wdg.unleash(); |
| 20 | 20 | ||
| 21 | loop { | 21 | loop { |
| 22 | Timer::after(Duration::from_secs(1)).await; | 22 | Timer::after(Duration::from_secs(1)).await; |
| 23 | unsafe { wdg.pet() }; | 23 | wdg.pet(); |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index 345e948a6..d34fd439a 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] } |
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml index e4f97a589..5e3e0d0f7 100644 --- a/examples/stm32f2/Cargo.toml +++ b/examples/stm32f2/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } |
| 12 | 12 | ||
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index 3d314e6c5..29ab2009c 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } |
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| @@ -23,4 +23,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 23 | heapless = { version = "0.7.5", default-features = false } | 23 | heapless = { version = "0.7.5", default-features = false } |
| 24 | nb = "1.0.0" | 24 | nb = "1.0.0" |
| 25 | embedded-storage = "0.3.0" | 25 | embedded-storage = "0.3.0" |
| 26 | static_cell = "1.0" | 26 | static_cell = { version = "1.1", features = ["nightly"]} |
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 5d010f799..80bf59deb 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs | |||
| @@ -57,14 +57,11 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 63 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 64 | use defmt::*; | 61 | use defmt::*; |
| 65 | use embassy_executor::{Executor, InterruptExecutor}; | 62 | use embassy_executor::{Executor, InterruptExecutor}; |
| 66 | use embassy_stm32::interrupt; | 63 | use embassy_stm32::interrupt; |
| 67 | use embassy_stm32::pac::Interrupt; | 64 | use embassy_stm32::interrupt::{InterruptExt, Priority}; |
| 68 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 69 | use static_cell::StaticCell; | 66 | use static_cell::StaticCell; |
| 70 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -130,16 +127,15 @@ fn main() -> ! { | |||
| 130 | info!("Hello World!"); | 127 | info!("Hello World!"); |
| 131 | 128 | ||
| 132 | let _p = embassy_stm32::init(Default::default()); | 129 | let _p = embassy_stm32::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 134 | 130 | ||
| 135 | // High-priority executor: UART4, priority level 6 | 131 | // High-priority executor: UART4, priority level 6 |
| 136 | unsafe { nvic.set_priority(Interrupt::UART4, 6 << 4) }; | 132 | interrupt::UART4.set_priority(Priority::P6); |
| 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::UART4); | 133 | let spawner = EXECUTOR_HIGH.start(interrupt::UART4); |
| 138 | unwrap!(spawner.spawn(run_high())); | 134 | unwrap!(spawner.spawn(run_high())); |
| 139 | 135 | ||
| 140 | // Medium-priority executor: UART5, priority level 7 | 136 | // Medium-priority executor: UART5, priority level 7 |
| 141 | unsafe { nvic.set_priority(Interrupt::UART5, 7 << 4) }; | 137 | interrupt::UART5.set_priority(Priority::P7); |
| 142 | let spawner = EXECUTOR_MED.start(Interrupt::UART5); | 138 | let spawner = EXECUTOR_MED.start(interrupt::UART5); |
| 143 | unwrap!(spawner.spawn(run_med())); | 139 | unwrap!(spawner.spawn(run_med())); |
| 144 | 140 | ||
| 145 | // Low priority executor: runs in thread mode, using WFE/SEV | 141 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index f5f8b632d..7ecb64fce 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] } |
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| @@ -25,7 +25,7 @@ heapless = { version = "0.7.5", default-features = false } | |||
| 25 | nb = "1.0.0" | 25 | nb = "1.0.0" |
| 26 | embedded-storage = "0.3.0" | 26 | embedded-storage = "0.3.0" |
| 27 | micromath = "2.0.0" | 27 | micromath = "2.0.0" |
| 28 | static_cell = "1.0" | 28 | static_cell = { version = "1.1", features = ["nightly"]} |
| 29 | chrono = { version = "^0.4", default-features = false} | 29 | chrono = { version = "^0.4", default-features = false} |
| 30 | 30 | ||
| 31 | [profile.release] | 31 | [profile.release] |
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 5d010f799..80bf59deb 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs | |||
| @@ -57,14 +57,11 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 63 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 64 | use defmt::*; | 61 | use defmt::*; |
| 65 | use embassy_executor::{Executor, InterruptExecutor}; | 62 | use embassy_executor::{Executor, InterruptExecutor}; |
| 66 | use embassy_stm32::interrupt; | 63 | use embassy_stm32::interrupt; |
| 67 | use embassy_stm32::pac::Interrupt; | 64 | use embassy_stm32::interrupt::{InterruptExt, Priority}; |
| 68 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 69 | use static_cell::StaticCell; | 66 | use static_cell::StaticCell; |
| 70 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -130,16 +127,15 @@ fn main() -> ! { | |||
| 130 | info!("Hello World!"); | 127 | info!("Hello World!"); |
| 131 | 128 | ||
| 132 | let _p = embassy_stm32::init(Default::default()); | 129 | let _p = embassy_stm32::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 134 | 130 | ||
| 135 | // High-priority executor: UART4, priority level 6 | 131 | // High-priority executor: UART4, priority level 6 |
| 136 | unsafe { nvic.set_priority(Interrupt::UART4, 6 << 4) }; | 132 | interrupt::UART4.set_priority(Priority::P6); |
| 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::UART4); | 133 | let spawner = EXECUTOR_HIGH.start(interrupt::UART4); |
| 138 | unwrap!(spawner.spawn(run_high())); | 134 | unwrap!(spawner.spawn(run_high())); |
| 139 | 135 | ||
| 140 | // Medium-priority executor: UART5, priority level 7 | 136 | // Medium-priority executor: UART5, priority level 7 |
| 141 | unsafe { nvic.set_priority(Interrupt::UART5, 7 << 4) }; | 137 | interrupt::UART5.set_priority(Priority::P7); |
| 142 | let spawner = EXECUTOR_MED.start(Interrupt::UART5); | 138 | let spawner = EXECUTOR_MED.start(interrupt::UART5); |
| 143 | unwrap!(spawner.spawn(run_med())); | 139 | unwrap!(spawner.spawn(run_med())); |
| 144 | 140 | ||
| 145 | // Low priority executor: runs in thread mode, using WFE/SEV | 141 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs index c4e395f0f..953d99a45 100644 --- a/examples/stm32f4/src/bin/usb_ethernet.rs +++ b/examples/stm32f4/src/bin/usb_ethernet.rs | |||
| @@ -14,20 +14,11 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState | |||
| 14 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; | 14 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; |
| 15 | use embassy_usb::{Builder, UsbDevice}; | 15 | use embassy_usb::{Builder, UsbDevice}; |
| 16 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 17 | use static_cell::StaticCell; | 17 | use static_cell::make_static; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 19 | 19 | ||
| 20 | type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>; | 20 | type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>; |
| 21 | 21 | ||
| 22 | macro_rules! singleton { | ||
| 23 | ($val:expr) => {{ | ||
| 24 | type T = impl Sized; | ||
| 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 26 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 27 | x | ||
| 28 | }}; | ||
| 29 | } | ||
| 30 | |||
| 31 | const MTU: usize = 1514; | 22 | const MTU: usize = 1514; |
| 32 | 23 | ||
| 33 | #[embassy_executor::task] | 24 | #[embassy_executor::task] |
| @@ -60,7 +51,7 @@ async fn main(spawner: Spawner) { | |||
| 60 | let p = embassy_stm32::init(config); | 51 | let p = embassy_stm32::init(config); |
| 61 | 52 | ||
| 62 | // Create the driver, from the HAL. | 53 | // Create the driver, from the HAL. |
| 63 | let ep_out_buffer = &mut singleton!([0; 256])[..]; | 54 | let ep_out_buffer = &mut make_static!([0; 256])[..]; |
| 64 | let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer); | 55 | let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer); |
| 65 | 56 | ||
| 66 | // Create embassy-usb Config | 57 | // Create embassy-usb Config |
| @@ -81,10 +72,10 @@ async fn main(spawner: Spawner) { | |||
| 81 | let mut builder = Builder::new( | 72 | let mut builder = Builder::new( |
| 82 | driver, | 73 | driver, |
| 83 | config, | 74 | config, |
| 84 | &mut singleton!([0; 256])[..], | 75 | &mut make_static!([0; 256])[..], |
| 85 | &mut singleton!([0; 256])[..], | 76 | &mut make_static!([0; 256])[..], |
| 86 | &mut singleton!([0; 256])[..], | 77 | &mut make_static!([0; 256])[..], |
| 87 | &mut singleton!([0; 128])[..], | 78 | &mut make_static!([0; 128])[..], |
| 88 | ); | 79 | ); |
| 89 | 80 | ||
| 90 | // Our MAC addr. | 81 | // Our MAC addr. |
| @@ -93,18 +84,18 @@ async fn main(spawner: Spawner) { | |||
| 93 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; | 84 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; |
| 94 | 85 | ||
| 95 | // Create classes on the builder. | 86 | // Create classes on the builder. |
| 96 | let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); | 87 | let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); |
| 97 | 88 | ||
| 98 | // Build the builder. | 89 | // Build the builder. |
| 99 | let usb = builder.build(); | 90 | let usb = builder.build(); |
| 100 | 91 | ||
| 101 | unwrap!(spawner.spawn(usb_task(usb))); | 92 | unwrap!(spawner.spawn(usb_task(usb))); |
| 102 | 93 | ||
| 103 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); | 94 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); |
| 104 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 95 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 105 | 96 | ||
| 106 | let config = embassy_net::Config::Dhcp(Default::default()); | 97 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 107 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 98 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 108 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 99 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 109 | // dns_servers: Vec::new(), | 100 | // dns_servers: Vec::new(), |
| 110 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 101 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| @@ -117,7 +108,12 @@ async fn main(spawner: Spawner) { | |||
| 117 | let seed = u64::from_le_bytes(seed); | 108 | let seed = u64::from_le_bytes(seed); |
| 118 | 109 | ||
| 119 | // Init network stack | 110 | // Init network stack |
| 120 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 111 | let stack = &*make_static!(Stack::new( |
| 112 | device, | ||
| 113 | config, | ||
| 114 | make_static!(StackResources::<2>::new()), | ||
| 115 | seed | ||
| 116 | )); | ||
| 121 | 117 | ||
| 122 | unwrap!(spawner.spawn(net_task(stack))); | 118 | unwrap!(spawner.spawn(net_task(stack))); |
| 123 | 119 | ||
diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs index b2c587fa1..e5d122af7 100644 --- a/examples/stm32f4/src/bin/wdt.rs +++ b/examples/stm32f4/src/bin/wdt.rs | |||
| @@ -17,9 +17,7 @@ async fn main(_spawner: Spawner) { | |||
| 17 | let mut led = Output::new(p.PB7, Level::High, Speed::Low); | 17 | let mut led = Output::new(p.PB7, Level::High, Speed::Low); |
| 18 | 18 | ||
| 19 | let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000); | 19 | let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000); |
| 20 | unsafe { | 20 | wdt.unleash(); |
| 21 | wdt.unleash(); | ||
| 22 | } | ||
| 23 | 21 | ||
| 24 | let mut i = 0; | 22 | let mut i = 0; |
| 25 | 23 | ||
| @@ -36,9 +34,7 @@ async fn main(_spawner: Spawner) { | |||
| 36 | // MCU should restart in 1 second after the last pet. | 34 | // MCU should restart in 1 second after the last pet. |
| 37 | if i < 5 { | 35 | if i < 5 { |
| 38 | info!("Petting watchdog"); | 36 | info!("Petting watchdog"); |
| 39 | unsafe { | 37 | wdt.pet(); |
| 40 | wdt.pet(); | ||
| 41 | } | ||
| 42 | } | 38 | } |
| 43 | 39 | ||
| 44 | i += 1; | 40 | i += 1; |
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 6ddb7186e..657251c50 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } |
| 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } | 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } |
| @@ -26,4 +26,4 @@ nb = "1.0.0" | |||
| 26 | rand_core = "0.6.3" | 26 | rand_core = "0.6.3" |
| 27 | critical-section = "1.1" | 27 | critical-section = "1.1" |
| 28 | embedded-storage = "0.3.0" | 28 | embedded-storage = "0.3.0" |
| 29 | static_cell = "1.0" | 29 | static_cell = { version = "1.1", features = ["nightly"]} |
diff --git a/examples/stm32f7/build.rs b/examples/stm32f7/build.rs index c4e15f19c..2b5d412a9 100644 --- a/examples/stm32f7/build.rs +++ b/examples/stm32f7/build.rs | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | //! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs | 1 | //! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs |
| 2 | use std::env; | ||
| 3 | use std::fs::File; | 2 | use std::fs::File; |
| 4 | use std::io::prelude::*; | 3 | use std::io::prelude::*; |
| 5 | use std::io::{self}; | ||
| 6 | use std::path::PathBuf; | 4 | use std::path::PathBuf; |
| 5 | use std::{env, io}; | ||
| 7 | 6 | ||
| 8 | #[derive(Debug)] | 7 | #[derive(Debug)] |
| 9 | enum Error { | 8 | enum Error { |
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index 6d286c368..fde6a7576 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -15,18 +15,8 @@ use embassy_stm32::{bind_interrupts, eth, Config}; | |||
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 17 | use rand_core::RngCore; | 17 | use rand_core::RngCore; |
| 18 | use static_cell::StaticCell; | 18 | use static_cell::make_static; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | |||
| 21 | macro_rules! singleton { | ||
| 22 | ($val:expr) => {{ | ||
| 23 | type T = impl Sized; | ||
| 24 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 25 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 26 | x | ||
| 27 | }}; | ||
| 28 | } | ||
| 29 | |||
| 30 | bind_interrupts!(struct Irqs { | 20 | bind_interrupts!(struct Irqs { |
| 31 | ETH => eth::InterruptHandler; | 21 | ETH => eth::InterruptHandler; |
| 32 | }); | 22 | }); |
| @@ -55,7 +45,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 55 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; | 45 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; |
| 56 | 46 | ||
| 57 | let device = Ethernet::new( | 47 | let device = Ethernet::new( |
| 58 | singleton!(PacketQueue::<16, 16>::new()), | 48 | make_static!(PacketQueue::<16, 16>::new()), |
| 59 | p.ETH, | 49 | p.ETH, |
| 60 | Irqs, | 50 | Irqs, |
| 61 | p.PA1, | 51 | p.PA1, |
| @@ -72,15 +62,20 @@ async fn main(spawner: Spawner) -> ! { | |||
| 72 | 0, | 62 | 0, |
| 73 | ); | 63 | ); |
| 74 | 64 | ||
| 75 | let config = embassy_net::Config::Dhcp(Default::default()); | 65 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 76 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 66 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 77 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 67 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 78 | // dns_servers: Vec::new(), | 68 | // dns_servers: Vec::new(), |
| 79 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 69 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| 80 | //}); | 70 | //}); |
| 81 | 71 | ||
| 82 | // Init network stack | 72 | // Init network stack |
| 83 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 73 | let stack = &*make_static!(Stack::new( |
| 74 | device, | ||
| 75 | config, | ||
| 76 | make_static!(StackResources::<2>::new()), | ||
| 77 | seed | ||
| 78 | )); | ||
| 84 | 79 | ||
| 85 | // Launch network task | 80 | // Launch network task |
| 86 | unwrap!(spawner.spawn(net_task(&stack))); | 81 | unwrap!(spawner.spawn(net_task(&stack))); |
diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml index 4d7fc4548..c5245757b 100644 --- a/examples/stm32g0/Cargo.toml +++ b/examples/stm32g0/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } |
| 12 | 12 | ||
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml index 00e2dae4c..fbfbc6408 100644 --- a/examples/stm32g4/Cargo.toml +++ b/examples/stm32g4/Cargo.toml | |||
| @@ -6,10 +6,11 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } |
| 12 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | 12 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } |
| 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | ||
| 13 | 14 | ||
| 14 | defmt = "0.3" | 15 | defmt = "0.3" |
| 15 | defmt-rtt = "0.4" | 16 | defmt-rtt = "0.4" |
diff --git a/examples/stm32g4/src/bin/pll.rs b/examples/stm32g4/src/bin/pll.rs new file mode 100644 index 000000000..ef7d4800c --- /dev/null +++ b/examples/stm32g4/src/bin/pll.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_stm32::rcc::{ClockSrc, Pll, PllM, PllN, PllR, PllSrc}; | ||
| 8 | use embassy_stm32::Config; | ||
| 9 | use embassy_time::{Duration, Timer}; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | |||
| 12 | #[embassy_executor::main] | ||
| 13 | async fn main(_spawner: Spawner) { | ||
| 14 | let mut config = Config::default(); | ||
| 15 | |||
| 16 | config.rcc.pll = Some(Pll { | ||
| 17 | source: PllSrc::HSI16, | ||
| 18 | prediv_m: PllM::Div4, | ||
| 19 | mul_n: PllN::Mul85, | ||
| 20 | div_p: None, | ||
| 21 | div_q: None, | ||
| 22 | // Main system clock at 170 MHz | ||
| 23 | div_r: Some(PllR::Div2), | ||
| 24 | }); | ||
| 25 | |||
| 26 | config.rcc.mux = ClockSrc::PLL; | ||
| 27 | |||
| 28 | let _p = embassy_stm32::init(config); | ||
| 29 | info!("Hello World!"); | ||
| 30 | |||
| 31 | loop { | ||
| 32 | Timer::after(Duration::from_millis(1000)).await; | ||
| 33 | info!("1s elapsed"); | ||
| 34 | } | ||
| 35 | } | ||
diff --git a/examples/stm32g4/src/bin/usb_serial.rs b/examples/stm32g4/src/bin/usb_serial.rs new file mode 100644 index 000000000..c111a9787 --- /dev/null +++ b/examples/stm32g4/src/bin/usb_serial.rs | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::{panic, *}; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_stm32::rcc::{ClockSrc, Pll, PllM, PllN, PllQ, PllR, PllSrc}; | ||
| 8 | use embassy_stm32::time::Hertz; | ||
| 9 | use embassy_stm32::usb::{self, Driver, Instance}; | ||
| 10 | use embassy_stm32::{bind_interrupts, pac, peripherals, Config}; | ||
| 11 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | ||
| 12 | use embassy_usb::driver::EndpointError; | ||
| 13 | use embassy_usb::Builder; | ||
| 14 | use futures::future::join; | ||
| 15 | use {defmt_rtt as _, panic_probe as _}; | ||
| 16 | |||
| 17 | bind_interrupts!(struct Irqs { | ||
| 18 | USB_LP => usb::InterruptHandler<peripherals::USB>; | ||
| 19 | }); | ||
| 20 | |||
| 21 | #[embassy_executor::main] | ||
| 22 | async fn main(_spawner: Spawner) { | ||
| 23 | let mut config = Config::default(); | ||
| 24 | |||
| 25 | config.rcc.pll = Some(Pll { | ||
| 26 | source: PllSrc::HSE(Hertz(8000000)), | ||
| 27 | prediv_m: PllM::Div2, | ||
| 28 | mul_n: PllN::Mul72, | ||
| 29 | div_p: None, | ||
| 30 | // USB and CAN at 48 MHz | ||
| 31 | div_q: Some(PllQ::Div6), | ||
| 32 | // Main system clock at 144 MHz | ||
| 33 | div_r: Some(PllR::Div2), | ||
| 34 | }); | ||
| 35 | |||
| 36 | config.rcc.mux = ClockSrc::PLL; | ||
| 37 | |||
| 38 | let p = embassy_stm32::init(config); | ||
| 39 | info!("Hello World!"); | ||
| 40 | |||
| 41 | pac::RCC.ccipr().write(|w| w.set_clk48sel(0b10)); | ||
| 42 | |||
| 43 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); | ||
| 44 | |||
| 45 | let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); | ||
| 46 | config.manufacturer = Some("Embassy"); | ||
| 47 | config.product = Some("USB-Serial Example"); | ||
| 48 | config.serial_number = Some("123456"); | ||
| 49 | |||
| 50 | config.device_class = 0xEF; | ||
| 51 | config.device_sub_class = 0x02; | ||
| 52 | config.device_protocol = 0x01; | ||
| 53 | config.composite_with_iads = true; | ||
| 54 | |||
| 55 | let mut device_descriptor = [0; 256]; | ||
| 56 | let mut config_descriptor = [0; 256]; | ||
| 57 | let mut bos_descriptor = [0; 256]; | ||
| 58 | let mut control_buf = [0; 64]; | ||
| 59 | |||
| 60 | let mut state = State::new(); | ||
| 61 | |||
| 62 | let mut builder = Builder::new( | ||
| 63 | driver, | ||
| 64 | config, | ||
| 65 | &mut device_descriptor, | ||
| 66 | &mut config_descriptor, | ||
| 67 | &mut bos_descriptor, | ||
| 68 | &mut control_buf, | ||
| 69 | ); | ||
| 70 | |||
| 71 | let mut class = CdcAcmClass::new(&mut builder, &mut state, 64); | ||
| 72 | |||
| 73 | let mut usb = builder.build(); | ||
| 74 | |||
| 75 | let usb_fut = usb.run(); | ||
| 76 | |||
| 77 | let echo_fut = async { | ||
| 78 | loop { | ||
| 79 | class.wait_connection().await; | ||
| 80 | info!("Connected"); | ||
| 81 | let _ = echo(&mut class).await; | ||
| 82 | info!("Disconnected"); | ||
| 83 | } | ||
| 84 | }; | ||
| 85 | |||
| 86 | join(usb_fut, echo_fut).await; | ||
| 87 | } | ||
| 88 | |||
| 89 | struct Disconnected {} | ||
| 90 | |||
| 91 | impl From<EndpointError> for Disconnected { | ||
| 92 | fn from(val: EndpointError) -> Self { | ||
| 93 | match val { | ||
| 94 | EndpointError::BufferOverflow => panic!("Buffer overflow"), | ||
| 95 | EndpointError::Disabled => Disconnected {}, | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { | ||
| 101 | let mut buf = [0; 64]; | ||
| 102 | loop { | ||
| 103 | let n = class.read_packet(&mut buf).await?; | ||
| 104 | let data = &buf[..n]; | ||
| 105 | info!("data: {:x}", data); | ||
| 106 | class.write_packet(data).await?; | ||
| 107 | } | ||
| 108 | } | ||
diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml index b9204fba8..ebe511347 100644 --- a/examples/stm32h5/Cargo.toml +++ b/examples/stm32h5/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } |
| 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } | 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } |
| @@ -30,7 +30,7 @@ critical-section = "1.1" | |||
| 30 | micromath = "2.0.0" | 30 | micromath = "2.0.0" |
| 31 | stm32-fmc = "0.2.4" | 31 | stm32-fmc = "0.2.4" |
| 32 | embedded-storage = "0.3.0" | 32 | embedded-storage = "0.3.0" |
| 33 | static_cell = "1.0" | 33 | static_cell = { version = "1.1", features = ["nightly"]} |
| 34 | 34 | ||
| 35 | # cargo build/run | 35 | # cargo build/run |
| 36 | [profile.dev] | 36 | [profile.dev] |
diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs index fa1f225fe..78c8282a6 100644 --- a/examples/stm32h5/src/bin/eth.rs +++ b/examples/stm32h5/src/bin/eth.rs | |||
| @@ -16,18 +16,8 @@ use embassy_stm32::{bind_interrupts, eth, Config}; | |||
| 16 | use embassy_time::{Duration, Timer}; | 16 | use embassy_time::{Duration, Timer}; |
| 17 | use embedded_io::asynch::Write; | 17 | use embedded_io::asynch::Write; |
| 18 | use rand_core::RngCore; | 18 | use rand_core::RngCore; |
| 19 | use static_cell::StaticCell; | 19 | use static_cell::make_static; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | |||
| 22 | macro_rules! singleton { | ||
| 23 | ($val:expr) => {{ | ||
| 24 | type T = impl Sized; | ||
| 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 26 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 27 | x | ||
| 28 | }}; | ||
| 29 | } | ||
| 30 | |||
| 31 | bind_interrupts!(struct Irqs { | 21 | bind_interrupts!(struct Irqs { |
| 32 | ETH => eth::InterruptHandler; | 22 | ETH => eth::InterruptHandler; |
| 33 | }); | 23 | }); |
| @@ -74,7 +64,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 74 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; | 64 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; |
| 75 | 65 | ||
| 76 | let device = Ethernet::new( | 66 | let device = Ethernet::new( |
| 77 | singleton!(PacketQueue::<4, 4>::new()), | 67 | make_static!(PacketQueue::<4, 4>::new()), |
| 78 | p.ETH, | 68 | p.ETH, |
| 79 | Irqs, | 69 | Irqs, |
| 80 | p.PA1, | 70 | p.PA1, |
| @@ -91,15 +81,20 @@ async fn main(spawner: Spawner) -> ! { | |||
| 91 | 0, | 81 | 0, |
| 92 | ); | 82 | ); |
| 93 | 83 | ||
| 94 | let config = embassy_net::Config::Dhcp(Default::default()); | 84 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 95 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 85 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 96 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 86 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 97 | // dns_servers: Vec::new(), | 87 | // dns_servers: Vec::new(), |
| 98 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 88 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| 99 | //}); | 89 | //}); |
| 100 | 90 | ||
| 101 | // Init network stack | 91 | // Init network stack |
| 102 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 92 | let stack = &*make_static!(Stack::new( |
| 93 | device, | ||
| 94 | config, | ||
| 95 | make_static!(StackResources::<2>::new()), | ||
| 96 | seed | ||
| 97 | )); | ||
| 103 | 98 | ||
| 104 | // Launch network task | 99 | // Launch network task |
| 105 | unwrap!(spawner.spawn(net_task(&stack))); | 100 | unwrap!(spawner.spawn(net_task(&stack))); |
diff --git a/examples/stm32h5/src/bin/usb_serial.rs b/examples/stm32h5/src/bin/usb_serial.rs index 3912327e2..336eed644 100644 --- a/examples/stm32h5/src/bin/usb_serial.rs +++ b/examples/stm32h5/src/bin/usb_serial.rs | |||
| @@ -45,11 +45,9 @@ async fn main(_spawner: Spawner) { | |||
| 45 | 45 | ||
| 46 | info!("Hello World!"); | 46 | info!("Hello World!"); |
| 47 | 47 | ||
| 48 | unsafe { | 48 | pac::RCC.ccipr4().write(|w| { |
| 49 | pac::RCC.ccipr4().write(|w| { | 49 | w.set_usbsel(pac::rcc::vals::Usbsel::HSI48); |
| 50 | w.set_usbsel(pac::rcc::vals::Usbsel::HSI48); | 50 | }); |
| 51 | }); | ||
| 52 | } | ||
| 53 | 51 | ||
| 54 | // Create the driver, from the HAL. | 52 | // Create the driver, from the HAL. |
| 55 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); | 53 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); |
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index 8b534ca05..62ef5e9e4 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } |
| 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } | 12 | embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "unstable-traits", "proto-ipv6"] } |
| @@ -30,7 +30,7 @@ critical-section = "1.1" | |||
| 30 | micromath = "2.0.0" | 30 | micromath = "2.0.0" |
| 31 | stm32-fmc = "0.2.4" | 31 | stm32-fmc = "0.2.4" |
| 32 | embedded-storage = "0.3.0" | 32 | embedded-storage = "0.3.0" |
| 33 | static_cell = "1.0" | 33 | static_cell = { version = "1.1", features = ["nightly"]} |
| 34 | 34 | ||
| 35 | # cargo build/run | 35 | # cargo build/run |
| 36 | [profile.dev] | 36 | [profile.dev] |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index dbfc90cf4..12d37f7a4 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -15,18 +15,8 @@ use embassy_stm32::{bind_interrupts, eth, Config}; | |||
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 17 | use rand_core::RngCore; | 17 | use rand_core::RngCore; |
| 18 | use static_cell::StaticCell; | 18 | use static_cell::make_static; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | |||
| 21 | macro_rules! singleton { | ||
| 22 | ($val:expr) => {{ | ||
| 23 | type T = impl Sized; | ||
| 24 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 25 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 26 | x | ||
| 27 | }}; | ||
| 28 | } | ||
| 29 | |||
| 30 | bind_interrupts!(struct Irqs { | 20 | bind_interrupts!(struct Irqs { |
| 31 | ETH => eth::InterruptHandler; | 21 | ETH => eth::InterruptHandler; |
| 32 | }); | 22 | }); |
| @@ -56,7 +46,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 56 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; | 46 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; |
| 57 | 47 | ||
| 58 | let device = Ethernet::new( | 48 | let device = Ethernet::new( |
| 59 | singleton!(PacketQueue::<16, 16>::new()), | 49 | make_static!(PacketQueue::<16, 16>::new()), |
| 60 | p.ETH, | 50 | p.ETH, |
| 61 | Irqs, | 51 | Irqs, |
| 62 | p.PA1, | 52 | p.PA1, |
| @@ -73,15 +63,20 @@ async fn main(spawner: Spawner) -> ! { | |||
| 73 | 0, | 63 | 0, |
| 74 | ); | 64 | ); |
| 75 | 65 | ||
| 76 | let config = embassy_net::Config::Dhcp(Default::default()); | 66 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 77 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 67 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 78 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 68 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 79 | // dns_servers: Vec::new(), | 69 | // dns_servers: Vec::new(), |
| 80 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 70 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| 81 | //}); | 71 | //}); |
| 82 | 72 | ||
| 83 | // Init network stack | 73 | // Init network stack |
| 84 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 74 | let stack = &*make_static!(Stack::new( |
| 75 | device, | ||
| 76 | config, | ||
| 77 | make_static!(StackResources::<2>::new()), | ||
| 78 | seed | ||
| 79 | )); | ||
| 85 | 80 | ||
| 86 | // Launch network task | 81 | // Launch network task |
| 87 | unwrap!(spawner.spawn(net_task(&stack))); | 82 | unwrap!(spawner.spawn(net_task(&stack))); |
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 14e6b7914..6078fc3fe 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs | |||
| @@ -16,18 +16,8 @@ use embassy_time::{Duration, Timer}; | |||
| 16 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 17 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; | 17 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; |
| 18 | use rand_core::RngCore; | 18 | use rand_core::RngCore; |
| 19 | use static_cell::StaticCell; | 19 | use static_cell::make_static; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | |||
| 22 | macro_rules! singleton { | ||
| 23 | ($val:expr) => {{ | ||
| 24 | type T = impl Sized; | ||
| 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 26 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 27 | x | ||
| 28 | }}; | ||
| 29 | } | ||
| 30 | |||
| 31 | bind_interrupts!(struct Irqs { | 21 | bind_interrupts!(struct Irqs { |
| 32 | ETH => eth::InterruptHandler; | 22 | ETH => eth::InterruptHandler; |
| 33 | }); | 23 | }); |
| @@ -57,7 +47,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 57 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; | 47 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; |
| 58 | 48 | ||
| 59 | let device = Ethernet::new( | 49 | let device = Ethernet::new( |
| 60 | singleton!(PacketQueue::<16, 16>::new()), | 50 | make_static!(PacketQueue::<16, 16>::new()), |
| 61 | p.ETH, | 51 | p.ETH, |
| 62 | Irqs, | 52 | Irqs, |
| 63 | p.PA1, | 53 | p.PA1, |
| @@ -74,15 +64,20 @@ async fn main(spawner: Spawner) -> ! { | |||
| 74 | 0, | 64 | 0, |
| 75 | ); | 65 | ); |
| 76 | 66 | ||
| 77 | let config = embassy_net::Config::Dhcp(Default::default()); | 67 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 78 | //let config = embassy_net::Config::StaticConfig(embassy_net::Config { | 68 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 79 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 69 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 80 | // dns_servers: Vec::new(), | 70 | // dns_servers: Vec::new(), |
| 81 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 71 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| 82 | //}); | 72 | //}); |
| 83 | 73 | ||
| 84 | // Init network stack | 74 | // Init network stack |
| 85 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 75 | let stack = &*make_static!(Stack::new( |
| 76 | device, | ||
| 77 | config, | ||
| 78 | make_static!(StackResources::<2>::new()), | ||
| 79 | seed | ||
| 80 | )); | ||
| 86 | 81 | ||
| 87 | // Launch network task | 82 | // Launch network task |
| 88 | unwrap!(spawner.spawn(net_task(&stack))); | 83 | unwrap!(spawner.spawn(net_task(&stack))); |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 1972f8ff2..d360df085 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -62,49 +62,39 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 62 | T::enable(); | 62 | T::enable(); |
| 63 | <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); | 63 | <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); |
| 64 | 64 | ||
| 65 | unsafe { | 65 | ch1.set_speed(Speed::VeryHigh); |
| 66 | ch1.set_speed(Speed::VeryHigh); | 66 | ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 67 | ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 67 | ch2.set_speed(Speed::VeryHigh); |
| 68 | ch2.set_speed(Speed::VeryHigh); | 68 | ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 69 | ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 69 | ch3.set_speed(Speed::VeryHigh); |
| 70 | ch3.set_speed(Speed::VeryHigh); | 70 | ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 71 | ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 71 | ch4.set_speed(Speed::VeryHigh); |
| 72 | ch4.set_speed(Speed::VeryHigh); | 72 | ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 73 | ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); | ||
| 74 | } | ||
| 75 | 73 | ||
| 76 | let mut this = Self { inner: tim }; | 74 | let mut this = Self { inner: tim }; |
| 77 | 75 | ||
| 78 | this.set_freq(freq); | 76 | this.set_freq(freq); |
| 79 | this.inner.start(); | 77 | this.inner.start(); |
| 80 | 78 | ||
| 81 | unsafe { | 79 | let r = T::regs_gp32(); |
| 82 | T::regs_gp32() | 80 | r.ccmr_output(0) |
| 83 | .ccmr_output(0) | 81 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); |
| 84 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); | 82 | r.ccmr_output(0) |
| 85 | T::regs_gp32() | 83 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); |
| 86 | .ccmr_output(0) | 84 | r.ccmr_output(1) |
| 87 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); | 85 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); |
| 88 | T::regs_gp32() | 86 | r.ccmr_output(1) |
| 89 | .ccmr_output(1) | 87 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); |
| 90 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); | 88 | |
| 91 | T::regs_gp32() | ||
| 92 | .ccmr_output(1) | ||
| 93 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); | ||
| 94 | } | ||
| 95 | this | 89 | this |
| 96 | } | 90 | } |
| 97 | 91 | ||
| 98 | pub fn enable(&mut self, channel: Channel) { | 92 | pub fn enable(&mut self, channel: Channel) { |
| 99 | unsafe { | 93 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); |
| 100 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); | ||
| 101 | } | ||
| 102 | } | 94 | } |
| 103 | 95 | ||
| 104 | pub fn disable(&mut self, channel: Channel) { | 96 | pub fn disable(&mut self, channel: Channel) { |
| 105 | unsafe { | 97 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); |
| 106 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); | ||
| 107 | } | ||
| 108 | } | 98 | } |
| 109 | 99 | ||
| 110 | pub fn set_freq(&mut self, freq: Hertz) { | 100 | pub fn set_freq(&mut self, freq: Hertz) { |
| @@ -112,11 +102,11 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 112 | } | 102 | } |
| 113 | 103 | ||
| 114 | pub fn get_max_duty(&self) -> u32 { | 104 | pub fn get_max_duty(&self) -> u32 { |
| 115 | unsafe { T::regs_gp32().arr().read().arr() } | 105 | T::regs_gp32().arr().read().arr() |
| 116 | } | 106 | } |
| 117 | 107 | ||
| 118 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { | 108 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { |
| 119 | defmt::assert!(duty < self.get_max_duty()); | 109 | defmt::assert!(duty < self.get_max_duty()); |
| 120 | unsafe { T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) } | 110 | T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) |
| 121 | } | 111 | } |
| 122 | } | 112 | } |
diff --git a/examples/stm32h7/src/bin/wdg.rs b/examples/stm32h7/src/bin/wdg.rs index 2b0301aad..9181dfd67 100644 --- a/examples/stm32h7/src/bin/wdg.rs +++ b/examples/stm32h7/src/bin/wdg.rs | |||
| @@ -15,10 +15,10 @@ async fn main(_spawner: Spawner) { | |||
| 15 | 15 | ||
| 16 | let mut wdg = IndependentWatchdog::new(p.IWDG1, 20_000_000); | 16 | let mut wdg = IndependentWatchdog::new(p.IWDG1, 20_000_000); |
| 17 | 17 | ||
| 18 | unsafe { wdg.unleash() }; | 18 | wdg.unleash(); |
| 19 | 19 | ||
| 20 | loop { | 20 | loop { |
| 21 | Timer::after(Duration::from_secs(1)).await; | 21 | Timer::after(Duration::from_secs(1)).await; |
| 22 | unsafe { wdg.pet() }; | 22 | wdg.pet(); |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index ffb6cdb43..2ead714e4 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [features] | 7 | [features] |
| 8 | default = ["nightly"] | 8 | default = ["nightly"] |
| 9 | nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", | 9 | nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", "embassy-executor/nightly", |
| 10 | "embassy-lora", "lora-phy", "lorawan-device", "lorawan", "embedded-io/async"] | 10 | "embassy-lora", "lora-phy", "lorawan-device", "lorawan", "embedded-io/async"] |
| 11 | 11 | ||
| 12 | [dependencies] | 12 | [dependencies] |
| @@ -31,4 +31,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } | |||
| 31 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 31 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 32 | heapless = { version = "0.7.5", default-features = false } | 32 | heapless = { version = "0.7.5", default-features = false } |
| 33 | embedded-hal = "0.2.6" | 33 | embedded-hal = "0.2.6" |
| 34 | static_cell = "1.0" | 34 | static_cell = "1.1" |
diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml index 8b6508c87..93d48abeb 100644 --- a/examples/stm32l1/Cargo.toml +++ b/examples/stm32l1/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } |
| 12 | 12 | ||
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 29d091f94..3bb473ef5 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 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } | 11 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } |
| 12 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] } | 12 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] } |
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index 281346e5f..1771e5202 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs | |||
| @@ -12,12 +12,10 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 12 | fn main() -> ! { | 12 | fn main() -> ! { |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | unsafe { | 15 | pac::RCC.ccipr().modify(|w| { |
| 16 | pac::RCC.ccipr().modify(|w| { | 16 | w.set_adcsel(0b11); |
| 17 | w.set_adcsel(0b11); | 17 | }); |
| 18 | }); | 18 | pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); |
| 19 | pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); | ||
| 20 | } | ||
| 21 | 19 | ||
| 22 | let p = embassy_stm32::init(Default::default()); | 20 | let p = embassy_stm32::init(Default::default()); |
| 23 | 21 | ||
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index d6e744aa6..a36ed5d90 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs | |||
| @@ -11,11 +11,9 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 11 | fn main() -> ! { | 11 | fn main() -> ! { |
| 12 | info!("Hello World!"); | 12 | info!("Hello World!"); |
| 13 | 13 | ||
| 14 | unsafe { | 14 | pac::RCC.apb1enr1().modify(|w| { |
| 15 | pac::RCC.apb1enr1().modify(|w| { | 15 | w.set_dac1en(true); |
| 16 | w.set_dac1en(true); | 16 | }); |
| 17 | }); | ||
| 18 | } | ||
| 19 | 17 | ||
| 20 | let p = embassy_stm32::init(Default::default()); | 18 | let p = embassy_stm32::init(Default::default()); |
| 21 | 19 | ||
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index acb48c765..6035c291f 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } |
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| @@ -25,4 +25,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 25 | heapless = { version = "0.7.5", default-features = false } | 25 | heapless = { version = "0.7.5", default-features = false } |
| 26 | rand_core = { version = "0.6.3", default-features = false } | 26 | rand_core = { version = "0.6.3", default-features = false } |
| 27 | embedded-io = { version = "0.4.0", features = ["async"] } | 27 | embedded-io = { version = "0.4.0", features = ["async"] } |
| 28 | static_cell = "1.0" | 28 | static_cell = { version = "1.1", features = ["nightly"]} |
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index b84e53d3a..32eba4277 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs | |||
| @@ -15,20 +15,11 @@ use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; | |||
| 15 | use embassy_usb::{Builder, UsbDevice}; | 15 | use embassy_usb::{Builder, UsbDevice}; |
| 16 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 17 | use rand_core::RngCore; | 17 | use rand_core::RngCore; |
| 18 | use static_cell::StaticCell; | 18 | use static_cell::make_static; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 20 | ||
| 21 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; | 21 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; |
| 22 | 22 | ||
| 23 | macro_rules! singleton { | ||
| 24 | ($val:expr) => {{ | ||
| 25 | type T = impl Sized; | ||
| 26 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 27 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 28 | x | ||
| 29 | }}; | ||
| 30 | } | ||
| 31 | |||
| 32 | const MTU: usize = 1514; | 23 | const MTU: usize = 1514; |
| 33 | 24 | ||
| 34 | bind_interrupts!(struct Irqs { | 25 | bind_interrupts!(struct Irqs { |
| @@ -78,10 +69,10 @@ async fn main(spawner: Spawner) { | |||
| 78 | let mut builder = Builder::new( | 69 | let mut builder = Builder::new( |
| 79 | driver, | 70 | driver, |
| 80 | config, | 71 | config, |
| 81 | &mut singleton!([0; 256])[..], | 72 | &mut make_static!([0; 256])[..], |
| 82 | &mut singleton!([0; 256])[..], | 73 | &mut make_static!([0; 256])[..], |
| 83 | &mut singleton!([0; 256])[..], | 74 | &mut make_static!([0; 256])[..], |
| 84 | &mut singleton!([0; 128])[..], | 75 | &mut make_static!([0; 128])[..], |
| 85 | ); | 76 | ); |
| 86 | 77 | ||
| 87 | // Our MAC addr. | 78 | // Our MAC addr. |
| @@ -90,18 +81,18 @@ async fn main(spawner: Spawner) { | |||
| 90 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; | 81 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; |
| 91 | 82 | ||
| 92 | // Create classes on the builder. | 83 | // Create classes on the builder. |
| 93 | let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); | 84 | let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); |
| 94 | 85 | ||
| 95 | // Build the builder. | 86 | // Build the builder. |
| 96 | let usb = builder.build(); | 87 | let usb = builder.build(); |
| 97 | 88 | ||
| 98 | unwrap!(spawner.spawn(usb_task(usb))); | 89 | unwrap!(spawner.spawn(usb_task(usb))); |
| 99 | 90 | ||
| 100 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); | 91 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); |
| 101 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 92 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 102 | 93 | ||
| 103 | let config = embassy_net::Config::Dhcp(Default::default()); | 94 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 104 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 95 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 105 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 96 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 106 | // dns_servers: Vec::new(), | 97 | // dns_servers: Vec::new(), |
| 107 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 98 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| @@ -112,7 +103,12 @@ async fn main(spawner: Spawner) { | |||
| 112 | let seed = rng.next_u64(); | 103 | let seed = rng.next_u64(); |
| 113 | 104 | ||
| 114 | // Init network stack | 105 | // Init network stack |
| 115 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 106 | let stack = &*make_static!(Stack::new( |
| 107 | device, | ||
| 108 | config, | ||
| 109 | make_static!(StackResources::<2>::new()), | ||
| 110 | seed | ||
| 111 | )); | ||
| 116 | 112 | ||
| 117 | unwrap!(spawner.spawn(net_task(stack))); | 113 | unwrap!(spawner.spawn(net_task(stack))); |
| 118 | 114 | ||
diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml index be205f880..e2318c3d6 100644 --- a/examples/stm32u5/Cargo.toml +++ b/examples/stm32u5/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } |
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index 8cfac772a..83a443754 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml | |||
| @@ -6,9 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] } |
| 12 | embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] } | ||
| 12 | 13 | ||
| 13 | defmt = "0.3" | 14 | defmt = "0.3" |
| 14 | defmt-rtt = "0.4" | 15 | defmt-rtt = "0.4" |
diff --git a/examples/stm32wb/src/bin/tl_mbox.rs b/examples/stm32wb/src/bin/tl_mbox.rs index 8f4e70af0..9fc4b8aac 100644 --- a/examples/stm32wb/src/bin/tl_mbox.rs +++ b/examples/stm32wb/src/bin/tl_mbox.rs | |||
| @@ -4,14 +4,15 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::tl_mbox::{Config, TlMbox}; | 7 | use embassy_stm32::bind_interrupts; |
| 8 | use embassy_stm32::{bind_interrupts, tl_mbox}; | 8 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; |
| 9 | use embassy_stm32_wpan::TlMbox; | ||
| 9 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 12 | ||
| 12 | bind_interrupts!(struct Irqs{ | 13 | bind_interrupts!(struct Irqs{ |
| 13 | IPCC_C1_RX => tl_mbox::ReceiveInterruptHandler; | 14 | IPCC_C1_RX => ReceiveInterruptHandler; |
| 14 | IPCC_C1_TX => tl_mbox::TransmitInterruptHandler; | 15 | IPCC_C1_TX => TransmitInterruptHandler; |
| 15 | }); | 16 | }); |
| 16 | 17 | ||
| 17 | #[embassy_executor::main] | 18 | #[embassy_executor::main] |
| @@ -44,10 +45,10 @@ async fn main(_spawner: Spawner) { | |||
| 44 | info!("Hello World!"); | 45 | info!("Hello World!"); |
| 45 | 46 | ||
| 46 | let config = Config::default(); | 47 | let config = Config::default(); |
| 47 | let mbox = TlMbox::new(p.IPCC, Irqs, config); | 48 | let mbox = TlMbox::init(p.IPCC, Irqs, config); |
| 48 | 49 | ||
| 49 | loop { | 50 | loop { |
| 50 | let wireless_fw_info = mbox.wireless_fw_info(); | 51 | let wireless_fw_info = mbox.sys_subsystem.wireless_fw_info(); |
| 51 | match wireless_fw_info { | 52 | match wireless_fw_info { |
| 52 | None => info!("not yet initialized"), | 53 | None => info!("not yet initialized"), |
| 53 | Some(fw_info) => { | 54 | Some(fw_info) => { |
diff --git a/examples/stm32wb/src/bin/tl_mbox_tx_rx.rs b/examples/stm32wb/src/bin/tl_mbox_tx_rx.rs index 1724d946f..439bd01ac 100644 --- a/examples/stm32wb/src/bin/tl_mbox_tx_rx.rs +++ b/examples/stm32wb/src/bin/tl_mbox_tx_rx.rs | |||
| @@ -4,13 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::tl_mbox::{Config, TlMbox}; | 7 | use embassy_stm32::bind_interrupts; |
| 8 | use embassy_stm32::{bind_interrupts, tl_mbox}; | 8 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; |
| 9 | use embassy_stm32_wpan::TlMbox; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 11 | ||
| 11 | bind_interrupts!(struct Irqs{ | 12 | bind_interrupts!(struct Irqs{ |
| 12 | IPCC_C1_RX => tl_mbox::ReceiveInterruptHandler; | 13 | IPCC_C1_RX => ReceiveInterruptHandler; |
| 13 | IPCC_C1_TX => tl_mbox::TransmitInterruptHandler; | 14 | IPCC_C1_TX => TransmitInterruptHandler; |
| 14 | }); | 15 | }); |
| 15 | 16 | ||
| 16 | #[embassy_executor::main] | 17 | #[embassy_executor::main] |
| @@ -43,55 +44,20 @@ async fn main(_spawner: Spawner) { | |||
| 43 | info!("Hello World!"); | 44 | info!("Hello World!"); |
| 44 | 45 | ||
| 45 | let config = Config::default(); | 46 | let config = Config::default(); |
| 46 | let mbox = TlMbox::new(p.IPCC, Irqs, config); | 47 | let mbox = TlMbox::init(p.IPCC, Irqs, config); |
| 47 | 48 | ||
| 48 | info!("waiting for coprocessor to boot"); | 49 | let sys_event = mbox.sys_subsystem.read().await; |
| 49 | let event_box = mbox.read().await; | 50 | info!("sys event: {}", sys_event.payload()); |
| 50 | 51 | ||
| 51 | let mut payload = [0u8; 6]; | 52 | mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; |
| 52 | event_box.copy_into_slice(&mut payload).unwrap(); | ||
| 53 | 53 | ||
| 54 | let event_packet = event_box.evt(); | 54 | info!("starting ble..."); |
| 55 | let kind = event_packet.evt_serial.kind; | 55 | mbox.ble_subsystem.write(0x0c, &[]).await; |
| 56 | 56 | ||
| 57 | // means recieved SYS event, which indicates in this case that the coprocessor is ready | 57 | info!("waiting for ble..."); |
| 58 | if kind == 0x12 { | 58 | let ble_event = mbox.ble_subsystem.read().await; |
| 59 | let code = event_packet.evt_serial.evt.evt_code; | ||
| 60 | let payload_len = event_packet.evt_serial.evt.payload_len; | ||
| 61 | 59 | ||
| 62 | info!( | 60 | info!("ble event: {}", ble_event.payload()); |
| 63 | "==> kind: {:#04x}, code: {:#04x}, payload_length: {}, payload: {:#04x}", | ||
| 64 | kind, | ||
| 65 | code, | ||
| 66 | payload_len, | ||
| 67 | payload[3..] | ||
| 68 | ); | ||
| 69 | } | ||
| 70 | |||
| 71 | // initialize ble stack, does not return a response | ||
| 72 | mbox.shci_ble_init(Default::default()); | ||
| 73 | |||
| 74 | info!("resetting BLE"); | ||
| 75 | mbox.send_ble_cmd(&[0x01, 0x03, 0x0c, 0x00, 0x00]); | ||
| 76 | |||
| 77 | let event_box = mbox.read().await; | ||
| 78 | |||
| 79 | let mut payload = [0u8; 7]; | ||
| 80 | event_box.copy_into_slice(&mut payload).unwrap(); | ||
| 81 | |||
| 82 | let event_packet = event_box.evt(); | ||
| 83 | let kind = event_packet.evt_serial.kind; | ||
| 84 | |||
| 85 | let code = event_packet.evt_serial.evt.evt_code; | ||
| 86 | let payload_len = event_packet.evt_serial.evt.payload_len; | ||
| 87 | |||
| 88 | info!( | ||
| 89 | "==> kind: {:#04x}, code: {:#04x}, payload_length: {}, payload: {:#04x}", | ||
| 90 | kind, | ||
| 91 | code, | ||
| 92 | payload_len, | ||
| 93 | payload[3..] | ||
| 94 | ); | ||
| 95 | 61 | ||
| 96 | info!("Test OK"); | 62 | info!("Test OK"); |
| 97 | cortex_m::asm::bkpt(); | 63 | cortex_m::asm::bkpt(); |
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index 6191d01e9..260f9afa1 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] } |
| 12 | embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" } | 12 | embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" } |
diff --git a/examples/stm32wl/src/bin/lora_lorawan.rs b/examples/stm32wl/src/bin/lora_lorawan.rs index e179c5ca1..805d21418 100644 --- a/examples/stm32wl/src/bin/lora_lorawan.rs +++ b/examples/stm32wl/src/bin/lora_lorawan.rs | |||
| @@ -35,7 +35,7 @@ async fn main(_spawner: Spawner) { | |||
| 35 | config.rcc.enable_lsi = true; // enable RNG | 35 | config.rcc.enable_lsi = true; // enable RNG |
| 36 | let p = embassy_stm32::init(config); | 36 | let p = embassy_stm32::init(config); |
| 37 | 37 | ||
| 38 | unsafe { pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)) } | 38 | pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)); |
| 39 | 39 | ||
| 40 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); | 40 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); |
| 41 | 41 | ||
diff --git a/examples/stm32wl/src/bin/random.rs b/examples/stm32wl/src/bin/random.rs index 182c607f9..d8562fca5 100644 --- a/examples/stm32wl/src/bin/random.rs +++ b/examples/stm32wl/src/bin/random.rs | |||
| @@ -15,11 +15,9 @@ async fn main(_spawner: Spawner) { | |||
| 15 | config.rcc.enable_lsi = true; //Needed for RNG to work | 15 | config.rcc.enable_lsi = true; //Needed for RNG to work |
| 16 | 16 | ||
| 17 | let p = embassy_stm32::init(config); | 17 | let p = embassy_stm32::init(config); |
| 18 | unsafe { | 18 | pac::RCC.ccipr().modify(|w| { |
| 19 | pac::RCC.ccipr().modify(|w| { | 19 | w.set_rngsel(0b01); |
| 20 | w.set_rngsel(0b01); | 20 | }); |
| 21 | }); | ||
| 22 | } | ||
| 23 | 21 | ||
| 24 | info!("Hello World!"); | 22 | info!("Hello World!"); |
| 25 | 23 | ||
