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.

CCS/LP-CC2652RB: Mutex example code merged with uartecho and sd raw

Part Number: LP-CC2652RB
Other Parts Discussed in Thread: SYSCONFIG, CC2652RB,

Tool/software: Code Composer Studio

Hello,

I have to receive incoming data from uart via arduino and store the incoming data into a sd card attached with cc2652 launchpad. In this problem i am trying to use mutex example code with two tasks and a semaphore to switch tasks. I have put uartecho code in one task and sdraw code in other task. please see my code below. I am getting errors. Is th apporach right?

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SD.h>
#include <ti/display/Display.h>
#include <ti/drivers/UART.h>
/* Driver configuration */
#include "ti_drivers_config.h"
#define WRITEENABLE 0

/* Size of data buffers */
#define BUFFER_SIZE 1024

/* Starting sector to write/read to */
#define STARTINGSECTOR 0

/* Bytes per Megabyte */
#define BYTESPERMEGABYTE 1048576

static uint8_t writeBuffer[BUFFER_SIZE];
static uint8_t readBuffer[BUFFER_SIZE];
#if (WRITEENABLE)
static uint8_t emptyBuffer[BUFFER_SIZE] = {0};
#endif

/* XDC module Headers */
#include <xdc/std.h>
#include <xdc/runtime/System.h>

/* BIOS module Headers */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>

#include <ti/drivers/Board.h>

#define TASKSTACKSIZE 512

Void task1Fxn(UArg arg0, UArg arg1);
Void task2Fxn(UArg arg0, UArg arg1);

Int resource = 0;
Int finishCount = 0;
UInt32 sleepTickCount;

Task_Struct task1Struct, task2Struct;
Char task1Stack[TASKSTACKSIZE], task2Stack[TASKSTACKSIZE];
Semaphore_Struct semStruct;
Semaphore_Handle semHandle;

/*
* ======== main ========
*/
int main()
{
/* Construct BIOS objects */
Task_Params taskParams;
Semaphore_Params semParams;
Display_init();
GPIO_init();
SD_init();
/* Call driver init functions */
Board_init();
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

/* Construct writer/reader Task threads */
Task_Params_init(&taskParams);
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task1Stack;
taskParams.priority = 1;
Task_construct(&task1Struct, (Task_FuncPtr)task1Fxn, &taskParams, NULL);

taskParams.stack = &task2Stack;
taskParams.priority = 2;
Task_construct(&task2Struct, (Task_FuncPtr)task2Fxn, &taskParams, NULL);

/* Construct a Semaphore object to be use as a resource lock, inital count 1 */
Semaphore_Params_init(&semParams);
Semaphore_construct(&semStruct, 1, &semParams);

/* Obtain instance handle */
semHandle = Semaphore_handle(&semStruct);

/* We want to sleep for 10000 microseconds */
sleepTickCount = 10000 / Clock_tickPeriod;

BIOS_start(); /* Does not return */
return(0);
}

/*
* ======== task1Fxn ========
*/
Void task1Fxn(UArg arg0, UArg arg1)
{
UInt32 time;

for (;;) {
SD_Handle sdHandle;
Display_Handle display;
uint32_t cardCapacity;
uint32_t totalSectors;
uint32_t sectorSize;
uint32_t sectors;
uint32_t i;
int16_t result;
Display_init();
GPIO_init();
SD_init();
System_printf("Running task1 function\n");

if (Semaphore_getCount(semHandle) == 0) {
System_printf("Sem blocked in task1\n");
}

/* Get access to resource */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);

/* Do work by waiting for 2 system ticks to pass */
time = Clock_getTicks();
while (Clock_getTicks() <= (time + 1)) {
;
}

/* Do work on locked resource */
resource += 1;
/* Unlock resource */

Semaphore_post(semHandle);

Task_sleep(sleepTickCount);
/* Open the display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
/* Failed to open display driver */
while (1);
}

/* Initialize the writeBuffer with data */
for (i = 0; i < BUFFER_SIZE; i++) {
writeBuffer[i] = i & 0xFF;
}

/* Mount and register the SD Card */
sdHandle = SD_open(CONFIG_SD_0, NULL);
if (sdHandle == NULL) {
Display_printf(display, 0, 0, "Error starting the SD card!");
while (1);
}

result = SD_initialize(sdHandle);
if (result != SD_STATUS_SUCCESS) {
Display_printf(display, 0, 0, "Error initializing the SD card!");
while (1);
}

/* Turn on user LED */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
Display_printf(display, 0, 0, "\n\rStarting the SD example...\n");

/* Read capacity information from the SD card */
totalSectors = SD_getNumSectors(sdHandle);
sectorSize = SD_getSectorSize(sdHandle);
cardCapacity = (totalSectors / BYTESPERMEGABYTE) * sectorSize;

/* Display capacity information */
Display_printf(display, 0, 0, "======== SD Card Information ========");
Display_printf(display, 0, 0, "Sectors:\t\t%u", totalSectors);
Display_printf(display, 0, 0, "Sector Size:\t\t%u bytes", sectorSize);
Display_printf(display, 0, 0, "Card Capacity:\t\t%u MB", cardCapacity);
Display_printf(display, 0, 0, "=====================================\n");

/* Calculate number of sectors taken up by the array by rounding up */
sectors = (BUFFER_SIZE + sectorSize - 1) / sectorSize;

#if (WRITEENABLE)
Display_printf(display, 0, 0, "Writing %u bytes...", BUFFER_SIZE);

result = SD_write(sdHandle, writeBuffer, STARTINGSECTOR, sectors);
if (result != SD_STATUS_SUCCESS) {
Display_printf(display, 0, 0, "Error writing to the SD card!");
while (1);
}
#else
Display_printf(display, 0, 0, "Run the example with WRITEENABLE "
"= 1 to enable writes to the SD card!");
#endif

Display_printf(display, 0, 0, "Reading %u bytes...", BUFFER_SIZE);

result = SD_read(sdHandle, readBuffer, STARTINGSECTOR, sectors);
if (result != SD_STATUS_SUCCESS) {
Display_printf(display, 0, 0, "Error reading from the SD card!");
while (1);
}

/* Compare data read from the SD card with expected values */
Display_printf(display, 0, 0, "\nComparing read and write data...");
if (memcmp(readBuffer, writeBuffer, BUFFER_SIZE)) {
#if (WRITEENABLE)
Display_printf(display, 0, 0,
"Data read does not match write data!");
while (1);
#else
Display_printf(display, 0, 0,
"WRITEENABLE == 0, therefore data mismatch occurred!");
#endif
}
else {
Display_printf(display, 0, 0,
"Data matches!");
}

#if (WRITEENABLE)
/* Clear any previously written data overwriting data with 0x0 */
Display_printf(display, 0, 0, "Erasing data written...");
result = SD_write(sdHandle, emptyBuffer, STARTINGSECTOR, sectors);
if (result != SD_STATUS_SUCCESS) {
Display_printf(display, 0, 0, "Error erasing the SD card!");
while (1);
}
#endif

Display_printf(display, 0, 0, "Done!");
SD_close(sdHandle);

}
}
}


