Ravi1
September 26, 2024, 8:43am
1
Hello Team Toradex,
I am using verdin imx8mp device and for that device i am write a code for UART in visual studio code using qt c++, but whenever i am trying to initialize UART it will show error, Error opening UART device. the code i am using is shown below
int UARTModule::initUART(const char *device, int baudRate) {
uartFd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (uartFd == -1) {
qDebug() << “Error opening UART device”;
return -1;
}
struct termios options;
tcgetattr(uartFd, &options);
cfsetispeed(&options, baudRate);
cfsetospeed(&options, baudRate);
tcsetattr(uartFd, TCSANOW, &options);
return uartFd;
}
so give me the solution for this
Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!
Did you like my answer?
Based on the provided context, it seems like you are encountering an issue with opening the UART device on your Verdin iMX8MP module. Here are a few steps to troubleshoot and potentially resolve the issue:
Check Device Path : Ensure that the device path you are using is correct. For Verdin family, the UART device names are typically /dev/verdin-uart1
, /dev/verdin-uart2
, etc. Verify that the device path you are passing to the initUART
function matches one of these.
Permissions : Ensure that your application has the necessary permissions to access the UART device. You might need to run your application with elevated privileges or adjust the permissions of the device file.
Device Availability : Verify that the UART device is available and not being used by another process. You can list the available UART devices using the command:
ls /dev/verdin-uart*
Error Handling : Enhance your error handling to get more information about why the open
call is failing. You can use perror
to print the error message:
if (uartFd == -1) {
perror("Error opening UART device");
return -1;
}
Baud Rate : Ensure that the baud rate you are setting is supported. The standard baud rates are predefined, and you should use one of those.
Here is an updated version of your code with enhanced error handling:
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <QDebug>
int UARTModule::initUART(const char *device, int baudRate) {
uartFd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (uartFd == -1) {
perror("Error opening UART device");
return -1;
}
struct termios options;
if (tcgetattr(uartFd, &options) != 0) {
perror("Error getting UART attributes");
close(uartFd);
return -1;
}
cfsetispeed(&options, baudRate);
cfsetospeed(&options, baudRate);
options.c_cflag |= (CLOCAL | CREAD); // Enable the receiver and set local mode
options.c_cflag &= ~CSIZE; // Mask the character size bits
options.c_cflag |= CS8; // Select 8 data bits
options.c_cflag &= ~PARENB; // No parity
options.c_cflag &= ~CSTOPB; // 1 stop bit
options.c_cflag &= ~CRTSCTS; // No hardware flow control
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // Raw input
options.c_iflag &= ~(IXON | IXOFF | IXANY); // No software flow control
options.c_oflag &= ~OPOST; // Raw output
if (tcsetattr(uartFd, TCSANOW, &options) != 0) {
perror("Error setting UART attributes");
close(uartFd);
return -1;
}
return uartFd;
}
If the issue persists, please provide additional details such as the exact error message from perror
and the device path you are using.
Please, also check if these links can help you solve your problem:
Colibri iMX6 DL 512MB IT
running c code on Torizon
Hi guys
I am stumped by this… wasted 2 days already…
I am able to get my RS485 port to write to a terminal program, so I know I have MOST of my settings correct anyways, for example
9600 baud
1 stop bit
no parity
8 data bits
no flow control
and not so many days ago, I was actually able to get it to read from the serial port as well.
(So this means that at least my device-tree should be in good shape… which is a relief in itself.)
Sin…
We are having some issues getting a UART (more specifically the 2 that are not used for terminals of both processors) initialized on the M4 core of the verdin IMX8MM.
Setup
Verdin iMX8M Mini DualLite
Custom carrier board
Device tree for A53 with both UART’s (UART1 and UART2) disabled
J-link debugger connected
We have tried adding the UART driver to our application and the iuart_interrupt_transfer example. In both cases if we change the UART from uart4 to uart2 in the board, pinmux and main f…
How to Use UART on Torizon OS | Toradex Developer Center .
Ravi1
September 27, 2024, 6:42am
3
Hello Team Toradex,
int UARTModule::initUART(const char *device, int baudRate) {
uartFd = open(device, O_RDWR | O_NOCTTY /| O_NDELAY /);
if (uartFd == -1) {
qDebug() << “Error opening UART device:” << strerror(errno);
return -1;
}
struct termios options;
if (tcgetattr(uartFd, &options) < 0) {
qDebug() << "Error getting UART attributes:" << strerror(errno);
close(uartFd);
return -1;
}
cfsetispeed(&options, baudRate);
cfsetospeed(&options, baudRate);
options.c_cflag |= (CLOCAL | CREAD); // Enable the receiver and set local mode
options.c_cflag &= ~PARENB; // No parity
options.c_cflag &= ~CSTOPB; // 1 stop bit
options.c_cflag &= ~CSIZE; // Mask the character size bits
options.c_cflag |= CS8; // 8 data bits
options.c_cflag &= ~CRTSCTS; // No hardware flow control
options.c_iflag &= ~(IXON | IXOFF | IXANY); // Disable software flow control
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // Raw input mode
options.c_oflag &= ~OPOST; // Raw output mode
if (tcsetattr(uartFd, TCSANOW, &options) != 0) {
qDebug() << "Error setting UART attributes:" << strerror(errno);
close(uartFd);
return -1;
}
return uartFd;
}
void UARTModule::sendData(int uart, const char *data) {
//write(uart, data, strlen(data));
ssize_t bytes_written = write(uart, data, strlen(data));
if (bytes_written < 0) {
qDebug() << “Error writing to UART:” << strerror(errno);
} else {
qDebug() << “Successfully wrote” << bytes_written << “bytes to UART.”;
}
}
using the above 2 functions I have used for the UART initialization and send data use for the to write data but whenever i have write data on uart i have see that output on Putty console.
But whenever i have write data on uart it will be torizon login window it will ask me to login torizon device instead of showing my uart data so how to resolve this?
I am using verdin imx8mp device
Hi @Ravi1
Ravi1:
using the above 2 functions I have used for the UART initialization and send data use for the to write data but whenever i have write data on uart i have see that output on Putty console.
But whenever i have write data on uart it will be torizon login window it will ask me to login torizon device instead of showing my uart data so how to resolve this?
I am not able to understand your issue.
Ravi1
September 30, 2024, 9:01am
5
@sahil.tx
When I have try to deploy the code from visual studio code it shows the below error
ERROR: failed to solve: commontorizon/qt6-wayland-imx8:3.3.1: failed to resolve source metadata for docker.io/commontorizon/qt6-wayland-imx8:3.3.1: failed to do request: Head “https://registry-1.docker.io/v2/commontorizon/qt6-wayland-imx8/manifests/3.3.1 ”: dial tcp: lookup registry-1.docker.io on 172.26.64.1:53: read udp 172.26.66.45:37532->172.26.64.1:53: i/o timeout
The terminal process “/usr/bin/bash ‘-c’, ‘DOCKER_HOST= docker build --progress=plain --pull -f /home/RaviVanand/test/Dockerfile.sdk /home/RaviVanand/test -t cross-toolchain-arm64-test --build-arg IMAGE_ARCH=arm64 --build-arg GPU=-imx8 --build-arg APP_ROOT=/home/torizon/app’” terminated with exit code: 1
Hi @Ravi1 ,
What OS you are using?
Ravi1
October 1, 2024, 5:07am
7
Hii@sahil.tx,
I am using torizon os
Hi @Ravi1 ,
Please take reference from this article .
Ravi1
October 1, 2024, 9:01am
9
Hello @sahil.tx ,
By following the this article . I am able to initialize the UART Interface.
But my problem is that When I have try to deploy the code from visual studio code it shows the below error
ERROR: failed to solve: commontorizon/qt6-wayland-imx8:3.3.1: failed to resolve source metadata for docker.io/commontorizon/qt6-wayland-imx8:3.3.1: failed to do request: Head “https://registry-1.docker.io/v2/commontorizon/qt6-wayland-imx8/manifests/3.3.1”: dial tcp: lookup registry-1.docker.io on 172.26.64.1:53: read udp 172.26.66.45:37532->172.26.64.1:53: i/o timeout
The terminal process “/usr/bin/bash ‘-c’, ‘DOCKER_HOST= docker build --progress=plain --pull -f /home/RaviVanand/test/Dockerfile.sdk /home/RaviVanand/test -t cross-toolchain-arm64-test --build-arg IMAGE_ARCH=arm64 --build-arg GPU=-imx8 --build-arg APP_ROOT=/home/torizon/app’” terminated with exit code: 1