SuperHouse / esp-open-rtos

Open source FreeRTOS-based ESP8266 software framework
BSD 3-Clause "New" or "Revised" License
1.53k stars 491 forks source link

sdk_spi_flash_erase_sector + sdk_spi_flash_write doesn't work #538

Open zeroflag opened 6 years ago

zeroflag commented 6 years ago

I use the combination of _sdk_spi_flash_erasesector + _sdk_spi_flashwrite to write out same data to the flash memory. But after reading it back the result still contain what it was already there previously. In other words it doesn't change the content of the sector.

Here is an example code that tries to update the 100th sector.

char buffer[8] = "test1234";
sdk_spi_flash_erase_sector(100);
sdk_spi_flash_write(100 * 4096, (uint32_t*) &buffer, 8);
char result[8];
sdk_spi_flash_read(100 * 4096, (uint32_t*) &result, 8);
printf("result: %.8s", result);
zeroflag commented 6 years ago

I just realized if the flash mode is set to QIO then it works but if it's DIO it doesn't.

doragasu commented 6 years ago

How do you set QIO mode? I have several modules with Flash ID C84016 (sdk_spi_flash_get_id() returns 1640C8, but I think this number must be byte swapped to get the correct ID). With these modules, everything works fine. But I am now using other modules with flash ID E04016 (different manufacturer) and flash does not work. I have tried using both sdk_spi_XXX functions, and spiflash_XXX functions without success. Maybe my problem is the same as yours.

zeroflag commented 6 years ago

How do you set QIO mode?

I use esptool.py with --flash_mode qio parameter. I suspect this makes the device to stay in that mode.

doragasu commented 6 years ago

OK, I found out that the way was easier than expected: using the download tool.

I tired first downloading my application with all the modes, and none worked. Then I noticed that the bootloader was run before my application, so flashed the bootloader with QIO mode and... voila! It works :)

Anyway, it is a bit nasty that the flash write functions return success even when they are failing. Maybe this can be improved, so they return failure when erasing/writing fails due to misconfiguration.