SimpleAP+SNP

From Texas Instruments Wiki
Jump to: navigation, search

Objective

The objective of this article is to get the reader familiarized with the Simple Applications Processor (SAP) project. It will cover how the SAP can be paired with the Simple Network Processor (SNP) to implement a dual chip Bluetooth Low Energy (BLE) system. After reading this wiki, the user should be ready to develop their own custom SAP solution. This wiki will demo SAP + SNP using two SmartRF06 boards with CC2640EMs communicating over UART with Power Management(PM) enabled.

See the graphic below for a functional block diagram of the dual chip SAP + SNP solution. In this case, the External MCU is the SAP and the CC2640 is the SNP.

SAP + SNP Connection



Prerequisites

It is assumed that the reader has

  • Installed the latest version of the TI BLE Stack (v2.1.0 at the time of this writing) which can be downloaded here
  • Installed a compatible version of Code Composer Studio (CCS) or IAR
  • Read SWRU393_CC2640_BLE_Software_Developer's_Guide, which can be found in the BLE stack install in the Documents folder or downloaded here
  • Read the Simple Network Processor API Guide also found in the Documents folder of the BLE stack install
  • Purchased two SmartRF06 boards and CC2640EMs



Introduction

The SAP project is aimed at developers who would like to quickly add BLE to an existing product or developers whose application is too complex for a fully embedded BLE solution. Most of the BLE protocol is implemented on the SNP and abstracted away from the applications processor, allowing the application processor (SAP) to access link data without the overhead of implementing various layers of the BLE protocol.

Note: This is different than the Host test project because most of the HCI layer is abstracted away, and the applications processor is responsible for maintaining fewer aspects of the BLE stack.

Transport Layer Protocol (NPI)

The SNP and SAP uses the TI's Unified Network Processor Interface (NPI) to communicate over UART or SPI. This protocol is extensively documented at this wiki page: [Unified NPI]

It is strongly recommended that the user read the above guide before getting started with the SAP and SNP projects.

If the Application processor is GPIO constrained, and needs to accomplish a two wire NPI implementation (with power savings). A custom NPI version has been created to accomplish this, more information at this wiki: http://processors.wiki.ti.com/index.php/NPI_Two_Wire_UART_with_PM

NPI BLE SNP Subsystem

The NPI wiki linked above explains the Unified NPI protocol in detail. One of the features of Unified NPI is that it allows multiple software subsystems to talk over the same serial link without collision. The SNP has its own dedicated subsystem, which will handle all BLE SNP related NPI traffic. This BLE SNP subsystem is documented in detail in The Simple Network Processor API Guide which is included in the BLE SDK.

It can also be found online here: http://processors.wiki.ti.com/index.php/File:CC2640_Simple_Network_Processer_API_Guide.pdf

SAP Library

The SAP library is created to abstract the BLE specifics, allowing the AP developer to easily set up services, and send/receive data over BLE. This allows the AP developer to focus on developing the AP's other functionality while offering a "black box" interface to the SAP lib for BLE functionality. The internal architecture of the SAP lib is shown below. Red blocks are code modules that execute from the NPI task, blue blocks are code modules that will execute from the SimpleAP task. Note that the entire functionality of Unified NPI and the NPI task are included in the SAP library. SAP API forms the interface between the main application processor task and the NPI task which eventually talks to the proper serial peripheral drivers.

SAP_lib.PNG

SAP Lib Porting Guide

The TI BLE SDK example SimpleAP project runs on the CC26xx device. However, the SAP library can be run on any TI-RTOS capable processor. Due to inherent differences between the device peripherals, some care must be taken.

More information to come on this subject.

Connecting the SAP to SNP

The SAP must be connected to the SNP over UART0. They can be connected using jumper wires connected to the headers on the SmartRF06 boards. The photo below shows these connections.

SAP + SNP connections


The Table below shows the UART (with MRDY, SRDY) pinout for the SNP and SAP projects.
Remember to cross over the UART connections, see diagram above under UART with power savings

Signal Name SAP Pin Location SNP Pin Location
UART0 RX P408.12 P408.12
UART0 TX P408.14 P408.14
MRDY P403.2 P403.12
SRDY P403.4 P403.16

Building the Demo

There are two supported environments for code development, IAR and CCS. There is also an option of flashing the SNP using one of the prebuilt hex files included in the BLE v2.1 stack.

Note: If you are moving from a IAR build environment to CCS or vice versa, clear out the RTOS files

  • Delete <$BLE_STACK_INSTALL>\Projects\ble\SimpleNP\CC26xx\IAR\Application\CC2640\configPkg folder
  • Delete <$BLE_STACK_INSTALL>\Projects\ble\SimpleNP\CC26xx\IAR\Config\src folder


Flashing the SNP using SmartRF Flash Programmer 2

  • Install the TI SmartRF Flash Programmer 2 from here
  • Open SmartRF Flash Programmer, choose your device from the side window pane
  • Under flash image(s) navigate to <$BLE_STACK_INSTALL>\Accessories\HexFiles where <$BLE_STACK_INSTALL> is the location of your BLE stack
    • For using UART with power management use: CC2640_SmartRF-7ID_SimpleNP_UART_PM_SBL.hex
    • For using UART without power management use : CC2640_SmartRF-7ID_SimpleNP_UART_noPM.hex
  • Make sure erase program and verify are checked
  • Hit the play button in the bottom right corner to flash the chip, make sure that power remains connected during this process

