Legato Uart Read junk character , Read after wake up , Ar759x

Hi,

We are facing an issue with the uart read after wake up, it is returning junk characters, Ar759x is used, Kindly please suggest a way

following are the code example

#define SERIAL_PORT “/dev/ttyHS0”
#define PARITY ‘N’
#define WORD_SIZE (8)
#define STOP_BIT (1)
#define READ_TIMEOUT (5)

#define HEX_100_VALUE (0x100)
#define INITIAL_VALUE ((uint8_t)0u)
#define MSG_MAX_SIZE (256)

static void serialFdMonitorHandler(int pFd, short pEvents)
{
ssize_t len;
char arr[MSG_MAX_SIZE] = {0};

if (pEvents & POLLIN ){
	sprintf(arr,"%s","");

		len = read(pFd, arr, sizeof(arr));	
		arr[len] = '\0';
		if(len < 0){
			LE_INFO("Failed");
		}else{
			printf("\n");
			printf("Buffer = %s\n", arr);
			/* Discards old data in the rx buffer */
			tcflush( pFd, TCIFLUSH);
		}
}	

}

STATUS UartProcess_Init(void_t)
{
STATUS en_resStatus;

/*------------------------------- Opening the Serial Port -------------------------------*/
s32_fd  = le_tty_Open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
if(s32_fd >= 0){
	if(LE_OK == le_tty_SetBaudRate(s32_fd, LE_TTY_SPEED_115200)){
        /* Set framing on serial port */
        /* Parity - No Parity, Word Size - 8 bit, Stop Bit - 1 */
        if(LE_OK == le_tty_SetFraming(s32_fd, PARITY, WORD_SIZE, STOP_BIT)){
            /* Set flow control option on serial port - None*/
            if(LE_OK == le_tty_SetFlowControl(s32_fd, LE_TTY_FLOW_CONTROL_NONE)){
                /* Disables conversion of EOL characters, disables local echo, sets character mode, read timeouts */
                if(LE_OK == le_tty_SetRaw(s32_fd, MSG_MAX_SIZE, READ_TIMEOUT)){
					SerialFdMonitor = le_fdMonitor_Create("SerialPort", s32_fd, serialFdMonitorHandler,POLLIN);
					en_resStatus = SUCCESS;
				}else{
                    en_resStatus = FAILURE;
                }
            }else{
                en_resStatus = FAILURE;
            }
        }else{
            en_resStatus = FAILURE;
        }
    }else{
        en_resStatus = FAILURE;
    }
}else{
    en_resStatus = FAILURE;
}
return en_resStatus;

}

Output :

Buffer = �������������������������������������������������������������������

Buffer = ���������������������������������������������������������������������������������������

Buffer = �������������������������������������������������������������������������������������������

Hi vimal.babu

Which firmware version are you using?
Can you please describe step by step how to reproduce this issue?
Can you reproduce it without the Legato application?
Can this issue be reproduced with hard reset, power on/off?
What is the reproducible of this problem? Is it reproduced with the stress tests?

You can try to enable hardware flow control.

Hardware Serial Number: 1401150_Rev_5

Which firmware version are you using?

legato version
17.10.0.m1.rc28_4fa247c026489245e70a35638f9b5dbb_modified

Can you please describe step by step how to reproduce this issue?

Steps to reproduce…

Step1 ) Install legato app

$ app install uartApp.ar759x.update 192.168.225.1 

Step2 ) Start the application in legato, we are able to take ssh to the board
$ ssh root@192.168.225.1

Step3) To confirm uart1 is available for linux app

$ uartMode set 1 app
$uartMode get 1
	UART1 is available for use by Linux applications.

Step4) Start the uartApp in legato

$ app start uartApp

Step5 ) The development kit Air prime is connected to PC through uart 1, in PC side we are sending some charcaters with \n termination to uartApp

Note

  1. After starting uartApp . At PC side if we wait for about 5 to 6 sec and send a data to uartApp it will show junk characters in logread

  2. If we start uartApp and PC side app and there is no delay in sending data to uartApp will received data properly, verfied in logread

Can you reproduce it without the Legato application?
Does the means like using normal linux api, we have done that also, but the result remains the same, junk received.

Can this issue be reproduced with hard reset, power on/off?
We are not doing the hardreset , or power on/off , because app stop /start itself the uart issues come.

What is the reproducible of this problem? Is it reproduced with the stress tests?
Every time we are facing this issue, no need for any stress test, issue can easily be reproduced.

You can try to enable hardware flow control.
Yes we have given LE_TTY_FLOW_CONTROL_HARDWARE but still we obtain junk

Hi @vimal.babu

Could you help to share your full uartApp file so that I can try with my device?

Hi Donald, Vimal,

I would guess the junk char is just because of UART sleep after idle.

A quick test is to send below when issue happened, and ideally app uart read should recover

stty -F /dev/ttyHS0 115200

Once confirmed, please consider using stty or below routine to keep UART active, to avoid entering this situation.

Thanks

Hi,

We have tried tcflow(fd1,TCION ); command in a timer , so uart wont go to sleep when idle. But we require Power management , so when uart dont receive any data it should go to sleep, and when a data receives it should wakeup and receive data.

