从零实现BLE协议栈(8-2)实验:08_phy_ll_procedures
8-2 动手实验:编译运行 08_phy_ll_procedures
本篇是第 8 章的配套实验,实际验证 LL Control Procedure 的 Instant 同步机制。
一、概述
08_phy_ll_procedures 在 Demo 07 的基础上,增加了 LL Procedure(链路层过程) 支持,演示两种典型过程:
- LL_CONNECTION_UPDATE_IND:Master 通知 Slave 在指定 Instant(connEventCounter)同步更新连接参数
- LL_CHANNEL_MAP_IND:Master 通知 Slave 在指定 Instant 切换跳频通道表
核心机制是 Instant 同步——Master 和 Slave 约定在同一个 connEventCounter 时刻生效新参数,无需握手确认。
通过本实验,你将观察 Connection Update 过程的完整日志:接收 → pending → 到达 Instant → 新参数生效。
二、编译与烧录
west build -b nrf52dk/nrf52832 .\write-BLE-stack-from-scratch\08_phy_ll_procedures\ -p
west flash
编译产物:
Memory region Used Size Region Size %age Used
FLASH: 100912 B 512 KB 19.25%
RAM: 19648 B 64 KB 29.98%
三、运行测试
.\write-BLE-stack-from-scratch\tools\venv\Scripts\python.exe `
.\write-BLE-stack-from-scratch\tools\bumble_connect.py `
--transport usb:2FE3:000B `
--target 66:55:44:33:22:11 `
--update-interval 80 `
--duration 20
关键参数:--update-interval 80 让 Bumble 在连接建立后发起 Connection Parameter Update,将 interval 从默认 40 (50ms) 更新为 80 (100ms)。
Bumble 侧:连接建立后稳定保持 20 秒,期间完成 1 次 Connection Update。
已知问题:bumble_connect.py 的
on_params_update回调有 TypeError(参数签名不匹配),但不影响连接和过程执行。
四、串口日志
LL Procedure 接收与 Pending
[CONN] #18 OK | ww=5 lat=0/4 | pending: cu=0 cm=0
[CONN] #19 OK | ww=5 lat=0/4 | pending: cu=0 cm=0
[LL_PROC] Received LL_CONNECTION_UPDATE_IND:
WinSize: 1
WinOffset: 0
Interval: 80 (x1.25ms = 100000 us)
Latency: 4
Timeout: 200
Instant: 25
[CONN] #20 OK | ww=5 lat=0/4 | pending: cu=1 cm=0
↑ 过程挂起中
[CONN] #21 OK | ww=5 lat=0/4 | pending: cu=1 cm=0
[CONN] #22 OK | ww=5 lat=0/4 | pending: cu=1 cm=0
[CONN] #23 OK | ww=5 lat=0/4 | pending: cu=1 cm=0
[CONN] #24 OK | ww=5 lat=0/4 | pending: cu=1 cm=0
Instant 到达:参数生效
[LL_PROC] Connection Update applied at event #25 (Instant reached)
Old: interval=40 (50ms), latency=4, timeout=200
New: interval=80 (100ms), latency=4, timeout=200
Recalculated: interval_ticks=3277, ww_periodic=10
[CONN] #25 OK | ww=10 lat=0/4 | pending: cu=0 cm=0
↑ WW 翻倍(interval 从 50ms→100ms,SCA 不变)
[CONN] #26 SKIP | ww=10 lat=1/4 | pending: cu=0 cm=0
[CONN] #27 SKIP | ww=10 lat=2/4 | pending: cu=0 cm=0
...
Pending 期间 Latency 禁用
注意 #20~#24 的 lat=0/4:虽然 connSlaveLatency=4,但有 Procedure pending 时 禁止跳过事件(Core Spec Vol 6B §5.1.1),确保不错过 Instant。
连接总结
========== Connection Summary ==========
Total events: 214
Events listened: 82
Events skipped: 132
RX OK: 205
RX timeout: 9
RX CRC error: 0
Anchor updates: 205
Max consec miss: 2
Conn Updates: 1
Chan Map Updates: 0
日志解读
- Instant=25:在第 20 个事件收到 LL_CONNECTION_UPDATE_IND,Instant 设为 25——给 5 个事件的缓冲时间
- interval 40→80:connInterval 从 50ms 翻倍到 100ms,事件密度降低
- ww_periodic 5→10:WW = 100ppm × 100ms = 10µs,与新 interval 匹配
- Latency 恢复:Instant 到达后 cu=0,Slave Latency 重新启用(#26 起 SKIP 恢复)
五、关键概念图
Instant 同步时序
Master Slave
│ │
│── LL_CONNECTION_UPDATE_IND ─────→│ 收到于 event #20
│ Instant=25, Interval=80 │ pending: cu=1
│ │
│ event #21 (old params) │ lat=0 (forced listen)
│ event #22 (old params) │ lat=0
│ event #23 (old params) │ lat=0
│ event #24 (old params) │ lat=0
│ │
│ event #25 ← Instant reached │ NEW params take effect
│ (interval=80, ww=10) │ pending: cu=0
│ │ lat=SKIP 恢复
│ event #26 (new params) │
Procedure 对 Latency 的影响
正常模式 (无 pending):
LISTEN → SKIP → SKIP → SKIP → SKIP → LISTEN → ...
Procedure pending 模式:
LISTEN → LISTEN → LISTEN → LISTEN → LISTEN → (Instant) → SKIP → SKIP → ...
↑ 不跳过,确保不错过 Instant ↑
参数对比
更新前 更新后
Interval: 40 (50ms) 80 (100ms)
RTC ticks: 1638 3277
WW periodic: 5 µs 10 µs
事件频率: 20 Hz 10 Hz
本系列教程同款硬件:👇
芯片: nRF 52832 开发板
工具: nRF 52840 BLE Dongle 蓝牙嗅探器
工具: 逻辑分析仪
工具: BPA low energy 蓝牙分析仪
本文版权归作者:ixbwer所有,转载请注明原文链接:https://www.cnblogs.com/ixbwer/p/19810140,否则保留追究法律责任的权利。

浙公网安备 33010602011771号