x86架构Up Board 2(Ubilinux)下如何定义MPC2515 SPI设备设置?
Got it, since you're working on an x86-based Up Board 2 where device trees aren't used (unlike ARM systems), we need to rely on kernel modules and sysfs/module parameters to register the MCP2515 SPI device. Here's a step-by-step guide:
1. Verify & Load Required Kernel Modules
First, make sure the SPI controller driver and MCP2515 CAN driver are available:
- Check if the SPI controller module is loaded (for Apollo Lake-based Up Board 2, this is usually
spi_intel):lsmod | grep spi - Check if the MCP2515 driver is loaded:
lsmod | grep mcp251x - If either module is missing, load them manually:
modprobe spi_intel modprobe mcp251x - If modules don't exist at all, you'll need to recompile your kernel with these configs enabled:
CONFIG_SPI_INTEL=mor=y(for Intel SPI controller)CONFIG_CAN_MCP251X=mor=y(for MCP2515 CAN driver)
2. Register the MCP2515 SPI Device
Since there's no device tree, we have to manually tell the kernel about the MCP2515 on the SPI bus. Use one of these two methods:
Method 1: Sysfs Interface (Recommended)
This is the most flexible way to register the device at runtime:
- First, identify your SPI bus number (Up Board typically uses
spi0; confirm withls /sys/bus/spi/devices/). - Register the MCP2515 with your SPI bus and chip select (CS) pin (replace
spi0and0with your actual bus/CS number):echo mcp2515 0 > /sys/bus/spi/devices/spi0/new_device- The
0here is the chip select pin number (adjust if you're using a different CS pin).
- The
Method 2: Module Parameters
You can pass device details directly when loading the MCP2515 driver:
- Unload the driver first if it's already loaded:
rmmod mcp251x - Reload the driver with SPI bus, CS, and speed parameters (adjust values to match your hardware):
modprobe mcp251x spi_port=0 spi_cs=0 spi_speed=1000000spi_speedsets the SPI clock (MCP2515 supports up to 10MHz; 1MHz is a safe default).
3. Configure & Activate the CAN Interface
Once the device is registered, the kernel will create a CAN interface (usually can0):
- List available CAN interfaces to confirm:
ip link show - Set your desired CAN bitrate (e.g., 500kbps):
ip link set can0 type can bitrate 500000 - Activate the interface:
ip link set can0 up - Test the interface:
- Send a test frame:
cansend can0 123#1122334455667788 - Listen for incoming frames:
candump can0
- Send a test frame:
4. Persist Settings Across Reboots
To make these changes stick after a reboot:
- Add the required modules to
/etc/modulesso they load on boot:spi_intel mcp251x - Create a systemd service to auto-register the device and configure the CAN interface:
- Create
/etc/systemd/system/can-setup.servicewith this content:[Unit] Description=Auto-configure MCP2515 CAN Interface After=multi-user.target [Service] Type=oneshot ExecStart=/bin/bash -c 'echo mcp2515 0 > /sys/bus/spi/devices/spi0/new_device; ip link set can0 type can bitrate 500000; ip link set can0 up' [Install] WantedBy=multi-user.target - Enable and start the service:
systemctl enable can-setup.service systemctl start can-setup.service
- Create
Important Hardware Notes
Double-check your wiring:
- Connect SPI SCLK, MOSI, MISO pins between Up Board and MCP2515 correctly.
- Ensure the CS pin matches the chip select number you used in the registration step.
- The MCP2515's INT pin can be connected to a GPIO for interrupt support (optional but improves performance), but it's not required for basic functionality.
内容的提问来源于stack exchange,提问作者MaryemAyadi

