You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

x86架构Up Board 2(Ubilinux)下如何定义MPC2515 SPI设备设置?

Setting Up MCP2515 CAN Controller via SPI on x86 Up Board 2 (Ubilinux 4.9.45)

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=m or =y (for Intel SPI controller)
    • CONFIG_CAN_MCP251X=m or =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:

This is the most flexible way to register the device at runtime:

  • First, identify your SPI bus number (Up Board typically uses spi0; confirm with ls /sys/bus/spi/devices/).
  • Register the MCP2515 with your SPI bus and chip select (CS) pin (replace spi0 and 0 with your actual bus/CS number):
    echo mcp2515 0 > /sys/bus/spi/devices/spi0/new_device
    
    • The 0 here is the chip select pin number (adjust if you're using a different CS pin).

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=1000000
    
    • spi_speed sets 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
      

4. Persist Settings Across Reboots

To make these changes stick after a reboot:

  1. Add the required modules to /etc/modules so they load on boot:
    spi_intel
    mcp251x
    
  2. Create a systemd service to auto-register the device and configure the CAN interface:
    • Create /etc/systemd/system/can-setup.service with 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
      

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:45:55