Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
Diff: drivers/FlashIAP.cpp
- Revision:
- 186:707f6e361f3e
- Parent:
- 184:08ed48f1de7f
--- a/drivers/FlashIAP.cpp Thu Apr 19 17:12:19 2018 +0100 +++ b/drivers/FlashIAP.cpp Fri Jun 22 16:45:37 2018 +0100 @@ -107,10 +107,18 @@ _mutex->lock(); while (size) { uint32_t current_sector_size = flash_get_sector_size(&_flash, addr); + bool unaligned_src = (((size_t) buf / sizeof(uint32_t) * sizeof(uint32_t)) != (size_t) buf); chunk = std::min(current_sector_size - (addr % current_sector_size), size); - if (chunk < page_size) { + // Need to use the internal page buffer in any of these two cases: + // 1. Size is not page aligned + // 2. Source buffer is not aligned to uint32_t. This is not supported by many targets (although + // the pointer they accept is of uint8_t). + if (unaligned_src || (chunk < page_size)) { + chunk = std::min(chunk, page_size); memcpy(_page_buf, buf, chunk); - memset(_page_buf + chunk, 0xFF, page_size - chunk); + if (chunk < page_size) { + memset(_page_buf + chunk, 0xFF, page_size - chunk); + } prog_buf = _page_buf; prog_size = page_size; } else {