本帖最后由 一号小鱼 于 2017-12-25 13:22 编辑
我的板子上用STM32F205驱动SPI FLASH W25M02G,现在可以正常读出flash 的ID,但是不能读写擦除,读了一下开机时候的寄存器值,如下图:
3个寄存器值
3个寄存器的解释
硬件上/WP接上拉。
问题1:SR1的Block Protect Bits (BP3, BP2, BP1, BP0, TB) 的这几个位开机就是1是正常的么?
问题2:我将这几个位清0后写入SR1,再回读是正常的0x00,但是进行一次读操作后又恢复到0x7C.这又是什么情况。
问题3:这种情况下,我对flash 进行ERASE,SR3得到的状态值0x04,
擦除失败?
问题4:如果是保护状态,按表说明,这个情况下FLASH应该是没有锁定的吧?我理解可有错?
大家帮忙看下
{
/*!< Enable the write access to the FLASH */
sFLASH_WriteEnable();
/*!< Select the FLASH: Chip Select low */
sFLASH_CS_LOW();
/*!< Send "Read Status Register" instruction */
sFLASH_SendByte(sFLASH_CMD_WRSR);
/*!< Send Status Register addr */
sFLASH_SendByte(sreg);
sFLASH_SendByte(buftype);
/*!< Deselect the FLASH: Chip Select high */
sFLASH_CS_HIGH();
}
[/mw_shl_code]
开机初始化完成之后必须把SR1的保护位都清0才可以进行后续操作。
谢谢,现在貌似是可以擦除了,不会报擦除跟写错误。但是现在写不进去,不报写错误,但是写完之后SR3-WEL没有自动归0,BUSY是清掉了的。
{
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();
//ÇD»»¿éÇø
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¾Y×°ÔØíê3éoó£¬D′èëò»ò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¾Y×°ÔØíê3éoó£¬D′èëò»ò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命令?
一周热门 更多>