# UART2 Linux application mode is not working

**URL:** <https://forum.legato.io/t/uart2-linux-application-mode-is-not-working/5479>\
**Category:** Uncategorized\
**Created:** [October 27, 2020, 6:32pm UTC](https://forum.legato.io/t/uart2-linux-application-mode-is-not-working/5479 "2020-10-27T18:32:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arun](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@arun](https://forum.legato.io/u/arun)\
**Post date:** [October 27, 2020, 6:32pm UTC](https://forum.legato.io/t/uart2-linux-application-mode-is-not-working/5479/1 "2020-10-27T18:32:22Z")

</div>

Hi all,

i am facing an issue with UART2 in application mode , Once i enable uart 2 for application mode, ttyHSL1 is coming as disabled (checked by dmesg | grep tty). While running the app it reporting the below mentioned error

Jan 6 05:49:27 swi-mdm9x28-wp user.err Legato: =ERR= | supervisor[859]/supervisor T=main | app.c GetDevID() 670 | Could not get file info for ‘/dev/ttyHSL1’. No such file or directory.

Jan 6 05:49:27 swi-mdm9x28-wp user.err Legato: =ERR= | supervisor[859]/supervisor T=main | app.c SetCfgDevicePermissions() 775 | Failed to set permissions (rw) for app ‘rs232app\_test’ on device ‘/dev/ttyHSL1’.

Jan 6 05:49:27 swi-mdm9x28-wp user.err Legato: =ERR= | supervisor[859]/supervisor T=main | app.c app\_Start() 3452 | Failed to set Smack rules or set up app area.

Please suggest a solution to overcome this issue, Thanks in advance

Regards,

Arun

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [October 27, 2020, 11:03pm UTC](https://forum.legato.io/t/uart2-linux-application-mode-is-not-working/5479/2 "2020-10-27T23:03:57Z")

</div>

Can you attach your app here?  
What module and fw ate you using?  
Have yoh tried unsandbox the app?

BTW, have you set the AT!MAPUART=17,2 so that UART2 can be used in linux app?  
once you set this, after reset, you should not see /dev/ttyHSL1

---

<div class="post-metadata">

**Author:** ![arun](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@arun](https://forum.legato.io/u/arun)\
**Post date:** [October 28, 2020, 5:04am UTC](https://forum.legato.io/t/uart2-linux-application-mode-is-not-working/5479/3 "2020-10-28T05:04:31Z")

</div>

Hi,

Please find the code snipped below

void\* Modbus\_Reading\_Thread(void\* object)  
{  
int res = 0;

```
LE_INFO("MODBUS Thread Started");

while(1)
{
    res = read(Serial_Port_fd,&Rx_Buffer[Rx_count],RX_RS485_SIZE-2);
   

    if(res)
    {
        Rx_count += res;
        Byte_Recv = 1;
        byteTimeout = BYTE_TO_BYTE_TIMEOUT;
        
        if(Rx_count > (RX_RS485_SIZE-2)) /* Buffer overflow checking in case of junk receiving */
        {
            Rx_count = 0;
        }
    }
}

```

}

# /\*

- 
- Serial Port Initialization Program
- 

============================================================================================  
\*/

void Serial\_Driver\_Port()  
{

Serial\_Port\_fd = open(“/dev/ttyHSL1”, O\_RDWR | O\_NOCTTY | O\_NDELAY);

if (Serial\_Port\_fd == -1)  
{  
/\*  
\* Could not open the port.  
\*/

```
LE_ERROR("open_port: Unable to open /dev/ttyHSL1 - ");

```

}  
else  
{  
fcntl(Serial\_Port\_fd, F\_SETFL, 0);

```
le_tty_SetRaw(Serial_Port_fd, 0, 0);	//ECHO is OFF

le_tty_SetFraming(Serial_Port_fd, 'N', 8, 1);

pthread_create(&MODBUS_Read_Thread_ID, (pthread_attr_t*)(0), &Modbus_Reading_Thread, (void*)(0));

sleep(1);

LE_INFO("COM PORT HSL1 Opened");

```

}  
}

.cdef file

```
// Linux filesystem device paths.
device:
{
    // Get read and write access to the UART1 port.
    [rw] /dev/ttyHSL1 /dev/ttyHSL1
}

```

in .adef file

sandbox : false

I used uartMode set 2 app command for setting application mode, after system restart HSL1 disabled is coming in dmesg, while using uartMode get 2 command reports linux application

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [October 28, 2020, 5:29am UTC](https://forum.legato.io/t/uart2-linux-application-mode-is-not-working/5479/4 "2020-10-28T05:29:41Z")

</div>

once you set AT!MAPUART=17,2 , after reset, you should not see /dev/ttyHSL1

---

<div class="post-metadata">

**Author:** ![arun](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@arun](https://forum.legato.io/u/arun)\
**Post date:** [October 28, 2020, 6:38am UTC](https://forum.legato.io/t/uart2-linux-application-mode-is-not-working/5479/5 "2020-10-28T06:38:56Z")

</div>

Hi,  
I performed the AT command set, and restarted , it showing as below

root@swi-mdm9x28-wp:~# dmesg | grep tty  
[0.000000] Kernel command line: console=ttyHSL0,115200 console=ttyHSL1,115200 root=/dev/ram rootfs\_ro=true user1\_fs=ubifs verity=on ima\_ready=0 lkversion=SWI9X07Y\_02.28.03.03 androidboot.serialno=5c5d67dd androidboot.authorized\_kernel=true quiet androidboot.baseband=msm rootfstype=ubifs rootflags=bulk\_read  
[0.660730] ttyHS0 is reserved for AT service.  
[0.663953] 78b0000.uart: ttyHS0 at MMIO 0x78b0000 (irq = 49, base\_baud = 460800) is a MSM HS UART  
[0.666305] ttyHS1 could be used as generic serial port.  
[0.669063] 78af000.uart: ttyHS1 at MMIO 0x78af000 (irq = 48, base\_baud = 460800) is a MSM HS UART  
[0.671868] ttyHSL1 is disabled.  
[0.672155] ttyHSL0 is disabled.

i have to use ttyHS1 for my application?

---

<div class="post-metadata">

**Author:** ![arun](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@arun](https://forum.legato.io/u/arun)\
**Post date:** [October 28, 2020, 7:12am UTC](https://forum.legato.io/t/uart2-linux-application-mode-is-not-working/5479/6 "2020-10-28T07:12:47Z")

</div>

Hi,

Thanks for the support its working as expected, please find the working code sample below

# /\*

- 
- Receive MODBUS Packet Program
- 

============================================================================================  
\*/

void\* Modbus\_Reading\_Thread(void\* object)  
{  
int res = 0;

```
uint8_t temp_buf[RX_RS485_SIZE] = {0};

LE_INFO("MODBUS Thread Started");

while(1)
{
    res = read(Serial_Port_fd,temp_buf,RX_RS485_SIZE-2);
    
    if(res > 0)
    {
		if((Rx_count + res) > (RX_RS485_SIZE-2))
			Rx_count = 0;

		memcpy(&Rx_Buffer[Rx_count],temp_buf,res);

		Rx_count += res;
	
        Byte_Recv = 1;
        byteTimeout = BYTE_TO_BYTE_TIMEOUT;
        
        if(Rx_count > (RX_RS485_SIZE-2)) /* Buffer overflow checking in case of junk receiving */
        {
            Rx_count = 0;
        }
    }
}

```

}

# /\*

- 
- Serial Port Initialization Program
- 

============================================================================================  
\*/

void Serial\_Driver\_Port()  
{

Serial\_Port\_fd = open(“/dev/ttyHS1”, O\_RDWR | O\_NOCTTY | O\_NDELAY);

if (Serial\_Port\_fd == -1)  
{  
/\*  
\* Could not open the port.  
\*/

```
LE_ERROR("open_port: Unable to open /dev/ttyHS1 - ");

```

}  
else  
{  
fcntl(Serial\_Port\_fd, F\_SETFL, 0);

```
le_tty_SetBaudRate(Serial_Port_fd,LE_TTY_SPEED_19200);

le_tty_SetRaw(Serial_Port_fd, 0, 0);	//ECHO is OFF

le_tty_SetFraming(Serial_Port_fd, 'N', 8, 1);

pthread_create(&MODBUS_Read_Thread_ID, (pthread_attr_t*)(0), &Modbus_Reading_Thread, (void*)(0));

sleep(1);

LE_INFO("COM PORT HSL1 Opened");

```

}  
}

in .cdef file

```
// Linux filesystem device paths.
device:
{
    // Get read and write access to the UART1 port.
    [rw] /dev/ttyHS1 /dev/ttyHS1
}

```
