yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
RDK X5 MagicBox📖
1.RDK MagicBox
  • 1. RDK MagicBox Official Materials
  • 2. Troubleshooting boot failure
  • 3. Linux memory query
2.RDK MagicBox Introduction
  • 1. Introduction to RDK MagicBox
  • 2. Write System File
  • 3. Hardware Interface Description
3.RDK MagicBox User Guide
1. Quick Start
  • Quick Start
2. Basic Peripheral Usage
  • Basic Peripheral Usage
3. Algorithm Development
  • 1. Stereo Depth Estimation
  • 2. Gesture Interaction
  • 3. Voice Interaction
4.RDK MagicBox Basic Settings
  • 1.Network configuration
  • 2.Remote login
  • 3.Update system
  • 4.srpi-config user guide
  • 5.config. txt configuration file
  • 6.Self-startup setting
  • 7.RDK exclusive command usage
  • 8.Linux command usage
  • 9.GPIO readwrite operation
  • 10.Image classification algorithm
  • 11.Use USB camera
  • 12.MIPI Camera Usage
5.RDKX5 Magicbox Basic Development Course
For C language
  • 1. Camera Image Acquisition and Display
  • 2. Camera Image Local Saving
  • 3. Camera Image Acquisition and Encoding
  • 4. Video File Decoding and Display
  • 5. RTSP Stream Decoding
  • 6. VPS Scaling Example
  • 7. Target Detection Algorithm — focs
  • 8. Target Detection Algorithm — YOLOv5s
  • 9. Using CAN
For Python language
  • 1. Prerequisites Before Using Pin Functions
  • 2. Using GPIO
  • 3. Using PWM
  • 4. Use serial port
  • 5. Using I2C
  • 6. Using SPI
For Linux Development
  • Linux Development Guide
6.Online AI Model Course
Online AI Model Course(Text Interaction)
  • 0. Preparation before use
  • 1. OpenRouter Large Model API Aggregation Platform
  • 2. Multimodal Visual Understanding Application
  • 3. Multimodal Visual Positioning Application
  • 4. Multimodal Table Scanning Application
  • 5. Multimodal Autonomous Agent Application
Online AI Model Course(Voice Interaction)
  • 1. Online Speech‑to‑Text (ASR)
  • 2. Online Text‑to‑Speech (TTS)
  • 3. AI Large Model Voice Interaction
  • 4. Multimodal Visual Voice Interaction
  • 5. Multimodal Visual Positioning Application
  • 6. Multimodal Table Scanning Application
  • 7. Multimodal Autonomous Agent Application
  • 8. AI Large Model Online Voice Assistant
7.OpenClaw Embodied AI Development
  • 1. Introduction to OpenClaw
  • 2. OpenClaw Deployment
  • 3. OpenClaw Whatsapp Plugin Application
  • 4. OpenClaw WebChat Interaction
  • 5. OpenClaw TUI Interaction
  • 6. OpenClaw Tool Introduction
  • 7. OpenClawGate Gateway User Manual
  • 8. OpenClaw Plugin Feature Introduction
  • 9. OpenClaw ClawHub Introduction (skill installation)
  • 10. OpenClaw Application - File Management
  • 11. OpenClaw Application - Camera
  • 12. OpenClaw Application - Browser Control
  • 13. OpenClaw Application - Script Execution
  • 14. OpenClaw Application - AI‑programmed Status Light Control
  • 15. OpenClaw Application - AI‑programmed Servo Control
  • 16. OpenClaw Application - Dedicated AI Assistant
