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.

TM4C129XNCZAD: Using multiple UARTs with TI-RTOS

Part Number: TM4C129XNCZAD

Hello I am trying to migrate an old project onto TM4C129XNMCZAD microcontroller and I wanted to use TI-RTOS so I can multithread. One issue I am having is I do not know how to initialize UART peripherals other than UART0. The only UART that is defined in the Board.h file is UART0 even though this board supports multiple UARTs. Is there a tutorial or an example with a TM4C129x device that uses multiple UARTs on TI-RTOS? I have the UART echo example working so I don't have a problem with creating the tasks.

//code in the Board.h file

#define Board_USBDEVICE             DK_TM4C129X_USBDEVICE

#define Board_UART0                 DK_TM4C129X_UART0 //=> the only UART definition.

#define Board_WATCHDOG0             DK_TM4C129X_WATCHDOG0

  • Hello Omer,

    The Board.h file and the DK_TM4C129X.c/.h files are just provided based on what is used across all example projects. They can be expanded as needed for each user.

    For example, to add two more UART using BoosterPack 1 & BoosterPack 2 slots for UART, you can make the following adjustments.

    Board.h

    #define Board_UART0                 DK_TM4C129X_UART0
    #define Board_UART3                 DK_TM4C129X_UART3
    #define Board_UART5                 DK_TM4C129X_UART5
    

    DK_TM4C129X.h

    /*!
     *  @def    DK_TM4C129X_UARTName
     *  @brief  Enum of UARTs on the DK_TM4C129X dev board
     */
    typedef enum DK_TM4C129X_UARTName {
        DK_TM4C129X_UART0 = 0,
        DK_TM4C129X_UART3,
        DK_TM4C129X_UART5,
    
        DK_TM4C129X_UARTCOUNT
    } DK_TM4C129X_UARTName;

    DK_TM4C129X.c

    #include <ti/drivers/uart/UARTTiva.h>
    
    UARTTiva_Object uartTivaObjects[DK_TM4C129X_UARTCOUNT];
    unsigned char uartTivaRingBuffer[DK_TM4C129X_UARTCOUNT][32];
    
    /* UART configuration structure */
    const UARTTiva_HWAttrs uartTivaHWAttrs[DK_TM4C129X_UARTCOUNT] = {
        {
            .baseAddr = UART0_BASE,
            .intNum = INT_UART0,
            .intPriority = (~0),
            .flowControl = UART_FLOWCONTROL_NONE,
            .ringBufPtr  = uartTivaRingBuffer[0],
            .ringBufSize = sizeof(uartTivaRingBuffer[0])
        },
        {
            .baseAddr = UART3_BASE,
            .intNum = INT_UART3,
            .intPriority = (~0),
            .flowControl = UART_FLOWCONTROL_NONE,
            .ringBufPtr  = uartTivaRingBuffer[1],
            .ringBufSize = sizeof(uartTivaRingBuffer[1])
        },
        {
            .baseAddr = UART5_BASE,
            .intNum = INT_UART5,
            .intPriority = (~0),
            .flowControl = UART_FLOWCONTROL_NONE,
            .ringBufPtr  = uartTivaRingBuffer[2],
            .ringBufSize = sizeof(uartTivaRingBuffer[2])
        }
    };
    
    const UART_Config UART_config[] = {
        {
            .fxnTablePtr = &UARTTiva_fxnTable,
            .object = &uartTivaObjects[0],
            .hwAttrs = &uartTivaHWAttrs[0]
        },
        {
            .fxnTablePtr = &UARTTiva_fxnTable,
            .object = &uartTivaObjects[1],
            .hwAttrs = &uartTivaHWAttrs[1]
        },
        {
            .fxnTablePtr = &UARTTiva_fxnTable,
            .object = &uartTivaObjects[2],
            .hwAttrs = &uartTivaHWAttrs[2]
        },
        {NULL, NULL, NULL}
    };
    
    /*
     *  ======== DK_TM4C129X_initUART ========
     */
    void DK_TM4C129X_initUART()
    {
        /* Enable and configure the peripherals used by the uart. */
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
        GPIOPinConfigure(GPIO_PJ0_U3RX);
        GPIOPinConfigure(GPIO_PJ1_U3TX);
        GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
        GPIOPinConfigure(GPIO_PH6_U7RX);
        GPIOPinConfigure(GPIO_PH7_U7TX);
        GPIOPinTypeUART(GPIO_PORTH_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    
        /* Initialize the UART driver */
        UART_init();
    }

    From there you can set your Parameters and UART_open with Board_UART3 & Board_UART5 to create your tasks.

    Hopefully that helps with understanding what all is needed to add additional UART peripherals to the configuration.

    Best Regards,

    Ralph Jacobi

  • Thanks for the quick answer, I tried this but it did not work with UART1, I will look at the code you sent to see if I it works and resolve the thread if it does. 

  • Thanks for the help! I had one of the PINs named wrong for the second UART.

  • Hi Omer,

    Glad to have been of help. I've been there many times on naming one pin wrong and scratching my head. Slight smile

    Best Regards,

    Ralph Jacobi