This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2650: UART write to terminal

Part Number: CC2650


Dear Community, Dear Colleges

I know this is surely an old and banal topic.

I'm developing one project on CC2650 with the IDE IAR. I would like to write the content of a buffer variable to a terminal (Putty, Terminal) via UART, using the driver function UART_write().

Unfortunately, this does not work. I'm not able to output/write nothing to the Putty or to the Terminal. 

I need your help.

Here, I will describe the current situation.

1. First, I have the UART init function. At the end of the function I try to write a byte to the terminal using the UART_write(). This does not work.

__________________________________________________________________________________________________

#include <ti/drivers/UART.h>
#include <ti/drivers/uart/UARTCC26XX.h>
#include <xdc/runtime/System.h>
#include "board.h"

int Init_UART(void)
{
    UART_Params params;

    // Configure UART parameters.
    UART_Params_init(&params);
    params.baudRate = 115200;
    uartParams.readMode = UART_MODE_BLOCKING;
    uartParams.writeMode = UART_MODE_BLOCKING;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readTimeout =  ((250) * 1000) / Clock_tickPeriod;
    uartParams.dataLength = UART_LEN_8;
    uartParams.parityType = UART_PAR_NONE;
    uartParams.stopBits = UART_STOP_ONE;
    uartParams.readEcho = UART_ECHO_OFF;

    // Open / power on the UART.
    UART_init();
  
    uartHandle = UART_open(Board_UART, &uartParams);
    uint8_t Array_One[1] = {1};
    int count = UART_write(uartHandle, Array_One, sizeof(Array_One));

    return count;
}

2. Second, I have the following app.cfg file.

_________________________________________________

/* sysbios */
var useSysbiosInRom = true;

if ( useSysbiosInRom )
{
  var ROM = xdc.useModule('ti.sysbios.rom.ROM');
  ROM.romName = ROM.CC2650;
}

var Defaults = xdc.useModule('xdc.runtime.Defaults');
var Types = xdc.useModule('xdc.runtime.Types');
var Diags = xdc.useModule('xdc.runtime.Diags');
var Error = xdc.useModule('xdc.runtime.Error');
var Main = xdc.useModule('xdc.runtime.Main');
var Memory = xdc.useModule('xdc.runtime.Memory') 
var SysCallback = xdc.useModule('xdc.runtime.SysCallback');
var System = xdc.useModule('xdc.runtime.System');
var Text = xdc.useModule('xdc.runtime.Text');

if ( useSysbiosInRom )
{
  var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
}
else
{
  var HeapMin = xdc.useModule('xdc.runtime.HeapMin');
}
var Reset = xdc.useModule('xdc.runtime.Reset');
var BIOS = xdc.useModule('ti.sysbios.BIOS');
var Clock = xdc.useModule('ti.sysbios.knl.Clock');
var Task = xdc.useModule('ti.sysbios.knl.Task');

var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
var M3Hwi = xdc.useModule('ti.sysbios.family.arm.m3.Hwi');
var Power = xdc.useModule('ti.sysbios.family.arm.cc26xx.Power');

/* Enable idle task (default). */
Task.enableIdleTask = true;

/* Idle CPU when threads blocked waiting for an interrupt */
Power.idle = true;
Power.policyFunc = Power.standbyPolicy;

/* Turn off RCOSC calibration */
Power.calibrateRCOSC = false;

/* compile out all Assert's */
Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;

/* Don't load string names of modules on the target */
Defaults.common$.namedModule = false;

/* Allow Mod_create() and Mod_construct() but not delete() or destruct() */
Defaults.common$.memoryPolicy = Types.CREATE_POLICY;

/* Don't load diagnostic/descriptive text strings on the target */
Text.isLoaded = false;

/* Use the minimal user-supplied callback provider */
System.SupportProxy = SysCallback;

/* no exit handlers needed */
System.maxAtexitHandlers = 0;

/* main() and Hwi, Swi stack size */
Program.stack = 1024;

if ( useSysbiosInRom )
{
  /* no command-line arguments main(argc, argv) needed */
  Program.argSize = 0;
}

/* build a custom, optimized version of SYS/BIOS */
BIOS.libType = BIOS.LibType_Custom;

/* no logging - all compiled out */
BIOS.logsEnabled = false;

/* disable Asserts in SYS/BIOS code */
BIOS.assertsEnabled = false;

/* Reduce number of Task priority levels to save RAM */
Task.numPriorities = 6;

/* Set the default Task stack size - used if one is not specified */
Task.defaultStackSize = 512;

/* Don't check stacks for overflow - saves cycles (and power) and Flash */
Task.checkStackFlag = false;

/* Disable exception handling to save Flash - undo during active development */
M3Hwi.enableException = true;
M3Hwi.excHandlerFunc = null; /* null = default while loop function. Use e.g. "&myFxn" to use your own function. */
M3Hwi.nvicCCR.UNALIGN_TRP = 0;
M3Hwi.nvicCCR.DIV_0_TRP = 0;

/* Don't check for interrupt stack overflow during Idle loop */
Hwi.checkStackFlag = false;

