diff --git a/libraries/AP_HAL_SITL/Storage.cpp b/libraries/AP_HAL_SITL/Storage.cpp index e2d1b3f000..fe6b84a19f 100644 --- a/libraries/AP_HAL_SITL/Storage.cpp +++ b/libraries/AP_HAL_SITL/Storage.cpp @@ -26,6 +26,14 @@ extern const AP_HAL::HAL& hal; #endif #endif +#ifndef HAL_FLASH_MIN_WRITE_SIZE +#define HAL_FLASH_MIN_WRITE_SIZE 1 +#endif + +#ifndef HAL_FLASH_ALLOW_UPDATE +#define HAL_FLASH_ALLOW_UPDATE 1 +#endif + void Storage::_storage_open(void) { if (_initialised) { @@ -225,12 +233,36 @@ static bool sitl_flash_write(uint32_t addr, const uint8_t *data, uint32_t length if (pread(flash_fd, old, length, addr) != length) { AP_HAL::panic("Failed to read flash.dat at %u len=%u", unsigned(addr), unsigned(length)); } +#if defined(HAL_FLASH_MIN_WRITE_SIZE) && HAL_FLASH_MIN_WRITE_SIZE == 32 + if ((length % HAL_FLASH_MIN_WRITE_SIZE) != 0 || (addr % HAL_FLASH_MIN_WRITE_SIZE) != 0) { + AP_HAL::panic("Attempt to write flash at %u length %u\n", addr, length); + } + // emulate H7 requirement that writes be to untouched bytes + for (uint32_t i=0; i