Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules: hal_nordic: nrfx: use dt_nodelabel_exists #86159

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gmarull
Copy link
Member

@gmarull gmarull commented Feb 21, 2025

As of today, nrfx components are selectable depending if devicetree has
a certain compatible or not, and in case of IP that can operate in
multiple modes, nodelabel+compatible. An example of the later is:

config NRFX_SPI0
    bool "SPI0 driver instance"
    depends on $(dt_nodelabel_has_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPI))
    select NRFX_SPI

config NRFX_SPIM0
    bool "SPIM0 driver instance"
    depends on $(dt_nodelabel_has_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPIM))
    select NRFX_SPIM

config NRFX_SPIS0
    bool "SPIS0 driver instance"
    depends on $(dt_nodelabel_has_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPIS))
    select NRFX_SPIS

These symbols are later selected by e.g. SPI driver if spi0 node is
enabled. While this works in the Zephyr context, it can be a problem in
applications using nrfx directly in the application layer, unless they
tweak devicetree. For example, if devicetree spi0 node defaults to
compatible = "nordic,nrf-spim", NRFX_SPI0 or NRFX_SPIS0 won't be
selectable, but an application using nrfx directly doesn't really care
about what is defined in devicetree as it is effectively bypassing it.
It just wants to select e.g. CONFIG_NRFX_SPI0=y and forget about the
rest.

This patch fixes this problem by just checking for the existence of
certain nodelabels.

Add a new function to check if a nodelabel exists in devicetree.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
As of today, nrfx components are selectable depending if devicetree has
a certain compatible or not, and in case of IP that can operate in
multiple modes, nodelabel+compatible. An example of the later is:

```
config NRFX_SPI0
    bool "SPI0 driver instance"
    depends on $(dt_nodelabel_has_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPI))
    select NRFX_SPI

config NRFX_SPIM0
    bool "SPIM0 driver instance"
    depends on $(dt_nodelabel_has_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPIM))
    select NRFX_SPIM

config NRFX_SPIS0
    bool "SPIS0 driver instance"
    depends on $(dt_nodelabel_has_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPIS))
    select NRFX_SPIS
```

These symbols are later selected by e.g. SPI driver if `spi0` node is
enabled. While this works in the Zephyr context, it can be a problem in
applications using nrfx directly in the application layer, unless they
tweak devicetree. For example, if devicetree `spi0` node defaults to
`compatible = "nordic,nrf-spim"`, NRFX_SPI0 or NRFX_SPIS0 won't be
selectable, but an application using nrfx directly doesn't really care
about what is defined in devicetree as it is effectively bypassing it.
It just wants to select e.g. `CONFIG_NRFX_SPI0=y` and forget about the
rest.

This patch fixes this problem by just checking for the existence of
certain nodelabels.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant