nrf52840 with NOR memory

https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/drivers/spi_flash/src/main.c#L36

may I know where I can find the pin connections used in this example 

"const struct device *flash_dev = DEVICE_DT_GET_ONE(SPI_FLASH_COMPAT);" 

#if DT_HAS_COMPAT_STATUS_OKAY(jedec_spi_nor)
#define SPI_FLASH_COMPAT jedec_spi_nor

I checked jedec yaml file but no pins is defined there as well 

Parents
  • Hi,

    The pin connections are typically defined in the board's device tree file (.dts) . It is where you would specify the hardware specifics like pin connections. You would need to check the device tree file for your specific board to see how the pins are defined for your SPI device.

    -Priyanka

  • For this specific sample, spi-flash , i am using nrf52840 , may i ask where i can find the .dts file? I only find the .dtsi file.  And within this nrf52840.dtsi, also no specific pin is given or set. 

    spi2: spi@40023000 {
    /*
    * This spi node can be SPI, SPIM, or SPIS,
    * for the user to pick:
    * compatible = "nordic,nrf-spi" or
    * "nordic,nrf-spim" or
    * "nordic,nrf-spis".
    */
    compatible = "nordic,nrf-spim";
    #address-cells = <1>;
    #size-cells = <0>;
    reg = <0x40023000 0x1000>;
    interrupts = <35 NRF_DEFAULT_IRQ_PRIORITY>;
    max-frequency = <DT_FREQ_M(8)>;
    easydma-maxcnt-bits = <16>;
    status = "disabled";
    };

  • Hi,

    You can check the dts file here:

    But in case you need to make any modifications to the dts file, you need to create an overlay file in your project folder.

    -Priyanka

  • can i change the line 

    "const struct device *flash_dev = DEVICE_DT_GET_ONE(SPI_FLASH_COMPAT);" 

    to 

    const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(spi1));

    then i redefine the spi pins in overlay file to something similar to this ? 

    &spi1 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi1_default>;
        pinctrl-1 = <&spi1_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 30 GPIO_ACTIVE_LOW>;
        bme280: bme280@0 {
            compatible = "bosch,bme280";
            reg = <0>;
            spi-max-frequency = <125000>;
        };
    };
  • #define SPIOP SPI_WORD_SET(8) | SPI_TRANSFER_MSB

    struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(w25m02g), SPIOP, 0);

    const struct device *spi_dev = DEVICE_DT_GET(DT_NODELABEL(spi1));

    &spi1 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi1_default>;
        pinctrl-1 = <&spi1_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
    
        w25m02g: w25m02g@0 {
            compatible = "winbond,w25m02g";
            reg = <0>;
            spi-max-frequency = <80000000>;
            size = <2147483648>;
            wp-gpios = <&gpio0 21 GPIO_ACTIVE_LOW>;
            hold-gpios = <&gpio0 23 GPIO_ACTIVE_LOW>;
        };
    };

    May I ask if the SPI_DT_SPEC_GET and DEVICE_DT_GET can change with each other? Are they serving the same purpose? 

    Can both work with spi_transceive?  how about flash_write? 

  • No. They both have different purposes. It's true that both are used to get the device information from the dts.

    SPI_DT_SPEC_GET is used to get information regarding SPI from the dts. This macro is used when you need to perform operations like spi_transcieve_dt, spi_read_dt, etc. It returns a spi_dt_spec struct which includes the SPI device instance and it's configuration.

    DEVICE_DT_GET is used to get a pointer to the device structure for a given device from the dts. And this macro is used when you need to perform operations like flash_write or flash_read. 

    Hope these clarify your doubts. I would suggest you to create a new ticket for further queries if the initial topic for the ticket is solved, as this will help keep devzone clean and help future seekers when they search for specific topics.

    -Priyanka

Reply
  • No. They both have different purposes. It's true that both are used to get the device information from the dts.

    SPI_DT_SPEC_GET is used to get information regarding SPI from the dts. This macro is used when you need to perform operations like spi_transcieve_dt, spi_read_dt, etc. It returns a spi_dt_spec struct which includes the SPI device instance and it's configuration.

    DEVICE_DT_GET is used to get a pointer to the device structure for a given device from the dts. And this macro is used when you need to perform operations like flash_write or flash_read. 

    Hope these clarify your doubts. I would suggest you to create a new ticket for further queries if the initial topic for the ticket is solved, as this will help keep devzone clean and help future seekers when they search for specific topics.

    -Priyanka

Children
No Data
Related