Page 1 of 2

Spidev file not generated for slave

Posted: 2025-05-13 12:38
by Samip_veer
I am using luckfox-pico mini B and want to use it as a SPI slave device but spidev0.0 is not generated in /dev folder hereby sending my device file code and slave code.
---------Device tree code ---------------

Code: Select all

&spi0 {
    status = "okay";
    spi-slave; 
    slave {  
        compatible ="rockchip,spidev";
        reg = <0>;
        id = <0>;
    };
};
---------Slave C program------------------

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/spi/spidev.h>
#include <sys/ioctl.h>
#include <string.h>

#define SPI_DEVICE_PATH "/dev/spidev0.0"

int main() {
    int spi_file,ret;
    uint8_t tx_buffer[50];
    uint8_t rx_buffer[255];

    /* Open the SPI device */
    if ((spi_file = open(SPI_DEVICE_PATH, O_RDWR)) < 0) {
        perror("Failed to open SPI device");
        return -1;
    }

    /* Configure SPI mode and bits per word */
    uint8_t mode = SPI_MODE_0;
    uint8_t bits = 8;
    if (ioctl(spi_file, SPI_IOC_WR_MODE, &mode) < 0) {
        perror("Failed to set SPI mode");
        close(spi_file);
        return -1;
    }
    if (ioctl(spi_file, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) {
        perror("Failed to set SPI bits per word");
        close(spi_file);
        return -1;
    }

    /* Perform SPI transfer */
    struct spi_ioc_transfer transfer = {
        .tx_buf = (unsigned long)tx_buffer,
        .rx_buf = (unsigned long)rx_buffer,
        .len = sizeof(rx_buffer),
        .delay_usecs = 0,
        .speed_hz = 49000000,  // SPI speed in Hz
        .bits_per_word = 8,
    };

    while(1)
    {
        /* Clear buffer */
        memset(rx_buffer,0,sizeof(rx_buffer));
       
       /* Waiting for data */
        do {
            ret = ioctl(spi_file, SPI_IOC_MESSAGE(1), &transfer);    
        } while (ret < 0);

        /* Print  rx_buffer*/
        printf("---------Receive %d bytes of data  max speed:%d Hz---------\n",ret,transfer.speed_hz);
        printf("SPI RX: 0x%08X:", 0);
        for (int i = 0; i < ret; i++) {
            printf(" %02X",rx_buffer[i] );
            if ((i + 1) % 16 == 0){
                printf("\nSPI RX: 0x%08X:", i+1);
            }
        }
        printf("\n");
    }

    /* Close the SPI device */
    close(spi_file);

    return 0;
}
I have done the following configuration
1. User mode SPI device driver support = Y
2. SPI slave protocol handlers = Y

Can you please help regarding the matter i am following the procedure from the WIKI but still not able to generate device file.

Re: Spidev file not generated for slave

Posted: 2025-05-14 2:22
by Crocodile
Hello, please obtain the spi kernel information and attach the complete device tree file

Code: Select all

cat /var/log/messages  | grep "spi" 

Re: Spidev file not generated for slave

Posted: 2025-05-14 8:46
by Samip_veer
Here by sharing details

Code: Select all

[root@luckfox slprograms]# cat /var/log/messages  | grep "spi"
Jan  1 00:00:00 luckfox kern.info kernel: [    0.088934] spi-nand spi2.0: Winbond SPI NAND was found.
Jan  1 00:00:00 luckfox kern.info kernel: [    0.088961] spi-nand spi2.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
Jan  1 00:00:00 luckfox kern.notice kernel: [    0.090173] 7 cmdlinepart partitions found on MTD device spi-nand0
Jan  1 00:00:00 luckfox kern.notice kernel: [    0.090190] Creating 7 MTD partitions on "spi-nand0":
------Device tree file---------

Code: Select all

// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2023 Luckfox Electronics Co., Ltd.
 */

/dts-v1/;

#include "rv1103.dtsi"
#include "rv1106-evb.dtsi"
#include "rv1103-luckfox-pico-ipc.dtsi"

/ {
	model = "Luckfox Pico Mini";
	compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1103";
};

/**********SFC**********/
&sfc {
	status = "okay";
	flash@0 {
		compatible = "spi-nand";
		reg = <0>;
		spi-max-frequency = <75000000>;
		spi-rx-bus-width = <4>;
		spi-tx-bus-width = <1>;
	};
};

/**********SDMMC**********/
&sdmmc {
	max-frequency = <50000000>;
	no-sdio;
	no-mmc;
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	disable-wp;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc0_clk &sdmmc0_cmd &sdmmc0_det &sdmmc0_bus4>;
	status = "okay";
};

/**********ETH**********/
&gmac {
	status = "disabled";
};

/**********USB**********/
&usbdrd_dwc3 {
	status = "okay";
	dr_mode = "peripheral";
};

/**********SPI**********/
/* SPI0_M0 */

//&spi0 {
//	status = "okay";
//	spidev@0 {
//		spi-max-frequency = <50000000>;
//	};
//};

//&spi0 {
//    status = "okay";
//    spi_test@00 {
//        compatible = "rockchip,spidev";
//        reg = <0>;    
//        spi-cpha;  
//        spi-cpol;    
//        spi-lsb-first; 
//        spi-max-frequency = <1000000>;  
//        status = "okay";
//    };
//};

&spi0 {
    status = "okay";
    spi-slave; 
    slave {  
        compatible ="rockchip,spidev";
        reg = <0>;
        id = <0>;
    };
};

/**********I2C**********/
/* I2C3_M1 */
&i2c3 {
	status = "disabled";
	clock-frequency = <100000>;
};

/**********UART**********/
/* UART3_M1 */
&uart3 {
	status = "disabled";
};

/* UART4_M1 */
&uart4 {
	status = "disabled";
};

/**********PWM**********/
/* PWM1_M0 */
&pwm1 {
	status = "disabled";
};


Re: Spidev file not generated for slave

Posted: 2025-05-15 1:14
by Crocodile
According to the logs, your device tree modifications have not been successfully applied, please check whether the recompiled boot.img is burned

Re: Spidev file not generated for slave

Posted: 2025-05-15 7:05
by Samip_veer
Burning of the boot.img is probably correct but while compiling the kernel i am getting the following warning regarding SPI

Code: Select all

/home/samip/luckfox-pico/sysdrv/source/kernel/arch/arm/boot/dts/rv1106.dtsi:1059.21-1072.4: Warning (spi_bus_bridge): /spi@ff500000: incorrect #address-cells for SPI bus
  also defined at /home/samip/luckfox-pico/sysdrv/source/kernel/arch/arm/boot/dts/rv1103-luckfox-pico-ipc.dtsi:314.7-335.3
  also defined at /home/samip/luckfox-pico/sysdrv/source/kernel/arch/arm/boot/dts/rv1103g-luckfox-pico-mini.dts:77.7-86.3
arch/arm/boot/dts/rv1103g-luckfox-pico-mini.dtb: Warning (spi_bus_reg): Failed prerequisite 'spi_bus_bridge'
I even tried adding property of address cell as shown below

Code: Select all

&spi0 {
   	 status = "okay";
	#address-cells = <0>;
   	spi-slave; 
	slave {  
        compatible ="rockchip,spidev";
        reg = <0>;
        id = <0>;
    };
};
But then i get a warning regarding the reg property as shown below

Code: Select all

/home/samip/luckfox-pico/sysdrv/source/kernel/arch/arm/boot/dts/rv1103-luckfox-pico-ipc.dtsi:322.3-13: Warning (reg_format): /spi@ff500000/spidev@0:reg: property has invalid length (4 bytes) (#address-cells == 0, #size-cells == 0)
/home/samip/luckfox-pico/sysdrv/source/kernel/arch/arm/boot/dts/rv1103-luckfox-pico-ipc.dtsi:326.7-17: Warning (reg_format): /spi@ff500000/fbtft@0:reg: property has invalid length (4 bytes) (#address-cells == 0, #size-cells == 0)
/home/samip/luckfox-pico/sysdrv/source/kernel/arch/arm/boot/dts/rv1103g-luckfox-pico-mini.dts:83.9-19: Warning (reg_format): /spi@ff500000/slave:reg: property has invalid length (4 bytes) (#address-cells == 0, #size-cells == 0)
arch/arm/boot/dts/rv1103g-luckfox-pico-mini.dtb: Warning (pci_device_bus_num): Failed prerequisite 'reg_format'
arch/arm/boot/dts/rv1103g-luckfox-pico-mini.dtb: Warning (i2c_bus_reg): Failed prerequisite 'reg_format'
arch/arm/boot/dts/rv1103g-luckfox-pico-mini.dtb: Warning (spi_bus_reg): Failed prerequisite 'reg_format'
Please check and if any modification in the device tree required please assist on the same.

Re: Spidev file not generated for slave

Posted: 2025-05-15 9:29
by Crocodile
The “#address-cells = <0>;” is not need to add, the attachment is the boot.img I compiled, after the test, you can successfully register /dev/spidev0.0, the reference is also the instructions in the wiki, and there is no problem with the actual measurement

Re: Spidev file not generated for slave

Posted: 2025-05-15 13:18
by Crocodile
Supplementary attachments

Re: Spidev file not generated for slave

Posted: 2025-05-15 14:15
by Samip_veer
Thank you for the boot.img file now the device is being generated
Hereby attaching logs for the same

Code: Select all

[root@luckfox root]# cat /var/log/messages  | grep "spi"
Jan  1 00:00:05 luckfox kern.warn kernel: [    0.088929] rockchip-spi ff500000.spi: no high_speed pinctrl state
Jan  1 00:00:05 luckfox kern.err kernel: [    0.089415] spi_slave spi0: /spi@ff500000/spidev@0 is not called 'slave'
Jan  1 00:00:05 luckfox kern.warn kernel: [    0.089448] spi_slave spi0: Failed to create SPI device for /spi@ff500000/spidev@0
Jan  1 00:00:05 luckfox kern.err kernel: [    0.089470] spi_slave spi0: /spi@ff500000/fbtft@0 is not called 'slave'
Jan  1 00:00:05 luckfox kern.warn kernel: [    0.089483] spi_slave spi0: Failed to create SPI device for /spi@ff500000/fbtft@0
Jan  1 00:00:05 luckfox kern.info kernel: [    0.090014] rockchip-spi ff500000.spi: probed, poll=0, rsd=0
Jan  1 00:00:05 luckfox kern.info kernel: [    0.091526] spi-nand spi2.0: Winbond SPI NAND was found.
Jan  1 00:00:05 luckfox kern.info kernel: [    0.091556] spi-nand spi2.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
Jan  1 00:00:05 luckfox kern.notice kernel: [    0.092915] 7 cmdlinepart partitions found on MTD device spi-nand0
Jan  1 00:00:05 luckfox kern.notice kernel: [    0.092938] Creating 7 MTD partitions on "spi-nand0":
Can you please also share boot.img for master device (luckfox-mini B) as device is generated but there is no output on oscilloscope here by sharing logs for master

Code: Select all

[root@luckfox root]# cat /var/log/messages  | grep "spi"
Jan  1 00:00:00 luckfox kern.warn kernel: [    0.087869] rockchip-spi ff500000.spi: no high_speed pinctrl state
Jan  1 00:00:00 luckfox kern.err kernel: [    0.088858] rockchip-spi ff500000.spi: chipselect 0 already in use
Jan  1 00:00:00 luckfox kern.err kernel: [    0.088890] spi_master spi0: spi_device register error /spi@ff500000/fbtft@0
Jan  1 00:00:00 luckfox kern.warn kernel: [    0.088909] spi_master spi0: Failed to create SPI device for /spi@ff500000/fbtft@0
Jan  1 00:00:00 luckfox kern.err kernel: [    0.088930] rockchip-spi ff500000.spi: chipselect 0 already in use
Jan  1 00:00:00 luckfox kern.err kernel: [    0.088944] spi_master spi0: spi_device register error /spi@ff500000/spi_test@00
Jan  1 00:00:00 luckfox kern.warn kernel: [    0.088956] spi_master spi0: Failed to create SPI device for /spi@ff500000/spi_test@00
Jan  1 00:00:00 luckfox kern.info kernel: [    0.088967] rockchip-spi ff500000.spi: probed, poll=0, rsd=0
Jan  1 00:00:00 luckfox kern.info kernel: [    0.090425] spi-nand spi2.0: Winbond SPI NAND was found.
Jan  1 00:00:00 luckfox kern.info kernel: [    0.090451] spi-nand spi2.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
Jan  1 00:00:00 luckfox kern.notice kernel: [    0.091799] 7 cmdlinepart partitions found on MTD device spi-nand0
Jan  1 00:00:00 luckfox kern.notice kernel: [    0.091821] Creating 7 MTD partitions on "spi-nand0":
Jan  1 00:00:07 luckfox kern.err kernel: [    7.457669] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/status
Jan  1 00:00:07 luckfox kern.err kernel: [    7.457718] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/pinctrl-0
Jan  1 00:00:07 luckfox kern.err kernel: [    7.457734] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/spidev@0/status
Jan  1 00:00:07 luckfox kern.err kernel: [    7.457749] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/spidev@0/spi-max-frequency

Re: Spidev file not generated for slave

Posted: 2025-05-16 3:15
by Crocodile
In SPI communication, a slave device cannot send out data without a clock input from the master. The SPI master configuration can be done using the luckfox-config command. (Note: Modifying the device tree may cause luckfox-config to stop functioning correctly, as it only supports configuration in master mode.)

The boot.img I provided is only to help you verify the cause of the configuration failure. At this point, we can rule out flashing issues. If you need further investigation, you can provide your own boot.img for analysis.

Re: Spidev file not generated for slave

Posted: 2025-05-17 12:19
by Samip_veer
My point is i am trying to do a establish a communication between (luckfox-pico-mini-B(slave)) to (luckfox-pico-mini-B(master)), I have configured both the devices and modified the device tree but not able to to establish communication there were following issues :-

1) Slave side spidev0.0 device was not generated
But thanks to your boot.img for slave i am able to generate the device

2) Master side spidev0.0 device is generted but no output on oscilloscope
I feel there is some problem in configuring the device tree it would be very helpful if you can generate a boot.img for (luckfox-pico-mini-B(spi_master)) and share it here.

for your refrence i am sharing kernel info for the master device below

Code: Select all

Jan  1 00:00:00 luckfox kern.warn kernel: [    0.087962] rockchip-spi ff500000.spi: no high_speed pinctrl state
Jan  1 00:00:00 luckfox kern.err kernel: [    0.088957] rockchip-spi ff500000.spi: chipselect 0 already in use
Jan  1 00:00:00 luckfox kern.err kernel: [    0.088988] spi_master spi0: spi_device register error /spi@ff500000/fbtft@0
Jan  1 00:00:00 luckfox kern.warn kernel: [    0.089006] spi_master spi0: Failed to create SPI device for /spi@ff500000/fbtft@0
Jan  1 00:00:00 luckfox kern.err kernel: [    0.089026] rockchip-spi ff500000.spi: chipselect 0 already in use
Jan  1 00:00:00 luckfox kern.err kernel: [    0.089039] spi_master spi0: spi_device register error /spi@ff500000/spi_test@00
Jan  1 00:00:00 luckfox kern.warn kernel: [    0.089052] spi_master spi0: Failed to create SPI device for /spi@ff500000/spi_test@00
Jan  1 00:00:00 luckfox kern.info kernel: [    0.089063] rockchip-spi ff500000.spi: probed, poll=0, rsd=0
Jan  1 00:00:00 luckfox kern.info kernel: [    0.090520] spi-nand spi2.0: Winbond SPI NAND was found.
Jan  1 00:00:00 luckfox kern.info kernel: [    0.090546] spi-nand spi2.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
Jan  1 00:00:00 luckfox kern.notice kernel: [    0.091910] 7 cmdlinepart partitions found on MTD device spi-nand0
Jan  1 00:00:00 luckfox kern.notice kernel: [    0.091930] Creating 7 MTD partitions on "spi-nand0":