Project Zero
Table of Contents
- Introduction
- Hardware Prerequisites
- Software Prerequisites
- File Import
- Logging
- Service/Profile Table
- Usage
Introduction
This project is based on the SimpleBLEPeripheral sample application in the TI BLE SDK.
The following changes are done:
- Import some files to the CCS Workspace instead of linking to file system.
- Rename filenames and function names.
- Log to UART instead of writing to display driver.
- Remove SimpleGATTProfile and use new LED, Button and Data services instead.
App Build Configuration | Compatible Stack Configuration | Description |
---|---|---|
FlashROM_StackLibrary | FlashROM_Library | Application build configuration linked to Stack library (fully executable) |
FlashROM_Library configurations use the stack library configuration, which is explained here.
Hardware Prerequisites
The default Simple Peripheral configuration uses the LAUNCHXL-CC2640R2. This hardware configuration is shown in the below image:
For custom hardware, see the Running the SDK on Custom Boards section of the BLE-Stack User's Guide for Bluetooth 4.2.
Software Prerequisites
For information on what versions of Code Composer Studio and IAR Embedded Workbench to use, see the Release Notes located in the docs/blestack folder. For information on how to import this project into your IDE workspace and build/run, please refer to The CC2640R2F Platform section in the BLE-Stack User's Guide for Bluetooth 4.2.
This project is meant to be used with the TI Simplelink Starter smart phone app (for iOs and Android).
File Import
In order to have the workshop as non-destructive as possible, certain files are imported to the workspace, that is, copied from a location on disk to wherever the Code Composer Studio workspace directory is.
This means that if you change for example project_zero.c, the changes to the file will not be reflected in the directory the SimpleLink Academy files are installed in, but the directory you select as workspace directory when Code Composer Studio starts up.
File | Description |
---|---|
main.c | Initialize IOs, set up printf, create TI-RTOS tasks. |
project_zero.c | User application task. Main task loop and BLE callbacks. |
project_zero.h | User application task header. API for task creation in main.c. |
led_service.c/h | Service implementation |
button_service.c/h | Service implementation |
data_service.c/h | Service implementation |
devinfoservice.c/h | Service implementation |
Board files | Pin and peripheral configuration |
app_ble_uartlog.cfg | TI-RTOS configuration file, with log hooks. |
Note that when the TI-RTOS configuration file is in the workspace, the generated output from XDC-tools (TI-RTOS kernel configuration etc) will also be placed in the workspace.
A note on linked files: Other files in the projects are linked from the file system directly, for example TI-RTOS or BLE-Stack files. Any changes done to these files are reflected in all projects that use these files. These files have the following icon with a tiny arrow:
Logging
Additional files uart_log.c have been added, and the TI-RTOS config script has been modified to redirect TI-RTOS Log_xx calls to the UART. More information about this can be found on the uart_log github page
The logging takes up about 23kB of Flash memory in this application, because it uses System_printf functionality, as well as the UART driver and a Text table from TI-RTOS. In addition there is some overhead per statement, as well as the strings themselves. To remove the impact Log has on the image size, add a global compiler define xdc_runtime_Log_DISABLE_ALL as well as changing the TI-RTOS config file to read Text.isLoaded = false; instead of true.
Service/Profile Table
This project contains four services.
Service | UUID | Description |
---|---|---|
led_service | 1110 | Read and toggle LED status |
button_service | 1120 | Get notification when a button is pressed |
data_service | 1130 | Start a data stream. (No smart phone app support.) |
devinfoservice | N/A | Device info service (see the Bluetooth Core spec.) |
See a description for each service under Usage.
Usage
This application uses the UART peripheral to provide an interface for the application. The UART is only used for log messages.
This document will use PuTTY to serve as the display for the output of the CC2640R2 LaunchPad, and it will use Simplelink Starter as the phone app that will act as the central device that will connect to the Project Zero device. Note that any other serial terminal and smart phone BLE application can be used. The following default parameters are used for the UART peripheral for display:
UART Param | Default Values |
---|---|
Baud Rate | 115200 |
Data length | 8 bits |
Parity | None |
Stop bits | 1 bit |
Flow Control | None |
After connecting to PuTTY, you will receive log messages relating to the initialization procedure and see a message stating the address of the device and that it is in the advertising state:
INFO: (../Application/project_zero.c:822) GAP is started. Our address: 0x98072DAA5C67
INFO: (../Application/project_zero.c:827) Advertising
Open up the SimpleLink Starter app. The device is advertising as Project Zero R2.
Click the device, then select the Service Explorer option from the pop up menu. You will notice the PuTTY window has updated to show the GAP state has changed to Connected and the address of the peer device is listed:
INFO: (../Application/project_zero.c:1315) (CB) GAP State change: 6, Sending msg to app.
INFO: (../Application/project_zero.c:837) Connected. Peer address: 0x5AD80C8EFF73
INFO: (../Application/project_zero.c:1194) MTU Size change: 65 bytes
LED Service
Select the service with the UUID that starts with f0001110 and you should see two Characteristics with Read/Write abilities. The red LED is controlled by the characteristic with UUID f0001111. The green LED is controlled by the characteristic with UUID f0001112. Writing a non-zero value will turn the LEDs on. Writing zero will turn the LEDs off.
Name | UUID | Properties | Description |
---|---|---|---|
Characteristic 1 | f0001111 | Read/Write | Control the red LED |
Characteristic 2 | f0001112 | Read/Write | Control the green LED |
You will also see log messages corresponding to your actions in the PuTTY window:
INFO: (../Application/project_zero.c:925) Value Change msg: LED Service LED0: 01
INFO: (../Application/project_zero.c:933) Turning LED0 on
Button Service
The button service is controlled by the Service with UUID that starts with f0001120. Like the LED service, there are two characteristics for the button. The first characteristic corresponds to BTN-1. The second characteristic corresponds to BTN-2.
Name | UUID | Properties | Description |
---|---|---|---|
Characteristic 1 | f0001121 | Read/Notify | Monitor BTN-1 |
Characteristic 2 | f0001122 | Read/Notify | Monitor BTN-2 |
To receive updates when a button is pressed, first set the notify state for the characteristic to 'On'. Then press a button. You should see the value in the Read characteristic window change between 00 (the button is released) and 01 (the button is pressed). You will also see corresponding messages in the UART screen.
INFO: (../Application/project_zero.c:879) Button 0 pressed
INFO: (../PROFILES/button_service.c:313) SetParameter : BUTTON0 len: 1
INFO: (../PROFILES/button_service.c:344) Trying to send noti/ind: connHandle 0, Notification enabled
INFO: (../PROFILES/button_service.c:450) ReadAttrCB : BUTTON0 connHandle: 0 offset: 0 method: 0xff
INFO: (../Application/project_zero.c:1500) Button interrupt: Button 0
INFO: (../Application/project_zero.c:879) Button 0 released
INFO: (../PROFILES/button_service.c:313) SetParameter : BUTTON0 len: 1
Data Service
You can send and receive multiple bytes by reading and writing to the first characteristic of the service with the UUID that starts with f0001130.
Name | UUID | Properties | Description |
---|---|---|---|
Characteristic 1 | f0001131 | Read/Write | Send data to be printed on the UART. |
To send more than one byte at a time, separate bytes with a comma. For example, to write "BLE", write 0x42,0x4C,0x45 to the first characteristic.
INFO: (../PROFILES/data_service.c:531) WriteAttrCB : String connHandle(0) len(3) offset(0) method(0x12)
INFO: (../Application/project_zero.c:1339) (CB) Characteristic value change: svc(0x1130) paramID(0). Sending msg to app.
INFO: (../Application/project_zero.c:993) Value Change msg: Data Service String: BLE+
INFO: (../PROFILES/data_service.c:439) ReadAttrCB : String connHandle: 0 offset: 0 method: 0x0a