# SemiHosting # IAR和CCS都支持一种Semi-Hosting技术(半独立主机),这对产品早期开发的使用 `printf`和 `System_printf` 是非常方便的,轻易将调试信息打印在IDE的终端。但是一旦Semi-Hosting 使能,绝大的TI-RTOS例程在没有连接的IDE到时候不会运行,主要是因为类似 `System_flush()` API 需要等待IDE应答。区别其他IDE,CCS的握手机制不太一样,通过CCS编译生成的工程可以独立IDE运行。 对于Semi-Hosting,我们参考以下模型理解 ![](http://www.leconiot.com/md_res/cc1310/app/semi_hosting/images/semi_hosting.png) 本文以下CC2640R2F BLE5.0 SDK下面的 `C:\ti\simplelink_cc2640r2_sdk_1_40_00_45\examples\rtos\CC2640R2_LAUNCHXL\sysbios\hello` 工程为例,介绍如何使用SemiHosting支持的`System_printf`用以打印调试信息。 ## Console/Terminal ## ### IAR ### 在IAR [导入Examples](_)已经详细讲解如何导入Examples,参考它,导入Hello 例程。 在Main函数中,以下代码段实现主要功能: ```C int main() { /* Call driver init functions */ Board_initGeneral(); System_printf("hello world\n"); /* * normal BIOS programs, would call BIOS_start() to enable interrupts * and start the scheduler and kick BIOS into gear. But, this program * is a simple sanity test and calls BIOS_exit() instead. */ BIOS_exit(0); /* terminates program and dumps SysMin output */ return(0); } ``` 对于以上代码的` System_printf("hello world\n");`需要借助仿真器Debug的时候在Terminal打印。 **IAR-View->Terminal I/O** ![](http://www.leconiot.com/md_res/cc1310/app/semi_hosting/images/terminal_io.png) >**注意**:这里的终端打印只有在借助仿真器在线调试打印,并且离开IAR,复位可能不能正常运行。 ### CCS ### CCS的Console 比较明显 **Window->Show View->Console.** ![CCS](http://www.leconiot.com/md_res/cc1310/app/semi_hosting/images/ccs_console.png) ## 对于Semi-Hosting我们如何使能和禁止 ## 对于独立工程,我们又该怎么去禁止和使能呢? ### 使能/禁止 ### 对于IAR,使能支持(Semihosted)或者禁止(None) **Project>Options>General Options>Library Configuration>Semihosted** ![IAR 使能禁止 SemiHost功能](http://www.leconiot.com/md_res/cc1310/app/semi_hosting/images/iar_semi_setting.png) CCS则通过以下选择; **Project>Properties>Debug>Enable Semihosting(requires a breadpoint at SVC_Hnadler)** ![CCS 使能/禁止 SemiHost功能](http://www.leconiot.com/md_res/cc1310/app/semi_hosting/images/ccs_semi_setting.png)) 同时需要工程配置文件`hello.cfg`使用 `SysMin`模块,同样地可以通过`SysCallback`重映射IO到我们指定的打印接口(比如串口)来禁止改功能; ```C /* * The System.SupportProxy defines a low-level implementation of System * functions such as System_printf(), System_flush(), etc. * * Pick one pair: * - SysMin * This module maintains an internal configurable circular buffer that * stores the output until System_flush() is called. * The size of the circular buffer is set via SysMin.bufSize. * - SysCallback * SysCallback allows for user-defined implementations for System APIs. * The SysCallback support proxy has a smaller code footprint and can be * used to supply custom System_printf services. * The default SysCallback functions point to stub functions. See the * SysCallback module's documentation. */ var SysMin = xdc.useModule('xdc.runtime.SysMin'); SysMin.bufSize = 512; System.SupportProxy = SysMin; //var SysCallback = xdc.useModule('xdc.runtime.SysCallback'); //System.SupportProxy = SysCallback; //SysCallback.abortFxn = "&myUserAbort"; //SysCallback.exitFxn = "&myUserExit"; //SysCallback.flushFxn = "&myUserFlush"; //SysCallback.putchFxn = "&myUserPutch"; //SysCallback.readyFxn = "&myUserReady"; ``` ### 依赖文件 ### 如果使能了SemiHosting,需要`#inlucde`以下文件防止编译错误: ``` /* XDC Module Headers */ #include #include ``` ## 参考 ## [What is semihosting?](http://www.keil.com/support/man/docs/armcc/armcc_pge1358787046598.htm) [TI-RTOS Examples SemiHosting](http://processors.wiki.ti.com/index.php/TI-RTOS_Examples_SemiHosting) ## 加入我们 ## 文章所有代码、工具、文档开源。加入我们[**QQ群 593145299**](https://jq.qq.com/?_wv=1027&k=512J9pr)获取更多支持,共同研究Contiki应用和TI-15.4Stack。

CC2640R2F&BLE5.0-乐控畅联 ©Copyright 2017, 成都乐控畅联科技有限公司.