Skip to content

Commit aae5e12

Browse files
author
Zhou Xiao
committed
fix(ble): ensure internal malloc in ble log spi out
(cherry picked from commit d300617) Co-authored-by: Zhou Xiao <[email protected]>
1 parent 3fcb964 commit aae5e12

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

components/bt/common/ble_log/ble_log_spi_out.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define SPI_OUT_PACKET_LOSS_FRAME_SIZE (6)
3838
#define SPI_OUT_TRANS_ITVL_MIN_US (30)
3939
#define SPI_OUT_UL_LOG_STR_BUF_SIZE (100)
40+
#define SPI_OUT_MALLOC(size) heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
4041

4142
#if SPI_OUT_TS_SYNC_ENABLED
4243
#define SPI_OUT_TS_SYNC_TIMEOUT (1000 * 1000)
@@ -233,13 +234,13 @@ static void spi_out_le_audio_log_deinit(void);
233234
static int spi_out_init_trans(spi_out_trans_cb_t **trans_cb, uint16_t buf_size)
234235
{
235236
// Memory allocations
236-
*trans_cb = (spi_out_trans_cb_t *)malloc(sizeof(spi_out_trans_cb_t));
237+
*trans_cb = (spi_out_trans_cb_t *)SPI_OUT_MALLOC(sizeof(spi_out_trans_cb_t));
237238
if (!(*trans_cb)) {
238239
return -1;
239240
}
240241
memset(*trans_cb, 0, sizeof(spi_out_trans_cb_t));
241242

242-
uint8_t *buf = (uint8_t *)spi_bus_dma_memory_alloc(SPI_OUT_BUS, (size_t)buf_size, 0);
243+
uint8_t *buf = (uint8_t *)SPI_OUT_MALLOC((size_t)buf_size);
243244
if (!buf) {
244245
free(*trans_cb);
245246
*trans_cb = NULL;
@@ -311,7 +312,7 @@ IRAM_ATTR static inline void spi_out_append_trans(spi_out_trans_cb_t *trans_cb)
311312
static int spi_out_log_cb_init(spi_out_log_cb_t **log_cb, uint16_t buf_size, uint8_t type)
312313
{
313314
// Initialize log control block
314-
*log_cb = (spi_out_log_cb_t *)malloc(sizeof(spi_out_log_cb_t));
315+
*log_cb = (spi_out_log_cb_t *)SPI_OUT_MALLOC(sizeof(spi_out_log_cb_t));
315316
if (!(*log_cb)) {
316317
ESP_LOGE(BLE_LOG_TAG, "Failed to initialize log control block!");
317318
return -1;
@@ -427,7 +428,7 @@ IRAM_ATTR static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8
427428

428429
memcpy(buf, (const uint8_t *)&head, SPI_OUT_FRAME_HEAD_LEN);
429430
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN, addr, len);
430-
if (len_append) {
431+
if (len_append && addr_append) {
431432
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
432433
}
433434
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + total_length, &checksum, SPI_OUT_FRAME_TAIL_LEN);
@@ -520,7 +521,7 @@ static int spi_out_ul_log_init(void)
520521
}
521522

522523
// Initialize string buffer
523-
ul_log_str_buf = (uint8_t *)malloc(SPI_OUT_UL_LOG_STR_BUF_SIZE);
524+
ul_log_str_buf = (uint8_t *)SPI_OUT_MALLOC(SPI_OUT_UL_LOG_STR_BUF_SIZE);
524525
if (!ul_log_str_buf) {
525526
ESP_LOGE(BLE_LOG_TAG, "Failed to initialize string buffer for upper layer task log!");
526527
goto str_buf_init_failed;

components/bt/common/ble_log/include/ble_log/ble_log_spi_out.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "esp_timer.h"
1414
#include "esp_log.h"
1515
#include "freertos/semphr.h"
16+
#include "esp_heap_caps.h"
1617

1718
// Public enums
1819
enum {

0 commit comments

Comments
 (0)