From f733528d7ac42bc45e61f232ba4127506fc5dff5 Mon Sep 17 00:00:00 2001 From: chrysn Date: Thu, 23 Oct 2025 16:42:23 +0200 Subject: [PATCH 1/2] Make the DECT-2020 NR+ libmodem.a available as a feature --- Cargo.toml | 8 ++++++++ build.rs | 18 ++++++++++++++++-- wrapper.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 739c3d6..93d3624 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,14 @@ arm-none-eabi-objcopy = [] llvm-objcopy = ["dep:llvm-tools"] log = [] +## Links the DECT modem library +## +## This exposes the same set of headers, but internally uses a different +## libmodem.a library, which is used with considerable differences. Note that +## using this also requires using an alternative radio core firmware, which is +## not shipped in crates. +dect = [] + nrf9160 = [] nrf9151 = ["nrf9120"] nrf9161 = ["nrf9120"] diff --git a/build.rs b/build.rs index 385af64..f8d5dec 100644 --- a/build.rs +++ b/build.rs @@ -96,20 +96,34 @@ fn main() { let bindings_out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs"); std::fs::write(bindings_out_path, rust_source).expect("Couldn't write updated bindgen output"); - #[cfg(feature = "nrf9160")] + #[cfg(all(feature = "nrf9160", not(feature = "dect")))] let libmodem_original_path = if cfg!(feature = "log") { Path::new(&nrfxlib_path).join("nrf_modem/lib/cellular/nrf9160/hard-float/libmodem_log.a") } else { Path::new(&nrfxlib_path).join("nrf_modem/lib/cellular/nrf9160/hard-float/libmodem.a") }; - #[cfg(feature = "nrf9120")] + #[cfg(all(feature = "nrf9120", not(feature = "dect")))] let libmodem_original_path = if cfg!(feature = "log") { Path::new(&nrfxlib_path).join("nrf_modem/lib/cellular/nrf9120/hard-float/libmodem_log.a") } else { Path::new(&nrfxlib_path).join("nrf_modem/lib/cellular/nrf9120/hard-float/libmodem.a") }; + #[cfg(all(feature = "nrf9160", feature = "dect"))] + let libmodem_original_path = if cfg!(feature = "log") { + Path::new(&nrfxlib_path).join("nrf_modem/lib/dect_phy/nrf9160/hard-float/libmodem_log.a") + } else { + Path::new(&nrfxlib_path).join("nrf_modem/lib/dect_phy/nrf9160/hard-float/libmodem.a") + }; + + #[cfg(all(feature = "nrf9120", feature = "dect"))] + let libmodem_original_path = if cfg!(feature = "log") { + Path::new(&nrfxlib_path).join("nrf_modem/lib/dect_phy/nrf9120/hard-float/libmodem_log.a") + } else { + Path::new(&nrfxlib_path).join("nrf_modem/lib/dect_phy/nrf9120/hard-float/libmodem.a") + }; + let libmodem_changed_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("libmodem.a"); // The modem library now has compressed headers, but Rust cannot deal with that. diff --git a/wrapper.h b/wrapper.h index fccb710..2cf7fa3 100644 --- a/wrapper.h +++ b/wrapper.h @@ -15,6 +15,7 @@ #include "nrf_modem/include/nrf_modem_bootloader.h" #include "nrf_modem/include/nrf_modem_trace.h" #include "nrf_modem/include/nrf_gai_errors.h" +#include "nrf_modem/include/nrf_modem_dect_phy.h" /* * Crypto Cell 310 (CC310) platform headers From 8af2554d37bf1be6fe0c10594c18d356f538c872 Mon Sep 17 00:00:00 2001 From: chrysn Date: Tue, 11 Nov 2025 01:21:04 +0100 Subject: [PATCH 2/2] Run with -fshort-enums This is backed by observing structs such as nrf_modem_dect_phy_event: With packed enums, the fields in its nrf_modem_dect_phy_init_event make perfect sense (plausible voltage and temperatures, and no error); with long enums, it's all garbage data. --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index f8d5dec..976f96d 100644 --- a/build.rs +++ b/build.rs @@ -45,6 +45,8 @@ fn main() { .clang_arg("-mcpu=cortex-m33") // Use softfp .clang_arg("-mfloat-abi=soft") + // Enum types are short, eg. nrf_modem_dect_phy_err is 16bit + .clang_arg("-fshort-enums") // We're no_std .use_core() // Include only the useful stuff