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

devicetree Arduino bindings do not support identification of bus controllers #20330

Closed
pabigot opened this issue Nov 5, 2019 · 4 comments
Closed
Assignees
Labels
area: Devicetree bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@pabigot
Copy link
Collaborator

pabigot commented Nov 5, 2019

(split off from #20325)

The commit 442df97 (scripts/dts: Remove alias defines for labels) breaks the existing use of a node label to identify Arduino bus resources. The commit was incorrect in stating that the generated label was never used. There is one in-tree use, in samples/drivers/i2c_scanner.

If it is desirable to identify Arduino bus resources, then either a fix like the following must be applied to all Arduino binding overlays, or some new mechanism that generates macros based on node labels (not label property) must be added to the scripting.

diff --git a/boards/arm/nucleo_l476rg/arduino_r3_connector.dtsi b/boards/arm/nucleo_l476rg/arduino_r3_connector.dtsi
index 1f47915822..c6a37a6ffd 100644
--- a/boards/arm/nucleo_l476rg/arduino_r3_connector.dtsi
+++ b/boards/arm/nucleo_l476rg/arduino_r3_connector.dtsi
@@ -5,6 +5,9 @@
  */
 
 / {
+       aliases {
+               arduino-i2c = &i2c1;
+       };
        arduino_header: connector {
                compatible = "arduino-header-r3";
                #gpio-cells = <2>;
@@ -34,5 +37,3 @@
                           <21 0 &gpiob 8 0>;   /* D15 */
        };
 };
-
-arduino_i2c: &i2c1 {};
diff --git a/samples/drivers/i2c_scanner/src/main.c b/samples/drivers/i2c_scanner/src/main.c
index 44c1724377..ac71a0d85f 100644
--- a/samples/drivers/i2c_scanner/src/main.c
+++ b/samples/drivers/i2c_scanner/src/main.c
@@ -10,8 +10,8 @@
 #include <device.h>
 #include <drivers/i2c.h>
 
-#ifdef ARDUINO_I2C_LABEL
-#define I2C_DEV ARDUINO_I2C_LABEL
+#ifdef DT_ALIAS_ARDUINO_I2C_LABEL
+#define I2C_DEV DT_ALIAS_ARDUINO_I2C_LABEL
 #else
 #define I2C_DEV "I2C_0"
 #endif
@pabigot pabigot added the bug The issue is a bug, or the PR is fixing a bug label Nov 5, 2019
@pabigot pabigot added the priority: low Low impact/importance bug label Nov 5, 2019
@ulfalizer
Copy link
Collaborator

ulfalizer commented Nov 5, 2019

How do I reproduce this failure? The sample builds when I do

$ cmake -GNinja -DBOARD=arduino_due ..
$ ninja

Is it just a runtime failure?

@ulfalizer
Copy link
Collaborator

Ah... never mind. Didn't notice the last part of the diff.

@galak
Copy link
Collaborator

galak commented Feb 19, 2020

I think this will be resolved by the NODELABEL support from issue #22555 and PR #22612

@pabigot
Copy link
Collaborator Author

pabigot commented Apr 6, 2020

This now works:

diff --git a/samples/drivers/i2c_scanner/src/main.c b/samples/drivers/i2c_scanner/src/main.c
index 9e4d3cc86b..7fd0e47c79 100644
--- a/samples/drivers/i2c_scanner/src/main.c
+++ b/samples/drivers/i2c_scanner/src/main.c
@@ -10,8 +10,8 @@
 #include <device.h>
 #include <drivers/i2c.h>
 
-#ifdef ARDUINO_I2C_LABEL
-#define I2C_DEV ARDUINO_I2C_LABEL
+#if DT_HAS_NODE(DT_NODELABEL(arduino_i2c))
+#define I2C_DEV DT_LABEL(DT_NODELABEL(arduino_i2c))
 #else
 #define I2C_DEV "I2C_0"
 #endif

@pabigot pabigot closed this as completed Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

3 participants