fix(ble): Fix restore write-back error caused by memory allocated in PSRAM

This commit is contained in:
xiongweichao
2026-02-24 10:30:34 +08:00
parent 223de94067
commit c9ea57b795
2 changed files with 15 additions and 3 deletions
+14 -2
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -127,7 +127,7 @@ do{\
} while(0) } while(0)
#define OSI_FUNCS_TIME_BLOCKING 0xffffffff #define OSI_FUNCS_TIME_BLOCKING 0xffffffff
#define OSI_VERSION 0x0001000A #define OSI_VERSION 0x0001000B
#define OSI_MAGIC_VALUE 0xFADEBEAD #define OSI_MAGIC_VALUE 0xFADEBEAD
#define BLE_PWR_HDL_INVL 0xFFFF #define BLE_PWR_HDL_INVL 0xFFFF
@@ -232,6 +232,7 @@ struct osi_funcs_t {
void (* _esp_hw_power_down)(void); void (* _esp_hw_power_down)(void);
void (* _esp_hw_power_up)(void); void (* _esp_hw_power_up)(void);
void (* _ets_backup_dma_copy)(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_rem); void (* _ets_backup_dma_copy)(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_rem);
void *(* _malloc_retention)(size_t size);
void (* _ets_delay_us)(uint32_t us); void (* _ets_delay_us)(uint32_t us);
void (* _btdm_rom_table_ready)(void); void (* _btdm_rom_table_ready)(void);
bool (* _coex_bt_wakeup_request)(void); bool (* _coex_bt_wakeup_request)(void);
@@ -374,6 +375,7 @@ static int task_create_wrapper(void *task_func, const char *name, uint32_t stack
static void task_delete_wrapper(void *task_handle); static void task_delete_wrapper(void *task_handle);
static bool is_in_isr_wrapper(void); static bool is_in_isr_wrapper(void);
static void *malloc_internal_wrapper(size_t size); static void *malloc_internal_wrapper(size_t size);
static void *malloc_retention_wrapper(size_t size);
static int read_mac_wrapper(uint8_t mac[6]); static int read_mac_wrapper(uint8_t mac[6]);
static void srand_wrapper(unsigned int seed); static void srand_wrapper(unsigned int seed);
static int rand_wrapper(void); static int rand_wrapper(void);
@@ -453,6 +455,7 @@ static const struct osi_funcs_t osi_funcs_ro = {
._cause_sw_intr_to_core = NULL, ._cause_sw_intr_to_core = NULL,
._malloc = malloc, ._malloc = malloc,
._malloc_internal = malloc_internal_wrapper, ._malloc_internal = malloc_internal_wrapper,
._malloc_retention = malloc_retention_wrapper,
._free = free, ._free = free,
._read_efuse_mac = read_mac_wrapper, ._read_efuse_mac = read_mac_wrapper,
._srand = srand_wrapper, ._srand = srand_wrapper,
@@ -1060,6 +1063,15 @@ static void *malloc_internal_wrapper(size_t size)
return p; return p;
} }
static void *malloc_retention_wrapper(size_t size)
{
void *p = heap_caps_malloc(size, MALLOC_CAP_RETENTION);
if(p == NULL) {
ESP_LOGE(BT_LOG_TAG, "Malloc failed");
}
return p;
}
void *malloc_ble_controller_mem(size_t size) void *malloc_ble_controller_mem(size_t size)
{ {
void *p = heap_caps_malloc(size, BLE_CONTROLLER_MALLOC_CAPS); void *p = heap_caps_malloc(size, BLE_CONTROLLER_MALLOC_CAPS);