yeisonint wrote: ↑2024-12-21 5:56
I was finally able to load the module into the kernel with the following configuration, but it fails in the last step:
1. Compile busybox/buildroot
./build.sh lunch
./build.sh
2. Add CAN support to the kernel, include MCP251X driver
./build.sh clean kernel
cd sysdrv/source/kernel
cp ./arch/arm/configs/luckfox_rv1106_linux_defconfig .config
make ARCH=arm menuconfig
Networking support ---> CAN bus subsystem support ---> select Raw CAN Protocol and go to CAN Device drivers ---> CAN SPI interfaces ---> select `Microchip MCP251x and MCP25625 SPI CAN controllers` as modules (M)
make ARCH=arm savedefconfig
cp defconfig ./arch/arm/configs/luckfox_rv1106_linux_defconfig
3. Go back to sdk root folder, and modify buildroot
cd sysdrv/source/buildroot/buildroot-2023.02.6
make luckfox_pico_defconfig
make menuconfig
Target packages ---> Networking applications ---> select can-utils
make savedefconfig
make
4. Go dts folder
cd sysdrv/source/kernel/arch/arm/boot/dts
5. Modify `rv1103g-luckfox-pico-mini.dts`
Chage
/* SPI0_M0 */
&spi0 {
status = "disabled";
...
To:
/* SPI0_M0 */
&spi0 {
status = "okay";
...
6. Modify `rv1103-luckfox-pico-ipc.dtsi`
Add this after DHT11 section:
can0: mcp2515@0 {
compatible = "microchip,mcp2515";
reg = <0 0>;
clocks = <&clk_mcp2515>;
clock-names = "mcp2515";
spi-max-frequency = <10000000>;
interrupt-parent = <&gpio0>;
interrupts = <RK_PA4 GPIO_ACTIVE_LOW>;
vdd-supply = <&vcc_3v3>;
xceiver-supply = <&vcc_3v3>;
};
clk_mcp2515: clk_mcp2515 {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <8000000>;
};
Change SPI configuraton from:
// SPI
&spi0 {
pinctrl-0 = <&spi0m0_clk &spi0m0_miso &spi0m0_mosi &spi0m0_cs0>;
#address-cells = <1>;
#size-cells = <0>;
spidev@0 {
compatible = "rockchip,spidev";
spi-max-frequency = <50000000>;
reg = <0>;
};
fbtft@0{
compatible = "sitronix,st7789v";
reg = <0>;
spi-max-frequency = <20000000>;
fps = <30>;
buswidth = <8>;
debug = <0x7>;
led-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_HIGH>;//BL
dc-gpios = <&gpio1 RK_PA2 GPIO_ACTIVE_HIGH>; //DC
reset-gpios = <&gpio1 RK_PC3 GPIO_ACTIVE_LOW>; //RES
};
};
to:
&spi0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi0m0_clk &spi0m0_miso &spi0m0_mosi &spi0m0_cs0>;
mcp2515@0 {
compatible = "microchip,mcp2515";
reg = <0 0>;
spi-max-frequency = <10000000>;
interrupts = <&gpio0 RK_PA4 GPIO_ACTIVE_LOW>;
interrupt-parent = <&gpio0>;
clocks = <&clk_mcp2515>;
clock-names = "mcp2515";
};
};
7. Build all
./build.sh lunch
./build.sh
8. Burn the firmware to the board
sudo ./rkflash.sh update
9. Connections
Pico mini b - MCP2515
SPI0_CS0_M0 -> CS
SPI0_CLK_M0 -> SCLK
SPI0_MOSI_M0 -> SI
SPI0_MISO_M0 -> SO
GPIO0_A4_d -> INT
10. Power on and connect to the board
11. Load the module in the kernel
cd /oem/usr/ko
insmod mcp251x.ko
12. Check dmesg:
dmesg | grep -E 'can|spi|mcp251x'
Output:
[ 0.126339] can: controller area network core
[ 0.126456] can: raw protocol
[ 0.126468] can: broadcast manager protocol
[ 0.126486] can: netlink gateway - max_hops=1
[ 0.371569] ubi0: scanning is finished
[ 6.574255] ubi4: scanning is finished
[ 7.841856] ubi5: scanning is finished
[ 105.192216] mcp251x spi0.0 can0: MCP2515 successfully initialized.
13. Setting up CAN (Here it fails!!!!!)
ip link set can0 up type can bitrate 1000000
it says:
ip: either "dev" is duplicate, or "type" is garbage
if you only run:
ip link set can0 up
the dmesg says:
[ 3849.858662] mcp251x spi0.0 can0: bit-timing not yet defined
[ 3849.858717] mcp251x spi0.0: unable to set initial baudrate!
How can I set this up now, I feel like I'm so close to achieving it?