NOTICE: The Processors Wiki will End-of-Life in December of 2020. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

CC26xx Adding basic printf over uart with TI-RTOS

From Texas Instruments Wiki
Jump to: navigation, search

Most of the Bluetooth Smart sample applications use SysCallback as the system provider for TI-RTOS. See TI-RTOS User's Guide for more information about the system providers.

In this case, SysCallback is ideal. It is very lightweight, and it is up to us to provide the hooks used by the system helpers such as System_printf(). See the CDOCs for XDC the Runtime module for information about printf formatting. See also the CDOCs for SysCallback for documentation on the hooks.

We will provide a handler for SysCallback.putchFxn. This is invoked by the system provider proxy whenever System_printf() is called.

This is configured by editing the TI-RTOS config file, usually called appBLE.cfg in the Bluetooth sample apps.

<syntaxhighlight lang='java'> var SysCallback = xdc.useModule('xdc.runtime.SysCallback'); // Already present SysCallback.putchFxn = "&uartPrintf_putch"; // Our callback </syntaxhighlight>

The example implementation of uartPrintf_putch provided below will simply add characters to a circular buffer. To get the data out on the UART, we also need some kind of flushing function.

In order to be unobtrusive to the rest of the system, we will make TI-RTOS call our flushing function when nothing else is going on, i.e. when the Idle task is running. Typically, when the Idle task is called it will in turn call the power manager which puts the system to the lowest power mode allowed. Right now we will insert our UART flush function before that point.

<syntaxhighlight lang='java'> var Idle = xdc.useModule('ti.sysbios.knl.Idle'); // Must be added to the .cfg file for correct parsing. Would have been added by the Power module in any case. Idle.addFunc('&uartPrintf_flush'); // Our flushing function. </syntaxhighlight>

The example uartPrintf_flush() provided below will simply use the TI-RTOS UART driver and call UART_write() with the data in the circular buffer.

In order to use the flush function, the user is required to call UART_open() with valid parameters and a valid UART configuration and give the UART object's handle (returned from UART_open) to UartPrintf_init(). Example usage for main.c:

<syntaxhighlight lang='c'>

  1. include "uart_printf.h"
  2. include <xdc/runtime/System.h>

... int main() {

 PIN_init(BoardGpioInitTable);
 // Enable System_printf(..) UART output
 UART_Params uartParams;
 UART_Params_init(&uartParams);
 uartParams.baudRate = 115200;
 UartPrintf_init(UART_open(Board_UART, &uartParams));
 System_printf("Hello, universe!\r\n");
 
 //...
 /* enable interrupts and start SYS/BIOS */
 BIOS_start();

</syntaxhighlight>

The above example will set up the UART for Blocking mode (this is important) and use the Board_UART index define (usually 0 since there's only one UART) from Board.h. It is expected that Board.c contains the setup for the UART driver's hardware configurations. The sample applications' Board.c files should have this set up out of the box.

Download example[edit]

Both the function uartPrintf_putch() and uartPrintf_flush(), along with a sample modified TI-RTOS .cfg file can be downloaded here: File:Cc26xx system printf syscallback example.zip

E2e.jpg {{
  1. switchcategory:MultiCore=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article CC26xx Adding basic printf over uart with TI-RTOS here.

Keystone=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article CC26xx Adding basic printf over uart with TI-RTOS here.

C2000=For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article CC26xx Adding basic printf over uart with TI-RTOS here. DaVinci=For technical support on DaVincoplease post your questions on The DaVinci Forum. Please post only comments about the article CC26xx Adding basic printf over uart with TI-RTOS here. MSP430=For technical support on MSP430 please post your questions on The MSP430 Forum. Please post only comments about the article CC26xx Adding basic printf over uart with TI-RTOS here. OMAP35x=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article CC26xx Adding basic printf over uart with TI-RTOS here. OMAPL1=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article CC26xx Adding basic printf over uart with TI-RTOS here. MAVRK=For technical support on MAVRK please post your questions on The MAVRK Toolbox Forum. Please post only comments about the article CC26xx Adding basic printf over uart with TI-RTOS here. For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article CC26xx Adding basic printf over uart with TI-RTOS here.

}}

Hyperlink blue.png Links

Amplifiers & Linear
Audio
Broadband RF/IF & Digital Radio
Clocks & Timers
Data Converters

DLP & MEMS
High-Reliability
Interface
Logic
Power Management

Processors

Switches & Multiplexers
Temperature Sensors & Control ICs
Wireless Connectivity