Using Bluetooth Serial Port Profile in Linux Print


This application note explains how to configure and use the WiFi/BT module on the i.MX 8M SOM to obtain serial access to the Target system from the Host computer over Bluetooth.

Step through the following procedure:

  1. Boot Linux to the shell interface on the i.MX 8M. Attach the on-board WiFi/BT module to the Bluez stack via the UART HCI using the following command:
  2. root@imx8m-som:~# hciattach /dev/ttymxc1 qca -t120 115200 flow frame_hci_cmd_pkt: Sending EDL_PATCH_VER_REQ_CMD HCI-CMD -1: 0x1 0x0 0xfc 0x1 0x19 read_vs_hci_event: Wait for HCI-Vendor Specfic Event from SOC wait_for_data: HCI-VS-EVENT available in TTY Serial buffer <...> HCI Reset is done Setting TTY to N_HCI line discipline Device setup complete

  3. Validate that the initialization has been successful using hciconfig. Note the <Target Address> - the Bluetooth address value of your BT module in the output:

    root@imx8m-som:~# hciconfig hci0 up root@imx8m-som:~# hciconfig hci0: Type: Primary Bus: UART BD Address: 61:47:AA:32:44:07 ACL MTU: 1024:7 SCO MTU: 60:8 UP RUNNING PSCAN RX bytes:698 acl:0 sco:0 events:41 errors:0 TX bytes:1004 acl:0 sco:0 commands:41 errors:0

  4. Switch on some Bluetooth devices (smartphone, TV, etc) in the vicinity of the i.MX 8M. Run the BT scan on the i.MX 8M. Validate that you can detect available Bluetooth and/or BLE (Bluetooth Low Energy) devices:
  5. root@imx8m-som:~# hcitool scan Scanning ... 5C:F3:70:70:FA:D5 ubuntu-0 F0:F6:1C:67:F4:D4 iPhone yur root@imx8m-som:~# hcitool lescan LE Scan ... 14:BB:6E:2F:9B:07 (unknown) ^C

  6. Verify communucation over Bluetooth:
    • Add the Serial Port profile to the list of Bluetooth profiles. In the example below the Bluetooth channel number to access this profile is 1. Start the background listening for raw connections on the channel 1:
    • root@imx8m-som:~# sdptool add --channel=1 SP root@imx8m-som:~# rfcomm --raw listen /dev/rfcomm0 1 & Waiting for connection on channel 1

    • On the Host, open a raw Bluetooth connection to the Target (<Target Address> Bluetooth Device, channel 1):
    • [yur@ubuntu ~]$ sudo rfcomm --raw connect 0 61:47:AA:32:44:07 1 Connected /dev/rfcomm0 to 61:47:AA:32:44:07 on channel 1 Press CTRL-C for hangup

    • In the Target console observe an indication of the connection from the Host:
    • Connection from 5C:F3:70:70:FA:D5 to /dev/rfcomm0 Press CTRL-C for hangup

    • Send a text string (command) to the Target over the Bluetooth serial port from the Host:
    • [yur@ubuntu ~]$ echo "Hello from Host over the BT Serial" \ | sudo tee /dev/rfcomm0 Hello from Host over the BT Serial

    • On the Target receive the text string (command) just sent from Host:
    • root@imx8m-som:~# cat /dev/rfcomm0 Hello from Host over the BT Serial ^C

    • Send something from the Target to the Host:
    • root@imx8m-som:~# echo Hello from Target over the BT Serial > \ /dev/rfcomm0

    • Receive the string just sent from the Target on the Host:
    • [yur@ubuntu ~]$ sudo cat /dev/rfcomm0 Hello from Target over the BT Serial ^C