FRDM RW612 - zephyr rtosでbluetoothを使用してみる。
- はじめに
NXPの無線通信対応マイコン評価ボード「[FRDM-RW612] (https://www.nxp.jp/design/design-center/development-boards-and-designs/FRDM-RW612)
および、zephyrのサンプルアプリケーションプログラム(samples/bluetoot)および開発用のツール(tests/bluetooth/shell)を使用して、bluetoothの動作を確認してみた際の記録メモです。
- ビルド前の事前対応
$ west blobs fetch hal_nxp
- ビルド
$ west build -b frdm_rw612 samples/bluetooth/ビルド対象のサンプル/ -p always
- 基板への書き込み
$ sudo env "PATH=/usr/local/LinkServer_26.3.123:$PATH" $(which west) flash -r linkserver
- 上記ビルド前の事前対応~基板への書き込みについては、下記を参照。
FRDM RW612 - zephyr rtosでwifiを使用してみる。
-
bluetoothのサンプルアプリケーション、開発ツールの実行例
- サンプルアプリケーションのディレクトリ samples/bluetooth
- サンプルアプリケーションとは別に、開発用のツールとしてtests/bluetooth/shellが利用できた。
- サンプルアプリケーションおよび開発用の実行例を以下に示す。(サンプルアプリケーションは複数あるため、一部をピックアップしている。)
- サンプルアプリケーションbeacon
samples/bluetooth/beacon
*** Booting Zephyr OS build v4.2.0-5452-g169cf86969d7 ***
Starting Beacon Demo
[00:00:00.280,110] <inf> bt_hci_core: HCI transport: BT NXP
[00:00:00.280,221] <inf> bt_hci_core: Identity: C0:95:DA:01:BF:4A (public)
[00:00:00.280,237] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x8300, manufacturer 0x0025
[00:00:00.280,245] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x1429
Bluetooth initialized
Beacon started, advertising as C0:95:DA:01:BF:4A (public)
- サンプルアプリケーションperipheral
peripheralのサンプルアプリケーションは、スマートフォンのBluetoothアプリケーションから参照可能となっている。
①スマートフォンからの接続開始時のメッセージ
②スマートフォンからの切断開始時のメッセージ
samples/bluetooth/peripheral
*** Booting Zephyr OS build v4.2.0-5452-g169cf86969d7 ***
[00:00:00.238,691] <inf> fs_nvs: 8 Sectors of 4096 bytes
[00:00:00.238,704] <inf> fs_nvs: alloc wra: 0, f78
[00:00:00.238,710] <inf> fs_nvs: data wra: 0, 8a
[00:00:00.288,916] <inf> bt_hci_core: No ID address. App must call settings_load()
Bluetooth initialized
[00:00:00.289,272] <inf> bt_hci_core: HCI transport: BT NXP
[00:00:00.289,391] <inf> bt_hci_core: Identity: C0:95:DA:01:BF:4A (public)
[00:00:00.289,409] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x8300, manufacturer 0x0025
[00:00:00.289,418] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x1429
Advertising successfully started
Indicate VND attr 0x180206dc (UUID 12345678-1234-5678-1234-56789abcdef1)
Updated MTU: TX: 23 RX: 23 bytes
Connected ①
Updated MTU: TX: 527 RX: 65 bytes
[00:00:08.858,310] <inf> hrs: HRS notifications enabled
[00:00:08.978,268] <inf> bas: BAS Notifications enabled
[00:00:36.713,385] <inf> hrs: HRS notifications disabled ②
[00:00:37.119,314] <inf> bas: BAS Notifications disabled
Disconnected, reason 0x13
スマートフォンの画面(左:接続前、右:接続後)
スマートフォンアプリケーションLightBlueを使用して、
接続後に、基板側のサービスに対して値を書き込んだときのメッセージ(★の部分)
samples/bluetooth/peripheral
*** Booting Zephyr OS build v4.2.0-5452-g169cf86969d7 ***
[00:00:00.238,571] <inf> fs_nvs: 8 Sectors of 4096 bytes
[00:00:00.238,584] <inf> fs_nvs: alloc wra: 0, f78
[00:00:00.238,590] <inf> fs_nvs: data wra: 0, 8a
[00:00:00.288,590] <inf> bt_hci_core: No ID address. App must call settings_load()
Bluetooth initialized
[00:00:00.288,946] <inf> bt_hci_core: HCI transport: BT NXP
[00:00:00.289,065] <inf> bt_hci_core: Identity: C0:95:DA:01:BF:4A (public)
[00:00:00.289,083] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x8300, manufacturer 0x0025
[00:00:00.289,092] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x1429
Advertising successfully started
Indicate VND attr 0x180206dc (UUID 12345678-1234-5678-1234-56789abcdef1)
Updated MTU: TX: 23 RX: 23 bytes
Connected
Updated MTU: TX: 527 RX: 65 bytes
[00:01:06.745,555] <inf> hrs: HRS CTRL Point Written 1 ★
HRS Control point request: 170 ★(0xAA)
[00:01:36.805,544] <inf> hrs: HRS CTRL Point Written 1 ★
HRS Control point request: 187 ★(0xBB)
Disconnected, reason 0x13
- サンプルアプリケーションcentral
samples/bluetooth/central
*** Booting Zephyr OS build v4.2.0-5452-g169cf86969d7 ***
Bluetooth initialized
Scanning successfully started
Device found: 58:C3:AA:30:19:7F (random) (RSSI -61)
Device found: DE:DB:B7:91:3C:1D (random) (RSSI -82)
Device found: 58:C3:AA:30:19:7F (random) (RSSI -65)
~略~
- サンプルアプリケーションobserver
samples/bluetooth/observer
*** Booting Zephyr OS build v4.2.0-5452-g169cf86969d7 ***
Starting Observer Demo
Started scanning...
Exiting main thread.
Device found: 02:0B:8F:DF:57:83 (random) (RSSI -79), type 3, AD data len 31
Device found: DF:9E:28:51:76:7B (random) (RSSI -80), type 0, AD data len 27
Device found: DF:9E:28:51:76:7B (random) (RSSI -79), type 4, AD data len 0
Device found: 31:7F:64:9E:15:1E (random) (RSSI -82), type 3, AD data len 31
Device found: 33:B1:9F:06:B5:CB (random) (RSSI -84), type 3, AD data len 31
Device found: 07:3B:10:17:85:AC (random) (RSSI -84), type 3, AD data len 31
Device found: 27:23:A9:11:1F:A0 (random) (RSSI -80), type 3, AD data len 31
~略~
- 開発用ツール
開発用ツールの操作例として、
初期化(bt init)、デバイスの探索(bt scan on/off)、接続(bt connect)を示す。
tests/bluetooth/shell
uart:~$ bt init
Bluetooth initialized
Settings Loaded
[00:00:37.538,100] <inf> fs_nvs: 8 Sectors of 4096 bytes
[00:00:37.538,162] <inf> fs_nvs: alloc wra: 0, f78
[00:00:37.538,165] <inf> fs_nvs: data wra: 0, 8a
[00:00:37.588,415] <wrn> bt_hci_core: Num of Controller's ISO packets != ISO bt_conn_tx contexts(15 != 1)
[00:00:37.591,007] <inf> bt_hci_core: No ID address. App must call settings_load()
[00:00:37.594,606] <inf> bt_hci_core: HCI transport: BT NXP
[00:00:37.594,707] <inf> bt_hci_core: Identity: C0:95:DA:01:BF:4A (public)
[00:00:37.594,734] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x8300, manufacturer 0x0025
[00:00:37.594,746] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x1429
uart:~$ bt scan on
Bluetooth active scan enabled
~中略~
[DEVICE]: 46:C8:FF:8B:CC:25 (random), AD evt type 0, RSSI -61 This Device C:1 S:1 D:0 SR:0 E:0 Prim: LE 1M, Secn: No packets, Interval: 0x0000 (0 us), SID: 0xff ★
~中略~
uart:~$ bt scan off
Scan successfully stopped
uart:~$ bt connect 46:C8:FF:8B:CC:25 random ★に接続
Connection pending
Connected: 46:C8:FF:8B:CC:25 (random)
LE data len updated: TX (len: 251 time: 2120) RX (len: 251 time: 2120)
LE PHY updated: TX PHY LE 2M, RX PHY LE 2M
~中略~
LE Features: 0x0201d9f9f70179ff
- 開発用ツールのhelp
bt
uart:~$ bt
bt - Bluetooth shell commands
Subcommands:
init : [no-settings-load], [sync]
disable : [none]
settings-load : [none]
hci-cmd : <ogf> <ocf> [data]
id-create : <address: XX:XX:XX:XX:XX:XX>
id-reset : <id> <address: XX:XX:XX:XX:XX:XX>
id-delete : <id>
id-show : [none]
id-select : <id>
name : [name]
appearance : [none]
scan : [--timeout <timeout>] [--filter-dups] [--fal]
[--coded] [--no-1m] [--interval <n * 0.625 ms]
[--window <n * 0.625 ms>] <value: on, passive, off>
scan-filter-set : Scan filter set commands
scan-filter-clear : Scan filter clear commands
scan-verbose-output : <value: on, off>
advertise : ([--int-min <val>] [--int-max <val>] | [--interval
<val>]) <type: off, on, nconn> [mode: discov,
non_discov] [filter-accept-list: fal, fal-scan,
fal-conn] [identity] [no-name] [name-ad] [appearance]
[disable-37] [disable-38] [disable-39]
directed-adv : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
[mode: low] [identity] [dir-rpa]
adv-create : <type: conn-scan conn-nscan, nconn-scan nconn-nscan>
[ext-adv] [no-2m] [coded] [anon] [tx-power]
[scan-reports] [filter-accept-list: fal, fal-scan,
fal-conn] [identity] [directed <address:
XX:XX:XX:XX:XX:XX> <type: (public|random)>] [mode:
low] [dir-rpa] [disable-37] [disable-38] [disable-39]
adv-param : <type: conn-scan conn-nscan, nconn-scan nconn-nscan>
[ext-adv] [no-2m] [coded] [anon] [tx-power]
[scan-reports] [filter-accept-list: fal, fal-scan,
fal-conn] [identity] [directed <address:
XX:XX:XX:XX:XX:XX> <type: (public|random)>] [mode:
low] [dir-rpa] [disable-37] [disable-38] [disable-39]
adv-data : <data> [scan-response <data>] <type: discov, hex>
[appearance] [name <str>] [dev-name]
adv-start : [timeout <timeout>] [num-events <num events>]
adv-stop : [none]
adv-delete : [none]
adv-select : [adv]
adv-info : [none]
adv-oob : [none]
adv-rpa-expire : <on, off>
per-adv : <on, off>
per-adv-param : [<interval-min> [<interval-max> [tx_power]]]
per-adv-data : [data]
per-adv-update-did : Update periodic advertising DID
per-adv-sync-create : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
<sid> [skip <count>] [timeout <ms>] [aoa] [aod_1us]
[aod_2us] [cte_only]
per-adv-sync-delete : [<index>]
per-adv-sync-select : [sync]
encrypted-ad : Manage advertiser with encrypted data
connect : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
[coded] [no-1m]
connect-name : <name filter>
disconnect : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
select : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
info : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
conn-update : <min> <max> <latency> <timeout>
data-len-update : <tx_max_len> [tx_max_time]
phy-update : <tx_phy> [rx_phy] [s2] [s8]
channel-map : <channel-map: XXXXXXXXXX> (36-0)
oob : [none]
clear : [all] [<address: XX:XX:XX:XX:XX:XX> <type:
(public|random)>]
security : <security level BR/EDR: 0 - 4, LE: 1 - 4> [force-pair]
bondable : <on, off>
bonds : [none]
connections : [none]
auth : <method: all, input, display, yesno, confirm, oob,
status, none>
auth-cancel : [none]
auth-passkey : <passkey>
auth-passkey-notify : <type>
auth-passkey-confirm : [none]
auth-pairing-confirm : [none]
oob-remote : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
<oob rand> <oob confirm>
oob-clear : [none]
fal-add : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
fal-rem : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
fal-clear : [none]
fal-connect : <on, off> [coded] [no-1m]
app-passkey : [passkey]
gatt
uart:~$ gatt
gatt - Bluetooth GATT shell commands
Subcommands:
discover : [UUID] [start handle] [end handle]
discover-characteristic : [UUID] [start handle] [end handle]
discover-descriptor : [UUID] [start handle] [end handle]
discover-include : [UUID] [start handle] [end handle]
discover-primary : [UUID] [start handle] [end handle]
discover-secondary : [UUID] [start handle] [end handle]
exchange-mtu : [none]
read : <handle> [offset]
read-uuid : <UUID> [start handle] [end handle]
read-multiple : <handle 1> <handle 2> ...
signed-write : <handle> <data> [length] [repeat]
subscribe : <CCC handle> <value handle> [ind]
resubscribe : <address: XX:XX:XX:XX:XX:XX> <type:
(public|random)> <CCC handle> <value handle>
[ind]
write : <handle> <offset> <data>
write-without-response : <handle> <data> [length] [repeat]
write-without-response-cb : <handle> <data> [length] [repeat]
unsubscribe : [none]
get : <start handle> [end handle]
set : <handle> [data...]
show-db : [uuid] [num_matches]
att_mtu : Output ATT MTU size
metrics : [value: on, off]
register : register pre-predefined test service
unregister : unregister pre-predefined test service
notify : <handle> <data>
notify-mult : count [data]
uart:~$