From 97c00f1a22b3fd2d509c5ec75f365f8d38e6151c Mon Sep 17 00:00:00 2001 From: Stephan Brunner Date: Fri, 7 Feb 2020 22:35:18 +0100 Subject: [PATCH] Fix I2CEEBlockDevice read() When reading a data block, the returned error codes from the I2C subsystem are different from normal single byte operations. We have to verify that the read-function for multiple bytes does return zero, because it returns "readBytes != expectedLength". Additionally, sync before trying to read from the eeprom as slow devices may not yet be ready to return data, especially with low-priced ones used with fast controllers. --- .../storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp b/components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp index 42bbce7c96..93aab7ae76 100644 --- a/components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp +++ b/components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp @@ -68,7 +68,9 @@ int I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size) _i2c->stop(); - if (_i2c->read(_i2c_addr, static_cast(buffer), size) < 0) { + _sync(); + + if (0 != _i2c->read(_i2c_addr, static_cast(buffer), size)) { return BD_ERROR_DEVICE_ERROR; }