Become a leader in the IoT community!

New DevHeads get a 320-point leaderboard boost when joining the DevHeads IoT Integration Community. In addition to learning and advising, active community leaders are rewarded with community recognition and free tech stuff. Start your Legendary Collaboration now!

Step 1 of 5

CREATE YOUR PROFILE *Required

Change Email
OR
Step 2 of 5

WHAT BRINGS YOU TO DEVHEADS? *Choose 1 or more

Collaboration & Work 🤝
Learn & Grow 📚
Contribute Experience & Expertise 🔧
Step 3 of 5

WHAT'S YOUR INTEREST OR EXPERTISE? *Choose 1 or more

Hardware & Design 💡
Embedded Software 💻
Edge Networking
Step 4 of 5

Personalize your profile

Step 5 of 5

Read & agree to our COMMUNITY RULES

  1. We want this server to be a welcoming space! Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.
  2. If you see something against the rules or something that makes you feel unsafe, let staff know by messaging @admin in the "support-tickets" tab in the Live DevChat menu.
  3. No age-restricted, obscene or NSFW content. This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.
  4. No spam. This includes DMing fellow members.
  5. You must be over the age of 18 years old to participate in our community.
  6. Our community uses Answer Overflow to index content on the web. By posting in this channel your messages will be indexed on the worldwide web to help others find answers.
  7. You agree to our Terms of Service (https://www.devheads.io/terms-of-service/) and Privacy Policy (https://www.devheads.io/privacy-policy)
By clicking "Finish", you have read and agreed to the our Terms of Service and Privacy Policy.

How to Configure DTS and Struct for SPI Controller Driver with Child Nodes in Zephyr?

Hello Guys,
I am developing a SPI Controller Driver for TI processors for Zephyr,
I have a doubt on how do i set the Dts to look like?

ideally it should like this if we include soc.dtsi, board.dts, overlay.dts

`&spi1 {
compatible = “ti,omap-spi”;
reg = <0x48030000 0x1000>;
interrupts = <25>;
#address-cells = <1>;
#size-cells = <0>;

spi1_device0: spi-device@0 {
reg = <0>;
spi-max-frequency = <1000000>;
spi-cs-delay = <5>;
word_length = <8>
};

spi1_device1: spi-device@1 {
reg = <1>;
spi-max-frequency = <2000000>;
spi-cs-delay = <10>;
word_length = <32>
};
};`

As of now, I am getting the SPI controller to have 4 CS, no DMA, no slave mode

how do i set my struct config to accomodate the above?

it would be simple if there was no child nodes
like the below
`struct spi_omap_config {
DEVICE_MMIO_NAMED_ROM(base);
uint32_t irq;
};`

but with child nodes in the equation, i am so confused…

  1. ZacckOsiemo#0000

    will have some time later Ill try and reproduce this.

  2. ZacckOsiemo#0000

    Ok now on this, wait so you have a driver and that is fine, what you want is to be able to control 4 devices off of your driver and no DMA and while being master right?

  3. ZacckOsiemo#0000

    @melta101 if the above is correct you need to define your CS lines in the overlay as GPIOS

  4. ZacckOsiemo#0000

    and if you have enabled DMA in your controller driver you need to override the dma feature in your overlay

  5. ZacckOsiemo#0000

    Let me know If I am looking at this too simply

  6. 32bitSaviour#0000

    What if you define a struct for a child node. Then in your config you have an array of the children like so `const struct spi_children_dev childs[4];`. This way you could parse the device tree and initialize each child node. What if.

  7. melta101#0000

    sorry for the delay..

  8. melta101#0000

    Yep,
    That’s the plan
    but in this case, we dont need to use GPIO to activate it,
    there are register to do those stuffs

  9. melta101#0000

    makes sense
    i was thinking something similar
    but how do i define the API init macros?

  10. melta101#0000

    lets take the above example

    reg -> array
    interupt -> array

    but as what type, do we define those child nodes?

    i was thinking of passing it as array itself
    but those would mean
    instead of
    ` spi1_device0: spi-device@0 {
    reg = <0>;
    spi-max-frequency = <1000000>;
    spi-cs-delay = <5>;
    word_length = <8>
    };`
    it would be become
    `spi1_device0:spi-device@0 = <0 100000 5 8>`

  11. 32bitSaviour#0000

    What about just capturing that data.
    `struct spi_omap_device {
    uint32_t reg;
    uint32_t spi_max_freq;
    uint32_t spi_cs_delay;
    uint32_t word_length;
    };`

    The creating an init macro that we call using `DT_INST_FOREACH_CHILD`

  12. 32bitSaviour#0000

    Something like “`#define MELTA_SPI_DEVICE_INIT(inst, child) \
    { \
    .reg = DT_PROP(child, reg), \
    .spi_max_freq = DT_PROP(child, spi_max_frequency), \
    .spi_cs_delay = DT_PROP(child, spi_cs_delay), \
    .word_length = DT_PROP(child, word_length), \
    }, “`

  13. melta101#0000

    Will try the above once i reach back
    Thanks

  14. ZacckOsiemo#0000

    ah I see

  15. melta101#0000

    the define macros should look like this

    #define SPI_OMAP_DEVICE_INIT(inst) \
    static const struct spi_cs_omap_config spi_cs_omap_config_##inst[] = SPI_SENSOR_CONFIG_ARRAY(inst); \
    static struct spi_omap_config spi_omap_config_##inst = { \
    DEVICE_MMIO_NAMED_ROM_INIT(DT_INST_REG_ADDR(inst)), \
    .irq = DT_INST_IRQN(inst), \
    .cs_config = spi_cs_omap_config_##inst, \
    };

    if i am not wrong

  16. melta101#0000

    that way
    We can write the dts like below

    **soc.dtsi**

    `/soc {
    spi0: spi@48030000 {
    compatible = “ti,omap-spi”;
    reg = <0x48030000 0x1000>;
    interrupts = <41>;
    spi-max-frequency = <48000000>;
    status = “disabled”;
    };
    };
    `

    **board.dts**

    ` &spi0 {
    status = “okay”;
    };
    };`

    **sensor.overlay**

    `&spi0 {
    sensor@0 {
    compatible = “generic,sensor”;
    reg = <0>;
    frequency = <12000000>;
    ti,cs-delay = <10>;
    label = “SENSOR_0”;
    };

    sensor@1 {
    compatible = “generic,sensor”;
    reg = <1>;
    frequency = <24000000>;
    ti,cs-delay = <20>;
    label = “SENSOR_1”;
    };
    };`

    i suppose the above is acceptable for zephyr style of application programming

  17. 32bitSaviour#0000

    yes this looks good to me.

  18. ZacckOsiemo#0000

    ultimate PR review right there mate

CONTRIBUTE TO THIS THREAD

Browse other questions tagged 

Leaderboard

RANKED BY XP

All time
  • 1.
    Avatar
    @Nayel115
    1620 XP
  • 2.
    Avatar
    @UcGee
    650 XP
  • 3.
    Avatar
    @melta101
    600 XP
  • 4.
    Avatar
    @lifegochi
    250 XP
  • 5.
    Avatar
    @Youuce
    180 XP
  • 6.
    Avatar
    @hemalchevli
    170 XP