How to use the UART1 with an APP -- Development Studio 5.1


#1

Map service (​Customer Linux application) to uart1 by :

root@swi-mdm9x15:~# microcom -E /dev/ttyAT
AT!MAPUART?
!MAPUART: 1,16

OK
AT!MAPUART=17,1
OK
AT!MAPUART?
!MAPUART: 17,16

OK
root@swi-mdm9x15:~# reboot -n

To Built my app project with :
uartStd.c:

#include"legato.h"
//#include"interface.h"

int open_port(void)
{
  int fd; 																														/* File descriptor for the port */

  fd = open("/dev/ttyHS0", O_RDWR | O_NOCTTY | O_NDELAY);			/*uart1*/
  //fd = open("/dev/ttyHSL1", O_RDWR | O_NOCTTY | O_NDELAY);		/*uart2*/

  if (fd == -1)
  {
  /*
  * Could not open the port.
  */
    perror("open_port: Unable to open /dev/ttyHSL1 - ");
  }
  else
     fcntl(fd, F_SETFL, 0);

  return (fd);
}

void ledTimer(le_timer_Ref_t t)
{
	//to do
	//printf("==== hello UART test =====\r");
}
//--------------------------------------------------------------------------------------------------
/**
 * Main program starts here
 */
//--------------------------------------------------------------------------------------------------
COMPONENT_INIT
{
	LE_INFO("=============== Hello UART . ===============");
	int uart_fd = open_port();
	int n = write(uart_fd, "ATZ\r", 4);
	if (n < 0)
	    fputs("write() of 4 bytes failed!\n", stderr);

	LE_INFO("Attempt to output to UART produces: %d", n);

	le_timer_Ref_t ledTimerRef = le_timer_Create("LED Timer");
	le_timer_SetMsInterval(ledTimerRef, 1000);
	le_timer_SetRepeat(ledTimerRef, 0);
	le_timer_SetHandler(ledTimerRef,ledTimer);
	le_timer_Start(ledTimerRef);
}

Component.cdef :

sources:
{
    uartStd.c
}

requires:
{
    device:
    {
    	// Get read and write access to the UART1 port.
        [rw]    /dev/ttyHS0   /dev/ttyHS0
    }
}

uartStd.adef :

version: 1.0.10

executables:
{
	uart1Ctrl = ( uartStdComponent )
}

processes:
{
	envVars:
	{
		LE_LOG_LEVEL = DEBUG
	}
	run:
	{
		( uart1Ctl )
	}
}

Run on the legato, output the logs:

Jan  6 00:37:42 | supervisor[464]/supervisor T=main | app.c CreateFileLink() 1504 | Created file link '/tmp/legato/serviceDirectoryClient' to '/legato/systems/current/appsWriteable/uartStd/tmp/legato/serviceDirectoryClient'.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxCoreDumpFileBytes to value 102400.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxFileBytes to value 102400.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxLockedMemoryBytes to value 8192.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxFileDescriptors to value 256.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxMQueueBytes to value 512.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxThreads to value 20.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxQueuedSignals to value 100.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | proc.c proc_Start() 1190 | Starting process 'uart1Ctl' with pid 7568
Jan  6 00:37:42 | supervisor[7568]/supervisor T=main | proc.c proc_Start() 1155 | Execing 'uart1Ctl'
Jan  6 00:37:42 | supervisor[7568]/supervisor T=main | proc.c proc_Start() 1167 | Could not exec 'uart1Ctl'.  No such file or directory.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | proc.c proc_SigChildHandler() 1942 | Process 'uart1Ctl' (PID: 7568) has exited with exit code 1.
Jan  6 00:37:42 | supervisor[464]/supervisor T=main | proc.c GetFaultAction() 1744 | No fault action specified for process 'uart1Ctl'. Assuming 'ignore'.
Jan  6 00:37:43 | supervisor[464]/supervisor T=main | app.c app_SigChildHandler() 3221 | Process 'uart1Ctl' in app 'uartStd' faulted: Ignored.
Jan  6 00:37:43 | _appStopClient[7569]/framework T=main | LE_FILENAME CreateSocket() 550 | Socket opened as standard i/o file descriptor 2!
Jan  6 00:37:43 | supervisor[464]/supervisor T=main | apps.c DeactivateAppContainer() 340 | Application 'uartStd' has stopped.

Any advise for my issue, thanks.

Best Regards!


#2

Hi @lumao,

Interesting issue, if you try microcom /dev/ttyHS0 can it open the port?
Which firmware version are you using?

Can you give the result of cat /sys/devices/platform/msm_serial_hs.0/config as well just to make sure.

Thanks


#3

Hi,

root@swi-mdm9x15:~# microcom /dev/ttyHS0
root@swi-mdm9x15:~# microcom /dev/ttyHS0
root@swi-mdm9x15:~# cat /sys/devices/platform/msm_serial_hs.0/config 
APP
root@swi-mdm9x15:~# cat /sys/devices/platform/msm_serial_hs.0/config
APP
root@swi-mdm9x15:~# cm info
Device:     WP8548
IMEI:       35xx7706004xxxx
FSN:        LLxx2300101xxx
Firmware:   SWI9X15Y_07.11.22.00 r33729 CARMD-EV-FRMWR1 2017/01/11 18:04:06
Bootloader: SWI9X15Y_07.11.22.00 r33729 CARMD-EV-FRMWR1 2017/01/11 18:04:06
priIdPn:    9906xx1
priIdRev:   01.00
skuId:      1103xxx
root@swi-mdm9x15:~# cm legato
This service does not exist.
root@swi-mdm9x15:~# legato version
16.10.1_a6a25fbda05738774857dccb9fd76a99_modified
root@swi-mdm9x15:~#

#4

I don’t know how to open the uart port also.
When I type :

`microcom /dev/ttyHS0`

it return nothing, so I type

`Ctrl +x` 

back to the command line.


#5

HI @lumao,

Not sure if you’ve noticed but in uartStd.adef you have defined the executable uart1Ctrl but are trying to run the process uart1Ctl - they don’t match.

Try:

executables:
{
	uart1Ctrl = ( uartStdComponent )
}

processes:
{
	envVars:
	{
		LE_LOG_LEVEL = DEBUG
	}
	run:
	{
		( uart1Ctrl )
	}
}

Raf


#6

Hi,
It make sense.
using ‘uartStd’ instead of ‘uartCtrl’ . Now it is working. Thank you for all of your help.

updated uartStd.adef :
version: 1.0.10

executables:
{
	uartStd = ( uartStdComponent )
}

processes:
{
	envVars:
	{
		LE_LOG_LEVEL = DEBUG
	}
	run:
	{
		( uartStd )
	}
} 

regards.