I've tried to measure spi_flash_erase_sector() speed and I got surprisingly slow results... It takes more than 3000000 to cycles to erase the sector 4096 bytes long. The average value is about 3500000. Assuming we have 80MHz and 4Mb memory full memory erase should take about 50 sec, but esptool does it much faster (10 times I think). Is it really so slow? Most probably I'm doing something wrong (measurement, calculation or wrong function usage). Please, point me out to my mistake.
Code: Select all
uint32_t getCycleCount()
{
uint32_t ccount;
__asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
return ccount;
}
#define BEGIN_MEASURE startTime = getCycleCount();
#define PRINT_TIME(x) \
endTime = getCycleCount(); \
printf(x); \
printf("%d \r\n", endTime - startTime);
...
uint32_t addr = 0x160000;
portTickType startTime, endTime;
BEGIN_MEASURE
if (flashEraseSector((addr / SPI_FLASH_SEC_SIZE)) != SPI_FLASH_RESULT_OK)
printf("error erase sector\n");
PRINT_TIME("erase sector: ")
BEGIN_MEASURE
if (flashEraseSector((addr / SPI_FLASH_SEC_SIZE) + 1) != SPI_FLASH_RESULT_OK)
printf("error erase sector\n");
PRINT_TIME("erase sector: ")