Ejemplo n.º 1
0
/******************************************************************************
  Function:
    void DRV_NVM_SST25VF064_WriteStatusRegister(uint8_t newStatus)

  Summary:
    Programs the status register.
    
  Description:
    This routine programs the status register of the flash device
    with the new value specified by newStatus. Only bits that are
    actuall writable will be modified.

  Parameters:
    newStatus - the new status that will be used.

  Returns:
    None
******************************************************************************/
void DRV_NVM_SST25VF064_WriteStatusRegister(uint8_t newStatus)
{

    while(!SPILOCK(spiInitData.channel));
    
    SPIINITIALIZE((DRV_SPI_INIT_DATA *)&spiInitData);

    // this is the sequence of the status register write
    // SST25_CMD_EWSR must be followed by SST25_CMD_WRSR
    SST25CSLow();
    
    // send write enable command
    PUTSPIBYTE(spiInitData.channel, SST25_CMD_EWSR);
	
    SST25CSHigh();

    SST25CSLow();

    // send write status register command
    PUTSPIBYTE(spiInitData.channel, SST25_CMD_WRSR);

    // program the new status bits
    PUTSPIBYTE(spiInitData.channel, newStatus);

    SST25CSHigh();

    // Wait for write end
    while(DRV_NVM_SST25VF064_IsWriteBusy());

    SPIUNLOCK(spiInitData.channel);
}
Ejemplo n.º 2
0
/******************************************************************************
  Function:
    uint8_t DRV_NVM_SST25VF064_WriteSector( uint32_t address,
                                            uint8_t *pData,
                                            uint16_t nCount )

  Summary:
    Performs the sector write of the SPI flash device.

  Description:
    This routine is internal to this module. This is called by the
    DRV_NVM_SST25VF064_Write() function to perform the actual
    programming.

  Parameters:
    address - starting address of the array to be written
    pData   - pointer to the source of the array
    nCount  - specifies the number of bytes to be written

  Returns:
    1 - if the write is successful
    0 - if the write was not successful 
******************************************************************************/
uint8_t DRV_NVM_SST25VF064_WriteSector(uint32_t address, uint8_t *pData, uint16_t nCount)
{
    uint32_t    addr;
    uint8_t     *pD;
    uint16_t    counter, ret;

    addr = address;
    pD = pData;

    // do a write enable first
    DRV_NVM_SST25VF064_WriteEnable();

    // set up address
    SST25CSLow();

    PUTSPIBYTE(spiInitData.channel, SST25_CMD_WRITE);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)addr).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)addr).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)addr).uint8Address[0]);

    for (counter = 0; counter < nCount; counter++)
    {
        PUTSPIBYTE(spiInitData.channel, *pD);
        pD++;
    }
    SST25CSHigh();
    // check status of the page write
    while(DRV_NVM_SST25VF064_IsWriteBusy());

    // Write Disable
    SST25CSLow();

    PUTSPIBYTE(spiInitData.channel, SST25_CMD_WRDI);

    SST25CSHigh();

    ret = 1;

#ifdef ENABLE_SST25VF064_WRITE_VERIFICATION
    // Since data verification takes time,
    // this code is disabled by default
    // to have faster programming time
    for(counter = 0; counter < nCount; counter++)
    {
        if(*pData != DRV_NVM_SST25VF064_ReadByte(address))
        {
            ret = 0;
            break;
        }
        pData++;
        address++;
    }
