Rdzleo 2b4cf82f0c fix(ble): 释放 27 KB DRAM 给 BT controller, 修复手机搜不到 BLE 信号
============ 问题现象 ============

  烧录 f5a2777 (A+B+C 三件套 + BT_ALLOCATION_FROM_SPIRAM_FIRST) 后:
     BOOT 按键可正常进入配网模式 (不再 future_new abort)
     手机搜不到 Kapi 蓝牙信号
    日志:
      E (2240) BLE_INIT: Malloc failed
      E (2240) BT_HCI: CC evt: op=0x2008, status=0x7 (HCI_BLE_WRITE_ADV_DATA)
      代码层 "广播启动成功" 但 ADV_DATA 实际为空, 手机不可见

============ 根因 ============

  CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST 只影响 Bluedroid host 层动态分配,
  不影响 BT controller. 上一次提交修了 host (future_new 不再 NULL),
  但 controller 自己分配 advertising buffer 仍然失败 → ADV_DATA op=0x2008
  malloc fail → 广播空数据.

  size 对比 (Kapi vs Baji 已修好版本):
    Kapi DIRAM .bss = 51152 字节 (54.25%, 剩余 156 KB)
    Baji DIRAM .bss = 23536 字节 (50.58%, 剩余 169 KB)

  差异定位 (per-archive .bss):
    libbt.a       : Kapi 12450 / Baji 0  (Baji 已挪 PSRAM)
    libnet80211.a : Kapi  7570 / Baji 0  (Baji 已挪 PSRAM)
    liblwip.a     : Kapi  4691 / Baji 0  (Baji 已挪 PSRAM)
    libwpa.a      : Kapi  1326 / Baji 0  (Baji 已挪 PSRAM)
    libpp.a       : Kapi  1177 / Baji 0  (Baji 已挪 PSRAM)
    合计 27214 字节 (~27 KB) 都在 Kapi 内部 SRAM, 不在 Baji.

============ 修复 ============

  sdkconfig + sdkconfig.defaults.esp32s3:
    +CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
    +CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY=y

  作用: 允许 ESP-IDF linker 把 BT/WiFi/LWIP 等核心库的 .bss 段整体
  搬到 PSRAM, 释放等量内部 SRAM 给 BT controller 启动时分配
  ADV_DATA / SCAN_RSP_DATA / connection state buffer.

============ 验证 (用户实测 2026-05-21) ============

   BOOT 按键进入配网模式, 蓝牙配网音效正常播放
   手机扫描可见 Kapi 蓝牙信号
   蓝牙连接 + WiFi 配置 + 设备重启后自动连 WiFi 成功

  size 实测 (修复后):
    DIRAM .bss: 51152 → 23816 (-27336 字节, -27 KB)
    DIRAM 总占: 185410 → 158114 (54.25% → 46.26%)
    剩余 DIRAM: 156350 → 183646 (+27 KB)
  Flash Data 多出 27 KB .bss (实际放 PSRAM).

============ 移植说明 ============

  本修复需与上次 commit f5a2777 (A+B+C 三件套 + BT_ALLOCATION_FROM_SPIRAM_FIRST)
  搭配使用, 缺一不可:
    - f5a2777 修 host: future_new 不 abort, 可进入配网模式
    - 本次   修 controller: ADV_DATA buffer 可分配, 手机搜得到
    - 加 A方案 LWIP_MAX_SOCKETS=20: 修 RTC 偶发连接失败
    - 加 B方案 ForceRebuildEngine: 兜底 SDK 状态污染
    - 加 C方案 DIAG_RTC_BIND_ENABLE: 一键诊断埋点

  关联文档:
    全局 CLAUDE.md "BLE 配网 DRAM 紧张完整排查流程"
    项目记忆 project_ble_provisioning_issues.md
    Baji commit bffd316 (相同思路在 Baji 验证有效)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 16:03:32 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00

XiaoZhi AI Chatbot

(中文 | English | 日本語)

Introduction

👉 Build your AI chat companion with ESP32+SenseVoice+Qwen72B!【bilibili】

👉 Equipping XiaoZhi with DeepSeek's smart brain【bilibili】

👉 Build your own AI companion, a beginner's guide【bilibili】

Project Purpose

This is an open-source project released under the MIT license, allowing anyone to use it freely, including for commercial purposes.

Through this project, we aim to help more people get started with AI hardware development and understand how to implement rapidly evolving large language models in actual hardware devices. Whether you're a student interested in AI or a developer exploring new technologies, this project offers valuable learning experiences.

Everyone is welcome to participate in the project's development and improvement. If you have any ideas or suggestions, please feel free to raise an Issue or join the chat group.

Learning & Discussion QQ Group: 376893254

Implemented Features

  • Wi-Fi / ML307 Cat.1 4G
  • BOOT button wake-up and interruption, supporting both click and long-press triggers
  • Offline voice wake-up ESP-SR
  • Streaming voice dialogue (WebSocket or UDP protocol)
  • Support for 5 languages: Mandarin, Cantonese, English, Japanese, Korean SenseVoice
  • Voice print recognition to identify who's calling AI's name 3D Speaker
  • Large model TTS (Volcano Engine or CosyVoice)
  • Large Language Models (Qwen, DeepSeek, Doubao)
  • Configurable prompts and voice tones (custom characters)
  • Short-term memory, self-summarizing after each conversation round
  • OLED / LCD display showing signal strength or conversation content
  • Support for LCD image expressions
  • Multi-language support (Chinese, English)

Hardware Section

Breadboard DIY Practice

See the Feishu document tutorial:

👉 XiaoZhi AI Chatbot Encyclopedia

Breadboard demonstration:

Breadboard Demo

Supported Open Source Hardware

Firmware Section

Flashing Without Development Environment

For beginners, it's recommended to first use the firmware that can be flashed without setting up a development environment.

The firmware connects to the official xiaozhi.me server by default. Currently, personal users can register an account to use the Qwen real-time model for free.

👉 Flash Firmware Guide (No IDF Environment)

Development Environment

  • Cursor or VSCode
  • Install ESP-IDF plugin, select SDK version 5.3 or above
  • Linux is preferred over Windows for faster compilation and fewer driver issues
  • Use Google C++ code style, ensure compliance when submitting code

Developer Documentation

AI Agent Configuration

If you already have a XiaoZhi AI chatbot device, you can configure it through the xiaozhi.me console.

👉 Backend Operation Tutorial (Old Interface)

Technical Principles and Private Deployment

👉 Detailed WebSocket Communication Protocol Documentation

For server deployment on personal computers, refer to another MIT-licensed project xiaozhi-esp32-server

Star History

Star History Chart
Description
Kapi_Rtc_toy 卡皮吧啦项目_火山RTC版本
Readme MIT 24 MiB
Languages
C++ 66.2%
C 27.3%
Python 5.9%
CMake 0.6%