diff --git a/XilinxProcessorIPLib/drivers/spips/examples/xspips_flash_intr_example.c b/XilinxProcessorIPLib/drivers/spips/examples/xspips_flash_intr_example.c index fee8c292..5cce6f78 100644 --- a/XilinxProcessorIPLib/drivers/spips/examples/xspips_flash_intr_example.c +++ b/XilinxProcessorIPLib/drivers/spips/examples/xspips_flash_intr_example.c @@ -88,8 +88,16 @@ #define WRITE_ENABLE_CMD 0x06 #define FAST_READ_CMD 0x0B #define CHIP_ERASE_CMD 0x60 +#define BULK_ERASE_CMD 0xC7 #define BLOCK_ERASE_64K_CMD 0xD8 #define READ_ID 0x90 +#define SST_READ_ID 0x9F + +/* Global Block-Protection Unlock register */ +#define GLOBAL_BLK_PROT_UNLK 0x98 + +/* All SST flash parts have ID 0xBF */ +#define SST_FLASH_ID 0xBF /* * The following constants define the offsets within a FlashBuffer data @@ -106,6 +114,9 @@ #define DUMMY_SIZE 1 /* Number of dummy bytes for fast read */ #define RD_ID_SIZE 4 /* Read ID command + 3 bytes ID response */ +/* Flag stating sst flash or not */ +static int is_sst; + /* * The following constants specify the extra bytes which are sent to the @@ -155,6 +166,8 @@ static int FlashReadID(XSpiPs *SpiInstance); int SpiPsFlashIntrExample(XScuGic *IntcInstancePtr, XSpiPs *SpiInstancePtr, u16 SpiDeviceId, u16 SpiIntrId); +static int SST_GlobalBlkProtectUnlk(XSpiPs *SpiInstancePtr); + /************************** Variable Definitions *****************************/ /* @@ -352,6 +365,15 @@ int SpiPsFlashIntrExample(XScuGic *IntcInstancePtr, XSpiPs *SpiInstancePtr, return XST_FAILURE; } + if (is_sst == 1) { + /* Unlock the Global Block-Protection Unlock register bits */ + SST_GlobalBlkProtectUnlk(SpiInstancePtr); + if (Status != XST_SUCCESS) { + xil_printf("SPI Flash Interrupt Example Read ID Failed\r\n"); + return XST_FAILURE; + } + } + /* * Erase the flash */ @@ -638,6 +660,37 @@ static void FlashRead(XSpiPs *SpiPtr, u32 Address, u32 ByteCount, u8 Command) while (TransferInProgress); } +/****************************************************************************** +* +* This function Unlocks the Global Block-Protection Unlock register bits. +* +* @param None. +* +* @return +* - XST_SUCCESS if successful +* - XST_FAILURE if not successful +* +* @note None. +* +******************************************************************************/ +static int SST_GlobalBlkProtectUnlk(XSpiPs *SpiInstancePtr) +{ + int Status; + u8 WriteEnable[] = { WRITE_ENABLE_CMD }; + u8 ulbpr[] = { GLOBAL_BLK_PROT_UNLK }; + + /* send wite enable */ + Status = XSpiPs_PolledTransfer(SpiInstancePtr, WriteEnable, NULL,sizeof(WriteEnable)); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + /* Unlock the Global Block-Protection Unlock register bits */ + Status = XSpiPs_PolledTransfer(SpiInstancePtr, ulbpr, NULL, sizeof(ulbpr)); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + return XST_SUCCESS; +} /****************************************************************************** * @@ -675,6 +728,20 @@ static int FlashReadID(XSpiPs *SpiInstance) while (TransferInProgress); + if ((RecvBuffer[4] == 0xff) || (RecvBuffer[4] == 0x00)) { + /* Use SST_READ_ID(0x9f) for reading id*/ + SendBuffer[0] = SST_READ_ID; + XSpiPs_PolledTransfer(SpiInstance, SendBuffer, RecvBuffer, + (4 + ByteCount)); + + while (TransferInProgress); + + if (RecvBuffer[4] == SST_FLASH_ID) { + /* SST flash part */ + is_sst = 1; + } + } + for(Index=0; Index < ByteCount; Index++) { xil_printf("ID : %0x\r\n", RecvBuffer[4 + Index]); } @@ -843,7 +910,11 @@ static void FlashErase(XSpiPs *SpiPtr) /* * Setup the bulk erase or chip-erase command */ - WriteBuffer[COMMAND_OFFSET] = CHIP_ERASE_CMD; + if (is_sst == 0) { + WriteBuffer[COMMAND_OFFSET] = CHIP_ERASE_CMD; + } else { + WriteBuffer[COMMAND_OFFSET] = BULK_ERASE_CMD; + } /* * Send the bulk erase command; no receive buffer is specified