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

Add official support for the ST M24 I2C EEPROM series #73136

Conversation

benediktibk
Copy link
Collaborator

It is already with the existing implementation of the AT24 possible to use an EEPROM from the ST M24 series, although it is not very well documented (see #73064 and #69021). To avoid this confusion I have generalized the driver for the AT24 and AT25 so that it can be reused for other compatibles and added specific bindings for the ST M24 I2C automotive series.
With this approach it is rather clear which ICs are supported by which driver, and it can be easily extended for other compatible ICs.

@benediktibk benediktibk force-pushed the add_eeprom_m24xxx_bindings branch 2 times, most recently from 44ed1b3 to d711611 Compare May 22, 2024 09:30
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

Thanks for digging into this direction, but adequate use of dts should help getting things more simple.

Comment on lines 4 to 16
description: ST M24C04-A125 automotive 4-kbit I2C EEPROM

compatible: "st,m24c04-a125"

include: ["atmel,at2x-base.yaml", i2c-device.yaml]

properties:
size:
const: 512
pagesize:
const: 16
address-width:
const: 8
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need to have all these "non-compatible" compatibles using fixed properties?

What about a more generic st,m24xxx compatible ?
Aim it to document that a class of devices is supported and show how to configure it.

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 would rather prefer to be specific, as this has multiple advantages:

  1. If I only document the proper usage, I still have to add some text which has to be maintained. And usually documentation gets forgotten during updates and changes and it is therefore more likely be incorrect in the future.
  2. This adds a build time check, which avoids improper use and therefore frustration and bugs in real applications. And as the hardware won't change anymore I think this is worth the effort.
  3. Having a very generic compatible brought us to the current situation. From my experience it is rather handy on the first sight to add a more generic compatible, but in the end hardware vendors tend to do all kind of weird stuff with their hardware identifiers. There might not be something currently in the range of st,m24xxx which is incompatible with this driver, but I wouldn't bet on this to be true in the future as well.
  4. It is more clear to a user which compatible should be used for which IC in the hardware design.

drivers/eeprom/eeprom_at2x.c Outdated Show resolved Hide resolved
@benediktibk benediktibk force-pushed the add_eeprom_m24xxx_bindings branch from d711611 to c497304 Compare May 22, 2024 10:28
@benediktibk benediktibk marked this pull request as ready for review May 22, 2024 10:58
@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding area: EEPROM labels May 22, 2024
Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

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

NAK. This will become a maintenance nightmare given all the different, compatible EEPROMs out there. I wish you had approached me before embarking on this.

@benediktibk
Copy link
Collaborator Author

NAK. This will become a maintenance nightmare given all the different, compatible EEPROMs out there. I wish you had approached me before embarking on this.

Is the NACK for only the IC specific compatibles, or the complete approach? Because I wouldn't be a big fan of having a more generic st,m24xxx (as explained here #73136 (comment)), but I would consider this still be better than the current status.

@henrikbrixandersen
Copy link
Member

Is the NACK for only the IC specific compatibles, or the complete approach? Because I wouldn't be a big fan of having a more generic st,m24xxx (as explained here #73136 (comment)), but I would consider this still be better than the current status.

I really do not see an issue with the current compatible and I would not want to add a bunch of vendor-specific aliases for this.

As mentioned earlier, I believe this can be solved by improving the documentation on how to configure serial EEPROMs in Zephyr. I plan on starting this work prior to v3.7.0.

@benediktibk
Copy link
Collaborator Author

Is the NACK for only the IC specific compatibles, or the complete approach? Because I wouldn't be a big fan of having a more generic st,m24xxx (as explained here #73136 (comment)), but I would consider this still be better than the current status.

I really do not see an issue with the current compatible and I would not want to add a bunch of vendor-specific aliases for this.

As mentioned earlier, I believe this can be solved by improving the documentation on how to configure serial EEPROMs in Zephyr. I plan on starting this work prior to v3.7.0.

Unfortunately I will have to disagree, because as a user it is rather confusing to use the compatible of A for B. I'm not convinced that documentation will solve this issue. On top of that, having build time checks and therefore a mechanism to fail early avoids a lot of issues in the long run.

@pdgendt
Copy link
Collaborator

pdgendt commented May 22, 2024

I like the comment of @erwango, put a generic compatible at the end if the list?

@benediktibk benediktibk force-pushed the add_eeprom_m24xxx_bindings branch from c497304 to 17b6ff5 Compare May 22, 2024 11:57
@benediktibk
Copy link
Collaborator Author

But anyway, @henrikbrixandersen is strongly against this, he prefers to stick to only the historical binding of atmel,at24 as it preceeds the reimplementation by other vendors and wants to avoid the confusion with additional documentation. Please correct me, if I am (unintentionally) citing you incorrectly.

@henrikbrixandersen
Copy link
Member

But anyway, @henrikbrixandersen is strongly against this, he prefers to stick to only the historical binding of atmel,at24 as it preceeds the reimplementation by other vendors and wants to avoid the confusion with additional documentation. Please correct me, if I am (unintentionally) citing you incorrectly.

No, that is correct.

@erwango
Copy link
Member

erwango commented May 22, 2024

But anyway, @henrikbrixandersen is strongly against this, he prefers to stick to only the historical binding of atmel,at24 as it preceeds the reimplementation by other vendors and wants to avoid the confusion with additional documentation. Please correct me, if I am (unintentionally) citing you incorrectly.

No, that is correct.

@henrikbrixandersen I understand your position, but what would you propose to explicit the fact that atmel,at24 compatible devices are supported?
This is already the second PR we have on the same topic and I guess that the ones pushing PRs are much less than the one that needed it and gave up. Obviously we miss some way to document this clearly.

@pdgendt
Copy link
Collaborator

pdgendt commented May 22, 2024

I tend to agree, there are ongoing discussions whether to rename struct net_buf to something generic, which has a much bigger impact than to generalize a common driver for different peripherals.

@henrikbrixandersen
Copy link
Member

henrikbrixandersen commented May 22, 2024

@henrikbrixandersen I understand your position, but what would you propose to explicit the fact that atmel,at24 compatible devices are supported?
This is already the second PR we have on the same topic and I guess that the ones pushing PRs are much less than the one that needed it and gave up. Obviously we miss some way to document this clearly.

My plan is to add a documentation page under https://docs.zephyrproject.org/latest/hardware/peripherals/eeprom.html detailing how to look up the various properties of a serial EEPROM in the data sheet with examples of how to represent these in a devicetree node.

Furthermore, I plan revisiting all occurrences of compatible = "atmel,at2*" within the tree and add a more specific compatible to the left of it (sort of like what is done here, but with the specific part number instead of xxx: https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/shields/x_nucleo_eeprma2/x_nucleo_eeprma2.overlay). This should help people grepping through the tree to realise that these devices are already supported.

We can also extend the help text of the bindings and Kconfig options to list "st,m24xxx" and other families to help people find them.

@henrikbrixandersen
Copy link
Member

I tend to agree, there are ongoing discussions whether to rename struct net_buf to something generic, which has a much bigger impact than to generalize a common driver for different peripherals.

I honestly don't believe the two are comparable. Also, as you may recall, it was decided not to rename net_buf for now, but merely move it up to increase visibility.

@erwango
Copy link
Member

erwango commented May 22, 2024

@henrikbrixandersen I understand your position, but what would you propose to explicit the fact that atmel,at24 compatible devices are supported?
This is already the second PR we have on the same topic and I guess that the ones pushing PRs are much less than the one that needed it and gave up. Obviously we miss some way to document this clearly.

My plan is to add a documentation page under https://docs.zephyrproject.org/latest/hardware/peripherals/eeprom.html detailing how to look up the various properties of a serial EEPROM in the data sheet with examples of how to represent these in a devicetree node.

Furthermore, I plan revisiting all occurrences of compatible = "atmel,at2*" within the tree and add a more specific compatible to the left of it (sort of like what is done here, but with the specific part number instead of xxx: https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/shields/x_nucleo_eeprma2/x_nucleo_eeprma2.overlay). This should help people grepping through the tree to realise that these devices are already supported.

We can also extend the help text of the bindings and Kconfig options to list "st,m24xxx" and other families to help people find them.

Ok, then, that's basically quite aligned with the content of my review (here and here) so I can't agree more.

@benediktibk benediktibk force-pushed the add_eeprom_m24xxx_bindings branch from 17b6ff5 to d795d84 Compare May 22, 2024 12:32
@benediktibk
Copy link
Collaborator Author

Lets see if I have understood it correctly. This PR now contains only additional bindings and build_all tests which show how they can be used. This doesn't impact the implementation of the AT24 at all, but states explicitly which devices are supported, with the added benefit of build time failures for improper usage.

@benediktibk
Copy link
Collaborator Author

The build error seems to be unrelated to these changes:

 Traceback (most recent call last):
  File "/home/runner/.local/lib/python3.10/site-packages/sphinx/cmd/build.py", line 337, in build_main
    app.build(args.force_all, args.filenames)
  File "/home/runner/.local/lib/python3.10/site-packages/sphinx/application.py", line 351, in build
    self.builder.build_update()
  File "/home/runner/.local/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 293, in build_update
    self.build(to_build,
  File "/home/runner/.local/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 313, in build
    updated_docnames = set(self.read())
  File "/home/runner/.local/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 417, in read
    self._read_parallel(docnames, nproc=self.app.parallel)
  File "/home/runner/.local/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 473, in _read_parallel
    tasks.join()
  File "/home/runner/.local/lib/python3.10/site-packages/sphinx/util/parallel.py", line 107, in join
    if not self._join_one():
  File "/home/runner/.local/lib/python3.10/site-packages/sphinx/util/parallel.py", line 125, in _join_one
    exc, logs, result = pipe.recv()
  File "/usr/lib/python3.10/multiprocessing/connection.py", line 250, in recv
    buf = self._recv_bytes()
  File "/usr/lib/python3.10/multiprocessing/connection.py", line 414, in _recv_bytes
    buf = self._recv(4)
  File "/usr/lib/python3.10/multiprocessing/connection.py", line 383, in _recv
    raise EOFError
EOFError

Exception occurred:
  File "/usr/lib/python3.10/multiprocessing/connection.py", line 383, in _recv
    raise EOFError

@benediktibk benediktibk requested a review from decsny May 27, 2024 11:43
@henrikbrixandersen
Copy link
Member

henrikbrixandersen commented May 30, 2024

My plan is to add a documentation page under docs.zephyrproject.org/latest/hardware/peripherals/eeprom.html detailing how to look up the various properties of a serial EEPROM in the data sheet with examples of how to represent these in a devicetree node.

Furthermore, I plan revisiting all occurrences of compatible = "atmel,at2*" within the tree and add a more specific compatible to the left of it (sort of like what is done here, but with the specific part number instead of xxx: main/boards/shields/x_nucleo_eeprma2/x_nucleo_eeprma2.overlay). This should help people grepping through the tree to realise that these devices are already supported.

We can also extend the help text of the bindings and Kconfig options to list "st,m24xxx" and other families to help people find them.

Please see #73512

@benediktibk
Copy link
Collaborator Author

Rebased onto main to resolve conflicts.

@decsny decsny dismissed their stale review June 14, 2024 20:43

at a glance looks better

@benediktibk benediktibk force-pushed the add_eeprom_m24xxx_bindings branch from 85f766e to dbf78a8 Compare June 26, 2024 19:25
@benediktibk
Copy link
Collaborator Author

Rebased onto main to resolve merge conflicts.

@benediktibk benediktibk force-pushed the add_eeprom_m24xxx_bindings branch from dbf78a8 to 280f7f7 Compare June 27, 2024 06:57
@benediktibk benediktibk requested a review from pdgendt July 1, 2024 16:41
pdgendt
pdgendt previously approved these changes Jul 4, 2024
Copy link
Collaborator

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

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

I think this makes sense, but needs maintainer (Brix) approval. Should this still be considered for 3.7?

@benediktibk
Copy link
Collaborator Author

I think this makes sense, but needs maintainer (Brix) approval. Should this still be considered for 3.7?

I don't mind when it is getting merged, I just think it should end up in main at some point. Maybe we can convince @henrikbrixandersen with the next PR which tries to implement an AT24 variant ;-).

@henrikbrixandersen
Copy link
Member

I think this makes sense, but needs maintainer (Brix) approval. Should this still be considered for 3.7?

I don't mind when it is getting merged, I just think it should end up in main at some point. Maybe we can convince @henrikbrixandersen with the next PR which tries to implement an AT24 variant ;-).

As I have told you already, this PR will not be merged upstream. We already have what you call "official support for the ST M24 I2C EEPROM series". The proper solution is to use the devicetree "compatible" string as it is intended, and simply add a "atmel,at24" (as this is the common programming model for this type of device) at the end of the list..

Copy link

github-actions bot commented Sep 3, 2024

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

Generalize the AT24/AT25 EEPROM implementation, so that it can be
reused for bindings of compatible chips from other vendors.

Signed-off-by: Benedikt Schmidt <[email protected]>
Add a binding for the I2C EEPROM series M24xxx from ST.

Signed-off-by: Benedikt Schmidt <[email protected]>
Use the AT2X driver for the ST M24 I2C EEPROM series.

Signed-off-by: Benedikt Schmidt <[email protected]>
Add an instance of the ST M24 I2C EEPROM to the
EEPROM build_all tests.

Signed-off-by: Benedikt Schmidt <[email protected]>
@benediktibk
Copy link
Collaborator Author

Rebased onto main to resolve merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: EEPROM area: Shields Shields (add-on boards)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants