ESP8266 Developer Zone The Official ESP8266 Forum 2016-03-16T23:55:51+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=1883 2016-03-16T23:55:51+08:00 2016-03-16T23:55:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1883&p=6147#p6147 <![CDATA[Re: SPI Driver API in RTOS SDK v1.3]]>

Code:

uint8 param_set_entry(uint8 EntryNum, uint16 EntrySize, uint32 *EntryPtr)
{
  uint8   retval;
  uint8   retry;
  uint16  sect;
  uint16  size;
  uint32 *buff = NULL;
  SpiFlashOpResult result;

  if((EntryNum < PARAM_ENTRY_MAX) && (EntrySize <= CONFIG_PARAM_ENTRY_SIZE))
  {
    sect = (CONFIG_PARAM_USRSEC_OFFSET + EntryNum * CONFIG_PARAM_ENTRY_SIZE) / CONFIG_SPI_FLASH_SEC_SIZE;

    /* Allocate buff for a sector */
    if( (PARAM_ENTRY_MAX * CONFIG_PARAM_ENTRY_SIZE) <= CONFIG_SPI_FLASH_SEC_SIZE )
    {
      /* There is only 1 sector used, the current Entry locates in the 1st Sector */
      size = PARAM_ENTRY_MAX * CONFIG_PARAM_ENTRY_SIZE;
    }
    else  /* There is only 2 sector used*/
    {
      if((EntryNum * CONFIG_PARAM_ENTRY_SIZE) >= CONFIG_SPI_FLASH_SEC_SIZE)
      {
        /*the current Entry locates in the 2st Sector*/
        size = PARAM_ENTRY_MAX * CONFIG_PARAM_ENTRY_SIZE - CONFIG_SPI_FLASH_SEC_SIZE;
      }
      else  /*the current Entry locates in the 1st Sector*/
      {
        size = CONFIG_SPI_FLASH_SEC_SIZE;
      }
    }

    buff = (uint32 *)malloc(size);
    if(NULL == buff)
      return false;

    /*Try to backup Entries to be erased */
    retry = CONFIG_PARAM_RETRY;
    retval = false;

    while(retry)
    {
      result = spi_flash_read((sect * CONFIG_SPI_FLASH_SEC_SIZE), buff, (uint32)size);
      switch(result)
      {
        case SPI_FLASH_RESULT_OK:
        {
          retval = true;
          retry = 1;
          break;
        }
        default:
        {
          break;;
        }
      }
      retry --;
    }

    if(false == retval)
      goto Failed;

    /*Try to erased sector */
    retry = CONFIG_PARAM_RETRY;
    retval = false;

    while(retry)
    {
      result = spi_flash_erase_sector(sect);
      switch(result)
      {
        case SPI_FLASH_RESULT_OK:
        {
          retval = true;
          retry  = 1;
          break;
        }
        default:
        {
          break;;
        }
      }
      retry --;
    }

    if(false == retval)
      goto Failed;


    /* Merge Data into buffer */
    memcpy((buff + ((EntryNum * CONFIG_PARAM_ENTRY_SIZE) % CONFIG_SPI_FLASH_SEC_SIZE)), EntryPtr, EntrySize);

    /*Try to Write Entries to Erased Sector */
    retry = CONFIG_PARAM_RETRY;
    retval = false;

    while(retry)
    {
      result = spi_flash_write((sect * CONFIG_SPI_FLASH_SEC_SIZE), buff, (uint32)size);
      switch(result)
      {
        case SPI_FLASH_RESULT_OK:
        {
          retval = true;
          retry  = 1;
          break;
        }
        default:
        {
          break;;
        }
      }
      retry --;
    }

Failed:
    if(NULL != buff)
      free(buff);
    return retval;
  }
  return false;
}

Statistics: Posted by esp8266ac — Wed Mar 16, 2016 11:55 pm


]]>
2016-03-16T10:57:22+08:00 2016-03-16T10:57:22+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1883&p=6134#p6134 <![CDATA[Re: SPI Driver API in RTOS SDK v1.3]]>

SPI Flash 读写速度太慢了, 以一个Sector 为例, 从读回数据备份,擦除Sector,写回数据, 4K数据需要耗费5分钟左右

擦写 Flash 不会这么慢的,能否提供您的测试代码,以供查证?

Statistics: Posted by ESP_Faye — Wed Mar 16, 2016 10:57 am


]]>
2016-03-16T09:45:30+08:00 2016-03-16T09:45:30+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1883&p=6128#p6128 <![CDATA[Re: SPI Driver API in RTOS SDK v1.3]]>
SPI Flash 读写速度太慢了, 以一个Sector 为例, 从读回数据备份,擦除Sector,写回数据, 4K数据需要耗费5分钟左右;

有办法优化速度?

Statistics: Posted by esp8266ac — Wed Mar 16, 2016 9:45 am


]]>
2016-03-08T14:41:41+08:00 2016-03-08T14:41:41+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1883&p=6031#p6031 <![CDATA[SPI Driver API in RTOS SDK v1.3]]>
• uint32 spi_flash_get_id (void)
Get ID info of SPI Flash.
• SpiFlashOpResult spi_flash_read_status (uint32 ∗ status)
Read state register of SPI Flash.
• SpiFlashOpResult spi_flash_write_status (uint32 status_value)
Write state register of SPI Flash.
• SpiFlashOpResult spi_flash_erase_sector (uint16 sec)
Erase the Flash sector.
• SpiFlashOpResult spi_flash_write (uint32 des_addr, uint32 ∗ src_addr, uint32 size)
Write data to Flash.
• SpiFlashOpResult spi_flash_read (uint32 src_addr, uint32 ∗ des_addr, uint32 size)
Read data from Flash.

而在RTOS SDK Programming Guide中提及:

9. 基本示例:从 Flash 读取数据
(1) Flash 读写数据,要求必须 4 字节对齐。例如,从 Flash 读取数据:
(2) 向 Flash 写入数据同理,要求 4 字节对齐,使用接口 spi_flash_write 即可。
(3) 编译应用程序,生成固件烧录到 ESP8266 硬件模组中。
(4) 硬件模组掉电,切换到运行模式,重新上电,运行应用程序。

Flash Write 一般是要先Read/Backup 有用数据, Erase Sector, 合并备份的数据和要写入的数据,把所有数据写到Flash;
ProgrammingGuide 说 直接使用 spi_flash_write, 难道是spi_flash_write封装了上述功能吗? 还请帮忙澄清一下,谢谢!

Statistics: Posted by esp8266ac — Tue Mar 08, 2016 2:41 pm


]]>