patrickrrocha
Posts: 3
Joined: Fri Jan 31, 2020 2:02 pm

SPI1-spidev2 troubleshoot

Wed Feb 12, 2020 2:54 pm

I am trying to connect a HAT with an ARINC controller chip (hi-3593) that should use CE2 pin (spi1.2) to communicate with the RPi. It also has 2 mcp2515 CAN controllers which are initiallizing and working accordingly. I am loading the dtoverlay=spi1-3cs in the config.txt to enable the 3 chip selects of the SPI1 But while implementing the device tree overlay for the ARINC chip I have stumbled upon an error:

Which is strange because it is the same syntax used for spidev0 and spidev1 used in the enabling of the mcp2515 can controllers.
Here is the working dts of the mcp2515 enabled in spi1.0:

Code: Select all

/*
 * Device tree overlay for mcp251x/can1 on spi1.1 edited by petit_miner
 */

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
    /* disable spi-dev for spi1.1 */
    [email protected] {
        target = <&spi1>;
        __overlay__ {
            status = "okay";
        };
    };

    [email protected] {
	target = <&spidev1>;
	__overlay__ {
	    status = "okay";
	};
    };

    /* the interrupt pin of the can-controller */
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            can1_pins: can1_pins {
                brcm,pins = <25>;
                brcm,function = <0>; /* input */
            };
        };
    };

    /* the clock/oscillator of the can-controller */
    [email protected] {
        target-path = "/clocks";
        __overlay__ {
            /* external oscillator of mcp2515 on spi1.1 */
            can1_osc: can1_osc {
                compatible = "fixed-clock";
                #clock-cells = <0>;
                clock-frequency  = <16000000>;
            };
        };
    };

    /* the spi config of the can-controller itself binding everything together */
    [email protected] {
        target = <&spi1>;
        __overlay__ {
            /* needed to avoid dtc warning */
            #address-cells = <1>;
            #size-cells = <0>;
            can1: [email protected] {
                reg = <1>;
                compatible = "microchip,mcp2515";
                pinctrl-names = "default";
                pinctrl-0 = <&can1_pins>;
                spi-max-frequency = <10000000>;
                interrupt-parent = <&gpio>;
                interrupts = <25 0x2>;
                clocks = <&can1_osc>;
            };
        };
    };
    __overrides__ {
        oscillator = <&can1_osc>,"clock-frequency:0";
        spimaxfrequency = <&can1>,"spi-max-frequency:0";
        interrupt = <&can1_pins>,"brcm,pins:0",<&can1>,"interrupts:0";
    };
};
Here is the non working dts of the hi-3593 arinc chip which I am trying to enable in spi1.2

Code: Select all

/*
 * Device tree overlay for hi3593/arinc on spi1.2
 */

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
    /* disable spi-dev for spi1.2 */
    [email protected] {
        target = <&spi1>;
        __overlay__ {
            status = "okay";
        };
    };

    [email protected] {
	target = <&spidev2.0>;
	__overlay__ {
	    status = "okay";
	};
    };

    /* the interrupt pin of the hi3593 */
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            arinc_pins: arinc_pins {
                brcm,pins = <13 16>;
                brcm,function = <0>; /* input */
            };
        };
    };

    /* the clock/oscillator of the hi3593 */
    [email protected] {
        target-path = "/clocks";
        __overlay__ {
            /* external oscillator of hi3593 on spi1.2 */
            arinc_osc: arinc_osc {
                compatible = "fixed-clock";
                #clock-cells = <0>;
                clock-frequency  = <16000000>;
            };
        };
    };

    /* the spi config of the can-controller itself binding everything together */
    [email protected] {
        target = <&spi1>;
        __overlay__ {
            /* needed to avoid dtc warning */
            #address-cells = <1>;
            #size-cells = <0>;
            arinc: [email protected] {
                reg = <0>;
                compatible = "holt,hi3593";
                spi-max-frequency = <10000000>;
                interrupt-parent = <&gpio>;
                interrupts = <13 0>, <16 0>;
                //reset-gpio = <&gpio5 6 GPIO_ACTIVE_HIGH>;
                oscillator = <&arinc_osc>;
            };
        };
    };
    __overrides__ {
        oscillator = <&arinc_osc>,"clock-frequency:0";
        spimaxfrequency = <&arinc>,"spi-max-frequency:0";
        interrupt = <&arinc_pins>,"brcm,pins:0",<&arinc>,"interrupts:0";
    };
};
Here is the config.txt file beeing used