Regards,
Vimal Babu

Hi,

i tried to upload the files here but not allowing please so i am copying entire code here

/----Capture System Header---------------------------------------------------/
#include<string.h>
/---- Capture the header prepared by user -----------------------------------/
#include “legato.h”
#include “interfaces.h”
#include “eCallUartHandler.h”
#include <termios.h>
/----#define macro used only within your file--------------------------------/

#define SERIAL_PORT “/dev/ttyHS0”
#define PARITY ‘N’
#define WORD_SIZE (8)
#define STOP_BIT (1)
#define READ_TIMEOUT (0)
#define COMM_BAUDRATE (B115200)
#define PC_COMM_RD_MIN_SIZE (0)
#define COMM_READ_TIMEOUT (0)

#define HEX_100_VALUE (0x100)
#define INITIAL_VALUE ((uint8_t)0u)
#define MSG_MAX_SIZE (256)
#define ECALL_WAKEUP_SRC “eCall_WakeupSrc”
/----The #define Function Type Macro used only within your file -------------/

/----The typedef definition used only within your file-----------------------/

/----The enum tag definition used only within your file----------------------/

/----Struct/Union tag definition used only within your file------------------/

/----Static Variable Declaration shared within a file------------------------/
static int32_t s32_fd;
le_fdMonitor_Ref_t SerialFdMonitor = NULL;
le_pm_WakeupSourceRef_t eCallWakeupSrc;

/----Global variable definitions---------------------------------------------/

/* Thread id of PcCommHandler thread */

/----Static Function Prototype Declaration----------------------------------/
//static void serialFdMonitorHandler(int pFd, short pEvents);
/----Function Definitions---------------------------------------------------/
COMPONENT_INIT
{
STATUS en_resStatus;

    en_resStatus = UartProcess_Init();
    if(SUCCESS == en_resStatus){
            LE_INFO("Initialization Failure");
    }else{
            LE_INFO("Initialization successful");
    }
    return;

}

/******************************************************************************
.Purpose : Serial Port Monitor Thread
.Arguments : NIL
.Returns : NIL
.Note :
******************************************************************************/

static void serialFdMonitorHandler(int pFd, short pEvents)
{
ssize_t len;
char arr[MSG_MAX_SIZE] = {0};

if (pEvents & POLLIN ){
    sprintf(arr,"%s","");
        len = read(pFd, arr, sizeof(arr));
        arr[len] = '\0';
        if(len < 0){
            LE_INFO("Failed");
        }else{
            printf("\n");
            printf("Buffer = %s\n", arr);
            /* Discards old data in the rx buffer */
            tcflush( pFd, TCIFLUSH);
        }
}else{

    printf("Something fishy\n ");
}

}

STATUS UartProcess_Init(void_t)
{
STATUS en_resStatus;

    /*------------------------------- Opening the Serial Port -------------------------------*/
    s32_fd  = le_tty_Open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
    if(s32_fd >= 0){
            if(LE_OK == le_tty_SetBaudRate(s32_fd, LE_TTY_SPEED_115200)){
                    /* Set framing on serial port */
                    /* Parity - No Parity, Word Size - 8 bit, Stop Bit - 1 */
                    if(LE_OK == le_tty_SetFraming(s32_fd, PARITY, WORD_SIZE, STOP_BIT)){
                            /* Set flow control option on serial port - None*/
                            if(LE_OK == le_tty_SetFlowControl(s32_fd, LE_TTY_FLOW_CONTROL_NONE)){
                                    /* Disables conversion of EOL characters, disables local echo, sets character mode, read timeouts */
                                    if(LE_OK == le_tty_SetRaw(s32_fd, MSG_MAX_SIZE, READ_TIMEOUT)){
                                            SerialFdMonitor = le_fdMonitor_Create("SerialPort", s32_fd, serialFdMonitorHandler,POLLIN);

                                            en_resStatus = SUCCESS;
                                    }else{
                                            en_resStatus = FAILURE;
                                    }
                            }else{
                                    en_resStatus = FAILURE;
                            }
                    }else{
                            en_resStatus = FAILURE;
                    }
            }else{
                    en_resStatus = FAILURE;
            }
    }else{
            en_resStatus = FAILURE;
    }
    return en_resStatus;

}
/----End of File------------------------------------------------------------/

Please help me to solve this issue

Regards,
Vimal Babu

Seems this is the behavior, not sure if your host can adjust.

Hi @vimal.babu

It is a behavior of AR75xx module. The default auto suspend delay UART1 ( /dev/ttyHS0) is 5 seconds.
You can use UART2 (/dev/ttyHSL1) for uart read data.

Hi @Donald,

Thank you very much for the help.

We have switched to the uart2 and the result are the following

  1. Uart2 doesnot give any junk characters
  2. But Uart2 some of the characters are missing

eg if total command to be received was. “eCall-start manual 112 89”, some time i am receving only “eCal”, or “-start manual 112” or “manual 112 89”

If possible can you please share a code that receives perfectly with a FdMonitorHandler

Regards,
Vimal Babu

Hi vimal.babu

Did you try to increase the auto suspend delay on UART1 as suggested by jyijyi?