From 2e71bbaa21b6453cbb2522ed77e210c66f88fc77 Mon Sep 17 00:00:00 2001 From: Harry Hornbacher Date: Fri, 25 Sep 2026 16:38:18 +0200 Subject: [PATCH] Allocate NPL controller and host memory from internal RAM - Hand the NimBLE controller malloc_internal instead of the untagged malloc - Allocate NPL events, callouts and the msys mbuf pools with calloc_internal - Make ble::malloc_internal available on every chip, not only ESP32/C3/S3 --- esp-radio/src/ble/mod.rs | 3 ++- esp-radio/src/ble/npl.rs | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/esp-radio/src/ble/mod.rs b/esp-radio/src/ble/mod.rs index 50fa0b6551e..b3a7fd3d892 100644 --- a/esp-radio/src/ble/mod.rs +++ b/esp-radio/src/ble/mod.rs @@ -36,11 +36,12 @@ unstable_module! { pub mod controller; } +#[cfg(bt_controller = "btdm")] pub(crate) unsafe extern "C" fn malloc(size: u32) -> *mut crate::sys::c_types::c_void { unsafe { crate::compat::malloc::malloc(size as usize).cast() } } -#[cfg(any(esp32, esp32c3, esp32s3))] +#[cfg(any(bt_controller = "btdm", bt_controller = "npl"))] pub(crate) unsafe extern "C" fn malloc_internal(size: u32) -> *mut crate::sys::c_types::c_void { unsafe { crate::compat::malloc::malloc_internal(size as usize).cast() } } diff --git a/esp-radio/src/ble/npl.rs b/esp-radio/src/ble/npl.rs index f7f02ec2a77..70aa9641338 100644 --- a/esp-radio/src/ble/npl.rs +++ b/esp-radio/src/ble/npl.rs @@ -356,7 +356,7 @@ static G_OSI_FUNCS: ExtFuncsT = ExtFuncsT { esp_intr_alloc: Some(self::ble_os_adapter_chip_specific::esp_intr_alloc), esp_intr_free: Some(esp_intr_free), - malloc: Some(crate::ble::malloc), + malloc: Some(crate::ble::malloc_internal), free: Some(crate::ble::free), #[cfg(esp32c2)] hal_uart_start_tx: None, @@ -1039,7 +1039,8 @@ unsafe extern "C" fn ble_npl_event_init( if unsafe { (*event).dummy } == 0 { unsafe { - let evt = crate::compat::malloc::calloc(1, core::mem::size_of::()) as *mut Event; + let evt = crate::compat::malloc::calloc_internal(1, core::mem::size_of::()) + as *mut Event; (*evt).event_fn_ptr = func; (*evt).ev_arg_ptr = arg; @@ -1214,7 +1215,8 @@ unsafe extern "C" fn ble_npl_callout_init( unsafe { let new_callout = - crate::compat::malloc::calloc(1, core::mem::size_of::()) as *mut Callout; + crate::compat::malloc::calloc_internal(1, core::mem::size_of::()) + as *mut Callout; (*new_callout).eventq = eventq; ble_npl_event_init(addr_of_mut!((*new_callout).events), func, args); (*callout).dummy = new_callout as i32; @@ -1570,11 +1572,11 @@ pub(crate) fn ble_deinit() { #[cfg(esp32c2)] fn os_msys_buf_alloc() -> bool { unsafe { - OS_MSYS_INIT_1_DATA = crate::compat::malloc::calloc( + OS_MSYS_INIT_1_DATA = crate::compat::malloc::calloc_internal( 1, core::mem::size_of::() * SYSINIT_MSYS_1_MEMPOOL_SIZE, ) as *mut u32; - OS_MSYS_INIT_2_DATA = crate::compat::malloc::calloc( + OS_MSYS_INIT_2_DATA = crate::compat::malloc::calloc_internal( 1, core::mem::size_of::() * SYSINIT_MSYS_2_MEMPOOL_SIZE, ) as *mut u32;