組込み Linux Ultra96V2 Bluetoothを立ち上げてみた

Vivado2023.1とPetaLinux2023.1でビルドしたlinux-xlnx6.1.5_LTSでblutoothを立ち上げてみます。(結論:親として子デバイスを見つけれず、接続出来ませんでした。 子(Advertising)はuBuntu(親)と接続出来ました。)

Ultra96V2のBluetooth用のモジュールはWifiのモジュールと同じでMicrochip社製のWILC3000に変更になっているので、まずWILC3000ドライバーに対応させなければなりません。 結構大変です。 『組込み Linux Ultra96V2 PetaLinux2023.1 やっとWifi動いた!』をご参考ください。 更に、bluetooth.serviceやbluez5が入っていないので、インストールしなければならないのですが、パッケージ管理ツールdnfをインストールしてWifi DHCP接続の時のnameserverを解決しなければなりません。 それは『組込み Linux Ultra96V2 Wifi DHCPでdnfを動かす host not resolved解決』をご参考ください。

(注意)Bluetoothは起動出来たのですが、何故かscan onで対象のデバイスを見つけることが出来ず接続しませんでした。

上記の2つが出来た上でここから以下の事をしなければならないので結構大変でした。

Vivado RTS/CTS接続

AvnetのUltra96V2のドキュメントにBluetoothを動作させるにはRTS/CTSが必要と書かれています。

5.5.2 Bluetooth
The ATWILC300-MR110CA Bluetooth interface connects through a UART interface. Since the
Bluetooth UART interface requires hardware flow-control (RTS/CTS), which is only available
through the PL
, the UART RX/TX signals are connected to PS UART0 (MIO2, MIO3) and the
RTS/CTS signals are connected to the PL High-Density (HD) bank. A blue LED is connected
to Bank 26 programmable logic and can be used to indicate that Bluetooth is enabled when
configured properly.

Ultra96-V2-HW-User-Guide-v1_3.pdf より抜粋bluz5[=y]

RTS/CTS作成

  • 回路図を見るとBluetoothはUART0に接続されているので、
  • VivadoでブロックデザインのZunq UltraScale+上でダブルクリックしてRe-costomize IPウィンドウを開けて、
  • UART0の下の『MODEM』にチェックを入れます。
  • これでZynq UltraScale+ブロックにRTSとCTSの端子が表示されます。
  • RTS(出力)->CTS(入力)で接続される。(通信ハンドシェーク用)
  • RTS(出力):Request to send=送信要求:送ってもいいよの信号
  • CTS(入力):Clear to send=送信可:RTSを受け取ったら送信しても良いという事

  • Vivadoブロックデザインの空白部分で右クリックして『Create Port』をクリックして、
  • UART0_CTS』は『INPUT』ポートとして作成し
  • UART0_RTS』は『OUTPUT』ポートとして作成します。

WILC3000モジュールとの外部接続確認

  • 勝手に作った『UART0_CTS』と『UART0_RTS』ポートは実際のZynq UltraScaleのPL側のピンに接続されていない為、WILC3000のRTSとCTSに接続します。
  • Ultra96V2の回路図をみると、WILC3000の『BT_RTS』端子と『BT_CTS』端子はそれぞれ、B7とB5ピンにつながっています。
  • なので、『BT_RTS』(出力)に接続されているB7ピンを『UART0_CTS』(入力)に接続し、
  • BT_CTS』(入力)に接続されているB5ピンを『UART0_RTS』(出力)に接続します。
  • この下の.xdc(Xilinx Design Constraint)ファイルで記述します。
https://www.avnet.com/opasdata/d120001/medias/docus/193/Ultra96-V2%20Rev1%20Schematic.pdf 引用

PS部とPL部の内部接続

  • 接続には.xdcファイルに実際のピンと先程作ったポートの接続を記載しなければなりません。
  • ファイル名やファイルの置く場所はどこでも構いませんが、私はVivadoプロジェクトディレクトリに、『ichiri_bt.xdc』としてviで新規作成しました。
/ichiri_bt.xdc
## UART0
set_property -dict { PACKAGE_PIN B7   IOSTANDARD LVCMOS18 } [get_ports { UART0_CTS }]; 
set_property -dict { PACKAGE_PIN B5   IOSTANDARD LVCMOS18 } [get_ports { UART0_RTS }]; 
  • そして、作成した.xdcをVivadoに取り込みます。
  • Vivadoの『File』〜『Add Sources』で『Add or create constraints』を選択し『Next』をクリックし、
  • 先程作った『.xdc』ファイルを取り込みます。

