-
Notifications
You must be signed in to change notification settings - Fork 7.4k
dts: arm: STM32 boards use DT to configure I2C #663
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, some minor things to tweak.
drivers/i2c/i2c_ll_stm32.c
Outdated
@@ -140,11 +140,11 @@ DEVICE_AND_API_INIT(i2c_stm32_1, CONFIG_I2C_1_NAME, &i2c_stm32_init, | |||
#ifdef CONFIG_I2C_STM32_INTERRUPT | |||
static void i2c_stm32_irq_config_func_1(struct device *dev) | |||
{ | |||
IRQ_CONNECT(I2C1_EV_IRQn, CONFIG_I2C_1_IRQ_PRI, | |||
IRQ_CONNECT(I2C1_EV_IRQn, CONFIG_I2C_1_IRQ_EVENT_PRI, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should get the IRQ# from the DT as well
drivers/i2c/Kconfig
Outdated
@@ -215,6 +215,8 @@ config I2C_1 | |||
bool "Enable I2C Port 1" | |||
default n | |||
|
|||
if !(I2C_STM32_V1 || I2C_STM32_V2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets introduce a HAS_DTS_I2C and use that instead.
dts/arm/96b_carbon.dts
Outdated
@@ -27,3 +27,8 @@ | |||
current-speed = <115200>; | |||
status = "ok"; | |||
}; | |||
|
|||
&i2c1 { | |||
default-configuration = <0x14>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets not deal with default-configuration right now. We should re-work how that's done in Zephyr anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to put I2C_n_DEFAULT_CFG back into the board Kconfig.defconfig files. Also, I forgot to mention but we need to tweak the compatible. I assume the whole _v1 & _v2 drivers are because the I2C HW differs (and so the compatible should kinda match that).
@@ -10,14 +10,4 @@ if BOARD_96B_CARBON | |||
config BOARD | |||
default 96b_carbon | |||
|
|||
if I2C_1 | |||
|
|||
config I2C_1_DEFAULT_CFG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to leave all I2C_n_DEFAULT_CFG in here for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value for all I2C_n_DEFAULT_CFG is 0x00. Why should we change it in the board defconfig? Users should configure it in their applications. Please let me know if this change is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left all I2C_n_DEFAULT_CFG in Kconfig.defconfig files for now.
168eb2e
to
6766b99
Compare
I updated the compatibles to match _v1 & _v2 I2C HW. |
This binding gives the base structures for all I2C devices | ||
|
||
properties: | ||
- clock-frequency : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dts/common/yaml/uart.yaml is using "clock-frequency" to mean clock frequency driving the module, not the bus speed. We would better have "bus-speed" or "bus-clock-frequency". Bus speed or speed modes is also what I2C standard talks about. As it is the name "clock-frequency" is confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the clock-frequency because I followed the linux kernel DT bindings for I2C. Moreover, I have read in a previous comment (on github or mailing list, I cannot remember) that ST plans to use the same dts files for linux and zephyr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, aim is to converge to Linux Kernel DT.
For node properties, it's better to stick with Linux naming, as long as this is not in complete contradiction with driver behavior in Zephyr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks for clarification.
@@ -218,7 +220,7 @@ config I2C_1 | |||
config I2C_1_NAME | |||
string "Port 1 device name" | |||
default "I2C_1" | |||
depends on I2C_1 | |||
depends on I2C_1 && !HAS_DTS_I2C | |||
|
|||
config I2C_1_DEFAULT_CFG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under impression that the main point of using DTS is to get rid of things like this one from the Kconfig. Shouldn't default configuration be handled by DTS? I.e. shouldn't we add?
depends on !HAS_DTS_I2C
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially the PR handled also the default configuration in the DTS. I was asked in a previous comment to leave it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's it it out for now..We'd need to add the parameters we want to configure rather than a generic and vague default configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to suggest to sort out such issues as default configuration now, not later. Introducing new DTS based I2C config is a good chance to get rid of this config option. It is quite ugly. It's also not clear what DTS based I2C drivers should do with it.
As @erwango suggested one way to go would be to add in DTS specific parameters we want to configure. The other approach, mentioned by @ydamigos, would be not to call i2c_configure() in I2C driver initialization function but relay on a user calling i2c_configure() in the application. In this case we would not need to define any additional parameters in DTS. I'm personally in favor of the second approach.
Once this PR is merged I can update Atmel I2C drivers to use DTS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter approach sounds better to me. Keeps the DTS minimal, which it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we have already decided to go definitely for the latter approach but if we did we need to add
depends on !HAS_DTS_I2C
here to exclude this config option for DTS based I2C drivers. Also, we need to ensure that the driver initialization function does not call i2c_configure().
If we remove I2C_1_DEFAULT_CFG from Kconfig.defconfig but not from here and the driver initialization we will attempt to configure the driver with invalid parameters at boot, this should result in an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left all I2C_n_DEFAULT_CFG in Kconfig.defconfig files for now. As we plan not to handle the default configuration in the DTS file, I believe we should address this issue in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also a good option. I'll open a Jira issue to give this matter more visibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to get the base I2C stuff in for DT, I have idea's on how we can we than use DT to replace I2C_n_DEFAULT_CFG for HAS_DTS_I2C enabled platforms
dts/arm/st/stm32f103Xb.dtsi
Outdated
compatible = "st,stm32-i2c-v1"; | ||
reg = <0x40005400 0x400>; | ||
interrupts = <31 0>, <32 0>; | ||
starus = "disable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status = "disabled"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
dts/common/yaml/i2c.yaml
Outdated
- clock-frequency : | ||
type: int | ||
category: optional | ||
description: Desired I2C bus clock frequency in Hz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the I2C standard: "The bus speed is always constrained to the maximum communication rate of the slowest device attached to the bus". So this is the one important piece of information which needs to be provided by DTS. Otherwise I2C driver has no way of knowing what is the maximum speed it is allowed to run the bus at.
Maybe we should change the description to "Maximum I2C bus clock frequency in Hz"? Or do we need a second property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again here, I used part of the description in linux kernel DT bindings for I2C (https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/i2c/i2c-stm32.txt)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In properties description, I'm not opposed to clarifying driver behavior as it could diverge in some cases vs Linux's driver behavior and does not have impact on dts files (and won't cause any divergence on dts files themselves)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will update the description to "Maximum I2C bus clock frequency in Hz".
dts/arm/st/stm32f103Xb.dtsi
Outdated
compatible = "st,stm32-i2c-v1"; | ||
reg = <0x40005400 0x400>; | ||
interrupts = <31 0>, <32 0>; | ||
starus = "disable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: interrupt-names = "event", "error";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
dts/arm/st/stm32f103Xb.dtsi
Outdated
compatible = "st,stm32-i2c-v1"; | ||
reg = <0x40005800 0x400>; | ||
interrupts = <33 0>, <34 0>; | ||
starus = "disable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: interrupt-names = "event", "error";v
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
dts/arm/st/stm32f4.dtsi
Outdated
compatible = "st,stm32-i2c-v1"; | ||
reg = <0x40005400 0x400>; | ||
interrupts = <31 0>, <32 0>; | ||
starus = "disable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: interrupt-names = "event", "error";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
i2c2: i2c@40005800 { | ||
compatible = "st,stm32-i2c-v1"; | ||
reg = <0x40005800 0x400>; | ||
interrupts = <33 0>, <34 0>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: interrupt-names = "event", "error";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
i2c3: i2c@40005C00 { | ||
compatible = "st,stm32-i2c-v1"; | ||
reg = <0x40005C00 0x400>; | ||
interrupts = <72 0>, <73 0>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: interrupt-names = "event", "error";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
i2c1: i2c@40005400 { | ||
compatible = "st,stm32-i2c-v2"; | ||
reg = <0x40005400 0x400>; | ||
interrupts = <31 0>, <32 0>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: interrupt-names = "event", "error";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
i2c2: i2c@40005800 { | ||
compatible = "st,stm32-i2c-v2"; | ||
reg = <0x40005800 0x400>; | ||
interrupts = <33 0>, <34 0>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: interrupt-names = "event", "error";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
i2c3: i2c@40005C00 { | ||
compatible = "st,stm32-i2c-v2"; | ||
reg = <0x40005C00 0x400>; | ||
interrupts = <72 0>, <73 0>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: interrupt-names = "event", "error";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it.
Updated according to the review requests |
I do not have prior experience with dts files but I think something is wrong with the generated dts board header when I added the interrupt-names:
The define ST_STM32_I2C_V1_40005400_EVENT_IRQ points to the priority instead of the interrupt and I believe that a define ST_STM32_I2C_V1_40005400_EVENT_IRQ_PRIORITY is missing. The same happens for the ERROR_IRQ. @agross-linaro Is there a problem with the generated dts board header or this is the correct output? |
The name should be applied to each of the cells. There are two cells in your irqs, so it should be doing the right thing. I'll test out your patches and see what is going on. |
#680 is now merged. |
It was merged on master, do you plan to merge it also in arm branch? |
dec8cf1
to
9454295
Compare
Yes, will update the arm branch |
Add yaml files to DT for initial support of STM32 I2C Origin: original Signed-off-by: Yannis Damigos <[email protected]>
Configure I2C using DT for the following STM32 boards: disco_l475_iot1 nucleo_f401re 96b_carbon olimexino_stm32 Signed-off-by: Yannis Damigos <[email protected]>
The extract_dts_includes.py script was merged in arm branch, so I updated the PR. |
…yrproject-rtos#663) Also fixing the return type to be int, since that's what zephyr returns. Signed-off-by: Geoff Gustafson <[email protected]>
This patches allow the configuration of I2C using DT for the following STM32 boards:
disco_l475_iot1
nucleo_f401re
96b_carbon
olimexino_stm32