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: TM4C1294NCPDT UART Interrupt creation

Part Number: TM4C1294NCPDT

Tool/software: TI-RTOS

Hello,

I am trying to implement a UART interrupt in TIRTOS for the TM4C1294NCPDT controller and am getting stuck when trying to register an interrupt handler.

My init function in EK_TM4C1294XL.c:

/*
 *  ======== EK_TM4C1294XL_initUART ========
 */
void EK_TM4C1294XL_initUART(void)
{
    /* UART 0 */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART0_BASE, 120000000, 9600,
                                (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                                 UART_CONFIG_PAR_NONE));

    /* Initialize the UART driver */
#if TI_DRIVERS_UART_DMA
    EK_TM4C1294XL_initDMA();
#endif
    UART_init();

    /* Enables UART FIFO */
    UARTFIFOEnable(UART0_BASE);

    /* Set RX FIFO interrupt at maximum and TX interrupt at minimum */
    UARTFIFOLevelSet(UART0_BASE, UART_FIFO_RX7_8, UART_FIFO_TX1_8);

    /* Bind interrupt handler function */
    UARTIntRegister(UART0_BASE, UART0InterruptHandler);

    /* Enable the interrupt */
    UARTIntEnable(UART0_BASE, UART_INT_RX);

}

The UART0InterruptHandler function is defined elsewhere:

void UART0InterruptHandler(void){

    uint32_t intStatus = UARTIntStatus(UART0_BASE, false);  //false = 0
    UARTIntClear(UART0_BASE, UART_INT_RX);
    UARTIntDisable(UART0_BASE, UART_INT_RX);
    if(intStatus & UART_INT_RX){    //Rx interrupt
        while(UARTCharsAvail(UART0_BASE)){
            UART_buffer[UART_buffer_index] = UARTCharGet(UART0_BASE); //extract chars one by one
            UART_buffer_index++;
        }
    }

    return;

}

The issue is that when I try to run the code with the UARTIntRegister function included, as soon as the code is loaded into the controller (even before I hit run) the controller runs to the loader_exit function and the console displays the following message:

FSR = 0x0000
HFSR = 0x40000000
DFSR = 0x00000008
MMAR = 0x00016400
BFAR = 0x00016400
AFSR = 0x00000000
Terminating execution...

If I do not include the UARTIntRegister function, everything works fine (no interrupts, obviously.) What am I doing wrong? Is there a global interrupt that I am not enabling somewhere? Or, do I need to make some changes in the .cfg file for this to work?

Thank you,

svl123

  • The RTOS is responsible for assigning interrupts. I am fuzzy on the details, but I know that you can not register interrupts with TivaWare functions in TI-RTOS projects.

  • Here's the details that Peter was referring to: e2e.ti.com/.../2347913 (different device, but same concept).

    You can just use the UART driver supplied in TI-RTOS (e.g. look at the UART Echo example in TI-RTOS). It does all the interrupt management for you. Or you can use the code as a template/starting point if it does not quite meet your needs.

    Todd

  • Todd, thank you for the reply. I have a few concerns:

    1. I understand that I can use the example but I am not sure how quickly the example code runs - my understanding is that it creates a task whereas I'd like a HWI or SWI to run when the UART interrupt fires so that I can quickly copy the contents of the RX FIFO to my own buffer.

    2. The uartecho example only reacts to the reception of a byte - effectively this is the case where the UART_INT_RX interrupt is enabled with no FIFO, right? Now, if I for example want an interrupt on the Receive timeout condition, for example, how can I implement that as well?

    Is it possible to use the interrupt in the way that I stated in my original post? Or is using the functions in uart.c not supported in TIRTOS?
  • svl123 said:
    1. I understand that I can use the example but I am not sure how quickly the example code runs - my understanding is that it creates a task whereas I'd like a HWI or SWI to run when the UART interrupt fires so that I can quickly copy the contents of the RX FIFO to my own buffer.

    The TI-RTOS UART driver is more natural with tasks. It can be used in Hwi or Swi context f you use the callback mode. Using the supplied driver was just a suggestion. You can use the approach you were taking (except you need to not use driverlib to plug the interrupt).

    svl123 said:
    2. The uartecho example only reacts to the reception of a byte - effectively this is the case where the UART_INT_RX interrupt is enabled with no FIFO, right? Now, if I for example want an interrupt on the Receive timeout condition, for example, how can I implement that as well?

    That's just the example. The driver can do larger blocks of data and use timeouts. Please refer to the doxygen documentation for the driver (open Documentation Overview in the installed TI-RTOS product to find the links).

    svl123 said:
    Is it possible to use the interrupt in the way that I stated in my original post? Or is using the functions in uart.c not supported in TIRTOS?

    Yes, but just make sure you tell the kernel about the interrupt (e.g. use Hwi_create or Hwi_construct to have the kernel manage the ISR or make the ISR a zero-latency interrupt).

    Todd

  • Todd, thank you. The thing to do was get rid of the IntRegister call in the initUART function and instead create a UART0 HWI in the cfg editor and enter the callback function there.

    Thank you,

    svl123