From 56bd4a78b34bee7d33ef76cc011ba54412cc53ee Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 26 Oct 2015 14:50:50 +0300 Subject: [PATCH] Fix short unaligned writes in SPIFFS HAL, 2nd attempt (#924) --- cores/esp8266/spiffs_hal.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/spiffs_hal.cpp b/cores/esp8266/spiffs_hal.cpp index 756896f65..7f3245c0d 100644 --- a/cores/esp8266/spiffs_hal.cpp +++ b/cores/esp8266/spiffs_hal.cpp @@ -109,12 +109,11 @@ int32_t spiffs_hal_write(uint32_t addr, uint32_t size, uint8_t *src) { } if (addr < alignedBegin) { - uint32_t nb = alignedBegin - addr; - if (nb > size) - nb = size; - uint32_t tmp = 0xffffffff; - memcpy(((uint8_t* )&tmp) + 4 - nb, src, nb); - if (!ESP.flashWrite(alignedBegin - 4, &tmp, 4)) { + uint32_t ofs = alignedBegin - addr; + uint32_t nb = (size < ofs) ? size : ofs; + uint8_t tmp[4] __attribute__((aligned(4))) = {0xff, 0xff, 0xff, 0xff}; + memcpy(tmp + 4 - ofs, src, nb); + if (!ESP.flashWrite(alignedBegin - 4, (uint32_t*) tmp, 4)) { DEBUGV("_spif_write(%d) addr=%x size=%x ab=%x ae=%x\r\n", __LINE__, addr, size, alignedBegin, alignedEnd); return SPIFFS_ERR_INTERNAL;