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.

Linux/AM5718: UART write error

Part Number: AM5718

Tool/software: Linux

I am using AM5718 IDK EVM,and ti-processor-sdk-linux-am57xx-evm-05.03.00.07. No LCD is connected and jumper J51 is open.

I understand that RS485 (UART2) corresponds to "/dev/ttyS1".

When I try the code snippet given below, open is successful, but write fails.

code
-----------------------------------------------------------------

#define UART2_FILE_NAME "/dev/tty1"

char buf[512] = {0X41, 0x42, 0x43, 0x44, 0x45, 0x46};

if ((int_FPUart2 = open(UART2_FILE_NAME, O_RDWR)) < 0) {

    printf("Failed to open uart2%s\n", UART2_FILE_NAME);

    exit(1);

}

if( write(int_FPUart2, buf, 6)==6)
     printf("Writing uart2 ok\n");

else
     printf("Error Writing uart2\n");

------------------------------------------------------
if I try the command "stty -F /dev/ttyS1", I get the following error:

"stty: /dev/ttyS1: Input/output error"


What should I do to enable and write to UART2 in the EVM?

  • Hello, the person that is best to respond is out for a couple of days and will reply with more information later this week. I'm sorry for the delay.

  • Hi,

    UART2 is not enabled in device tree for AM5718 IDK EVM, so you cannot access ttyS1 in Linux.

    You won't be able to use UART2 on AM5718 IDK EVM either, because its RS485 transceiver (U77) is designed to be controlled by PRU but the SDK doesn't provide a PRU firmware to do so.

  • Thank you for your reply.

    I want to know one more information. Other than UART3, which UART can I access on AM 5718 EVM? I want to try out
    UART functions from user space.

    regards,

    Anupama

  • Hi,

    ""won't be able to use UART2 on AM5718 IDK EVM"" Why do you say so??

    The Pinmux of AM5718 IDK shows UART2 connected to D28,D26. Emulating RS485 may not be possible but as I understand UART 2 can be used as bare UART provided Linux has access to this peripheral. 

    With a suitable modification in hardware (R583,R582 removed) I guess I can looping them and test the UART2  . As i understand once I remove off R583 and R582 the dependence on PRU is negated.Correct me if I am wrong??

    We are not trying to test U77 RS485 feature. 

    Aim is to invoke a UART channel , add it to device tree and test its functionality.

  • I said that referring to the unmodified board. Of cause you can do a lot more with hardware modifications.

    yes, you can use UART2 RXD & TXD signals if you disconnect the RS-485 transceiver.

  • Anupama Krishnapillai said:
    I want to know one more information. Other than UART3, which UART can I access on AM 5718 EVM?

    You can check the board schematics. UART1 RXD/TXD are routed to the expansion header J21.

  • Hi, 

    1. While searching DTS related to UART3, I am finding the following values related to pin-muxing. Can you explain/give links explaining how to derive the values 0x248 and 0x3f8 ?

    2. Other than hardware changes, are these the only places in DTS that I need to modify to get my UART1 working ?


    -----am57xx-idk-common.dtsi-----------------------------------------------
    &uart3 {
    status = "okay";
    interrupts-extended = <&crossbar_mpu GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH
    &dra7_pmx_core 0x248>;
    };


    -----am57xx-beagle-x15-common.dtsi-----------------------------------------------
    &uart3 {
    status = "okay";
    interrupts-extended = <&crossbar_mpu GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>,
    <&dra7_pmx_core 0x3f8>;

       regards,

    Anupama

  • Anupama,

    Please check the following forum thread.

  • Hi,


        Thank you for your reply. I went through the links. Following changes were done in am57xx-idk-common.dtsi
    to enable UART1 and UARt2:

    1)    -------------------- am57xx-idk-common.dtsi------------------------
    &uart1 {

     status = "okay";

    interrupts-extended = <&crossbar_mpu GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH
     
    &dra7_pmx_core 0x3E0>;

    };

    &uart2 {
    status = "okay";
    interrupts-extended = <&crossbar_mpu GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH

     &dra7_pmx_core 0x3f0>;


    };

    2) 

    Uart_Settings.txt
    struct termios termios_Settings;
    if ((int_FPUart2 = open(UART2_FILE_NAME, O_RDWR)) < 0) 
    {		
    	printf("Failed to open uart1%s\n", UART2_FILE_NAME);
    
    	exit(1);	
    }
    	
    
    
    	
    	tcgetattr(int_FPUart2, &termios_Settings);
    
    	ispeed = cfsetispeed(&termios_Settings, B9600);
    	
    	ospeed = cfsetospeed(&termios_Settings, B9600);
    	
    
    
    	termios_Settings.c_cflag  &= ~PARENB; //no parity
    	termios_Settings.c_cflag  &= ~CSTOPB; //Stop bits =1
    
    	termios_Settings.c_cflag &= ~CSIZE; /* Clears the Mask       */
    	termios_Settings.c_cflag |=  CS8;   /* Set the data bits = 8 */
    
    	termios_Settings.c_cflag  &= ~CRTSCTS; //turn off hw flow ctrl
    	termios_Settings.c_cflag  |= (CREAD |CLOCAL); 
    
    	termios_Settings.c_iflag  &= ~(IXON | IXOFF | IXANY); //turn off sw flow ctrl, XON/XOFF
    
    	termios_Settings.c_oflag  &= ~OPOST; //raw o/p
    
    	termios_Settings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG); //non-Canonical mode - raw model
    
    	if (tcsetattr(int_FPUart2, TCSAFLUSH, &termios_Settings) == 0)
    	{
    		printf("Serial Set Attr successfully\n");
    	}
    Pin-mux for UART1, and UART2 were set in mux_data.h
      ----------------mux_data.h--------------------------------------------------------------

    {UART1_RXD, (M0 | PIN_INPUT | SLEWCONTROL)}, /* uart1_rxd.uart1_rxd */

    {UART1_TXD, (M0 | PIN_OUTPUT | SLEWCONTROL)}, /* uart1_txd.uart1_txd */

    {UART2_RXD, (M4 | PIN_INPUT)}, /* uart2_rxd.uart2_rxd */

    {UART2_TXD, (M0 | PIN_OUTPUT)}, /* uart2_txd.uart2_txd */

    ---------------------------------------------------------------

    Now I'm able to open and write to the UARTS. I also face the following issue:

    3) When we receive a character through UART2, it is automatically transmitted through the TX pin. Verified this using oscilloscope connected to Tx and Rx pins.

    If we loop back the Tx and Rx pins and write some character to the UART, it goes on in a loop.

    The settings done for UART is attached.

    Can you ensure the correctness of settings done in 1) and 2) and can give me a guidance on issue mentioned in 3) ?

    regards,

    Anupama

  • Hi,

           A gentle reminder..

    regards,

    Anupama

  • Hi Anupama,

    I am not sure what causes the received chars routed to TX again. You don't see the problem with UART1, but only on UART2? Did you remove resister R582 and R583 to disconnect the R-485 transceiver?

    Anupama Krishnapillai said:

      ----------------mux_data.h--------------------------------------------------------------

    {UART1_RXD, (M0 | PIN_INPUT | SLEWCONTROL)}, /* uart1_rxd.uart1_rxd */
    {UART1_TXD, (M0 | PIN_OUTPUT | SLEWCONTROL)}, /* uart1_txd.uart1_txd */
    {UART2_RXD, (M4 | PIN_INPUT)}, /* uart2_rxd.uart2_rxd */
    {UART2_TXD, (M0 | PIN_OUTPUT)}, /* uart2_txd.uart2_txd */

    Are this pin mux setttings done in core_padconf_array_essential_am571x_idk[] in board/ti/am57xx/mux_data.h?

    Can you try to use the same mode M0 or M4 for both UART2 RX and TX pins?

  • Hi,

            I have followed your suggestions. There was a misunderstanding in my configuration of the UART. I had configured the canonical mode. After changing it,  UART2 and UART1 are working now.      

    I also dont know what caused the received chars routed to TX.

              Thank You for your support.

    Anupama

  • Hi Anupama,

    Thanks for the update.

    Anupama Krishnapillai said:
    There was a misunderstanding in my configuration of the UART. I had configured the canonical mode. After changing it,  UART2 and UART1 are working now.   

    So RX chars don't route to TX anymore after configured to use non-canonical mode?

  • Hi Bin Liu,

                   No,  RX chars are not routed to TX after configuring non-canonical mode. Is there any explanation for this?

    Though I have got the muxmode value M4 for UART2_RXD and M0 for UART2_TXD from the TI pin-mux tool,  I have  changed the muxmode of both UART2_RXD and UART2_TXD to M4 as suggested by you.

    regards,

    Anupama

  • Anupama,

    Sorry, I don't have an explanation about the canonical mode. I never used it before. My suggestion of M4 vs. M0 mode was just for ruling out any factors of the cause.

    So even if RXD/TXD pins are in both M4 mode, but with canonical mode, RX chars are still routed to TX? If so, it sounds it is the canonical mode setting which causes the problem, not the pinmux setting. Is it correct?

  • Hi Bin Liu,

                    When RXD/TXD pins are both in M4 mode and canonical mode is configured, RX chars are not routed to TX. So I'm confused what caused the routing of RX chars to TX in the initial setup.

    I will try to do a) and b) one at a time to find the issue i.e.

    a) Not setting M4 

    b) Not setting canonical mode.

    regards,

    Anupama