/******************************************************************************
  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);

}
Пример #2
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_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_M25P80_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_M25P80_WriteStatusRegister(0x00);

    while(!SPILOCK(spiInitData.channel));

    DRV_SPI_Initialize((DRV_SPI_INIT_DATA *)&spiInitData);

    DRV_NVM_M25P80_WriteEnable();

    DRV_NVM_M25P80_ChipSelectEnable();

    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_SER);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[0]);

    DRV_NVM_M25P80_ChipSelectDisable();

    SPIUNLOCK(spiInitData.channel);

    // Wait for write end
    while(DRV_NVM_M25P80_IsWriteBusy());
}
Пример #3
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_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_M25P80_WriteStatusRegister(uint8_t newStatus)
{

    while(!SPILOCK(spiInitData.channel));

    SPIINITIALIZE((DRV_SPI_INIT_DATA *)&spiInitData);

    // this is the sequence of the status register write
    // M25P80_CMD_WREN must be followed by SST25_CMD_WRSR
    DRV_NVM_M25P80_ChipSelectEnable();

    // send write enable command
    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_WREN);

    DRV_NVM_M25P80_ChipSelectDisable();

    DRV_NVM_M25P80_ChipSelectEnable();

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

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

    DRV_NVM_M25P80_ChipSelectDisable();

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

    SPIUNLOCK(spiInitData.channel);
}
/******************************************************************************
  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);
}
Пример #5
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_M25P80_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_M25P80_WriteEnable();

    // set up address
    DRV_NVM_M25P80_ChipSelectEnable();

    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_WRITE);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS)addr).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS)addr).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS)addr).uint8Address[0]);

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

    ret = 1;

#ifdef ENABLE_M25P80_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_M25P80_ReadByte(address))
        {
            ret = 0;
            break;
        }
        pData++;
        address++;
    }
#endif

    return (ret);

}
/******************************************************************************
  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;
    
    DRV_NVM_SST25_ChipSelectEnable();

    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);

    DRV_NVM_SST25_ChipSelectDisable();

    return (temp);
}
/******************************************************************************
  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);
}
Пример #8
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_ChipErase( )

  Summary:
    Erase the flash device.

  Description:
    This routine erases the whole memory of the flash device.

  Parameters:
    None

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

    while(!SPILOCK(spiInitData.channel));

    SPIINITIALIZE((DRV_SPI_INIT_DATA *)&spiInitData);

    // send write enable command
    DRV_NVM_M25P80_WriteEnable();

    DRV_NVM_M25P80_ChipSelectEnable();
    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_ERASE);
    DRV_NVM_M25P80_ChipSelectDisable();

    // wait for BULK ERASE to be done
    while(DRV_NVM_M25P80_CheckWriteInProgress() == 1);

    SPIUNLOCK(spiInitData.channel);

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

}
/******************************************************************************
  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());
}
Пример #10
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_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_M25P80_WriteByte(uint8_t data, uint32_t address)
{
    DRV_NVM_M25P80_WriteEnable();

    DRV_NVM_M25P80_ChipSelectEnable();

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

    DRV_NVM_M25P80_ChipSelectDisable();

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

}
Пример #11
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);
}
Пример #12
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_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_M25P80_Read(uint32_t address, uint8_t *pData, uint16_t nCount)
{
    while(!SPILOCK(spiInitData.channel));

    DRV_SPI_Initialize((DRV_SPI_INIT_DATA *)&spiInitData);

    DRV_NVM_M25P80_ChipSelectEnable();

    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_READ);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[2]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[1]);
    PUTSPIBYTE(spiInitData.channel, ((M25P80_ADDRESS) address).uint8Address[0]);

    DRV_SPI_GetBuffer(spiInitData.channel, pData, nCount);

    DRV_NVM_M25P80_ChipSelectDisable();
    SPIUNLOCK(spiInitData.channel);
}
Пример #13
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;

}
/******************************************************************************
  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;

    DRV_NVM_SST25_ChipSelectEnable();

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

    DRV_NVM_SST25_ChipSelectDisable();
    
    return temp;

}
Пример #15
0
/******************************************************************************
  Function:
    uint8_t DRV_NVM_M25P80_CheckWriteInProgress(void)

  Summary:
    Checks the Write In Progress device status.

  Description:
    This routine is internal to this module. This reads the status register of
	the device to check the Write in Progress status bit.

  Parameters:
    None

  Returns:
    1 - if the device's WIP status bit is set
	0 - if the device's WIP status bit is not set
******************************************************************************/
uint8_t DRV_NVM_M25P80_CheckWriteInProgress(void)
{
    uint8_t status;

    // check status of Write in Progress
    DRV_NVM_M25P80_ChipSelectEnable();
    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_RDSR);
    GETSPIBYTE((spiInitData.channel)& M25P80_WIP_STATUS, status);
    DRV_NVM_M25P80_ChipSelectDisable();
    if ((status & M25P80_WIP_STATUS) == 0)
        return 0;
    else
        return 1;

}
Пример #16
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_ReadIDRegister( void )

  Summary:
    Reads the ID register of the device.

  Description:
    This function reads the ID of the device.

  Parameters:
    Pointer to the buffer for the device ID information.

  Returns:
    None
******************************************************************************/
void DRV_NVM_M25P80_ReadIDRegister(uint8_t* pBuffer)
{
    uint8_t     deviceUniqueIDLen = 21;

    while(!SPILOCK(spiInitData.channel));

    SPIINITIALIZE((DRV_SPI_INIT_DATA *)&spiInitData);

    DRV_NVM_M25P80_ChipSelectEnable();
    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_RDID);

    while(deviceUniqueIDLen)
    {
        deviceUniqueIDLen--;
        GETSPIBYTE(spiInitData.channel, *pBuffer++);
    }

    DRV_NVM_M25P80_ChipSelectDisable();

    SPIUNLOCK(spiInitData.channel);

}
Пример #17
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;
}
Пример #18
0
/******************************************************************************
  Function:
    void DRV_NVM_M25P80_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_M25P80_WriteEnable(void)
{
    DRV_NVM_M25P80_ChipSelectEnable();
    PUTSPIBYTE(spiInitData.channel, M25P80_CMD_WREN);
    DRV_NVM_M25P80_ChipSelectDisable();
}
/******************************************************************************
  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)
{
    DRV_NVM_SST25_ChipSelectEnable();
    PUTSPIBYTE(spiInitData.channel, SST25_CMD_WREN);
    DRV_NVM_SST25_ChipSelectDisable();
}
Пример #20
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();
}