RTT调试不占用串口,也不用接多余的线,在调试时比uart打印日志更加方便。
在nordic的zigbee/ble/thread 3.2 SDK(v3.2.0_9fade31),
修改目标工程为
C:\nordic_zigbee_v3.2.0_9fade31\examples\multiprotocol\ble_zigbee\ble_zigbee_dynamic_door_lock_nus\pca10056\s140\arm5_no_packs\ble_zigbee_dynamic_door_lock_pca10056_s140.uvprojx
在工程中添加rtt相关的C代码文件
源文件的路径在
X:\nordic_zigbee_v3.2.0_9fade31\external\segger_rtt
sdk_config.h文件中增加启用RTT的宏,这部分在3.2以后的版本可能已经增加,使用时请注意区分。
增加的代码段如下:
//========================================================== // //========================================================== #ifndef NRF_LOG_BACKEND_RTT_ENABLED #define NRF_LOG_BACKEND_RTT_ENABLED 1 #endif // // Size of the buffer is a trade-off between RAM usage and processing. // if buffer is smaller then strings will often be fragmented. // It is recommended to use size which will fit typical log and only the // longer one will be fragmented.
#ifndef NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE #define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 128 #endif
// #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS #define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1 #endif
// // If RTT fails to accept any new data after retries // module assumes that host is not active and on next // request it will perform only one write attempt. // On successful writing, module assumes that host is active // and scheme with retry is applied again.
#ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT #define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3 #endif
// |
第二段代码
//
//========================================================== //
//========================================================== // // Note that either @ref NRF_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE // or this value is actually used. It depends on which one is bigger.
#ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_UP #define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 14000 #endif
// #ifndef SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS #define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 2 #endif
// #ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN #define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 16 #endif
// #ifndef SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS #define SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS 2 #endif
//
// The following modes are supported: // - SKIP - Do not block, output nothing. // - TRIM - Do not block, output as much as fits. // - BLOCK - Wait until there is space in the buffer. // <0=> SKIP // <1=> TRIM // <2=> BLOCK_IF_FIFO_FULL
#ifndef SEGGER_RTT_CONFIG_DEFAULT_MODE #define SEGGER_RTT_CONFIG_DEFAULT_MODE 0 #endif
// //==========================================================
// //==========================================================
|
增加代码完成之后,可视化的界面(仅截取相关部分)如下
由于segger_rtt是新添加的,还要在工程中将该文件夹的路径增加到搜索区域。一般使用相对路径,配置的方法如下图:
在SDK中,工程不作修改的情况下可以使用以下路径:
..\..\..\..\..\..\..\external\segger_rtt
在main()函数,增加一个代码进行测试。
增加的代码如下
SEGGER_RTT_printf(0,"haha, this is a rtt log\r\n");
第五步 大功告成
将上面的工程编译后,下载到目标板,(注意,先不要处于Deubg状态),打开J-Link RTT Viewer v6.60c(也可以是其他版本),这里是windows10,其他操作系统请百度。并且按下F2连接到当前的Jlink。复位目标板,在RTT Viewer 将显示日志如下:
所有的工作完成!
这个方法适用于Nordic semi芯片的Keil工程,比如nrf52832, 52840等,这里以zigbee-ble混合工程为例,ble / thread工作应该也可以用。不同的IDE可以参照实现。
------------------------------------------------
Newbit Studio, 感谢你的光临
http://weibo.com/newbittech
------------------------------------------------