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.

How to use System_printf in tirtos_simplelink_2_11_00_03_eng

Other Parts Discussed in Thread: SYSBIOS, CC2650

Hi,

I want to use System_prinf in tirtos_simplelink_2_11_00_03_eng on M3 (MCU)

But I try many way my search on TI E2E but still print nothing.

Thank

  • Hi Vincent,

    In order to use System_printf() in your app, please follow below steps:

    • Include xdc.runtime.System module in your app's *.cfg file
    xdc.useModule('xdc.runtime.System');
    • Include System.h header in your C file and then you can make System_printf() calls.
    #include <xdc/runtime/System.h>
    
    Void func()
    {
       ...
       System_printf("This is test msg %d.\n", msgId);
    }

    System_printf() usage is very similar to printf() usage. For more info please see System_printf() cdoc here.

    Best,

    Ashish

  • Hi Ashish,
    Sorry I forgot to mention my environment.
    The Compile is IAR 7.30.3
    The Chip core is M3(this SOC is under NDA now so I can not mention chip name)

    My config is :
    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');
    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    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');

    /* Use the minimal user-supplied callback provider */
    System.SupportProxy = SysCallback;
    /* no exit handlers needed */
    System.maxAtexitHandlers = 0;

    and the app also has include
    /*********************************************************************
    * INCLUDES
    */
    #include <string.h>
    #include <xdc/std.h>

    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/System.h>

    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Semaphore.h>
    #include <ti/sysbios/knl/Queue.h>

    #include <ICall.h>
    #include "bcomdef.h"
    #include "gatt.h"
    #include "ll.h"
    #include "hci.h"
    #include "gapgattserver.h"
    #include "gattservapp.h"
    #include "central.h"
    #include "gapbondmgr.h"
    #include "simpleGATTprofile.h"

    #include "osal_snv.h"
    #include "ICallBleAPIMSG.h"

    #include "util.h"
    #include "board_key.h"
    #include "board_lcd.h"
    #include "Board.h"
    #include <driverlib/trng.h>

    #include "simpleBLECentral.h"

    but the System_printf has nothing out via uart0
    Do I need define GPIO fun first or enable UART fun.

    Thanks
  • Hi
    Now I do this like below:

    in appBLE.cfg
    var SysCallback = xdc.useModule('xdc.runtime.SysCallback');
    var SysStd = xdc.useModule('xdc.runtime.SysStd');
    var System = xdc.useModule('xdc.runtime.System');
    /* Use the minimal user-supplied callback provider */
    System.SupportProxy = SysStd;


    in app
    #include <xdc/runtime/System.h>

    void func (void){
    .....
    System_printf("Printf Fun Ok");

    }

    But IAR build project show the error message
    no definition for "__dwrite"[referenced from xxwritebuffered.o(dl7M_tln.a)]
    Error while running Linker

    So the problem is about setting IAR compile or xxx.cfg

    Thanks
  • Hi
    it is me again, now I do this document "TI-RTOS 2.10 User’s Guide" UART driver chapt....
    UART_Params_init(&params);
    //params.baudRate = someNewBaudRate;
    params.baudRate = 115200;
    params.parityType = UART_PAR_NONE;
    params.dataLength = UART_LEN_8;
    params.stopBits = UART_STOP_ONE;
    params.writeDataMode = UART_DATA_BINARY;
    params.readDataMode = UART_DATA_BINARY;
    params.readReturnMode = UART_RETURN_FULL;
    params.readEcho = UART_ECHO_OFF;
    handle = UART_open(Board_UART, &params); //<=======This line does work
    if (!handle) {
    System_printf("UART did not open");
    }


    uint8_t str[] = "SimpleBLECentral_init Dome\r\n";
    UART_write(handle, str, sizeof(str)); //<===============This line does work too

    System_printf("Printf Fun========================== Ok");//<=========but this System_printf also does not work........why?
    System_flush();
  • I find the problem is in IAR Arm compile does not support System_printf.
    So I am going to find the How to define the "__dwrite" in IAR.
  • Hi Vincent,

    System_printf() by default uses either the SysStd or SysMin (default is SysMin) system provider. Depending on which system provider is plugged in, either putchar() or __write() is called. Both these calls use the semihosting library to print to the console in IAR. "__dwrite" is already implemented in IAR's runtime library. Which library are you linking with ?

    In order for semihosting to work, you need to be connected to the debugger. If the board is running stand alone, then it is best to plug in UART to get the print msgs. Since you already have UART_write() working, you can do the following to forward all System_printf() msgs to UART:

    *.cfg:
    var System = xdc.useModule('xdc.runtime.System');
    var SysCallback = xdc.useModule('xdc.runtime.SysCallback');
    
    System.SupportProxy = SysCallback;
    
    SysCallback.abortFxn = "&userAbort";
    SysCallback.exitFxn  = "&userExit";
    SysCallback.flushFxn = "&userFlush";
    SysCallback.putchFxn = "&userPutch";
    SysCallback.readyFxn = "&userReady";
    
    *.c:
    
    Void userAbort(CString str)
    {
    }
    
    Void userExit(Int val)
    {
    }
    
    Void userFlush()
    {
    }
    
    Void userPutch(Char ch)
    {
      UART_write(handle, ch, sizeof(ch));
    }
    
    Void userReady()
    {
      ...
    }

    Once you do the above setup, you can use System_printf() instead of UART_write() and all your prints will be visible on the UART console.

    Best,

    Ashish

  • Hi Ashish,
    Actuality I dont know which lib I use it now,
    But I post what I did and It does work but it seems running SW it is not good
    My .cfg is:
    /* Use the minimal user-supplied callback provider */
    System.SupportProxy = SysCallback;

    My board_uartDB.c is
    #include "board_uartDB.h"

    UART_Handle URhandle;
    UART_Params URparams;

    void VKDBUART_INIT (void)
    {
    UART_Params params;

    Board_initUART();
    UART_Params_init(&params);

    params.baudRate = 115200;
    params.parityType = UART_PAR_NONE;
    params.dataLength = UART_LEN_8;
    params.stopBits = UART_STOP_ONE;
    params.writeDataMode = UART_DATA_BINARY;
    params.readDataMode = UART_DATA_BINARY;
    params.readReturnMode = UART_RETURN_FULL;
    params.readEcho = UART_ECHO_OFF;
    URhandle = UART_open(Board_UART, &params);
    if( !URhandle )
    {
    printf("UART did not open");
    }
    else
    {
    printf("The UART DB initial OK\r\n");
    }
    }

    int WRITEFUNC (int handle, char *pcBuffer, int len)
    {
    //UART_write(URhandle, pcBuffer, len);//The handle must use our init handle!!
    UARTCC26XX_write(URhandle, pcBuffer, len);
    return len;
    }

    int READFUNC (void)
    {
    char c;
    UARTCC26XX_read(URhandle, &c, 1);
    //UART_read(URhandle, &c, 1);
    return (int)c;
    }

    My board_uartDB.h is
    #ifndef BOARD_UARTDB_H
    #define BOARD_UARTDB_H

    #ifdef __cplusplus
    extern "C" {
    #endif

    #include <stdio.h>
    #include <string.h>
    #include "Board.h"
    //#include <ti/drivers/UART.h>
    #include <ti/drivers/uart/UARTCC26XX.h>
    //#include <xdc/runtime/System.h>
    //==============================================================================

    #define Board_initUART() UART_init()

    #define WRITEFUNC __write
    #define READFUNC __readc

    extern UART_Handle URhandle;
    //==============fun=============================================================
    void VKDBUART_INIT (void);

    // Function __write() / __sys_write
    int WRITEFUNC (int handle, char *pcBuffer, int len);
    // Function __readc() / __sys_readc
    int READFUNC (void);


    setting like above it does work by printf.

    and I do like you say
    .cfg
    /* Use the minimal user-supplied callback provider */
    System.SupportProxy = SysCallback;

    SysCallback.abortFxn = "&userAbort";
    SysCallback.exitFxn = "&userExit";
    SysCallback.flushFxn = "&userFlush";
    SysCallback.putchFxn = "&userPutch";
    SysCallback.readyFxn = "&userReady";

    My board_uartDB.c is
    #include "board_uartDB.h"

    UART_Handle URhandle;
    UART_Params URparams;

    void VKDBUART_INIT (void)
    {
    UART_Params params;

    Board_initUART();
    UART_Params_init(&params);

    params.baudRate = 115200;
    params.parityType = UART_PAR_NONE;
    params.dataLength = UART_LEN_8;
    params.stopBits = UART_STOP_ONE;
    params.writeDataMode = UART_DATA_BINARY;
    params.readDataMode = UART_DATA_BINARY;
    params.readReturnMode = UART_RETURN_FULL;
    params.readEcho = UART_ECHO_OFF;
    URhandle = UART_open(Board_UART, &params);
    if( !URhandle )
    {
    System_printf("UART did not open");
    }
    else
    {
    System_printf("The UART DB initial OK\r\n");
    }
    }
    /*
    int WRITEFUNC (int handle, char *pcBuffer, int len)
    {
    //UART_write(URhandle, pcBuffer, len);//The handle must use our init handle!!
    UARTCC26XX_write(URhandle, pcBuffer, len);
    return len;
    }

    int READFUNC (void)
    {
    char c;
    UARTCC26XX_read(URhandle, &c, 1);
    //UART_read(URhandle, &c, 1);
    return (int)c;
    }
    */

    void userAbort(CString str)
    {
    }

    void userExit(Int val)
    {
    }

    void userFlush()
    {
    }

    int userPutch(int ch)
    {
    UARTCC26XX_write(URhandle, &ch, sizeof(ch));
    return 1;
    }

    void userReady()
    {
    }

    My board_uartDB.h is
    #ifndef BOARD_UARTDB_H
    #define BOARD_UARTDB_H

    #ifdef __cplusplus
    extern "C" {
    #endif

    #include <stdio.h>
    #include <string.h>
    #include "Board.h"
    //#include <ti/drivers/UART.h>
    #include <ti/drivers/uart/UARTCC26XX.h>
    #include <xdc/runtime/System.h>
    //==============================================================================

    #define Board_initUART() UART_init()

    #define userPutch __write
    //#define READFUNC __readc
    //#define WRITEFUNC __write
    //#define READFUNC __readc

    extern UART_Handle URhandle;
    //==============fun=============================================================
    void VKDBUART_INIT (void);

    // Function __write() / __sys_write
    int WRITEFUNC (int handle, char *pcBuffer, int len);
    // Function __readc() / __sys_readc
    int READFUNC (void);

    void userAbort(CString str);
    void userExit(int val);
    void userFlush();
    int userPutch(int ch);
    void userReady();

    IAR compile has error message: no definition userPutch and how do I fix this.
  • Hi Vincent,

    Can you paste the entire build log ? Also, the function signature for userPutch() in the code you shared is incorrect. It should be "Void userPutch(Char ch)". Please fix the function signature.

    Best,
    Ashish

  • Hi,
    The .cfg
    var ROM = xdc.useModule('ti.sysbios.rom.ROM');
    ROM.romName = ROM.CCxxxx; <---I can not show the right now

    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');
    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    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;

    /* 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;

    SysCallback.abortFxn = "&userAbort";
    SysCallback.exitFxn = "&userExit";
    SysCallback.flushFxn = "&userFlush";
    SysCallback.putchFxn = "&userPutch";
    SysCallback.readyFxn = "&userReady";



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

    /* main() and Hwi, Swi stack size */
    Program.stack = 1024;
    /* 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;

    /* Create a small "alloc-only" heap */
    BIOS.heapSize = 1668;

    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;

    /* 10 us tick period */
    Clock.tickPeriod = 10;



    the my xxx.c
    #include "board_uartDB.h"

    UART_Handle URhandle;
    UART_Params URparams;

    void VKDBUART_INIT (void)
    {
    UART_Params params;

    Board_initUART();
    UART_Params_init(&params);

    params.baudRate = 115200;
    params.parityType = UART_PAR_NONE;
    params.dataLength = UART_LEN_8;
    params.stopBits = UART_STOP_ONE;
    params.writeDataMode = UART_DATA_BINARY;
    params.readDataMode = UART_DATA_BINARY;
    params.readReturnMode = UART_RETURN_FULL;
    params.readEcho = UART_ECHO_OFF;
    URhandle = UART_open(Board_UART, &params);
    if( !URhandle )
    {
    System_printf("UART did not open");
    }
    else
    {
    System_printf("The UART DB initial OK-1\r\n");
    printf("The UART DB initial OK-2\r\n");
    }
    }

    int WRITEFUNC (int handle, char *pcBuffer, int len)
    {
    //UART_write(URhandle, pcBuffer, len);//The handle must use our init handle!!
    UARTCC26XX_write(URhandle, pcBuffer, len);
    return len;
    }

    int READFUNC (void)
    {
    char c;
    UARTCC26XX_read(URhandle, &c, 1);
    //UART_read(URhandle, &c, 1);
    return (int)c;
    }


    void userAbort(CString str)
    {

    }

    void userExit(Int val)
    {

    }

    void userFlush()
    {

    }

    void userPutch(char ch)
    {
    UARTCC26XX_write(URhandle, &ch, sizeof(ch));
    }

    void userReady()
    {

    }

    and my xxx.h
    #ifndef BOARD_UARTDB_H
    #define BOARD_UARTDB_H

    #ifdef __cplusplus
    extern "C" {
    #endif

    #include <stdio.h>
    #include <string.h>
    #include "Board.h"
    //#include <ti/drivers/UART.h>
    #include <ti/drivers/uart/UARTCC26XX.h>
    #include <xdc/runtime/System.h>
    //==============================================================================

    #define Board_initUART() UART_init()

    //here I dont know how to define for IAR compile
    //#define userPutch __write
    //#define READFUNC __readc

    //The stdio.h printf use====define
    //#define WRITEFUNC __write
    //#define READFUNC __readc

    extern UART_Handle URhandle;
    //==============fun=============================================================
    void VKDBUART_INIT (void);

    // Function __write() / __sys_write
    int WRITEFUNC (int handle, char *pcBuffer, int len);
    // Function __readc() / __sys_readc
    int READFUNC (void);

    void userAbort(CString str);
    void userExit(int val);
    void userFlush();
    void userPutch(char ch);
    void userReady();


    #ifdef __cplusplus
    }
    #endif

    #endif



    The IAR compile error message is
    Error[Li005]:no definition for"__write" [referenced from putchar.o(dl7M_tln.a)]
    Error while running Linker

    Now all of setting is do what you teach me...
    Thanks
  • Hi Ashish,
    You were right, I was totally misunderstanding what you mean.
    Now System_printf does work good and pretty happy running on my FW app layer.
    There is one more question that I want to ask.
    Does TI-RTOS support like scanf() fun?
    I also need use uart port to listen command like AT Command.

    Thanks
  • Hi Vincent,

    Glad to know System_printf() is working for you now.

    The System module does not support scanf() functionality. What you could do is provide your own implementation of __read() that uses UART_read() underneath. This way you will be able to use the C runtime library's scanf. Please see "IMPLEMENTING LOW-LEVEL CHARACTER INPUT AND OUTPUT" section of the IAR user guide addendum. This section explains how to implement your own version of __read and also has an example for reference.

    Best,

    Ashish

  • Hi Ashish,
    I got it,

    Thanks
  • Ashish Kapania said:
    • Include xdc.runtime.System module in your app's *.cfg file
    xdc.useModule('xdc.runtime.System');
    • Include System.h header in your C file and then you can make System_printf() calls.
    #include <xdc/runtime/System.h>
    
    Void func()
    {
       ...
       System_printf("This is test msg %d.\n", msgId);
    }

    This doesn't seem to work in IAR. it's complaining about undefined __write function.

  • Can you start a new thread? Please include version numbers and the device you are on.
  • Error[Li005]: no definition for "PLL_Init"
    Error[Li005]: no definition for "UART_Init"
    Error[Li005]: no definition for "UART_OutChar"
    Error[Li005]: no definition for "UART_OutString"
    Error[Li005]: no definition for "UART_InString"
    Error[Li005]: no definition for "UART_InUDec"
    Error[Li005]: no definition for "UART_OutUDec"
    Error[Li005]: no definition for "UART_InUHex"
    Error[Li005]: no definition for "UART_OutUHex"

    This is my error and i have added uart.h file please its urgent
  • Hi Harshal,
    We generally discourage posting a new question to an old closed thread because the person who answered before may no longer be available, and also it will allow whomever is currently assigned to monitor the forum to respond to you more quickly. For these reasons, I suggest you start a new thread with your question and reference this thread.

    Thank you