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.

TM4C1294KCPDT: Serial port driver debugging problem

Part Number: TM4C1294KCPDT

1. Without the operating system, the following serial port interrupt function can print information normally.

void UARTIntHandler(void)

{

    uint32_t ui32Status;

                        char data;

 

    // Get the interrrupt status.

    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

 

    // Clear the asserted interrupts.   

    ROM_UARTIntClear(UART0_BASE, ui32Status);

 

    // Loop while there are characters in the receive FIFO.

    while(ROM_UARTCharsAvail(UART0_BASE))

    {

        // Read the next character from the UART.

        data = ROM_UARTCharGetNonBlocking(UART0_BASE);

        /* check the ring buffer for available space and put data */

                                               

                                                if (!RingBufFull(&sUartRing)) {

                                                RingBufWriteOne(&sUartRing, data);

                                                }                                  

    }

}

2.  In the ucos3 system, the interrupt function of 1 is abnormal, and some of the contents are printed, but the following serial port interrupt function can print information normally.

void UARTStdioIntHandler(void)

{

    uint32_t ui32Ints;

    int8_t cChar;

    int32_t i32Char;

    static bool bLastWasCR = false;

 

    //

    // Get and clear the current interrupt source(s)

    //

    ui32Ints = MAP_UARTIntStatus(g_ui32Base, true);

    MAP_UARTIntClear(g_ui32Base, ui32Ints);

 

    //

    // Are we being interrupted because the TX FIFO has space available?

    //

    if(ui32Ints & UART_INT_TX)

    {

        //

        // Move as many bytes as we can into the transmit FIFO.

        //

        UARTPrimeTransmit(g_ui32Base);

 

        //

        // If the output buffer is empty, turn off the transmit interrupt.

        //

        if(TX_BUFFER_EMPTY)

        {

            MAP_UARTIntDisable(g_ui32Base, UART_INT_TX);

        }

    }

 

    //

    // Are we being interrupted due to a received character?

    //

    if(ui32Ints & (UART_INT_RX | UART_INT_RT))

    {

        //

        // Get all the available characters from the UART.

        //

        while(MAP_UARTCharsAvail(g_ui32Base))

        {

            //

            // Read a character

            //

            i32Char = MAP_UARTCharGetNonBlocking(g_ui32Base);

            cChar = (unsigned char)(i32Char & 0xFF);

 

            //

            // If echo is disabled, we skip the various text filtering

            // operations that would typically be required when supporting a

            // command line.

            //

            if(!g_bDisableEcho)

            {

                //

                // Handle backspace by erasing the last character in the

                // buffer.

                //

                if(cChar == '\b')

                {

                    //

                    // If there are any characters already in the buffer, then

                    // delete the last.

                    //

                    if(!RX_BUFFER_EMPTY)

                    {

                        //

                        // Rub out the previous character on the users

                        // terminal.

                        //

                        UARTwrite("\b \b", 3);

 

                        //

                        // Decrement the number of characters in the buffer.

                        //

                        if(g_ui32UARTRxWriteIndex == 0)

                        {

                            g_ui32UARTRxWriteIndex = UART_RX_BUFFER_SIZE - 1;

                        }

                        else

                        {

                            g_ui32UARTRxWriteIndex--;

                        }

                    }

 

                    //

                    // Skip ahead to read the next character.

                    //

                    continue;

                }

 

                //

                // If this character is LF and last was CR, then just gobble up

                // the character since we already echoed the previous CR and we

                // don't want to store 2 characters in the buffer if we don't

                // need to.

                //

                if((cChar == '\n') && bLastWasCR)

                {

                    bLastWasCR = false;

                    continue;

                }

 

                //

                // See if a newline or escape character was received.

                //

                if((cChar == '\r') || (cChar == '\n') || (cChar == 0x1b))

                {

                    //

                    // If the character is a CR, then it may be followed by an

                    // LF which should be paired with the CR.  So remember that

                    // a CR was received.

                    //

                    if(cChar == '\r')

                    {

                        bLastWasCR = 1;

                    }

 

                    //

                    // Regardless of the line termination character received,

                    // put a CR in the receive buffer as a marker telling

                    // UARTgets() where the line ends.  We also send an

                    // additional LF to ensure that the local terminal echo

                    // receives both CR and LF.

                    //

                    cChar = '\r';

                    UARTwrite("\n", 1);

                }

            }

 

            //

            // If there is space in the receive buffer, put the character

            // there, otherwise throw it away.

            //

            if(!RX_BUFFER_FULL)

            {

                //

                // Store the new character in the receive buffer

                //

                g_pcUARTRxBuffer[g_ui32UARTRxWriteIndex] =

                    (unsigned char)(i32Char & 0xFF);

                ADVANCE_RX_BUFFER_INDEX(g_ui32UARTRxWriteIndex);

 

                //

                // If echo is enabled, write the character to the transmit

                // buffer so that the user gets some immediate feedback.

                //

                if(!g_bDisableEcho)

                {

                    UARTwrite((const char *)&cChar, 1);

                }

            }

        }

 

        //

        // If we wrote anything to the transmit buffer, make sure it actually

        // gets transmitted.

        //

        UARTPrimeTransmit(g_ui32Base);

        MAP_UARTIntEnable(g_ui32Base, UART_INT_TX);

    }

}

In the interrupt function of 2, in the code engineering, adding a printf function also prints a part of the information.
The previous print information was printed by UARTPrint.

In summary, when calling the interrupt described by 1 and calling printf, the problem is similar.
    
What is the difference between these two interrupts, except for the opening of RX, the disconnection of RT and TX (this does not affect the printing information)
Please help analyze and explain the above situation.

  • Hi,
    I'm not sure why the interrupt function 1 didn't work with the operating system. Perhaps, it may have something to do with how the OS handles/manages the interrupts. I have no familiarity with ucos3 so can't provide much insights into it. However, you mentioned about printf. I will discourage you from using printf as a way of debugging. If you have managed to use UARTstudio as a replacement for the printf then you should not use the printf as much as possible. The printf makes use of the CIO and it is a complicated method to interact with the I/O. Please take a look at this wiki link where it mentions not to use printf inside an interrupt handler which is unsafe.
    processors.wiki.ti.com/.../Tips_for_using_printf
  • Hi,
    I have not heard back from you. I assume your issue is somehow resolved with the wiki link about how the printf being handled is helpful. I will close this thread for now. If you have new questions you can open a new thread or reopen this thread if your issue is not resolved.