See screenshot below for explanation

Flashing the SNP with SmartRF Flash Programmer 2

Once you have successfully flashed the SNP, you can skip that part of the following descriptions

CCS
Note: if you plan on debugging the SAP and SNP simultaneously (have two instances of CCS running) you will need to create a new workspace for the second window. From now on, it will be assumed that the user is using the dual workspace method.

  • Import the Projects
    • Project>Import CCS Projects ...>Click Select search-directory: radio button>Click browse >Using the file explorer navigate to <$BLE_STACK_INSTALL>\Projects\ble\SimpleNP.
      • The SimpleNP and SimpleNP stack projects should be discovered
      • Import the SimpleNP projects into your first workspace.
    • Using the above method, navigate to <$BLE_STACK_INSTALL>\Projects\ble\SimpleAP
      • Import the SimpleAP project into your second workspace
  • Configure the debugger
    • CCS needs a way to differentiate between the two XDS100v3 debuggers, this is done by serial number, configured in the .ccxml file
    • To find the serial number of your debugger open the command line and execute: C:\ti\ccs_base\common\uscif\xds100serial
      • The serial numbers of your connected devices should be listed, you can toggle power to determine which one is which
    • Set the serial number of the debugger in the SimpleNP, SimpleNPStack, and SAPLib, and SimpleAP projects
      • Under the active project > open the targetConfigs folder > double click on CC2640F128.ccxml
      • Click on target configurations in the upper right corner
      • Select the Texas Instruments XDS100v3 USB Debug Probe in the left pane
      • Set Debug Probe Selection combobox to "Select by serial number"
      • enter your serial number in the field below
    • Rise and repeat for all of the projects, note that the SimpleNP and SimpleNPStack should use one debugger and SAPLib and SimpleAP should use the other
Using multiple XDS100v3 debuggers in CCS
  • Set preprocessor defines
    • All projects need to consistently use the same symbol defines
    • In this case UART with PM is used so the symbols POWER_SAVING and NPI_USE_UART should be defined in each project
    • The defines can be accessed in CCS by right clicking the active project > properties > build > ARM compiler > Advanced options > Predefined Symbols
  • Build the SAPLib
    • There is a batch script for building the SAPLib project, after setting the preprocessor defines for the SAPLib project, open a command line and execute the following commands:
      • cd <$BLE_STACK_INSTALL>\Projects\ble\SAP\CC26xx\CCS
      • sap_lib.bat
    • This will build the SAP Library that the SimpleAP projects links against
  • Build and load the SimpleNP
    • Note: This step is not needed if you're using the prebuilt HEX file
    • Make the SimpleNPStack project active, build and load it using the green debug icon
      • It is safe to ignore the message about the main not being defined, click the red stop icon to quit
    • Make the SimpleNP project active, build and load using the green debug icon
      • Run the code using the green play button, code the SimpleNP image is now on the network processor
  • Build and load the SimpleAP
    • Make the SimpleAP project active, build and load it using the green debug icon
    • Run the code using the green play button, code the SimpleAP image is now on the applications processor

IAR
The supported version of IAR is v7.40.2

  • Import the projects
    • Start two instances of IAR
    • file > open > workspace > <$BLE_STACK_INSTALL>\Projects\ble\SimpleNP\CC26xx\IAR in one window
    • file > open > workspace > <$BLE_STACK_INSTALL>\Projects\ble\SimpleAP\CC26xx\IAR in the other window
  • Set preprocessor defines
    • As with CCS, preprocessor defines must be consistent across all projects.
    • Defines can be set by right clicking the project>options>C/C++ Compiler> select Preprocessor tab > enter defined symbols in text box in bottom right
      • Complete this process for SimpleNP stack and app, SimpleAP, and SAP library (<$BLE_STACK_INSTALL>\Projects\ble\SAP\CC26xx\IAR)
Setting preprocessor defines in IAR
  • Build SAP Library
    • You can use an included batch file to build the SAP library once you have set the preprocessor defines
    • This batch file can be found at <$BLE_STACK_INSTALL>\Projects\ble\SAP\CC26xx\IAR
      • Note that you may need to edit this file depending on you IAR installation.
      • For example, the bCOM variable may need to be set to Embedded Workbench 7.2
      • make sure that the bCMD variable is the proper path to your IarBuild.exe
    • Open a command line, execute: cd <$BLE_STACK_INSTALL>\Projects\ble\SAP\CC26xx\IAR
    • Then run the command: sap_lib.bat, this will build the SAP library
  • Build and load the SimpleNP
    • Note: This step is not needed if you're using the prebuilt HEX file
    • Select the CC2640tack, right click on the project > set as active
    • Build and enter debug mode using the green play button in the upper toolbar
    • Select your debugger, note that both SimpleNP projects should go on the same board with the SimpleAP on the other
    • Click the run
    • Repeat the above process for the CC2640App
  • Build and load the SimpleAP
    • Follow Process above, note there is no stack project for the SimpleAP
    • Be sure to select the proper debugger



Using the sample application

Note: When using the Serial Bootloader(SBL) .hex image, bring up the SNP first, otherwise the MRDY line trigger the SNP to go into the bootloader state

  • The SAP will display its current state on the LCD including its address, and the address of its peer
  • You can connect to SimpleNP using BTool or any other device; the device info service is loaded on by default, allowing it to be compatible with mobile devices