/*
* ======== task2Fxn ========
*/
Void task2Fxn(UArg arg0, UArg arg1)
{
for (;;) {
System_printf("Running task2 function\n");
char input;
const char echoPrompt[] = "Echoing characters:\r\n";
UART_Handle uart;
UART_Params uartParams;

/* Call driver init functions */
GPIO_init();
UART_init();

/* Configure the LED pin */
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

/* Turn on user LED */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.baudRate = 115200;

uart = UART_open(CONFIG_UART_0, &uartParams);

if (uart == NULL) {
/* UART_open() failed */
while (1);
}

UART_write(uart, echoPrompt, sizeof(echoPrompt));

/* Loop forever echoing */
while (1) {
UART_read(uart, &input, 1);
UART_write(uart, &input, 1);
}

if (Semaphore_getCount(semHandle) == 0) {
System_printf("Sem blocked in task2\n");
}

/* Get access to resource */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);

/* Do work on locked resource */
resource += 1;
/* Unlock resource */

Semaphore_post(semHandle);

Task_sleep(sleepTickCount);

finishCount++;
if (finishCount == 5) {
System_printf("Calling BIOS_exit from task2\n");
BIOS_exit(0);
}
}
}

 

  • Hi Shivam,

    I have assigned an expert to help you on this issue. In the meantime, can you please share the error messages to better help with the debugging process? In addition, which SDK version are you using?

    I would also reference the following TI-RTOS guide on task, semaphore, and mutex uses/example code: https://dev.ti.com/tirex/explore/content/simplelink_cc13x2_26x2_sdk_4_20_01_04/docs/ble5stack/ble_user_guide/html/ble-stack-5.x-guide/tirtos-index.html#ti-rtos-rtos-kernel-overview

    Best Regards,

    Jenny

  • Thanks jenny, please refer the code and the errors i am getting below. I am using CCS  Version: 10.1.1.00004 

    The errors and their lines in program are as below:

    "../mutex.c", line 233: warning #112-D: statement is unreachable         //  if (Semaphore_getCount(semHandle) == 0) 
    "../mutex.c", line 310: error #20: identifier "CONFIG_SDFatFS_0" is undefined  // sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM);
    "../mutex.c", line 431: warning #121-D: return value type does not match the function type // return (NULL);
    "../mutex.c", line 432: warning #112 -D: statement is unreachable   //  if (Semaphore_getCount(semHandle) == 0) 

    /*
    * Copyright (c) 2015-2019, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */
    
    /*
    * ======== mutex.c ========
    */
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    #include <file.h>
    #include <stdbool.h>
    #include <stddef.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    /* POSIX Header files */
    #include <pthread.h>
    
    #include <third_party/fatfs/ffcio.h>
    
    #include <ti/display/Display.h>
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/SDFatFS.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    
    /* Buffer size used for the file copy process */
    #ifndef CPY_BUFF_SIZE
    #define CPY_BUFF_SIZE 2048
    #endif
    
    /* String conversion macro */
    #define STR_(n) #n
    #define STR(n) STR_(n)
    
    /* Drive number used for FatFs */
    #define DRIVE_NUM 0
    
    const char inputfile[] = "fat:"STR(DRIVE_NUM)":input.txt";
    const char outputfile[] = "fat:"STR(DRIVE_NUM)":output.txt";
    
    const char textarray[] = \
    "***********************************************************************\n"
    "0 1 2 3 4 5 6 7\n"
    "01234567890123456789012345678901234567890123456789012345678901234567890\n"
    "This is some text to be inserted into the inputfile if there isn't\n"
    "already an existing file located on the media.\n"
    "If an inputfile already exists, or if the file was already once\n"
    "generated, then the inputfile will NOT be modified.\n"
    "***********************************************************************\n";
    
    static Display_Handle display;
    
    /* Set this to the current UNIX time in seconds */
    const struct timespec ts = {
    .tv_sec = 1469647026,
    .tv_nsec = 0
    };
    
    /* File name prefix for this filesystem for use with TI C RTS */
    char fatfsPrefix[] = "fat";
    
    unsigned char cpy_buff[CPY_BUFF_SIZE];
    
    /*
    * ======== mainThread ========
    * Thread to perform a file copy
    *
    * Thread tries to open an existing file inputfile[]. If the file doesn't
    * exist, create one and write some known content into it.
    * The contents of the inputfile[] are then copied to an output file
    * outputfile[]. Once completed, the contents of the output file are
    * printed onto the system console (stdout).
    */
    
    
    /* XDC module Headers */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    
    /* BIOS module Headers */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>
    
    #include <ti/drivers/Board.h>
    
    #define TASKSTACKSIZE 512
    
    Void task1Fxn(UArg arg0, UArg arg1);
    Void task2Fxn(UArg arg0, UArg arg1);
    
    Int resource = 0;
    Int finishCount = 0;
    UInt32 sleepTickCount;
    UInt32 sleepTickCount1;
    Task_Struct task1Struct, task2Struct;
    Char task1Stack[TASKSTACKSIZE], task2Stack[TASKSTACKSIZE];
    Semaphore_Struct semStruct;
    Semaphore_Handle semHandle;
    
    /*
    * ======== main ========
    */
    int main()
    {
    /* Construct BIOS objects */
    Task_Params taskParams;
    Semaphore_Params semParams;
    
    /* Call driver init functions */
    Board_init();
    
    /* Construct writer/reader Task threads */
    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task1Stack;
    taskParams.priority = 1;
    Task_construct(&task1Struct, (Task_FuncPtr)task1Fxn, &taskParams, NULL);
    
    taskParams.stack = &task2Stack;
    taskParams.priority = 2;
    Task_construct(&task2Struct, (Task_FuncPtr)task2Fxn, &taskParams, NULL);
    
    /* Construct a Semaphore object to be use as a resource lock, inital count 1 */
    Semaphore_Params_init(&semParams);
    Semaphore_construct(&semStruct, 1, &semParams);
    
    /* Obtain instance handle */
    semHandle = Semaphore_handle(&semStruct);
    
    /* We want to sleep for 10000 microseconds */
    sleepTickCount = 10000 / Clock_tickPeriod;
    
    BIOS_start(); /* Does not return */
    return(0);
    }
    
    /*
    * ======== task1Fxn ========
    */
    Void task1Fxn(UArg arg0, UArg arg1)
    {
    UInt32 time;
    
    for (;;) {
    System_printf("Running task1 function\n");
    char input;
    const char echoPrompt[] = "Echoing characters:\r\n";
    UART_Handle uart;
    UART_Params uartParams;
    
    /* Call driver init functions */
    GPIO_init();
    UART_init();
    
    /* Configure the LED pin */
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
    /* Turn on user LED */
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    
    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.baudRate = 115200;
    
    uart = UART_open(CONFIG_UART_0, &uartParams);
    
    if (uart == NULL) {
    /* UART_open() failed */
    while (1);
    }
    
    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
    /* Loop forever echoing */
    while (1) {
    UART_read(uart, &input, 1);
    UART_write(uart, &input, 1);
    }
    if (Semaphore_getCount(semHandle) == 0) {
    System_printf("Sem blocked in task1\n");
    }
    
    /* Get access to resource */
    Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
    
    /* Do work by waiting for 2 system ticks to pass */
    time = Clock_getTicks();
    while (Clock_getTicks() <= (time + 1)) {
    ;
    }
    
    /* Do work on locked resource */
    resource += 1;
    /* Unlock resource */
    
    Semaphore_post(semHandle);
    
    Task_sleep(sleepTickCount);
    }
    }
    
    /*
    * ======== task2Fxn ========
    */
    Void task2Fxn(UArg arg0, UArg arg1)
    {
    for (;;) {
    System_printf("Running task2 function\n");
    
    SDFatFS_Handle sdfatfsHandle;
    
    /* Variables for the CIO functions */
    FILE *src, *dst;
    
    /* Variables to keep track of the file copy progress */
    unsigned int bytesRead = 0;
    unsigned int bytesWritten = 0;
    unsigned int filesize;
    unsigned int totalBytesCopied = 0;
    
    /* Return variables */
    int result;
    
    /* Call driver init functions */
    GPIO_init();
    Display_init();
    SDFatFS_init();
    
    /* Configure the LED pin */
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
    /* add_device() should be called once and is used for all media types */
    add_device(fatfsPrefix, _MSA, ffcio_open, ffcio_close, ffcio_read,
    ffcio_write, ffcio_lseek, ffcio_unlink, ffcio_rename);
    
    /* Open the display for output */
    display = Display_open(Display_Type_UART, NULL);
    if (display == NULL) {
    /* Failed to open display driver */
    while (1);
    }
    
    /* Initialize real-time clock */
    clock_settime(CLOCK_REALTIME, &ts);
    
    /* Turn on user LED */
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    
    Display_printf(display, 0, 0, "Starting the fatsd example\n");
    Display_printf(display, 0, 0,
    "This example requires a FAT filesystem on the SD card.\n");
    Display_printf(display, 0, 0,
    "You will get errors if your SD card is not formatted with a filesystem.\n");
    
    /* Mount and register the SD Card */
    sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM);
    if (sdfatfsHandle == NULL) {
    Display_printf(display, 0, 0, "Error starting the SD card\n");
    while (1);
    }
    else {
    Display_printf(display, 0, 0, "Drive %u is mounted\n", DRIVE_NUM);
    }
    
    /* Try to open the source file */
    src = fopen(inputfile, "r");
    if (!src) {
    Display_printf(display, 0, 0, "Creating a new file \"%s\"...",
    inputfile);
    
    /* Open file for both reading and writing */
    src = fopen(inputfile, "w+");
    if (!src) {
    Display_printf(display, 0, 0,
    "Error: \"%s\" could not be created.\nPlease check the "
    "Board.html if additional jumpers are necessary.\n",
    inputfile);
    Display_printf(display, 0, 0, "Aborting...\n");
    while (1);
    }
    
    fwrite(textarray, 1, strlen(textarray), src);
    fflush(src);
    
    /* Reset the internal file pointer */
    rewind(src);
    
    Display_printf(display, 0, 0, "done\n");
    }
    else {
    Display_printf(display, 0, 0, "Using existing copy of \"%s\"\n",
    inputfile);
    }
    
    /* Create a new file object for the file copy */
    dst = fopen(outputfile, "w");
    if (!dst) {
    Display_printf(display, 0, 0, "Error opening \"%s\"\n", outputfile);
    Display_printf(display, 0, 0, "Aborting...\n");
    while (1);
    }
    else {
    Display_printf(display, 0, 0, "Starting file copy\n");
    }
    
    /*
    * Optional call to disable internal buffering. This allows FatFs to use
    * multi-block writes to increase throughput if applicable. Note that this
    * may come with a performance penalty for smaller writes.
    */
    result = setvbuf(dst, NULL, _IONBF, 0);
    if (result != 0) {
    Display_printf(display, 0, 0, "Call to setvbuf failed!");
    }
    
    /* Copy the contents from the src to the dst */
    while (true) {
    /* Read from source file */
    bytesRead = fread(cpy_buff, 1, CPY_BUFF_SIZE, src);
    if (bytesRead == 0) {
    break; /* Error or EOF */
    }
    
    /* Write to dst file */
    bytesWritten = fwrite(cpy_buff, 1, bytesRead, dst);
    if (bytesWritten < bytesRead) {
    Display_printf(display, 0, 0, "Disk Full\n");
    break; /* Error or Disk Full */
    }
    
    /* Update the total number of bytes copied */
    totalBytesCopied += bytesWritten;
    }
    
    fflush(dst);
    
    /* Get the filesize of the source file */
    fseek(src, 0, SEEK_END);
    filesize = ftell(src);
    rewind(src);
    
    /* Close both inputfile[] and outputfile[] */
    fclose(src);
    fclose(dst);
    
    Display_printf(display, 0, 0,
    "File \"%s\" (%u B) copied to \"%s\" (Wrote %u B)\n",
    inputfile, filesize, outputfile, totalBytesCopied);
    
    /* Now output the outputfile[] contents onto the console */
    dst = fopen(outputfile, "r");
    if (!dst) {
    Display_printf(display, 0, 0, "Error opening \"%s\"\n", outputfile);
    Display_printf(display, 0, 0, "Aborting...\n");
    while (1);
    }
    
    /* Print file contents */
    while (true) {
    /* Read from output file */
    bytesRead = fread(cpy_buff, 1, CPY_BUFF_SIZE, dst);
    if (bytesRead == 0) {
    break; /* Error or EOF */
    }
    cpy_buff[bytesRead] = '\0';
    /* Write output */
    Display_printf(display, 0, 0, "%s", cpy_buff);
    }
    
    /* Close the file */
    fclose(dst);
    
    /* Stopping the SDCard */
    SDFatFS_close(sdfatfsHandle);
    Display_printf(display, 0, 0, "Drive %u unmounted\n", DRIVE_NUM);
    
    return (NULL);
    if (Semaphore_getCount(semHandle) == 0) {
    System_printf("Sem blocked in task2\n");
    }
    
    /* Get access to resource */
    Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
    
    /* Do work on locked resource */
    resource += 1;
    /* Unlock resource */
    
    Semaphore_post(semHandle);
    
    Task_sleep(sleepTickCount);
    
    finishCount++;
    if (finishCount == 10) {
    System_printf("Calling BIOS_exit from task2\n");
    BIOS_exit(0);
    }
    }
    }
    int32_t fatfs_getFatTime(void)
    {
    time_t seconds;
    uint32_t fatTime;
    struct tm *pTime;
    
    /*
    * TI time() returns seconds elapsed since 1900, while other tools
    * return seconds from 1970. However, both TI and GNU localtime()
    * sets tm tm_year to number of years since 1900.
    */
    seconds = time(NULL);
    
    pTime = localtime(&seconds);
    
    /*
    * localtime() sets pTime->tm_year to number of years
    * since 1900, so subtract 80 from tm_year to get FAT time
    * offset from 1980.
    */
    fatTime = ((uint32_t)(pTime->tm_year - 80) << 25) |
    ((uint32_t)(pTime->tm_mon) << 21) |
    ((uint32_t)(pTime->tm_mday) << 16) |
    ((uint32_t)(pTime->tm_hour) << 11) |
    ((uint32_t)(pTime->tm_min) << 5) |
    ((uint32_t)(pTime->tm_sec) >> 1);
    
    return ((int32_t)fatTime);
    }

    EDIT: I attached the code provided in a separate file. -Ammar

  • Hey Shivam,

    Please use the Syntaxhighlighter tool when sharing code, it makes it much more easily readable for everyone viewing this forum. You can also consider uploading the code as a separate attachment. This again, will help the readability of the forums.

    SHIVAM TRIVEDI said:
    "../mutex.c", line 310: error #20: identifier "CONFIG_SDFatFS_0" is undefined  // sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM);

    This define is generated by the SysConfig tool in the provided example project. Since you are merging projects, I would right click on the .syscfg file in the fatsd project and open it as a text file. Then, copy over the relevant SD section and paste it into the target project's .syscfg file. This will ensure SysConfig generates the necessary files/defines with the SD module.

  • Thanks Ammar for your suggestions, when i am using the code in file you attached above i am still getting error - statement not reachable for " if (Semaphore_getCount(semHandle) == 0) " statement. 
    How can i remove this error, am i right with my approach of merging the two codes of fatsd and uartecho for receiving data from atmega328 via uart and store the incoming data into an SD card.
    Let me know how to switch between two tasks that is recieve the incoming data and simulatneously store it and loop back.

    Thanks in advance.

  • As suggested by you when i am adding the code from fatsd sysconfig for SD section in the sysconfig of mutex example code i am still getting errors below:

    SyntaxError: Identifier 'SD' has already been declared
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:23:95910
    at Object.o [as contextify] (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:23:95960)
    at n.each.e (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:33:336644)
    at Wt (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:9:5239)
    at Function.zs (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:9:40286)
    at Object.t.runScript (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:33:336616)
    at <anonymous>

    Also the sysconfig of fatsd has declarations with "var" keyword whereas sysconfig of mutex example code has declarations with "const" keyword. 

  • As suggested by you when i am adding the code from fatsd sysconfig for SD section in the sysconfig of mutex example code i am still getting errors below:

    SyntaxError: Identifier 'SD' has already been declared
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:23:95910
    at Object.o [as contextify] (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:23:95960)
    at n.each.e (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:33:336644)
    at Wt (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:9:5239)
    at Function.zs (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:9:40286)
    at Object.t.runScript (C:\ti\ccs1011\ccs\utils\sysconfig_1.6.0\dist\cli.js:33:336616)
    at <anonymous>

    Also the sysconfig of fatsd has declarations with "var" keyword whereas sysconfig of mutex example code has declarations with "const" keyword. 

  • Hey Shivam,

    We can change this using the SysConfig GUI editor instead too. Revert back to your original .syscfg on the UART example and open using the SysConfig editor.

    On the left, under TI Drivers, select the + button next to SD. This will add the SD driver as it's used in the fatsd example (although you will have to ensure your pin numbers are mapped accordingly, and modify to your setup). Once changed, you can compare the generated ti_drivers_config.c file to inspect the changes. You'll notice what was once CONFIG_SDFatFS_0 in the fatsd project, is now CONFIG_SD_0. You can either rename any calls in your code to this new name, or rename it in SysConfig so that it generates the name that matches the fatsd project (see the "Name" field in the sysconfig GUI).

    statement not reachable for " if (Semaphore_getCount(semHandle) == 0) " statement.

    To comment on the above error, you will have to inspect your code and cleanup where necessary. You will find that a while(1) { } statement was inserted before this line. The compiler is warning you that the statement is not reachable because the code will not escape the while(1) once entered.

    For reference, there is some training material using our SimpleLink Academy modules: link here.

  • Thanks Ammar, 
    The issue of CONFIG_SDFatFS_0 is solved, but there is a new error i am facing that is mentioned below:

    #include "ti_drivers_config.h"

    Description Resource Path Location Type
    #1965 cannot open source file "ti_drivers_config.h" mutex.c /mutex_CC2652RB_LAUNCHXL_tirtos_ccs line 76 C/C++ Problem

    How can i remove this error?

  • Hey Shivam,

    This file should be generated by sysConfig, and is located in the output directory folder when you build. Can you see the generated filed in your project?

  • Thanks Ammar , now i am getting the following error:

    <Linking>
     
     undefined        first referenced                                                                                    
      symbol              in file                                                                                         
     ---------        ----------------                                                                                    
     clock_settime    ./mutex.obj                                                                                         
     fatfs_getFatTime C:/ti/simplelink_cc13x2_26x2_sdk_4_20_01_04/source/third_party/fatfs/lib/ccs/m4f/fatfs.a<diskio.obj>
     
    error #10234-D: unresolved symbols remain
    error #10010: errors encountered during linking; "mutex_CC2652RB_LAUNCHXL_tirtos_ccs.out" not built
     
    >> Compilation failure
    makefile:151: recipe for target 'mutex_CC2652RB_LAUNCHXL_tirtos_ccs.out' failed
    gmake[1]: *** [mutex_CC2652RB_LAUNCHXL_tirtos_ccs.out] Error 1
    makefile:147: recipe for target 'all' failed
    gmake: *** [all] Error 2
    
    **** Build Finished ****
    

  • Please go to Project Settings> Build> Arm Linker > File Search Path on the fatsd project and verify that fatfs.a file is included in the project. Usually, unresolved symbols are due to a missing linker include path for the modules listed.

  • Okay i will check but this error is coming in mutex code where i have put uart echo code and fatsd code in two tasks.
    Are you saying that i have to verify the fatfs.a file from fatsd code and put it in corresponding mutex code?

    Thanks,

    shivam

  • I have verified both the fatsd and mutex code , i am also attaching the snapshot for them. As you can see that in both the images there is only one extra file in fatsd i.e. generated libraries that is 3rd last. shall i include this one or it auto generates? 
    Now i have manually added the generated file into the file search path but still error is coming up for unresolved symbols.

    Please check.

  • Hey Shivam,

    I'm sorry you're having trouble here. There may be some issue with your project as the linker is not pulling in the library as necessary. You can try to Rebuild the project or start from a clean workspace.

    Here's a helpful guide on TI RTOS that will help you moving forward: https://dev.ti.com/tirex/explore/node?node=AJ5GKtlWu9o0mNaNx6ItPQ__pTTHBmu__LATEST 

  • Hi ammar its working fine now. I have used the attached code and the unresolved error are solved and there are no complilation errors.

    But i am unable to see the output or the code doesnot work logically as expected. Ideally the mutex code shows Running Task1 function & Running Task2 function. But now it is not showing those statement. What doe you think can be a possible reason.

    Please help me on this.

    Thanks,
    Shivam

    #include <file.h>
    #include <stdbool.h>
    #include <stddef.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <third_party/fatfs/ffcio.h>
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>
    #include <ti/drivers/SDFatFS.h>
    /* Driver configuration */
    #include "ti_drivers_config.h"
    /* Driver configuration */
    #include "ti_drivers_config.h"
    /* String conversion macro */
    #define STR_(n)             #n
    #define STR(n)              STR_(n)
    
    /* Drive number used for FatFs */
    #define DRIVE_NUM           0
    
    const char inputfile[] = "fat:"STR(DRIVE_NUM)":input.txt";
    const char outputfile[] = "fat:"STR(DRIVE_NUM)":output.txt";
    char textarray[] = "Hello from shivam";
    
    char fatfsPrefix[] = "fat";
    
    /* XDC module Headers */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    
    /* BIOS module Headers */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>
    
    #include <ti/drivers/Board.h>
    
    #define TASKSTACKSIZE   512
    
    Void task1Fxn(UArg arg0, UArg arg1);
    Void task2Fxn(UArg arg0, UArg arg1);
    
    Int resource = 0;
    Int finishCount = 0;
    UInt32 sleepTickCount;
    
    Task_Struct task1Struct, task2Struct;
    Char task1Stack[TASKSTACKSIZE], task2Stack[TASKSTACKSIZE];
    Semaphore_Struct semStruct;
    Semaphore_Handle semHandle;
    
    /*
     *  ======== main ========
     */
    int main()
    {
        /* Construct BIOS objects */
        Task_Params taskParams;
        Semaphore_Params semParams;
    
        /* Call driver init functions */
        Board_init();
    
        /* Construct writer/reader Task threads */
        Task_Params_init(&taskParams);
        taskParams.stackSize = TASKSTACKSIZE;
        taskParams.stack = &task1Stack;
        taskParams.priority = 1;
        Task_construct(&task1Struct, (Task_FuncPtr)task1Fxn, &taskParams, NULL);
    
        taskParams.stack = &task2Stack;
        taskParams.priority = 2;
        Task_construct(&task2Struct, (Task_FuncPtr)task2Fxn, &taskParams, NULL);
    
        /* Construct a Semaphore object to be use as a resource lock, inital count 1 */
        Semaphore_Params_init(&semParams);
        Semaphore_construct(&semStruct, 1, &semParams);
    
        /* Obtain instance handle */
        semHandle = Semaphore_handle(&semStruct);
    
        /* We want to sleep for 10000 microseconds */
        sleepTickCount = 10000 / Clock_tickPeriod;
    
        BIOS_start();    /* Does not return */
        return(0);
    }
    
    /*
     *  ======== task1Fxn ========
     */
    Void task1Fxn(UArg arg0, UArg arg1)
    {
        UInt32 time;
        UART_Handle handle;
        UART_Params params;
        char rxBuf;         // Receive buffer
        GPIO_init();
        UART_init();
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
        for (;;) {
            System_printf("Running task1 function\n");
            UART_Params_init(&params);
                        params.baudRate      = 115200;
                        params.writeDataMode = UART_DATA_BINARY;
                        // Open the UART and do the read
                        handle = UART_open(CONFIG_UART_0, &params);
                        if (handle == NULL) {
                               /* UART_open() failed */
                               while (1);
                           }
                           /* Turn on user LED to indicate successful initialization */
                        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
                           while(rxBuf!='\n')
                           {
    
                               UART_read(handle, &rxBuf, 1);
    
                               UART_write(handle, &rxBuf, 1);
                               System_printf(&rxBuf);
                           }
    
            if (Semaphore_getCount(semHandle) == 0) {
                System_printf("Sem blocked in task1\n");
            }
    
            /* Get access to resource */
            Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
    
            /* Do work by waiting for 2 system ticks to pass */
            time = Clock_getTicks();
            while (Clock_getTicks() <= (time + 1)) {
                ;
            }
    
            /* Do work on locked resource */
            resource += 1;
            /* Unlock resource */
    
            Semaphore_post(semHandle);
    
            Task_sleep(sleepTickCount);
        }
    }
    
    /*
     *  ======== task2Fxn ========
     */
    Void task2Fxn(UArg arg0, UArg arg1)
    {
        SDFatFS_Handle sdfatfsHandle;
        FILE *src;
        SDFatFS_init();
        add_device(fatfsPrefix, _MSA, ffcio_open, ffcio_close, ffcio_read,
                    ffcio_write, ffcio_lseek, ffcio_unlink, ffcio_rename);
        for (;;) {
            System_printf("Running task2 function\n");
            sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM);
                               src = fopen(inputfile, "r");
                                  if (!src) {
                                      /* Open file for both reading and writing */
                                      src = fopen(inputfile, "w+");
                                      if (!src) {
                                          while (1);
                                      }
                               fwrite(textarray, 1, strlen(textarray), src);
                               fclose(src);
                               SDFatFS_close(sdfatfsHandle);
                                  }
    
            if (Semaphore_getCount(semHandle) == 0) {
                System_printf("Sem blocked in task2\n");
            }
    
            /* Get access to resource */
            Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
    
            /* Do work on locked resource */
            resource += 1;
            /* Unlock resource */
    
            Semaphore_post(semHandle);
    
            Task_sleep(sleepTickCount);
    
            finishCount++;
            if (finishCount == 5) {
                System_printf("Calling BIOS_exit from task2\n");
                BIOS_exit(0);
            }
        }
    }
    int32_t fatfs_getFatTime(void)
    {
        /*
         *  FatFs uses this API to get the current time in FatTime format.  User's
         *  must implement this function based on their system's timekeeping
         *  mechanism.  See FatFs documentation for details on FatTime format.
         */
        /* Jan 1 2017 00:00:00 */
        return (0x4A210000);
    }
    
    
    

  • Hey Shivam,

    I see you're using System_printf() to print to the Console. Take a look at this related post for use of System_printf(): https://e2e.ti.com/support/legacy_forums/embedded/starterware/f/790/p/625906/2307484#2307484

     Additionally, you'll have to make use of the debugger to investigate any potential issues with the code you run. Here's a general training on TI RTOS: https://training.ti.com/getting-started-ti-rtos-training-series . This is in addition to the previous link provided to our Simplelink Academy modules.

  • Part Number: LP-CC2652RB

    Tool/software: Code Composer Studio

    Hi i am trying to run recieve UART data from another microcontroller to CC2652 and write it to sd card attached to CC2652. For starting point i am trying to read uart data and write a dummy text to SD card not the incoming uart data. However i am not able to do this operation as well and the code gets stuck in the fwrite statement in the code attached below.

    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
           while(1)
           {
    
               UART_read(handle, &rxBuf, 1);
    
               //UART_write(handle, &rxBuf, 1);
               /* Mount and register the SD Card */
                       sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM);
    
                       src = fopen(inputfile, "w+");
    
                       fwrite(textarray, 1, strlen(textarray), src); // The code is getting stuck over here.
                       GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF);
                       fflush(src);
                       rewind(src);
                       fclose(src);
                       SDFatFS_close(sdfatfsHandle);
    
    
           }

    Please tell me how i can remove this problem and get the code working. 

    Thanks in advance,

    Shivam

  • Hey Shivam,

    I've assigned an expert to comment. What SDK version are you using?

  • Part Number: LP-CC2652RB

    Tool/software: Code Composer Studio

    Hi,

    I am trying to use the mutex example code with two tasks. In this i have used uartecho code in one task function and fatsd code in another task function. But the merged code is not working.
    Please tell how i can make it work. I am attaching the code i am have made after merging.
    I am expecting to receive uart data from another microcontroller attached to CC2652 when task 1 function runs. When the 2nd task runs, i am expecting to save a dummy text in SD card.

    #include <file.h>
    #include <stdbool.h>
    #include <stddef.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <third_party/fatfs/ffcio.h>
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>
    #include <ti/drivers/SDFatFS.h>
    /* Driver configuration */
    #include "ti_drivers_config.h"
    /* Driver configuration */
    #include "ti_drivers_config.h"
    /* String conversion macro */
    #define STR_(n)             #n
    #define STR(n)              STR_(n)
    
    /* Drive number used for FatFs */
    #define DRIVE_NUM           0
    
    const char inputfile[] = "fat:"STR(DRIVE_NUM)":input.txt";
    const char outputfile[] = "fat:"STR(DRIVE_NUM)":output.txt";
    char textarray[] = "Hello from shivam";
    
    char fatfsPrefix[] = "fat";
    
    /* XDC module Headers */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    
    /* BIOS module Headers */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>
    
    #include <ti/drivers/Board.h>
    
    #define TASKSTACKSIZE   512
    
    Void task1Fxn(UArg arg0, UArg arg1);
    Void task2Fxn(UArg arg0, UArg arg1);
    
    Int resource = 0;
    Int finishCount = 0;
    UInt32 sleepTickCount;
    
    Task_Struct task1Struct, task2Struct;
    Char task1Stack[TASKSTACKSIZE], task2Stack[TASKSTACKSIZE];
    Semaphore_Struct semStruct;
    Semaphore_Handle semHandle;
    
    /*
     *  ======== main ========
     */
    int main()
    {
        /* Construct BIOS objects */
        Task_Params taskParams;
        Semaphore_Params semParams;
    
        /* Call driver init functions */
        Board_init();
    
        /* Construct writer/reader Task threads */
        Task_Params_init(&taskParams);
        taskParams.stackSize = TASKSTACKSIZE;
        taskParams.stack = &task1Stack;
        taskParams.priority = 1;
        Task_construct(&task1Struct, (Task_FuncPtr)task1Fxn, &taskParams, NULL);
    
        taskParams.stack = &task2Stack;
        taskParams.priority = 2;
        Task_construct(&task2Struct, (Task_FuncPtr)task2Fxn, &taskParams, NULL);
    
        /* Construct a Semaphore object to be use as a resource lock, inital count 1 */
        Semaphore_Params_init(&semParams);
        Semaphore_construct(&semStruct, 1, &semParams);
    
        /* Obtain instance handle */
        semHandle = Semaphore_handle(&semStruct);
    
        /* We want to sleep for 10000 microseconds */
        sleepTickCount = 10000 / Clock_tickPeriod;
    
        BIOS_start();    /* Does not return */
        return(0);
    }
    
    /*
     *  ======== task1Fxn ========
     */
    Void task1Fxn(UArg arg0, UArg arg1)
    {
        UInt32 time;
        UART_Handle handle;
        UART_Params params;
        char rxBuf;         // Receive buffer
        GPIO_init();
        UART_init();
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
        for (;;) {
            System_printf("Running task1 function\n");
            UART_Params_init(&params);
                        params.baudRate      = 115200;
                        params.writeDataMode = UART_DATA_BINARY;
                        // Open the UART and do the read
                        handle = UART_open(CONFIG_UART_0, &params);
                        if (handle == NULL) {
                               /* UART_open() failed */
                               while (1);
                           }
                           /* Turn on user LED to indicate successful initialization */
                        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
                           while(rxBuf!='\n')
                           {
    
                               UART_read(handle, &rxBuf, 1);
    
                               UART_write(handle, &rxBuf, 1);
                               System_printf(&rxBuf);
                           }
    
            if (Semaphore_getCount(semHandle) == 0) {
                System_printf("Sem blocked in task1\n");
            }
    
            /* Get access to resource */
            Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
    
            /* Do work by waiting for 2 system ticks to pass */
            time = Clock_getTicks();
            while (Clock_getTicks() <= (time + 1)) {
                ;
            }
    
            /* Do work on locked resource */
            resource += 1;
            /* Unlock resource */
    
            Semaphore_post(semHandle);
    
            Task_sleep(sleepTickCount);
        }
    }
    
    /*
     *  ======== task2Fxn ========
     */
    Void task2Fxn(UArg arg0, UArg arg1)
    {
        SDFatFS_Handle sdfatfsHandle;
        FILE *src;
        SDFatFS_init();
        add_device(fatfsPrefix, _MSA, ffcio_open, ffcio_close, ffcio_read,
                    ffcio_write, ffcio_lseek, ffcio_unlink, ffcio_rename);
        for (;;) {
            System_printf("Running task2 function\n");
            sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM);
                               src = fopen(inputfile, "r");
                                  if (!src) {
                                      /* Open file for both reading and writing */
                                      src = fopen(inputfile, "w+");
                                      if (!src) {
                                          while (1);
                                      }
                               fwrite(textarray, 1, strlen(textarray), src);
                               fclose(src);
                               SDFatFS_close(sdfatfsHandle);
                                  }
    
            if (Semaphore_getCount(semHandle) == 0) {
                System_printf("Sem blocked in task2\n");
            }
    
            /* Get access to resource */
            Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
    
            /* Do work on locked resource */
            resource += 1;
            /* Unlock resource */
    
            Semaphore_post(semHandle);
    
            Task_sleep(sleepTickCount);
    
            finishCount++;
            if (finishCount == 5) {
                System_printf("Calling BIOS_exit from task2\n");
                BIOS_exit(0);
            }
        }
    }
    int32_t fatfs_getFatTime(void)
    {
        /*
         *  FatFs uses this API to get the current time in FatTime format.  User's
         *  must implement this function based on their system's timekeeping
         *  mechanism.  See FatFs documentation for details on FatTime format.
         */
        /* Jan 1 2017 00:00:00 */
        return (0x4A210000);
    }
    
    
    

    Thanks,

    shivam 

  • Hi Shivam,

    I'm sorry to hear that this didn't work for you. However, you are going to need to provide a bit more information than "it's not working". Can you debug and step through your code and see where it is failing or what behavior that you are looking for and not seeing?

    In the future, it would be best if you would do some debugging on your side before posting. This will ensure that you have the information that we need to help answer your question, and you may even find the answer yourself along the way.

    Best Regards,
    Alec

  • Hey Ammar, Thanks for your help. I am using version 4.30.00.54 of the SDK.

    Further to inform you that the code is getting stuck in UART_read() not in fwrite statement. Let me know what i need to do implement UART_read() in non blocking mode. 

    UART_Handle handle;
    UART_Params params;
    
    UART_Params_init (&params);
    params.baudrate = 115200;
    params.writeDataMode = UART_DATA_TEXT;
    params.readDataMode = UART_DATA_TEXT;
    params.readReturnMode = UART_RETURN_NewLine;
    handle = UART_open(someUART_configIndexValue, &params);

    Is there anything else i need to do apart from passing these parameters to the UART_callback?

  • Hi Shivam,

    Please refer to the following example: https://dev.ti.com/tirex/explore/node?node=AIn8Ns14w6iC4y0OWsuykQ__pTTHBmu__LATEST

    This example utilizes nonblocking UART read. This examples is made to use UART2, however, you can apply the same changes for UART. Reference how UART is initialized within the mainThread in the file uart2callback.c.

    Best Regards,

    Jenny

  • Thanks for the link. I will try to implement it and get back. But it is strange that i am not able to implement a simple application with TI which i did with arduino in a couple of days. The kind of support from the TI for their application codes is also not satisfactory.
    Further is it possible to merge the fatsd code into this example? Will i have to take the TI-RTOS fatsd code or NORTOS code for fatsd?

  • But it is strange that i am not able to implement a simple application with TI which i did with arduino in a couple of days. The kind of support from the TI for their application codes is also not satisfactory.

  • But it is strange that i am not able to implement a simple application with TI which i did with arduino in a couple of days. The kind of support from the TI for their application codes is also not satisfactory.

  • But it is strange that i am not able to implement a simple application with TI which i did with arduino in a couple of days. The kind of support from the TI for their application codes is also not satisfactory.

  • Hi Shivam,

    I am closing this thread since it is a duplicate of other open posts of yours. I will post a response on the thread linked below.

    https://e2e.ti.com/support/wireless-connectivity/bluetooth/f/538/t/945251


    Best Regards,
    Alec

  • Hi Shivam,

    I am closing this thread since it is a duplicate of other open posts of yours. I will post a response on the thread linked below.

    https://e2e.ti.com/support/wireless-connectivity/bluetooth/f/538/t/945251


    Best Regards,
    Alec

  • Yes sure, you can close the thread. But i can't see your response.

  • Yes sure, you can close the thread. But i can't see your response.

  • I remember I had help you about the same topic at this post. I can integrate fatsd and uart2callback example to write a input string to SD card using CC2652RB_LAUNCHXLwithout problem. This is about application code and I suppose you can do this easily by yourself.

    Basically, the steps are:

    1. Use fatsd example as base.

    2. Add uart thread into fatsd example.

    3. Use semaphore to control posting message received in uart thread to fatsd thread to write into fatsd.

    Hope this helps.

  • Already try to help you in . It won't help to create countless post for the same issue.

  • Already try to help you in . It won't help to create countless post for the same issue.

  • Thanks, but it didnt solve the problem then. Anyways now i am able to write a dummy input string to the SD card and receive a single character from UART and the program gets stuck. I want to continously receive the uart data and write into it.

    Can you share your code if you are able to do it? Take a look at my code below:

    #include <file.h>
    #include <stdbool.h>
    #include <stddef.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>

    /* POSIX Header files */
    #include <pthread.h>
    #include <semaphore.h>
    #include <third_party/fatfs/ffcio.h>

    //#include <ti/display/Display.h>
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/SDFatFS.h>
    #include <ti/drivers/UART2.h>
    /* XDC module Headers */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    /* Driver configuration */
    #include "ti_drivers_config.h"
    static sem_t sem;
    static volatile size_t numBytesRead;
    /* Buffer size used for the file copy process */
    #ifndef CPY_BUFF_SIZE
    #define CPY_BUFF_SIZE 2048
    #endif

    /* String conversion macro */
    #define STR_(n) #n
    #define STR(n) STR_(n)

    /* Drive number used for FatFs */
    #define DRIVE_NUM 0

    const char inputfile[] = "fat:"STR(DRIVE_NUM)":input.txt";
    const char outputfile[] = "fat:"STR(DRIVE_NUM)":output.txt";

    const char textarray[] ="Hello from shivam";

    //static Display_Handle display;

    /* Set this to the current UNIX time in seconds */
    const struct timespec ts = {
    .tv_sec = 1469647026,
    .tv_nsec = 0
    };

    /* File name prefix for this filesystem for use with TI C RTS */
    char fatfsPrefix[] = "fat";

    unsigned char cpy_buff[CPY_BUFF_SIZE];
    /*
    * ======== callbackFxn ========
    */
    void callbackFxn(UART2_Handle handle, void *buffer, size_t count,
    void *userArg, int_fast16_t status)
    {
    if (status != UART2_STATUS_SUCCESS) {
    /* RX error occured in UART2_read() */
    while (1);
    }

    numBytesRead = count;
    sem_post(&sem);
    }


    /*
    * ======== mainThread ========
    * Thread to perform a file copy
    *
    * Thread tries to open an existing file inputfile[]. If the file doesn't
    * exist, create one and write some known content into it.
    * The contents of the inputfile[] are then copied to an output file
    * outputfile[]. Once completed, the contents of the output file are
    * printed onto the system console (stdout).
    */
    void *mainThread(void *arg0)
    {
    char input;
    const char echoPrompt[] = "Echoing characters:\r\n";
    UART2_Handle handle;
    UART2_Params uartParams;
    int32_t semStatus;
    uint32_t status = UART2_STATUS_SUCCESS;
    SDFatFS_Handle sdfatfsHandle;
    /* Create semaphore */
    semStatus = sem_init(&sem, 0, 0);

    if (semStatus != 0) {
    /* Error creating semaphore */
    while (1);
    }

    /* Create a UART in CALLBACK read mode */
    UART2_Params_init(&uartParams);
    uartParams.readMode = UART2_Mode_CALLBACK;
    uartParams.readCallback = callbackFxn;
    uartParams.baudRate = 115200;

    handle = UART2_open(CONFIG_UART2_0, &uartParams);

    if (handle == NULL) {
    /* UART2_open() failed */
    while (1);
    }

    /* Turn on user LED to indicate successful initialization */
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

    /* Pass NULL for bytesWritten since it's not used in this example */
    UART2_write(handle, echoPrompt, sizeof(echoPrompt), NULL);

    /* Loop forever echoing */
    while (1) {
    numBytesRead = 0;

    /* Pass NULL for bytesRead since it's not used in this example */
    status = UART2_read(handle, &input, 1, NULL);

    if (status != UART2_STATUS_SUCCESS) {
    /* UART2_read() failed */
    while (1);

    }

    /* Do not write until read callback executes */
    sem_wait(&sem);

    if (numBytesRead > 0) {
    status = UART2_write(handle, &input, 1, NULL);
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    /* Variables for the CIO functions */
    FILE *src;
    /* Call driver init functions */
    GPIO_init();

    SDFatFS_init();

    /* Configure the LED pin */
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    /* add_device() should be called once and is used for all media types */
    add_device(fatfsPrefix, _MSA, ffcio_open, ffcio_close, ffcio_read,
    ffcio_write, ffcio_lseek, ffcio_unlink, ffcio_rename);

    /* Open the display for output */
    //display = Display_open(Display_Type_UART, NULL);
    //if (display == NULL) {
    /* Failed to open display driver */
    // while (1);
    //}

    /* Initialize real-time clock */
    clock_settime(CLOCK_REALTIME, &ts);

    /* Turn on user LED */
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

    //Display_printf(display, 0, 0, "Starting the fatsd example\n");
    //Display_printf(display, 0, 0,
    // "This example requires a FAT filesystem on the SD card.\n");
    //Display_printf(display, 0, 0,
    //"You will get errors if your SD card is not formatted with a filesystem.\n");

    /* Mount and register the SD Card */
    sdfatfsHandle = SDFatFS_open(CONFIG_SDFatFS_0, DRIVE_NUM);
    //if (sdfatfsHandle == NULL) {
    //Display_printf(display, 0, 0, "Error starting the SD card\n");
    // while (1);
    //}
    //else {
    // Display_printf(display, 0, 0, "Drive %u is mounted\n", DRIVE_NUM);
    //}

    /* Try to open the source file */
    src = fopen(inputfile, "r");
    if (!src) {
    //Display_printf(display, 0, 0, "Creating a new file \"%s\"...",
    //inputfile);

    /* Open file for both reading and writing */
    src = fopen(inputfile, "w+");
    if (!src) {
    //Display_printf(display, 0, 0,
    // "Error: \"%s\" could not be created.\nPlease check the "
    // "Board.html if additional jumpers are necessary.\n",
    // inputfile);
    //Display_printf(display, 0, 0, "Aborting...\n");
    while (1);
    }

    fwrite(textarray, 1, strlen(textarray), src);
    fflush(src);

    /* Reset the internal file pointer */
    rewind(src);

    //Display_printf(display, 0, 0, "done\n");
    }
    else {
    //Display_printf(display, 0, 0, "Using existing copy of \"%s\"\n",
    //inputfile);
    }
    /* Close inputfile[] */
    fclose(src);
    /* Stopping the SDCard */
    SDFatFS_close(sdfatfsHandle);
    //Display_printf(display, 0, 0, "Drive %u unmounted\n", DRIVE_NUM);


    if (status != UART2_STATUS_SUCCESS) {
    /* UART2_write() failed */
    while (1);
    }
    }
    return (NULL);
    }

    }

    /*
    * ======== fatfs_getFatTime ========
    */
    int32_t fatfs_getFatTime(void)
    {
    time_t seconds;
    uint32_t fatTime;
    struct tm *pTime;

    /*
    * TI time() returns seconds elapsed since 1900, while other tools
    * return seconds from 1970. However, both TI and GNU localtime()
    * sets tm tm_year to number of years since 1900.
    */
    seconds = time(NULL);

    pTime = localtime(&seconds);

    /*
    * localtime() sets pTime->tm_year to number of years
    * since 1900, so subtract 80 from tm_year to get FAT time
    * offset from 1980.
    */
    fatTime = ((uint32_t)(pTime->tm_year - 80) << 25) |
    ((uint32_t)(pTime->tm_mon) << 21) |
    ((uint32_t)(pTime->tm_mday) << 16) |
    ((uint32_t)(pTime->tm_hour) << 11) |
    ((uint32_t)(pTime->tm_min) << 5) |
    ((uint32_t)(pTime->tm_sec) >> 1);

    return ((int32_t)fatTime);
    }

  • Still the problem is not getting solved. Why will i create multiple posts if i get proper support on the forum.

  • Basically, the steps are:

    1. Use fatsd example as base.

    2. Add uart thread into fatsd example.

    3. Use semaphore to control posting message received in uart thread to fatsd thread to write into fatsd.

    I cannot help to check your code since I know it doesn't work. I am sure my steps works. Maybe you can try to implement what I described.

  • Yes i am following the steps 1 , 2 & 3 mentioned above. With these steps i am able receive only one character at a time and then again receive it after pressing reset. I am also able to write a dummy data once into the file. However i want to contiously receive the uart data and simulatneously. 
    If i dont do fopen/fwrite/fclose in uart thread then how i will be able to write the uart data into sd card.
    Please refer the code attached above else suggest a short code only for uart contious receive and write.

    Thanks,

    shivam

  • Hi Shivam,

    Sorry for the delay, we have also merged the threads rather than just leave them closed. Now, I want to address a few items. 

    Firstly, I think there may be a bit of a misconception of this product's position in the market. This is a wireless connectivity product intended for use with our wireless protocol stacks such as BLE, IEE 802.15.4, ZigBee, Thread, etc. Our wireless devices are also all intended to be used with an RTOS, which cannot be said for most Arduino products.

    Secondly, please understand that we do not ever claim that our SDK will contain a solution for every use case. The examples in our SDK are examples of how to utilize our hardware products, and we still expect our customers to have the knowledge and/or experience to understand how to modify these examples to fit their use cases.

    Lastly, please keep in mind that E2E has a rule against making duplicate posts. I understand that you may not want to spend the time waiting for responses, but please understand that many of us are answering numerous questions a day, along with other direct customer interactions and projects. If you want quick responses, you will typically get them by providing as much information as possible to help us quickly determine the root of your problem. Our goal on E2E is not to debug your code for you, but to help you understand whether an issue you are facing is a bug in our software or an issue in your implementation, and then helping to guide you to a solution. When the answer in your ORIGINAL post has been answered, we would appreciate it if you click resolved and create a new post if you have any follow-up questions that are not what is originally in the post. Asking unrelated follow-up questions in the same thread will make things much more confusing for someone who references your post in the future.

    If you have any questions or concerns, please let me know.

    Best Regards,
    Alec

  • Okay thanks for your detailed response. 
    Coming back to your products' usage is it not possible to receive uart data from another microcontroller and save it in an SD card. If you compare it with arduino, this functionality is in their examples.
    I am mentioning because support is an important factor in designing embedded systems and this is the way we learn and grow.
    Asking un-related questions is again happening because i got good response from a particular mentor, when some of them didn't answer.
    Coming back to my question, my problem is still not solved. Shall i create a different thread?

  • You cannot directly copy mainThread codes of fatsd into uartecho thread. My suggestion is to create two separate threads, one is for UART reading and another is for fatsd writing. Use semaphore wait in fatsd thread to wait semaphore post when UART thread collects some bytes to post semaphore to fatsd thread to write data. Hope my explanations help.

  • Okay thanks, i will try this. 
    Mena while can you suggest me some resource to understand how to use semaphore to switch between tasks as in the simplelink academy it is a very short explanation.

    Thanks,

    Shivam

  • There’s semaphore usage in uart2callback example which you can refer to.

  • That i know.  I was talking about reading material. Anyways Thanks!

  • Try to refer to

  • This is paid coursework. I guess you guys should have open-source support.

  • I will try this , it sound good but i have to reach that level of knowledge of using semaphore.

    However, when i am trying to debug my present code i am getting following messages on the screen. Please refer the attached images step by step with label Bios_start1, Bios_start2, Bios_start3 . The IDE is asking to change scalability settings when the debugger enters release_pem4f.c. Shall i change the settings, if yes to what.

    My final goal is to view line by line execution in mainthread function of the merged code attached above. I am not able to view line by line execution in my merged code.

    Thanks,

    Shivam

  • The material in the link is free. Why do you think you have to pay anything?

  • The material is very short for implementation. Full material is at link below:

    sso.teachable.com/.../ti-rtos-cc1352

  • Since i have stopped getting reply here. I am going to create a separate thread.

    Thanks,
    Shivam

  • What is your latest issue/question?