From 320834a5e75ca19b5e878258baceaeee3624dca3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Fri, 2 May 2014 22:12:45 +1000 Subject: [PATCH] HAL_PX4: read from FRAM in 128 byte chunks (2nd try) this time without the amazingly silly bug --- libraries/AP_HAL_PX4/Storage.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/AP_HAL_PX4/Storage.cpp b/libraries/AP_HAL_PX4/Storage.cpp index 4d7b10716..62301266c 100644 --- a/libraries/AP_HAL_PX4/Storage.cpp +++ b/libraries/AP_HAL_PX4/Storage.cpp @@ -154,8 +154,14 @@ void PX4Storage::_storage_open(void) if (fd == -1) { hal.scheduler->panic("Failed to open " MTD_PARAMS_FILE); } - if (read(fd, _buffer, sizeof(_buffer)) != sizeof(_buffer)) { - hal.scheduler->panic("Failed to read " MTD_PARAMS_FILE); + const uint16_t chunk_size = 128; + for (uint16_t ofs=0; ofs<sizeof(_buffer); ofs += chunk_size) { + ssize_t ret = read(fd, &_buffer[ofs], chunk_size); + if (ret != chunk_size) { + ::printf("storage read of %u bytes at %u to %p failed - got %d errno=%d\n", + (unsigned)sizeof(_buffer), (unsigned)ofs, &_buffer[ofs], (int)ret, (int)errno); + hal.scheduler->panic("Failed to read " MTD_PARAMS_FILE); + } } close(fd); _initialised = true; -- GitLab