#endif

    return (ret);

}
Ejemplo n.º 3
0
/************************************************************************
* Function: void SST25ResetWriteProtection()
*                                                                       
* Overview: this function reset write protection bits
*                                                                       
* Input: none                                                     
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void SST25ResetWriteProtection(void)
{
#if defined(USE_M25P80)    
    BYTE status;
#endif

    while(!SPILock(spiInitData.channel))
        ;
    
    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();
    
    // send write enable command
    SPIPut(spiInitData.channel, SST25_CMD_EWSR);
    SPIGet(spiInitData.channel);
	
    SST25CSHigh();
	
#if defined(USE_M25P80)    
    SST25CSLow();
    // verify if the WEL bit is set high
    while(1)
    {
        SPIPut(spiInitData.channel, SST25_CMD_RDSR);
        SPIGet(spiInitData.channel);

        status = 0xFF;
        while((status & SST25_STATUS_MASK) > 0)
        {
            SPIPut(spiInitData.channel, 0);
            status = SPIGet(spiInitData.channel);
        }
        if ((status & SST25_WEL_STATUS) == SST25_WEL_STATUS)
            break;
    }
    SST25CSHigh();
#endif


    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_WRSR);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, 0);
    SPIGet(spiInitData.channel);

    SST25CSHigh();
    SPIUnLock(spiInitData.channel);

    // Wait for write end
    while(SST25IsWriteBusy());
}
Ejemplo n.º 4
0
/************************************************************************
* Function: void SST25ResetWriteProtection()
*                                                                       
* Overview: this function reset write protection bits
*                                                                       
* Input: none                                                     
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void SST25ResetWriteProtection(void)
{
#if defined(USE_M25P80)    
    uint8_t status;
#endif

 //   while(!SPILock(spiInitData.spiId));
   
    SST25CSLow();
    
    // send write enable command
    SPIPut(spiInitData.spiId, SST25_CMD_EWSR);
    PLIB_SPI_BufferRead(spiInitData.spiId);
	
    SST25CSHigh();
	
#if defined(USE_M25P80)    
    SST25CSLow();
    // verify if the WEL bit is set high
    while(1)
    {
        SPIPut(spiInitData.spiId, SST25_CMD_RDSR);
        SPIGet(spiInitData.spiId);

        status = 0xFF;
        while((status & SST25_STATUS_MASK) > 0)
        {
            SPIPut(spiInitData.spiId, 0);
            status = SPIGet(spiInitData.spiId);
        }
        if ((status & SST25_WEL_STATUS) == SST25_WEL_STATUS)
            break;
    }
    SST25CSHigh();
#endif


    SST25CSLow();

    SPIPut(spiInitData.spiId, SST25_CMD_WRSR);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, 0);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SST25CSHigh();
 //   SPIUnLock(spiInitData.spiId);

    // Wait for write end
    while(SST25IsWriteBusy());
}
Ejemplo n.º 5
0
/************************************************************************
* Function: void SST25ReadArray(DWORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function reads data into buffer specified
*                                                                       
* Input: flash memory address, pointer to the data buffer, data number
*                                                                       
************************************************************************/
void SST25ReadArray(uint32_t address, uint8_t *pData, uint16_t nCount)
{

    SST25CSLow();

    SPIPut(spiInitData.spiId, SST25_CMD_READ);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address>>16);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address>>8);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    while(nCount--)
    {
        SPIPut(spiInitData.spiId, 0);
        *pData++ = PLIB_SPI_BufferRead(spiInitData.spiId);
    }

    SST25CSHigh();

}
Ejemplo n.º 6
0
/************************************************************************
* Function: void SST25SectorErase(DWORD address)                                           
*                                                                       
* Overview: this function erases a 4Kb sector
*                                                                       
* Input: address within sector to be erased
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void SST25SectorErase(DWORD address)
{
    SST25WriteEnable();
    
    while(!SPILock(spiInitData.channel))
        ;

    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_SER);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[2]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[1]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[0]);
    SPIGet(spiInitData.channel);

    SST25CSHigh();
    SPIUnLock(spiInitData.channel);

    // Wait for write end
    while(SST25IsWriteBusy());
}
Ejemplo n.º 7
0
/************************************************************************
* Function: void SST25SectorErase(DWORD address)                                           
*                                                                       
* Overview: this function erases a 4Kb sector
*                                                                       
* Input: address within sector to be erased
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void SST25SectorErase(uint32_t address)
{
    SST25WriteEnable();
    
 //   while(!SPILock(spiInitData.spiId));

    SST25CSLow();

    SPIPut(spiInitData.spiId, SST25_CMD_SER);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address>>16);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address>>8);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SST25CSHigh();
 //   SPIUnLock(spiInitData.spiId);

    // Wait for write end
    while(SST25IsWriteBusy());
}
Ejemplo n.º 8
0
/******************************************************************************
  Function:
    void DRV_NVM_SST25VF064_SectorErase( uint32_t address )

  Summary:
    Erase the sector specified by the given address.
    
  Description:
    This routine erases the sector of where the given address resides.
    
  Parameters:
    None

  Returns:
    None
******************************************************************************/
void DRV_NVM_SST25VF064_SectorErase(uint32_t address)
{
    // Note: This sector erase do not check for block protection (BP [3:0]).
    //       This function undo the block protection and erases
    //       the sector of the given address.
    DRV_NVM_SST25VF064_WriteStatusRegister(0x00);
    
    while(!SPILOCK(spiInitData.channel));

    SPIINITIALIZE((DRV_SPI_INIT_DATA *)&spiInitData);

    DRV_NVM_SST25VF064_WriteEnable();

    SST25CSLow();

    PUTSPIBYTE(spiInitData.channel, SST25_CMD_SER);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[0]);

    SST25CSHigh();
    
    // Wait for write end
    while(DRV_NVM_SST25VF064_IsWriteBusy());

    SPIUNLOCK(spiInitData.channel);

}
Ejemplo n.º 9
0
/************************************************************************
* Function: void SST25WriteByte(BYTE data, DWORD address)                                           
*                                                                       
* Overview: this function writes a byte to the address specified
*                                                                       
* Input: data to be written and address
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void SST25WriteByte(uint8_t data, uint32_t address)
{
    SST25WriteEnable();

    SST25CSLow();

    SPIPut(spiInitData.spiId, SST25_CMD_WRITE);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address>>16);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address>>8);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, data);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SST25CSHigh();

    // Wait for write end
    while(SST25IsWriteBusy());
}
Ejemplo n.º 10
0
/************************************************************************
* Function: void SST25ReadArray(DWORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function reads data into buffer specified
*                                                                       
* Input: flash memory address, pointer to the data buffer, data number
*                                                                       
************************************************************************/
void SST25ReadArray(DWORD address, BYTE *pData, WORD nCount)
{
    while(!SPILock(spiInitData.channel))
        ;

    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_READ);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[2]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[1]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[0]);
    SPIGet(spiInitData.channel);

    while(nCount--)
    {
        SPIPut(spiInitData.channel, 0);
        *pData++ = SPIGet(spiInitData.channel);
    }

    SST25CSHigh();
    SPIUnLock(spiInitData.channel);
}
Ejemplo n.º 11
0
/************************************************************************
* Function: BYTE SST25ReadByte(DWORD address)             
*                                                                       
* Overview: this function reads a byte from the address specified         
*                                                                       
* Input: address                                                     
*                                                                       
* Output: data read
*                                                                       
************************************************************************/
BYTE SST25ReadByte(DWORD address)
{
    BYTE    temp;
    
    while(!SPILock(spiInitData.channel))
        ;
    
    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_READ);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[2]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[1]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, ((DWORD_VAL) address).v[0]);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, 0);
    temp = SPIGet(spiInitData.channel);

    SST25CSHigh();

    SPIUnLock(spiInitData.channel);

    return (temp);
}
Ejemplo n.º 12
0
/************************************************************************
* Function: BYTE SST25ReadByte(DWORD address)             
*                                                                       
* Overview: this function reads a byte from the address specified         
*                                                                       
* Input: address                                                     
*                                                                       
* Output: data read
*                                                                       
************************************************************************/
uint8_t SST25ReadByte(uint32_t address)
{
    uint8_t    temp;
    
    SST25CSLow();

    SPIPut(spiInitData.spiId, SST25_CMD_READ);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address>>16);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address>>8);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, address);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, 0);
    temp = PLIB_SPI_BufferRead(spiInitData.spiId);

    SST25CSHigh();

    return (temp);
}
Ejemplo n.º 13
0
/************************************************************************
* Function: SST25WriteEnable()                                         
*                                                                       
* Overview: this function allows write/erase SST25. Must be called  
* before every write/erase command.                                         
*                                                                       
* Input: none                                                          
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void SST25WriteEnable(void)
{

    SST25CSLow();
    SPIPut(spiInitData.spiId, SST25_CMD_WREN);
    PLIB_SPI_BufferRead(spiInitData.spiId);
    SST25CSHigh();

}
Ejemplo n.º 14
0
/************************************************************************
* Function: SST25WriteEnable()                                         
*                                                                       
* Overview: this function allows write/erase SST25. Must be called  
* before every write/erase command.                                         
*                                                                       
* Input: none                                                          
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void SST25WriteEnable(void)
{
    while(!SPILock(spiInitData.channel))
        ;
    
    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();
    SPIPut(spiInitData.channel, SST25_CMD_WREN);
    SPIGet(spiInitData.channel);
    SST25CSHigh();
    SPIUnLock(spiInitData.channel);
}
Ejemplo n.º 15
0
/******************************************************************************
  Function:
    static inline __attribute__((__always_inline__)) uint8_t ReadStatusRegister(void)

  Summary:
    Reads the status register of the device.

  Description:
    This is an internal inline function called within the module to
    read the status register of the device.

  Parameters:
    None

  Returns:
    Returns a byte indicating the status of the device.
******************************************************************************/
static inline __attribute__((__always_inline__)) uint8_t ReadStatusRegister(void)
{
    uint8_t    temp;

    SST25CSLow();

    PUTSPIBYTE(spiInitData.channel, SST25_CMD_RDSR);
    GETSPIBYTE(spiInitData.channel, temp);

    SST25CSHigh();
    
    return temp;

}
Ejemplo n.º 16
0
/************************************************************************
* Function: BYTE SST25IsWriteBusy(void)  
*                                                                       
* Overview: this function reads status register and chek BUSY bit for write operation
*                                                                       
* Input: none                                                          
*                                                                       
* Output: non zero if busy
*                                                                       
************************************************************************/
uint8_t SST25IsWriteBusy(void)
{
    uint8_t    temp;

    SST25CSLow();
    SPIPut(spiInitData.spiId, SST25_CMD_RDSR);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SPIPut(spiInitData.spiId, 0);
    temp = PLIB_SPI_BufferRead(spiInitData.spiId);
    SST25CSHigh();

    return (temp & 0x01);
}
Ejemplo n.º 17
0
/************************************************************************
* Function: BYTE SST25WriteArray(DWORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function writes a data array at the address specified
*                                                                       
* Input: flash memory address, pointer to the data array, data number
*                                                                       
* Output: return 1 if the operation was successfull
*                                                                     
************************************************************************/
BYTE SST25WriteArray(DWORD address, BYTE *pData, WORD nCount)
{
    DWORD   addr;
    BYTE    *pD;
    WORD    counter;
#if defined(USE_M25P80)    
    BYTE status;
#endif

    addr = address;
    pD = pData;

    // WRITE
    for(counter = 0; counter < nCount; counter++)
    {
        SST25WriteByte(*pD++, addr++);
    }

#if defined(USE_M25P80)

    // check status of Write in Progress
    // wait for BULK ERASE to be done
    SST25CSLow();
    SPIPut(spiInitData.channel, SST25_CMD_RDSR);
    SPIGet(spiInitData.channel);
    while(1)
    {
        SPIPut(spiInitData.channel, 0);
        status = (SPIGet(spiInitData.channel)& SST25_WIP_STATUS);
        if ((status & SST25_WIP_STATUS) == 0)
            break;
    }

    SST25CSHigh();
	
#endif

    // VERIFY
    for(counter = 0; counter < nCount; counter++)
    {
        if(*pData != SST25ReadByte(address))
            return (0);
        pData++;
        address++;
    }

    return (1);
}
Ejemplo n.º 18
0
/************************************************************************
* Function: BYTE SST25WriteArray(DWORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function writes a data array at the address specified
*                                                                       
* Input: flash memory address, pointer to the data array, data number
*                                                                       
* Output: return 1 if the operation was successfull
*                                                                     
************************************************************************/
uint8_t SST25WriteArray(uint32_t address, uint8_t *pData, uint16_t nCount)
{
    uint32_t   addr;
    uint8_t    *pD;
    uint16_t    counter;
#if defined(USE_M25P80)    
    uint8_t status;
#endif

    addr = address;
    pD = pData;

    // WRITE
    for(counter = 0; counter < nCount; counter++)
    {
        SST25WriteByte(*pD++, addr++);
    }

#if defined(USE_M25P80)

    // check status of Write in Progress
    // wait for BULK ERASE to be done
    SST25CSLow();
    SPIPut(spiInitData.spiId, SST25_CMD_RDSR);
    SPIGet(spiInitData.spiId);
    while(1)
    {
        SPIPut(spiInitData.spiId, 0);
        status = (SPIGet(spiInitData.spiId)& SST25_WIP_STATUS);
        if ((status & SST25_WIP_STATUS) == 0)
            break;
    }

    SST25CSHigh();
	
#endif

    // VERIFY
    for(counter = 0; counter < nCount; counter++)
    {
        if(*pData != SST25ReadByte(address))
            return (0);
        pData++;
        address++;
    }

    return (1);
}
Ejemplo n.º 19
0
/******************************************************************************
  Function:
    uint8_t DRV_NVM_SST25VF064_ReadByte( uint32_t address )

  Summary:
    Reads a byte from the specified address.
    
  Description:
    This routine is internal to this module. This reads a a byte from the  
    given address. 

  Parameters:
    address - location byte to be read

  Returns:
    read byte 
******************************************************************************/
uint8_t DRV_NVM_SST25VF064_ReadByte(uint32_t address)
{
    uint8_t temp;
    
    SST25CSLow();

    PUTSPIBYTE(spiInitData.channel, SST25_CMD_READ);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[0]);
    GETSPIBYTE(spiInitData.channel, temp);

    SST25CSHigh();

    return (temp);
}
Ejemplo n.º 20
0
/******************************************************************************
  Function:
    void DRV_NVM_SST25VF064_WriteByte( uint8_t data,
                                       uint32_t address )

  Summary:
    Writes a byte to the specified address.
    
  Description:
    This routine is internal to this module. This writes a byte to the 
    given address. 

  Parameters:
    data    - byte to be written
    address - location of the programmed byte

  Returns:
    None.
******************************************************************************/
void DRV_NVM_SST25VF064_WriteByte(uint8_t data, uint32_t address)
{
    DRV_NVM_SST25VF064_WriteEnable();

    SST25CSLow();

    PUTSPIBYTE(spiInitData.channel, SST25_CMD_WRITE);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[0]);
    PUTSPIBYTE(spiInitData.channel, data);

    SST25CSHigh();

    // Wait for write end
    while(DRV_NVM_SST25VF064_IsWriteBusy());
}
Ejemplo n.º 21
0
/******************************************************************************
  Function:
    void DRV_NVM_SST25VF064_Read(   uint32_t address,
                                    uint8_t *pData, 
                                    uint16_t nCount )

  Summary:
    Reads an array of bytes from the specified address.
    
  Description:
    This routine reads an array of bytes from the specified address location. The
    read array is saved to the location pointed to by pData. The number of bytes 
    to be read is specified by nCount.

  Parameters:
    address - starting address of the array to be read
    pData   - pointer to the destination of the read array
    nCount  - specifies the number of bytes to be read

  Returns:
    None
******************************************************************************/
void DRV_NVM_SST25VF064_Read(uint32_t address, uint8_t *pData, uint16_t nCount)
{
    while(!SPILOCK(spiInitData.channel));

    SPIINITIALIZE((DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();

    PUTSPIBYTE(spiInitData.channel, SST25_CMD_READ);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((SST25_ADDRESS)address).uint8Address[0]);  

    DRV_SPI_GetBuffer(spiInitData.channel, pData, nCount);

    SST25CSHigh();
    SPIUNLOCK(spiInitData.channel);
}
Ejemplo n.º 22
0
/************************************************************************
* Function: BYTE SST25IsWriteBusy(void)  
*                                                                       
* Overview: this function reads status register and chek BUSY bit for write operation
*                                                                       
* Input: none                                                          
*                                                                       
* Output: non zero if busy
*                                                                       
************************************************************************/
BYTE SST25IsWriteBusy(void)
{
    BYTE    temp;

    while(!SPILock(spiInitData.channel))
        ;

    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);

    SST25CSLow();
    SPIPut(spiInitData.channel, SST25_CMD_RDSR);
    SPIGet(spiInitData.channel);

    SPIPut(spiInitData.channel, 0);
    temp = SPIGet(spiInitData.channel);
    SST25CSHigh();
    SPIUnLock(spiInitData.channel);

    return (temp & 0x01);
}
Ejemplo n.º 23
0
/******************************************************************************
  Function:
    void DRV_NVM_SST25VF064_ChipErase( )

  Summary:
    Erase the flash device.
    
  Description:
    This routine erases the whole memory of the flash device.
    
  Parameters:
    None

  Returns:
    None
 ******************************************************************************/
