Chat freely about anything...

User avatar
By WickedCode
#72107 Hi,

I've tried to measure the time of spi_flash_erase_sector and I've got really 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). So, the question is where i'm wrong? ;) I mean measurement, calculation or wrong function usage.

I used the following code to measure:
Code: Select alluint32_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: ")