CC2541 BLE Peripheral工程的建立

        安装了TI给出的BLE协议栈软件包后,就可以看到TI提供的一些例程。说实话,TI的BLE的工程布局并不是那么容易理解的,而且在很多细节的地方存在这一些不合理之处。但是不容置疑的是,TI的BLE工程布局肯定是考虑了各方面的因素,可谓是面面俱到,所以才定下这样的布局方式。然而,这样考虑全局的布局却未必真的适合某个具体的应用。正是考虑到这个原因,所以我将重新调整BLE工程布局。
当进入TI提供的工程的第一层目录时,跟工程相关的只有Components与Project两个文件,只凭着这两个文件完全无法了解工程的布局的,一定要多进入几层目录后才能看到具体的布局。这种方式,给人藏着掖着的感觉,所以,需要将这些藏在里面的布局全部看门见山似的凸显出来。纵观整个官方工程,可以给它分成几个部分:
——APP部分,Application部分放着更应用相关的文件。
——HAL部分,Hardware abstract layer部分放的是跟处理器外设相关的文件。
——NPI部分,Network Proccessor Interface部分是介于APP与HAL之间的相关部分。
——OSAL部分,Operational system Abstract layer部分放的是这个抽象操作系统的文件。
——BLEStack部分,这部分专门存放跟BLE协议栈相关的文件。
——Profiles部分,这部分存放着跟具体应用所需要的相关BLE配置文件。
—— Project部分 ,这个部分放着的项目工程相关的文件。

可以根据上面的分类开始新建我们的工程了。
1、新建文件夹,取名为BLE Peripheral,并在这个目录下新建7个文件夹,分别取名为:APP、BLEStack、HAL、NPI、OSAL、Profiles、Project,如下图所示:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 
 2、进入APP文件夹,并在这个目录下新建两个名为Source与Include的文件夹,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE协议栈安装位置处BLE-CC254x-1.3.2\Projects\ble\common\cc2540目录下的OnBoard.c与OnBoard.h分别拷贝到APP目录下的Source与Include目录下。
将协议栈目录BLE-CC254x-1.3.2\Projects\ble\SimpleBLEPeripheral\Source下的OSAL_SimpleBLEPeripheral.c、simpleBLEPeripheral.c、SimpleBLEPeripheral_Main.c拷贝到APP下Source.h中,将BLE-CC254x-1.3.2\Projects\ble\SimpleBLEPeripheral\Source目录下的simpleBLEPeripheral.h拷贝到APP下的Include中。
可以看到APP目录下的Source与Include下分别有下面的文件:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
  
3、进入BlEStack目录下,并在这个目录下新建两个名为Include与Libraries的文件夹。
在Include目录下还需要再新建Controller与Host的文件夹,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Components\ble\controller\include下的全部文件拷贝到这个Controller目录下。
将BLE-CC254x-1.3.2\Components\ble\hci下的全部文件拷贝到这个Controller目录下。
将BLE-CC254x-1.3.2\Components\ble\include下的hci.h文件也拷贝到Controller中。
这样Controller目录下存放着下面文件:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Components\ble\include目录下除hci.c文件外的全部文件都拷贝到Host目录下。
将BLE-CC254x-1.3.2\Components\ble\host目录下的linkdb.h文件拷贝到Host目录下。
将BLE-CC254x-1.3.2\Projects\ble\Include下的全部文件:gapgattserver.h与gattservapp.h拷贝到Host目录下。
这样Host目录下存放着下面10个H文件:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
  在Libraries目录下新建CC2540DB、CC2541DB、Common三个文件夹,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 
将BLE-CC254x-1.3.2\Projects\ble\Libraries\CC2540DB\bin下所有.lib文件全部拷贝到这里的CC2540DB目录下。
将BLE-CC254x-1.3.2\Projects\ble\Libraries\CC2541DB\bin下所有.lib文件全部拷贝到这里的CC2541DB目录下。
将BLE-CC254x-1.3.2\Projects\ble\Libraries\Common\bin下的所有.lib文件全部拷贝到这里的Common目录下。
这样CC2540DB、CC2541DB、Common目下分别有下面的文件:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客

4、进入HAL目录,然后在这个目录下新建3个文件夹:Source、Include、Target,如下所示:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 
将BLE-CC254x-1.3.2\Components\hal\common下的全部文件拷贝到这个Source目录下,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Components\hal\include下的全部文件拷贝到这个Include文件中,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
  Target目录下还需要新建4个文件夹,分别取名为:CC2540EB、CC2540USB、CC2541ARC、CC2541ST。然后分别在这4个目录下新建Source与Include两个文件夹:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Components\hal\target\CC2540EB下的全部.c文件全部拷贝到CC2540EB\Source下。
将BLE-CC254x-1.3.2\Components\hal\target\CC2540EB下的全部.h文件全部拷贝到CC2540EB\Include下。
这样CC2540EB的Source与Include目录分别存放着下面的文件:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Components\hal\target\CC2540USB下的全部.c文件全部拷贝到CC2540USB\Source下。
将BLE-CC254x-1.3.2\Components\hal\target\CC2540USB下的全部.h文件全部拷贝到CC2540USB\Include下。
将BLE-CC254x-1.3.2\Components\hal\target\CC2540USB下的文件usb拷贝到CC2540USB\Include下。
这样CC2540USB的Source与Include目录分别存放着下面的文件:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Components\hal\target\CC2541ARC下的全部.c文件全部拷贝到CC2541ARC\Source下。
将BLE-CC254x-1.3.2\Components\hal\target\CC2541ARC下的全部.h文件全部拷贝到CC2541ARC\Include下。
这样CC2541ARC的Source与Include目录分别存放着下面的文件:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Components\hal\target\CC2541ST下的全部.c文件全部拷贝到CC2541ST\Source下。
将BLE-CC254x-1.3.2\Components\hal\target\CC2541ST下的全部.h文件全部拷贝到CC2541ST\Include下。
这样CC2541ST的Source与Include目录分别存放着下面的文件:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
  
5、进入NPI目录,并在这个目录下新建Source与Include下,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Projects\ble\common\npi\npi_np下的npi.c拷贝到NPI\Source下。
将BLE-CC254x-1.3.2\Projects\ble\common\npi\npi_np下的npi.h拷贝到NPI\Include下。

6、进入OSAL目录下,并在这个目录下新建Source与Include文件,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE-CC254x-1.3.2\Components\osal\common下的全部文件拷贝到OSAL\source下。
将BLE-CC254x-1.3.2\Components\osal\mcu\cc2540下的osal_svn.c文件拷贝到OSAL\Source下。
将BLE-CC254x-1.3.2\Components\osal\include下的全部文件拷贝到OSAL\Include下。
这样OSAL下的Source与Include的文件如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 
7、进入Profiles目录下,将BLE-CC254x-1.3.2\Projects\ble\Profiles下的全部文件文件拷贝到Profiles目录下,
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
在上面的每个目录下新建Source与Include,并将对应的.c文件拷贝到Source选,.h拷贝到Include下。
其中Roles还需要添加其他文件,把协议栈目录BLE-CC254x-1.3.2\Components\ble\host下gatt_uuid.c拷贝到这里的Roles\Source。

8、进入Project目录下,新建Config与LinkerConfig两个文件,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 将BLE-CC254x-1.3.2\Projects\ble\config下的全部.cfg文件拷贝到Config文件中,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 将BLE-CC254x-1.3.2\Projects\ble\common\cc2540目录下的全部的.xcl的文件拷贝到LinkerConfig中,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 
9、打开IAR软件,点击Project->Create New Project,然后会跳出一个框,选择OK,接着给项目取名,保存在项目文件的Project目录下。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
  CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
  CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 
10、在工程下,添加组(右键->Add Group),最终建成的项目组布局如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客 
 
 11、往各个项目组中添加工程文件(右键->Add files)。
将BLE Peripheral\APP\Include下的全部文件添加到工程组APP下的Include中。
将BLE Peripheral\APP\Source下的全部文件添加到工程组APP下的Source中。如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE Peripheral\BLEStack\Include\Controller下的全部文件添加到Include下的Controller。
将BLE Peripheral\BLEStack\Include\Host下的全部文件添加到Include下的Host。
将BLE Peripheral\BLEStack\Libraries\CC2541DB目录下的CC2541_BLE_peri.lib添加到Libraries中。
将D:\BLE Peripheral\BLEStack\Libraries\Common目录下的CC2541x_BLE_TCL_TTL_None.lib添加到Libraries中。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE Peripheral\HAL\Include目录下全部文件添加到HAL工程组下的Include中。
将BLE Peripheral\HAL\Source目录下全部文件添加到HAL工程组下的Source中。
将BLE Peripheral\HAL\Target\CC2540EB\Include下的全部文件添加到HAL下的Target下的CC2540EB下的Include中。
将BLE Peripheral\HAL\Target\CC2540EB\Include下除_hal_uart_dma.c、_hal_uart_isr.c、_hal_uart_spi.c以外的全部文件添加到HAL下的Target下的CC2540EB下的Include中。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE Peripheral\NPI\Include下的文件添加到NPI下的Include中。
将BLE Peripheral\NPI\Source下的文件添加到NPI下的Source中。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE Peripheral\OSAL\Include下的全部文件添加到OSAL工程组下的Include中。
将BLE Peripheral\OSAL\Source下的全部文件添加到OSAL工程组下的Source中。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE Peripheral\Profiles\DevInfo\Include下的devinfoservice.h添加到Profiles工程下的Include中。
将BLE Peripheral\Profiles\DevInfo\Source下的devinfoservice.c添加到Profiles工程下的Source中。
将BLE Peripheral\Profiles\Roles\Include下的gapbondmgr.h与peripheral.h两个文件添加到Profiles下的Include中。
将BLE Peripheral\Profiles\Roles\Source下的gap.c、gapboundmgr.c、gatt_uuid.c、periphreal.c添加到Profiles下的Source中。
将BLE Peripheral\Profiles\SimpleProfile\Include下的simpleGATTprofile.h添加到Profiles下的Include中。
将BLE Peripheral\Profiles\SimpleProfile\Source下的simpeGATTprofile.c添加到Profiles下的Source中。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
将BLE Peripheral\Project\Config下的buildComponents.cfg与buildConfig.cfg文件添加到工程组ProjConfig中。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 12、配置工程,点击Project->Options。
进入General Options->Target选项界面,Device选择Texas Instruments的CC2541F256.i51;Numer of virture选择为16;Location for constants and str选择ROM mapped as data。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 进入General Options->Stack/heap选项界面,设置Stack size与Heap sizes,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 进入C/C++ Compiler->Optimizations,设置优化选项,这里选择Hight下的size,表示高等级的大小优化,如下:
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
进图C/C++ Compiler->Proceessor预处理选项界面,设置包含路径与一些宏定义。在Additional include directories下添加包含路径如下:

$PROJ_DIR$\..\APP\Include $PROJ_DIR$\..\BLEStack\Include\Controller $PROJ_DIR$\..\BLEStack\Include\Host $PROJ_DIR$\..\HAL\Include $PROJ_DIR$\..\HAL\Target\CC2540EB\Include $PROJ_DIR$\..\NPI\Include $PROJ_DIR$\..\OSAL\Include $PROJ_DIR$\..\Profiles\Devinfo\Include $PROJ_DIR$\..\Profiles\Roles\Include $PROJ_DIR$\..\Profiles\SimpleProfile\Include

其中 $PROJ_DIR$表示工程文件所在的目录。
在Defined symbols下的添加一些宏定义,如下:

INT_HEAP_LEN=3072 HALNODEBUG OSAL_CBTIMER_NUM_TASKS=1 HAL_AES_DMA=TRUE HAL_DMA=TRUE xPOWER_SAVING xPLUS_BROADCASTER HAL_LCD=TRUE

CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 
进入C/C++ Compiler->Extral Options下,选上Use command line options,并在下面添加命令如下:

-f $PROJ_DIR$\config\buildComponents.cfg -f $PROJ_DIR$\config\buildConfig.cfg

其中后面的两个.cfg已将在工程文件中了。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 进入Linker->Config,选择连接配置文件,勾上Override default选择项,然后选择公曾目录BLE Peripheral\Project\LinkerConfig下的ti_51ew_cc2540b.xcl文件。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 进入Linker->Output,勾上Override default,并勾上Allow CC-SPY-.....。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 进入Linker->Extra output下,设置需要额外生成的文件,勾上Generate extra output file和Overide default,并设置生成BLEPeripheral.hex文件。在format一栏选着Output format为intel-extended。

CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
 进入linker->list,勾上Generate linker listing。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
进入Debugger-setup,选择仿真器为texal Instruments,并勾上Device Description file下的Override default.
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客
进入Texas Instruments->Download,将Erase flash选上。
CC2541 BLE Peripheral工程的建立 - ziye334 - ziye334的博客

13、文件的修改
打开buildConfig.cfg文件,将里面的内容修改成如下:

// BLE Host Build Configurations //-DHOST_CONFIG=BROADCASTER_CFG //-DHOST_CONFIG=OBSERVER_CFG -DHOST_CONFIG=PERIPHERAL_CFG //-DHOST_CONFIG=CENTRAL_CFG //-DHOST_CONFIG=BROADCASTER_CFG+OBSERVER_CFG //-DHOST_CONFIG=PERIPHERAL_CFG+OBSERVER_CFG //-DHOST_CONFIG=CENTRAL_CFG+BROADCASTER_CFG //-DHOST_CONFIG=PERIPHERAL_CFG+CENTRAL_CFG // GATT Database being off chip //-DGATT_DB_OFF_CHIP // GAP Privacy Feature //-DGAP_PRIVACY -DGAP_PRIVACY_RECONNECT // Include GAP Bond Manager //-DGAP_BOND_MGR // CC2541 Device -DCC2541 // OAD Target Configuration Parameters // OAD Image Version (0x0000-0x7FFF) -DOAD_IMAGE_VERSION=0x0000 // OAD User IDs -DOAD_IMAGE_A_USER_ID="'A', 'A', 'A', 'A'" -DOAD_IMAGE_B_USER_ID="'B', 'B', 'B', 'B'"

最重要的是将 -DHOST_CONFIG=PERIPHERAL_CFG与 -DCC2541两个选项没有屏蔽掉。

14、编译工程
编译器会先提示你保存项目,取名为BLEPeriperal,完后点击OK,编译器开始编译,如果成功则会出现0警告,0错误字样。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值