/* Minimize Flash and RAM usage of Error module */
Error.raiseHook = null; /* null = default while loop function. Use e.g. "&myFxn" to your own handler function. */
Error.maxDepth = 2;

/* Set the default CPU frequency */
BIOS.cpuFreq.lo = 48000000;

/* Put reset vector at start of Flash */
M3Hwi.resetVectorAddress  = 0x0;

/* Put interrupt vector at start of RAM so interrupts can be configured at runtime */
M3Hwi.vectorTableAddress  = 0x20000000;

/* CC2650 has 50 interrupts */
M3Hwi.NUM_INTERRUPTS = 50;

if ( useSysbiosInRom )
{
  /* Create a small "alloc-only" heap */
  BIOS.heapSize = 1924;
}
else
{
  var heapMinParams = new HeapMin.Params;
  heapMinParams.size = 1924;
  var myHeapMin = HeapMin.create(heapMinParams);
  Memory.defaultHeapInstance = myHeapMin;
}

var Swi = xdc.useModule('ti.sysbios.knl.Swi');
Swi.numPriorities = 6;
BIOS.swiEnabled = true;

BIOS.includeXdcRuntime = true;

/* Tasks cannot pend based on priority */
Semaphore.supportsPriority = false;

/* Change default error function -- just spin */
Error.policyFxn = Error.policySpin;

/* true:  Allow runtime creation of e.g. semaphores
 * false: Compile out reference to Memory in BIOS */
BIOS.runtimeCreatesEnabled = true;

/* Abort and exit functions -- just spin */
System.abortFxn = System.abortSpin;
System.exitFxn = System.exitSpin;

/* CC26xx Boot module */
var Boot = xdc.useModule('ti.sysbios.family.arm.cc26xx.Boot');
Boot.driverlibVersion = 2;
Boot.customerConfig = false;
Boot.checkBackdoor = true;

/* Clock tick Period set to 10 us if not defined */
Clock.tickPeriod = 10;

/* Uart printout
System.SupportProxy = SysCallback;
var Idle = xdc.useModule('ti.sysbios.knl.Idle');
Idle.addFunc('&uartPrintf_flush');
SysCallback.putchFxn = "&uartPrintf_putch";
*/

var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS'); 
TIRTOS.useUART = true;

/* System_printf configuration for JTAG comm with IAR */

var SysStd = xdc.useModule("xdc.runtime.SysStd");
System.SupportProxy = SysStd;

System.extendedFormats = '%$L%$S%$F%f';

3. Thirdly. The settings in IAR.

________________________________________________________________________________________

Please, can someone help me and tell me what do I wrong and what is the right way :)

Thank you in advance for your help.

Radka-Shmatka

  • Hi,

    If not already done, I would recommend to leverage the uartecho provided by TI. It should work out of the box.

    If not, verify the settings of your serial terminal (see the README file of the example). You may also want to use a logic analyzer to confirm the device is sending out something. Last but not least, try to run the system in debug mode to confirm that no exception is raised.

    I hope this will help,

    Best regards,

  • Dear Clément

    Thank you very much for your reply.

    Regarding your first suggestion. I tried to run the uartecho example, but it didn't work just as well as my code :D

    Regarding your second suggestion. It is good. I prepared a debug session with all init and write functions from the TI RTOS UART driver and also the logic analyzer. So I will debug through the code and see if the device is sending out something. 

    Best regards,

    Radka-Shmatka :)

  • Dear Clément, Dear Community

    Thank you a lot for your great support.

    I did it. It works. I found my mistake. The mistake was in the UART_Params settings. The write buffer was send to the UART, but the UART state remains all the time busy. So the buffer was never send to the terminal.

    The UART works properly with the following UART_Params settings:

    int Init_UART(void)
    {
        UART_Params params;
    
        // Configure UART parameters.    
        UART_Params_init(&uartParams);
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 9600;
    
        // Open / power on the UART.
        UART_init();
      
        uartHandle = UART_open(Board_UART, &uartParams);
        UARTCC26XX_Object* object = (UARTCC26XX_Object*)uartHandle->object;
        uint8_t Array_One[7] = {0x31, 0x32, 0x37, 0x39, 0x36, 0x35, 0x34};
        int count = UART_write(uartHandle, Array_One, sizeof(Array_One));
    
        return count;
    }

    Additionaly, I commented the last section "System_printf configuration for JTAG comm with IAR" in the app.cfg file.

    /* Uart printout
    System.SupportProxy = SysCallback;
    var Idle = xdc.useModule('ti.sysbios.knl.Idle');
    Idle.addFunc('&uartPrintf_flush');
    SysCallback.putchFxn = "&uartPrintf_putch";
    */
    
    var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS'); 
    TIRTOS.useUART = true;
    
    /* System_printf configuration for JTAG comm with IAR 
    
    var SysStd = xdc.useModule("xdc.runtime.SysStd");
    System.SupportProxy = SysStd;
    
    System.extendedFormats = '%$L%$S%$F%f';
    */

    That was it, dear Colleges  :)

    I wish you a nice weekend :)

    Radka-Shmatka :)

  • Hi,

    Well done!

    Thank you for sharing your solution.

    Have a great weekend.

    Regards,