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.

_CIOBUF with SD Card and Console

Other Parts Discussed in Thread: TM4C1294NCPDT, EK-TM4C1294XL

Hello,

I'm having a problem trying to setup UART 0 as a console and configuring FatFs to access the SD card/USB drive at the same time.  I'm following the examples "fatsdusbcopy" and "uartconsole" for a TIVA TM4C1294NCPDT.  Using my custom board, I can make both of these examples run independently without problem.  However, when I try to combine their functionality, execution on my target exits into "trgmsc.c".  I don't get any compilation errors, but the code won't execute without crashing.  The hardware seems to initialize okay, but when I use puts or printf to send a message to the console, that's when the program exits.  It seems like maybe there is a common buffer (CIOBUF???) that may be causing the issue, but I don't understand what's wrong.   My code crashes at the printf (it prints about half the string before exiting), shown below:


int main(void) { Task_Params taskParams; /* Call board init functions */ Board_initGeneral(); Board_initGPIO(); Board_initUART(); Board_initSDSPI(); Board_initUSBMSCHFatFs(); add_device("UART", _MSA, UARTUtils_deviceopen, UARTUtils_deviceclose, UARTUtils_deviceread, UARTUtils_devicewrite, UARTUtils_devicelseek, UARTUtils_deviceunlink, UARTUtils_devicerename); // Open UART0 for writing to stdout and set buffer freopen("UART:0", "w", stdout); setvbuf(stdout, NULL, _IOLBF, 128); // Open UART0 for reading from stdin and set buffer freopen("UART:0", "r", stdin); setvbuf(stdin, NULL, _IOLBF, 128); /* * Initialize UART port 0 used by SysCallback. This and other SysCallback * UART functions are implemented in UARTUtils.c. Calls to System_printf * will go to UART0, the same as printf. */ UARTUtils_systemInit(0); /* Construct file copy Task thread */ Task_Params_init(&taskParams); taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task0Stack; taskParams.instance->name = "fatsdUSBCopyTask"; Task_construct(&task0Struct, (Task_FuncPtr)taskFxn, &taskParams, NULL); /* Turn on user LED */ GPIO_write(MICA_DEBUG_LED, Board_LED_ON); printf("Starting the FatSD USB Copy example\n"); /* Start BIOS */ BIOS_start();

Can someone provide guidance on how to correct the problem?


Thank you,

Eric

  • Hi Eric,

    I think when you combine the examples, the C std calls that hook printf(),puts() to UART APIs (in UARTconsole app) and fread(), fwrite() to FATfs APIs (in FATfs app) are causing a conflict. I recommend using UART APIs and FATfs APIs directly in your application than invoking them through C Std APIs like printf(), fread(). Please make sure they don't conflict in your application.

    If you still hit the same issue, please share your project so that I can have a look.

    Vikram

  • Hi Vikram,


    I would really like to be able to use the C std calls.  I was able to successfully combine both examples using a 2.14 version of RTOS which included the Fat APIs within BIOS.  But, I'm now using the 2.16 version of BIOS, in which the Fat APIs have been moved to middleware.  Is it something with the transition to middleware that is causing the problem?

    Please see my project attached.  Please note, while this code is based on the EK-TM4C1294XL example, I modified the board specific files to represent the hardware on my custom PCB.

    Thanks for your help!

    Eric7367.Project File for Vikram.zip

  • Hi Eric,

    I am looking into your code. I will get back to you soon.

    Vikram
  • Hi Eric,

    I quickly scanned your code. It looks like UART is used to output data. I would recommend using System_printf() instead of printf() for this operation.

    System_printf() is similar to printf() and in your application configuration, it is configured to output through UART.

    And I would also recommend removing this code:

    Eric Kaltenbacher said:
    add_device("UART", _MSA, UARTUtils_deviceopen, UARTUtils_deviceclose, UARTUtils_deviceread, UARTUtils_devicewrite, UARTUtils_devicelseek, UARTUtils_deviceunlink, UARTUtils_devicerename); // Open UART0 for writing to stdout and set buffer freopen("UART:0", "w", stdout); setvbuf(stdout, NULL, _IOLBF, 128); // Open UART0 for reading from stdin and set buffer freopen("UART:0", "r", stdin); setvbuf(stdin, NULL, _IOLBF, 128);

    Vikram