.xsa作成

  • 取り込んだら、.xsa.bitファイルを生成します。
  • Run Synthesis』実行
  • Run Implementation』実行
  • Generate Bitstream』実行。 これで.bitファイルが生成されます。
  • File』〜『Export』〜『Export Platfiom…』実行。 これで.xsaファイルが生成されます。bluz5[=y]取り込んだら、.xsa.bitファイルを生成します。
  • Run Synthesis』実行
  • Run Implementation』実行
  • Generate Bitstream』実行。 これで.bitファイルが生成されます。
  • File』〜『Export』〜『Export Platfiom…』実行。 これで.xsaファイルが生成されます。

以下のwarningが出た。 何でかな?(解決できなかった)

WARNING: [BD 41-1306] The connection to interface pin is being overridden by the user with net . This pin will not be connected as a part of interface connection .

PetaLinux

.xsa取り込み

  • PetaLinuxのプロジェクトディレクトリに移動して、
  • 『petalinux-config –get-hw-description=』コマンドとオプションで.xsaを取り込みます。
  • 私の場合、一つ上がVivadoプロジェクトディレクトリで、そこにdesign_ultra96v2_wrapper.xsaファイルがあるので、『../design_ultra96v2_wrapper.xsa』と指定しています。
  • 因みに、Ultra96V2のBluetoothを動作させるには、『組込み Linux Ultra96V2 PetaLinux2023.1 やっとWifi動いた!』で実施したよう、WILC3000用にPetaLinuxのソースコードやデバイスツリーやMakefileなどを変更しなければなりません。
  • 更に、『組込み Linux Ultra96V2 Wifi DHCPでdnfを動かす host not resolved解決
$ cd <PETA_PROJ_DIR>
$ petalinux-config --get-hw-description=../design_ultra96v2_wrapper.xsa

system-user-dtsi変更

<PETA_PRJ_DIR>/project-spec/meta-user/recipes-bsp/device-tree/files$ cat system-user.dtsiを以下のように変更します。

  • &sdhci1, &wicore, &sdio_pwrseq 部分はWILC3000モジュールでWifiを動作させる時に使っています。
  • bluetoothノード削除:既存のデバイスツリーには、TI製のモジュールの記述があるので削除。 bluetoothノードを削除しないと、/dev/ttyPS1が作成されない。

/include/ "system-conf.dtsi"
/ {
};
&sdhci1{
    status = "okay";
    bus-width = <0x4>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_sdhci1_default>;
    xlnx,mio_bank = <0>;
    non-removable;
    disable-wp;
    #address-cells = <1>;
    #size-cells = <0>;
};
&wlcore{
        compatible    = "microchip,wilc3000";
        irq-gpios     = <&gpio 76 GPIO_ACTIVE_HIGH>; /* MIO76 WLAN_IRQ    1V8 */
        reset-gpios   = <&gpio  7 GPIO_ACTIVE_HIGH>; /* MIO7  RADIO_RST_N 1V8 */
        post-power-on-delay-ms = <0x0a>;
        chip_en-gpios = <&gpio  8 GPIO_ACTIVE_HIGH>; /* MIO8  RADIO_EN    1V8 */
        status        = "okay";
        reg           = <0>;
        bus-width     = <4>;
};

&sdio_pwrseq{
    chip_en_gpios=<&gpio 8 1>;
};


&uart0{
    /delete-node/ bluetooth;
};

&uart0{
    /delete-property/ cts-override;
};

petalinux-config -c rootfs

以下を[=y]にする。

petalinux-config -c kernel

Bluetooth SDIO部の設定が必要かもしれない。

https://ww1.microchip.com/downloads/en/DeviceDoc/ATWILC-Devices-Linux-Porting-User-Guide-DS70005329.pdf

ビルド

<PETA_PROJ_DIR>に移動してビルド。

$ cd <PETA_PROJ_DIR>
$ petalinux-build

そしてBOOT.BIN作成

