This code example demonstrates Bluetooth® SPP server using AIROC™ Wi-Fi & Bluetooth® combo chip.
- Programming language: C
- Embedded Linux platforms (Arm® Cortex®-A Class processors) for host communications. Supported Embedded Linux host platforms:
- RPI CM4-lite IFX custom HW board from Infineon
- IMX8 nano uCOM board from Embedded Artists
- AIROC™ BTSTACK library and Linux porting layer source code
- AIROC™ Wi-Fi & Bluetooth® combo chip Bluetooth® Firmware file (.hcd).
- Linux Host PC with Ubuntu 20.04
- GNU Arm® GCC AArch64 v9.3.0 (
GCC_ARM
)
Set up the hardware required for this code example as follows:
Figure 1. Hardware setup block diagram
Set up a cross compiler according to the target platform requirement along with CMake on the Linux host PC based on Ubuntu 20.04.
Note: These steps are for Arm® 64-based target platform. Review these steps before adding support for any other target.
-
Open a terminal on the Linux host PC.
-
Use the following command to install the cross compiler, build tools, and dependencies:
sudo apt-get install git cmake gcc-aarch64-linux-gnu build-essential -y
This section describes the steps to be executed on the Linux host PC for compiling the code example.
-
Create a directory under
$HOME
on the Linux host PC and switch to the created directory. Use the following commands for reference:mkdir $HOME/Linux_CE cd $HOME/Linux_CE
-
Fetch the code example source code using the following command:
git clone https://github.com/Infineon/linux-example-btstack-spp
-
Clone the code example dependencies (BTSTACK library, Linux porting layer source code, and audio profiles) using the following commands:
git clone https://github.com/Infineon/btstack --branch release-v3.6.0 git clone https://github.com/Infineon/bluetooth-linux.git --branch release-v1.0.0 git clone https://github.com/Infineon/bt-audio-profiles.git --branch release-v1.0.0
Creates four different directories after cloning the code example and its dependencies with the directory structure as follows:
Figure 2. Code example directory structure
-
Clone the Bluetooth® firmware using following command.
git clone https://github.com/Infineon/combo-bluetooth-firmware.git
User can choose appropriate Bluetooth® firmware for particular AIROC™ Wi-Fi & Bluetooth® combo chip from cloned "combo-bluetooth-firmware" directory.
-
Create the build folder under the code example source folder and build the code example using the following commands:
cd $HOME/Linux_CE/linux-example-btstack-spp mkdir build && cd build cmake -DCMAKE_C_COMPILER:PATH=<GCC_CROSS_COMPILER> ../ && make
Where,
GCC_CROSS_COMPILER
is the target cross compiler for GCC (generally /usr/bin/aarch64-linux-gnu-gcc for Arm® 64-based targets)
The code example executable is generated under the build folder with the same name of code example.
For example, in this project, the "linux-example-btstack-spp" executable is generated at /home/$USER/Linux_CE/linux-example-btstack-spp/build.
This code example acts as a SPP server.
Devices used:
-
Device Under Test (DUT): One hardware platform (Linux host platform and AIROC™ Wi-Fi & Bluetooth® combo chip) are required that runs the SPP code example. Role: "SPP Server"
-
Testing Device: Windows 10 Machine with a terminal emulator application such as Tera Term for creating SPP connection. Role: "SPP Client"
Operation procedure:
-
Copy the code example executable, AIROC™ BTSTACK libraries and Bluetooth® Firmware file from the Linux host PC to the target platform using SCP. For example, use the following commands:
cd $HOME/Linux_CE/linux-example-btstack-spp/build scp linux-example-btstack-spp <TARGET_USER>@<TARGET_IP>:<TARGET_PATH>/. cd $HOME/Linux_CE/btstack/stack/COMPONENT_WICED_DUALMODE/COMPONENT_ARMv8_LINUX/COMPONENT_GCC scp libbtstack.so <TARGET_USER>@<TARGET_IP>:<TARGET_PATH>/. scp <FW_FILE.hcd> <TARGET_USER>@<TARGET_IP>:<TARGET_PATH>/.
Where,
TARGET_USER
is user name of the target platformTARGET_IP
is the IP address of the target platformTARGET_PATH
is the path of target platformFW_FILE.hcd
file is the Bluetooth® Firmware file cloned in step-4 of Using the code example section.
-
Take SSH console of target platform.
ssh <TARGET_DEVICE_USER_NAME>@<TARGET_DEVICE_IP_ADDRESS>
-
Add the udev rule in the target host board for HCI UART and GPIO to bypass root access. Use the following steps to create and set up a udev rule.
Note: If you have root access, the following udev rules are not required; you can execute the code example with
sudo
permissions or by switching to the root user.-
Create a new .rules (for example, combo-chip-uart-port.rules) file under /etc/udev/rules.d/ directory for HCI UART. Use the following commands:
IMX8Nano:
echo "KERNEL==\"ttymxc0\"d,SYMLINK+=\"combo_chip_uart\",MODE=\"0666\"" | sudo tee /etc/udev/rules.d/combo-chip-uart-port.rules
RPICM4:
echo "KERNEL==\"ttyAMA0\",SYMLINK+=\"combo_chip_uart\",MODE=\"0666\"" | sudo tee /etc/udev/rules.d/combo-chip-uart-port.rules
-
Create new .rules (for example, combo-chip-gpio-port.rules) for BT_REG_ON GPIO under /etc/udev/rules.d/. Use the following commands:
IMX8Nano & RPICM4:
-
Create a rule file using the following command.
sudo vim /etc/udev/rules.d/combo-chip-gpio-port.rules.rules
-
Add the following rules in created files:
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R $user:$group /sys/class/gpio/export /sys/class/gpio/unexport;'" SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R $user:$group /sys%p/direction /sys%p/value; chmod 660 /sys%p/direction /sys%p/value;'"
-
-
Reboot the target device:
sudo reboot
Where,
ttymxc0
andttyAMA0
are HCI UART ports for IMX8Nano and RPICM4 respectivelycombo_chip_uart
is a friendly name for the HCI UART port0666
is the permission mask to bypass the root access for HCI UART
-
-
Execute the application by setting the paths of the AIROC™ BTSTACK library using the following command on the target platform.
cd <TARGET_PATH> chmod +x <APP_NAME> LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<BTSTACK_LIB_PATH> ./<APP_NAME> -c <COM_PORT> -b 3000000 -f 921600 -r <GPIOCHIPx> <REGONPIN> -n -p <FW_FILE_NAME>.hcd -d 112233221133
Where,
TARGET_PATH
is the path of the target platform where the code example application copied toBTSTACK_LIB_PATH
is the path of the AIROC™ BTSTACK library. Skip this if the AIROC™ BTSTACK library and executable are in the same folder/dev/ttymxc0
is the COM_PORT for IMX8Nano/dev/ttyAMA0
is the COM_PORT for RPICM43000000
is the HCI baud rate112233221133
is a device BD address-r <GPIOCHIPx> <REGONPIN> -n
is setting the GPIO control to enable autobaud for AIROC™ Wi-Fi & Bluetooth® combo chip-r gpiochip5 0 -n
For IMX8Nano-r gpiochip0 3 -n
For RPICM4
921600
is the firmware download baud rate.hcd
is the firmware to download (make sure to validate this firmware file path)
Note: Currently, random BD addresses are used for testing.
-
On Windows 10 PCs, right click on the Bluetooth® icon in the system tray and select 'Show Bluetooth® Devices'. In the Settings menu that opens for 'Bluetooth® & Other Devices', Select 'Add a Bluetooth® Device'. Find and pair with the SPP Server.
-
In the Settings menu that opens for 'Bluetooth® & Other Devices', scroll down and select "More Bluetooth® options" and then select the 'COM Ports' tab. You can see an incoming and an outgoing COM port on your computer.
Figure 3. SPP Server Connection with Windows 10 PC
- Use serial port application such as Tera Term to open the outgoing COM port with 115200 baud rate (115200-8-N-1 serial configuration). Opening the port will create the SPP connection(see Figure 4).
Figure 4. Opening COM port in Tera Term
---------------------SPP MENU-----------------------
0. Exit
1. Print Menu
2. Send Large Sample Data
3. Send Data
Choose option -> 3
Enter the Data to be Sent :
Hello
-
Press any key (a-z or 0-9) on terminal of the outgoing COM port, the spp application will receive the key that was pressed from the outgoing COM port.
-
On the SPP Server CE, select option 2, "Send Large Sample Data", to send large size data to the SPP client. Repeated continuous numbers from 0 to max payload size will be sent and the corresponding printable ascii characters will be visible on the terminal emulator such as Tera Term of the Windows 10 machine(see Figure 5).
Figure 5. Sending large sample data
You can also use option 3, "Send Data", to send the user-entered characters to the SPP Client. The same will be visible on the Windows 10 machine's terminal emulator, such as Tera Term (see Figure 6).
You can debug the example using a generic Linux debugging mechanism such as the following:
-
Debugging by logging: Add required prints in the application and check them during execution.
-
Debugging using GDB: See the GDB man page for more details.
This code example does the following:
The SPP server CE initializes the stack, opens the RFCOMM channel, and waits for the SPP connection from the client. Once SPP is connected, users can send data to the SPP client via the user menu. Data sent from the SPP client is printed on the SPP Server CE console.
Note: Run the application without any arguments to get details of command-line arguments.
Files | Description of files |
---|---|
app/main.c | Implements the main function which takes the user command line inputs. |
app/spp.c | Implements SPP Server functionalities |
include/spp.h | Header file for SPP server functionality. |
app_bt_config/wiced_bt_config.c | This file contains configurations related to BT settings, GAP and HF. |
Table 1. Application resources
Resource | Alias/object | Purpose |
---|---|---|
UART | HCI | UART is used for HCI communication with host system |
Resources | Links |
---|---|
Device documentation | CYW5557x |
AIROC™ BTSTACK library | AIROC™ BTSTACK library |
Linux porting layer source code | Linux porting layer source code |
Infineon provides a wealth of data at www.infineon.com to help you select the right device, and quickly and effectively integrate it into your design.
Document title: CE237175 - AIROC™ BTSTACK: Bluetooth® SPP server for Linux host
Version | Description of change |
---|---|
1.0.0 | New code example |
© Cypress Semiconductor Corporation, 2023. This document is the property of Cypress Semiconductor Corporation, an Infineon Technologies company, and its affiliates ("Cypress"). This document, including any software or firmware included or referenced in this document ("Software"), is owned by Cypress under the intellectual property laws and treaties of the United States and other countries worldwide. Cypress reserves all rights under such laws and treaties and does not, except as specifically stated in this paragraph, grant any license under its patents, copyrights, trademarks, or other intellectual property rights. If the Software is not accompanied by a license agreement and you do not otherwise have a written agreement with Cypress governing the use of the Software, then Cypress hereby grants you a personal, non-exclusive, nontransferable license (without the right to sublicense) (1) under its copyright rights in the Software (a) for Software provided in source code form, to modify and reproduce the Software solely for use with Cypress hardware products, only internally within your organization, and (b) to distribute the Software in binary code form externally to end users (either directly or indirectly through resellers and distributors), solely for use on Cypress hardware product units, and (2) under those claims of Cypress’s patents that are infringed by the Software (as provided by Cypress, unmodified) to make, use, distribute, and import the Software solely for use with Cypress hardware products. Any other use, reproduction, modification, translation, or compilation of the Software is prohibited.
TO THE EXTENT PERMITTED BY APPLICABLE LAW, CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS DOCUMENT OR ANY SOFTWARE OR ACCOMPANYING HARDWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. No computing device can be absolutely secure. Therefore, despite security measures implemented in Cypress hardware or software products, Cypress shall have no liability arising out of any security breach, such as unauthorized access to or use of a Cypress product. CYPRESS DOES NOT REPRESENT, WARRANT, OR GUARANTEE THAT CYPRESS PRODUCTS, OR SYSTEMS CREATED USING CYPRESS PRODUCTS, WILL BE FREE FROM CORRUPTION, ATTACK, VIRUSES, INTERFERENCE, HACKING, DATA LOSS OR THEFT, OR OTHER SECURITY INTRUSION (collectively, "Security Breach"). Cypress disclaims any liability relating to any Security Breach, and you shall and hereby do release Cypress from any claim, damage, or other liability arising from any Security Breach. In addition, the products described in these materials may contain design defects or errors known as errata which may cause the product to deviate from published specifications. To the extent permitted by applicable law, Cypress reserves the right to make changes to this document without further notice. Cypress does not assume any liability arising out of the application or use of any product or circuit described in this document. Any information provided in this document, including any sample design information or programming code, is provided only for reference purposes. It is the responsibility of the user of this document to properly design, program, and test the functionality and safety of any application made of this information and any resulting product. "High-Risk Device" means any device or system whose failure could cause personal injury, death, or property damage. Examples of High-Risk Devices are weapons, nuclear installations, surgical implants, and other medical devices. "Critical Component" means any component of a High-Risk Device whose failure to perform can be reasonably expected to cause, directly or indirectly, the failure of the High-Risk Device, or to affect its safety or effectiveness. Cypress is not liable, in whole or in part, and you shall and hereby do release Cypress from any claim, damage, or other liability arising from any use of a Cypress product as a Critical Component in a High-Risk Device. You shall indemnify and hold Cypress, including its affiliates, and its directors, officers, employees, agents, distributors, and assigns harmless from and against all claims, costs, damages, and expenses, arising out of any claim, including claims for product liability, personal injury or death, or property damage arising from any use of a Cypress product as a Critical Component in a High-Risk Device. Cypress products are not intended or authorized for use as a Critical Component in any High-Risk Device except to the limited extent that (i) Cypress’s published data sheet for the product explicitly states Cypress has qualified the product for use in a specific High-Risk Device, or (ii) Cypress has given you advance written authorization to use the product as a Critical Component in the specific High-Risk Device and you have signed a separate indemnification agreement.
Cypress, the Cypress logo, and combinations thereof, WICED, ModusToolbox, PSoC, CapSense, EZ-USB, F-RAM, and Traveo are trademarks or registered trademarks of Cypress or a subsidiary of Cypress in the United States or in other countries. For a more complete list of Cypress trademarks, visit www.infineon.com. Other names and brands may be claimed as property of their respective owners.