![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Freescale FRDM-K64F development platform with external Macronix Serial NOR Flash used to perform SPI Read, Program, and Erase.
Diff: main.cpp
- Revision:
- 2:32ff86163041
- Parent:
- 1:550759f64702
diff -r 550759f64702 -r 32ff86163041 main.cpp --- a/main.cpp Mon Jul 20 20:56:50 2015 +0000 +++ b/main.cpp Thu Jul 23 17:11:38 2015 +0000 @@ -5,7 +5,7 @@ DigitalOut myled1(LED1); //Blue DigitalOut led_green(LED_GREEN); DigitalOut led_red(LED_RED); - + // SPI_MX25R(PinName mosi, PinName miso, PinName sclk, PinName cs) ; // FRDM-K64F // D13 SPI0_SCK (PTD1) J2<12> @@ -15,8 +15,8 @@ // Vdd =3.3V = J3<4> // Gnd =0.0V = J2<14> SPI_MX25R spi_mem(PTD2, PTD3, PTD1,PTD0) ; - - + + void rdRange(unsigned long rd_start_address, unsigned long rd_end_address) { unsigned int i, j ; @@ -52,7 +52,7 @@ } printf("\n\r") ; } - + void rdSFDPRange(unsigned long rd_start_address, unsigned long rd_end_address) { unsigned int i, j ; @@ -88,7 +88,7 @@ } printf("\n\r") ; } - + void rdFREADRange(unsigned long rd_start_address, unsigned long rd_end_address) { unsigned int i, j ; @@ -124,22 +124,26 @@ } printf("\n\r") ; } - + void commandMenu(void) // TeraTerm Display (Enable Terminal Local Echo On). { printf("== Commands =========== (Comments) ===============================================\n\r") ; printf("\n\r") ; printf(" wren (Write Enable, set WEL=1, 06h)\n\r") ; printf(" wrdi (Write Disable, set WEL=0, 04h)\n\r") ; - printf(" rdid (Read Manu and Dev ID, 9Fh)\n\r") ; + printf(" rdid (Read Manu & JEDEC Dev ID, 9Fh)\n\r") ; + printf(" rems (Read Elect. Manu & Dev ID,90h)\n\r") ; + printf(" res (Read Elect. Signiture, ABh)\n\r") ; printf(" rdsr (Read Status Register, 05h)\n\r") ; printf(" rdcr (Read Config Register, 15h)\n\r") ; + printf(" rdscr (Read Security Register, 2Bh)\n\r") ; + printf(" enso (Enter Secure OTP Area, B1h)\n\r") ; + printf(" exso (Exit Secure OTP Area, C1h)\n\r") ; printf(" reset (ResetEnable + SoftwareReset = 66h + 99h)\n\r") ; printf(" hp (Enter HP mode = WREN=06h + WRSR= 01h 000002h)\n\r") ; printf(" lp (Enter LP mode = WREN=06h + WRSR= 01h 000000h)\n\r") ; - printf(" enso (Enter Secure OTP Area, B1h)\n\r") ; - printf(" exso (Exit Secure OTP Area, C1h)\n\r") ; printf(" wrsr data_3B (Write SR 01h +3B data,ex: wrsr 000002h, set wren 1st)\n\r") ; + printf(" wrscr data_1B (Write Security Reg 2Fh +1B data, caution LDSO bit OTP!)\n\r") ; printf(" se address (4KB Sector Erase, ex: be 0x00 <- note: sets WEL)\n\r") ; printf(" be address (64KB Block Erase, ex: be 0x00 <- note: sets WEL)\n\r") ; printf(" 32Kbe address (32KB Block Erase, ex: 32kbe 0x00 <- note: sets WEL)\n\r") ; @@ -152,7 +156,7 @@ printf("==================================================================================\n\r") ; printf("\n\r") ; } - + int main() { char cmd[32] ; int i ; @@ -202,6 +206,11 @@ data[0] = spi_mem.readStatus() ; printf(" status register = 0x%02X\n\r", data[0]) ; printf("RDSR = 05h done\n\r") ; + + } else if (strcmp(cmd, "rdscr") == 0) { // Read Security Register + data[0] = spi_mem.readSecurity() ; + printf(" security register = 0x%02X\n\r", data[0]) ; + printf("RDSR = 05h done\n\r") ; } else if (strcmp(cmd, "reset") == 0) { // ResetEnable + Software Reset spi_mem.resetEnable() ; @@ -212,10 +221,19 @@ printf(" configuration register = 0x%04X\n\r", spi_mem.readConfig()) ; printf("RDCR = 15h done\n\r") ; - } else if (strcmp(cmd, "rdid") == 0) { // Read ID + } else if (strcmp(cmd, "rdid") == 0) { // Read Manufacturer and JEDEC Device ID printf(" ID = 0x%06X\n\r", spi_mem.readID()) ; printf("RDID = 9Fh done\n\r") ; + + } else if (strcmp(cmd, "rems") == 0) { // Read Electronic Munufacturer and Device ID + printf(" ID = 0x%04X\n\r", spi_mem.readREMS()) ; + printf("REMS = 90h done\n\r") ; + } else if (strcmp(cmd, "res") == 0) { // Read Electronic Signiture + data[0] = spi_mem.readRES() ; + printf(" Electronic Signiture = 0x%02X\n\r", data[0]) ; + printf("RES = ABh done\n\r") ; + } else if (strcmp(cmd, "wren") == 0) { // Write Enable spi_mem.writeEnable() ; printf(" WREN = 06h set\n\r") ; @@ -300,11 +318,17 @@ } // end poll printf("32KBE = 52h done\n\r") ; - } else if (strcmp(cmd, "wrsr") == 0) { // Write to Status and Configuration Reg 1 and 2 + } else if (strcmp(cmd, "wrsr") == 0) { // Write to Status and Configuration Reg 1 and 2 scanf("%X", &address) ; spi_mem.writeStatusreg(address) ; // Write SR cmd 01h +SRdata 00h +CR1data 00h +CR2data 02h, (CR2<1> = 1 to Enter HP Mode) wait(0.5) ; printf(" You wrote 0x%X to Staus and Config Register 1 and 2 \n\r", address) ; + + } else if (strcmp(cmd, "wrscr") == 0) { // Write to Security Reg + scanf("%X", &address) ; + spi_mem.writeSecurityreg(address) ; // WRSCUR cmd 2Fh + 1B of data + wait(0.5) ; + printf(" You wrote 0x%X to Security Register \n\r", address) ; } else if (strcmp(cmd, "hp") == 0) { // Enter High Performance Mode spi_mem.writeEnable() ; // send WREN 1st