$ cd <PETA_PROJ_DIR>/images/build
$ petalinux-package --boot --format BIN --fsbl zynqmp_fsbl.elf --u-boot u-boot.elf --pmufw pmufw.elf --fpga ../../../p    roject_3.runs/impl_1/design_ultra96v2_wrapper.bit --force
  • microSDのBOOTパーティションにBOOT.BIN boot.scr image.ubを書き込み、ROOTFSパーティションにルートファイルシステムrootfs.tar.gzを展開して、Ultra96V2に装着して起動してみる。
  • 今まで表示されなかったttyPS1が表示されるようになった。 これでttyPS1にBluetoothを設定できます。
  • ttyPS0はconsole出力なのでminicom画面用です。
xlnx-6:~$ dmesg |grep ttyPS
[    0.000000] Kernel command line: earlycon console=ttyPS0,115200 clk_ignore_unused root=/dev/mmcblk0p2 rw rootwait
[    2.437318] ff000000.serial: ttyPS1 at MMIO 0xff000000 (irq = 25, base_baud = 6249999) is a xuartps
[    2.441553] ff010000.serial: ttyPS0 at MMIO 0xff010000 (irq = 26, base_baud = 6249999) is a xuartps
[    2.455485] printk: console [ttyPS0] enabled
xlnx-6:~$ cd /dev
xlnx-6:/dev$ ls -l ttyPS*
crw------- 1 peta tty     239, 0 Jun 28 00:54 ttyPS0
crw-rw---- 1 root dialout 239, 1 Nov  8  2022 ttyPS1

Firmware

組込み Linux Ultra96V2 PetaLinux2023.1 やっとWifi動いた!』でWILC3000モジュールのbluetooth用Firmwareも入れているので、『組込み Linux Ultra96V2 PetaLinux2023.1 やっとWifi動いた!』を実施した場合は問題ないですが、していない場合は『https://github.com/linux4wilc/firmware』から『wilc3000_ble_firmware.bin』を取ってきて、microSDのROOTFSパーティションの『/lib/firmware/mchp/』にコピーしておく。

Ultra96V2でBluetooth起動

以下のPDFを参考。 Ultra96V2はWILC3000のWifi通信にはSDIOモードを使っているので、wilc-sdio.koモードです。(5.13)

https://ww1.microchip.com/downloads/en/DeviceDoc/ATWILC-Devices-Linux-Porting-User-Guide-DS70005329.pdf

bluz5[=y]にしたらbluetoothctlを使えると思うのですが、bluz5[=y]にする前にbluetoothctlを使えなかったので、dnfでインストールしました。 これが必要かどうかわかっていません。 dnfを使うのは『組込み Linux Ultra96V2 Wifi DHCPでdnfを動かす host not resolved解決』で説明しています。

xlnx-6 : ~ $ sudo dnf install  hciconfigが非推奨で、Kernel6ではうまく動作しないということだな。bluez*

確認 

  • bluetoothdプロセスがなかったら、bluetoothd -nで起動する。
  • bluetooth.service がactiveでなかったらsystemctl startでactiveにする。
xlnx-6 : ~ $ ps aux |grep blue
root         522  0.3  0.2   8324  4540 ?        Ss   07:31   0:00 /usr/libexec/bluetooth/bluetoothd
peta         646  0.0  0.0   3008  1276 ttyPS0   S+   07:32   0:00 grep blue

xlnx-6 : ~ $ bluetoothd -n


