Skip to content

About

UART and CAN Test Tools.A comprehensive collection of test utilities for UART/serial and CAN bus communication on Linux systems.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

UART and CAN Test Tools

A comprehensive collection of test utilities for UART/serial and CAN bus communication on Linux systems.

⚠️ AI-Generated Code Disclaimer

This project was developed with assistance from Artificial Intelligence tools.

While the code has been reviewed and tested, users are advised to:

  • ✅ Review and understand the code before deployment in production environments
  • ✅ Thoroughly test the tools in your specific environment
  • ✅ Use caution when testing on critical systems or hardware
  • ✅ Report any issues or bugs encountered

The tools are provided as-is for testing and development purposes. Users assume full responsibility for their use.

Overview

This project provides three test tools for debugging and testing serial communication interfaces:

  • comm_test (Recommended) - Integrated tool supporting both UART and CAN interfaces
  • uart_test - Standalone UART/serial interface tester
  • can_test - Standalone CAN bus interface tester

Features

  • ✅ Support for UART and CAN interfaces
  • ✅ Configurable timeout and transmission intervals (millisecond precision)
  • ✅ Auto-configuration for CAN interfaces (no manual setup required)
  • ✅ Real-time data transmission/reception display
  • ✅ Graceful exit with Ctrl+C signal handling
  • ✅ Cross-platform support (x86 and ARM architectures)

Requirements

Build Requirements

  • GCC compiler (for x86)
  • ARM cross-compiler (for ARM builds): arm-linux-gnueabihf-gcc

Runtime Requirements

  • Linux kernel with CAN support (for CAN tools)
  • Root/sudo privileges (for CAN interface configuration)

Building

Native Build (x86)

# Build all tools
make

# Clean build artifacts
make clean

# Install to /usr/local/bin
make install

ARM Cross-Compilation

# Build ARM versions
./build_arm.sh

# Or use Makefile directly
make -f Makefile.arm
make -f Makefile.arm clean

# Strip debug symbols and reduce size
make -f Makefile.arm strip

# Create deployment package
make -f Makefile.arm package

Usage

comm_test (Integrated Tool)

The comm_test tool combines UART and CAN testing capabilities in one unified interface.

Basic Syntax

./comm_test -t <type> -d <device> -m <mode> [options]

Common Options

  • -t <type>: Interface type - uart or can [required]
  • -d <device>: Device name - e.g., /dev/ttyAS3 or can0 [required]
  • -m <mode>: Operation mode - 0 for receive, 1 for send [required]
  • -i <timeout>: Read timeout in milliseconds (default: 1000ms)
  • -l <interval>: Send interval in milliseconds (default: 100ms)
  • -h: Show help information

UART-specific Options

  • -b <baudrate>: Baud rate (default: 115200)
    • Supported rates: 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600

CAN-specific Options

  • -c <canid>: CAN ID in hex or decimal (default: 0x123)

Examples

UART Receive Mode:

# Basic receive mode
./comm_test -t uart -d /dev/ttyAS3 -m 0

# Custom baud rate and timeout
./comm_test -t uart -d /dev/ttyS0 -m 0 -b 9600 -i 5000

# USB serial adapter
./comm_test -t uart -d /dev/ttyUSB0 -m 0 -b 115200 -i 2000

UART Send Mode:

# Basic send mode
./comm_test -t uart -d /dev/ttyAS3 -m 1

# Fast send (50ms interval)
./comm_test -t uart -d /dev/ttyAS3 -m 1 -b 115200 -l 50

# Slow send (2 second interval)
./comm_test -t uart -d /dev/ttyAS3 -m 1 -b 115200 -l 2000

CAN Receive Mode:

# Listen for all CAN frames
./comm_test -t can -d can0 -m 0

# Long listening session (10 second timeout)
./comm_test -t can -d can0 -m 0 -i 10000

# Real-time monitoring (no timeout)
./comm_test -t can -d can0 -m 0 -i 0

CAN Send Mode:

# Send standard CAN frame (ID=0x123)
./comm_test -t can -d can0 -m 1

# Custom CAN ID (hex)
./comm_test -t can -d can0 -m 1 -c 0x456 -l 100

# Custom CAN ID (decimal)
./comm_test -t can -d can0 -m 1 -c 300 -l 200

# High-speed send (10ms interval)
./comm_test -t can -d can0 -m 1 -c 0x100 -l 10

Standalone Tools

uart_test

Simple UART tester with fixed parameters.

# Receive mode
./uart_test -d /dev/ttyAS3 -b 115200 -m 0

# Send mode (fixed 2 second interval)
./uart_test -d /dev/ttyAS3 -b 115200 -m 1

can_test

Simple CAN tester with fixed parameters.

# Receive mode
./can_test -d can0 -m 0

# Send mode
./can_test -d can0 -m 1 -i 0x123 -l 100

CAN Interface Setup

Automatic Configuration (Recommended)

comm_test automatically configures CAN interfaces on startup:

  1. Brings down the interface
  2. Configures bitrate to 500Kbps
  3. Brings up the interface

Note: Automatic configuration requires root privileges.

Manual Configuration

If you prefer to configure manually:

# Load CAN kernel modules
sudo modprobe can
sudo modprobe can_raw

# Configure CAN interface (e.g., can0 at 500Kbps)
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0

# Verify interface status
ip -details link show can0

Deployment to ARM Devices

Cross-Compilation

./build_arm.sh

Transfer to Device

scp build_arm/comm_test root@<device-ip>:/usr/local/bin/

Run on ARM Device

chmod +x /usr/local/bin/comm_test
comm_test -t uart -d /dev/ttyAS3 -m 1 -b 115200

Output Format

UART Mode

  • Receive: <device> 接收[bytes]: <data>
  • Send: <device> 发送[counter]: <data>

CAN Mode

  • Receive: <device> 接收[bytes]: ID=0xXXX DLC=N 数据: XX XX XX XX XX XX XX XX
  • Send: <device> 发送: ID=0xXXX DLC=N 数据: XX XX XX XX XX XX XX XX

Signal Handling

All tools support graceful exit via:

  • Ctrl+C (SIGINT)
  • kill command (SIGTERM)

Resources are properly cleaned up on exit.

Project Structure

.
├── comm_test.c       # Integrated UART/CAN test tool
├── uart_test.c       # Standalone UART test tool
├── can_test.c        # Standalone CAN test tool
├── Makefile          # Native build configuration
├── Makefile.arm      # ARM cross-compilation configuration
├── build_arm.sh      # ARM build script
└── build_x86.sh      # x86 build script

Comparison

Tool Features Recommended For
comm_test ✅ Most comprehensive
✅ Single tool for both interfaces
✅ Fully configurable
✅ Bilingual interface
Daily use - all scenarios
uart_test Simple, fixed parameters Basic UART testing only
can_test Simple, fixed parameters Basic CAN testing only

Recommendation: Use comm_test for most scenarios. It provides the most complete functionality and best user experience.

License

This project is provided as-is for testing and development purposes.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

About

UART and CAN Test Tools.A comprehensive collection of test utilities for UART/serial and CAN bus communication on Linux systems.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages