How to use Bluetooth on i.MX8M boards

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use Bluetooth on i.MX8M boards

How to use Bluetooth on i.MX8M boards

How to use Bluetooth on i.MX8M boards

 

This article introduces how to connect a device via Bluetooth to the i.MX8M family of boards. The steps shown in this document were done using the i.MX8M Plus.

 

Start Bluetooth

 

First, enable the BT service and start it. If systemctl refuses to start or enable these services, consider using the force option -f at the end of the following commands:

systemctl enable bluetooth.service
systemctl start bluetooth.service

Check status of BT. It should be active and running:

systemctl status bluetooth

You should see "Running" on Status:

● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2021-11-29 19:41:18 UTC; 4s ago
     Docs: man:bluetoothd(8)
 Main PID: 710 (bluetoothd)
   Status: "Running"
    Tasks: 1
   Memory: 1.9M
   CGroup: /system.slice/bluetooth.service
           └─710 /usr/libexec/bluetooth/bluetoothd

Nov 29 19:41:18 imx8mpevk systemd[1]: Starting Bluetooth service...
Nov 29 19:41:18 imx8mpevk systemd[1]: Started Bluetooth service.

 

Load Wi-Fi

 

To use the Bluetooth, it is necessary first to load the Wi-Fi, otherwise it won't be possible to load BT firmware. To do this, use the following steps:

modprobe moal mod_para=nxp/wifi_mod_para.conf
wpa_passphrase SSID SSID_PASSWD >> /etc/wpa_supplicant.conf
wpa_supplicant -d -B -i mlan0 -c /etc/wpa_supplicant.conf -Dnl80211

Up to this point, you should be able to use BT, however, if you want to continue connecting to a network using Wi-Fi, you can use the following steps. Otherwise, skip the following and go to the next section.

Run below command:

connmanctl

Connect to Wi-Fi:

connmanctl> enable wifi
connmanctl> scan wifi

#This should list the networks:
connmanctl> services

connmanctl> agent on
connmanctl> connect wifi_<some_numbers>_managed_psk

#Enter password of wifi network
Passphrase?

connmanctl> quit

Now that Wi-Fi is connected, BT can be used.

 

Select serial port for Bluetooth

 

Show serial ports available on the system (each board has different devices):

dmesg | grep tty

i.MX8M Plus shows these results:

[    0.000000] Kernel command line: console=ttymxc1,115200 root=/dev/mmcblk2p2 rootwait rw
[    0.166330] 30860000.serial: ttymxc0 at MMIO 0x30860000 (irq = 29, base_baud = 5000000) is a IMX
[    0.166815] 30880000.serial: ttymxc2 at MMIO 0x30880000 (irq = 30, base_baud = 5000000) is a IMX
[    0.167185] 30890000.serial: ttymxc1 at MMIO 0x30890000 (irq = 31, base_baud = 1500000) is a IMX
[    1.189285] printk: console [ttymxc1] enabled
[    4.160356] systemd[1]: system-getty.slice: unit configures an IP firewall, but the local system does not support BPF/cgroup firewalling.
[    7.171005] audit: type=1006 audit(1605328853.412:2): pid=665 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=1 res=1

For this article, the ttymxc0 port was selected. To attach the device port and set the baudrate (115200 for this case) run the following commands, where hciconfig is used to configure BT device and up opens and initializes HCI device:

hciattach ttymxc0 any 115200 flow
hciconfig hci0 up
hciconfig

 After running the commands above, you should see this:

hci0:   Type: Primary  Bus: UART
        BD Address: 00:E9:3A:0D:C7:80  ACL MTU: 1016:5  SCO MTU: 120:6
        UP RUNNING
        RX bytes:1424 acl:0 sco:0 events:82 errors:0
        TX bytes:1218 acl:0 sco:0 commands:82 errors:0

Now you can manage BT with bluetoothctl.

 

Connect device

 

To start bluetoothctl run the following command:

bluetoothctl

Scan for devices:

[bluetooth]# power on
[bluetooth]# default-agent 
[bluetooth]# pairable on

#Start scanning for devices:
[bluetooth]# scan on

You should see the discovered devices:

[CHG] Controller 00:E9:3A:0D:C7:80 Discovering: yes
[NEW] Device E0:89:7E:86:47:47 E0-89-7E-86-47-47
[NEW] Device 59:80:27:7E:98:A2 59-80-27-7E-98-A2
[NEW] Device EC:81:93:51:FE:66 EC-81-93-51-FE-66
[NEW] Device 50:32:37:D0:A5:B8 50-32-37-D0-A5-B8
[NEW] Device 2C:DD:64:A1:B2:48 2C-DD-64-A1-B2-48
[NEW] Device 08:66:98:EF:B6:C5 08-66-98-EF-B6-C5
...
...

Wait for the system to find the device you want to pair and use the following command:

#Use the corresponding address from your device
[bluetooth]# pair 88:29:9C:59:BC:F6

 

Confirm the passkey both in the i.MX8M board and device. If all steps were done successfully you should see now the name of your connected device instead of [bluetooth]#. To stop scanning, the scan off command can be used. To see connected devices and information, use the following commands:

#A galaxy S10+ was connected to the i.MX8M Plus
[Galaxy S10+]# devices
[Galaxy S10+]# info

 

No ratings
Version history
Last update:
‎12-01-2021 09:41 AM
Updated by: