esp8266/modesp: flash_write(): Writes in multiples of 4 bytes.

This commit is contained in:
Paul Sokolovsky 2016-03-27 15:32:58 +03:00
parent 53302f1616
commit fd86bf5917

View File

@ -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_int_t offset = mp_obj_get_int(offset_in);
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); 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); SpiFlashOpResult res = spi_flash_write(offset, bufinfo.buf, bufinfo.len);
if (res == SPI_FLASH_RESULT_OK) { if (res == SPI_FLASH_RESULT_OK) {
return mp_const_none; return mp_const_none;