OK-MX93 SPI2CAN/ADC Release
Documentation Overview
This document describes how to use the KV11Z SPI2CAN driver to implement IMX93 peripheral interface expansion. The driver connects to the KV11Z microcontroller via SPI interface, extending CAN bus and ADC acquisition capabilities for the IMX93 processor.
Key Features:
CAN Bus Extension: Provides 1Mbps CAN 2.0A/B communication capability
ADC Acquisition Extension: Supports 8-channel 16-bit ADC with 1kHz sampling rate per channel
Standard Interface: Fully compatible with Linux CAN Socket API and IIO subsystem
High-Performance Transfer: Efficient data transfer architecture based on SPI+DMA+interrupt
With this driver, developers can easily implement industrial-grade CAN communication and multi-channel analog signal acquisition on the IMX93 platform.
System Architecture
System Architecture Diagram
Hardware Connection Description
IMX93 and KV11Z are connected via standard SPI bus:
MOSI: Master Output, Slave Input
MISO: Master Input, Slave Output
SCLK: SPI clock signal
CS: Chip select signal (controlled by GPIO)
IRQ: Interrupt signal (KV11Z to IMX93)
Important Configuration Notes:
Must use GPIO CS + DMA method, main controller CS method has known issues
For device tree configuration, refer to the OK-MX93-C.dts file in the project
SPI frequency recommended to be set at 7-12.5MHz, DMA configuration recommended to be enabled
Data Flow Diagram
Directory Structure
.
├── adctest.c
├── build.sh
├── cantest.c
└── OKMX93-linux-kernel-6.1.36
├── arch
│ └── arm64
│ └── boot
│ └── dts
│ └── freescale
│ └── OK-MX93-C.dts
└── drivers
└── net
└── can
└── kv11z_spi2can.c
Core Components
1. kv11z_spi2can.c - Core Driver Program
Function: KV11Z SPI2CAN/ADC Linux kernel driver
Implements CAN network device interface, supports standard Linux CAN Socket API
Implements IIO ADC device interface, supports multi-channel ADC data acquisition
Communicates with KV11Z microcontroller via SPI protocol
Supports interrupt-driven high-performance data transfer
Key Features:
CAN Function: Supports standard and extended CAN frames, configurable baud rate and filters (under development)
ADC Function: 8-channel ADC acquisition, supports triggered buffer mode and direct read mode
High Performance: Multi-threaded architecture, supports concurrent CAN and ADC operations
Configurable: Rich module parameters, supports runtime tuning
Module Parameters:
# CAN Configuration
g_can_bitrate=1000000 # CAN baud rate (default 1Mbps)
# ADC Configuration
g_adc_mask=0xFF # ADC channel enable mask (default all channels)
g_adc_sample_rate=1000 # ADC sampling rate (default 1kHz)
# SPI Configuration
spi_speed=7000000 # SPI bus speed (default 7MHz)
transfer_time_us=30 # SPI transfer interval (default 30μs)
# Debug Options
debug=0 # Debug information switch (0=off, 1=on)
2. adctest.c - ADC Test Application
Function: ADC data acquisition test tool
Supports two ADC reading modes: direct mode and buffer mode
Provides real-time data display and CSV file output
Supports timestamps and performance statistics
Hardware compatibility detection and channel validation
Key Features:
Dual Mode Support: Direct read mode (sysfs) and buffer mode (IIO buffer)
Flexible Configuration: Configurable channel mask and sampling rate
Data Export: Supports CSV format data export for subsequent analysis
Real-time Display: Color terminal output and statistical information
Usage Examples:
# Compile
gcc -O2 -o adctest adctest.c
# Buffer mode, enable channels 0-3, with timestamps
./adctest -m 1 -c 0x0F -t
# Direct mode, 500ms sampling interval
./adctest -m 0 -d 500000
# Save data to CSV file
./adctest -m 1 -f /tmp/adc_data
# View help
./adctest -h
3. cantest.c - CAN Bus Test Tool
Function: Comprehensive CAN bus testing and benchmarking tool
Supports CAN frame generation, transmission and reception
Provides MD5 verification to ensure data integrity
Supports file transfer over CAN bus
Real-time performance monitoring and statistical analysis
Key Features:
Performance Testing: Supports bulk transmission testing of large numbers of frames
Data Integrity: MD5 verification ensures transmission data integrity
File Transfer: Supports arbitrary file transfer over CAN bus
Real-time Monitoring: Progress bar display, FPS statistics, error statistics, etc.
Usage Examples:
# Compile
gcc -O2 -o cantest cantest.c
# Transmitter: Send 1000 random CAN frames
./cantest -i can0 -t -n 1000 -d 1000
# Receiver: Receive CAN frames and verify
./cantest -i can0 -r
# File transfer transmitter
./cantest -i can0 -t -f /path/to/file
# File transfer receiver
./cantest -i can0 -r -f /path/to/output
# View help
./cantest -h
Quick Start
1. Environment Setup
Ensure cross-compilation toolchain is installed:
# Set cross-compilation environment
source environment-setup-aarch64-toolchain
2. Build System
# Complete build
./build.sh all
# Or step-by-step build
./build.sh uboot
./build.sh kernel
./build.sh apps
./build.sh mkfs
3. Deploy Driver
# Load driver module
insmod kv11z_spi2can.ko
# Configure CAN interface
ip link set can0 type can bitrate 1000000
ip link set can0 up
# Verify ADC device
ls /sys/bus/iio/devices/
4. Function Testing
# Test ADC function
./adctest -m 1 -c 0xFF -t
# Test CAN function
./cantest -i can0 -t -n 100
Technical Specifications
Hardware Requirements
Main Controller: OK-MX93 development board (IMX93 processor)
Co-processor: KV11Z microcontroller
Interface: SPI bus connection
CAN: Supports CAN 2.0A/B protocol
ADC: 8-channel 12-bit ADC
Performance Metrics
CAN Baud Rate: Up to 1Mbps
ADC Sampling Rate: Up to 1kHz (per channel)
SPI Speed: Up to 12.5MHz
Latency: CAN frame transmission latency ≤1ms
Throughput: Supports 7500 frames/second CAN transmission
Software Compatibility
Kernel Version: Linux 6.1.36
Architecture: ARM64 (aarch64)
Compiler: GCC cross-compilation toolchain
API: Standard Linux CAN Socket API, IIO subsystem API
Troubleshooting
Common Issues
Compilation Failure
Check if cross-compilation environment is correctly set
Confirm all dependency packages are installed
Driver Loading Failure
Check if device tree configuration is correct
Confirm SPI interface and GPIO configuration
CAN Communication Abnormal
Check CAN bus hardware connections
Verify if baud rate configuration matches
ADC Data Abnormal
Check ADC channel mask configuration
Verify if sampling rate setting is reasonable
Debugging Methods
# Enable driver debug information
echo 1 > /sys/module/kv11z_spi2can/parameters/debug
# View system logs
dmesg | grep kv11z
# Check device status
cat /proc/interrupts | grep kv11z
Technical Support
For technical support, please contact the development team or refer to relevant technical documentation.
Note: This software package is only applicable to OK-MX93 development board. Please ensure hardware configuration is correct before use.Other boards please porting by yourself.
Disclaimer:
"Any support, information, and technology ("Materials") provided by NXP are provided AS IS, without any warranty express or implied, and NXP disclaims all direct and indirect liability and damages in connection with the Material to the maximum extent permitted by the applicable law. NXP accepts no liability for any assistance with applications or product design. Materials may only be used in connection with NXP products. Any feedback provided to NXP regarding the Materials may be used by NXP without restriction."
View full article