Uart read fdmonitor not working after few minutes

I am faced the issue in uart fdmonitor handler,uart baudrate 460800. uart get interrupt every 1 milli second.

  1. In fdmonitor handler when we report a le_event_Report function it will work few minute,
    after that fdmonitor handler is not calling.
  2. cat /dev/ttyHS1 is also not printing any data.
  3. If we remove le_event_Report function from the fdmonitor handler it will work fine.
  4. if we restart app it work again.

please attach the application here
Please also try in WP76 R10.1 as i don’t see problem with that, not sure if issue happened only with 1ms interrupt

sorry your website is not supporting new user file attachement. please check below
root@swi-mdm9x28-wp:~# cm info
Device: WP7608
IMEI: 35291309036xxxx
FSN: 3N050785621410
Firmware Version: SWI9X07Y_02.28.03.03 000000 jenkins 2019/05/21 03:33:04
Bootloader Version: SWI9X07Y_02.28.03.03 000000 jenkins 2019/05/21 03:33:04
MCU Version: 002.011
PRI Part Number (PN): 9908665
PRI Revision: 001.002
Carrier PRI Name: GENERIC
Carrier PRI Revision: 002.068_000
SKU: 1104194
Last Reset Cause: Reset, User Requested
Resets Count: Expected: 79 Unexpected: 0
root@swi-mdm9x28-wp:~# legato version

.c file*****

static mcuApp_t App1;
mcuApp_t* hApp = &App1;

int WriteToUart(const uint8_t *wBuf , uint32_t wLen)
int retLen;
int offset=0;
LE_INFO(“seraia fd:%d”, hApp->serialFd);

PRINTDATAINHEX(“UWRITE”, (uint8_t*)wBuf, wLen);
while(offset < wLen)
retLen = write( hApp->serialFd ,wBuf+offset ,wLen-offset);
if(-1 == retLen)
else if(retLen <= (wLen-offset))
offset = offset + retLen;
retLen = offset;
LE_INFO(“Uart write byte count:%d” ,retLen);

LE_INFO(“Uart Total write byte count:%d Recieved len:%d”,offset ,wLen);
LE_INFO("write to uart :%d ", retLen);
return retLen;

