Imx6ul Bluetooth: Difference between revisions

From embeddedTS Manuals
(Clarification)
No edit summary
Line 2: Line 2:


Both Wi-Fi and Bluetooth can be active at the same time on this platform. Note however, that either the Wi-Fi interface needs to be not brought up if Wi-Fi is unused, or it needs to actively connect to an access point or act as an access point. The Bluetooth module can be activated with the following commands:
Both Wi-Fi and Bluetooth can be active at the same time on this platform. Note however, that either the Wi-Fi interface needs to be not brought up if Wi-Fi is unused, or it needs to actively connect to an access point or act as an access point. The Bluetooth module can be activated with the following commands:
For Bluez versions found on Debian Stretch and below:
<source lang=bash>
<source lang=bash>
# Enable Bluetooth, and load the firmware
# Enable Bluetooth, and load the firmware
Line 9: Line 11:


# Attach the BLE device to the system, increase the baud, and enable flow control
# Attach the BLE device to the system, increase the baud, and enable flow control
# Note that newer versions of BlueZ do not function correctly with
# the hciconfig command. See the following comment block for details.
hciattach /dev/ttymxc2 any 115200 noflow
hciattach /dev/ttymxc2 any 115200 noflow
hciconfig hci0 up
hciconfig hci0 up
hcitool cmd 0x3F 0x0053 00 10 0E 00 01
hcitool cmd 0x3F 0x0053 00 10 0E 00 01
stty -F /dev/ttymxc2 921600 crtscts
stty -F /dev/ttymxc2 921600 crtscts
</source>


# Newer versions of BlueZ require a different setup process
For newer versions of BlueZ found on Debian Buster or newer:
# than outlined above. The BlueZ project is deprecating older
<source lang=bash>
# commands which directly manipulate the HCI of Bluetooth.
echo BT_POWER_UP > /dev/wilc_bt
# Some commands have replacements, but not all at this time.
echo BT_DOWNLOAD_FW > /dev/wilc_bt
# The following can be used with newer installations of BlueZ
echo BT_FW_CHIP_WAKEUP > /dev/wilc_bt
# to perform the same commands as above:
 
# btattach -N -B /dev/ttymxc2 -S 115200 &
btattach -N -B /dev/ttymxc2 -S 115200 &
# hcitool cmd 0x3F 0x0053 00 10 0E 00 01
hcitool cmd 0x3F 0x0053 00 10 0E 00 01
# kill %1 # This terminates the above btattach command
kill %1 # This terminates the above btattach command
# btattach -B /dev/ttymxc2 -S 921600 &
btattach -B /dev/ttymxc2 -S 921600 &
</source>
</source>



Revision as of 16:52, 12 October 2021

The Wi-Fi option for this platform also includes a Bluetooth 5.0 LE module. Support for Bluetooth is provided by the BlueZ project. BlueZ has support for many different profiles for HID, A2DP, and many more. Refer to the BlueZ documentation for more information. Please see our BLE Examples page for information on installing the latest BlueZ release, getting started, and using demo applications.

Both Wi-Fi and Bluetooth can be active at the same time on this platform. Note however, that either the Wi-Fi interface needs to be not brought up if Wi-Fi is unused, or it needs to actively connect to an access point or act as an access point. The Bluetooth module can be activated with the following commands:

For Bluez versions found on Debian Stretch and below:

# Enable Bluetooth, and load the firmware
echo BT_POWER_UP > /dev/wilc_bt
echo BT_DOWNLOAD_FW > /dev/wilc_bt
echo BT_FW_CHIP_WAKEUP > /dev/wilc_bt

# Attach the BLE device to the system, increase the baud, and enable flow control
hciattach /dev/ttymxc2 any 115200 noflow
hciconfig hci0 up
hcitool cmd 0x3F 0x0053 00 10 0E 00 01
stty -F /dev/ttymxc2 921600 crtscts

For newer versions of BlueZ found on Debian Buster or newer:

echo BT_POWER_UP > /dev/wilc_bt
echo BT_DOWNLOAD_FW > /dev/wilc_bt
echo BT_FW_CHIP_WAKEUP > /dev/wilc_bt

btattach -N -B /dev/ttymxc2 -S 115200 &
hcitool cmd 0x3F 0x0053 00 10 0E 00 01
kill %1 # This terminates the above btattach command
btattach -B /dev/ttymxc2 -S 921600 &

At this point, the device is running at 921600 baud with flow control, and is fully set up ready to be controlled by various components of BlueZ tools. For example, to do a scan of nearby devices:

bluetoothctl
power on
scan on

This will return a list of devices such as:

root@ts-imx6ul:~# bluetoothctl  
Agent registered
[CHG] Controller F8:F0:05:XX:XX:XX Pairable: yes
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller F8:F0:05:XX:XX:XX Powered: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller F8:F0:05:XX:XX:XX Discovering: yes
[NEW] Device 51:DD:C0:XX:XX:XX Device_Name
[NEW] Device 2A:20:E2:XX:XX:XX Device_Name
[CHG] Device 51:DD:C0:XX:XX:XX RSSI: -93
[CHG] Device 51:DD:C0:XX:XX:XX RSSI: -82
[NEW] Device E2:08:B5:XX:XX:XX Device_Name
[CHG] Device 51:DD:C0:XX:XX:XX RSSI: -93
[CHG] Device 2A:20:E2:XX:XX:XX RSSI: -94
[NEW] Device 68:62:92:XX:XX:XX Device_Name
[NEW] Device 68:79:12:XX:XX:XX Device_Name
[bluetooth]# quit

Please note that the Bluetooth module requires the modem control lines CTS and RTS as flow control when running at higher baud rates. It is possible to run the module at the initial 115200 baud if the flow control lines are unwanted.

The module supports some other commands as well:

# Allow the BT chip to enter sleep mode
echo BT_FW_CHIP_ALLOW_SLEEP > /dev/wilc_bt

# Power down the BT radio when not in use
echo BT_POWER_DOWN > /dev/wilc_bt