8.ROS2 Basic Tutorial
  • 1.Introduction to ROS2
  • 2.ROS2 install Humble
  • 3.ROS2 development environment
  • 4.ROS2 workspace
  • 5.ROS2 function package
  • 6.ROS2 node
  • 7.ROS2 topic communication
  • 8.ROS2 service communication
  • 9.ROS2 action communication
  • 10.ROS2 custom interface message
  • 11.ROS2 parameter service case
  • 12.ROS2 meta-function package
  • 13.ROS2 distributed communication
  • 14.ROS2 DDS
  • 15.ROS2 time related API
  • 16.ROS2 common command tools
  • 17.ROS2 rviz2 use
  • 18.ROS2 rqt toolbox
  • 19.ROS2 Launch startup file configuration
  • 20.ROS2 recording and playback tool
  • 21.ROS2 URDF model
  • 22.ROS2 Gazebo simulation platform
  • 23.ROS2 TF2 coordinate transformation
Download
  • Code
  • Software_tools
  • SystemFile
Download ZIP

Welcome to RDK X5 MagicBox repository

9. Using CAN

Using CAN

Using CANProtocol IntroductionInterface DescriptionModule IntroductionDriver Guidecan-utils tool introductionBasic usageTest GuideLoopback TestCANFD loopback testDual device communication testApplication Guide

Protocol Introduction

CAN CAN is the abbreviation of Controller Area Network, and its Chinese name is Controller Area Network. It is an ISO internationally standardized serial communication protocol and a serial communication protocol bus for real-time applications. It can use twisted pair cables to transmit signals and is one of the most widely used field buses in the world.

Advantages of CAN bus:

  • High reliability and strong anti-interference ability. The phy chip periphery is based on differential signals and twisted pair cables for transmission, which effectively offsets electromagnetic interference; the hardware-cured data link layer can automatically solve the problem of clock asynchrony between multiple nodes.
  • Strong error detection capability. The hardware-cured data link layer includes detection capabilities such as CRC and bit detection, which can almost 100% detect communication anomalies.
  • Perfect error management mechanism. If the message frame arbitration fails or is damaged during transmission, it can be automatically retransmitted; in the case of serious errors, the node has the function of automatically disconnecting from the bus, cutting off its connection with the bus without affecting the normal operation of the bus.
  • Strong real-time performance. The CAN bus has a high data transmission rate and can process and transmit large amounts of data in real time, meeting the real-time requirements of automotive electronic control systems.
  • Low cost The hardware cost of CAN bus is relatively low, which can reduce the overall cost of automotive electronic control system.
  • Long communication distance and fast message transmission speed The direct communication distance can reach up to 10km (rate below 4Kbps); the communication rate can reach up to 1Mbps (the maximum distance is 40m at this time).
  • Support multi-host communication and lossless arbitration technology When two nodes publish information at the same time, the high priority message can transmit data without being affected.
  • Abolition of the "address" concept, efficient and flexible One of the biggest features of CAN protocol is the abolition of traditional station address encoding, instead of communication message encoding.
  • Line encoding 1) The number of network nodes constituted by CAN is unlimited, and it has great flexibility in use; 2) When adding nodes to the bus, it will not affect the software, hardware and application layer of the existing nodes on the bus.
  • Simple structure, convenient networking, strong scalability When adding new devices, just put them on the twisted pair, without additional line modification (such as SPI, etc.).

CAN FD The strong market demand for improving the performance of the CAN bus has led to the emergence of CAN-FD (Flexible Data rate). CAN-FD promotes the advantages of CAN and makes up for its shortcomings. Its main features are as follows:

  • Extended effective data field The effective data field of each frame message of the CAN-FD protocol can reach 64 bytes5, while the traditional CAN protocol has only 8 bytes. This greatly increases the data transmission capacity, allowing more data to be transmitted in a single message.
  • Dual bit rate mode The CAN-FD protocol introduces a dual bit rate mode, which uses the nominal bit rate (up to 1 Mbit/s) in the arbitration segment and a higher data bit rate (up to 5 Mbit/s) in the data segment. This mode can increase the data transmission rate while ensuring compatibility.
  • Improved cyclic redundancy check and stuffing bit counter The CAN-FD protocol uses an improved cyclic redundancy check (CRC) and stuffing bit counter (SBC) to improve error detection capabilities. These improvements enhance data integrity and reliability.
  • Cancel support for remote frames To simplify the frame structure, the CAN-FD protocol cancels support for remote frames. This means that in a CAN-FD network, communication is done via data frames, and control and request via remote frames are no longer required.

 

