Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updating numbered headings

...

Bluetooth is widely used when it is necessary to provide a wireless access to the devices located in short distances. In this application note we will show how to organize a wireless control channel to the NXP i.MX RT1050 EVK running Linux using a USB Bluetooth adapter. In practical embedded applications such a wireless channel may be used to implement a command/response protocol to control your i.MX RT1050 based device via Bluetooth from the host machine (computer, notebook, smart-phone, etc.).

1. Hardware Platform

The hardware platform used in this application note is the NXP i.MX RT1050 EVK board with a USB Bluetooth adapter plugged into the USB1 or USB2 interface connector. The adapter used by Emcraft to perform the tests documented below was RFCOMM Protocol TDI Bluetooth Device. The generic Linux kernel device driver for the USB transport HCI layer (CONFIG_BT_HCIBTUSB) is used in this configuration so other USB Bluetooth adapters should work as described below too.

2. Software Platform

The goal is to have the i.MX RT1050 act as a device with the Serial Port Profile (SPP) in the Bluetooth network. The i.MX RT1050 will emulate the serial port over the Bluetooth transport and therefore the host will see the i.MX RT1050 as an ordinary serial RS-232 port.

...

The functionality described below is available from the rootfs.uImage project provided by Emcraft for NXP i.MX RT1050 EVK.

3. Test Setup

We will use the following terminology below:

  • Target: NXP i.MX RT1050 EVK board with the Bluetooth adapter plugged into the USB (J9) port.
    The Bluetooth <Target address> in the examples below is 04:7F:0E:31:B7:94.

  • Host: Any computer with a Bluetooth interface, running Linux with the Bluetooth tools (bluez-utils) installed.
    The Bluetooth <Host address> in the examples below is BC:77:37:5C:32:57.

3.1. Test Connectivity

  1. Power-on the NXP i.MX RT1050 EVK board and wait for the Linux to boot on the Target. Run the Bluetooth daemons in the background:

    Code Block
    ...
    / # hcid -n&
    [1] 97 hcid -n
    hcid[97]: Bluetooth HCI daemon
    / # sdpd -n&
    [2] 98 sdpd -n
    / #
  2. Plug-in the Bluetooth adapter to the USB1 interface of the NXP i.MX RT1050 EVK board. Observe the messages like these in the Target console:

    Code Block
    usb 1-1: new full-speed USB device number 3 using ci_hdrc
    
    usb 1-1: Duplicate descriptor for config 1 interface 1 altsetting 5, skipping hcid[229]: HCI dev 0 regBluetooth: hci0: CSR: Unbranded CSR clone detected; adding workarounds and force-suspending once...
    isteBluetooth: hci0: CSR: Failed to suspend the device for our Barrot 8041a02 receive-issue workaround
    red
    hcid[229]: HCI dev 0 up
    hcid[235]: Can't set encrypt on hci0: Invalid request code (56)
    hcid[229]: Starting security manager 0
  3. Get the <Target address> Bluetooth address of the adapter you have just plugged-in:

    Code Block
    / # hcitool dev
    Devices:
    hci0 04:7F:0E:31:B7:94
    / #
  4. 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:

    Code Block
    / # sdptool add --channel=1 SP
    Serial Port service registered
  5. Start the background listening for raw connections on the channel 1:

    Code Block
    / # rfcomm --raw listen /dev/rfcomm0 1 &
    [3] 110 rfcomm --raw listen /dev/rfcomm0 1
    / # Waiting for connection on channel 1
  6. On the Host, open a raw Bluetooth connection to the Target (<Target Address> Bluetooth Device, channel 1):

    Code Block
    $ sudo rfcomm --raw connect 0 04:7F:0E:31:B7:94 1
    Connected /dev/rfcomm0 to 04:7F:0E:31:B7:94 on channel 1
    Press CTRL-C for hangup
  7. In the Target console observe an indication of the connection from the Host:

    Code Block
    Connection from BC:77:37:5C:32:57 to /dev/rfcomm0
    Press CTRL-C for hangup
  8. Send a text string (command) to the Target over the Bluetooth serial port from the Host:

    Code Block
    $ echo "Hello from Host over the BT Serial" | sudo tee /dev/rfcomm0
    Hello from Host over the BT Serial
  9. On the Target receive the text string (command) just sent from Host:

    Code Block
    / # cat /dev/rfcomm0
    Hello from Host over the BT Serial
    ^C
  10. Send a text string (response) from the Target to Host over the Bluetooth serial port:

    Code Block
    / # echo "Hello from Target over the BT Serial" > /dev/rfcomm0
  11. Receive the text string (response) just sent from the Target over the Bluetooth serial port:

    Code Block
    $ sudo cat /dev/rfcomm0
    Hello from Target over the BT Serial
    ^C
  12. Disconnect the Host from the Bluetooth serial line by pressing Ctrl-C in the rfcomm --raw connect ... terminal window:

    Code Block
    ^C
    Disconnected
  13. Observe the rfcomm termination on the Target side:

...