Re: Enabling i2c on nucleo_f429zi
Jason Bens <jason.bens@...>
Hi David. I'm also not an expert, but I'll try to help you if I can. More experienced users can feel free to correct me on this.toggle quoted messageShow quoted text
First off, regarding "And accordingly its the devicetree contains an i2c1 node but not in the root node and I'm still figuring out what does that mean". Surprisingly, the i2c1 node actually is in the root node. It's a long and convoluted path, but at the top of the nucleo_f429zi.dts file, another soc-specific dts fragment is included, <st/f4/stm32f429Xi.dtsi>. This is relative to zephyr/dts/arm/. This device tree fragment includes another device tree fragment, which includes another ... and another ... and another.. and so on, until you finally get to stm32f4.dtsi, which is basically the starting point of the stm32f4 soc family. It's here that you'll find the root node, inside of which is the soc node, which contains your i2c1 node, as well as the rest of your peripherals. DTS files are c-like. So, the ampersand in front of i2c1 in the nucleo dts file means you're working on a reference to the node, and not the node itself, which is defined elsewhere.
Next, you're probably hitting the #error "Please set the correct I2C device" line because the precompile conditionals are using the DT_ALIAS macro. Per https://docs.zephyrproject.org/latest/reference/devicetree/api.html?highlight=dt_alias#c.DT_ALIAS, DT_ALIAS looks for a node identifier in the /aliases node. Unfortunately, the nucleof429 dts file doesn't have an alias called i2c_0 or i2c_1. You'll have to add it yourself. My untested attempt:
led0 = &green_led_1;
led1 = &blue_led_1;
led2 = &red_led_1;
sw0 = &user_button;
i2c_1 = &i2c1;
It would also be possible to use DT_NODELABEL(i2c1) to get the node identifier using the node label, rather than the alias. Note the difference here between the node i2c1 and the alias i2c_1.
Hopefully that can help get you started.
From: users@... <users@...> On Behalf Of David Demelier
Sent: April 6, 2022 9:17 AM
Subject: [Zephyr-users] Enabling i2c on nucleo_f429zi
Quite new to zephyr and still reading its documentation actively. I've been able to successfully generate, debug and use GPIO based applications (following the very well documented blinky and other examples).
Now I'd like to use an i2c device (temperature sensors) that I was able to successfully use under a standard Linux distribution for testing.
I'm still having lots of confusion regarding the devicetree APIs and general use of it.
First of all, I've enabled i2c by adding this to my prj.conf:
Then I've followed an example in the tree
#if DT_NODE_HAS_STATUS(DT_ALIAS(i2c_0), okay)
#define I2C_DEV_NAME DT_LABEL(DT_ALIAS(i2c_0))
#elif DT_NODE_HAS_STATUS(DT_ALIAS(i2c_1), okay)
#define I2C_DEV_NAME DT_LABEL(DT_ALIAS(i2c_1))
#elif DT_NODE_HAS_STATUS(DT_ALIAS(i2c_2), okay)
#define I2C_DEV_NAME DT_LABEL(DT_ALIAS(i2c_2))
#error "Please set the correct I2C device"
But to my understanding, to work you need to have i2c_0 in the devicetree for my board because I reach the `#error` line at compile time. And accordingly its the devicetree contains an i2c1 node but not in the root node and I'm still figuring out what does that mean.
pinctrl-0 = <&i2c1_scl_pb8 &i2c1_sda_pb9>;
pinctrl-names = "default";
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>; };
Any help and additional documentation I should read are welcome.