Skip to content

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

Merged
merged 2 commits into from
Jul 6, 2017

Conversation

ydamigos
Copy link
Collaborator

@ydamigos ydamigos commented Jul 1, 2017

This patches allow the configuration of I2C using DT for the following STM32 boards:

disco_l475_iot1
nucleo_f401re
96b_carbon
olimexino_stm32

@galak galak self-assigned this Jul 1, 2017
@galak galak requested review from erwango and agross-oss July 1, 2017 13:58
Copy link
Collaborator

@galak galak left a 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.

@@ -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,
Copy link
Collaborator

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

@@ -215,6 +215,8 @@ config I2C_1
bool "Enable I2C Port 1"
default n

if !(I2C_STM32_V1 || I2C_STM32_V2)
Copy link
Collaborator

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.

@@ -27,3 +27,8 @@
current-speed = <115200>;
status = "ok";
};

&i2c1 {
default-configuration = <0x14>;
Copy link
Collaborator

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.

Copy link
Collaborator

@galak galak left a 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
Copy link
Collaborator

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.

Copy link
Collaborator Author

@ydamigos ydamigos Jul 1, 2017

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?

Copy link
Collaborator Author

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.

@ydamigos ydamigos force-pushed the dts-i2c branch 3 times, most recently from 168eb2e to 6766b99 Compare July 2, 2017 10:06
@ydamigos
Copy link
Collaborator Author

ydamigos commented Jul 2, 2017

I updated the compatibles to match _v1 & _v2 I2C HW.

This binding gives the base structures for all I2C devices

properties:
- clock-frequency :
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator

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

compatible = "st,stm32-i2c-v1";
reg = <0x40005400 0x400>;
interrupts = <31 0>, <32 0>;
starus = "disable";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status = "disabled"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it.

- clock-frequency :
type: int
category: optional
description: Desired I2C bus clock frequency in Hz
Copy link
Member

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?

Copy link
Collaborator Author

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)

Copy link
Member

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)

Copy link
Collaborator Author

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".

compatible = "st,stm32-i2c-v1";
reg = <0x40005400 0x400>;
interrupts = <31 0>, <32 0>;
starus = "disable";
Copy link
Member

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";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it.

compatible = "st,stm32-i2c-v1";
reg = <0x40005800 0x400>;
interrupts = <33 0>, <34 0>;
starus = "disable";
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it.

compatible = "st,stm32-i2c-v1";
reg = <0x40005400 0x400>;
interrupts = <31 0>, <32 0>;
starus = "disable";
Copy link
Member

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";

Copy link
Collaborator Author

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>;
Copy link
Member

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";

Copy link
Collaborator Author

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>;
Copy link
Member

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";

Copy link
Collaborator Author

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>;
Copy link
Member

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";

Copy link
Collaborator Author

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>;
Copy link
Member

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";

Copy link
Collaborator Author

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>;
Copy link
Member

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";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it.

@ydamigos
Copy link
Collaborator Author

ydamigos commented Jul 3, 2017

Updated according to the review requests

@ydamigos
Copy link
Collaborator Author

ydamigos commented Jul 3, 2017

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:

/* i2c@40005400 */
#define ST_STM32_I2C_V1_40005400_BASE_ADDRESS_0		0x40005400
#define ST_STM32_I2C_V1_40005400_IRQ_0			31
#define ST_STM32_I2C_V1_40005400_IRQ_0_PRIORITY		0
#define ST_STM32_I2C_V1_40005400_IRQ_1			32
#define ST_STM32_I2C_V1_40005400_IRQ_1_PRIORITY		0
#define ST_STM32_I2C_V1_40005400_LABEL			"I2C_1"
#define ST_STM32_I2C_V1_40005400_SIZE_0			1024
#define ST_STM32_I2C_V1_40005400_BASE_ADDRESS		ST_STM32_I2C_V1_40005400_BASE_ADDRESS_0
#define ST_STM32_I2C_V1_40005400_ERROR_IRQ		ST_STM32_I2C_V1_40005400_IRQ_1_PRIORITY
#define ST_STM32_I2C_V1_40005400_EVENT_IRQ		ST_STM32_I2C_V1_40005400_IRQ_0_PRIORITY
#define ST_STM32_I2C_V1_40005400_SIZE			ST_STM32_I2C_V1_40005400_SIZE_0

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?

@agross-oss
Copy link
Collaborator

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.

@agross-oss
Copy link
Collaborator

agross-oss commented Jul 4, 2017

Found the issue. It was a bug in the script. Please see:
#680

@ydamigos

@galak
Copy link
Collaborator

galak commented Jul 4, 2017

#680 is now merged.

@ydamigos
Copy link
Collaborator Author

ydamigos commented Jul 4, 2017

It was merged on master, do you plan to merge it also in arm branch?

@ydamigos ydamigos force-pushed the dts-i2c branch 2 times, most recently from dec8cf1 to 9454295 Compare July 4, 2017 15:42
@galak
Copy link
Collaborator

galak commented Jul 5, 2017

Yes, will update the arm branch

ydamigos added 2 commits July 6, 2017 17:58
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]>
@ydamigos
Copy link
Collaborator Author

ydamigos commented Jul 6, 2017

The extract_dts_includes.py script was merged in arm branch, so I updated the PR.

@galak galak merged commit 784814d into zephyrproject-rtos:arm Jul 6, 2017
@ydamigos ydamigos deleted the dts-i2c branch July 6, 2017 19:40
nagineni pushed a commit to nagineni/zephyr that referenced this pull request Nov 20, 2017
…yrproject-rtos#663)

Also fixing the return type to be int, since that's what
zephyr returns.

Signed-off-by: Geoff Gustafson <[email protected]>
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.

5 participants