Code: Select all

                                                                                                                                                                                       
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
#dtoverlay=vc4-fkms-v3d

# NOOBS Auto-generated Settings:

#New directives CTU Project:
dtparam=i2c_vc=on

#Bluetooth Disabling
dtoverlay=pi3-disable-bt
sudo systemctl disable hciuart

#dtoverlay=spi1-1cs,cs0_spidev=disabled

#SPI1 Overlay

dtoverlay=spi1-3cs,cs0_pin=6,cs1_pin=12,cs2_pin=26,cs0_spidev=off,cs1_spidev=off,cs2_spidev=off

#CAN Overlay

dtoverlay=mcp2515-can1-spi1-1,oscillator=20000000,interrupt=5,spimaxfrequency=500000
dtoverlay=mcp2515-can0-spi1-0,oscillator=20000000,interrupt=7,spimaxfrequency=500000

#ARINC Overlay

dtoverlay=hi3593-arinc-spi1-2,oscillator=12000000,spimaxfrequency=500000

#Debugging Device Tree
dtdebug=on
Here is the log obtained with

Code: Select all

sudo vcdbg log msg

Code: Select all

001549.866: brfs: File read: /mfs/sd/config.txt
001551.301: brfs: File read: 2405 bytes
001632.468: brfs: File read: /mfs/sd/config.txt
001856.852: gpioman: gpioman_get_pin_num: pin DISPLAY_DSI_PORT not defined
001858.944: *** Restart logging
001859.010: brfs: File read: 2405 bytes
001889.442: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
001898.542: brfs: File read: /mfs/sd/bcm2710-rpi-3-b-plus.dtb
001898.606: Loading 'bcm2710-rpi-3-b-plus.dtb' to 0x100 size 0x69ae
002121.851: brfs: File read: 27054 bytes
002126.480: brfs: File read: /mfs/sd/config.txt
002127.052: dtparam: i2c_arm=on
002152.240: dtparam: audio=on
002182.482: dtparam: i2c_vc=on
002204.692: brfs: File read: 2405 bytes
002217.529: brfs: File read: /mfs/sd/overlays/pi3-disable-bt.dtbo
002252.897: Loaded overlay 'pi3-disable-bt'
002326.175: brfs: File read: 954 bytes
002340.333: brfs: File read: /mfs/sd/overlays/spi1-3cs.dtbo
002368.718: Loaded overlay 'spi1-3cs'
002368.775: dtparam: cs0_pin=6
002369.575: dtparam: cs1_pin=12
002370.386: dtparam: cs2_pin=26
002371.204: dtparam: cs0_spidev=off
002371.939: dtparam: cs1_spidev=of
002510.892: brfs: File read: 2269 bytes
002526.540: brfs: File read: /mfs/sd/overlays/mcp2515-can1-spi1-1.dtbo
002555.128: Loaded overlay 'mcp2515-can1-spi1-1'
002555.185: dtparam: oscillator=20000000
002555.969: dtparam: interrupt=5
002557.298: dtparam: spimaxfrequency=5
002677.414: brfs: File read: 1941 bytes
002692.240: brfs: File read: /mfs/sd/overlays/mcp2515-can0-spi1-0.dtbo
002721.024: Loaded overlay 'mcp2515-can0-spi1-0'
002721.085: dtparam: oscillator=20000000
002721.863: dtparam: interrupt=7
002723.196: dtparam: spimaxfrequency=5
002844.939: brfs: File read: 1941 bytes
002860.698: brfs: File read: /mfs/sd/overlays/hi3593-arinc-spi1-2.dtbo
002880.694: dterror: can't find symbol 'spidev2'
002880.708: Failed to resolve overlay 'hi3593-arinc-spi1-2'
002882.157: brfs: File read: 1837 bytes
002886.600: brfs: File read: /mfs/sd/cmdline.txt
002886.697: Read command line from file 'cmdline.txt':
002886.759: 'boot=overlay console=serial0,115200 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles'
004924.188: gpioman: gpioman_get_pin_num: pin EMMC_ENABLE not defined
005098.909: brfs: File read: 173 bytes
005477.284: brfs: File read: /mfs/sd/kernel7.img
005477.350: Loading 'kernel7.img' to 0x8000 size 0x52b718
005477.424: Device tree loaded to 0x2eff8c00 (size 0x73db)
005479.627: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
006812.721: vchiq_core: vchiq_init_state: slot_zero = 0xfad80000, is_master = 1
006817.477: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
006823.297: TV service:host side not connected, dropping notification 0x00000002, 0x00000001, 0x00000010
011073.410: brfs: File read: 5420824 bytes
The log shows this error:

Code: Select all

 dterror: can't find symbol 'spidev2'
Does anyone know what could be causing this spi1.2 enabling problem?
Sorry for the long post, thank you for your attention.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2588
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: SPI1-spidev2 troubleshoot

Wed Feb 12, 2020 4:19 pm

Hmm, where to start? I'll try working through your post in order, commenting as I go.
I am loading the dtoverlay=spi1-3cs in the config.txt to enable the 3 chip selects of the SPI1 But while implementing the device tree overlay for the ARINC chip I have stumbled upon an error:

Which is strange because it is the same syntax used for spidev0 and spidev1 used in the enabling of the mcp2515 can controllers.
Here is the working dts of the mcp2515 enabled in spi1.0:
As an example, that overlay suffers from some inaccurate comments and other strangeness:

Code: Select all

    /* disable spi-dev for spi1.1 */
[The overlay does nothing of the sort - it enables spi1 as an interface and also enables spidev for spi0.1 (that's what "spidev1" refers to). Why it would do this is unclear.

Code: Select all

        target = <&spi1>;
        __overlay__ {
...
            can1: [email protected] {
The overlay instantiates a driver on spi1.1, so spidev shouldn't be enabled there, but the overlay isn't guaranteeing that.
Here is the non working dts of the hi-3593 arinc chip which I am trying to enable in spi1.2

Code: Select all

    /* disable spi-dev for spi1.2 */
As a statement of intent this is understandable, but it doesn't reflect what the overlay does.

Code: Select all

	target = <&spidev2.0>;
This is wrong on many levels:
1. "spidev2.0" isn't a legal label - they have to obey the same rules as C identifiers - "spidev2_0" would be better.
2. Nothing is defining the label "spidev2.0" (or "spidev2_0"). It isn't in the base .dtbs, and overlays (with a few exceptions) can't add new symbols to the base dtb (but this will change in the future).
3. Why "spidev2.0" anyway? "spidev1.2"/"spidev1_2" would make more sense.
4. Setting the status to "okay" is enabling it, not disabling it.
5. It's totally unnecessary because of the way you instantiate spi1-3cs in config.txt - see below.

Code: Select all

            arinc: [email protected] {
                reg = <0>;
                compatible = "holt,hi3593";
                spi-max-frequency = <10000000>;
                interrupt-parent = <&gpio>;
                interrupts = <13 0>, <16 0>;
                //reset-gpio = <&gpio5 6 GPIO_ACTIVE_HIGH>;
                oscillator = <&arinc_osc>;
            };
Here you've omitted the pinctrl-names and pinctrl-0 properties that the example overlay had, which means that your arinc_pins node does nothing. As the purpose of those declarations is just to prevent others from using your pins (it would be different if you were setting an Alt function on them) you can live without them, but it's inconsistent and confusing for readers.

Code: Select all

        interrupt = <&arinc_pins>,"brcm,pins:0",<&arinc>,"interrupts:0";
You appear to declare two interrupt pins, but the overlay can only change one of them.
Here is the config.txt file beeing used

Code: Select all

...
dtoverlay=spi1-3cs,cs0_pin=6,cs1_pin=12,cs2_pin=26,cs0_spidev=off,cs1_spidev=off,cs2_spidev=off
And here's the reason you don't need to worry about spidevs - the spi1-3cs overlay has already disabled them all.

I suggest you:
* Delete the bogus comment and your reference to spidev2.0.
* Add the pinctrl-0 and pinctrl-names properties.
* Consider adding a parameter to configure the second interrupt.

patrickrrocha
Posts: 3
Joined: Fri Jan 31, 2020 2:02 pm

Re: SPI1-spidev2 troubleshoot

Thu Feb 13, 2020 2:58 pm

Thank you PhilE!
I'm sorry in the previous post I've uploaded the wrong dts file for the hi-3593 chip the right one would be this one:

Code: Select all

/*
 * Device tree overlay for hi3593/arinc on spi1.2
 */
/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
    /* enable spi-dev for spi1.2 */
    [email protected] {
        target = <&spi1>;
        __overlay__ {
            status = "okay";
        };
    };

    [email protected] {
        target = <&spidev2>;
        __overlay__ {
            status = "okay";
        };
    };

    /* the interrupt pin of the hi3593 */
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            arinc_pins: arinc_pins {
                brcm,pins = <13 16>;
                brcm,function = <0>; /* input */
            };
        };
    };

    /* the clock/oscillator of the hi3593 */
    [email protected] {
        target-path = "/clocks";
        __overlay__ {
            /* external oscillator of hi3593 on spi1.2 */
            arinc_osc: arinc_osc {
                compatible = "fixed-clock";
                #clock-cells = <0>;
                clock-frequency  = <16000000>;
            };
        };
    };

    /* the spi config of the can-controller itself binding everything together */
    [email protected] {
        target = <&spi1>;
        __overlay__ {
            /* needed to avoid dtc warning */
            #address-cells = <1>;            #size-cells = <0>;
            arinc: [email protected] {
                reg = <0>;
                compatible = "holt,hi3593";
                pinctrl-names = "default";
                pinctrl-0 = <&arinc_pins>;
                spi-max-frequency = <10000000>;
                interrupt-parent = <&gpio5>;
                interrupts = <13 0>, <16 0>;
                //reset-gpio = <&gpio5 6 GPIO_ACTIVE_HIGH>;
                oscillator = <&arinc_osc>;
            };
        };
    };
    __overrides__ {
        oscillator = <&arinc_osc>,"clock-frequency:0";
        spimaxfrequency = <&arinc>,"spi-max-frequency:0";
        interrupts = <&arinc_pins>,"brcm,pins:0",<&arinc>,"interrupts:0";
    };
};
But I'm still getting this error:

Code: Select all

002849.944: brfs: File read: 1941 bytes
002865.573: brfs: File read: /mfs/sd/overlays/hi3593-arinc-spi1-2.dtbo
002885.642: dterror: can't find symbol 'spidev2'
002885.656: Failed to resolve overlay 'hi3593-arinc-spi1-2'
And about that suggestion:
* Consider adding a parameter to configure the second interrupt.
Could you explain to me how to do so? Because I couldn't find any documentation about enabling more than one interrupt pin through the dts file.

Thank you for your time!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2588
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: SPI1-spidev2 troubleshoot

Thu Feb 13, 2020 3:18 pm

Here's a version of the overlay that has a chance of working (but see notes below):

Code: Select all

/*
 * Device tree overlay for hi3593/arinc on spi1.2
 */
/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
    /* enable spi-dev for spi1.2 */
    [email protected] {
        target = <&spi1>;
        __overlay__ {
            status = "okay";
        };
    };

    /* the interrupt pin of the hi3593 */
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            arinc_pins: arinc_pins {
                brcm,pins = <13 16>;
                brcm,function = <0>; /* input */
            };
        };
    };

    /* the clock/oscillator of the hi3593 */
    [email protected] {
        target-path = "/clocks";
        __overlay__ {
            /* external oscillator of hi3593 on spi1.2 */
            arinc_osc: arinc_osc {
                compatible = "fixed-clock";
                #clock-cells = <0>;
                clock-frequency  = <16000000>;
            };
        };
    };

    /* the spi config of the ARINC 429 serial controller */
    [email protected] {
        target = <&spi1>;                  // The "1" of "spi1.2"
        __overlay__ {
            /* needed to avoid dtc warning */
            #address-cells = <1>;
            #size-cells = <0>;
            arinc: [email protected] {              // Should match the "reg" property
                reg = <2>;                 // The "2" of spi1.2
                compatible = "holt,hi3593";
                pinctrl-names = "default";
                pinctrl-0 = <&arinc_pins>;
                spi-max-frequency = <10000000>;
                interrupt-parent = <&gpio>;
                interrupts = <13 0>, <16 0>;
                //reset-gpio = <&gpio 6 GPIO_ACTIVE_HIGH>;
                oscillator = <&arinc_osc>;
            };
        };
    };
    __overrides__ {
        oscillator = <&arinc_osc>,"clock-frequency:0";
        speed = <&arinc>,"spi-max-frequency:0";
        interrupt1 = <&arinc_pins>,"brcm,pins:0",<&arinc>,"interrupts:0";
        interrupt2 = <&arinc_pins>,"brcm,pins:4",<&arinc>,"interrupts:8";
    };
};
Notes:
1. Compare this overlay with your version and see if you can work out why I've made the changes.
2. I can't find a driver for the HI3493 in the current and upcoming Linux trees. Do you have an out-of-tree driver?