Interface Description

  • RDK X5 provides a CAN communication interface and is equipped with a 120 ohm terminal resistor switch. When the terminal resistor needs to be enabled, just close the switch.
  • Terminal interface model: SH1.0 1X3P

Module Introduction

RDK X5 integrates TCAN4550 TCAN4550 is a CAN FD controller with an integrated CAN FD transceiver, supporting data rates up to 8Mbps. This CAN FD controller complies with the ISO11898-1:2015 High-speed Controller Area Network (CAN) data link layer specification and meets the physical layer requirements of the ISO11898–2:2016 High-speed CAN specification. TCAN4550 provides an interface between the CAN bus and the system processor through a serial peripheral interface (SPI), supports both classic CAN and CAN FD, and implements port expansion or CAN support for processors that do not support CAN FD. TCAN4550 provides CAN FD transceiver functions: differential transmission capability to the bus and differential reception capability from the bus.

  • Supports 1M CAN 2M CAN FD

Driver Guide

dts

​x
&spi5 {
  status = "okay";
  pinctrl-names = "default";
  pinctrl-0 = <&pinctrl_spi5 &lsio_gpio0_7 &lsio_gpio0_12>;

  tcan4x5x: tcan4x5x@0 {
    compatible = "ti,tcan4x5x";
    reg = <0>;
    #address-cells = <1>;
    #size-cells = <1>;
    spi-max-frequency = <10000000>;
    bosch,mram-cfg = <0x0 0 0 16 0 0 1 1>;
    interrupt-parent = <&ls_gpio0_porta>;
    interrupts = <12 IRQ_TYPE_EDGE_FALLING>;
    reset-gpios = <&ls_gpio0_porta 7 GPIO_ACTIVE_HIGH>;
  };
};

Drive code

xxxxxxxxxx
kernel\drivers\net\can\m_can\tcan4x5x-core.c

can-utils tool introduction

can-utils is a set of open source tools for Linux operating systems, specifically designed to handle tasks related to the CAN (Controller Area Network) bus. The CAN bus is widely used in automotive and industrial automation for communication between devices. This toolset provides a variety of command-line tools for sending, receiving and processing data on the CAN network. For example: cansend: Send a single CAN frame. candump: Capture and display data passing through the CAN interface. canplayer: Replay data recorded by candump. cansniffer: Display changes in CAN data. can-utils also includes some tools for advanced functions, such as setting CAN hardware filters or debugging CAN devices and networks. These tools are provided through a command-line interface and can be flexibly integrated into scripts and automation systems.

 

Basic usage

1. candump Display, filter and record CAN data

Basic usage:

xxxxxxxxxx
candump can0
  • Displays all CAN data passing through the can0 interface.

Filter for a specific ID:

xxxxxxxxxx
candump can0,123:7FF
  • Display CAN frame with ID 123.

Log data to file:

xxxxxxxxxx
candump -l can0
  • This will log the data through can0 to a file, the default file name format is candump-date.log.

2. canplayer canplayer is used to play back the CAN data log recorded with candump.

Basic usage:

xxxxxxxxxx
canplayer -I candump.log

 

  • Will replay the CAN data recorded in the file candump.log.

3. cansend is used to send the specified CAN frame

Basic usage:

xxxxxxxxxx
cansend can0 123#1122334455667788

 

  • Send a CAN frame with ID 123 and data content 1122334455667788 to the can0 interface.

4. cangen Generates random or regular CAN traffic for testing or simulation.

Basic usage:

xxxxxxxxxx
cangen can0 -I 1A -L 8 -D i -g 10 -n 100
  • Generate 100 incremental packets with ID 1A and length 8 bytes on can0, with 10 ms interval between each packet.

