CC2540串口输出调试功能
可以用printf()做串口打印输出
这个功能非常简单,首先在工程管理下的preprocessor把串口打开HAL_UART=TRUE。

然后看我的npi.c文件,多了什么自己琢磨,懒点的就直接复制吧:
/*******************************************************************************
Filename: npi.c
Revised: $Date: 2008-06-11 14:30:47 -0700 (Wed, 11 Jun 2008) $
Revision: $Revision: 17210 $ Description: This file contains the Network Processor Interface (NPI),
which abstracts the physical link between the Application
Processor (AP) and the Network Processor (NP). The NPI
serves as the HAL's client for the SPI and UART drivers, and
provides API and callback services for its client. Copyright 2006-2012 Texas Instruments Incorporated. All rights reserved. IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
*******************************************************************************/ /*******************************************************************************
* INCLUDES
*/ #include "hal_types.h"
#include "hal_board.h"
#include "npi.h"
#include "OSAL.h" /*******************************************************************************
* MACROS
*/ /*******************************************************************************
* CONSTANTS
*/ /*******************************************************************************
* TYPEDEFS
*/ /*******************************************************************************
* LOCAL VARIABLES
*/ /*******************************************************************************
* GLOBAL VARIABLES
*/ /*******************************************************************************
* PROTOTYPES
*/ /*******************************************************************************
* FUNCTIONS
*/ /*******************************************************************************
* @fn NPI_InitTransport
*
* @brief This routine initializes the transport layer and opens the port
* of the device. Note that based on project defines, either the
* UART, USB (CDC), or SPI driver can be used.
*
* input parameters
*
* @param npiCback - User callback function when data is available.
*
* output parameters
*
* @param None.
*
* @return None.
*/ void NPI_InitTransport( npiCBack_t npiCBack )
{
halUARTCfg_t uartConfig; // configure UART
uartConfig.configured = TRUE;
uartConfig.baudRate = NPI_UART_BR;
uartConfig.flowControl = NPI_UART_FC;
uartConfig.flowControlThreshold = NPI_UART_FC_THRESHOLD;
uartConfig.rx.maxBufSize = NPI_UART_RX_BUF_SIZE;
uartConfig.tx.maxBufSize = NPI_UART_TX_BUF_SIZE;
uartConfig.idleTimeout = NPI_UART_IDLE_TIMEOUT;
uartConfig.intEnable = NPI_UART_INT_ENABLE;
uartConfig.callBackFunc = (halUARTCBack_t)NIP_input; // start UART
// Note: Assumes no issue opening UART port.
(void)HalUARTOpen( NPI_UART_PORT, &uartConfig ); return;
}
__near_func int putchar(int c)
{
unsigned char buf[1];
buf[0] = c;
NPI_WriteTransport(buf, 1);
return (int)c;
}
//#define HAL_UART_RX_FULL 0x01
//#define HAL_UART_RX_ABOUT_FULL 0x02
//#define HAL_UART_RX_TIMEOUT 0x04
//#define HAL_UART_TX_FULL 0x08
//#define HAL_UART_TX_EMPTY 0x10
void NIP_input(uint8 port, uint8 event) //add
{
(void)port;
uint8 slen;
uint8 *pbuf;
if(event & HAL_UART_RX_TIMEOUT) //接收完成事件
{
slen = NPI_RxBufLen();
pbuf = osal_mem_alloc(slen);
if(pbuf!=NULL)
{
if(slen)
{
NPI_ReadTransport(pbuf, slen);
NPI_WriteTransport(pbuf, slen);
}
osal_mem_free(pbuf);
}
}
if(event & (HAL_UART_RX_FULL|HAL_UART_RX_ABOUT_FULL))
{
slen = NPI_RxBufLen();
pbuf = osal_mem_alloc(slen);
if(pbuf!=NULL)
{
slen = NPI_RxBufLen();
if(slen)
{
NPI_ReadTransport(pbuf, slen);
NPI_WriteTransport(pbuf, slen);
}
osal_mem_free(pbuf);
}
}
}
/*******************************************************************************
* @fn NPI_ReadTransport
*
* @brief This routine reads data from the transport layer based on len,
* and places it into the buffer.
*
* input parameters
*
* @param buf - Pointer to buffer to place read data.
* @param len - Number of bytes to read.
*
* output parameters
*
* @param None.
*
* @return Returns the number of bytes read from transport.
*/
uint16 NPI_ReadTransport( uint8 *buf, uint16 len )
{
return( HalUARTRead( NPI_UART_PORT, buf, len ) );
} /*******************************************************************************
* @fn NPI_WriteTransport
*
* @brief This routine writes data from the buffer to the transport layer.
*
* input parameters
*
* @param buf - Pointer to buffer to write data from.
* @param len - Number of bytes to write.
*
* output parameters
*
* @param None.
*
* @return Returns the number of bytes written to transport.
*/
uint16 NPI_WriteTransport( uint8 *buf, uint16 len )
{
return( HalUARTWrite( NPI_UART_PORT, buf, len ) );
} /*******************************************************************************
* @fn NPI_RxBufLen
*
* @brief This routine returns the number of bytes in the receive buffer.
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return Returns the number of bytes in the receive buffer.
*/
uint16 NPI_RxBufLen( void )
{
return( Hal_UART_RxBufLen( NPI_UART_PORT ) );
} /*******************************************************************************
* @fn NPI_GetMaxRxBufSize
*
* @brief This routine returns the max size receive buffer.
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return Returns the max size of the receive buffer.
*/
uint16 NPI_GetMaxRxBufSize( void )
{
return( NPI_UART_RX_BUF_SIZE );
} /*******************************************************************************
* @fn NPI_GetMaxTxBufSize
*
* @brief This routine returns the max size transmit buffer.
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return Returns the max size of the transmit buffer.
*/
uint16 NPI_GetMaxTxBufSize( void )
{
return( NPI_UART_TX_BUF_SIZE );
} /*******************************************************************************
******************************************************************************/
再看头文件npi.h:
/*******************************************************************************
Filename: npi.h
Revised: $Date: 2007-10-28 09:35:41 -0700 (Sun, 28 Oct 2007) $
Revision: $Revision: 15796 $ Description: This file contains the Network Processor Interface (NPI),
which abstracts the physical link between the Application
Processor (AP) and the Network Processor (NP). The NPI
serves as the HAL's client for the SPI and UART drivers, and
provides API and callback services for its client. Copyright 2008-2012 Texas Instruments Incorporated. All rights reserved. IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
*******************************************************************************/ #ifndef NPI_H
#define NPI_H #ifdef __cplusplus
extern "C"
{
#endif /*******************************************************************************
* INCLUDES
*/ #include "hal_types.h"
#include "hal_board.h"
#include "hal_uart.h"
#include "stdio.h" /*******************************************************************************
* MACROS
*/ /*******************************************************************************
* CONSTANTS
*/ /* UART port */
#if !defined NPI_UART_PORT #if ((defined HAL_UART_SPI) && (HAL_UART_SPI != 0)) // FOR SPI
#if (HAL_UART_SPI == 2)
#define NPI_UART_PORT HAL_UART_PORT_1
#else
#define NPI_UART_PORT HAL_UART_PORT_0
#endif
#else // FOR UART
#if ((defined HAL_UART_DMA) && (HAL_UART_DMA == 1))
#define NPI_UART_PORT HAL_UART_PORT_0
#elif ((defined HAL_UART_DMA) && (HAL_UART_DMA == 2))
#define NPI_UART_PORT HAL_UART_PORT_1
#else
#define NPI_UART_PORT HAL_UART_PORT_0
#endif
#endif // Endif for HAL_UART_SPI/DMA
#endif //Endif for NPI_UART_PORT //#if !defined( NPI_UART_FC )
#define NPI_UART_FC FALSE
//#endif // !NPI_UART_FC #define NPI_UART_FC_THRESHOLD 48
#define NPI_UART_RX_BUF_SIZE 128
#define NPI_UART_TX_BUF_SIZE 128
#define NPI_UART_IDLE_TIMEOUT 6
#define NPI_UART_INT_ENABLE TRUE //#if !defined( NPI_UART_BR )
#define NPI_UART_BR HAL_UART_BR_115200
//#endif // !NPI_UART_BR /*******************************************************************************
* TYPEDEFS
*/ typedef void (*npiCBack_t) ( uint8 port, uint8 event ); /*******************************************************************************
* LOCAL VARIABLES
*/ /*******************************************************************************
* GLOBAL VARIABLES
*/ /*******************************************************************************
* FUNCTIONS
*/ //
// Network Processor Interface APIs
// extern void NPI_InitTransport( npiCBack_t npiCBack );
extern uint16 NPI_ReadTransport( uint8 *buf, uint16 len );
extern uint16 NPI_WriteTransport( uint8 *, uint16 );
extern uint16 NPI_RxBufLen( void );
extern uint16 NPI_GetMaxRxBufSize( void );
extern uint16 NPI_GetMaxTxBufSize( void );
//extern MEMORY_ATTRIBUTE int putchar(char c);
extern void NIP_input(uint8 port, uint8 event); //add
/*******************************************************************************
*/ #ifdef __cplusplus
}
#endif #endif /* NPI_H */
再再然后hal_driver.c下修改:
void HalDriverInit (void)函数下的:
/* UART */
#if (defined HAL_UART) && (HAL_UART == TRUE)
HalUARTInit();
NPI_InitTransport(NIP_input);
#endif
大功告成!!!!
CC2540串口输出调试功能的更多相关文章
- 从0移植uboot(五) _实现串口输出
串口作为一种非常简单的通信方式,才是嵌入式系统调试的王道,通过设置串口输出,我们可以将程序运行的情况直接通过串口线输出到屏幕上,对于这种异常重要的功能,uboot原生就提供了支持,但为此我们需要做一些 ...
- (转) 从0移植uboot(五) _实现串口输出
ref : https://www.cnblogs.com/xiaojiang1025/p/6500520.html 串口作为一种非常简单的通信方式,才是嵌入式系统调试的王道,通过设置串口输出,我们可 ...
- cotex_m3内核提供的ITM串口打印调试
cotex_m3内核的ARM提供了ITM串口打印观测的功能,可以不用ARM单片机自己的串口就可在开发时候串口打印调试.节约了宝贵的内部资源,同时也为调试提供了方便.使用方法如下: 1 将下面的SWO_ ...
- 直接对寄存器操作,实现usart的串口输出寄存器的配置
就像前面提到的,我用的板子是一款stm32f107系列的板子,在这块板子上,已经开发出了一套比较成熟的库函数,这也就意味着你可以不用直接去操作存储器来实现某些功能.比方说对于USART来说可以直接通过 ...
- VC使用CRT调试功能来检测内存泄漏
信息来源:csdn C/C++ 编程语言的最强大功能之一便是其动态分配和释放内存,但是中国有句古话:“最大的长处也可能成为最大的弱点”,那么 C/C++ 应用程序正好印证了这句话.在 C/C+ ...
- KDB支持单步调试功能(ARM架构)
0 实践发现KDB不支持step调试功能 (本文针对的是arm CotexA9架构,各种架构的实现方式不一样, X86的好像已经支持,不过本人没有验证过) 1 首先看下要调试的代码段 ...
- 在ubuntu下把php的网页调试功能打开
我这儿的环境是 Ubuntu 14.04 + Lighttpd + PHP5.5 默认情况下php的网页调试功能是不打开的,当PHP解析到一个错误的语法时会直接输出为空白. 我在网上找一许多文章,说 ...
- iOS项目之使用开关控制日志输出的功能
最近一直在做sdk的项目,用户提出了一个需求,需要屏蔽sdk内部的日志输出.由于sdk内部的日志是为了调试,如果屏蔽了肯定不方便,所以研究了一下日志输出开关的功能. 在这里介绍两种实现方案:一种方案是 ...
- CodeBlocks调试功能快捷教程
在程序设计中,单步调试能够跟踪程序的执行流程.跟踪过程中,还可以观察变量的变化,从而发现其中存在的问题.单步执行除了可以帮助我们发现设计的程序中存在的问题,对于初学者,还可以帮助我们理解语言的机制. ...
随机推荐
- react native 图片样式导致的坑
最近项目中遇到一个问题,代码如下,点击进入另一个页面时需要显示的图片会黑屏,另外退回到该页面的时候下面代码中的第一个图片会全黑几秒才渲染,从另一个路径进入该页面时并没有此问题,就找了半天是不是数据的问 ...
- LAMP(1) 在VirtualBox里安装Ubuntu Server
问题0.虚拟机中安装lamp环境 问题解决: 来自百度经验 问题1. 用putty远程登陆linux系统,显示network error connection refused 问题解决 问题2. my ...
- Python 【第七章】:Html 和 CSS
HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏览器根据标 ...
- iOS 10.0适配之旅
1.升级Xcode体验 升级到Xcode之后,调试程序好多东西都不是太适应 控制台莫名给你打印一堆不是太好理解的东西 之前使用 Alcatraz 下载的插件都不能用(如何使用Alcatraz) 打开麦 ...
- crodova打包apk个人总结
1.安装nodejs 2.安装 cordova npm install -g cordova 3.安装Java JDK,官网下载地址 系统变量→新建 JAVA_HOME 变量 . 变量值填写jdk的安 ...
- hg0088新2网址:已经做好了封装直接拿来就能用功能齐全
很简单,InkCanvas就不用多介绍了,它是一个面板,特点是你可以在它上面涂抹,就像大街上那些妖怪那样,把化妆品往脸上乱涂,涂得人不像人,鸡不像鸡. InkToolBar呢是一个现成的工具栏,你可以 ...
- SQLServer-----Union,Union All的使用方法
转载: http://blog.csdn.net/kiqinie/article/details/8132485 select a.Name from Material as a union sele ...
- 个人对B/S项目的一些理解(三)--Servlet与Strust
以下是我自工作以来,结合对C/S项目的认知,对B/S项目的一些理解. 如有不足或者错误,请各位指正. 由于个人一开始入门时是ASP.NET MVC,是一个比较完善.完整的框架,下面仅对JAVA的w ...
- 学习篇:TypeCodes的2015年博客升级记
原文: https://typecodes.com/mix/2015updateblog.html 2015年博客升级记 作者:vfhky | 时间:2015-05-23 17:25 | 分类:mix ...
- 使用ab对nginx进行压力测试
nginx以高并发,省内存著称. 相信大多数安装nginx的同学都想知道自己的nginx性能如何. 我想跟大家分享下我使用ab工具的压力测试方法和结果, ab是针对apache的性能测试工具,可以只安 ...