This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM620-Q1: What's involved in adding SPI ports to the config files - dts and dtsi?

Part Number: AM620-Q1
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

What config file changes are required to add SPI ports to the config files for a custom design?  For example, the below mcu SPI port is desired:

// JM 9/30
mcuspi4_pins_default: mcuspi4-default-pins {
pinctrl-single,pins = <
AM62X_MCU_IOPAD(0x0008, PIN_INPUT, 0) /* (B7) MCU_SPI4_CLK */
AM62X_MCU_IOPAD(0x0000, PIN_INPUT, 0) /* (E7) MCU_SPI4_CS0 */
AM62X_MCU_IOPAD(0x000c, PIN_INPUT, 0) /* (E8) MCU_SPI4_D0 */
AM62X_MCU_IOPAD(0x0010, PIN_INPUT, 0) /* (D8) MCU_SPI4_D1 */
>;
};
// end of 9/30

  • Hi Jim,

    there's a ton of E2E posts on this topic so I'd encourage some searching, but to get you started essentially it comes down to:

    1. Pinmux (best generated using the SysConfig tool at https://dev.ti.com/sysconfig/#/start 
    2. SPI device definition as a node added to the SPI peripheral module you want to use (to associated a port with a specific driver)
    3. Make sure the SPI device is enabled (status = "okay")

    A good example are the loopback test device tree fragments (overlays) in the kernel tree, such as this one here: https://git.ti.com/cgit/ti-linux-kernel/ti-linux-kernel/tree/arch/arm64/boot/dts/ti/k3-am625-sk-mcspi-loopback.dtso?h=ti-linux-6.6.y

    Regards, Andreas

  • Andreas,

    I made the attached changes in both kernel (dts/ti) and boot (dts) k3-am625-sk.dts but I don't see a spidev device in /dev.

    Do I need to set up an alias?

    SPI_Settings.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    // JM 9/30
    &mcu_pmx0 {
    mcu_spi0_pins_default: mcu_spi0-default-pins {
    pinctrl-single,pins = <
    AM62X_MCU_IOPAD(0x0008, PIN_INPUT, 0) /* (B7) MCU_SPI0_CLK */
    AM62X_MCU_IOPAD(0x0000, PIN_INPUT, 0) /* (E7) MCU_SPI0_CS0 */
    AM62X_MCU_IOPAD(0x000c, PIN_INPUT, 0) /* (E8) MCU_SPI0_D0 */
    AM62X_MCU_IOPAD(0x0010, PIN_INPUT, 0) /* (D8) MCU_SPI0_D1 */
    >;
    };
    };
    // end of 9/30
    // JM 10/1
    &mcu_spi0 {
    status = "okay";
    #address-cells = <1>;
    #size-cells = <0>;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Here's the boot log:

    U-Boot SPL 2023.04-dirty (Oct 01 20.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    U-Boot SPL 2023.04-dirty (Oct 01 2024 - 07:40:25 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 13408 bytes
    Trying to boot from MMC2
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Starting ATF on ARM64 core...
    NOTICE: BL31: v2.10.0(release):v2.10.0-367-g00f1ec6b87-dirty
    NOTICE: BL31: Built : 16:09:05, Feb 9 2024
    U-Boot SPL 2023.04-dirty (Oct 01 2024 - 07:40:31 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 1856 bytes
    Trying to boot from MMC2
    Authentication passed
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    The SPI interfaces with "SN65LVDS179MDGKREP" (LVDS transceiver).

  • Hi Jim,

    did you rebuild your Kernel? Or are you still using the original SDK image?

    I'm asking because when you rebuild the kernel you usually need to rebuild the kernel modules and install them (`make ARCH=... CROSS_COMPILE+... modules_install INSTALL_MOD_PATH=...`) otherwise the SPIDEV driver won't get loaded. There's no sign of anything 'spi' in your boot log so that could explain things. With the default kernel config the SPIDEV driver gets build as a module ('=m') so if the kernel can't find version-matching modules that won't work.

    Regards, Andreas

  • Andreas,

    It is a custom board so the device tree files have been modified (as well as the DDR) but I'm using the SDK image. (I've rebuilt u-boot and modified the SD card I'm booting from).

    For debugging other issues - other SDK branches, I rebuilt the kernel using "make linux" using the top level make file.  This "branch" is a clean SDK install.   ...no "make linux" command, yet.

  • Andreas,

    Would there be any difference in the way the mcu and main spi are configured?

    Also, I'm assuming there are spi api's we can use in a C program built with gcc to interface with the spi.  Where would I find information on that?

  • Andreas,

    I modified my description in the boot k3-am625-sk.dts file and get the following regarding the spi in the log:

    U-Boot SPL 2023.04-dirty (Oct 04 20.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    U-Boot SPL 2023.04-dirty (Oct 04 2024 - 16:59:39 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 13408 bytes
    Trying to boot from MMC2
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Starting ATF on ARM64 core...
    NOTICE: BL31: v2.10.0(release):v2.10.0-367-g00f1ec6b87-dirty
    NOTICE: BL31: Built : 16:09:05, Feb 9 2024
    U-Boot SPL 2023.04-dirty (Oct 04 2024 - 16:59:45 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 1856 bytes
    Trying to boot from MMC2
    Authentication passed
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    spi_master spi0: cannot find modalias for /bus@f0000/spi@20100000/spidev@0

  • For debugging other issues - other SDK branches, I rebuilt the kernel using "make linux" using the top level make file.  This "branch" is a clean SDK install.   ...no "make linux" command, yet.

    Doing this might just have broken your kernel-modules dependency.

    Can you execute the below command on your running target system to see if the Kernel can find appropriate modules?

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    root@am62xx-evm:~# ls -al /lib/modules/$(uname -r)
    total 1420
    drwxr-xr-x 3 root root 4096 Aug 28 2024 .
    drwxr-xr-x 4 root root 4096 Aug 28 2024 ..
    lrwxrwxrwx 1 root root 24 Aug 28 2024 build -> /home/a0797059/git/linux
    drwxr-xr-x 9 root root 4096 Aug 28 2024 kernel
    -rw-r--r-- 1 root root 326118 Aug 28 2024 modules.alias
    -rw-r--r-- 1 root root 331329 Aug 28 2024 modules.alias.bin
    -rw-r--r-- 1 root root 15804 Aug 28 2024 modules.builtin
    -rw-r--r-- 1 root root 38334 Aug 28 2024 modules.builtin.alias.bin
    -rw-r--r-- 1 root root 19744 Aug 28 2024 modules.builtin.bin
    -rw-r--r-- 1 root root 111699 Aug 28 2024 modules.builtin.modinfo
    -rw-r--r-- 1 root root 57260 Aug 28 2024 modules.dep
    -rw-r--r-- 1 root root 84441 Aug 28 2024 modules.dep.bin
    -rw-r--r-- 1 root root 168 Aug 28 2024 modules.devname
    -rw-r--r-- 1 root root 23998 Aug 28 2024 modules.order
    -rw-r--r-- 1 root root 358 Aug 28 2024 modules.softdep
    -rw-r--r-- 1 root root 186332 Aug 28 2024 modules.symbols
    -rw-r--r-- 1 root root 224279 Aug 28 2024 modules.symbols.bin
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Regards, Andreas

  • Andreas,

    Here's the output:

  • Andreas,

    Here's the latest boot log.  Actually, I changed the spi configuration in both the boot and the kernel k3-am625-sk.dts (correction to above post).

    U-Boot SPL 2023.04-dirty (Oct 08 20_2.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    U-Boot SPL 2023.04-dirty (Oct 08 2024 - 08:01:08 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 13408 bytes
    Trying to boot from MMC2
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Starting ATF on ARM64 core...
    NOTICE: BL31: v2.10.0(release):v2.10.0-367-g00f1ec6b87-dirty
    NOTICE: BL31: Built : 16:09:05, Feb 9 2024
    U-Boot SPL 2023.04-dirty (Oct 08 2024 - 08:01:25 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 1856 bytes
    Trying to boot from MMC2
    Authentication passed
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Andreas,

    The SPI port is connected to a TI LVDS transceiver (SN65LVDS179MDGKREP).

    The current DT description follows:

    &main_spi0 {
    status = "okay";
    #address-cells = <1>;
    #size-cells = <0>;
    pinctrl-0 = <&main_spi0_pins_default>;
    pinctrl-names = "default";
    spidev@0 {
    /*
    * Using spidev compatible is warned loudly,
    * thus use another equivalent compatible id
    * from spidev.
    */
    compatible = "rohm,dh2228fv";
    spi-max-frequency = <24000000>;
    reg = <0>;
    };
    };

    Do I need different entries (for "compatible", for instance)?

  • Andreas,

    Correction->  We're interfacing with a TI microcontroller (SPC5746CHK1AMMH6).  The TI LVDS transceiver is on the mcu_spi0.

    Also, your example pin_mux has everything set up as inputs...  Is this just their initial state and we don't need to concern ourselves with setting them up as they would be at run time?

    I used:

    main_spi0_pins_default: main_spi0-pins-default {
    pinctrl-single,pins = <
    AM62X_IOPAD(0x01bc, PIN_OUTPUT, 0) /* (D12) SPI0_CLK */
    AM62X_IOPAD(0x01c0, PIN_INPUT, 0) /* (C12) SPI0_D0 */
    AM62X_IOPAD(0x01c4, PIN_OUTPUT, 0) /* (A14) SPI0_D1 */
    AM62X_IOPAD(0x01b4, PIN_OUTPUT, 0) /* (C11) SPI0_CS0 */
    >;
    };

  • Hi Jim,

    Do I need different entries (for "compatible", for instance)?

    No for SPIDEV that's what you want.

    AM62X_IOPAD(0x01bc, PIN_OUTPUT, 0) /* (D12) SPI0_CLK */
    AM62X_IOPAD(0x01c0, PIN_INPUT, 0) /* (C12) SPI0_D0 */
    AM62X_IOPAD(0x01c4, PIN_OUTPUT, 0) /* (A14) SPI0_D1 */
    AM62X_IOPAD(0x01b4, PIN_OUTPUT, 0) /* (C11) SPI0_CS0 */

    Please stick to the pinmux ("INPUT") settings from https://git.ti.com/cgit/ti-linux-kernel/ti-linux-kernel/tree/arch/arm64/boot/dts/ti/k3-am625-sk-mcspi-loopback.dtso?h=ti-linux-6.6.y, otherwise it won't work.

    Also confirm the SPIDEV driver is both there and enabled:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    root@am62xx-evm:~# ls -al /lib/modules/$(uname -r)/kernel/drivers/spi
    total 356
    drwxr-xr-x 2 root root 4096 Aug 28 2024 .
    drwxr-xr-x 56 root root 4096 Aug 28 2024 ..
    -rw-r--r-- 1 root root 205552 Aug 28 2024 spi-omap2-mcspi.ko
    -rw-r--r-- 1 root root 146736 Aug 28 2024 spidev.ko
    root@am62xx-evm:~# zcat /proc/config.gz | grep SPIDEV
    CONFIG_SPI_SPIDEV=m
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Regards, Andreas

  • Andreas,

    OK!

    Here's the output to the commands you recommended:

    After I changed the pin mux to INPUT, I can see spidev0.0 in /dev/

    How can I send a byte of data periodically from a C file I build with GCC (I'll do a search while I wait for your reply).

    Also, why can I not use the u-boot utility sspi?  Here's the output:

    Thanks!

  • Andreas,

    Here's the latest log:

    U-Boot SPL 2023.04-dirty (Oct 09 20.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    U-Boot SPL 2023.04-dirty (Oct 09 2024 - 07:15:14 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 13408 bytes
    Trying to boot from MMC2
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Starting ATF on ARM64 core...
    NOTICE: BL31: v2.10.0(release):v2.10.0-367-g00f1ec6b87-dirty
    NOTICE: BL31: Built : 16:09:05, Feb 9 2024
    U-Boot SPL 2023.04-dirty (Oct 09 2024 - 07:15:31 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 1856 bytes
    Trying to boot from MMC2
    Authentication passed
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Andreas,

    I found a spidev_test example c code routine and it seems like it's working.  I have to wait until tomorrow to short MOSI and MISO together for this loopback routine (because our tech group is gone for the day) but this loopback test may be OK for our microprocessor to microcontroller interface for now.  I'll see if I can configure the mcu_spi and test that with other than the loopback connection.

    I'd still like an explanation for the sspi routine not working.  Our customer might want that.

    Thanks for your help so far!

  • Hi Jim,

    I found a spidev_test example c code routine and it seems like it's working.  I have to wait until tomorrow to short MOSI and MISO together for this loopback routine (because our tech group is gone for the day

    Yes that is always a great place to start!

    I'd still like an explanation for the sspi routine not working.  Our customer might want that.

    Without an external loopback in place that looks like as expected. If you have any trouble make sure to connect a logic analyzer, you should be able to see the clock and MOSI signals coming out.

    As for U-Boot's `sspi` utility, I've never used that, it also doesn't seem to be enabled/tested as part of out SDKs. It might be latching onto the wrong SPI bus? You could just use JTAG (or instrument the code with prints) and step through and see what's failing. Most likely a device tree or usage issue I think.

    Regards, Andreas

  • Andreas,

    OK!  After we tacked MOSI/MISO together on SPI0, I got the expected results:

    I do still need the sspi u-boot utility (if possible).  I can start another thread, if needed.  

    Thanks!

  • Andreas,

    If I make the same modifications in the DT files for mcu_spi0, why do I not see another instance of spidev for the mcu_spi0?

    // JM 10/3
    &main_spi0 {
    status = "okay";
    #address-cells = <1>;
    #size-cells = <0>;
    pinctrl-0 = <&main_spi0_pins_default>;
    pinctrl-names = "default";
    spidev@0 {
    /*
    * Using spidev compatible is warned loudly,
    * thus use another equivalent compatible id
    * from spidev.
    */
    compatible = "rohm,dh2228fv";
    spi-max-frequency = <24000000>;
    reg = <0>;
    };
    };
    // end of 10/3

    // JM 10/3
    &mcu_spi0 {
    status = "okay";
    #address-cells = <1>;
    #size-cells = <0>;
    pinctrl-0 = <&mcu_spi0_pins_default>;
    pinctrl-names = "default";
    spidev@1 {
    /*
    * Using spidev compatible is warned loudly,
    * thus use another equivalent compatible id
    * from spidev.
    */
    compatible = "rohm,dh2228fv";
    spi-max-frequency = <24000000>;
    reg = <0>;
    };
    };
    // end of 10/3

  • Andreas,

    I do get errors in the log...

    U-Boot SPL 2023.04-dirty (Oct 10 20.txt
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    U-Boot SPL 2023.04-dirty (Oct 10 2024 - 13:57:21 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 13408 bytes
    Trying to boot from MMC2
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Authentication passed
    Starting ATF on ARM64 core...
    NOTICE: BL31: v2.10.0(release):v2.10.0-367-g00f1ec6b87-dirty
    NOTICE: BL31: Built : 16:09:05, Feb 9 2024
    U-Boot SPL 2023.04-dirty (Oct 10 2024 - 13:57:35 -0400)
    SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.8--v09.02.08 (Kool Koala)')
    SPL initial stack usage: 1856 bytes
    Trying to boot from MMC2
    Authentication passed
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


  • // JM 10/3
    &mcu_spi0 {
    status = "okay";
    #address-cells = <1>;
    #size-cells = <0>;
    pinctrl-0 = <&mcu_spi0_pins_default>;
    pinctrl-names = "default";
    spidev@1 {
    /*
    * Using spidev compatible is warned loudly,
    * thus use another equivalent compatible id
    * from spidev.
    */
    compatible = "rohm,dh2228fv";
    spi-max-frequency = <24000000>;
    reg = <0>;

    Try declaring this as `spidev@0`. Usually the address part of the device tree node name needs to match whatever address the node is using or referring to (in your case "reg = <0>" for CS0).

    Regards, Andreas

  • Andreas,

    OK!  Great!  That seems to have done the trick...

    Thanks!