diff --git a/Cargo.toml b/Cargo.toml index bf2ae82..f0bbe69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nrfxlib" -version = "0.6.0" +version = "0.6.1" authors = ["Jonathan Pallant (42 Technology) "] edition = "2018" license = "MIT OR Apache-2.0" @@ -18,3 +18,4 @@ linked_list_allocator = { version = "0.10", default-features = false, features = ] } log = "0.4" nrfxlib-sys = "=1.5.1" +grounded = "0.2.0" diff --git a/README.md b/README.md index ec57330..35de59f 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,17 @@ See [nrf9160-demo](https://github.com/42-technology-ltd/nrf9160-demo) for a demo ## Changelog -### Unreleased Changes ([Source](https://github.com/42-technology-ltd/nrfxlib/tree/develop) | [Changes](https://github.com/42-technology-ltd/nrfxlib/compare/v0.6.0...develop)) +### Unreleased Changes ([Source](https://github.com/42-technology-ltd/nrfxlib/tree/develop) | [Changes](https://github.com/42-technology-ltd/nrfxlib/compare/v0.6.1...develop)) * None +### v0.6.1 ([Source](https://github.com/42-technology-ltd/nrfxlib/tree/v0.6.1) | [Changes](https://github.com/42-technology-ltd/nrfxlib/compare/v0.6.0...v0.6.1)) + +* Fixed a memory ownership issue in `nrf_modem_init`. The `nrf_modem_init_params` pointer given to the init must + have a static lifetime. This has been a stack variable since forever. + Originally this seems to have not been required, but this changed +-4 years ago + without documentation update from Nordic. + ### v0.6.0 ([Source](https://github.com/42-technology-ltd/nrfxlib/tree/v0.6.0) | [Changes](https://github.com/42-technology-ltd/nrfxlib/compare/v0.5.0...v0.6.0)) * Updated to nrfxlib-sys v1.5.1. diff --git a/src/lib.rs b/src/lib.rs index 6a5be3d..8333c03 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,12 +163,14 @@ pub fn init() -> Result<(), Error> { let heap_start = HEAP_MEMORY.as_mut_ptr() as *mut _; let heap_size = HEAP_MEMORY.len() * core::mem::size_of::(); cortex_m::interrupt::free(|cs| { - *LIBRARY_ALLOCATOR.borrow(cs).borrow_mut() = - Some(Heap::new(heap_start, heap_size)) + *LIBRARY_ALLOCATOR.borrow(cs).borrow_mut() = Some(Heap::new(heap_start, heap_size)) }); } // Tell nrf_modem what memory it can use. + static PARAMS: grounded::uninit::GroundedCell = + grounded::uninit::GroundedCell::uninit(); + let params = sys::nrf_modem_init_params_t { shmem: sys::nrf_modem_shmem_cfg { ctrl: sys::nrf_modem_shmem_cfg__bindgen_ty_1 { @@ -195,6 +197,8 @@ pub fn init() -> Result<(), Error> { ipc_irq_prio: 0, }; + cortex_m::interrupt::free(|_| unsafe { PARAMS.get().write(params) }); + unsafe { // Use the same TX memory region as above cortex_m::interrupt::free(|cs| { @@ -206,7 +210,7 @@ pub fn init() -> Result<(), Error> { } // OK, let's start the library - let result = unsafe { sys::nrf_modem_init(¶ms, sys::nrf_modem_mode_t_NORMAL_MODE) }; + let result = unsafe { sys::nrf_modem_init(PARAMS.get(), sys::nrf_modem_mode_t_NORMAL_MODE) }; // Was it happy? if result < 0 {