diff --git a/.github/workflows/rust_ci.yml b/.github/workflows/rust_ci.yml index 3bcf5613..c4f3a41e 100644 --- a/.github/workflows/rust_ci.yml +++ b/.github/workflows/rust_ci.yml @@ -63,3 +63,6 @@ jobs: - name: Examples-NRF-Build | Compile run: cd examples/nrf; cargo build + + - name: Examples-STM32WB-Build | Compile + run: cd examples/stm32wb; cargo build diff --git a/examples/stm32wb/.cargo/config.toml b/examples/stm32wb/.cargo/config.toml new file mode 100644 index 00000000..04d2e49e --- /dev/null +++ b/examples/stm32wb/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace nRF82840_xxAA with your chip as listed in `probe-rs chip list` +runner = "probe-rs run --chip STM32WB55RG" + +[build] +target = "thumbv7em-none-eabi" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/stm32wb/.gitignore b/examples/stm32wb/.gitignore new file mode 100644 index 00000000..73fab072 --- /dev/null +++ b/examples/stm32wb/.gitignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml new file mode 100644 index 00000000..ff286f1b --- /dev/null +++ b/examples/stm32wb/Cargo.toml @@ -0,0 +1,66 @@ +[package] +name = "stm32wb-openthread-examples" +version = "0.1.0" +edition = "2024" +authors = ["bjoernQ "] +resolver = "2" +categories = ["embedded", "hardware-support"] +keywords = ["thread", "openthread", "embedded", "embassy"] +description = "openthread examples for stm32wb chips" +repository = "https://github.com/ivmarkov/esp-openthread" +license = "MIT OR Apache-2.0" +readme = "README.md" + +[profile.dev] +# Rust debug is too slow. +# For debug builds always builds with some optimization +opt-level = "z" + +[profile.release] +codegen-units = 1 # LLVM can perform better optimizations using a single thread +opt-level = "z" +lto = "fat" +debug = 2 +debug-assertions = false +overflow-checks = false + +[features] +default = [] + +[dependencies] +# Change stm32wb55rg to your chip name in both dependencies, if necessary. +embassy-stm32 = { version = "0.6.0", features = [ "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti", "low-power", "executor-thread"] } +embassy-stm32-wpan = { version = "0.1.0", features = ["defmt", "stm32wb55rg", "wb-thread"] } +embassy-sync = { version = "0.8.0", features = ["defmt"] } +embassy-executor = { version = "0.10.0", features = ["defmt"] } +embassy-time = { version = "0.5.1", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } +embassy-net = { version = "0.9.1", features = ["defmt", "proto-ipv6", "medium-ip", "udp"] } + +defmt = "1.0.1" +defmt-rtt = "1.0.0" + +cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } +cortex-m-rt = "0.7.0" +embedded-hal = "1.0.0" +panic-probe = { version = "1.0.0", features = ["print-defmt"] } +heapless = { version = "0.9", default-features = false } +static_cell = "2" +embassy-futures = "0.1.2" +rand_core = "0.9" + +openthread = { path = "../../openthread", features = ["udp", "srp", "embassy-net-driver-channel", "stm32-offload", "defmt"] } +tinyrlibc = { version = "0.5", default-features = false, features = ["strstr", "strcmp", "isupper", "utoa", "strtoul"] } + +[[bin]] +path = "./src/bin/basic_udp.rs" +name = "basic_udp" +#required-features = ["udp"] +harness = false + +[patch.crates-io] +embassy-stm32 = { version = "0.6.0", git="https://github.com/embassy-rs/embassy.git", rev="1bd5523" } +embassy-stm32-wpan = { version = "0.1.0", git="https://github.com/embassy-rs/embassy.git", rev="1bd5523" } +embassy-sync = { version = "0.8.0", git="https://github.com/embassy-rs/embassy.git", rev="1bd5523" } +embassy-executor = { version = "0.10.0", git="https://github.com/embassy-rs/embassy.git", rev="1bd5523" } +embassy-time = { version = "0.5.1", git="https://github.com/embassy-rs/embassy.git", rev="1bd5523" } +embassy-net = { version = "0.9.1", git="https://github.com/embassy-rs/embassy.git", rev="1bd5523" } \ No newline at end of file diff --git a/examples/stm32wb/LICENSE-APACHE b/examples/stm32wb/LICENSE-APACHE new file mode 100644 index 00000000..d2c040e5 --- /dev/null +++ b/examples/stm32wb/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + +To apply the Apache License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/examples/stm32wb/LICENSE-MIT b/examples/stm32wb/LICENSE-MIT new file mode 100644 index 00000000..3d3dcbae --- /dev/null +++ b/examples/stm32wb/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright [year] [fullname] + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/examples/stm32wb/build.rs b/examples/stm32wb/build.rs new file mode 100644 index 00000000..ce33437c --- /dev/null +++ b/examples/stm32wb/build.rs @@ -0,0 +1,10 @@ +use std::error::Error; + +fn main() -> Result<(), Box> { + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + println!("cargo:rustc-link-arg-bins=-Ttl_mbox.x"); + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + + Ok(()) +} diff --git a/examples/stm32wb/src/bin/basic_udp.rs b/examples/stm32wb/src/bin/basic_udp.rs new file mode 100644 index 00000000..543f49af --- /dev/null +++ b/examples/stm32wb/src/bin/basic_udp.rs @@ -0,0 +1,186 @@ +#![no_std] +#![no_main] + +use core::net::{Ipv6Addr, SocketAddrV6}; + +use defmt::*; +use embassy_executor::Spawner; +use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; +use embassy_stm32::peripherals::RNG; +use embassy_stm32::rcc::Config as RccConfig; +use embassy_stm32::rng::Rng; +use embassy_stm32::{bind_interrupts, rng}; +use embassy_stm32_wpan::TlMbox; +use embassy_stm32_wpan::sub::thread::Runner; +use embassy_stm32_wpan::sub::{mm, thread}; +use openthread::{BytesFmt, OpenThread, OtResources, OtUdpResources, SimpleRamSettings, UdpSocket}; +use rand_core::RngCore; +use {defmt_rtt as _, panic_probe as _}; + +bind_interrupts!(struct Irqs{ + IPCC_C1_RX => ReceiveInterruptHandler; + IPCC_C1_TX => TransmitInterruptHandler; + RNG => rng::InterruptHandler; +}); + +#[embassy_executor::task] +async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) { + memory_manager.run_queue().await; +} + +#[embassy_executor::task] +async fn run_wpan_thread(mut thread: thread::Runner<'static>) { + thread.run_stack().await; +} + +use tinyrlibc as _; + +macro_rules! mk_static { + ($t:ty) => {{ + static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); + #[deny(unused_attributes)] + let x = STATIC_CELL.uninit(); + x + }}; + ($t:ty,$val:expr) => {{ + static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); + #[deny(unused_attributes)] + let x = STATIC_CELL.uninit().write($val); + x + }}; +} + +const BOUND_PORT: u16 = 1212; + +const UDP_SOCKETS_BUF: usize = 1280; +const UDP_MAX_SOCKETS: usize = 2; + +const THREAD_DATASET: &str = if let Some(dataset) = option_env!("THREAD_DATASET") { + dataset +} else { + "0e080000000000010000000300000b35060004001fffe002083a90e3a319a904940708fd1fa298dbd1e3290510fe0458f7db96354eaa6041b880ea9c0f030f4f70656e5468726561642d35386431010258d10410888f813c61972446ab616ee3c556a5910c0402a0f7f8" +}; + +#[embassy_executor::main( + executor = "embassy_stm32::executor::Executor", + entry = "cortex_m_rt::entry" +)] +async fn main(spawner: Spawner) { + /* + How to make this work: + + - Obtain a NUCLEO-STM32WB55 from your preferred supplier. + - Download and Install STM32CubeProgrammer. + - Download stm32wb5x_FUS_fw.bin, stm32wb5x_Thread_MTD_fw.bin, and Release_Notes.html from + gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x + - Open STM32CubeProgrammer + - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware. + - Once complete, click connect to connect to the device. + - On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services". + - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file + - Select that file, the memory address, "verify download", and then "Firmware Upgrade". + - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the + stm32wb5x_BLE_Mac_802_15_4_fw.bin file. It should not be the same memory address. + - Select that file, the memory address, "verify download", and then "Firmware Upgrade". + - Select "Start Wireless Stack". + - Disconnect from the device. + - Run this example. + + Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name. + */ + + let mut config = embassy_stm32::Config::default(); + config.rcc = RccConfig::new_wpan(); + let p = embassy_stm32::init(config); + info!("Hello World!"); + + let config = Config::default(); + let (thread, mm) = TlMbox::wait_ready(p.IPCC, Irqs, config) + .await + .unwrap() + .init_thread() + .await + .unwrap(); + + let runner = Runner::new(thread); + + spawner.spawn(run_mm_queue(mm).unwrap()); + + spawner.spawn(run_wpan_thread(runner).unwrap()); + + info!("Starting..."); + + let rng = mk_static!(Rng<'static, RNG>, Rng::new(p.RNG, Irqs)); + + let mut ieee_eui64 = [0; 8]; + RngCore::fill_bytes(rng, &mut ieee_eui64); + + let ot_resources = mk_static!(OtResources, OtResources::new()); + let ot_udp_resources = + mk_static!(OtUdpResources, OtUdpResources::new()); + let ot_settings_buf = mk_static!([u8; 1024], [0; 1024]); + + let ot_settings = mk_static!(SimpleRamSettings, SimpleRamSettings::new(ot_settings_buf)); + + let ot = OpenThread::new_with_udp(ieee_eui64, rng, ot_settings, ot_resources, ot_udp_resources) + .unwrap(); + + info!("About to spawn OT IP info"); + + spawner.spawn(run_ot_ip_info(ot.clone()).unwrap()); + + info!("Dataset: {}", THREAD_DATASET); + + ot.set_active_dataset_tlv_hexstr(THREAD_DATASET).unwrap(); + ot.enable_ipv6(true).unwrap(); + ot.enable_thread(true).unwrap(); + + let socket = UdpSocket::bind( + ot, + &SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, BOUND_PORT, 0, 0), + ) + .unwrap(); + + info!( + "Opened socket on port {} and waiting for packets...", + BOUND_PORT + ); + + let buf: &mut [u8] = unsafe { mk_static!([u8; UDP_SOCKETS_BUF]).assume_init_mut() }; + + loop { + let (len, local, remote) = socket.recv(buf).await.unwrap(); + + info!("Got {} from {} on {}", BytesFmt(&buf[..len]), remote, local); + + socket.send(b"Hello", Some(&local), &remote).await.unwrap(); + info!("Sent `b\"Hello\"`"); + } +} + +#[embassy_executor::task] +async fn run_ot_ip_info(ot: OpenThread<'static>) -> ! { + let mut cur_addrs = heapless::Vec::<(Ipv6Addr, u8), 4>::new(); + + loop { + let mut addrs = heapless::Vec::<(Ipv6Addr, u8), 4>::new(); + ot.ipv6_addrs(|addr| { + if let Some(addr) = addr { + let _ = addrs.push(addr); + } + + Ok(()) + }) + .unwrap(); + + if cur_addrs != addrs { + info!("Got new IPv6 address(es) from OpenThread: {:?}", addrs); + + cur_addrs = addrs; + + info!("Waiting for OpenThread changes signal..."); + } + + ot.wait_changed().await; + } +} diff --git a/openthread-sys/Cargo.toml b/openthread-sys/Cargo.toml index 7a2837a8..69a67488 100644 --- a/openthread-sys/Cargo.toml +++ b/openthread-sys/Cargo.toml @@ -19,6 +19,11 @@ force-generate-bindings = [] # If this feature is not enabled, the build will assume and use the "official" RiscV GCC toolchain: # https://github.com/riscv-collab/riscv-gnu-toolchain force-esp-riscv-toolchain = [] +# stm32wb support +stm32-offload = ["dep:stm32-bindings"] + +[dependencies] +stm32-bindings = { version = "0.2.1", features = ["lib_stm32wb_ot_mtd_lib", "wb_wpan_openthread"], optional=true } [build-dependencies] anyhow = "1" diff --git a/openthread-sys/build.rs b/openthread-sys/build.rs index 4fe3277e..c055c7c2 100644 --- a/openthread-sys/build.rs +++ b/openthread-sys/build.rs @@ -30,8 +30,9 @@ fn main() -> Result<()> { let dirs = if pregen_bindings && pregen_bindings_rs_file.exists() { // Use the pre-generated bindings Some((pregen_bindings_rs_file, pregen_libs_dir)) - } else if target.ends_with("-espidf") { + } else if target.ends_with("-espidf") || env::var("CARGO_FEATURE_STM32_OFFLOAD").is_ok() { // Nothing to do for ESP-IDF, `esp-idf-sys` will do everything for us + // Nothing to do for stm32wb, `stm32-bindings` will do everything for us None } else { let clang_sysroot = if use_gcc { diff --git a/openthread-sys/src/lib.rs b/openthread-sys/src/lib.rs index e288c8be..3920ffdb 100644 --- a/openthread-sys/src/lib.rs +++ b/openthread-sys/src/lib.rs @@ -45,9 +45,12 @@ pub use bindings::*; clippy::all )] mod bindings { - #[cfg(not(target_os = "espidf"))] + #[cfg(not(any(target_os = "espidf", feature = "stm32-offload")))] include!(env!("OPENTHREAD_SYS_BINDINGS_FILE")); #[cfg(target_os = "espidf")] pub use esp_idf_sys::*; + + #[cfg(feature = "stm32-offload")] + pub use stm32_bindings::openthread::*; } diff --git a/openthread/Cargo.toml b/openthread/Cargo.toml index e0293e84..07ce0e34 100644 --- a/openthread/Cargo.toml +++ b/openthread/Cargo.toml @@ -23,6 +23,7 @@ defmt = ["dep:defmt", "heapless/defmt-03", "embassy-time/defmt"] force-generate-bindings = ["openthread-sys/force-generate-bindings"] force-esp-riscv-toolchain = ["openthread-sys/force-esp-riscv-toolchain"] isupper = [] # Provide internal implementation of the `isupper` C fn +stm32-offload = ["openthread-sys/stm32-offload"] [dependencies] openthread-sys = { path = "../openthread-sys" } diff --git a/openthread/src/lib.rs b/openthread/src/lib.rs index 2e44478e..6c0f14d6 100644 --- a/openthread/src/lib.rs +++ b/openthread/src/lib.rs @@ -63,6 +63,8 @@ mod settings; mod signal; #[cfg(feature = "srp")] mod srp; +#[cfg(feature = "stm32-offload")] +pub mod stm32wb; #[cfg(feature = "udp")] mod udp; diff --git a/openthread/src/stm32wb.rs b/openthread/src/stm32wb.rs new file mode 100644 index 00000000..782b614d --- /dev/null +++ b/openthread/src/stm32wb.rs @@ -0,0 +1,30 @@ +//! Provides a fake radio + +use crate::{Capabilities, MacCapabilities, Radio, RadioErrorKind}; + +pub struct OffloadRadio; + +impl Radio for OffloadRadio { + type Error = RadioErrorKind; + + const CAPS: crate::Capabilities = Capabilities::all(); + + const MAC_CAPS: MacCapabilities = MacCapabilities::all(); + + async fn set_config(&mut self, _config: &crate::Config) -> Result<(), Self::Error> { + Ok(()) + } + + async fn receive(&mut self, _psdu_buf: &mut [u8]) -> Result { + unreachable!() + } + + async fn transmit( + &mut self, + _psdu: &[u8], + _cca: bool, + _ack_psdu_buf: Option<&mut [u8]>, + ) -> Result, Self::Error> { + unreachable!() + } +}