W25M02G不能读写擦除

2019-07-20 23:31发布

本帖最后由 一号小鱼 于 2017-12-25 13:22 编辑

我的板子上用STM32F205驱动SPI FLASH W25M02G,现在可以正常读出flash 的ID,但是不能读写擦除,读了一下开机时候的寄存器值,如下图: 3个寄存器值 3个寄存器值
3个寄存器的解释
360截图20171225104846073.jpg
360截图20171225104906891.jpg
360截图20171225104917559.jpg
硬件上/WP接上拉。
问题1:SR1的Block Protect Bits (BP3, BP2, BP1, BP0, TB) 的这几个位开机就是1是正常的么?
问题2:我将这几个位清0后写入SR1,再回读是正常的0x00,但是进行一次读操作后又恢复到0x7C.这又是什么情况。
问题3:这种情况下,我对flash 进行ERASE,SR3得到的状态值0x04,
360截图20171225105632503.jpg
擦除失败?
问题4:如果是保护状态,按表说明,这个情况下FLASH应该是没有锁定的吧?我理解可有错?
360截图20171225105849105.jpg
大家帮忙看下

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
6条回答
一号小鱼
2019-07-21 10:12
正点原子 发表于 2017-12-26 01:06
帮顶,多试试

谢谢,现在貌似是可以擦除了,不会报擦除跟写错误。但是现在写不进去,不报写错误,但是写完之后SR3-WEL没有自动归0,BUSY是清掉了的。 360截图20171227103730501.jpg [mw_shl_code=c,true]uint32_t SPI_NAND_WriteSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToWrite)
{
  uint32_t index = 0x00, numpagewritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
  uint32_t status = NAND_READY, size = 0x00;
        uint16_t pageaddr=(Address.Block<<6)|(Address.Page&0x003f);
        uint32_t waitwend=0;
        SPI_NAND_WaiteProtected();
        SPI_NAND_SetProtected();
  while((NumPageToWrite != 0x00) && (addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY))
  {       

                /*!< Select the FLASH: Chip Select low */
                sFLASH_CS_LOW();
                //&#199;D&#187;&#187;&#191;é&#199;&#248;
                if(Address.Zone==0)
                {
                        if(CurFlashDies==1)
                        {
                                CurFlashDies=0;
                                sFLASH_SendByte(sFLASH_CMD_DIES);
                                sFLASH_SendByte(0x00);
                        }
                }
                else if(Address.Zone==1)
                {
                        if(CurFlashDies==0)
                        {
                                CurFlashDies=1;
                                sFLASH_SendByte(sFLASH_CMD_DIES);
                                sFLASH_SendByte(0x01);               
                        }
                }
         /*!< Enable the write access to the FLASH */
                sFLASH_WriteEnable();
                /*!< Deselect the FLASH: Chip Select high */
                sFLASH_CS_HIGH();
               
                Flash_delay(1);
                sFLASH_CS_LOW();
                       
                /*!< Send "Write to Memory " instruction */
                sFLASH_SendByte(sFLASH_CMD_RANDOMPDL);//sFLASH_CMD_PDL
                /*!< Send WriteAddr Byte Address or Column Address byte to write to */
                sFLASH_SendByte(0x00);
                sFLASH_SendByte(0x00);
               
               

                /*!< while there is data to be written on the FLASH */
    /* Calculate the size */
    size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpagewritten);

    /* Write data (size-NAND_PAGE_SIZE)*/
    for(index=(size-NAND_PAGE_SIZE); index < size; index++)
    {
                        /*!< Send the current byte */
                        sFLASH_SendByte(pBuffer[index]);
    }
                /*!< Deselect the FLASH: Chip Select high */
                sFLASH_CS_HIGH();
                /*!< Wait the end of Flash writing */
                sFLASH_WaitForWriteEnd();

                        status=SPI_NAND_GetSR(sFLASH_SR1);
                        status=SPI_NAND_GetSR(sFLASH_SR3);
                SPI_NAND_SetSR(sFLASH_SR1,0x00);
       
                //êy&#190;Y×°&#212;&#216;íê3éoó£&#172;D′è&#235;ò&#187;ò3
                /*!< Select the FLASH: Chip Select low */
                sFLASH_CS_LOW();
                sFLASH_SendByte(sFLASH_CMD_PEXE);
                sFLASH_SendByte(sFLASH_DUMMY_BYTE);//Dummy                
                /*!< Send WriteAddr medium nibble address byte to write to */
                sFLASH_SendByte((pageaddr& 0xFF00) >> 8);
                /*!< Send WriteAddr low nibble address byte to write to */
                sFLASH_SendByte(pageaddr& 0xFF);
               
                /*!< Deselect the FLASH: Chip Select high */
                sFLASH_CS_HIGH();

                /*!< Wait the end of Flash writing */
                sFLASH_WaitForWriteEnd();
                status = SPI_NAND_GetStatus();
while(status==0x02)
{
                status = SPI_NAND_GetStatus();
        waitwend++;
        if(waitwend>0x10000)
        {
                break;
        }
}
                status = SPI_NAND_GetStatus();
                        status=SPI_NAND_GetSR(sFLASH_SR1);
                        status=SPI_NAND_GetSR(sFLASH_SR3);
if(status==0x02)
{
                SPI_NAND_SetSR(sFLASH_SR1,0x00);
       
                //êy&#190;Y×°&#212;&#216;íê3éoó£&#172;D′è&#235;ò&#187;ò3
                /*!< Select the FLASH: Chip Select low */
                sFLASH_CS_LOW();
                sFLASH_SendByte(sFLASH_CMD_PEXE);
                sFLASH_SendByte(sFLASH_DUMMY_BYTE);//Dummy                
                /*!< Send WriteAddr medium nibble address byte to write to */
                sFLASH_SendByte((pageaddr& 0xFF00) >> 8);
                /*!< Send WriteAddr low nibble address byte to write to */
                sFLASH_SendByte(pageaddr& 0xFF);
               
                /*!< Deselect the FLASH: Chip Select high */
                sFLASH_CS_HIGH();

                /*!< Wait the end of Flash writing */
                sFLASH_WaitForWriteEnd();
                status = SPI_NAND_GetStatus();
while(status==0x02)
{
                status = SPI_NAND_GetStatus();
        waitwend++;
        if(waitwend>0x10000)
        {
                break;
        }
}
}

    if(status == NAND_READY)
    {
      numpagewritten++;

      NumPageToWrite--;

      /* Calculate Next small page Address */
      addressstatus = SPI_NAND_AddressIncrement(&Address);   
    }
                else
                {
                        break;
                }
               
        }
        SPI_NAND_ClearProtected();
  return (status );
}
[/mw_shl_code]按手册上说明发送完这个之后应该是要自动清掉WEL,现在没清掉是说明没执行10h命令?

一周热门 更多>