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

**URL:** <https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361>\
**Category:** IoT Modules\
**Created:** [May 18, 2020, 11:55am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361 "2020-05-18T11:55:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vimal.babu](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vimal.babu](https://forum.sierrawireless.com/u/vimal.babu)\
**Post date:** [May 18, 2020, 11:55am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/1 "2020-05-18T11:55:37Z")

</div>

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 = ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½

---

<div class="post-metadata">

**Author:** ![Donald](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Donald](https://forum.sierrawireless.com/u/Donald)\
**Post date:** [May 20, 2020, 10:02am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/2 "2020-05-20T10:02:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vimal.babu](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vimal.babu](https://forum.sierrawireless.com/u/vimal.babu)\
**Post date:** [May 20, 2020, 10:49am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/3 "2020-05-20T10:49:27Z")

</div>

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](mailto: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

---

<div class="post-metadata">

**Author:** ![Donald](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Donald](https://forum.sierrawireless.com/u/Donald)\
**Post date:** [May 21, 2020, 1:54am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/4 "2020-05-21T01:54:16Z")

</div>

Hi @vimal.babu

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

---

<div class="post-metadata">

**Author:** ![lotam](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@lotam](https://forum.sierrawireless.com/u/lotam)\
**Post date:** [May 21, 2020, 2:55am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/5 "2020-05-21T02:55:52Z")

</div>

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.

> [@Problem with Reading UART](https://forum.sierrawireless.com/t/problem-with-reading-uart/13322/2):
>
> Which module are you using ? I remember in WP77 R8, the UART will go to sleep mode after some time. Maybe you can have a try on R9 FW. Or you can try using a timer to periodically wake up the UART; #define TIMER\_INTERVAL\_SEC 1 #define TIMER\_INTERVAL\_uSEC 100000 int fd1; static void tmrHandler(le\_timer\_Ref\_t timerRef) { //LE\_INFO(“INSIDE TIMER”); tcflow(fd1,TCION ); } COMPONENT\_INIT { fd1=OpenPort("/dev/ttyHS0"); le\_clk\_Time\_t clk = { .sec = TIMER\_INTERVAL\_SEC, .usec = TIMER\_INT…

Thanks

---

<div class="post-metadata">

**Author:** ![vimal.babu](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vimal.babu](https://forum.sierrawireless.com/u/vimal.babu)\
**Post date:** [May 21, 2020, 4:55am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/6 "2020-05-21T04:55:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vimal.babu](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vimal.babu](https://forum.sierrawireless.com/u/vimal.babu)\
**Post date:** [May 21, 2020, 5:12am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/7 "2020-05-21T05:12:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/jyijyi/32/4766_2.png) [@jyijyi](https://forum.sierrawireless.com/u/jyijyi)\
**Post date:** [May 22, 2020, 12:44am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/8 "2020-05-22T00:44:14Z")

</div>

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

> **[AT Commands Server & UART](https://forum.legato.io/t/at-commands-server-uart/4747/5)**
>
> In WP7702 the UART1 driver have the power management independent of system suspend/resume. UART1 wakeup can be triggered by RX or TX activity. But before it wakes up from RX, it loses several bits from the RX and then got out of sync. The default...

---

<div class="post-metadata">

**Author:** ![Donald](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Donald](https://forum.sierrawireless.com/u/Donald)\
**Post date:** [May 22, 2020, 2:45am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/9 "2020-05-22T02:45:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vimal.babu](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vimal.babu](https://forum.sierrawireless.com/u/vimal.babu)\
**Post date:** [May 27, 2020, 4:33am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/10 "2020-05-27T04:33:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Donald](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Donald](https://forum.sierrawireless.com/u/Donald)\
**Post date:** [May 28, 2020, 10:59am UTC](https://forum.sierrawireless.com/t/legato-uart-read-junk-character-read-after-wake-up-ar759x/20361/11 "2020-05-28T10:59:41Z")

</div>

Hi vimal.babu

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

> **[AT Commands Server & UART](https://forum.legato.io/t/at-commands-server-uart/4747/3)**
>
> Probably power saving is activated, you can install devmode as a quick/dirty fix. Or add calls to power manager in your application and disable power saving mode trough legato commands.
