I am using Android pie (android_p9.0.0_1.0.0-ga_image_8mmevk) on i.MX8M Mini EVK
I want use UART for my Application development.
As per document IMX8MMEVKHUG.pdf UART3 can be accessible from Expansion header(J1103) (Pin No.7, 8, 9, 10, 11)
Can you please guide me how to enable UART3 on i.MX8M Mini EVK and how to use it to send and receive data?
I think /dev/ttymxc2 is for UART3
But when I try to configure it I get following error:
stty -F /dev/ttymxc2 115200 raw -echo
stty: /dev/ttymxc2: Permission denied
Why I am getting such kind of error?
Is there any way to enable UART without compiling any other source code or kernel code. Please help me to solve this issue.
Attached IMX8MMEVKHUG.pdf and boot logs for reference.
Hi igorpadykov,
Thanks for your reply.
I am successfully able to use Android NDK and run and execute sample hello app on this iMX board.
Can you please guide me?
Thanks,
Abhijit
Hi Abhijit
for new questions recommended to create new thread.
Best regards
igor
Hi,
I have created new thread.
Please check link ; https://community.nxp.com/message/1166679
Thanks,
Abhijit
Hi igorpadykov,
Thanks for your reply.
But I want to just test UART first without creating any android application. Like using echo command.
I tried following but it didn't work.
stty -F /dev/ttymxc2 115200 raw -echo
stty: /dev/ttymxc2: Permission denied
echo Hello World > /dev/ttymxc2
Like this I want to test UART. Do you know how to this?
Hi Abhijit
uart can be tested in linux using unit test:
mxc_uart_test\test - imx-test - i.MX Driver Test Application Software
Best regards
igor
Hi igorpadykov,
I am able to test UART from the link you provide.
mxc_uart_test\test - imx-test - i.MX Driver Test Application Software
I use Android NDK to run this code.
But to before accessing UART I have to run following commands manually.
Command to get root access
To turn off SELinux (Security Enhanced Linux)
Command to set permissions for port /dev/ttymxc2. This is the device file for UART pins on NXP platform.
Command to set Baud rate to 115200
Is there any way so that I can avoid run these commands manually. Can I do these settings from Android application only?
Can you please guide me?
Following is the JNI file code from which UART is accessed. Is it a proper way to access UART? or I should do it differently?
#include <jni.h> #include <string> #include "simple.h" #include "uart_test.h" #include <android/log.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <sys/ioctl.h> #include <unistd.h> #include "uart_test.h" #include <android/log.h> #include <errno.h> #define LOOPBACK 0x8000 #define MESSAGE "Test Hello good evening bruviti\0" #define MESSAGE_SIZE sizeof(MESSAGE) #define MESSAGE1 "Test message\0" #define MESSAGE_SIZE1 sizeof(MESSAGE1) #define APPNAME "uart_test" extern "C" JNIEXPORT jstring JNICALL Java_com_example_temp_MainActivity_stringFromJNI(JNIEnv *env, jobject instance) { std::string hello = PrintHello(); printf("********************************************** In MYUART ************************************* \n"); int uart_file1; unsigned int line_val; char buf[5]; struct termios mxc, old; int retval = 0; int retries = 5; if ((uart_file1 = open("/dev/ttymxc2", O_RDWR)) == -1) { __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Error opening /dev/ttymxc2 ------------ %d\n", errno); } else { __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "/dev/ttymxc2 opened %d", uart_file1); } tcgetattr(uart_file1, &old); cfsetispeed (&old, B115200); cfsetospeed (&old, B115200); mxc = old; mxc.c_lflag &= ~(ICANON | ECHO | ISIG); mxc.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON); mxc.c_cflag |= CSTOPB; mxc.c_cflag = ~CSIZE | CS8; mxc.c_cflag &= ~PARENB; mxc.c_oflag = 0; mxc.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG); mxc.c_cc [VMIN]=30; mxc.c_cc [VTIME]=100; tcsetattr(uart_file1, TCSANOW, &mxc); __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Attributes set\n"); line_val = LOOPBACK; ioctl(uart_file1, TIOCMSET, &line_val); __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Test: IOCTL Set\n"); tcflush(uart_file1, TCIOFLUSH); write(uart_file1, MESSAGE, MESSAGE_SIZE); __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Data Written= %s\n", MESSAGE); sleep(1); memset(buf, 0, MESSAGE_SIZE); while (retries-- && retval < 5) retval += read(uart_file1, buf + retval, MESSAGE_SIZE - retval); __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Data Read back= %s\n", buf); sleep(2); ioctl(uart_file1, TIOCMBIC, &line_val); retval = tcsetattr(uart_file1, TCSAFLUSH, &old); close(uart_file1); if (memcmp(buf, MESSAGE, MESSAGE_SIZE)) { __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Data read back %s is different than data sent %s\n", buf, MESSAGE); } return env->NewStringUTF(hello.c_str()); }
Hi Abhijit
configuring permissions can be found on general android resources like:
https://developer.android.com/things/sdk/pio/uart
Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi igorpadykov,
As per your post
"configuring permissions can be found on general android resources like:
https://developer.android.com/things/sdk/pio/uart "
I checked this sample example. But this example is for boards having Android Things only and not other android.
How can i check for other Android BSP. I am using Android pie (android_p9.0.0_1.0.0-ga_image_8mmevk) on i.MX8M Mini EVK
i.MX8M Mini EVK is not in supported in hardware lists for Android Things. So I cannot flash Android Things.
If you can guide me to solve 'stty: /dev/ttymxc2: Permission denied' issue it will be easy for me to test UART.
Can you please guide me?
Thanks,
Abhijit