void DRV_NVM_SST25VF064_ChipErase(void)
{
    // reset the BPL bits to be non-write protected, in case they are
    // write protected
    DRV_NVM_SST25VF064_WriteStatusRegister(0x00);

    while(!SPILOCK(spiInitData.channel));
    SPIINITIALIZE((DRV_SPI_INIT_DATA *)&spiInitData);

    DRV_NVM_SST25VF064_WriteEnable();

    SST25CSLow();

    PUTSPIBYTE(spiInitData.channel, SST25_CMD_ERASE);

    SST25CSHigh();

    // Wait for write end
    while(DRV_NVM_SST25VF064_IsWriteBusy());

    SPIUNLOCK(spiInitData.channel);

    return;
}
Ejemplo n.º 24
0
/************************************************************************
* Function: void SST25ChipErase(void)
*                                                                       
* Overview: chip erase
*                                                                       
* Input: none
*                                                                       
************************************************************************/
void SST25ChipErase(void)
{
#if defined(USE_M25P80)    
    BYTE status;
#endif

#if defined(USE_SST25VF016)
    SST25WriteEnable();
#endif

    while(!SPILock(spiInitData.channel))
        ;

    DRV_SPI_Initialize(spiInitData.channel, (DRV_SPI_INIT_DATA *)&spiInitData);
    SST25CSLow();
#if defined(USE_M25P80)    
    // send write enable command
    SPIPut(spiInitData.channel, SST25_CMD_EWSR);
    SPIGet(spiInitData.channel);

    SST25CSHigh();
    Nop();
    SST25CSLow();

    // verify if the WEL bit is set high
    while(1)
    {
        SPIPut(spiInitData.channel, SST25_CMD_RDSR);
        SPIGet(spiInitData.channel);
        status = 0xFF;
        while((status & SST25_STATUS_MASK) > 0)
        {
            SPIPut(spiInitData.channel, 0);
            status = SPIGet(spiInitData.channel);
        }
        if ((status & SST25_WEL_STATUS) == SST25_WEL_STATUS)
            break;
    }
    SST25CSHigh();
#endif

    SST25CSLow();

    SPIPut(spiInitData.channel, SST25_CMD_ERASE);
    SPIGet(spiInitData.channel);

    SST25CSHigh();

#if defined (USE_M25P80)
    // wait for BULK ERASE to be done
    SST25CSLow();
    SPIPut(spiInitData.channel, SST25_CMD_RDSR);
    SPIGet(spiInitData.channel);
    while(1)
    {
        SPIPut(spiInitData.channel, 0);
        status = (SPIGet(spiInitData.channel)& SST25_WIP_STATUS);
        if ((status & SST25_WIP_STATUS) == 0)
            break;
    }

    SST25CSHigh();
#endif
    SPIUnLock(spiInitData.channel);
    
    // Wait for write end
    while(SST25IsWriteBusy());
}
Ejemplo n.º 25
0
/************************************************************************
* Function: void SST25ChipErase(void)
*                                                                       
* Overview: chip erase
*                                                                       
* Input: none
*                                                                       
************************************************************************/
void SST25ChipErase(void)
{
#if defined(USE_M25P80)    
    uint8_t status;
#endif

#if defined(USE_SST25VF016)
    SST25WriteEnable();
#endif

 //   while(!SPILock(spiInitData.spiId));

    SST25CSLow();

#if defined(USE_M25P80)    
    // send write enable command
    SPIPut(spiInitData.spiId, SST25_CMD_EWSR);
    SPIGet(spiInitData.spiId);

    SST25CSHigh();
    Nop();
    SST25CSLow();

    // verify if the WEL bit is set high
    while(1)
    {
        SPIPut(spiInitData.spiId, SST25_CMD_RDSR);
        SPIGet(spiInitData.spiId);
        status = 0xFF;
        while((status & SST25_STATUS_MASK) > 0)
        {
            SPIPut(spiInitData.spiId, 0);
            status = SPIGet(spiInitData.spiId);
        }
        if ((status & SST25_WEL_STATUS) == SST25_WEL_STATUS)
            break;
    }
    SST25CSHigh();
#endif

    SST25CSLow();

    SPIPut(spiInitData.spiId, SST25_CMD_ERASE);
    PLIB_SPI_BufferRead(spiInitData.spiId);

    SST25CSHigh();

#if defined (USE_M25P80)
    // wait for BULK ERASE to be done
    SST25CSLow();
    SPIPut(spiInitData.spiId, SST25_CMD_RDSR);
    SPIGet(spiInitData.spiId);
    while(1)
    {
        SPIPut(spiInitData.spiId, 0);
        status = (SPIGet(spiInitData.spiId)& SST25_WIP_STATUS);
        if ((status & SST25_WIP_STATUS) == 0)
            break;
    }

    SST25CSHigh();
#endif
 //   SPIUnLock(spiInitData.spiId);
    
    // Wait for write end
    while(SST25IsWriteBusy());
}
Ejemplo n.º 26
0
/******************************************************************************
  Function:
    void DRV_NVM_SST25VF064_WriteEnable( void )
    
  Summary:
    Enables the device for writes. 
    
  Description:
    This is an internal function called within the module to enable the 
    device for writes.
    
  Parameters:
    None

  Returns:
    None
******************************************************************************/
void DRV_NVM_SST25VF064_WriteEnable(void)
{
    SST25CSLow();
    PUTSPIBYTE(spiInitData.channel, SST25_CMD_WREN);
    SST25CSHigh();
}