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.

LM4f120 launchpad for using both UART0 and UART2

Test environments:

1. LM4F120 Launchpad

2. uart_echo project

3. CCS v5

Question:

I would like to use both UART0 and UART2 simultaneously. So, I set as follows "my test code".

I also add UART interrupt service routine to startup_ccs.c

UART0 is OK. But UART2 of PD7(U2TX) is not working. I can not see any signals from Oscilloscope at PIN PD7.

I would like to see both PD7 and PA1 signals with Oscilloscope.

Would you let me know my wrong? 

======== My test Code ==================

//*****************************************************************************
//
// uart_echo.c - Example for reading data from and writing data to the UART in
// an interrupt driven fashion.
// This is part of revision 9453 of the EK-LM4F120XL Firmware Package.
//
//*****************************************************************************

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

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>UART Echo (uart_echo)</h1>
//!
//! This example application utilizes the UART to echo text. The first UART
//! (connected to the USB debug virtual serial port on the evaluation board)
//! will be configured in 115,200 baud, 8-n-1 mode. All characters received on
//! the UART are transmitted back to the UART.
//
//*****************************************************************************


//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UART0IntHandler(void)
{
unsigned long ulStatus;

//
// Get the interrrupt status.
//
ulStatus = ROM_UARTIntStatus(UART0_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART0_BASE, ulStatus);

//
// Loop while there are characters in the receive FIFO.
//
while(0)//ROM_UARTCharsAvail(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
// ROM_UARTCharPutNonBlocking(UART0_BASE,
// ROM_UARTCharGetNonBlocking(UART0_BASE));

//
// Blink the LED to show a character transfer is occuring.
//
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

//
// Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks.
//
SysCtlDelay(SysCtlClockGet() / (1000 * 3));

//
// Turn off the LED
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

}
}

void
UART2IntHandler(void)
{
unsigned long ulStatus;

//
// Get the interrrupt status.
//
ulStatus = ROM_UARTIntStatus(UART2_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART2_BASE, ulStatus);

//
// Loop while there are characters in the receive FIFO.
//
while(0)//ROM_UARTCharsAvail(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
// ROM_UARTCharPutNonBlocking(UART0_BASE,
// ROM_UARTCharGetNonBlocking(UART0_BASE));

//
// Blink the LED to show a character transfer is occuring.
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

//
// Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks.
//
SysCtlDelay(SysCtlClockGet() / (1000 * 3));

//
// Turn off the LED
//
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

}
}

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
}
}

void
UART2Send(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART2_BASE, *pucBuffer++);
}
}

//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPUEnable();
ROM_FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

//
// Enable the GPIO port that is used for the on-board LED.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

//
// Enable the GPIO pins for the LED (PF2).
//
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);


//
// Enable processor interrupts.
//
ROM_IntMasterEnable();

//
// Set GPIO A0 and A1 as UART pins.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

GPIOPinConfigure(GPIO_PD6_U2RX);
GPIOPinConfigure(GPIO_PD7_U2TX);
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);


//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

ROM_UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));


//
// Enable the UART interrupt.
//
ROM_IntEnable(INT_UART0);
ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

ROM_IntEnable(INT_UART2);
ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);


//
// Prompt for text to be entered.
//
//UARTSend((unsigned char *)"\033[2JEntertext0: ", 16);