uint32_t fdmonitorCount=0;
uint32_t CheckMessageCount=0;
tm_Data_t ParseData;
void CheckMessageHdlr(void
LE_INFO("%s", func);
LE_INFO(“eventCount checkMessge:%d”, CheckMessageCount++);
ParseData = (tm_Data_t*)ctx;
PRINTDATAINHEX(“read data”, ParseData->Buf, ParseData->bLen);


  • AsyncRecvHandler () → Callback func for UART fd_monitor ,events(POLLIN).
    tm_Data_t tmpData;
    void AsyncRecvHandler (int fd, short event)
    int retval = -1;
    LE_INFO("%d %s %#x ",fd ,FUNCTION, event);

if((event & POLLIN))
LE_INFO(“eventCount fdmonitor:%d”,fdmonitorCount++);
memset(hApp->RxBuf, 0, sizeof(hApp->RxBuf) );
retval = read(fd, hApp->RxBuf, sizeof(hApp->RxBuf));

if(retval > 0 )

#if 1
memset(&tmpData, 0, sizeof(tmpData) );
tmpData.bLen = retval;
memcpy( &tmpData.Buf, hApp->RxBuf, retval);
le_event_Report(hApp->CheckMsgEvtId, &tmpData, sizeof(tmpData));//

if(event & POLLOUT)
le_fdMonitor_Disable(hApp->fdMonitorRef, POLLOUT);

if( (event & POLLRDHUP) || (event & POLLERR) || (event & POLLHUP))
LE_INFO(“event %#x”, event);
hApp->fdMonitorRef = le_fdMonitor_Create(“serial Comm”,
(le_fdMonitor_HandlerFunc_t) &AsyncRecvHandler,
LE_INFO("%s done", func);


  • OpenUart() → Func Open’s the uart and set the custom Baudrate,
  • And also the Set to read the 8 bit data sets the start bit and stop bit.
    int32_t OpenUart(void)
    struct termios tty;

LE_INFO(“OpenUart called”);
hApp->serialFd = open(MCU_UART1, O_RDWR | O_NONBLOCK| O_NDELAY);
if(hApp->serialFd < 0 ){
LE_ERROR(“mcu uart open failed : %d %s”, errno, strerror(errno));
return LE_FAULT;

LE_INFO("%s:%d",hApp->PortName, hApp->serialFd);
if (tcgetattr (hApp->serialFd, &tty) != 0) //Get attribute Prop
LE_INFO(“error %d from tcgetattr”, errno);
return LE_FAULT;

LE_INFO(“OpenUart Opened uartd. Modifyuing UART settings”);
cfsetospeed (&tty, BAUDRATE); // O/p Baudrate setting
cfsetispeed (&tty, BAUDRATE); // I/p baudrate setting

tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
tty.c_cflag |= (CLOCAL | CREAD); // ignore modem controls,(

cfmakeraw(&tty); // Make these options as default.
tcflush(hApp->serialFd , TCIOFLUSH); // Push the changes onto Uart File Descrriptor
if (tcsetattr (hApp->serialFd, TCSANOW, &tty) != 0) // Setting the Attributes
LE_INFO (“error %d from tcsetattr”, errno);
return LE_FAULT;

// Create monitor FD handle for activity, as defined by the events
LE_INFO(“OpenUart Opened uartd. Adding fdMonitor”);
hApp->fdMonitorRef = le_fdMonitor_Create(“serial Comm”,
(le_fdMonitor_HandlerFunc_t) &AsyncRecvHandler,
LE_INFO(“uart open success”);
return hApp->serialFd;

void TimerVerHDLR(le_timer_Ref_t timerref)
uint8_t data={“uart write done”};
WriteToUart(data, sizeof(data) );


void CreateVerTimer(void)
le_timer_Ref_t timerRef;
le_clk_Time_t clk={ 60, 0};

timerRef = le_timer_Create(“send data”);
le_timer_SetHandler(timerRef ,TimerVerHDLR);

le_timer_SetInterval(timerRef ,clk);
le_timer_SetRepeat(timerRef ,0);


void createParseeventHdlr(void)
LE_INFO("%s", func);
hApp->CheckMsgEvtId = le_event_CreateId(“checkMsg”, sizeof(tm_Data_t));
hApp->CheckMsgEvtHdlr = le_event_AddHandler(“chaeckMsgHdlr”, hApp->CheckMsgEvtId, CheckMessageHdlr);


void* AppThreadHdlr (void* context)
if( OpenUart() < 0)
LE_INFO(“uart open fail”);


LE_INFO(“mcuData app start”);
le_thread_Ref_t ThreadRef;
ThreadRef = le_thread_Create(“mcuAPP”, AppThreadHdlr, NULL);

#ifndef MCUDATA_H
#define MCUDATA_H

#include “legato.h”
#include “interfaces.h”
#include <termios.h>
#include <unistd.h>

#define MCU_UART1 “/dev/ttyHS1”

#define BAUDRATE B460800
#define MAXRXLEN 256

#define PROT_STX 0x02
#define PROT_ETX 0x03
#define PROT_DLE 0x10

#define MSGTYPE_LEN 1
#define MSGLEN_LEN 2
#define MSGCRC_LEN 2

#define PRINTDATAINHEX(_msgstr ,_buf ,_maxLen) {int _offset=0, _i=0,_ret=0;
int _max= _maxLen;
uint8_t _ptr= _buf;
char _debugstr[50];
LE_INFO("%s: Len=%d", _msgstr ,_max);
while(_max >= _offset) {
memset(_debugstr, 0, sizeof(_debugstr) );
for(_i=0,_ret=0; _i<10 && _max >= _offset;_i++) {
_ret+= sprintf((char
)_debugstr+_ret, “%02x ,”, _ptr[_offset]);
_offset++; }
LE_INFO("%s: %s", _msgstr, _debugstr); }

typedef struct mcu
int serialFd; ///< Serial device file descriptor
char *PortName; ///<
le_fdMonitor_Ref_t fdMonitorRef; ///< Reference to the fd monitor

uint16_t RxLen;

uint8_t MessageBuf[MAXMCUDATALEN];
uint16_t MessageBufIndex;

bool bDLEFound;

le_event_Id_t CheckMsgEvtId;
le_event_HandlerRef_t CheckMsgEvtHdlr;

typedef struct buffer
uint16_t bLen;

int WriteToUart(const uint8_t *, uint32_t );




[rw] /dev/ttyHS1 /dev/ttyHS1

sandboxed: false
version: 1.0.0
start: auto


mcuData = ( mcuDataComponent )


( mcuData )
// faultAction: restartApp

Please zip it and put to google drive.

BTW, I don’t see problem on R10.1
mcudata.log (49.3 KB)

please find attached sample code file.

Hi jyijyi,

i tried in release 13.1 legato 19.02 fdmonitor is working in 1 millisec, but after i getting data from uart i need to send other application , so i created api event handler when we report this event handler event , again fdmonitor is hanging after few minute.
(NOTE:event handler registered function we are not doing any performance , suddenly i am returning from that function )

Do you have the reproducible steps for PC and mangoh red board?

Am trying to do an sample program to read the input from terminal and based on the input need to call a specific method any one guide me how to do it in vscode.

You can try this application