Skip to content

EEPROM driver makes invalid assumptions #379

Open
@elagil

Description

@elagil

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions