diff --git a/esp8266/modesp.c b/esp8266/modesp.c index 18859ead8a..29b18d862d 100644 --- a/esp8266/modesp.c +++ b/esp8266/modesp.c @@ -553,6 +553,9 @@ STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) { mp_int_t offset = mp_obj_get_int(offset_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); + if (bufinfo.len & 0x3) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "len must be multiple of 4")); + } SpiFlashOpResult res = spi_flash_write(offset, bufinfo.buf, bufinfo.len); if (res == SPI_FLASH_RESULT_OK) { return mp_const_none;