/***************************************************************************** NOR FLASH Chip SPI Bus Driver for CC1010 SoC M25P80 / M25PE80 Page Alterability would be added later on /*Author(s)/* Abhishek Mitra and Anirban Banerjee, UC Riverside Portions from the SPI Bus example program from CC1010 Example ****************************************************************************/ #include #include #include #include #include #include #include #include #include // Define M25P80 instructions #define INST_WREN 0x06 #define INST_WRDI 0x04 #define INST_RDSR 0x05 #define INST_WRSR 0x01 #define INST_READ 0x03 #define INST_WRIT 0x02 #define INST_ERSE 0xD8 #define INST_ERBK 0xC7 #define INST_PWDN 0xB9 #define INST_RLSE 0xAB /*char AD0=0;//LSB char AD1=0; char AD2=0;//MSB */ // Define the addresses #define RAMBUF1_ADDRESS 0x0000 #define RAMBUF2_ADDRESS 0x0100 #define BUF_SIZE 256 // EEPROM access function prototypes void M25PWriteEnable(void); void M25PWriteDisable(void); void M25PWriteWait(void); void M25PReadByte(byte AD0, byte AD1, byte AD2); // one byte only void M25PReadBytes(byte AD0, byte AD1, byte AD2, byte xdata *buffer, word length); void M25PWriteByte(byte AD0, byte AD1, byte AD2, byte databyte); // one byte only bool M25PWriteBytes(byte AD0, byte AD1, byte AD2, byte xdata *buffer, word length); // 1-256 bytes void M25PReadStatus(void); void M25PWriteStatus(byte databyte); void M25PEraseSector(byte AD0, byte AD1, byte AD2); void M25PEraseChip(); void M25PWait(); void M25PBulkErase(); void M25PFill();//Fill the chip with rand data // Set up properly aligned RAM buffers byte xdata ramBuf1[BUF_SIZE] _at_ RAMBUF1_ADDRESS; byte xdata ramBuf2[BUF_SIZE] _at_ RAMBUF2_ADDRESS; // Array which will be initialized with random bytes byte xdata rndData[BUF_SIZE]; int main() { int i; // Turn off watchdog timer WDT_ENABLE(FALSE); // Set optimum settings for speed and low power consumption MEM_NO_WAIT_STATES(); FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS); // All I/Os are inputs after reset. Make I/Os connected to LEDs outputs RLED=YLED=GLED=BLED=LED_OFF; RLED_OE(TRUE); YLED_OE(TRUE); GLED_OE(TRUE); BLED_OE(TRUE); // Set up P0.3 as output to CS_N // Set P1.0 for nor PORTDIRBIT(1,0,POUT); // Fill rndData with random contents. srand(0xF012); for (i=0; i> 8;//8..15 WAD2 = address >> 16;//16..23 M25PWriteBytes(WAD0,WAD1,WAD2, rndData, BUF_SIZE ); // M25PReadBytes(WAD0,WAD1,WAD2, ramBuf1, BUF_SIZE ); //if (memcmp(rndData, ramBuf1, BUF_SIZE)) { // RLED = LED_ON; // printf("\n Fatal Error on page %d", i); } address+=256; } }