由于项目需要,将cc2541平台移植到cc2640上,需要特别提醒的是,cc2640有三种封装,协议栈默认使用的是7*7的封装,因此如果换成其它封装需要对工程配置进行修改。
特别说明:此串口用来调试打印log ,可以在powersaving下工作
一、串口驱动添加:
串口对于调试来说,作用很大,因此第一步先调通串口,方便后期的调试工作。下面以SimpleBLECentral工程为例添加:
1、在文件 C:
titirtos_simplelink_2_11_01_09packagestidriversUART.c 文件末尾添加串口初始化驱动:
//add by gyb
static UART_Handle SbpUartHandle;
static UART_Params SbpUartParams;
void GYB_UART_OPEN()
{
#ifndef GYB_UART_DISABLE
UART_Params_init(&SbpUartParams);
SbpUartParams.baudRate = 115200;
SbpUartParams.writeDataMode = UART_DATA_BINARY;
SbpUartParams.dataLength = UART_LEN_8;
SbpUartParams.stopBits = UART_STOP_ONE;
SbpUartHandle = UART_open(0,&SbpUartParams);
if (SbpUartHandle)
{
}
#endif
}
void printS(uint8 *buf)
{
UART_write(SbpUartHandle, buf, osal_strlen((char*)buf));
UART_write(SbpUartHandle, "rn",2); //把回车换行也加上,这样就方便多了
}
typedef unsigned long uint32;
#include "osal.h"
void printV(uint8 *title, uint16 value, uint16 format)
{
uint8 strLen;
uint8 buf[256];
osal_memset(buf,0, 256);
strLen = (uint8)osal_strlen( (char*)title );
osal_memcpy( buf, title, strLen );
gyb_ltoa( (uint32)value, &buf[strLen], format ); //数字转字符串
// strLen = (uint8)osal_strlen( (char*)buf);
// osal_memcpy(&buf[strLen], "rn", 2); //把回车换行也加上,这样就方便多了
//HalUARTWrite(HAL_UART_PORT_0, buf, strLen+2);
printS(buf);
}
2、在文件 C:titirtos_simplelink_2_11_01_09packagestidriversUART.h 中添加:
#include "hal_types.h"
//add by gyb
//typedef unsigned char uint8;
//typedef unsigned short uint16;
extern void GYB_UART_OPEN();
extern void printS(uint8 *buf);
extern void printV(uint8 *title, uint16 value, uint16 format);
3、在文件 C:tisimplelinkble_cc26xx_2_00_00_42893ComponentsosalcommonOSAL.c 中添加:
unsigned char * gyb_ltoa(unsigned long l, unsigned char *buf, uint16 radix)
{
#if defined( __GNUC__ )
return ( (char*)ltoa( l, buf, radix ) );
#else
unsigned char tmp1[10] = "", tmp2[10] = "", tmp3[10] = "";
unsigned short num1, num2, num3;
unsigned char i;
buf[0] = '