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.

Linux/PROCESSOR-SDK-AM335X: Cannot use mcp23s17 kernel driver with Beaglebone black

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Linux

Goodmorning,

I'm using a Beaglebone and I'm trying to use a mcp23s17 device connected to spi0 with cs0 pin as its chip select, the address of the peripheral is 0b01000000.

I've followed the link but it doesn't work.

If I try the command dmesg | grep spi, I get "mcp23s08 spi0.0: missing spi-present-mask".

If, instead of the kernel driver, I use it as a generic spi device, where I write and read directly on/from it, it works.

In attachment you can find both the .config file and my dts file.

What am I missing?

Thank you.4338.myConfig.txt

  • 8765.custom_board.txt
    /*
     * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License version 2 as
     * published by the Free Software Foundation.
     */
    /dts-v1/;
    
    #include "am33xx.dtsi"
    #include "am335x-bone-common.dtsi"
    
    &ldo3_reg {
        regulator-min-microvolt = <1800000>;
        regulator-max-microvolt = <1800000>;
        regulator-always-on;
    };
    
    &sgx {
        status = "okay";
    };
    
    / {
    	model = "TI AM335x BeagleBone Black";
    	compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
    };
    
    &cpu0_opp_table {
    	/*
    	 * All PG 2.0 silicon may not support 1GHz but some of the early
    	 * BeagleBone Blacks have PG 2.0 silicon which is guaranteed
    	 * to support 1GHz OPP so enable it for PG 2.0 on this board.
    	 */
    	oppnitro-1000000000 {
    		opp-supported-hw = <0x06 0x0100>;
    	};
    };
    
    &tscadc {
            adc {
                    ti,adc-channels = <4 5 6 7>;
    		status = "okay";
            };
    };
    
    &mmc1 {
        vmmc-supply = <&vmmcsd_fixed>;
    };
    
    &rtc {
    	system-power-controller;
    };
    
    
    /* Common pinmux */
    &am33xx_pinmux {
    
        ecap0_pins: pwm_pins {
    		pinctrl-single,pins = <
    			0x164 0x0	/* eCAP0_in_PWM0_out.eCAP0_in_PWM0_out MODE0 */
    		>;
    	};
        
        spi0_pins: pinmux_spi0_pins {
                pinctrl-single,pins = <
                    0x150 (PIN_INPUT_PULLUP | MUX_MODE0)   /* spi0_sclk.spi0_sclk, OUTPUT_PULLUP | MODE0 */
                    0x154 (PIN_INPUT_PULLUP | MUX_MODE0)   /* spi0_d0.spi0_d0, INPUT_PULLUP | MODE0 0x30 */
                    0x158 (PIN_INPUT_PULLUP | MUX_MODE0)  /* spi0_d1.spi0_d1, OUTPUT_PULLUP | MODE0 */
                    0x15c (PIN_INPUT_PULLUP | MUX_MODE0)   /* spi0_cs0.spi0_cs0, OUTPUT_PULLUP | MODE0 0x10 */
                >;
            };
    };
    
    /* PWM */
    &epwmss0 {
            status = "okay";
    
            ecap0: ecap@48300100 {
                    status = "okay";
                    pinctrl-names = "default";
                    pinctrl-0 = <&ecap0_pins>;
            };
    };
    
    // mcp23s17
    &spi0 {
            status = "okay";
            pinctrl-names = "default";
            pinctrl-0 = <&spi0_pins>;
    	ti,pindir-d0-out-d1-in = <1>;
            gpiom0:gpiom0@0{
                compatible = "mcp,mcp23s17";
                gpio-controller;
                #gpio-cells = <2>;
                microchip,spi-present-mask = <0X01>;// Periferiche connesse considerando A1,A2,A3 
                reg = <0>;                          // specify the chip select line MCP23017
                spi-max-frequency = <1000000>;
            };
    };
    
    /* Generic device
    &spi0{
    	pinctrl-names = "default";
    	pinctrl-0 = <&spi0_pins>;
    	status = "okay";
    	ti,pindir-d0-out-d1-in = <1>;
    
    	spidev@0{
    		pinctrl-0 = <&spi0_pins>;		
    		compatible = "linux,spidev";
    		reg = <0>;
    		spi-max-frequency = <10000000>;
    	};
    };*/
    

  • Hi Davide,

    Do you use AM335x BeagleBone Black board or custom board that is based on BeagleBone Black?

    Do you use AM335x TI PSDK Linux? If yes, which version?

    Regards,
    Pavel
  • Hello Pavel,
    thank you for your answer. My board is an original Beaglebone balck rev.3.
    Regarding the PSDK version, it is ti-processor-sdk-linux-am335x-evm-05.01.00.11
    Thank you again.

    Regards,
    Davide Brunelli
  • Davide,

    I see you are making all the AM335x McSPI0 pins as inputs. Note that McSPI Linux driver supports only master mode. And you have "ti,pindir-d0-out-d1-in = <1>;" entry which means that D0 pin is output and D1 as input.

    Also I see you are using "mcp,mcp23s17", and this is deprecated, should be used "microchip,mcp23s17" instead. And you can also try to replace "microchip,spi-present-mask" with "spi-present-mask". Refer to the below doc files:



    linux-4.14.67/Documentation/devicetree/bindings/gpio/gpio-mcp23s08.txt
    linux-4.14.67/Documentation/devicetree/bindings/spi/omap-spi.txt


    Regards,
    Pavel
  • Hello Pavel,

    thank you for your message. For being more clear, let's consider the two cases: 1) mcp23s17 controlled by my own library and 2) mcp23s17 controlled by kernel driver.

    1. mcp23s17 controlled by my own library

      Before writing to the forum, regarding the pins direction, I've made several tests.
      In particular if the PINS are set as follow :

                       0x150 0x10 /* spi0_sclk, OUTPUT_PULLUP | MODE0 */

                       0x154 0x10 /* spi0_d0, OUTPUT_PULLUP | MODE0 */

                       0x158 0x30 /* spi0_d1, INPUT_PULLUP | MODE0 */

                       0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */

      as they should be in an SPI master or even:

               0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */  

               0x154 0x30 /* spi0_d0, INPUT_PULLUP | MODE0 */  

               0x158 0x10 /* spi0_d1, OUTPUT_PULLUP | MODE0 */  

               0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */

      as described in the following links:

      -

      I can write correctly but I cannot read from the peripheral. The only solution that worked both for writing and reading correctly, was to set all the pins as INPUT_PULL_UP. Besides it was important to set SPI in mode 0 "Low at idle, capture on rising clock edge".

    2. mcp23s17 controlled by kernel driver

      I've tried the modifications that you indicated me, as you can see in the modified device tree in attachment
      custom_board2.txt
      /*
       * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
       *
       * This program is free software; you can redistribute it and/or modify
       * it under the terms of the GNU General Public License version 2 as
       * published by the Free Software Foundation.
       */
      /dts-v1/;
      
      #include "am33xx.dtsi"
      #include "am335x-bone-common.dtsi"
      
      &ldo3_reg {
          regulator-min-microvolt = <1800000>;
          regulator-max-microvolt = <1800000>;
          regulator-always-on;
      };
      
      &sgx {
          status = "okay";
      };
      
      / {
      	model = "TI AM335x BeagleBone Black";
      	compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
      };
      
      &cpu0_opp_table {
      	/*
      	 * All PG 2.0 silicon may not support 1GHz but some of the early
      	 * BeagleBone Blacks have PG 2.0 silicon which is guaranteed
      	 * to support 1GHz OPP so enable it for PG 2.0 on this board.
      	 */
      	oppnitro-1000000000 {
      		opp-supported-hw = <0x06 0x0100>;
      	};
      };
      
      &tscadc {
              adc {
                      ti,adc-channels = <4 5 6 7>;
      		status = "okay";
              };
      };
      
      &mmc1 {
          vmmc-supply = <&vmmcsd_fixed>;
      };
      
      &rtc {
      	system-power-controller;
      };
      
      
      /* Common pinmux */
      &am33xx_pinmux {
      
          ecap0_pins: pwm_pins {
      		pinctrl-single,pins = <
      			0x164 0x0	/* eCAP0_in_PWM0_out.eCAP0_in_PWM0_out MODE0 */
      		>;
      	};
          
          spi0_pins: pinmux_spi0_pins {
                  pinctrl-single,pins = <
                      0x150 (PIN_OUTPUT_PULLUP | MUX_MODE0)   /* spi0_sclk.spi0_sclk, OUTPUT_PULLUP | MODE0 */
                      0x154 (PIN_OUTPUT_PULLUP | MUX_MODE0)   /* spi0_d0.spi0_d0, INPUT_PULLUP | MODE0 0x30 */
                      0x158 (PIN_INPUT_PULLUP | MUX_MODE0)  /* spi0_d1.spi0_d1, OUTPUT_PULLUP | MODE0 */
                      0x15c (PIN_OUTPUT_PULLUP | MUX_MODE0)   /* spi0_cs0.spi0_cs0, OUTPUT_PULLUP | MODE0 0x10 */
                  >;
              };
      };
      
      /* PWM */
      &epwmss0 {
              status = "okay";
      
              ecap0: ecap@48300100 {
                      status = "okay";
                      pinctrl-names = "default";
                      pinctrl-0 = <&ecap0_pins>;
              };
      };
      
      // mcp23s17
      &spi0 {
              status = "okay";
              pinctrl-names = "default";
              pinctrl-0 = <&spi0_pins>;
      	ti,pindir-d0-out-d1-in = <1>;
              gpiom0:gpiom0@0{
                  compatible = "microchip,mcp23s17";
                  spi-cpha=<0>;
                  spi-cpol=<0>;
                  gpio-controller;
                  #gpio-cells = <2>;
                  spi-present-mask = <0X01>;		// Periferiche connesse considerando A1,A2,A3 
                  reg = <0>;                          // specify the chip select line MCP23017
                  spi-max-frequency = <1000000>;
              };
      };
      
      // Generic device
      /*&spi0{
      	pinctrl-names = "default";
      	pinctrl-0 = <&spi0_pins>;
      	status = "okay";
      	ti,pindir-d0-out-d1-in = <1>;
      
      	spidev@0{
      		pinctrl-0 = <&spi0_pins>;		
      		compatible = "linux,spidev";
      		reg = <0>;
      		spi-max-frequency = <10000000>;
      	};
      };*/
      
      , but unfortunately the result is the same. I've also tried to se the SPI MODE with spi-cpha=<0>; spi-cpol=<0>; but unsuccesfully.

    Have you got the possibility to try it ?

    Thank you.

  • Davide,

    I do not have BBB board with McSPI cape, thus I can not test this on my side.

    So you have 3 (or 2 ?) cases:

    1. mcp23s17 controlled by my own library - here you are not using Linux kernel? And here you set all the pins as input to work correct. But note that when set a pin to input, this pin is actually in/out, it is not input only. And we have a requirement to set the clock as input (I/O), even when we use it as output, check AM335x TRM sections below. You can make McSPI register dump in this working case and compare the result with the non-working case.

    9.3.1.50 conf_<module>_<pin> Register (offset = 800h–A34h)
    24.2.3 McSPI Pin List

    2. mcp23s17 controlled by kernel driver - controlled by "microchip,mcp23s17" driver? Here in this case, you need to set clock as input. Please provide me the updated DTS file and kernel boot up log in this case.

    3. mcp23s17 controlled by kernel driver - controlled by "linux,spidev"? Is this working fine case?

    Regards,
    Pavel
  • Check also below e2e thread regarding McSPI slave driver:

    e2e.ti.com/.../750532

    Regards,
    Pavel
  • Hello Pavel,
    I made it work!
    For reference I've change spi pins direction as:

    spi0_pins: pinmux_spi0_pins {
    pinctrl-single,pins = <
    0x150 (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_sclk.spi0_sclk, $
    0x154 (PIN_OUTPUT_PULLUP | MUX_MODE0) /* spi0_d0.spi0_d0, INP$
    0x158 (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_d1.spi0_d1, OUTPU$
    0x15c (PIN_OUTPUT_PULLUP | MUX_MODE0) /* spi0_cs0.spi0_cs0, O$
    >;
    };

    Besides, reading the driver code I saw that it requires microchip,spi-present-mask, not just spi-present-mask. So the final result is:

    &spi0 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins>;
    ti,pindir-d0-out-d1-in = <1>;
    gpiom@0{
    pinctrl-0 = <&spi0_pins>;
    microchip,spi-present-mask = <0X01>;
    compatible = "microchip,mcp23s17";
    gpio-controller;
    #gpio-cells = <2>;
    reg = <0>;
    spi-max-frequency = <1000000>;
    };
    };

    Thank very much you for your support.

    Best Regards,
    Davide