5. cansequence Send a series of CAN frames with increasing payload and check if there is frame loss.

Basic usage:

xxxxxxxxxx
cansequence can0

 

  • Send and inspect a series of CAN frames with increasing payload on can0.

6. cansniffer is used to display changes in CAN data, which is very helpful for debugging and understanding data flow.

Basic usage:

xxxxxxxxxx
cansniffer can0

 

  • Monitor and display any changes in CAN data on the can0 interface.

Test Guide

Loopback Test

Configure the can bus bit rate and loopback mode

xxxxxxxxxx
ip link set down can0
ip link set can0 type can bitrate 125000
ip link set can0 type can loopback on
ip link set up can0

View can0 configuration information

xxxxxxxxxx
ip -details link show can0

Continue to enter the receiving command (background receiving, can not block the serial port, the subsequent need to enter the sending command):

xxxxxxxxxx
candump can0 -L &

 

Send test input, and under normal circumstances the test data will be received immediately:

xxxxxxxxxx
cansend can0 123#1122334455667788

Test Results

 

CANFD loopback test

The arbitration segment baud rate is 500K, and the data field baud rate is 2M

xxxxxxxxxx
ip link set can0 down
ip link set can0 up type can bitrate 500000 dbitrate 2000000  fd on
ip link set can0 type can loopback on
ip link set can0 up

 

Send, receive CAN FD data

xxxxxxxxxx
candump can0 -L &
cansend can0 123##300112233445566778899aabbccddeeff

 

Dual device communication test

Hardware connection

 

  • GND to GND L to L H to H

Test command Two devices are configured with the same CAN bus bit rate

xxxxxxxxxx
ip link set down can0
ip link set can0 type can bitrate 125000
ip link set up can0

 

A device receives

xxxxxxxxxx
candump can0 -L

 

A device sends

xxxxxxxxxx
cansend can0 123#1122334455667788

 

Application Guide

Linux provides the SocketCAN interface, which makes CAN bus communication similar to Ethernet communication, and the application development interface is more universal and more flexible. Using socketCAN is just like using TCP/IP. Here is a simple sending and receiving routine:

First, configure the CAN bus bit rate and loopback mode

xxxxxxxxxx
ip link set down can0
ip link set can0 type can bitrate 125000
ip link set can0 type can loopback on
ip link set up can0

 

Writing a program

x
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <sys/socket.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <fcntl.h>

int main() {
  int sock;
  struct sockaddr_can addr;
  struct can_frame frame;

  // Create Socket
  sock = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  if (sock < 0) {
      perror("Socket");
      return 1;
  }

  // Get can0 interface
  struct ifreq ifr;
  strcpy(ifr.ifr_name, "can0");
  ioctl(sock, SIOCGIFINDEX, &ifr);

  // Binding Socket
  addr.can_family = PF_CAN;
  addr.can_ifindex = ifr.ifr_ifindex;
  bind(sock, (struct sockaddr *)&addr, sizeof(addr));

  // Send Message
  frame.can_id = 0x123;
  frame.can_dlc = 4;
  memcpy(frame.data, "\xde\xad\xbe\xef", 4);
  write(sock, &frame, sizeof(struct can_frame));

  // Receiving Messages
  while (1) {
      int nbytes = read(sock, &frame, sizeof(struct can_frame));
      if (nbytes > 0) {
          printf("Received: ID: 0x%X Data: ", frame.can_id);
          for (int i = 0; i < frame.can_dlc; i++) {
              printf("%02X ", frame.data[i]);
          }
          printf("\n");
      }
  }

  close(sock);
  return 0;
}

 

Compile and run Save the code to the file can_loopback.c.

Compile the program:

xxxxxxxxxx
gcc -o can_loopback can_loopback.c

 

Run the program:

xxxxxxxxxx
sudo ./can_loopback

 

The above code will send a CAN message and continuously receive and print the received messages.

Target Detection Algorithm — YOLOv5s
Prerequisites Before Using Pin Functions

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文