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.

RTOS/TM4C1294NCPDT: Multiple UART

Part Number: TM4C1294NCPDT


Tool/software: TI-RTOS

To do this correctly I need to 

/*!
 *  @def    EK_TM4C1294XL_UARTName
 *  @brief  Enum of UARTs on the EK_TM4C1294XL dev board
 */
typedef enum EK_TM4C1294XL_UARTName {
    EK_TM4C1294XL_UART0 = 0,
	EK_TM4C1294XL_UART1 = 1,
	EK_TM4C1294XL_UART2 = 2,

    EK_TM4C1294XL_UARTCOUNT
} EK_TM4C1294XL_UARTName;

and 

UARTTiva_Object uartTivaObjects[EK_TM4C1294XL_UARTCOUNT];
unsigned char uartTivaRingBuffer[EK_TM4C1294XL_UARTCOUNT][32];

/* UART configuration structure */
const UARTTiva_HWAttrs uartTivaHWAttrs[EK_TM4C1294XL_UARTCOUNT] = {
    {
        .baseAddr = UART0_BASE,
        .intNum = INT_UART0,
        .intPriority = (~0),
        .flowControl = UART_FLOWCONTROL_NONE,
        .ringBufPtr  = uartTivaRingBuffer[0],
        .ringBufSize = sizeof(uartTivaRingBuffer[0])
    }
    {
        .baseAddr = UART1_BASE,
        .intNum = INT_UART1,
        .intPriority = (~0),
        .flowControl = UART_FLOWCONTROL_NONE,
        .ringBufPtr  = uartTivaRingBuffer[0],
        .ringBufSize = sizeof(uartTivaRingBuffer[0])
    }
    {
        .baseAddr = UART2_BASE,
        .intNum = INT_UART2,
        .intPriority = (~0),
        .flowControl = UART_FLOWCONTROL_NONE,
        .ringBufPtr  = uartTivaRingBuffer[0],
        .ringBufSize = sizeof(uartTivaRingBuffer[0])
    }
};

const UART_Config UART_config[] = {
    {
        .fxnTablePtr = &UARTTiva_fxnTable,
        .object = &uartTivaObjects[0],
        .hwAttrs = &uartTivaHWAttrs[0]
    },
    {NULL, NULL, NULL}
};

I'm not sure I'm doing this right, can u provide example code to have multiple UART (independent of each other). I could not find the example code in the library to explain this (most complete hardware EK_TM4C1294XL.c/h rather than snippet version just for EVAL board). 

