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/TM4C1294NCPDT: TM4c1294NCPDT

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL, SYSBIOS

Tool/software: Code Composer Studio

I am working on TCP_ECHO code from TI-RTOS Tiva-C. In there I want to use UART functions within the TCP_echo code. 

I am successfully able to use Uart_Send function to send data to TCP socket but cannot incorporate Uart_Interrupt function in the code.Whenever I try to write in com port the code takes me to error state; which should have been in Uart_Interrupt Handler instead.                                                                                                                           

Pl, tell me whether it is possible to use Uart_Interrupt with the TCP_Echo code.

Same problem arose when using UART_Echo code. It is defined for UART0 but I could use it  other Uart Prorts.But to only send data ie. Uart_Send  Function. Again I'm unable to use Interrupt Handler..

Pl, look into it asao.

Thanks &Regards

Vinayak Ullagaddi

  • Hello,

      What is Uart_Send and Uart_Interrupt? Are these your own functions? How are you setting up the interrupt? Are you using any IntRegister to register the ISR callback? It can mess up the SYS/BIOS kernel. Please see the last post of this thread. https://e2e.ti.com/support/wireless-connectivity/bluetooth/f/538/p/635201/2347913 to see if you have similar issue. 

      You can use different UART other than UART0. You need to go to EK-TM4C1294XL.c file and modify uartTivaHWAttrs. Perhaps you can sort of reference how it is done for i2cTivaHWAttrs where multiple instances of the i2c are configured. Please note that if you are using the launchpad board, only UART0 can be used as the virtual COM port as UART0 is the only guy connected to the debug probe by default. 

  • Hi Vinayak ,

      I have not heard back from you. I hope you somehow resolve the issue. I will close the thread for now. If the issue is not resolved you can just reply back to reopen the thread. 

  • Mr.Charles

    1).   I have tried to register interrupt handler to the SysBios.But, I don't see any api for that. For example,there is one for simplelink devices OS_register_interruptHAndler where we can register interrupt  and enable and disable it accordingly.

    2). Even in the UART_Params structure there isn't anything for Uart Interrupt.

    In that structure there is Uart mode  >  Read mode & Write mode. Nothing is defined for interrupt handler.

    Traditional TivaC apis like uartsend works fine but when it comes to uart handler it crashes and goes into error state.

    I don't know why UartSend function is working in Sysbios???  >There is UartWrite  as alternative  that in Uart_Params

    but UartIntHandler is not working and there is no alternative for the same in Uart_Params

  • Hi,

      I'm not familiar with the Simplelink as it is another TI product, not Tiva device. 

      Have you tried to use the Hwi_create? I think you want to let the TI-RTOS use the Hwi to manage your interrupts. Don't register any interrupts using TivaWare API mixing with the TI-RTOS as it will mess the TI-RTOS. In my original reply, I referenced a post from our TI-RTOS expert. Please review the last post of the thread. 

      Below is an example using the Timer2A to generate a Hwi interrupt. Please take a look at the lines.

    myHwi = Hwi_create(39, (Hwi_FuncPtr)ledToggle, &hwiParams, &eb);

    Hwi_enableInterrupt(39);

    //----------------------------------------
    // BIOS header files
    //----------------------------------------
    #include <xdc/std.h>  						//mandatory - have to include first, for BIOS types
    #include <ti/sysbios/BIOS.h> 				//mandatory - if you call APIs like BIOS_start()
    #include <xdc/runtime/Log.h>				//needed for any Log_info() call
    #include <xdc/cfg/global.h> 				//header file for statically defined objects/handles
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/hal/Hwi.h>
    
    
    //------------------------------------------
    // TivaWare Header Files
    //------------------------------------------
    #include <stdint.h>
    #include <stdbool.h>
    
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/timer.h"
    
    
    //----------------------------------------
    // Prototypes
    //----------------------------------------
    void hardware_init(void);
    void ledToggle(void);
    
    
    //---------------------------------------
    // Globals
    //---------------------------------------
    volatile int16_t i16ToggleCount = 0;
    
    
    //---------------------------------------------------------------------------
    // main()
    //---------------------------------------------------------------------------
    void main(void)
    {
    
        hardware_init();                         // init hardware via Xware
    
        Hwi_Params hwiParams;
        Hwi_Handle myHwi;
        Error_Block eb;
        /* Initialize error block and hwiParams to default values */
        Error_init(&eb);
        Hwi_Params_init(&hwiParams);
        hwiParams.enableInt = FALSE;
        myHwi = Hwi_create(39, (Hwi_FuncPtr)ledToggle, &hwiParams, &eb);
        if (myHwi == NULL) {
        System_abort("Hwi create failed");
        }
        Hwi_enableInterrupt(39);
    
    
       BIOS_start();
    
    }
    
    
    //---------------------------------------------------------------------------
    // hardware_init()
    //
    // inits GPIO pins for toggling the LED
    //---------------------------------------------------------------------------
    void hardware_init(void)
    {
    	uint32_t ui32Period;
    
    	//Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz
    	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    
    	// ADD Tiva-C GPIO setup - enables port, sets pins 1-3 (RGB) pins for output
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    
    	// Turn on the LED
    	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 4);
    
    	// Timer 2 setup code
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);			// enable Timer 2 periph clks
    	TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC);		// cfg Timer 2 mode - periodic
    
    	ui32Period = (SysCtlClockGet() /2);						// period = CPU clk div 2 (500ms)
    	TimerLoadSet(TIMER2_BASE, TIMER_A, ui32Period);			// set Timer 2 period
    
    	TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);		// enables Timer 2 to interrupt CPU
    
    	TimerEnable(TIMER2_BASE, TIMER_A);						// enable Timer 2
    
    }
    
    
    //---------------------------------------------------------------------------
    // ledToggle()
    //
    // toggles LED on Tiva-C LaunchPad
    //---------------------------------------------------------------------------
    void ledToggle(void)
    {
        TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT);			// must clear timer flag FROM timer
    
    	// LED values - 2=RED, 4=BLUE, 8=GREEN
    	if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
    	{
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
    	}
    	else
    	{
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
    	}
    
    	i16ToggleCount += 1;									// keep track of #toggles
    
    	Log_info1("LED TOGGLED [%u] TIMES",i16ToggleCount);		// send toggle count to UIA
    
    }

     

  • //----------------------------------------
    // BIOS header files
    //----------------------------------------
    #include <xdc/std.h>                          //mandatory - have to include first, for BIOS types
    #include <ti/sysbios/BIOS.h>              //mandatory - if you call APIs like BIOS_start()
    #include <xdc/runtime/Log.h>              //needed for any Log_info() call
    #include <xdc/cfg/global.h>               //header file for statically defined objects/handles
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/hal/Hwi.h>
    #include <ti/drivers/UART.h>
    #include <ti/drivers/GPIO.h>

    //------------------------------------------
    // TivaWare Header Files
    //------------------------------------------
    #include <stdint.h>
    #include <stdbool.h>

    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/uart.h"
    #include "driverlib/pin_map.h"


    //----------------------------------------
    // Prototypes
    //----------------------------------------
    void hardware_init(void);
    void ledToggle(void);
    uint32_t ui32SysClock;

    //---------------------------------------
    // Globals
    //---------------------------------------
    volatile int16_t i16ToggleCount = 0;
    void UARTHandler(void);
    void UARTDataSend(const uint8_t *buffer, uint32_t ui32Count);
    void uart_init(void);
    //---------------------------------------------------------------------------
    // main()
    //---------------------------------------------------------------------------
    int main(void)
    {
        //Board_initUART();
        uart_init();                         // init hardware via Xware

        Hwi_Params hwiParams;

        Hwi_Handle myHwi;
        Error_Block eb;
        /* Initialize error block and hwiParams to default values */
        Error_init(&eb);
        Hwi_Params_init(&hwiParams);

       // hwiParams.arg = (UArg)arg0;

        hwiParams.enableInt = FALSE;
        myHwi = Hwi_create(22, (Hwi_FuncPtr)UARTHandler, &hwiParams, &eb);
        if (myHwi == NULL) {
        System_abort("Hwi create failed");
        }
        Hwi_enableInterrupt(22);


       BIOS_start();

    }

    //void UARTDataSend(const uint8_t *buffer, uint32_t ui32Count)
    //{
    //    //
    //    // Loop while there are more characters to send.
    //
    //    while(ui32Count--)
    //    {
    //        //
    //        // Write the next character to the UART.
    //        //
    //        UARTCharPut(UART1_BASE, *buffer++);
    //    }
    //}


    void UARTHandler(void)
    {     uint32_t ui32Status;
    ui32Status = UARTIntStatus(UART1_BASE, true); //get interrupt status
    UARTIntClear(UART1_BASE, ui32Status); //clear the asserted interrupts


    while(UARTCharsAvail(UART1_BASE)) //loop while there are chars
    {
    //    data = UARTCharGet(UART5_BASE);
    //    Receive_buff[i] = data;
    //
    //    //UARTCharPutNonBlocking(BASE, Receive_buff[i]);
    //    i++;
        UARTCharPutNonBlocking(UART1_BASE, UARTCharGetNonBlocking(UART1_BASE)); //echo character
    }

    }   // send toggle count to UIA


    //---------------------------------------------------------------------------
    // hardware_init()
    //
    // inits GPIO pins for toggling the LED
    //---------------------------------------------------------------------------
    void uart_init(void)
    {
        ui32SysClock = SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320, 40000000);

          SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
          SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);

          while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))
             {
             }


          GPIOPinConfigure(GPIO_PB0_U1RX);
          GPIOPinConfigure(GPIO_PB1_U1TX);
          GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);



          UARTConfigSetExpClk(UART1_BASE, ui32SysClock, 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
          IntMasterEnable(); //enable processor interrupts
          IntEnable(INT_UART1); //enable the UART interrupt
          UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts


          // Prompt for text to be entered.

        //  UARTDataSend("AT",2);


          // Loop forever echoing data through the UART.


    }


    //---------------------------------------------------------------------------
    // ledToggle()
    //
    // toggles LED on Tiva-C LaunchPad
    //---------------------------------------------------------------------------

  • I want to get data in Uart Interrupt Handler using Hwi in Tirtos. I am not able to do so. Please review the code and suggest me changes asap.

  • Some questions/comments:

      1. Are you using the LaunchPad or your custom board? The reason to ask is that only UART0 in the launchpad is connected to the debug probe for virtual COM port. You cannot use UART1 for virtual COM port on the LaunchPad. Please refer to the EK-TM4C1294XL launchPad user's guide if you are using the LP for your development. If you have your custom board, I assume you use FTDI or some sort to use UART1 as a COM port.

      2. If you are using the COM port, are you seeing the COM port in your Windows device manager?

      3. Can you get your code using UART1 working in a non TI-RTOS environment if you must use UART1? If you must use UART1 then I will suggest that you also try it on the non TI-RTOS environment. 

      4. Since I'm not sure if you use the launchPad or your custom board with the reason explained in #1, I will assume your code will not work even in polling mode. Is that correct?

      5. Please use an oscilloscope or the logic analyzer to assist you debug. 

  • Mr. Charles

    I did use uart1 with the tm4c129 launchpad. The com port I saw in the settings was usb com port no. and not the stellaris one(default for uart 0).

    My code is working fine in non-TI rtos environment where I am able to get data in UART interrupt Handler.

    I feel I am missing some parameters initialization in HWI for UART interrupt handler.

    I want to get this code running

    Pl, look through it and suggest me changes asap.

    Thanks,

    Vinayak Ullagaddi

  • Hi,

      I'm not clear with your reply. You said you use uart1 on the tm4c129 launchpad. This will not work as a COM port. You must use UART0. 

      When you said your code is working fine in non-TI RTOS, is it using the UART0 or UART1 and if you are connecting to the PC's COM port? Unless you have used your own custom board with the UART1 connecting to a FTDI chip, you cannot get UART1 to work as a COM port on the launchPad, whether TI-RTOS or not. 

      Why don't use try UART0 first?

  • //----------------------------------------
    // BIOS header files
    //----------------------------------------
    #include <xdc/std.h>                          //mandatory - have to include first, for BIOS types
    #include <ti/sysbios/BIOS.h>              //mandatory - if you call APIs like BIOS_start()
    #include <xdc/runtime/Log.h>              //needed for any Log_info() call
    #include <xdc/cfg/global.h>               //header file for statically defined objects/handles
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/hal/Hwi.h>
    #include <ti/drivers/UART.h>
    #include <ti/drivers/GPIO.h>

    //------------------------------------------
    // TivaWare Header Files
    //------------------------------------------
    #include <stdint.h>
    #include <stdbool.h>

    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/uart.h"
    #include "driverlib/pin_map.h"


    //----------------------------------------
    // Prototypes
    //----------------------------------------

    uint32_t ui32SysClock;

    //---------------------------------------
    // Globals
    //---------------------------------------
    volatile int16_t i16ToggleCount = 0;
    void UARTHandler(void);
    void UARTDataSend(const uint8_t *buffer, uint32_t ui32Count);
    void uart_init(void);
    //---------------------------------------------------------------------------
    // main()
    //---------------------------------------------------------------------------
    int main(void)
    {
        //Board_initUART();
        uart_init();                         // init hardware via Xware

        Hwi_Params hwiParams;

        Hwi_Handle myHwi;
        Error_Block eb;
        /* Initialize error block and hwiParams to default values */
        Error_init(&eb);
        Hwi_Params_init(&hwiParams);

    //    hwiParams.arg = (UArg)arg0;

        hwiParams.enableInt = FALSE;
        myHwi = Hwi_create(22, (Hwi_FuncPtr)UARTHandler, &hwiParams, &eb);
        if (myHwi == NULL) {
        System_abort("Hwi create failed");
        }
        Hwi_enableInterrupt(22);

        UARTDataSend("AT",2);


       BIOS_start();
       UARTDataSend("AT",2);

    }

    void UARTDataSend(const uint8_t *buffer, uint32_t ui32Count)
    {
        //
        // Loop while there are more characters to send.

        while(ui32Count--)
        {
            //
            // Write the next character to the UART.
            //
            UARTCharPut(UART3_BASE, *buffer++);
        }
    }


    void UARTHandler(void)
    {     uint32_t ui32Status;
    ui32Status = UARTIntStatus(UART3_BASE, true); //get interrupt status
    UARTIntClear(UART3_BASE, ui32Status); //clear the asserted interrupts


    while(UARTCharsAvail(UART3_BASE)) //loop while there are chars
    {
    //    data = UARTCharGet(UART5_BASE);
    //    Receive_buff[i] = data;
    //
    //    //UARTCharPutNonBlocking(BASE, Receive_buff[i]);
    //    i++;
        UARTCharPutNonBlocking(UART3_BASE, UARTCharGetNonBlocking(UART3_BASE)); //echo character
    }

    }   // send toggle count to UIA


    //---------------------------------------------------------------------------
    // hardware_init()
    //
    // inits GPIO pins for toggling the LED
    //---------------------------------------------------------------------------
    void uart_init(void)
    {
        ui32SysClock = SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320, 40000000);

          SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
          SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);

          while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA))
             {
             }


          GPIOPinConfigure(GPIO_PA4_U3RX);
          GPIOPinConfigure(GPIO_PA5_U3TX);
          GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5);



          UARTConfigSetExpClk(UART3_BASE, ui32SysClock, 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
          IntMasterEnable(); //enable processor interrupts
          IntEnable(INT_UART3); //enable the UART interrupt
          UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts


          // Prompt for text to be entered.

        //  UARTDataSend("AT",2);


          // Loop forever echoing data through the UART.


    }


    //---------------------------------------------------------------------------
    // ledToggle()
    //
    // toggles LED on Tiva-C LaunchPad
    //---------------------------------------------------------------------------

    Please look through the code and suggest me where I am wrong. I have used UART 3 on portA ie pin 4 and 5.

    Please don't discuss about uart only, in addition to that tell me why my code is not entering interrupt handler.

    What h/w parameters initialization am I missing???

    As soon as Hwi_enableInterrupt(22); is called the code goes into error state.

  • Hi Vinayak,

    Have you tried using the TIRTOS UART Driver instead of writing your own functions to send, receive, and handle interrupts? This will simplify what are you trying to do especially since you are using TIRTOS. 

    Jas

  • Vinayak,

    Any update on this thread?

    Todd

    [8/21 update: Marking as TI Thinks Resolved due to no activity from the original poster].