patrickrrocha
Posts: 3
Joined: Fri Jan 31, 2020 2:02 pm

Re: SPI1-spidev2 troubleshoot

Fri Feb 14, 2020 10:13 am

Thank you very much for the dts!
The compiled dtb was successfully loaded.
I'm using this Avionics driver:

https://github.com/ccxtechnologies/driver-avionics

I've compared both dts' in order to understand my mistakes but I still have one doubt regarding this part:

Code: Select all

interrupt2 = <&arinc_pins>,"brcm,pins:4",<&arinc>,"interrupts:8";


Why have you set the brcm pin to 4 and interrupt pin to 8 in the interrupt2?

The problem I'm facing now is the following:
After using the command:

Code: Select all

dmesg | grep -i -E "(mcp | spi)"
I received the following error regarding the probe of spi1.2:

Code: Select all

[    6.012754] hi3593: probe of spi1.2 failed with error -22
[    6.013883] mcp251x spi1.0 can0: MCP2515 successfully initialized.
[    6.040408] mcp251x spi1.1 can1: MCP2515 successfully initialized.
Additionally, would you have any documentation about this kind of error so we can consult it whenever we come across this situation of probe failing?

Thank you for your time.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2588
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: SPI1-spidev2 troubleshoot

Fri Feb 14, 2020 10:30 am

Code: Select all

interrupt2 = <&arinc_pins>,"brcm,pins:4",<&arinc>,"interrupts:8";
This line defines the parameter called "interrupt2". The parameter is configured to patch two integer properties (the ":<n>" part means a 4-byte integer at byte offset <n> from the start of the property) - "brcm,pins" at offset 4 in the node with the "arinc_pins" label, and "interrupts at offset 8 in the "arinc" node. If you search for the token "16" in the overlay (ignoring the "16000000") you'll find the patched locations. The value used to patch those locations is the value assigned to the parameter (e.g. "dtoverlay=hi3593,interrupt2=19" sets them to 19).

You can look up the names for Linux error numbers with:

Code: Select all

$ grep -w 22 /usr/include/*/errno*.h
/usr/include/asm-generic/errno-base.h:#define   EINVAL          22      /* Invalid argument */
"dmesg" might give you some further clues, but searching the driver (probably the probe function) for -EINVAL (or called functions that might have returned -EINVAL) is the way to go.

Return to “Device Tree”