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/MSP432-RTOS: UART Echo within TI-RTOS not behaving as expected

Part Number: MSP432-RTOS

Tool/software: Code Composer Studio

Hello, 

I have a program built where I am trying to develop something that reads UART data and sends UART data within TI-RTOS. 

I have run the uartecho.c demo and it works fine however when I try to bring this code into my current TI-Rots program, every character I send returns FF or FE. some characters return FF FF FE. I cannot figure out the cause of this behavior. 

Below is my code for the main thread, the uarty initialization and my idle function where the echo lies. (I was trying to do this in a task and i could not get it to work before).

//***** Header Files **********************************************************
// XDC module Header Files
#include <xdc/std.h>                                                            // XDC "base types" - must be included FIRST
#include <xdc/runtime/Types.h>                                                  // XDC constants/types used in xdc.runtime pkg
#include <xdc/cfg/global.h>                                                     // For all BIOS instances created statically in RTOS .cfg file
#include <xdc/runtime/Error.h>                                                  // For error handling (e.g. Error block)
#include <xdc/runtime/System.h>                                                 // XDC System functions (e.g. System_abort(), System_printf())
#include <xdc/runtime/Log.h>

// TI-RTOS Kernel Header Files
#include <ti/sysbios/BIOS.h>                                                    // BIOS module API
#include <ti/sysbios/knl/Task.h>                                                // Task APIs
#include <ti/sysbios/knl/Semaphore.h>                                           // Semaphore APIs
#include <ti/sysbios/knl/Clock.h>                                               // Clock APIs
#include <ti/drivers/ADC.h>
#include <ti/drivers/UART.h>

// Standard C Header Files
#include <stdint.h>                                                             // Standard integer types
#include <stddef.h>                                                             // Standard variable types and macros

// Peripheral Driver Header Files
#include "ti_drivers_config.h"                                                  // Syscfg Board/Drivers Header file
#include <ti/drivers/GPIO.h>                                                    // TI GPIO Driver header file
#include "myGpio.h"                                                             // Header file for myGpio.c
#include "myTimers.h"
#include "myADC.h"
#include "myUART.h"

/*
 *  ======== main ========
 */

//***** Prototypes ************************************************************


//***** Global Variables ******************************************************
Task_Handle         sensorRead, motorActuationDecision, buttonPressed, uartRx;
Task_Params         taskParams;
Error_Block         Eb;
UART_Handle uart;
UART_Params uartParams;

//***** Main Loop *************************************************************
int main(void)
{
    Board_init();
    myGpio_init();
    myTimers_init();
    myADC_init();
    myUart_init();

    Task_Params_init(&taskParams);
    taskParams.priority=2;
    taskParams.stackSize=512;


//    uartRx = Task_create(uartRxFxn, &taskParams, Error_IGNORE);
//    S_UartRX = Semaphore_create(0, NULL, Error_IGNORE);

    BIOS_start();
}

Above is my main code. Note that myUart_init is below. 

// XDC module Header Files
#include <xdc/std.h>                                                            // XDC "base types" - must be included FIRST
#include <xdc/runtime/Types.h>                                                  // XDC constants/types used in xdc.runtime pkg
#include <xdc/cfg/global.h>                                                     // For all BIOS instances created statically in RTOS .cfg file
#include <xdc/runtime/Error.h>                                                  // For error handling (e.g. Error block)
#include <xdc/runtime/System.h>                                                 // XDC System functions (e.g. System_abort(), System_printf())
#include <xdc/runtime/Log.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"


// ***Variables********************************************************************//
extern UART_Handle uart;
extern UART_Params uartParams;
extern const char  echoPrompt[];
unsigned char rxBuffer;

void myUart_init(){
    UART_init();

    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 = 115200;

    uart = UART_open(CONFIG_UART_0, &uartParams);
    //UART_write(uart, echoPrompt, sizeof(echoPrompt)); //NOTE IF I UNCOMMENT THIS THE ENTIRE PROGRAM BREAKS.

}

Finally, my idle function code is below where the uart read and write lie. 

// XDC module Header Files
#include <xdc/std.h>                                                            // XDC "base types" - must be included FIRST
#include <xdc/runtime/Types.h>                                                  // XDC constants/types used in xdc.runtime pkg
#include <xdc/cfg/global.h>                                                     // For all BIOS instances created statically in RTOS .cfg file
#include <xdc/runtime/Error.h>                                                  // For error handling (e.g. Error block)
#include <xdc/runtime/System.h>                                                 // XDC System functions (e.g. System_abort(), System_printf())
#include <xdc/runtime/Log.h>

// TI-RTOS Kernel Header Files
#include <ti/sysbios/BIOS.h>                                                    // BIOS module API
#include <ti/drivers/UART.h>

// Standard C Header Files
#include <stdint.h>                                                             // Standard integer types
#include <stddef.h>                                                             // Standard variable types and macros

// Peripheral Driver Header Files
#include <ti/drivers/Board.h>
#include "ti_drivers_config.h"                                                  // Syscfg Board/Drivers Header file
#include <ti/drivers/GPIO.h>                                                    // TI GPIO Driver header file
#include "myGpio.h"
#include <unistd.h>

char rxUART;
extern UART_Handle uart;
extern UART_Params uartParams;
const char  echoPrompt[] = "Echoing characters:\r\n";

void myIdleFxn (void)
{
    UART_write(uart, echoPrompt, sizeof(echoPrompt)); //This does nothing! There is no data showing up on the uart. 

    while (1) {
        UART_read(uart, &rxUART, 1); //Loginfo of the rxUART here shows 127. 
        UART_write(uart, &rxUART, 1);
    }
}

Please any help would be greatly appreciated. 

  • Hi Adam,

    I would not recommend using an Idle function for transmitting on the UART. The calls can be blocking, which means the Idle task is blocked. Can you try using a lower priority task instead.

    Todd

  • Thanks Todd, 

    I have tried this but am getting the same issue. The code works perfectly when I run the example however when I create a thread it does not work. Here is my thread:

    void *uartRx(void *arg0)
    {
        char        input;
        const char  echoPrompt[] = "Echoing characters:\r\n";
        UART_Handle uart;
        UART_Params uartParams;
    
        UART_init();
    
        /* 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.readEcho = UART_ECHO_OFF;
        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);
        }
    }
    

    I call this thread with a priority higher than anything else and it does not return the value inputted. It also fails to write the echoPrompt correctly, it gives me a completely wrong value. 

  • Are you using the same UART in multiple tasks?

  • Hey Todd, 

    The UART is only being used in this task. 

    The following is an image of the input and output when I send it data. 

    and the following is a capture of the execution graph where I believe the error may be arising. It seems as though something is blocking the Uart task half way through its process. Is this normal?

  • Hey Todd, 

    The UART is only being used in this task. 

    The following is an image of the input and output when I send it data. 

    and the following is a capture of the execution graph where I believe the error may be arising. It seems as though something is blocking the Uart task half way through its process. Is this normal?

  • Another attempt to create a thread more inline with my other threads has made things worse. 

    //Main.c
    
    uartRx = Task_create(uartRxFxn, &taskParams, Error_IGNORE);
    
    //myUart.c
    
    void uartRxFxn(UArg a0, UArg a1)
    {
    
        UART_init();
    
        /* Create a UART with data processing off. */
        UART_Params_init(&uartParams);
        uartParams.writeDataMode = UART_DATA_TEXT;
        uartParams.readDataMode = UART_DATA_TEXT;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readEcho = UART_ECHO_OFF;
        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, sizeof(input));
            UART_write(uart, &input, sizeof(input));
        }
    }
    

    The following is a screenshot of how the uartRx fucntion hogs the RTOS. I am unsure as to why this would be happening. The entire thing freezes.

    EDIT : This was resolved by increasing the stack size but the issue originally stated persists. 

  • The second attempt had a different issue because of the thread stack size, when I set the stack size to 1024 the issues are identical. 

  • Solution, drop the baud rate to 9600 and switch the clock to ACLK in the SYSCFG. 

  • Adam,

    Just as a follow up here. When a large amount of data is being echo'd to this thread, it will frequently be awoken to switch between UART_read() and UART_write().

    Slowing the baudrate has allowed you to slow the frequency at which this occurs because you're receiving bytes at a slow rate and thus this thread becomes unblocked less frequently.


    Regards,
    Derrick