RT-Thread CAN Practical Implementation
RT-Thread has completed the porting for the Infineon XMC7200 EVK. You can access the console via UART3 through the shell. This article will introduce how to port CAN on RT-Thread.
Next, we will complete the driver migration for CAN_FD and successfully boot RT-Thread. First, refer to the post below to set up the development environment:
https://club.rt-thread.org/ask/article/4e5abc98191c3747.html
Then, in the main RT-Thread repository, find the template project for XMC7200 (path: \bsp\Infineon\xmc7200-kit_xmc7200_evk). Without changing any parameters, we will modify the application to make three LEDs blink in a loop, and then proceed to compile and download the program for verification.
Download and Verification:
Schematic Analysis
From the schematic of the development board and the chip’s multiplexing manual, it can be seen that the CAN_FD chip is driven by pins P0.2 and P0.3, using CAN channel 0, channel 1 for control. Additionally, pin P1.0 controls the standby function of the CAN transceiver.
Driver Migration
Use the RT-Thread ENV tool to configure the kernel, enabling the CAN bus driver at the kernel level. Then, regenerate the KEIL MDK project by running scons — target=mdk5.
Add the hardware layer CAN driver code in the `HAL_Drivers` directory, naming the files `drv_can.c` and `drv_can.h`.
Referencing the STM32 RT-Thread HAL driver, we need to make targeted changes to various parts and carefully verify the driver API calls to complete the porting. Since this is my first time using the Infineon XMC series processors, I do not yet fully understand the structure of its driver library and the correspondence of registers, so further modifications are needed for proper functionality. Currently, the implemented feature is that the kernel driver is mounted and displays correctly.
As shown in the figure below, a device named xmc_can0 can be found, but it cannot be operated on.
CAN Testing
To complete the evaluation of the XMC7200 CANFD driver, a CAN bus analyzer is needed. Considering cost factors, I chose to replicate an existing solution from the JLCPCB open-source project and manually assemble a simple CAN collector for testing and data analysis. I selected the USB_TO_CAN tool shown below, proceeded with PCB fabrication, soldering, testing, and downloaded the official firmware for communication verification.
The completed hardware and testing results are shown in the figure below:
By referencing the STM32 CAN driver, we have ported the Infineon CAN driver to integrate with the RT-Thread CAN framework. Ultimately, we have established a testing framework for the traditional CAN mode, which has been submitted to GitHub at the following link: [https://github.com/Jason0204/rtthread-xmc7200](https://github.com/Jason0204/rtthread-xmc7200). The testing results are as follows:
The driver migration and partial testing of CANFD in traditional mode on the XMC7200EVK under RT-Thread have been completed.