spi_flash_erase_sector() speed

WickedCode
Posts: 1
Joined: Tue Nov 28, 2017 3:14 am

spi_flash_erase_sector() speed

Postby WickedCode » Thu Nov 30, 2017 4:38 am

Hello,

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: ")

blubb
Posts: 116
Joined: Mon Jun 22, 2015 5:35 am

Re: spi_flash_erase_sector() speed

Postby blubb » Fri Dec 01, 2017 5:11 am

I just repeated your experiment using system_get_time(). Here, spi_flash_erase_sector() takes about 70 ms most of the time. Sometimes it is quicker (40 ms), though.

Who is online

Users browsing this forum: No registered users and 120 guests