Skip to main content
Visitor II
December 3, 2021
Solved

Hello, i'd like to use u-boot command sspi to send commands to a spi device with a custom protocol (not a memory). However I see that the command tries to read an ID as it is talking to a flash nor : unrecognized JEDEC id bytes: 00, 00, 00.

  • December 3, 2021
  • 6 replies
  • 6453 views

Looking at the code, i see file sf_probe.c with .id      = UCLASS_SPI_FLASH, that performs the id reading. How can i use stm32_spi.c with .id         = UCLASS_SPI, driver instead? and send "raw" spi data?

    This topic has been closed for replies.
    Best answer by Lmoio.1

    Hello,

    I added an alias for the spi and the command started working.

    	aliases {
    		serial0 = &uart4;
    		serial1 = &usart3;
    		spi1 = &spi1;	
    	};

    thank you

    6 replies

    Technical Moderator
    December 6, 2021

    Hi @Lmoio.1​ ,

    Can you share your Device Tree and particularly the spi node ?

    Thx

    Olivier

    Lmoio.1Author
    Visitor II
    December 9, 2021

    Hi @Community member​ 

    I worked some more on this issue and I noticed that inside spi-uclass.c file, the function ret = uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus);

    put in bus a udevice parent with name spi@58003000 that is the QSPI base address, is this a possible issue? How can I force to use spi@44004000 that is SPI1?

    Thanks

    Lmoio.1Author
    Visitor II
    December 6, 2021

    Hi @Community member​,

    My spi node definition in the device tree is the following:

    &spi1 {
    	pinctrl-names = "default", "sleep";
    	pinctrl-0 = <&spi1_pins_a>;
    	pinctrl-1 = <&spi1_sleep_pins_a>;
    	status = "okay";
    	cs-gpios = <&gpioe 12 0>;
    	spidev@0 {
     compatible = "stm32_spi";
     reg = <0>; /* CS #0 */
     spi-max-frequency = <10000000>;
     };
    };

    I inlcude arch/arm/dts/stm32mp151.dtsi file so

    spi1: spi@44004000 {
    			#address-cells = <1>;
    			#size-cells = <0>;
    			compatible = "st,stm32h7-spi";
    			reg = <0x44004000 0x400>;
    			interrupts = <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
    			clocks = <&rcc SPI1_K>;
    			resets = <&rcc SPI1_R>;
    			dmas = <&dmamux1 37 0x400 0x01>,
    			 <&dmamux1 38 0x400 0x01>;
    			dma-names = "rx", "tx";
    			power-domains = <&pd_core>;
    			status = "disabled";
    		};

    I modified spi command  to use the stm32 driver (but i'm not sure) instead of the spi_generic_drv driver:

    	ret = spi_get_bus_and_cs(bus, cs, freq, mode, "stm32_spi",
    				 str, &dev, &slave);

    I added some print in the driver files, and when doing sspi 0:0.0 8 a, i see that it performs sf_probe.c probing function (spi_flash_std_probe and spi_flash_probe_slave) and gives:

    unrecognized JEDEC id bytes: 00, 00, 00.

    I also tried disabling the spi flash driver, modifiying the defconfig with

    CONFIG_ENV_IS_IN_SPI_FLASH=n
    CONFIG_DM_SPI_FLASH=n

    Now i see

    spi_get_bus_and_cs: Binding new device 'generic_0:2', busnum=0, cs=2, driver=stm32_spi 

    But then it fails at line

    priv->base = dev_remap_addr(dev);

    in the stm32_spi.c file.

    Technical Moderator
    December 9, 2021

    Hi @Lmoio.1​ ,

    Sorry for late reply.

    Looking at your DT this is the comment I can do :

    The node spidev@0 supposed to refer to the device connected on SPI.

    The compatible = "stm32_spi"; supposed to refer to this device driver ... provider or in-house code.

    In this case it refer to anything and anyway not to the stm32_spi driver.

    compatible = "st,stm32h7-spi"; is the only and correct binding to call stm32_spi driver.

    To be use SPI1 as raw I even wonder if you need to define a device node.

    Did you try to remove it ?

    Hope it help,

    Olivier

    Lmoio.1Author
    Visitor II
    December 10, 2021

    Hi @Community member​ 

    I tried command dm tree and noticed the following:

    spi          0 [  ]  stm32_spi            |  |-- spi@44004000

    spi          1 [ + ]  stm32_qspi           |  |-- spi@58003000

    so I figured out that qspi was actually enabled. I disabled it in the device tree and now I don't see its entry anymore. However there is no "+" on the spi entry.

    Why does the spy not get probed?

    I removed the node as you mentioned,

    &spi1 {

       pinctrl-names = "default", "sleep";

       pinctrl-0 = <&spi1_pins_a>;

       pinctrl-1 = <&spi1_sleep_pins_a>;

       status = "okay";

       cs-gpios = <&gpioe 12 0>;

    };

    now when i try sspi, i get

    Invalid bus 0 (err=-19)

    Are you able to use it somehow? Do you have a better idea if I need to send data to another stm32 mcu via spi during boot?

    Thanks

    Lidia

    Lmoio.1AuthorAnswer
    Visitor II
    December 14, 2021

    Hello,

    I added an alias for the spi and the command started working.

    	aliases {
    		serial0 = &uart4;
    		serial1 = &usart3;
    		spi1 = &spi1;	
    	};

    thank you

    Technical Moderator
    December 14, 2021

    Hi @Lmoio.1​ ,

    Well spotted !

    For reference for others could you please confirm the working spi DT node for this usage ?

    Thanks,

    Olivier

    Lmoio.1Author
    Visitor II
    December 14, 2021

    Hi,

    This is the device tree configuration i used

    &spi1 {
    	u-boot,dm-spl;
    	pinctrl-names = "default", "sleep";
    	pinctrl-0 = <&spi1_pins_a>;
    	pinctrl-1 = <&spi1_sleep_pins_a>;
    	status = "okay";
    	cs-gpios = <&gpioz 3 0>;
    };

    and i also reverted all modifications i did in the spi.c uboot command.

    To summarize:

    • CONFIG_CMD_SPI=y in the defconfig
    • qspi disabled in the device tree
    • spi enabled and with alias in the device tree
    • using the right bus "sspi 1:0.0 32 a"