全志R128蓝牙占用内存资源较大,修改menuconfig配置后经常编译不过或无法运行解决方法
  EN8RstcYnW4n 2023年11月05日 48 0

R128蓝牙占用内存资源较大,尝试修改过以下两处的蓝牙配置,修改后再重新编译就会失败

1、使用menuconfig修改配置CONFIG_BT_VAR_MEM_DYNC_ALLOC=y,后初始化蓝牙失败

[cmd ERR] bt_ready():556, Bluetooth init failed (err -105)

添加打印定位到是内存分配失败

2、使用menuconfig修改配置CONFIG_BT_SMP关闭可以减少很多内存,但是编译出错,提示缺少smp_null.c。

CONFIG_BT_VAR_MEM_DYNC_ALLOC配置问题,修改方法如下。,即交换

_net_buf_pool_list_end = .;

KEEP(*(SORT_BY_NAME("._net_buf_pool.static.*")))

这两行

diff --git a/include/ble/linker/common-ram.ld b/include/ble/linker/common-ram.ld
index e97433c91..40744e392 100755
--- a/include/ble/linker/common-ram.ld
+++ b/include/ble/linker/common-ram.ld
@@ -84,8 +84,8 @@
        {
                _net_buf_pool_list_start = .;
                _net_buf_pool_list = .;
                KEEP(*(SORT_BY_NAME("._net_buf_pool.static.*")))
                _net_buf_pool_list_end = .;
        } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)

CONFIG_BT_SMP 配置问题,下面内容保存为smp_null.c 放到

./src/ble/host/smp_null.c
/**
 * @file smp_null.c
 * Security Manager Protocol stub
 */

/*
 * Copyright (c) 2015-2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <errno.h>
#include <ble/sys/atomic.h>
#include <ble/sys/util.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/conn.h>
#include <bluetooth/buf.h>

#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_smp
#include "common/log.h"

#include "hci_core.h"
#include "conn_internal.h"
#include "l2cap_internal.h"
#include "smp.h"

static struct bt_l2cap_le_chan bt_smp_pool[CONFIG_BT_MAX_CONN];

int bt_smp_sign_verify(struct bt_conn *conn, struct net_buf *buf)
{
        return -ENOTSUP;
}

int bt_smp_sign(struct bt_conn *conn, struct net_buf *buf)
{
        return -ENOTSUP;
}

static int bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *req_buf)
{
        struct bt_conn *conn = chan->conn;
        struct bt_smp_pairing_fail *rsp;
        struct bt_smp_hdr *hdr;
        struct net_buf *buf;

        ARG_UNUSED(req_buf);

        /* If a device does not support pairing then it shall respond with
         * a Pairing Failed command with the reason set to "Pairing Not
         * Supported" when any command is received.
         * Core Specification Vol. 3, Part H, 3.3
         */

        buf = bt_l2cap_create_pdu(NULL, 0);
        /* NULL is not a possible return due to K_FOREVER */

        hdr = net_buf_add(buf, sizeof(*hdr));
        hdr->code = BT_SMP_CMD_PAIRING_FAIL;

        rsp = net_buf_add(buf, sizeof(*rsp));
        rsp->reason = BT_SMP_ERR_PAIRING_NOTSUPP;

        if (bt_l2cap_send_cb(conn, BT_L2CAP_CID_SMP, buf, NULL, NULL)) {
                net_buf_unref(buf);
        }

        return 0;
}

static int bt_smp_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
{
        int i;
        static const struct bt_l2cap_chan_ops ops = {
                .recv = bt_smp_recv,
        };

        BT_DBG("conn %p handle %u", conn, conn->handle);

        for (i = 0; i < ARRAY_SIZE(bt_smp_pool); i++) {
                struct bt_l2cap_le_chan *smp = &bt_smp_pool[i];

                if (smp->chan.conn) {
                        continue;
                }

                smp->chan.ops = &ops;

                *chan = &smp->chan;

                return 0;
        }

        BT_ERR("No available SMP context for conn %p", conn);

        return -ENOMEM;
}

BT_L2CAP_CHANNEL_DEFINE(smp_fixed_chan, BT_L2CAP_CID_SMP, bt_smp_accept, NULL);

int bt_smp_init(void)
{
        return 0;
}

#if defined(CONFIG_BT_DEINIT)
int bt_smp_deinit(void)
{
        return 0;
}

void bt_smp_mem_deinit(void)
{
        return;
}

void bt_keys_mem_deinit(void)
{
    return;
}
#endif
#if defined(CONFIG_BT_VAR_MEM_DYNC_ALLOC)
void keys_dynamic_mem_alloc(void)
{
}
void keys_dynamic_mem_free(void)
{
}
#endif
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  JBfJ5LpBD0AJ   2023年11月13日   23   0   0 初始化链表#define
  HE3leaVn7jMN   2023年11月24日   28   0   0 Timei++#include
  HE3leaVn7jMN   2023年11月26日   28   0   0 i++#include
EN8RstcYnW4n