/****************************************************************************** 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); }
/****************************************************************************** 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); }
/****************************************************************************** Function: void DRV_NVM_SST25VF064_Initialize( const SYS_MODULE_INIT * const init ) Summary: Initializes hardware and data for the given instance of the NVM module Description: This routine initializes hardware for the instance of the NVM module, using the hardware initialization given data. It also initializes all necessary internal data. Parameters: pInitData - Pointer to the data structure containing all data necessary to initialize the hardware. This pointer may be null if no data is required and static initialization values are to be used. Returns: None ******************************************************************************/ void DRV_NVM_SST25VF064_Initialize(DRV_SPI_INIT_DATA *pInitData) { // initialize the SPI channel to be used SPIINITIALIZE(pInitData); memcpy(&spiInitData, pInitData, sizeof(DRV_SPI_INIT_DATA)); }
/****************************************************************************** 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_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_ReadStatusRegister( void ) Summary: Reads the status register of the device. Description: This function reads the status register of the device. Parameters: None Returns: The current value of the status register. ******************************************************************************/ uint8_t DRV_NVM_SST25VF064_ReadStatusRegister(void) { uint8_t temp; while(!SPILOCK(spiInitData.channel)); SPIINITIALIZE((DRV_SPI_INIT_DATA *)&spiInitData); temp = ReadStatusRegister(); SPIUNLOCK(spiInitData.channel); return temp; }
/****************************************************************************** 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); }
/****************************************************************************** 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); }
/****************************************************************************** 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; }