xlnx-6 : ~ $ systemctl status bluetooth.service
* bluetooth.service - Bluetooth service
     Loaded: loaded (8;;file://xlnx-6.1/lib/systemd/system/bluetooth.service/lib/systemd/system/bluetooth.service8;;; e)
     Active: active (running) since Tue 2023-07-04 07:05:05 UTC; 24h ago
       Docs: 8;;man:bluetoothd(8)man:bluetoothd(8)8;;
   Main PID: 522 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 1145)
     Memory: 3.3M
     CGroup: /system.slice/bluetooth.service
             `-522 /usr/libexec/bluetooth/bluetoothd


xlnx-6 : ~ $ sudo systemctl start bluetooth.service

起動

# Do this only once after board power-up:
xlnx-6 : ~ $ sudo sh -c "echo BT_POWER_UP > /dev/wilc_bt"   //(1)wilc_btの権限がrootしか無いのでこれで実行。 

xlnx-6 : ~ $ dmesg | tail
      :
[   15.461885] at_pwr_dev: open()
[   15.461989] AT PWR: bt_power_up
[   15.461996] Device already up. request source is BT     //(1)WIFI用にDevice Treeで電源ONしているから。
[   15.463451] at_pwr_dev: close()

// $ sleep 1s  //<--- スクリプトを組む時は必要
xlnx-6 : ~ $ sudo sh -c "echo BT_DOWNLOAD_FW > /dev/wilc_bt"  //(2)
xlnx-6 : ~ $ dmesg | tail
      :
[ 1209.401284] at_pwr_dev: open()
[ 1209.401385] AT PWR: bt_download_fw
[ 1209.401391] Bluetooth firmware: mchp/wilc3000_ble_firmware.bin //(2)入れてあるfirmwareのファイルが読み込まれていますね。
[ 1209.404675] Downloading BT firmware size = 58852 ...
[ 1209.559540] Starting BT firmware
[ 1209.667323] BT Start Succeeded
[ 1209.667408] at_pwr_dev: close()

// $ sleep 1s
// $ sudo stty -F /dev/ttyPS1 115200  //無くてもOKでした。

xlnx-6 : ~ $ sudo hciattach ttyPS1 any 115200 noflow  //(3)ttyPS1(UART0)にhciを取り付けます。
Device setup complete                                 //(3)成功しました。

// xlnx-6 : ~ $ sudo which btattach                          //<----btattach有無確認。
// xlnx-6 : ~ $ sudo btattach -B /dev/ttyPS1 -S 115200 hci0  //<----本来はこれを使いたい。しかしhci0がないのでエラーになる。

xlnx-6 : ~ $ dmesg | tail
      :
[ 1948.476872] Bluetooth: MGMT ver 1.22

// $ sleep 1s
xlnx-6 : ~ $ sudo hciconfig hci0 up                       //(4) hci0立ち上げ。 これでhci0が現れます。

xlnx-6 : ~ $ sudo ln -svf /usr/libexec/bluetooth/bluetoothd /usr/sbin/  //(5)bluetoothデーモンのシンボリックリンク作成
'/usr/sbin/bluetoothd' -> '/usr/libexec/bluetooth/bluetoothd'

xlnx-6 : ~ $ hciconfig -a               // hci一覧表示。                                                                                        
hci0:   Type: Primary  Bus: UART        // hci0が出来ています。
        BD Address: F8:F0:05:C4:18:BF  AC[ 2031.788200] Bluetooth: hci0: unexpected cc 0x0c14 length: 1 < 249
L MTU: 27:30  SCO MTU: 0:0
        UP RUNNING 
        RX bytes:396 acl:0 sco:0 events:26 errors:0
        TX bytes:200 acl:0 sco:0 commands:26 errors:0
        Features: 0x00 0x00 0x00 0x00 0x60 0x00 0x00 0x00
        Packet type: DM1 DH1 HV1 
        Link policy: 
        Link mode: PERIPHERAL ACCEPT 
Can't read local name on hci0: Input/output error (5)   //しかし、名前を取得出来ないと言っています。
                                                        //非推奨のhciconfigで立ち上げているからかな?

xlnx-6 : ~ $ btmgmt                                     //btmgmtでhci0を確認してみます。
[mgmt]# info                                            //btmgmtのコンソールで、infoでコントローラを確認します。               
Index list with 1 item
hci0:   Primary controller
        addr F8:F0:05:C4:18:BF version 6 manufacturer 19 class 0x000000
        supported settings: powered connectable discoverable bondable le advertising secure-conn debug-keys privacy static-addr phy-configuration 
        current settings: powered le secure-conn 
        name xlnx-6.1                                    //nameを取得していますね。
        short name 

[mgmt]# exit                                           //btmgmtを抜けます。
  • btmgmtとbluetoothctlは同じようなものなのでどちらでもよい。 
  • 正確には、btmgmtはbluezのutility。 bluetoothctlはDebianプロジェクトで開発された。
  • 今度はbluetoothctlで動かしてみます。
  • これでbluetooth.serviceがactiveにしてくれています。 dnfでインストールする前は存在しなかった、bluetooth.serviceも/lib/systemd/system/に出来ています。
xlnx-6 : ~ $ bluetoothctl        //<--bluetoothctlコンソールに入ります。
Agent registeredln -svf /usr/libexec/bluetooth/bluetoothd /usr/sbin/
[CHG] Controller F8:F0:05:C4:18:BF Pairable: yes  //Ultra06V2のMACアドレスです。

[bluetooth]# show                //コントローラを確認できます。 btmgmtのinfoと同じ。
Controller F8:F0:05:C4:18:BF (public)
        Name: xlnx-6.1       //<----------------これも名前を読んでますね
        Alias: xlnx-6.1
        Class: 0x00000000
        Powered: yes
        Discoverable: no
        DiscoverableTimeout: 0x000000b4
        Pairable: yes
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v1D6Bp0246d0541
        Discovering: no
        Roles: central
        Roles: peripheral
Advertising Features:
        ActiveInstances: 0x00 (0)
        SupportedInstances: 0x05 (5)
        SupportedIncludes: tx-power
        SupportedIncludes: appearance
        SupportedIncludes: local-name

  • 接続可能なデバイスをスキャン(検索)してみます。
  • scanしましたがスピーカーやキーボードは見つかりません。(uBuntuではそれらは見つかりました)
[bluetooth]# scan on               //スキャン開始。 しかしなんかわからないデバイスしか見つからない
Discovery started
[CHG] Controller F8:F0:05:C4:18:BF Discovering: yes
[NEW] Device 43:55:29:E7:6B:12 43-55-29-E7-6B-12
[NEW] Device 44:4A:E2:71:60:7A 44-4A-E2-71-60-7A
[NEW] Device 62:71:35:C1:FB:BD 62-71-35-C1-FB-BD
[NEW] Device 46:BE:D6:03:D8:15 46-BE-D6-03-D8-15
[NEW] Device 4E:81:52:14:25:18 4E-81-52-14-25-18

[bluetooth]# devices
Device F4:CE:23:9E:95:C0 ichiri-H670
Device 43:55:29:E7:6B:12 43-55-29-E7-6B-12
Device 44:4A:E2:71:60:7A 44-4A-E2-71-60-7A
Device 62:71:35:C1:FB:BD 62-71-35-C1-FB-BD
Device 46:BE:D6:03:D8:15 46-BE-D6-03-D8-15
Device 4E:81:52:14:25:18 4E-81-52-14-25-18
[bluetooth]# info 43:55:29:E7:6B:12     //<-----見つけたMACアドレスを入れる情報が見れます
Device 43:55:29:E7:6B:12 (random)
        Alias: 43-55-29-E7-6B-12        //<------しかし名前が出ません
        Paired: no
        Bonded: no
        Trusted: no
        Blocked: no
        Connected: no
        LegacyPairing: no
        ManufacturerData Key: 0x004c
        ManufacturerData Value:
  10 05 03 1c 67 19 05                             ....g..         
        RSSI: -99
        TxPower: 12

[bluetooth]# scan off          //<---------------鬱陶しいのでスキャンを止めます
[CHG] Device 4E:81:52:14:25:18 TxPower is nil
[CHG] Device 4E:81:52:14:25:18 RSSI is nil
[CHG] Device 46:BE:D6:03:D8:15 TxPower is nil
[CHG] Device 46:BE:D6:03:D8:15 RSSI is nil
[CHG] Device 62:71:35:C1:FB:BD TxPower is nil
[CHG] Device 62:71:35:C1:FB:BD RSSI is nil
[CHG] Device 44:4A:E2:71:60:7A TxPower is nil
[CHG] Device 44:4A:E2:71:60:7A RSSI is nil
[CHG] Device 43:55:29:E7:6B:12 TxPower is nil
[CHG] Device 43:55:29:E7:6B:12 RSSI is nil
[CHG] Controller F8:F0:05:C4:18:BF Discovering: no
Discovery stopped

[bluetooth]# exit          //<---------------抜けます
xlnx-6 : ~ $ 

uBuntuでは本来下のようにメーカー名や商品名が表示されるてました。uBuntu側からuBuntuでは本来下のようにメーカー名や商品名が表示されるてました。

Device 38:B8:00:16:6E:51 SONY XRJ-65X95J
Device 76:07:18:16:23:5D Anker A7726
  • スキャンしてもスピーカーやキーボード等を見つけることが出来ませんでした。 hciconfigやhciattachは非推奨になっています。 もしかしたら、hcicofig -aでコントローラーの名前を見つける事が出来なかったように、Kernel 6.1.5と相性が悪いのかもしれません。 Kernelを5.15とか4に落とせば動作するかもしれませんが検証していません。 wilc_sdioだからかなぁ。
  • Ultra96V2では、何故かKernel起動時に/dev/hci0が生成されません。 
/etc/bluetooth/main.conf
[Policy]
AutoEnable=true  //これを設定したけどhci0は生成されず。

[General]     //これは設定していないけどPeripheral用のようなきがする。
DiscoverableTimeout = 0
Discoverable=true
  • wilc_sdioが関係しているかもしれない。
  • /dev/hci0が無いと、btattachは接続するhci0を指定しなければならないのですが、hci0はまだ存在していないのでbtattachは使えませんでした。 なので非推奨のhciattachやhciconfig hci0 upを使わなければなりませんでした。 これがKernel 6.1.5と相性が悪いのかもしれません。 それでscan onでスピーカー、マウス、キーボード等を見つけないのかもしれません。
  • uBuntuでは/dev/hci0が生成されています。
xlnx-6 : ~ $ dmesg |grep Bluetooth              //Ultra96V2(Kernel 6.1.5-xilinx-v2023.1)の場合、hci0が生成されません。
[    1.226199] Bluetooth: Core ver 2.22
[    1.234600] Bluetooth: HCI device and connection manager initialized
[    1.240956] Bluetooth: HCI socket layer initialized
[    1.245824] Bluetooth: L2CAP socket layer initialized
[    1.250876] Bluetooth: SCO socket layer initialized
[    1.660126] Bluetooth: HCI UART driver ver 2.3
[    1.663887] Bluetooth: HCI UART protocol H4 registered
[    1.669017] Bluetooth: HCI UART protocol BCSP registered
[    1.674346] Bluetooth: HCI UART protocol LL registered
[    1.679458] Bluetooth: HCI UART protocol ATH3K registered
[    1.684865] Bluetooth: HCI UART protocol Three-wire (H5) registered
[    1.691159] Bluetooth: HCI UART protocol Intel registered
[    1.696525] Bluetooth: HCI UART protocol QCA registered
[    1.915926] Bluetooth: RFCOMM TTY layer initialized
[    1.920575] Bluetooth: RFCOMM socket layer initialized
[    1.925723] Bluetooth: RFCOMM ver 1.11
[    1.929449] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    1.934750] Bluetooth: BNEP filters: protocol multicast
[    1.939974] Bluetooth: BNEP socket layer initialized
[    1.944929] Bluetooth: HIDP (Human Interface Emulation) ver 1.2
[    1.950859] Bluetooth: HIDP socket layer initialized
[   16.746894] Bluetooth firmware: mchp/wilc3000_ble_firmware.bin


ichiri@ichiri-H670:~ $ dmesg|grep Bluetooth               //uBuntu20.04(Kernel5.15.0-76-generic)の場合、hci0が生成されています。
[    2.400609] Bluetooth: Core ver 2.22
[    2.400621] Bluetooth: HCI device and connection manager initialized
[    2.400624] Bluetooth: HCI socket layer initialized
[    2.400625] Bluetooth: L2CAP socket layer initialized
[    2.400627] Bluetooth: SCO socket layer initialized
[    2.406701] Bluetooth: hci0: Firmware timestamp 2021.38 buildtype 1 build 31586
[    2.409353] Bluetooth: hci0: Found device firmware: intel/ibt-1040-4150.sfi
[    2.409362] Bluetooth: hci0: Boot Address: 0x100800
[    2.409363] Bluetooth: hci0: Firmware Version: 98-38.21
[    2.409363] Bluetooth: hci0: Firmware already loaded
[    2.473669] Bluetooth: hci0: MSFT filter_enable is already on
[    2.971867] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    2.971870] Bluetooth: BNEP filters: protocol multicast
[    2.971874] Bluetooth: BNEP socket layer initialized
[    8.937669] Bluetooth: RFCOMM TTY layer initialized
[    8.937676] Bluetooth: RFCOMM socket layer initialized
[    8.937679] Bluetooth: RFCOMM ver 1.11

スキャンで見つけていたら、以下で接続できるはずです。

[bluetooth]# connect MACアドレス

またbluezなどバージョンの確認は以下の通りです。

xlnx-6 : ~ $ bluetoothctl --version
bluetoothctl: 5.65
xlnx-6 : ~ $ btmgmt --version
btmgmt: 5.65

[mgmt]# version
Version 5.65
[bluetooth]# version
Version 5.65<!-- wp:html -->
<div class="file_name">Ultra96V2</div>
<!-- /wp:html -->

Advertiseモードではつながった

  • PeripheralモードでadvertisingをしたUltra96V2にセントラルデバイスとしてのuBuntu側から接続できました。 なのでVivadoの設定などは正しいのかなぁ。
Ultra96V2
xlnx-6 : ~ $ sudo sh -c "echo BT_POWER_UP > /dev/wilc_bt"     //(1)
xlnx-6 : ~ $ sudo sh -c "echo BT_DOWNLOAD_FW > /dev/wilc_bt"  //(2)

xlnx-6 : ~ $ sudo hciattach ttyPS1 any 115200 noflow          //(3)ttyPS1(UART0)にhciを取り付けます。
Device setup complete                               

xlnx-6 : ~ $ sudo hciconfig hci0 up                           //(4)
xlnx-6 : ~ $ sudo ln -svf /usr/libexec/bluetooth/bluetoothd /usr/sbin/           //(5)
xlnx-6 : ~ $ sudo hciconfig hci0 leadv                        //(6)
uBuntu
$ sudo bluetoothctl

[SONY:SRS-X1]# scan on    //<----コンソールは既に接続済みのSonyのスピーカーが出てきた
Discovery started
      :
      :
[NEW] Device F8:F0:05:C4:18:BF xlnx-6.1  //<----Ultra96V2を見つけた
      :
      :
      :

[bluetooth]# devices            //<----見つけたデバイス一覧で再確認
Device 38:B8:00:16:6E:51 SONY XRJ-65X95J
Device 76:07:18:16:23:5D Anker A7726
Device FC:A8:9A:75:07:7E SONY:SRS-X1
Device F8:F0:05:C4:18:BF xlnx-6.1    //<----Ultra96V2を見つけた    
Device 6E:7F:FC:5A:A3:E1 6E-7F-FC-5A-A3-E1
Device 43:67:64:FE:A0:59 43-67-64-FE-A0-59
Device 69:F1:79:B1:1A:11 69-F1-79-B1-1A-11
Device 72:A9:7B:40:2A:18 72-A9-7B-40-2A-18
Device 4B:AD:8C:BD:CA:F6 4B-AD-8C-BD-CA-F6
Device 71:5A:C6:FE:D9:97 71-5A-C6-FE-D9-97

[SONY:SRS-X1]# connect F8:F0:05:C4:18:BF  //<----Ultra96V2のMACアドレスしていで接続トライ
Attempting to connect to F8:F0:05:C4:18:BF
[CHG] Device F8:F0:05:C4:18:BF RSSI: -62
[CHG] Device 38:B8:00:16:6E:51 RSSI: -86
[CHG] Device FB:93:BE:10:A9:0E RSSI: -79
[CHG] Device F8:F0:05:C4:18:BF Connected: yes
[CHG] Device 6E:7F:FC:5A:A3:E1 RSSI: -91
Connection successful                         //<----つながった


[NEW] Primary Service (Handle 0x0461)
	/org/bluez/hci0/dev_F8_F0_05_C4_18_BF/service0008
	00001801-0000-1000-8000-00805f9b34fb
	Generic Attribute Profile
[NEW] Characteristic (Handle 0x0461)
	/org/bluez/hci0/dev_F8_F0_05_C4_18_BF/service0008/char0009
	00002a05-0000-1000-8000-00805f9b34fb
	Service Changed
[NEW] Descriptor (Handle 0xc564)
	/org/bluez/hci0/dev_F8_F0_05_C4_18_BF/service0008/char0009/desc000b
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Characteristic (Handle 0x0461)
	/org/bluez/hci0/dev_F8_F0_05_C4_18_BF/service0008/char000c
	00002b29-0000-1000-8000-00805f9b34fb
	Client Supported Features
[NEW] Characteristic (Handle 0x0461)
	/org/bluez/hci0/dev_F8_F0_05_C4_18_BF/service0008/char000e
	00002b2a-0000-1000-8000-008F8:F0:05:C4:18:BF05f9b34fb
	Database Hash
[NEW] Characteristic (Handle 0x0461)
	/org/bluez/hci0/dev_F8_F0_05_C4_18_BF/service0008/char0010
	00002b3a-0000-1000-8000-00805f9b34fb
	Unknown
[NEW] Primary Service (Handle 0x0461)
	/org/bluez/hci0/dev_F8_F0_05_C4_18_BF/service0012
	0000180a-0000-1000-8000-00805f9b34fb
	Device Information
[NEW] Characteristic (Handle 0x0461)
	/org/bluez/hci0/dev_F8_F0_05_C4_18_BF/service0012/char0013
	00002a50-0000-1000-8000-00805f9b34fb
	PnP ID



[xlnx-6.1]# info F8:F0:05:C4:18:BF    //<----コンソールが接続したUltra96V2の名前に変わった
Device F8:F0:05:C4:18:BF (public) hciconfigが非推奨で、Kernel6ではうまく動作しないということだな。
	Name: xlnx-6.1
	Alias: xlnx-6.1
	Paired: no
	Trusted: no
	Blocked: no
	Connected: no
	LegacyPairing: no
	UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
	UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
	Modalias: usb:v1D6Bp0246d0541
	RSSI: -62
	TxPower: 20

[bluetooth]# trust F8:F0:05:C4:18:BF
[CHG] Device F8:F0:05:C4:18:BF Trusted: yes
Changing F8:F0:05:C4:18:BF trust succeeded

[xlnx-6.1]# info F8:F0:05:C4:18:BF
Device F8:F0:05:C4:18:BF (public)F8:F0:05:C4:18:BF
	Name: xlnx-6.1
	Alias: xlnx-6.1
	Paired: no
	Trusted: yes      //<------------変更できた
	Blocked: no
	Connected: no
	LegacyPairing: no
	UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
	UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
	Modalias: usb:v1D6Bp0246d0541
	RSSI: -62
	TxPower: 20

[bluetooth]# disconnect F8:F0:05:C4:18:BF
Attempting to disconnect from F8:F0:05:C4:18:BF
Failed to connect: org.bluez.Error.Failed
Successful disconnected

一旦disconnectすると、Ultra96V2の方で再度Advertiseしなければならない。

(参考)

自動起動

wpa_supplicant-nl80211@.service のBeforeとWantsにbluetooth.targetを書き込んで、sudo systemctl enable bluetoothとしておくと起動時bluetooth.service(中でbluetoothdを起動)は起動してくれる。 その他hciattach等は、まだ手動で設定。

/lib/systemd/system/my_bluetooth.service
[Unit]
Description=Bluetooth starting shell script service
Documentation=
After=wpa_supplicant-nl80221@.service network.target bluetooth.target multi-user.target


[Service]
Type=simple
User=root
Group=root
TimeoutStartSec=0
Restart=on-failure
RestartSec=30s
#ExecStart=/home/peta/conf/a.sh
ExecStart=/home/peta/conf/my_bluetooth.sh
SyslogIdentifier=BluetoothUtilization
#ExecStop=

[Install]
WantedBy=bluetooth.target
  • sleep 20秒も待っているのにhciattachは動作しないので、hciattach以下を毎回手動で実行してました。
  • bluetooth.serviceでUser=rootで実行しているのでsudoは不要なはずですが、sudo付けて実行しても同じエラーでした。
  • 何故か、lnリンクも作成されていません。
/home/ichiri/ichiri_conf/my_bluetooth.sh
#!/bin/bash
sh -c "echo BT_POWER_UP > /dev/wilc_bt"
sleep 1
sh -c "echo BT_DOWNLOAD_FW > /dev/wilc_bt"
sleep 20
hciattach /dev/ttyPS1 any 115200 nosleep
sleep 1
hciconfig hci0 up
sleep 1
ln -svf /usr/libexec/bluetooth/bluetoothd /usr/sbin/

20秒待って実行しているので39秒かかって何かわからないエラーが出ています。

[   39.128126] Bluetooth: hci0: sending frame failed (-49)
[   39.133420] Bluetooth: hci0: Opcode 0x c03 failed: -49

コメント

タイトルとURLをコピーしました