UART Access Issue on Torizon OS with .NET and Docker Configuration

Hello,

I am working on UART with the hardware required to read UART data from different modules. I chose .NET for this project. I have successfully managed to control the LED using the application. The second part of the project involves communication between UART modules.

I enabled UART1, set the baud rate, and successfully tested echo functionality, receiving data on Hercules. Below are the outputs:

torizon@verdin-imx8mp-15502128:~$ ls -l /dev/verdin-uart*
lrwxrwxrwx 1 root root 7 Oct  9 15:18 /dev/verdin-uart1 -> ttymxc0
lrwxrwxrwx 1 root root 7 Oct  9 15:18 /dev/verdin-uart2 -> ttymxc1
lrwxrwxrwx 1 root root 7 Oct  9 15:18 /dev/verdin-uart3 -> ttymxc2
torizon@verdin-imx8mp-15502128:~$ ls -l /dev/ttymxc0
crw-rw---- 1 root dialout 207, 16 Jan 15 07:07 /dev/ttymxc0
torizon@verdin-imx8mp-15502128:~$ stty -F /dev/ttymxc0
speed 115200 baud; line = 0;
-brkint -imaxbel

I am using Torizon IDE in VS Code, but I am unable to access the UART. I get the following debug output when I try to deploy the code:

An error occurred: Access to the port '/dev/verdin-uart1' is denied.

Resources released.

I followed the UART (Linux) tutorial and the How to Use UART on Torizon OS guide. I also updated the script for docker-compose as follows:

docker-compose.yml

version: "3.9"
services:
  hardware-debug:
    build:
      context: .
      dockerfile: Dockerfile.debug
    image: ${LOCAL_REGISTRY}:5002/hardware-debug:${TAG}
    ports:
      - 2222:2222
    device_cgroup_rules:
      - "c 254:* rmw"
    volumes:
      - type: bind
        source: /dev
        target: /dev

  hardware:
    build:
      context: .
      dockerfile: Dockerfile
    image: ${DOCKER_LOGIN}/hardware:${TAG}
    devices:
      - "/dev/gpiochip0"
      - "/dev/verdin-uart1:/dev/verdin-uart1"

Dockerfile (snippet):

COPY --from=build ${APP_ROOT}/bin/Release/net8.0/linux-${IMAGE_ARCH}/publish ${APP_ROOT}

# Set environment variable for the serial port
ENV HARDWARE_SERIAL_PORT="/dev/verdin-uart1"

# Change directory to APP_ROOT
WORKDIR ${APP_ROOT}

# Command executed at runtime when the container starts
CMD ["./hardware"]

Despite these configurations, I am still unable to access the UART port. Please let me know if I need to modify anything or if you require additional details to troubleshoot this issue.

Regards,
Anurag

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Anurag,

Thank you for reaching out with your question. It sounds like you’re making great progress with your project, and I’m here to help you resolve the UART access issue you’re encountering.

To address the ‘Access to the port is denied’ error, please consider the following steps:

  1. Check User Permissions:

    • Ensure that the user running your application inside the Docker container has the necessary permissions to access the UART device. This typically involves adding the user to the ‘dialout’ group, which grants access to serial ports. You can modify your Dockerfile to add the Torizon user to the ‘dialout’ group with the following command:
      RUN usermod -aG dialout torizon
      
    • After making this change, rebuild your Docker image.
  2. Verify Docker Compose Configuration:

    • Double-check your docker-compose.yml file to ensure it correctly maps the UART device from the host to the container. Your configuration seems correct, but it’s always good to verify that the device path is accurate and matches the symlink (e.g., /dev/verdin-uart1).
    • Ensure the devices section in your docker-compose.yml is properly formatted:
      devices:
        - "/dev/verdin-uart1:/dev/verdin-uart1"
      
  3. Test Device Access:

    • After implementing these changes, test accessing the UART device from within the container. You can do this by running a simple command inside the container to check if the device is accessible:
      ls -l /dev/verdin-uart1
      
    • This should confirm that the device is present and accessible.
  4. Debugging:

    • If the issue persists, check the container logs for any additional error messages that might provide more context.
    • Also, ensure that no other process is using the UART device, as this could cause access conflicts.

By following these steps, you should be able to resolve the access issue and successfully communicate with the UART device from your .NET application on Torizon OS.

I hope this helps! If you have any further questions, feel free to ask.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Error using UART in Torizon: Operation not permitted.

Greetings @AnuragBluAI,

Just to check, are you running the debug or release version of this project. Looking at your docker-compose.yml, you only added the /dev/verdin-uart1 entry to the release version of the project. If you are running the debug version than that would make sense why you’re still having access issues.

Best Regards,
Jeremias

Hi @jeremias.tx

Thank you for your response.

I have reviewed the configuration and confirmed that the /dev/verdin-uart1 device entry was only added to the release version of the project in the docker-compose.yml file, as you mentioned.

I am currently trying to run the debug version, and based on your comment, I believe this could be causing the access issues.

Could you confirm if I should add the /dev/verdin-uart1 device entry to the debug version of the project (under the hardware-debug service in the docker-compose.yml file)? Or is there another solution to ensure that UART access works in the debug version?

I will proceed with these updates and let you know if the issue persists.

Thank you again for your help!

Best regards,
Anurag

Could you confirm if I should add the /dev/verdin-uart1 device entry to the debug version of the project (under the hardware-debug service in the docker-compose.yml file)? Or is there another solution to ensure that UART access works in the debug version?

Correct when you run the debug version the IDE will only use the configurations under <project-name>-debug in your compose file. Configurations under other services in the compose file will have no effect.

Best Regards,
Jeremias

Hello again @jeremias.tx ,
[UPDATE]

I have updated the code from the repository, and it works well with the release method so far. Your feedback is appreciated. I would like to keep this support open if that’s okay, as I have a lot of work involving high-speed UART.

docker-compose.yml

version: "3.9"

services:
  vitaldata-debug:
    build:
      context: .
      dockerfile: Dockerfile.debug
    image: ${LOCAL_REGISTRY}:5002/hardware-debug:${TAG}
    ports:
      - ${DEBUG_SSH_PORT}:${DEBUG_SSH_PORT}
    device_cgroup_rules:
      - "c 254:* rmw"
    volumes:
      - type: bind
        source: /dev
        target: /dev

  vitaldata:
    build:
      context: .
      dockerfile: Dockerfile
    image: ${DOCKER_LOGIN}/hardware:${TAG}
    devices:
      - "/dev/gpiochip0"
      - "/dev/verdin-uart1:/dev/verdin-uart1"

Regards,
Anurag.

Glad to hear you are making progress. Feel free to ask any further questions. I would just ask that if your questions are on a different topic, or issue then please open a new thread. It’s easier for us to track and follow issues this way, compared to having multiple issues being discussed in one thread.

Best Regards,
Jeremias