Exemplo n.º 1
0
u16 SST25V_ReadManuID_DeviceID(u32 ReadManu_DeviceID_Addr)
{
  u16 ManuID_DeviceID = 0;
  u8 ManufacturerID = 0,  DeviceID = 0;
  SST25V_CS_LOW();
  SPI_Flash_SendByte(ReadDeviceID);
  
  SPI_Flash_SendByte((ReadManu_DeviceID_Addr & 0xFF0000) >> 16);
  SPI_Flash_SendByte((ReadManu_DeviceID_Addr & 0xFF00) >> 8);
  SPI_Flash_SendByte(ReadManu_DeviceID_Addr & 0xFF);
  
  if(ReadManu_DeviceID_Addr==1)
  {
    DeviceID = SPI_Flash_ReceiveByte();
    ManufacturerID = SPI_Flash_ReceiveByte();
  }
  else
  {
    ManufacturerID = SPI_Flash_ReceiveByte();
    DeviceID = SPI_Flash_ReceiveByte();
  }
  
  ManuID_DeviceID = ((ManufacturerID<<8) | DeviceID);
  SST25V_CS_HIGH();
  
  return ManuID_DeviceID;
}
Exemplo n.º 2
0
void SST25V_WriteStatusRegister(u8 Byte)
{
  SST25V_EnableWriteStatusRegister();
  SST25V_CS_LOW();
  SPI_Flash_SendByte(WriteStatusRegister);
  SPI_Flash_SendByte(Byte);
  SST25V_CS_HIGH();
}
Exemplo n.º 3
0
void Write_CMD(void)
{	
	Select_Flash();  			// SPI CS 使能
	SPI_Flash_SendByte(0x50);
	NotSelect_Flash(); 			// SPI CS 禁用
	
	Select_Flash();				// SPI CS 使能
	SPI_Flash_SendByte(0x01);
	SPI_Flash_SendByte(0x00); 
	NotSelect_Flash();			// SPI CS 禁用
	Busy_Test();				// 忙检测
}
Exemplo n.º 4
0
void Page_Clr(u32 a1)
{
	Write_CMD();
	Write_EN();     
	Select_Flash();	  
	SPI_Flash_SendByte(0x20);
	SPI_Flash_SendByte((a1&0xffffff)>>16);        
	SPI_Flash_SendByte((a1&0xffff)>>8);          
	SPI_Flash_SendByte(a1&0xff);            
	NotSelect_Flash();
	Busy_Test();
}
Exemplo n.º 5
0
void SST25V_BlockErase_64KByte(u32 Addr)
{
  SST25V_WriteEnable();
  SST25V_CS_LOW();
  SPI_Flash_SendByte(BlockErace_64KB);
  SPI_Flash_SendByte((Addr & 0xFF0000) >> 16);
  SPI_Flash_SendByte((Addr & 0xFF00) >> 8);
  SPI_Flash_SendByte(Addr & 0xFF);
  
  SST25V_CS_HIGH();
  SST25V_WaitForWriteEnd();
}
Exemplo n.º 6
0
void FlashPageEarse(u16 page)
{	
	FlashWaitBusy();	
	Select_Flash();
	SPI_Flash_SendByte(PAGE_ERASE);
	SPI_Flash_SendByte((u8)(page >> 6));
	SPI_Flash_SendByte((u8)(page << 2));
	SPI_Flash_SendByte(Dummy_Byte);
	//|-23-|-22-|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
	//|2个无关位|------------12位页地址-------------|----10个无关位-----|
	NotSelect_Flash();	
}
Exemplo n.º 7
0
void SST25V_ByteWrite(u8 Byte, u32 WriteAddr)
{
  SST25V_WriteEnable();
  SST25V_CS_LOW();
  SPI_Flash_SendByte(Byte_Program);
  SPI_Flash_SendByte((WriteAddr & 0xFF0000) >> 16);
  SPI_Flash_SendByte((WriteAddr & 0xFF00) >> 8);
  SPI_Flash_SendByte(WriteAddr & 0xFF);
  
  SPI_Flash_SendByte(Byte);
  SST25V_CS_HIGH();  
  SST25V_WaitForWriteEnd(); 
}
Exemplo n.º 8
0
u8 SST25V_ByteRead(u32 ReadAddr)
{
  u8 Temp = 0;
  SST25V_CS_LOW();
  SPI_Flash_SendByte(Read_Data);
  SPI_Flash_SendByte((ReadAddr & 0xFF0000) >> 16);
  SPI_Flash_SendByte((ReadAddr& 0xFF00) >> 8);
  SPI_Flash_SendByte(ReadAddr & 0xFF);
  
  Temp = SPI_Flash_ReceiveByte();
  SST25V_CS_HIGH();
  return Temp;
}
Exemplo n.º 9
0
void FlashReadID(void)
{
	Select_Flash();	
	
	SPI_Flash_SendByte(0x90);
	SPI_Flash_SendByte(0x00);
	SPI_Flash_SendByte(0x00);
	SPI_Flash_SendByte(0x00);
	fac_id = SPI_Flash_ReadByte();	// BFH: 工程码SST
	dev_id = SPI_Flash_ReadByte();	// 41H: 器件型号SST25VF016B     
	
	NotSelect_Flash();	
}
Exemplo n.º 10
0
void SST25V_WaitForWriteEnd(void)
{
  u8 FLASH_Status = 0;
  SST25V_CS_LOW();
  SPI_Flash_SendByte(ReadStatusRegister);
  do
  {
    FLASH_Status = SPI_Flash_SendByte(Dummy_Byte);

  } while((FLASH_Status & WriteStatusRegister) == SET);

  SST25V_CS_HIGH();
}
Exemplo n.º 11
0
void FlashPageWrite(u16 page,u8 *Data)		//写一整页,页范围0-4095
{
	unsigned int i;
	FlashWaitBusy();
	Select_Flash();
	SPI_Flash_SendByte(BUFFER_2_WRITE);
	SPI_Flash_SendByte(0x00);
	SPI_Flash_SendByte(0x00);
	SPI_Flash_SendByte(0x00);
	for (i = 0;i < 528; i++)
	{
		SPI_Flash_SendByte(Data[i]);
	}
	NotSelect_Flash();
		
	if ( page < 4096)
	{
		Select_Flash();
		SPI_Flash_SendByte(B2_TO_MM_PAGE_PROG_WITH_ERASE);
		SPI_Flash_SendByte((u8)(page>>6));
		SPI_Flash_SendByte((u8)(page<<2));
		SPI_Flash_SendByte(0x00);
		NotSelect_Flash();
		FlashWaitBusy();
	}	
Exemplo n.º 12
0
void SST25V_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead)
{
  SST25V_CS_LOW();
  SPI_Flash_SendByte(Read_Data);
  SPI_Flash_SendByte((ReadAddr & 0xFF0000) >> 16);
  SPI_Flash_SendByte((ReadAddr& 0xFF00) >> 8);
  SPI_Flash_SendByte(ReadAddr & 0xFF);

  while(NumByteToRead--)
  {
    *pBuffer = SPI_Flash_ReceiveByte();
    pBuffer++;
  }
  SST25V_CS_HIGH();
}
Exemplo n.º 13
0
void SST25V_WaitForWriteEnd(void)
{
  u8 FLASH_Status = 0;
  u32 count=0x80000;//0x250000;   
  
  SST25V_CS_LOW();
  SPI_Flash_SendByte(ReadStatusRegister);
  do
  {
    FLASH_Status = SPI_Flash_SendByte(Dummy_Byte);

  } while(((FLASH_Status & WriteStatusRegister) == SET)&& (--count)); 

  SST25V_CS_HIGH(); 
}
Exemplo n.º 14
0
void Write_DIS(void)
{
	Select_Flash();  			// SPI CS 使能
	SPI_Flash_SendByte(0x04);	// 写禁止指令
	NotSelect_Flash();			// SPI CS 禁用
	Busy_Test();				// 忙检测
}	
Exemplo n.º 15
0
void SST25_WriteFlash2(u32 addr, u8 *readbuff, u16 length)
{
	u32 i = 0;
		
	Write_CMD();
	Write_EN();	
	Select_Flash();    
	SPI_Flash_SendByte(0xad);
	SPI_Flash_SendByte((addr&0xffffff)>>16);
	SPI_Flash_SendByte((addr&0xffff)>>8);
	SPI_Flash_SendByte(addr&0xff);
	SPI_Flash_SendByte(readbuff[0]);
	SPI_Flash_SendByte(readbuff[1]);
	NotSelect_Flash();
	i = 2;
	
	while (i < length)
	{
		Select_Flash();
		SPI_Flash_SendByte(0xad);
		SPI_Flash_SendByte(readbuff[i++]);
		SPI_Flash_SendByte(readbuff[i++]);
		NotSelect_Flash();
	}

	Write_DIS();	
	
	Select_Flash();	
	
	Busy_Test();
}
Exemplo n.º 16
0
u8 SST25V_ReadStatusRegister(void)
{
  u8 StatusRegister = 0;
  SST25V_CS_LOW();
  SPI_Flash_SendByte(ReadStatusRegister);
  StatusRegister = SPI_Flash_ReceiveByte();
  SST25V_CS_HIGH();
  return StatusRegister;
}
Exemplo n.º 17
0
void SST25V_strWrite(u8 *p, u32 WriteAddr,u16 length)
{
  SST25V_WriteEnable();
  SST25V_CS_LOW();
  SPI_Flash_SendByte(Byte_Program);
  SPI_Flash_SendByte((WriteAddr & 0xFF0000) >> 16);
  SPI_Flash_SendByte((WriteAddr & 0xFF00) >> 8);
  SPI_Flash_SendByte(WriteAddr & 0xFF);
  while(length--)
    {  
       SPI_Flash_SendByte(*p); 
        p++;
    }
  
  
  SST25V_CS_HIGH();  
  SST25V_WaitForWriteEnd(); 
}
Exemplo n.º 18
0
void SST25V_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead)
{
     u32  timeout=50000;
   // note:  befor read  operation, please  check state
   while((SST25V_ReadStatusRegister()&0x01)&&(timeout--))       
   	   ;
  SST25V_CS_LOW();
  SPI_Flash_SendByte(Read_Data);
  SPI_Flash_SendByte((ReadAddr & 0xFF0000) >> 16);
  SPI_Flash_SendByte((ReadAddr& 0xFF00) >> 8);
  SPI_Flash_SendByte(ReadAddr & 0xFF);

  while(NumByteToRead--)
  {
    *pBuffer = SPI_Flash_ReceiveByte();
    pBuffer++;
  }
  SST25V_CS_HIGH();
}
Exemplo n.º 19
0
void SST25_ReadFlash(u32 addr, u8 *readbuff, u16 length)
{
	u32 i = 0; 
	
	Select_Flash();
	
	SPI_Flash_SendByte(0x0b);
	SPI_Flash_SendByte((addr&0xffffff)>>16);
	SPI_Flash_SendByte((addr&0xffff)>>8);
	SPI_Flash_SendByte(addr&0xff);
	SPI_Flash_SendByte(0);
	
	while (i < length)
	{	
		readbuff[i] = SPI_Flash_ReadByte();
		i++;
	}
	
	NotSelect_Flash();	 	
}
Exemplo n.º 20
0
void FlashReadID(u8 *Data)
{
	u8 i;
	Select_Flash();	
  	SPI_Flash_SendByte(0x9F);
  	for(i = 0; i < 4; i++)
  	{
  		Data[i] = SPI_Flash_ReadByte();
  	}
  	NotSelect_Flash();	
}
Exemplo n.º 21
0
u8 Read_CMD(void)
{
	u8 busy;
	
	Select_Flash();
	
	SPI_Flash_SendByte(0x05);
	busy = SPI_Flash_ReadByte();
	
	NotSelect_Flash();

	return (busy);
}
Exemplo n.º 22
0
void DF_init(void)
{
     u32 device_id=0;	

      SST25V_Init();    

     SST25V_CS_LOW();
     SPI_Flash_SendByte(WriteDisable);
     SST25V_CS_HIGH();

     SST25V_CS_LOW();

    //-----erase chip-------------------
    //	SST25V_ChipErase();  
    //	DF_delay_ms(350);      
    //--------------------------------	
	
     SPI_Flash_SendByte( ReadJedec_ID  );
    device_id  = SPI_Flash_SendByte(0xFF)<<16;
    device_id = device_id | SPI_Flash_SendByte(0xFF)<<8;
    device_id = device_id | SPI_Flash_SendByte(0xFF);	 
    SST25V_CS_HIGH();

    //if(device_id == 0xBF254A)//SST25VF032B = 0xBF254A,
    {
        rt_kprintf("FLASH TYPE : %x\r\n",device_id);  
        //rt_kprintf("FLASH:SST25VF032B\r\n"); 
        SST25V_CS_LOW();
        SPI_Flash_SendByte( DBSY );
        SST25V_CS_HIGH();

        SST25V_CS_LOW();
        SPI_Flash_SendByte( EnableWriteStatusRegister );
        SST25V_CS_HIGH();

        SST25V_CS_LOW();
        SPI_Flash_SendByte( WriteStatusRegister );
        SPI_Flash_SendByte( 0 );
        SST25V_CS_HIGH();
    }

    delay_ms(700); 

}
Exemplo n.º 23
0
void FlashPageRead(u16 page,u8 *Data)
{
	u16 i;	
	FlashWaitBusy();
	Select_Flash();
	SPI_Flash_SendByte(PAGE_READ);
	SPI_Flash_SendByte((u8)(page >> 6));
  SPI_Flash_SendByte((u8)(page << 2));
  SPI_Flash_SendByte(0x00);//3个字节
  SPI_Flash_SendByte(0x00);
  SPI_Flash_SendByte(0x00);
  SPI_Flash_SendByte(0x00);
  SPI_Flash_SendByte(0x00);
  for (i = 0;i < 528; i++)
	{
		Data[i] = SPI_Flash_ReadByte();
	}
	NotSelect_Flash();	
}
Exemplo n.º 24
0
void SST25_WriteFlash(u32 addr, u8 *readbuff, u16 length)
{
	u32 i = 0, a2;
	
 	Page_Clr(addr);	// 删除页		  
	
	Write_CMD();
	Write_EN();	
	Select_Flash();    
	SPI_Flash_SendByte(0xad);
	SPI_Flash_SendByte((addr&0xffffff)>>16);
	SPI_Flash_SendByte((addr&0xffff)>>8);
	SPI_Flash_SendByte(addr&0xff);
	SPI_Flash_SendByte(readbuff[0]);
	SPI_Flash_SendByte(readbuff[1]);
	NotSelect_Flash();
	i = 2;
	
	while (i < length)
	{
		a2 = 120;
		while (a2 > 0) 
			a2--;

		Select_Flash();
		SPI_Flash_SendByte(0xad);
		SPI_Flash_SendByte(readbuff[i++]);
		SPI_Flash_SendByte(readbuff[i++]);
		NotSelect_Flash();
	}

	a2 = 100;
	while (a2 > 0) 
		a2--;
	
	Write_DIS();	
	Select_Flash();	
	Busy_Test();
}
Exemplo n.º 25
0
/*******************************************************************************
* Function Name  : SPI_FLASH_ReadByte
* Description    : Reads a byte from the SPI Flash.
*                  This function must be used only if the Start_Read_Sequence
*                  function has been previously called.
* Input          : None
* Output         : None
* Return         : Byte Read from the SPI Flash.
*******************************************************************************/
u16 SPI_Flash_ReadByte(u8 a)
{
  return (SPI_Flash_SendByte(a));
}
Exemplo n.º 26
0
/*******************************************************************************
* Function Name  : SPI_FLASH_ReadByte
* Description    : Reads a byte from the SPI Flash.
*                  This function must be used only if the Start_Read_Sequence
*                  function has been previously called.
* Input          : None
* Output         : None
* Return         : Byte Read from the SPI Flash.
*******************************************************************************/
u8 SPI_Flash_ReadByte(void)
{
  return (SPI_Flash_SendByte(Dummy_Byte));
}
Exemplo n.º 27
0
void SST25V_DBSY(void)
{ 
  SST25V_CS_LOW();
  SPI_Flash_SendByte(DBSY);
  SST25V_CS_HIGH();
}
Exemplo n.º 28
0
void SST25V_WriteDisable(void)
{
  SST25V_CS_LOW();
  SPI_Flash_SendByte(WriteDisable);
  SST25V_CS_HIGH();
}
Exemplo n.º 29
0
void SST25V_EnableWriteStatusRegister(void)
{
  SST25V_CS_LOW();
  SPI_Flash_SendByte(EnableWriteStatusRegister);
  SST25V_CS_HIGH();
}
Exemplo n.º 30
0
void Write_EN(void)
{
	Select_Flash();				// SPI CS 使能
	SPI_Flash_SendByte(0x06);	// 写使能指令
	NotSelect_Flash();			// SPI CS 禁用
}