eeprom: at2x: Add support for at24cXX#29046
eeprom: at2x: Add support for at24cXX#29046carlescufi merged 1 commit intozephyrproject-rtos:masterfrom
Conversation
|
I also made (what I think are) correction to some of the indentation |
Those devices can use several I2C address in order to address more than 256 Bytes using 8bit addressing. Also several physical component can be used as a contiguous memory. Signed-off-by: Guillaume Lager <guillaume.lager@gmail.com>
|
I have a board with When compiling, the following error occurs As of now, only |
|
That's expected, the address width is either 8 or 16. Setting the size to 512 is enough to handle the |
|
@kurddt I did a simple test. test source /*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <sys/printk.h>
#include <device.h>
#include <drivers/eeprom.h>
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(test);
void main(void)
{
const struct device *eeprom;
size_t eeprom_size;
const uint8_t wr_buf[17] = {0x00, 0x01, 0x2, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10};
uint8_t rd_buf[17] = {0x00, };
int ret;
/* EEPROM */
eeprom = device_get_binding(DT_LABEL(DT_ALIAS(eeprom_0)));
if (!eeprom) {
LOG_ERR("Cannot get EEPROM device");
return;
}
eeprom_size = eeprom_get_size(eeprom);
LOG_INF("eeprom_size: %d", eeprom_size);
/* 8-biyte read/write */
ret = eeprom_write(eeprom, 0, wr_buf, 8);
if (ret) {
LOG_ERR("eeprom_write() failed.");
return;
}
memset(rd_buf, 0, sizeof(rd_buf));
ret = eeprom_read(eeprom, 0, rd_buf, 8);
if (ret) {
LOG_ERR("eeprom_write() failed.");
return;
}
if (memcmp(wr_buf, rd_buf, 8)) {
LOG_ERR("8-byte write, read mismatch.");
LOG_HEXDUMP_ERR(wr_buf, 8, "wr_buf");
LOG_HEXDUMP_ERR(rd_buf, 8, "rd_buf");
}
/* 12-biyte read/write */
ret = eeprom_write(eeprom, 0, wr_buf, 12);
if (ret) {
LOG_ERR("eeprom_write() failed.");
return;
}
memset(rd_buf, 0, sizeof(rd_buf));
ret = eeprom_read(eeprom, 0, rd_buf, 12);
if (ret) {
LOG_ERR("eeprom_write() failed.");
return;
}
if (memcmp(wr_buf, rd_buf, 12)) {
LOG_ERR("12-byte write, read mismatch.");
LOG_HEXDUMP_ERR(wr_buf, 12, "wr_buf");
LOG_HEXDUMP_ERR(rd_buf, 12, "rd_buf");
}
/* 16-biyte read/write */
ret = eeprom_write(eeprom, 0, wr_buf, 16);
if (ret) {
LOG_ERR("eeprom_write() failed.");
return;
}
memset(rd_buf, 0, sizeof(rd_buf));
ret = eeprom_read(eeprom, 0, rd_buf, 16);
if (ret) {
LOG_ERR("eeprom_write() failed.");
return;
}
if (memcmp(wr_buf, rd_buf, 16)) {
LOG_ERR("16-byte write, read mismatch.");
LOG_HEXDUMP_ERR(wr_buf, 16, "wr_buf");
LOG_HEXDUMP_ERR(rd_buf, 16, "rd_buf");
}
/* 17-biyte read/write */
ret = eeprom_write(eeprom, 0, wr_buf, 17);
if (ret) {
LOG_ERR("eeprom_write() failed.");
return;
}
memset(rd_buf, 0, sizeof(rd_buf));
ret = eeprom_read(eeprom, 0, rd_buf, 17);
if (ret) {
LOG_ERR("eeprom_write() failed.");
return;
}
if (memcmp(wr_buf, rd_buf, 17)) {
LOG_ERR("17-byte write, read mismatch.");
LOG_HEXDUMP_ERR(wr_buf, 17, "wr_buf");
LOG_HEXDUMP_ERR(rd_buf, 17, "rd_buf");
}
LOG_INF("EEPROM Test End!");
return;
}1. Current PR(address-width = <16>)console 2. Other PR(address-width = <9>)PR: #21170 console |
|
@KwonTae-young The address-width is meant to be used as the word address width, for Basically 8 means 1 byte address will be sent on the I2C bus after the device addressing. When set to 16, 2 bytes of address are sent |
|
@kurddt I confirmed that it works with the address-width set to 8. I thought the address-width should be 9-bit as shown in the datasheet. Some people think it can be confusing. EDIT: I confirmed that Linux kenrel is also handling the same as this PR. |
|
Yes I looked at the Linux kernel to get inspiration on how to deal with that. @KwonTae-young If you have a suggestion to make the address-width description more clear please go ahead |
henrikbrixandersen
left a comment
There was a problem hiding this comment.
Looks good. Thanks!
|
Might be good to remove the "Device Tree" and "Device Tree bindings" tags since they are not relevant anymore. I seems that I can't do that myself |

Those devices can use several I2C address in order to address more
than 256 Bytes using 8bit addressing. Also several physical component
can be used as a contiguous memory.
Alternative to #21170
Signed-off-by: Guillaume Lager guillaume.lager@gmail.com