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.

TM4C1294NCPDT: UARTCharPut hangs as though UART is not enabled

Part Number: TM4C1294NCPDT


I have successfully used UARTCharGet and UARTCharPut  for sending and receiving a small number of bytes less than the FIFO size of 16.

Now I am sending more than 16 bytes and the UARTCharPut  function hangs indefinitely waiting for the FIFO to have a spot available in it.  Sometimes a FaultISR is raised.

It is as though the UARTEnable function has not been called (but is has inside UARTConfigSetExpClk), or it is as though subsequent to the UART being enabled, the UARTDisable function has been called.   However I find no such calls in my code nor in any TIVAware library code I am using.  I know I write to the 16 byte FIFO with more than 16 chars in quick succession, but then I am happy for the UARTCharPut  function to block waiting for the FIFO to empty out one or more of its elements.

I am not using interrupts and have not enabled them. 

I have attempted to use the UARTCharPut NonBlocking option after first waiting for UARTSpaceAvail to return true, to no avail.   The only way I have found to overcome this problem is to put a large delay prior to a run of a few calls to UARTCharPut  as follows

ROM_SysCtlDelay(200000);
UARTCharPut(Command_UART_PORT_with_EP,0x23);//reply with get filter type cmd
UARTCharPut(Command_UART_PORT_with_EP,(uint8_t)FilterChannel);//reply with channel
UARTCharPut(Command_UART_PORT_with_EP,(uint8_t)FilterType);

What possible reason can explain this behaviour ?

BTW here is my UART init routine:

void initialise_UART_with_EP(void)
{
	Command_UART_PORT_with_EP=UART6_BASE;

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); //EP to SP UART for Commands
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6); //enable EP to SP UART6.

	GPIOPinConfigure(GPIO_PP0_U6RX);//UART for commands between EP and SP
	GPIOPinConfigure(GPIO_PP1_U6TX);//UART for commands between EP and SP
	GPIOPinTypeUART(GPIO_PORTP_BASE, GPIO_PIN_0 | GPIO_PIN_1);//UART for commands between EP and SP

	UARTConfigSetExpClk(Command_UART_PORT_with_EP, ui32SysClock, 80000,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
}

  • Hi Peter,

     I wrote a small example on UART0 and observed both the terminal window and the scope and I don't see problem. I didn't need to add any delay. Looking at your code you have a baud rate of 80000 which is a bit odd to me. Can you try 115200 with your code and also my code?

    int
    main(void)
    {
        uint32_t ui32SysClock;
    
    
        ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN |
                                           SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);
    
    
        //
        // Enable the peripherals used by this example.
        // The UART itself needs to be enabled, as well as the GPIO port
        // containing the pins that will be used.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the GPIO pin muxing for the UART function.
        // This is only necessary if your part supports GPIO pin function muxing.
        // Study the data sheet to see which functions are allocated per pin.
        // TODO: change this to select the port/pin you are using
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Since GPIO A0 and A1 are used for the UART function, they must be
        // configured for use as a peripheral function (instead of GPIO).
        // TODO: change this to match the port/pin you are using
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Configure the UART for 115,200, 8-N-1 operation.
        // This function uses SysCtlClockGet() or ui32SysClock to get the system clock
        // frequency.  This could be also be a variable or hard coded value
        // instead of a function call.
        //
    
        UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));
    
        while (1) {
    		UARTCharPut(UART0_BASE, 'a');
    		UARTCharPut(UART0_BASE, 'b');
    		UARTCharPut(UART0_BASE, 'c');
    		UARTCharPut(UART0_BASE, 'd');
    		UARTCharPut(UART0_BASE, 'e');
    		UARTCharPut(UART0_BASE, 'f');
    		UARTCharPut(UART0_BASE, 'g');
    		UARTCharPut(UART0_BASE, 'h');
    		UARTCharPut(UART0_BASE, 'i');
    		UARTCharPut(UART0_BASE, 'j');
    		UARTCharPut(UART0_BASE, 'k');
    		UARTCharPut(UART0_BASE, 'l');
    		UARTCharPut(UART0_BASE, 'm');
    		UARTCharPut(UART0_BASE, 'n');
    		UARTCharPut(UART0_BASE, 'o');
        }
    
    }

  • Thanks for your reply Charles. When I tried code identical to yours it worked OK for me as well. (I created 20 lines, each sending a letter of the alphabet with UARTCharPut) and I noted the buffer filled up after line 16 as expected.

    This means the act of calling UARTCharPut() more than 16 times in quick succession is not the cause of my problem. I upped the baud rate from 80K to 115,2K and that didn't solve the problem.

    Something else in my code is causing the UARTCharPut to hang and then often raise a FaultISR if I comment out the ROM_SysCtlDelay(200000); in my above code.

    Using TI's document spma043.pdf (for Debugging FaultISR ) I tried investigating the FaultISR but it wasn't descriptive enough. All I learnt was that the Vector Number was 03 corresponding to a fault description of "Processor exceptions".

    A lot of other things are happening on the MCU so without narrowing it down I'm unsure what code to copy and paste.

    What else can I try ?

  • BTW in order to get the above code example you gave to work I had to take it out of the module where I normally call UARTCharPut() and place it into the main{} function as you did. When placed in the original module, only two calls to UARTCharPut() work, the 3rd call to UARTCharPut() hangs.
  • Hi Peter,
    Where are you calling the UARTCharPut()? What do you mean you had to take it out of the 'module? Can you show complete code where you call UARTCharPut()?
  • Hi Charles,

    I'm calling it in another *.c file (hence module).  my project is large and many things happen before and after that call and unless you can run the entire project then I don't know what parts to give you.  So what I am doing is commenting out sections bit by bit until the error goes away.  I'll let you know what I uncover.

    Thanks

    Peter

  • Hi Charles,

    I spent time commenting out plenty of things that happen prior to my UARTCharPut() calls to see if I can remove my sysctrldelay call but I have not been successful. I might put the investigation on hold and contribute again if I uncover something else in passing,

    regards
    Peter
  • Hi Peter,
    Let us know your result once you restart your investigation and you can always reopen the post or create a new post. For now, I will close the thread.