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

EEPROM driver makes invalid assumptions #379

Open
elagil opened this issue Aug 12, 2023 · 2 comments
Open

EEPROM driver makes invalid assumptions #379

elagil opened this issue Aug 12, 2023 · 2 comments

Comments

@elagil
Copy link
Contributor

elagil commented Aug 12, 2023

In using the EEPROM driver for an I2C chipset, I ran into timeout issues on larger reads and writes.
Note that I am using an I2C clock of 100 kHz.

That's because the driver assumes an I2C clock of 400 kHz

#define EEPROM_I2C_CLOCK 400000

Then uses that value to calculate the I2C timeout in

static systime_t calc_timeout(I2CDriver *i2cp, size_t txbytes, size_t rxbytes) {
(void)i2cp;
const uint32_t bitsinbyte = 10;
uint32_t tmo;
tmo = ((txbytes + rxbytes + 1) * bitsinbyte * 1000);
tmo /= EEPROM_I2C_CLOCK;
tmo += 10; /* some additional milliseconds to be safer */
return TIME_MS2I(tmo);
}

See especially

tmo /= EEPROM_I2C_CLOCK;

There seems to be generalized code already

#if defined(SAM7_PLATFORM)
#define EEPROM_I2C_CLOCK (MCK / (((i2cp->config->cwgr & 0xFF) + ((i2cp->config->cwgr >> 8) & 0xFF)) * (1 << ((i2cp->config->cwgr >> 16) & 7)) + 6))
#else
#define EEPROM_I2C_CLOCK (i2cp->config->clock_speed)
#endif

but it is not in use.

I would like to clean up that driver and fix it. Would you accept a pull request?

@fpoussin
Copy link
Member

fpoussin commented Dec 5, 2023

Hi,

Of course, pull requests are very welcome 😄

@elagil
Copy link
Contributor Author

elagil commented Dec 5, 2023

Ok, it will take some time.

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

No branches or pull requests

2 participants