Thanks


  • Hi Richard,

     Sorry,  below are the few TI-RTOS examples for UART that you might have already looked at. We don't have any more examples other what is shown below. 

      However, you can take a look at how multiple instances of other modules (i.e. I2C, SSI) are being initialized for reference. For example, if you look at the I2C you will find below code. Two instances of I2C:  I2C7 and I2C8 are instantiated here. You see that two instances of the I2C are configured in the i2cTivaHWAttrs structures as well as in I2C_config structure. 

     Now, let's go back to your UART initialization you will find that in the  UART_config[] structure you are missing the index 1 and 2 for UART1 and UART2. 

     

    I2CTiva_Object i2cTivaObjects[EK_TM4C129EXL_I2CCOUNT];
    
    const I2CTiva_HWAttrs i2cTivaHWAttrs[EK_TM4C129EXL_I2CCOUNT] = {
        {
            .baseAddr = I2C7_BASE,
            .intNum = INT_I2C7,
            .intPriority = (~0)
        },
        {
            .baseAddr = I2C8_BASE,
            .intNum = INT_I2C8,
            .intPriority = (~0)
        },
    };
    
    const I2C_Config I2C_config[] = {
        {
            .fxnTablePtr = &I2CTiva_fxnTable,
            .object = &i2cTivaObjects[0],
            .hwAttrs = &i2cTivaHWAttrs[0]
        },
        {
            .fxnTablePtr = &I2CTiva_fxnTable,
            .object = &i2cTivaObjects[1],
            .hwAttrs = &i2cTivaHWAttrs[1]
        },
        {NULL, NULL, NULL}
    };

    You will also need to fix up the index for UART1 and UART2 for their ringBufPtr and .ringBufSize. 

        {
            .baseAddr = UART1_BASE,
            .intNum = INT_UART1,
            .intPriority = (~0),
            .flowControl = UART_FLOWCONTROL_NONE,
            .ringBufPtr  = uartTivaRingBuffer[1],
            .ringBufSize = sizeof(uartTivaRingBuffer[1])
        }
        {
            .baseAddr = UART2_BASE,
            .intNum = INT_UART2,
            .intPriority = (~0),
            .flowControl = UART_FLOWCONTROL_NONE,
            .ringBufPtr  = uartTivaRingBuffer[2],
            .ringBufSize = sizeof(uartTivaRingBuffer[2])
  • I actually found the solution in CC2642R1 code sample with two UART implementation, then I learn how they did this and came up with this solution

    typedef enum EK_TM4C1294XL_UARTName {
        EK_TM4C1294XL_UART0 = 0,
        EK_TM4C1294XL_UART2 = 1,            // Added 20/6/18
        EK_TM4C1294XL_UART7 = 2,            // Added 20/6/18
    
        EK_TM4C1294XL_UARTCOUNT
    } EK_TM4C1294XL_UARTName;
    
    #include <ti/drivers/uart/UARTTiva.h>
    
    UARTTiva_Object uartTivaObjects[EK_TM4C1294XL_UARTCOUNT];
    unsigned char uartTivaRingBuffer[EK_TM4C1294XL_UARTCOUNT][32];
    
    /* UART configuration structure */
    const UARTTiva_HWAttrs uartTivaHWAttrs[EK_TM4C1294XL_UARTCOUNT] = {
        {
            .baseAddr = UART0_BASE,
            .intNum = INT_UART0,
            .intPriority = (~0),
            .flowControl = UART_FLOWCONTROL_NONE,
            .ringBufPtr  = uartTivaRingBuffer[EK_TM4C1294XL_UART0],
            .ringBufSize = sizeof(uartTivaRingBuffer[EK_TM4C1294XL_UART0])
        },
        {
            .baseAddr = UART2_BASE,
            .intNum = INT_UART2,
            .intPriority = (~0),
            .flowControl = UART_FLOWCONTROL_NONE,
            .ringBufPtr  = uartTivaRingBuffer[EK_TM4C1294XL_UART2],
            .ringBufSize = sizeof(uartTivaRingBuffer[EK_TM4C1294XL_UART2])
        },
        {
            .baseAddr = UART7_BASE,
            .intNum = INT_UART7,
            .intPriority = (~0),
            .flowControl = UART_FLOWCONTROL_NONE,
            .ringBufPtr  = uartTivaRingBuffer[EK_TM4C1294XL_UART7],
            .ringBufSize = sizeof(uartTivaRingBuffer[EK_TM4C1294XL_UART7])
        }
    };
    
    const UART_Config UART_config[EK_TM4C1294XL_UARTCOUNT] = {
        {
            .fxnTablePtr = &UARTTiva_fxnTable,
            .object = &uartTivaObjects[EK_TM4C1294XL_UART0],
            .hwAttrs = &uartTivaHWAttrs[EK_TM4C1294XL_UART0]
        },
        {
            .fxnTablePtr = &UARTTiva_fxnTable,
            .object = &uartTivaObjects[EK_TM4C1294XL_UART2],
            .hwAttrs = &uartTivaHWAttrs[EK_TM4C1294XL_UART2]
        },
        {
            .fxnTablePtr = &UARTTiva_fxnTable,
            .object = &uartTivaObjects[EK_TM4C1294XL_UART7],
            .hwAttrs = &uartTivaHWAttrs[EK_TM4C1294XL_UART7]
        }
        //,{NULL, NULL, NULL}
    };

    I just learnt that in NXP LPCxxxx and I think also CC26xx, they have complete set of library representing the all available peripheral. We're writing for application product which goes further than the evaluation board, I found it strange (and surprising) there is no complete set to represent all available peripheral for given TM4C device. I mean obliviously the compiler would remove unused part of library.