Skip to content

Conversation

@Manu3l0us
Copy link

In case the EEPROM data stored in the buffer shall be not writable from the I2C interface, the read-only property can now be set in the device tree.

@zephyrbot zephyrbot requested a review from teburd July 11, 2024 12:48
@Manu3l0us Manu3l0us force-pushed the read_only_eeprom_target branch from aba8e43 to b119543 Compare July 11, 2024 12:57
@zephyrbot zephyrbot added the size: XS A PR changing only a single line of code label Jul 11, 2024
@Manu3l0us Manu3l0us force-pushed the read_only_eeprom_target branch from b119543 to 0aa34cf Compare July 11, 2024 14:09
@Manu3l0us Manu3l0us force-pushed the read_only_eeprom_target branch 2 times, most recently from 2e4621a to 2abe1e1 Compare July 11, 2024 17:03
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.

Looks good! Now all that's needed is a corresponding test case in tests/drivers/i2c/i2c_target_api/ 👍

@Manu3l0us
Copy link
Author

Looks good! Now all that's needed is a corresponding test case in tests/drivers/i2c/i2c_target_api/ 👍

Good point, I will figure out how and update the PR once done.

@Manu3l0us
Copy link
Author

@henrikbrixandersen I am thinking about adding another EEPROM which is read-only to the device tree overlays within the test project. Also an EEPROM with 16bit addressing should be added to increase test coverage of the existing code which also supports this since a couple of months. I could probably do that at the same time. Does this sound like the right approach to you?

@henrikbrixandersen
Copy link
Member

@henrikbrixandersen I am thinking about adding another EEPROM which is read-only to the device tree overlays within the test project. Also an EEPROM with 16bit addressing should be added to increase test coverage of the existing code which also supports this since a couple of months. I could probably do that at the same time. Does this sound like the right approach to you?

Yes, that sounds good along with some accompanying test cases.

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Sep 14, 2024
@Manu3l0us
Copy link
Author

I took this up again as I was busy with other stuff during the last months. I tried to run the existing test on a RPi Pico but couldn't get it to work until now. What hardware setup is needed to run those tests?

@Manu3l0us
Copy link
Author

@henrikbrixandersen I finally had the time to write a simple test and I pushed my work in progress. Some questions:

  1. On the i2c_dw based target I'm using here, no NACK is generated and therefore I don't get a non-zero return code. Therefore I currently commented this check out for the test to run. Should I add a platform dependent test condition or how would you handle this?
  2. I added the overlay for the rpi_pico which I currently use and I updated the overlay for it. What is the general expectation when adding test cases? Shall I update the other overlays as well? I don't have the hardware to test any of those boards.

@Manu3l0us Manu3l0us force-pushed the read_only_eeprom_target branch 4 times, most recently from 9816428 to 0db9102 Compare November 14, 2024 15:02
In case the EEPROM data stored in the buffer shall be not writable from the
I2C interface, the read-only property can now be set in the device tree.

Signed-off-by: Manuel Aebischer <[email protected]>
@Manu3l0us Manu3l0us force-pushed the read_only_eeprom_target branch 3 times, most recently from f136954 to 7d2aeea Compare November 14, 2024 15:59
This additional test case verifies that an i2c_eeprom_target, which is
set as read-only in the device tree cannot be written from the I2C bus.

Signed-off-by: Manuel Aebischer <[email protected]>
@Manu3l0us Manu3l0us force-pushed the read_only_eeprom_target branch from 7d2aeea to 800ce8d Compare November 14, 2024 18:36
@Manu3l0us
Copy link
Author

Manu3l0us commented Nov 14, 2024

Okay, I saw that the boards are tested in CI, so I can safely add it to the overlays without breaking the tests

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.

Thanks! However, I don't think we need this read-only EEPROM added to each and every board here (and we really need to cut down on these boards).

Perhaps make the test conditional on the device being available (skip it if not present) and just add it to the board(s), you've tested with?

Comment on lines +310 to +312
#ifndef CONFIG_I2C_DW
zassert_not_equal(ret, 0, "Write attempt to read-only EEPROM 2 succeeded unexpectedly");
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Author

Choose a reason for hiding this comment

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

Usually the target should generate a NAK if it's being written and it's write protected, therefore the write on the controller side should return a non-zero return code. Unfortunately, the DesignWare I2C does not seem to implement this NAKing when used in target mode. I see if I can get hold of some other boards (e.g. STM32) to verify this as well.

@Manu3l0us
Copy link
Author

Thanks! However, I don't think we need this read-only EEPROM added to each and every board here (and we really need to cut down on these boards).

Perhaps make the test conditional on the device being available (skip it if not present) and just add it to the board(s), you've tested with?

Okay, understood. Will clean this up the coming week hopefully.

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Jan 23, 2025
Copy link
Member

@decsny decsny left a comment

Choose a reason for hiding this comment

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

dt prop is fine

@github-actions github-actions bot removed the Stale label Jan 28, 2025
#define I2C_EEPROM_INIT(inst) \
static struct i2c_eeprom_target_data i2c_eeprom_target_##inst##_dev_data = { \
.address_width = DT_INST_PROP_OR(inst, address_width, 8), \
.read_only = DT_INST_PROP_OR(inst, read_only, 8), \
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a copy-paste error. The read-only property is always present due to its type being boolean so there is no reason to give it a default value.

Suggested change
.read_only = DT_INST_PROP_OR(inst, read_only, 8), \
.read_only = DT_INST_PROP(inst, read_only), \

@henrikbrixandersen
Copy link
Member

@Manu3l0us Any plans for resuming work on this?

@henrikbrixandersen
Copy link
Member

@Manu3l0us I'm going to close this due to lack of response, although I'd love to see this feature make it in. Please reopen it if you decide to come back to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Devicetree area: EEPROM area: I2C size: XS A PR changing only a single line of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants