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.

  • Resolved

TM4C123GH6PGE: Example usb_dev_serial

Expert 2950 points

Replies: 25

Views: 536

Part Number: TM4C123GH6PGE

Hello,

Q1> Are the green bars unchanged in [Fig1] and [Fig2] ?

       The green bar is always full.

Regards.

Jame,Shin

  • Hi Jame,

      I think the green bar is always full is correct. When it is fully green it means it is empty. If there is some transfer, a portion of the green bar will be filled with red. 

      When it is first initialized in the main(), the DrawBufferMeter() is called. If you look at the source code of DrawBufferMeter it has the below code that says the meter is filled with green to indicate empty. 

    //
    // Fill the meter with green to indicate empty
    //
    GrContextForegroundSet(psContext, ClrGreen);
    GrRectFill(psContext, &sRect);

    //
    // Put a white box around the meter.
    //
    GrContextForegroundSet(psContext, ClrWhite);
    GrRectDraw(psContext, &sRect);

    Please also look at the UpdateBufferMeter() API where the portion or all of the green bar is filled with red depending on the transfer status. 

    //
    // Fill the full section with red (if there is anything to draw)
    //
    if(ui32FullPercent)
    {
    GrContextForegroundSet(psContext, ClrRed);
    GrRectFill(psContext, &sRect);
    }

    //
    // Fill the empty section with green.
    //
    sRect.i16XMin = i32XBreak;
    sRect.i16XMax = i32X + BUFFER_METER_WIDTH - 2;
    if(sRect.i16XMax > sRect.i16XMin)
    {
    GrContextForegroundSet(psContext, ClrGreen);
    GrRectFill(psContext, &sRect);
    }

    regards,

    Charles

     

  • In reply to Charles Tsai:

    Hello Charles,

    Thank you for your reply.

    I analyzed it with what you answered.

    The example source code seems to be a problem.

    When the ui32Fullness value becomes a constant, a red bar is drawn unconditionally.

    And the green bar is overwritten again at a high speed, which is not visible with eyes.

    How can I display data in a FIFO with a color bar?

    // Called by the main function.

    DrawBufferMeter(&g_sContext, 40, 22);

    DrawBufferMeter(&g_sContext, 40, 42);

    // Has there been any (transmit or receive) traffic since we last checked?

        1   byte sent to UART Tx to USB Rx buffer       (1 * 100) / 256 = 0.390625 ,  result 0

       100 byte sent to UART Tx to USB Rx buffer       (100*100)/ 256 = 39.0625 ,   result 39

    ui32Fullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) / UART_BUFFER_SIZE);

    UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 22);

    ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) / UART_BUFFER_SIZE);

    UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 42);

    // Fill the full section with red (if there is anything to draw)

    UpdateBufferMeter(tContext *psContext, uint32_t ui32FullPercent, int32_t i32X, int32_t i32Y)

    {

    // Determine where the break point between full (red) and empty (green) sections occurs.

       i32XBreak = (i32X + 1) + (ui32FullPercent * (BUFFER_METER_WIDTH - 2)) / 100;

                       case1>  // ( 40+1) + ( 0 * 54) / 100 = 41 + 0     = 41

                        case2>  // (40+1) + (39 * 54)/100 =   41 + 21.06 = 62

    if(ui32FullPercent)

       {

           GrContextForegroundSet(psContext, ClrRed);

           GrRectFill(psContext, &sRect);

       }

       // Fill the empty section with green

       sRect.i16XMin = i32XBreak;

       sRect.i16XMax = i32X + BUFFER_METER_WIDTH - 2;

       if(sRect.i16XMax > sRect.i16XMin)

       {

           GrRectFill(psContext, &sRect

           GrContextForegroundSet(psContext, ClrGreen););

       }

       // Revert to white for text drawing which may occur later.

       GrContextForegroundSet(psContext, ClrWhite);

    }

    regards,

    Jame,Shin

     

  • In reply to Jame shin:

    Hi Jame,

      The color bar just tries to reflect how many data are available in either the TX or RX USBbuffer. I don't really see a problem with it. I see the RED color changing from left to right. Note that the UpdatBufferMeter is only updated when there is any transmit or receive traffic from the perspective of the UART. You can try to transfer a large amount of data (i.e. a text file) from the USB to the UART. You will see the Tx bar changing rapidly. 

    regards,

    Charles

     

  • In reply to Charles Tsai:

    Hello Charles,

    Thank you for your reply

    In [Fig. 5], the red bar is hard to see when a lot of data is sent once.

    [Fig. 6] shows a very small red bar variation when sending a lot of data.

    I'm a bit hard to check.

    Does that mean I can see the tx bar you told me changing rapidly ?

    There is no see obvious change.

    Have a happy weekend.  ^ . ^

    regards,

    Jame,Shin

  • In reply to Jame shin:

    Hello Jame,

      Please bear in the mind the difference between the USB and UART in terms of their buffer size. The USB bulk transfer at full-speed can buffer 64 bytes of data while the UART has a much smaller FIFO buffer (i.e. 16). Therefore, the the UpdateBufferMeter will be called more often (much quicker like 4x faster) when the UART is receiving than when the USB port is receiving. Note for the RX bar, the ui32Fullness is relative to the UART's receive buffer. 

     

                //
                // Update the TX buffer fullness. Remember that the buffers are
                // named relative to the USB whereas the status display is from
                // the UART's perspective. The USB's transmit buffer is the UART's
                // receive buffer.
                //
                ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) /
                              UART_BUFFER_SIZE);
    UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 42);


    regards,

    Charles

     

  • In reply to Charles Tsai:

    Hello Charles,

    Thank you for your reply

    I understand what you said.

    PC Host USB0 (Stellaris Serial USB) TX --------> ICD-EVB  -----------> Rx 16x8bit FIFO ---------------------------------------

                                                                                           1                                                                               2                                                          |

    PC Host USB1(TivaWare serial USB)RX <------  USBDEV-EVB <----- USB Tx Buffer ( g_pi8USBTxBuffer[256] )  <----

                                                                                              USBDCDC

    PC Host USB0 (Stellaris Serial USB) RX <------- ICD-EVB  <----------- Tx 16x8bit FIFO <-------------------------------------

                                                                                              1                                                                          2                                                            |

    PC Host USB1(TivaWare serial USB)TX ------>  USBDEV-EVB ------> USB Rx Buffer ( g_pi8USBRxBuffer[256] )  ----

                                                                                              USBDCDC

    1 : Bulk IN/Out, Interrupt IN, Endpoint0   64Byte/s

    2. Hardwire Tx/Rx FiFO Size 16byte

    Q1> What does UART_FIFO_TX4_8 mean by setting the FIFO interrupt level in the UARTFIFOLevelSet () function  ?

           4 bytes, 25% of the total size of the FIFO, will be filled. So the USBUARTintHandler () function is called four times.

           In conclusion, is that UpdateBufferMeter () function is called 16 times !!

    regards,

    Jame,Shin

  • In reply to Jame shin:

    Hi Jame,

      Your understanding is correct except that the UART_FIFO_TX4_8 is to interrupt at half  (8 bytes out of 16 bytes) of the FIFO or 50%. Therefore, the USBUARTintHandler  will be called 8 times more quickly compared to when the USB is receiving/transmitting.

    regards,

    Charles

     

  • In reply to Charles Tsai:

    Hello Charles,

    Thank you for your reply

    UART_FIFO_TX1_8,

    UART_FIFO_TX2_8,

    UART_FIFO_TX4_8,

    UART_FIFO_TX6_8, 

    UART_FIFO_TX7_8.

     

    DRL-UG documents do not have descriptions in byte size.

    Does xxxx_TxN_n mean N x n bit  ?

    How is it 8 bytes .

    regards,

    Jame,Shin

  • In reply to Jame shin:

    Hi Jame,

      Please go to the uart.h file for the MACRO definition.

    //*****************************************************************************
    //
    // Values that can be passed to UARTFIFOLevelSet as the ui32TxLevel parameter
    // and returned by UARTFIFOLevelGet in the pui32TxLevel.
    //
    //*****************************************************************************
    #define UART_FIFO_TX1_8         0x00000000  // Transmit interrupt at 1/8 Full
    #define UART_FIFO_TX2_8         0x00000001  // Transmit interrupt at 1/4 Full
    #define UART_FIFO_TX4_8         0x00000002  // Transmit interrupt at 1/2 Full
    #define UART_FIFO_TX6_8         0x00000003  // Transmit interrupt at 3/4 Full
    #define UART_FIFO_TX7_8         0x00000004  // Transmit interrupt at 7/8 Full
    
    //*****************************************************************************
    //
    // Values that can be passed to UARTFIFOLevelSet as the ui32RxLevel parameter
    // and returned by UARTFIFOLevelGet in the pui32RxLevel.
    //
    //*****************************************************************************
    #define UART_FIFO_RX1_8         0x00000000  // Receive interrupt at 1/8 Full
    #define UART_FIFO_RX2_8         0x00000008  // Receive interrupt at 1/4 Full
    #define UART_FIFO_RX4_8         0x00000010  // Receive interrupt at 1/2 Full
    #define UART_FIFO_RX6_8         0x00000018  // Receive interrupt at 3/4 Full
    #define UART_FIFO_RX7_8         0x00000020  // Receive interrupt at 7/8 Full





    regards,

    Charles

     

  • In reply to Charles Tsai:

    Whose pumpkin is handsome.  ?

    Hello., 

    To everyone

    It gives a pleasant laugh. 

    regards,

    Jame, Shin

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.