26 static volatile uint16_t *flashBase;
27 static bool flashInitialized =
false;
30 static int flashInterrogate(
void);
31 static int flashPoll(uint32_t addr, uint16_t data);
32 static void flashReset(
void);
33 static void flashUnlockCmd(
void);
34 static int flashWriteBuffer(uint32_t sectorAddr, uint32_t addr,
35 uint16_t *data, uint32_t count);
51 if (!flashInitialized)
76 if (!flashInitialized)
97 if (!flashInitialized)
99 status = flashInterrogate();
107 flashBase[0x555] = 0x80;
108 flashBase[0x555] = 0xAA;
109 flashBase[0x2AA] = 0x55;
110 flashBase[0x555] = 0x10;
130 if (!flashInitialized)
132 status = flashInterrogate();
149 flashBase[0x555] = 0x80;
150 flashBase[0x555] = 0xAA;
151 flashBase[0x2AA] = 0x55;
153 *(
volatile uint16_t*) addr = 0x30;
155 return flashPoll(addr, 0xFFFF);
172 return flashInterrogate();
198 uint32_t sectorAddress, burst;
200 if (!flashInitialized)
202 status = flashInterrogate();
241 sectorAddress = addr & ~(flashInfo.
sectorSize - 1);
245 burst =
SL_MIN(burst, count & 0xFFFFFFFE);
247 status = flashWriteBuffer(sectorAddress, addr, (uint16_t*) data, burst);
289 tmp = *(
volatile uint16_t*)(addr & 0xFFFFFFFE);
292 tmp = (tmp & 0xFF) | (data << 8);
296 tmp = (tmp & 0xFF00) | data;
323 if (!flashInitialized)
325 status = flashInterrogate();
342 flashBase[0x555] = 0xA0;
344 *(
volatile uint16_t*) addr = data;
346 return flashPoll(addr, data);
395 static int flashInterrogate(
void)
398 flashBase = (
volatile uint16_t*) flashInfo.
baseAddress;
403 flashBase[0x555] = 0x90;
407 flashInfo.
deviceId = (flashBase[0x01] & 0xFF) << 16;
408 flashInfo.
deviceId |= (flashBase[0x0E] & 0xFF) << 8;
409 flashInfo.
deviceId |= flashBase[0x0F] & 0xFF;
413 flashBase[0x55] = 0x98;
416 if ((flashBase[0x10] !=
'Q') ||
417 (flashBase[0x11] !=
'R') ||
418 (flashBase[0x12] !=
'Y'))
425 if (flashBase[0x2C] != 1)
434 flashInfo.
sectorCount |= (flashBase[0x2E] << 8) & 0xFF00;
436 flashInfo.
sectorSize |= (flashBase[0x30] << 8) & 0xFF00;
443 flashInitialized =
true;
469 static int flashPoll(uint32_t addr, uint16_t data)
471 #define TOGGLE_BIT 0x40
472 #define TIMEOUT_BIT 0x20
474 uint16_t flashData1, flashData2, flashData3;
476 flashData1 = *(
volatile uint16_t*) addr;
477 flashData2 = *(
volatile uint16_t*) addr;
479 if ((flashData1 == data)
480 && (flashData2 == data))
487 flashData3 = *(
volatile uint16_t*) addr;
489 if ((((flashData1 ^ flashData2) & TOGGLE_BIT) == TOGGLE_BIT) &&
490 (((flashData2 ^ flashData3) & TOGGLE_BIT) == TOGGLE_BIT) &&
491 ((flashData1 & TIMEOUT_BIT) == TIMEOUT_BIT))
498 if ((((flashData1 ^ flashData2) & TOGGLE_BIT) != TOGGLE_BIT) ||
499 (((flashData2 ^ flashData3) & TOGGLE_BIT) != TOGGLE_BIT))
502 *(
volatile uint16_t*) addr;
503 if (*(
volatile uint16_t*) addr == data)
513 flashData1 = flashData2;
514 flashData2 = flashData3;
524 static void flashReset(
void)
533 static void flashUnlockCmd(
void)
535 flashBase[0x555] = 0xAA;
536 flashBase[0x2AA] = 0x55;
559 static int flashWriteBuffer(uint32_t sectorAddr,
565 volatile uint16_t *pDst;
567 pDst = (
volatile uint16_t*) addr;
568 count = (count / 2) - 1;
571 *(
volatile uint16_t*) sectorAddr = 0x25;
572 *(
volatile uint16_t*) sectorAddr = count;
573 for (i = 0; i <= count; i++)
577 *(
volatile uint16_t*) sectorAddr = 0x29;
581 return flashPoll((uint32_t) pDst, *data);
int NORFLASH_EraseDevice(void)
Erase entire flash device.
Definitions for the NORFLASH driver for Spansion S29GL128P90FFIR13.
uint32_t EBI_BankAddress(uint32_t bank)
Return base address of EBI bank.
int NORFLASH_ProgramWord16(uint32_t addr, uint16_t data)
Program a word (16bit) in the flash device.
bool NORFLASH_AddressValid(uint32_t addr)
Check if an address is valid for the flash device.
int NORFLASH_Init(void)
Initialize the NORFLASH module.
General purpose utilities.
NORFLASH_Info_TypeDef * NORFLASH_DeviceInfo(void)
Return a pointer to a NORFLASH_Info_TypeDef, which contain vital flash device information.
int NORFLASH_ProgramByte(uint32_t addr, uint8_t data)
Program a single byte in the flash device.
External Bus Iterface (EBI) peripheral API.
int NORFLASH_EraseSector(uint32_t addr)
Erase a sector in the flash device.
#define SL_MIN(a, b)
Macro for getting minimum value. No sideeffects, a and b are evaluated once only. ...
NORFLASH device information struct.
int NORFLASH_ProgramWord32(uint32_t addr, uint32_t data)
Program a word (32bit) in the flash device.
int NORFLASH_Program(uint32_t addr, uint8_t *data, uint32_t count)
Program the flash device.