//
// Loop forever echoing data through the UART.
//
while(1)
{
UARTSend((unsigned char *)"\033[2JEntertext0: ", 16);
UART2Send((unsigned char *)"\033[2JEntertext2: ", 16);
}
}

  • Hi Yoo Jin,

        As far as I know, I do not see anything wrong with your initialization .

    YOO JIN said:
    I would like to see both PD7 and PA1 signals with Oscilloscope.

    1. PA1 is connected to ICDI. I don't think you would be able to tap that signal easily.
    2. PD7/U2TX can be probed at J4. But as you have said, you can not see any signals from oscilloscope. Another way to verify that UART2 works is to configure it in loopback mode, and see if you are able receive the data that you sent through UART2.

    -kel

  • Have not your board - nor that MCU.  However - many other LX4F MCU employ PD7 as NMI - and thus a special "unlocking procedure" must be followed to "repurpose" that pin to other use.  (UART - your case!)

    Gory detail - to achieve that "repurpose" well listed in MCU data manual.  I'd bet 1/2 "vessel under sail" - this is your issue...  

    Advanced ARM MCUs provide great flexibility - but require that each/every pin be surveyed for correctness of purpose...

     

  • Thanks for your comments.

    Here is my test results before your comments

    When Multiple UARTs are wanted, only UART2 is not signaled on EK-LM4F120XL LaunchPad
    I apply hello project in TivaWare_C_Series-1.0 on EK-LM4F120XL.

    My test result is that UART0,1,3~7 are OK except UART2.

    UART2 does not make me sense.
    Are there any specific configuration for UART2?


    - Test Conditions-

    First, I understand that UARTStdioConfig() supports from 0 to 2.

    So, I changed uartstdio.c to support all 8 uarts as follows;

    static const uint32_t g_ui32UARTBase[8] =
    {
    UART0_BASE, UART1_BASE, UART2_BASE,
    UART3_BASE, UART4_BASE, UART5_BASE,
    UART6_BASE, UART7_BASE
    };


    static const uint32_t g_ui32UARTInt[8] =
    {
    INT_UART0, INT_UART1, INT_UART2,
    INT_UART3, INT_UART4, INT_UART5,
    INT_UART6, INT_UART7
    };

    static const uint32_t g_ui32UARTPeriph[8] =
    {
    SYSCTL_PERIPH_UART0, SYSCTL_PERIPH_UART1, SYSCTL_PERIPH_UART2,
    SYSCTL_PERIPH_UART3, SYSCTL_PERIPH_UART4, SYSCTL_PERIPH_UART5,
    SYSCTL_PERIPH_UART6, SYSCTL_PERIPH_UART7
    };

    Second, I configure UARTs from 0 to 7 to use UARTprintf() as follows;
    When test is doing, proper PINs are applied according to the number of UART.

    ConfigureUART(void)
    {
    //
    // Enable the GPIO Peripheral used by the UART.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    //
    // Enable UART7
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);

    //
    // Configure GPIO Pins for UART mode.
    //
    ROM_GPIOPinConfigure(GPIO_PE0_U7RX);
    ROM_GPIOPinConfigure(GPIO_PE1_U7TX);
    ROM_GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Use the internal 16MHz oscillator as the UART clock source.
    //
    UARTClockSourceSet(UART7_BASE, UART_CLOCK_PIOSC);

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(7, 115200, 16000000);
    }

  • YOO JIN said:

    UART2 does not make me sense.
    Are there any specific configuration for UART2?

    Earlier post provided cause/effect/cure for your UART2 issue.  (caveat - PD7 re-purposed as UART from its default NMI Status)

    MCU data manual describes - roadmaps the re-purpose...

  • cb1_mobile said:
    Earlier post provided cause/effect/cure for your UART2 issue.  (caveat - PD7 re-purposed as UART from its default NMI Status)

    Thanks for your comment.

    Regards

    YOO

  • @Yoo Jin

    cb1 is correct. See below from section 10.2.4 GPIO at LM4F120 datasheet.

    Commit Control

    "The GPIO commit control registers provide a layer of protection against accidental programming of
    critical hardware peripherals. Protection is provided for the GPIO pins that can be used as the four
    JTAG/SWD pins (PC[3:0])and the NMI pin (PD7 and PF0). Writes to protected bits of the GPIO
    Alternate Function Select (GPIOAFSEL) register (see page 632), GPIO Pull Up Select (GPIOPUR)
    register (see page 638), GPIO Pull-Down Select (GPIOPDR) register (see page 640), and GPIO
    Digital Enable (GPIODEN) register (see page 643) are not committed to storage unless the GPIO
    Lock (GPIOLOCK) register (see page 645) has been unlocked and the appropriate bits of the GPIO
    Commit (GPIOCR) register (see page 646) have been set."

    I have not done the unlocking procedure myself. See unlocking procedures from TI Joe at the post below. Take note that this unlocking procedure is for LM3S5P31. But, if you don't want to do this, just use the other UART ports.

    http://e2e.ti.com/support/microcontrollers/stellaris_arm/f/471/t/63836.aspx?pi24929=1

    -kel