![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
MX25R6435F Library Example
Fork of MX25Rxx35F_Serial_NOR_Flash_Testbench by
main.cpp@2:32ff86163041, 2015-07-23 (annotated)
- Committer:
- alec1
- Date:
- Thu Jul 23 17:11:38 2015 +0000
- Revision:
- 2:32ff86163041
- Parent:
- 1:550759f64702
- Child:
- 3:5dcc71b5ea22
added support for cmds REMS, RES, RDSCUR, WRSCUR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alec1 | 0:b2771f496313 | 1 | #include <ctype.h> |
alec1 | 0:b2771f496313 | 2 | #include "mbed.h" |
alec1 | 0:b2771f496313 | 3 | #include "SPI_MX25R.h" |
alec1 | 0:b2771f496313 | 4 | DigitalOut myled3(LED3); //Red |
alec1 | 0:b2771f496313 | 5 | DigitalOut myled1(LED1); //Blue |
alec1 | 0:b2771f496313 | 6 | DigitalOut led_green(LED_GREEN); |
alec1 | 1:550759f64702 | 7 | DigitalOut led_red(LED_RED); |
alec1 | 2:32ff86163041 | 8 | |
alec1 | 0:b2771f496313 | 9 | // SPI_MX25R(PinName mosi, PinName miso, PinName sclk, PinName cs) ; |
alec1 | 0:b2771f496313 | 10 | // FRDM-K64F |
alec1 | 0:b2771f496313 | 11 | // D13 SPI0_SCK (PTD1) J2<12> |
alec1 | 0:b2771f496313 | 12 | // D12 SPI0_MISO (PTD3) J2<10> |
alec1 | 0:b2771f496313 | 13 | // D11 SPI0_MOSI (PTD2) J2<8> |
alec1 | 0:b2771f496313 | 14 | // D10 SPI0_PCS0 (PTD0) J2<6> |
alec1 | 0:b2771f496313 | 15 | // Vdd =3.3V = J3<4> |
alec1 | 0:b2771f496313 | 16 | // Gnd =0.0V = J2<14> |
alec1 | 1:550759f64702 | 17 | SPI_MX25R spi_mem(PTD2, PTD3, PTD1,PTD0) ; |
alec1 | 2:32ff86163041 | 18 | |
alec1 | 2:32ff86163041 | 19 | |
alec1 | 1:550759f64702 | 20 | void rdRange(unsigned long rd_start_address, unsigned long rd_end_address) |
alec1 | 0:b2771f496313 | 21 | { |
alec1 | 0:b2771f496313 | 22 | unsigned int i, j ; |
alec1 | 0:b2771f496313 | 23 | unsigned char data[0x10] ; |
alec1 | 1:550759f64702 | 24 | unsigned long current_address = rd_start_address ; |
alec1 | 1:550759f64702 | 25 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 26 | printf("rd_start_address = 0x%08X\n\r", rd_start_address) ; |
alec1 | 1:550759f64702 | 27 | printf("rd_end_address = 0x%08X\n\r", rd_end_address) ; |
alec1 | 1:550759f64702 | 28 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 29 | printf(" ") ; // print header +0 to +F |
alec1 | 0:b2771f496313 | 30 | for (i = 0 ; i < 0x10 ; i++ ) { |
alec1 | 0:b2771f496313 | 31 | printf("+%X ",i) ; |
alec1 | 0:b2771f496313 | 32 | } |
alec1 | 0:b2771f496313 | 33 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 34 | printf(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --") ; |
alec1 | 1:550759f64702 | 35 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 36 | for (i = rd_start_address ; current_address < rd_end_address ; i++ ) { |
alec1 | 1:550759f64702 | 37 | printf("%06X : ", current_address ) ; // print start address : |
alec1 | 1:550759f64702 | 38 | for (j = 0 ; j <= 15 ; j++ ) { |
alec1 | 1:550759f64702 | 39 | data[j] = spi_mem.read8(current_address ) ; |
alec1 | 1:550759f64702 | 40 | printf("%02X ", data[j]) ; |
alec1 | 1:550759f64702 | 41 | current_address = current_address + 0x01 ; |
alec1 | 1:550759f64702 | 42 | } |
alec1 | 1:550759f64702 | 43 | printf(": ") ; |
alec1 | 0:b2771f496313 | 44 | for (i = 0 ; i < 0x10 ; i++ ) { |
alec1 | 1:550759f64702 | 45 | if (isprint(data[i])) { |
alec1 | 1:550759f64702 | 46 | printf("%c", data[i]) ; |
alec1 | 1:550759f64702 | 47 | } else { |
alec1 | 1:550759f64702 | 48 | printf(".") ; |
alec1 | 1:550759f64702 | 49 | } |
alec1 | 1:550759f64702 | 50 | } |
alec1 | 1:550759f64702 | 51 | printf(" :\n\r") ; |
alec1 | 1:550759f64702 | 52 | } |
alec1 | 1:550759f64702 | 53 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 54 | } |
alec1 | 2:32ff86163041 | 55 | |
alec1 | 1:550759f64702 | 56 | void rdSFDPRange(unsigned long rd_start_address, unsigned long rd_end_address) |
alec1 | 1:550759f64702 | 57 | { |
alec1 | 1:550759f64702 | 58 | unsigned int i, j ; |
alec1 | 1:550759f64702 | 59 | unsigned char data[0x10] ; |
alec1 | 1:550759f64702 | 60 | unsigned long current_address = rd_start_address ; |
alec1 | 1:550759f64702 | 61 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 62 | printf("rd_start_address = 0x%08X\n\r", rd_start_address) ; |
alec1 | 1:550759f64702 | 63 | printf("rd_end_address = 0x%08X\n\r", rd_end_address) ; |
alec1 | 1:550759f64702 | 64 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 65 | printf(" ") ; // print header +0 to +F |
alec1 | 1:550759f64702 | 66 | for (i = 0 ; i < 0x10 ; i++ ) { |
alec1 | 1:550759f64702 | 67 | printf("+%X ",i) ; |
alec1 | 1:550759f64702 | 68 | } |
alec1 | 1:550759f64702 | 69 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 70 | printf(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --") ; |
alec1 | 1:550759f64702 | 71 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 72 | for (i = rd_start_address ; current_address < rd_end_address ; i++ ) { |
alec1 | 1:550759f64702 | 73 | printf("%06X : ", current_address ) ; // print start address : |
alec1 | 1:550759f64702 | 74 | for (j = 0 ; j <= 15 ; j++ ) { |
alec1 | 1:550759f64702 | 75 | data[j] = spi_mem.readSFDP(current_address ) ; |
alec1 | 1:550759f64702 | 76 | printf("%02X ", data[j]) ; |
alec1 | 1:550759f64702 | 77 | current_address = current_address + 0x01 ; |
alec1 | 0:b2771f496313 | 78 | } |
alec1 | 0:b2771f496313 | 79 | printf(": ") ; |
alec1 | 0:b2771f496313 | 80 | for (i = 0 ; i < 0x10 ; i++ ) { |
alec1 | 0:b2771f496313 | 81 | if (isprint(data[i])) { |
alec1 | 0:b2771f496313 | 82 | printf("%c", data[i]) ; |
alec1 | 0:b2771f496313 | 83 | } else { |
alec1 | 0:b2771f496313 | 84 | printf(".") ; |
alec1 | 0:b2771f496313 | 85 | } |
alec1 | 0:b2771f496313 | 86 | } |
alec1 | 0:b2771f496313 | 87 | printf(" :\n\r") ; |
alec1 | 0:b2771f496313 | 88 | } |
alec1 | 0:b2771f496313 | 89 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 90 | } |
alec1 | 2:32ff86163041 | 91 | |
alec1 | 1:550759f64702 | 92 | void rdFREADRange(unsigned long rd_start_address, unsigned long rd_end_address) |
alec1 | 1:550759f64702 | 93 | { |
alec1 | 1:550759f64702 | 94 | unsigned int i, j ; |
alec1 | 1:550759f64702 | 95 | unsigned char data[0x10] ; |
alec1 | 1:550759f64702 | 96 | unsigned long current_address = rd_start_address ; |
alec1 | 1:550759f64702 | 97 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 98 | printf("rd_start_address = 0x%08X\n\r", rd_start_address) ; |
alec1 | 1:550759f64702 | 99 | printf("rd_end_address = 0x%08X\n\r", rd_end_address) ; |
alec1 | 1:550759f64702 | 100 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 101 | printf(" ") ; // print header +0 to +F |
alec1 | 1:550759f64702 | 102 | for (i = 0 ; i < 0x10 ; i++ ) { |
alec1 | 1:550759f64702 | 103 | printf("+%X ",i) ; |
alec1 | 1:550759f64702 | 104 | } |
alec1 | 1:550759f64702 | 105 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 106 | printf(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --") ; |
alec1 | 1:550759f64702 | 107 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 108 | for (i = rd_start_address ; current_address < rd_end_address ; i++ ) { |
alec1 | 1:550759f64702 | 109 | printf("%06X : ", current_address ) ; // print start address : |
alec1 | 1:550759f64702 | 110 | for (j = 0 ; j <= 15 ; j++ ) { |
alec1 | 1:550759f64702 | 111 | data[j] = spi_mem.readFREAD(current_address ) ; |
alec1 | 1:550759f64702 | 112 | printf("%02X ", data[j]) ; |
alec1 | 1:550759f64702 | 113 | current_address = current_address + 0x01 ; |
alec1 | 1:550759f64702 | 114 | } |
alec1 | 1:550759f64702 | 115 | printf(": ") ; |
alec1 | 1:550759f64702 | 116 | for (i = 0 ; i < 0x10 ; i++ ) { |
alec1 | 1:550759f64702 | 117 | if (isprint(data[i])) { |
alec1 | 1:550759f64702 | 118 | printf("%c", data[i]) ; |
alec1 | 1:550759f64702 | 119 | } else { |
alec1 | 1:550759f64702 | 120 | printf(".") ; |
alec1 | 1:550759f64702 | 121 | } |
alec1 | 1:550759f64702 | 122 | } |
alec1 | 1:550759f64702 | 123 | printf(" :\n\r") ; |
alec1 | 1:550759f64702 | 124 | } |
alec1 | 1:550759f64702 | 125 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 126 | } |
alec1 | 2:32ff86163041 | 127 | |
alec1 | 1:550759f64702 | 128 | void commandMenu(void) // TeraTerm Display (Enable Terminal Local Echo On). |
alec1 | 1:550759f64702 | 129 | { |
alec1 | 1:550759f64702 | 130 | printf("== Commands =========== (Comments) ===============================================\n\r") ; |
alec1 | 1:550759f64702 | 131 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 132 | printf(" wren (Write Enable, set WEL=1, 06h)\n\r") ; |
alec1 | 1:550759f64702 | 133 | printf(" wrdi (Write Disable, set WEL=0, 04h)\n\r") ; |
alec1 | 2:32ff86163041 | 134 | printf(" rdid (Read Manu & JEDEC Dev ID, 9Fh)\n\r") ; |
alec1 | 2:32ff86163041 | 135 | printf(" rems (Read Elect. Manu & Dev ID,90h)\n\r") ; |
alec1 | 2:32ff86163041 | 136 | printf(" res (Read Elect. Signiture, ABh)\n\r") ; |
alec1 | 1:550759f64702 | 137 | printf(" rdsr (Read Status Register, 05h)\n\r") ; |
alec1 | 1:550759f64702 | 138 | printf(" rdcr (Read Config Register, 15h)\n\r") ; |
alec1 | 2:32ff86163041 | 139 | printf(" rdscr (Read Security Register, 2Bh)\n\r") ; |
alec1 | 2:32ff86163041 | 140 | printf(" enso (Enter Secure OTP Area, B1h)\n\r") ; |
alec1 | 2:32ff86163041 | 141 | printf(" exso (Exit Secure OTP Area, C1h)\n\r") ; |
alec1 | 1:550759f64702 | 142 | printf(" reset (ResetEnable + SoftwareReset = 66h + 99h)\n\r") ; |
alec1 | 1:550759f64702 | 143 | printf(" hp (Enter HP mode = WREN=06h + WRSR= 01h 000002h)\n\r") ; |
alec1 | 1:550759f64702 | 144 | printf(" lp (Enter LP mode = WREN=06h + WRSR= 01h 000000h)\n\r") ; |
alec1 | 1:550759f64702 | 145 | printf(" wrsr data_3B (Write SR 01h +3B data,ex: wrsr 000002h, set wren 1st)\n\r") ; |
alec1 | 2:32ff86163041 | 146 | printf(" wrscr data_1B (Write Security Reg 2Fh +1B data, caution LDSO bit OTP!)\n\r") ; |
alec1 | 1:550759f64702 | 147 | printf(" se address (4KB Sector Erase, ex: be 0x00 <- note: sets WEL)\n\r") ; |
alec1 | 1:550759f64702 | 148 | printf(" be address (64KB Block Erase, ex: be 0x00 <- note: sets WEL)\n\r") ; |
alec1 | 1:550759f64702 | 149 | printf(" 32Kbe address (32KB Block Erase, ex: 32kbe 0x00 <- note: sets WEL)\n\r") ; |
alec1 | 1:550759f64702 | 150 | printf(" ce (Chip Erase = C7h, ex: ce <- note: sets WEL)\n\r") ; |
alec1 | 1:550759f64702 | 151 | printf(" pp address (256B Page Program, ex: pp 0x00 <- note: sets WEL)\n\r") ; |
alec1 | 1:550759f64702 | 152 | printf(" read address (read 1 byte of data, ex: read 0x0000)\n\r") ; |
alec1 | 1:550759f64702 | 153 | printf(" rd1 startadr endadr (read range of data, ex: rd1 0x00 0x10)\n\r") ; |
alec1 | 1:550759f64702 | 154 | printf(" fread startadr endadr (read range of data, ex: sfdp 0x00 0x10)\n\r") ; |
alec1 | 1:550759f64702 | 155 | printf(" sfdp startadr endadr (read range of SFDP, ex: sfdp 0x00 0x10)\n\r") ; |
alec1 | 1:550759f64702 | 156 | printf("==================================================================================\n\r") ; |
alec1 | 1:550759f64702 | 157 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 158 | } |
alec1 | 2:32ff86163041 | 159 | |
alec1 | 0:b2771f496313 | 160 | int main() { |
alec1 | 0:b2771f496313 | 161 | char cmd[32] ; |
alec1 | 0:b2771f496313 | 162 | int i ; |
alec1 | 0:b2771f496313 | 163 | int numData = 256 ; |
alec1 | 0:b2771f496313 | 164 | unsigned long address = 0 ; |
alec1 | 1:550759f64702 | 165 | unsigned long rd_start_address = 0 ; |
alec1 | 1:550759f64702 | 166 | unsigned long rd_end_address = 0 ; |
alec1 | 0:b2771f496313 | 167 | unsigned char data[256] ; |
alec1 | 0:b2771f496313 | 168 | |
alec1 | 0:b2771f496313 | 169 | extern serial_t stdio_uart ; |
alec1 | 0:b2771f496313 | 170 | serial_baud(&stdio_uart, 9600) ; |
alec1 | 0:b2771f496313 | 171 | |
alec1 | 0:b2771f496313 | 172 | printf("\n\r") ; |
alec1 | 0:b2771f496313 | 173 | printf("\n\r") ; |
alec1 | 0:b2771f496313 | 174 | printf("\n\r") ; |
alec1 | 0:b2771f496313 | 175 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 176 | printf("\n\r ####################################################\n\r") ; |
alec1 | 1:550759f64702 | 177 | printf(" # #\n\r") ; |
alec1 | 1:550759f64702 | 178 | printf(" # Macronix MX25Rxx35F Serial NOR Flash Testbench #\n\r") ; |
alec1 | 1:550759f64702 | 179 | printf(" # #\n\r") ; |
alec1 | 1:550759f64702 | 180 | printf(" ####################################################\n\r") ; |
alec1 | 0:b2771f496313 | 181 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 182 | printf("\n\r") ; |
alec1 | 1:550759f64702 | 183 | commandMenu() ; |
alec1 | 0:b2771f496313 | 184 | |
alec1 | 0:b2771f496313 | 185 | myled3 = 1; |
alec1 | 0:b2771f496313 | 186 | myled1 = 1; |
alec1 | 0:b2771f496313 | 187 | led_green = 0; |
alec1 | 1:550759f64702 | 188 | led_red = 1; |
alec1 | 0:b2771f496313 | 189 | |
alec1 | 0:b2771f496313 | 190 | while(1){ |
alec1 | 1:550759f64702 | 191 | printf("Enter command from list, or type menu.\n\r") ; |
alec1 | 0:b2771f496313 | 192 | printf("> ") ; |
alec1 | 0:b2771f496313 | 193 | scanf("%s", cmd) ; |
alec1 | 1:550759f64702 | 194 | |
alec1 | 1:550759f64702 | 195 | if (strcmp(cmd, "read") == 0) { // Read Byte |
alec1 | 0:b2771f496313 | 196 | scanf("%X", &address) ; |
alec1 | 0:b2771f496313 | 197 | data[0] = spi_mem.read8(address) ; |
alec1 | 0:b2771f496313 | 198 | printf("%01X : 0x%02X\n\r", address, data[0]) ; |
alec1 | 1:550759f64702 | 199 | |
alec1 | 1:550759f64702 | 200 | } else if (strcmp(cmd, "rd1") == 0) { // Read Range |
alec1 | 1:550759f64702 | 201 | scanf("%X", &rd_start_address) ; |
alec1 | 1:550759f64702 | 202 | scanf("%X", &rd_end_address) ; |
alec1 | 1:550759f64702 | 203 | rdRange(rd_start_address, rd_end_address) ; |
alec1 | 0:b2771f496313 | 204 | |
alec1 | 1:550759f64702 | 205 | } else if (strcmp(cmd, "rdsr") == 0) { // Read Status Register |
alec1 | 0:b2771f496313 | 206 | data[0] = spi_mem.readStatus() ; |
alec1 | 0:b2771f496313 | 207 | printf(" status register = 0x%02X\n\r", data[0]) ; |
alec1 | 0:b2771f496313 | 208 | printf("RDSR = 05h done\n\r") ; |
alec1 | 2:32ff86163041 | 209 | |
alec1 | 2:32ff86163041 | 210 | } else if (strcmp(cmd, "rdscr") == 0) { // Read Security Register |
alec1 | 2:32ff86163041 | 211 | data[0] = spi_mem.readSecurity() ; |
alec1 | 2:32ff86163041 | 212 | printf(" security register = 0x%02X\n\r", data[0]) ; |
alec1 | 2:32ff86163041 | 213 | printf("RDSR = 05h done\n\r") ; |
alec1 | 0:b2771f496313 | 214 | |
alec1 | 0:b2771f496313 | 215 | } else if (strcmp(cmd, "reset") == 0) { // ResetEnable + Software Reset |
alec1 | 0:b2771f496313 | 216 | spi_mem.resetEnable() ; |
alec1 | 0:b2771f496313 | 217 | spi_mem.reset() ; |
alec1 | 0:b2771f496313 | 218 | printf("Software ResestEnable 66h + Reset 99h completed\n\r") ; |
alec1 | 0:b2771f496313 | 219 | |
alec1 | 0:b2771f496313 | 220 | } else if (strcmp(cmd, "rdcr") == 0) { // Read Configuration Register |
alec1 | 0:b2771f496313 | 221 | printf(" configuration register = 0x%04X\n\r", spi_mem.readConfig()) ; |
alec1 | 0:b2771f496313 | 222 | printf("RDCR = 15h done\n\r") ; |
alec1 | 0:b2771f496313 | 223 | |
alec1 | 2:32ff86163041 | 224 | } else if (strcmp(cmd, "rdid") == 0) { // Read Manufacturer and JEDEC Device ID |
alec1 | 0:b2771f496313 | 225 | printf(" ID = 0x%06X\n\r", spi_mem.readID()) ; |
alec1 | 0:b2771f496313 | 226 | printf("RDID = 9Fh done\n\r") ; |
alec1 | 2:32ff86163041 | 227 | |
alec1 | 2:32ff86163041 | 228 | } else if (strcmp(cmd, "rems") == 0) { // Read Electronic Munufacturer and Device ID |
alec1 | 2:32ff86163041 | 229 | printf(" ID = 0x%04X\n\r", spi_mem.readREMS()) ; |
alec1 | 2:32ff86163041 | 230 | printf("REMS = 90h done\n\r") ; |
alec1 | 0:b2771f496313 | 231 | |
alec1 | 2:32ff86163041 | 232 | } else if (strcmp(cmd, "res") == 0) { // Read Electronic Signiture |
alec1 | 2:32ff86163041 | 233 | data[0] = spi_mem.readRES() ; |
alec1 | 2:32ff86163041 | 234 | printf(" Electronic Signiture = 0x%02X\n\r", data[0]) ; |
alec1 | 2:32ff86163041 | 235 | printf("RES = ABh done\n\r") ; |
alec1 | 2:32ff86163041 | 236 | |
alec1 | 0:b2771f496313 | 237 | } else if (strcmp(cmd, "wren") == 0) { // Write Enable |
alec1 | 0:b2771f496313 | 238 | spi_mem.writeEnable() ; |
alec1 | 0:b2771f496313 | 239 | printf(" WREN = 06h set\n\r") ; |
alec1 | 0:b2771f496313 | 240 | |
alec1 | 0:b2771f496313 | 241 | } else if (strcmp(cmd, "wrdi") == 0) { // Write Disable |
alec1 | 0:b2771f496313 | 242 | spi_mem.writeDisable() ; |
alec1 | 0:b2771f496313 | 243 | printf(" done\n\r") ; |
alec1 | 0:b2771f496313 | 244 | |
alec1 | 1:550759f64702 | 245 | } else if (strcmp(cmd, "enso") == 0) { // Enter Secure OTP Area |
alec1 | 1:550759f64702 | 246 | spi_mem.enterSecureOTP() ; |
alec1 | 1:550759f64702 | 247 | printf(" Entered Secure OTP Area\n\r") ; |
alec1 | 1:550759f64702 | 248 | |
alec1 | 1:550759f64702 | 249 | } else if (strcmp(cmd, "exso") == 0) { // Exit Secure OTP Area |
alec1 | 1:550759f64702 | 250 | spi_mem.exitSecureOTP() ; |
alec1 | 1:550759f64702 | 251 | printf(" Entered Secure OTP Area\n\r") ; |
alec1 | 1:550759f64702 | 252 | |
alec1 | 0:b2771f496313 | 253 | } else if (strcmp(cmd, "pp") == 0) { // Page Program |
alec1 | 0:b2771f496313 | 254 | scanf("%X", &address) ; |
alec1 | 0:b2771f496313 | 255 | printf("writing %d bytes to 0x%X\n\r",numData, address) ; |
alec1 | 0:b2771f496313 | 256 | spi_mem.writeEnable() ; // send WREN 1st |
alec1 | 0:b2771f496313 | 257 | for (i = 0 ; i < numData ; i++ ) { |
alec1 | 0:b2771f496313 | 258 | data[i] = i & 0xFF ; |
alec1 | 0:b2771f496313 | 259 | } |
alec1 | 0:b2771f496313 | 260 | spi_mem.programPage(address, data, numData) ; |
alec1 | 0:b2771f496313 | 261 | data[0] = 0 ; |
alec1 | 0:b2771f496313 | 262 | while((data[0] & 0x01) != 0x01 ) { |
alec1 | 0:b2771f496313 | 263 | printf(".") ; |
alec1 | 0:b2771f496313 | 264 | data[0] = spi_mem.readStatus() ; |
alec1 | 0:b2771f496313 | 265 | wait(0.01) ; |
alec1 | 0:b2771f496313 | 266 | } |
alec1 | 0:b2771f496313 | 267 | printf("\n\r") ; |
alec1 | 0:b2771f496313 | 268 | printf(" PP = 02h done\n\r") ; |
alec1 | 0:b2771f496313 | 269 | |
alec1 | 1:550759f64702 | 270 | } else if (strcmp(cmd, "ce") == 0) { // Chip Erase |
alec1 | 0:b2771f496313 | 271 | spi_mem.writeEnable() ; // send WREN 1st |
alec1 | 0:b2771f496313 | 272 | spi_mem.chipErase() ; |
alec1 | 0:b2771f496313 | 273 | data[0] = 0x01 ; // poll if WIP bit SR<0>=1 |
alec1 | 0:b2771f496313 | 274 | while((data[0] & 0x01) != 0 ) { |
alec1 | 0:b2771f496313 | 275 | printf("wait, chip erase in progress") ; |
alec1 | 0:b2771f496313 | 276 | data[0] = spi_mem.readStatus() ; |
alec1 | 0:b2771f496313 | 277 | printf(" --> status register = 0x%02X\n\r", data[0]) ; |
alec1 | 0:b2771f496313 | 278 | wait(5) ; |
alec1 | 0:b2771f496313 | 279 | } // end poll |
alec1 | 0:b2771f496313 | 280 | printf("CE = C7h done\n\r") ; |
alec1 | 0:b2771f496313 | 281 | |
alec1 | 1:550759f64702 | 282 | } else if (strcmp(cmd, "se") == 0) { // Sector Erase |
alec1 | 0:b2771f496313 | 283 | scanf("%X", &address) ; |
alec1 | 0:b2771f496313 | 284 | printf("Eraseing address 0x%X\n\r", address) ; |
alec1 | 0:b2771f496313 | 285 | spi_mem.writeEnable() ; // send WREN 1st |
alec1 | 0:b2771f496313 | 286 | spi_mem.sectorErase(address) ; |
alec1 | 0:b2771f496313 | 287 | data[0] = 0x01 ; // poll if WIP bit SR<0>=1 |
alec1 | 0:b2771f496313 | 288 | while((data[0] & 0x01) != 0 ) { |
alec1 | 0:b2771f496313 | 289 | printf(".") ; |
alec1 | 0:b2771f496313 | 290 | data[0] = spi_mem.readStatus() ; |
alec1 | 0:b2771f496313 | 291 | wait(0.1) ; |
alec1 | 0:b2771f496313 | 292 | } // end poll |
alec1 | 0:b2771f496313 | 293 | printf("SE = 20h done\n\r") ; |
alec1 | 0:b2771f496313 | 294 | |
alec1 | 0:b2771f496313 | 295 | } else if (strcmp(cmd, "be") == 0) { // 64KB Block Erase |
alec1 | 0:b2771f496313 | 296 | scanf("%X", &address) ; |
alec1 | 0:b2771f496313 | 297 | printf("Eraseing address 0x%X\n\r", address) ; |
alec1 | 0:b2771f496313 | 298 | spi_mem.writeEnable() ; // send WREN 1st |
alec1 | 0:b2771f496313 | 299 | spi_mem.blockErase(address) ; |
alec1 | 1:550759f64702 | 300 | data[0] = 0x01 ; // poll if WIP bit SR<0>=1 |
alec1 | 0:b2771f496313 | 301 | while((data[0] & 0x01) != 0 ) { |
alec1 | 0:b2771f496313 | 302 | printf(".") ; |
alec1 | 0:b2771f496313 | 303 | data[0] = spi_mem.readStatus() ; |
alec1 | 0:b2771f496313 | 304 | wait(0.1) ; |
alec1 | 0:b2771f496313 | 305 | } // end poll |
alec1 | 0:b2771f496313 | 306 | printf("BE = D8h done\n\r") ; |
alec1 | 0:b2771f496313 | 307 | |
alec1 | 1:550759f64702 | 308 | } else if (strcmp(cmd, "32kbe") == 0) { // 32KB Block Erase |
alec1 | 0:b2771f496313 | 309 | scanf("%X", &address) ; |
alec1 | 0:b2771f496313 | 310 | printf("Eraseing address 0x%X\n\r", address) ; |
alec1 | 0:b2771f496313 | 311 | spi_mem.writeEnable() ; // send WREN 1st |
alec1 | 0:b2771f496313 | 312 | spi_mem.blockErase(address) ; |
alec1 | 0:b2771f496313 | 313 | data[0] = 0x01 ; // poll if WIP bit SR<0>=1 |
alec1 | 0:b2771f496313 | 314 | while((data[0] & 0x01) != 0 ) { |
alec1 | 0:b2771f496313 | 315 | printf(".") ; |
alec1 | 0:b2771f496313 | 316 | data[0] = spi_mem.readStatus() ; |
alec1 | 0:b2771f496313 | 317 | wait(0.1) ; |
alec1 | 0:b2771f496313 | 318 | } // end poll |
alec1 | 0:b2771f496313 | 319 | printf("32KBE = 52h done\n\r") ; |
alec1 | 1:550759f64702 | 320 | |
alec1 | 2:32ff86163041 | 321 | } else if (strcmp(cmd, "wrsr") == 0) { // Write to Status and Configuration Reg 1 and 2 |
alec1 | 1:550759f64702 | 322 | scanf("%X", &address) ; |
alec1 | 1:550759f64702 | 323 | spi_mem.writeStatusreg(address) ; // Write SR cmd 01h +SRdata 00h +CR1data 00h +CR2data 02h, (CR2<1> = 1 to Enter HP Mode) |
alec1 | 1:550759f64702 | 324 | wait(0.5) ; |
alec1 | 1:550759f64702 | 325 | printf(" You wrote 0x%X to Staus and Config Register 1 and 2 \n\r", address) ; |
alec1 | 2:32ff86163041 | 326 | |
alec1 | 2:32ff86163041 | 327 | } else if (strcmp(cmd, "wrscr") == 0) { // Write to Security Reg |
alec1 | 2:32ff86163041 | 328 | scanf("%X", &address) ; |
alec1 | 2:32ff86163041 | 329 | spi_mem.writeSecurityreg(address) ; // WRSCUR cmd 2Fh + 1B of data |
alec1 | 2:32ff86163041 | 330 | wait(0.5) ; |
alec1 | 2:32ff86163041 | 331 | printf(" You wrote 0x%X to Security Register \n\r", address) ; |
alec1 | 0:b2771f496313 | 332 | |
alec1 | 0:b2771f496313 | 333 | } else if (strcmp(cmd, "hp") == 0) { // Enter High Performance Mode |
alec1 | 0:b2771f496313 | 334 | spi_mem.writeEnable() ; // send WREN 1st |
alec1 | 1:550759f64702 | 335 | spi_mem.writeStatusreg(0x000002) ; // Write SR cmd 01h +SRdata 00h +CR1data 00h +CR2data 02h, (CR2<1> = 1 to Ernter HP Mode) |
alec1 | 1:550759f64702 | 336 | printf(" You are now in High Performance mode (Red LED on)\n\r") ; |
alec1 | 1:550759f64702 | 337 | led_red = 0; |
alec1 | 1:550759f64702 | 338 | led_green = 1; |
alec1 | 0:b2771f496313 | 339 | |
alec1 | 0:b2771f496313 | 340 | } else if (strcmp(cmd, "lp") == 0) { // Enter Low Power Mode |
alec1 | 0:b2771f496313 | 341 | spi_mem.writeEnable() ; // send WREN 1st |
alec1 | 1:550759f64702 | 342 | spi_mem.writeStatusreg(0x000000) ; // Write SR cmd 01h +SRdata 00h +CR1data 00h +CR2data 00h, (CR2<1> = 0 to Ernter LP Mode) |
alec1 | 1:550759f64702 | 343 | printf(" You are now in Low Power mode (Green LED on)\n\r") ; |
alec1 | 1:550759f64702 | 344 | led_green = 0; |
alec1 | 1:550759f64702 | 345 | led_red = 1; |
alec1 | 1:550759f64702 | 346 | |
alec1 | 1:550759f64702 | 347 | } else if (strcmp(cmd, "fread") == 0) { // Read SFDP Range |
alec1 | 1:550759f64702 | 348 | scanf("%X", &rd_start_address) ; |
alec1 | 1:550759f64702 | 349 | scanf("%X", &rd_end_address) ; |
alec1 | 1:550759f64702 | 350 | rdFREADRange(rd_start_address, rd_end_address) ; |
alec1 | 1:550759f64702 | 351 | |
alec1 | 1:550759f64702 | 352 | } else if (strcmp(cmd, "sfdp") == 0) { // Read SFDP Range |
alec1 | 1:550759f64702 | 353 | scanf("%X", &rd_start_address) ; |
alec1 | 1:550759f64702 | 354 | scanf("%X", &rd_end_address) ; |
alec1 | 1:550759f64702 | 355 | rdSFDPRange(rd_start_address, rd_end_address) ; |
alec1 | 1:550759f64702 | 356 | |
alec1 | 0:b2771f496313 | 357 | } else if (strcmp(cmd, "help") == 0) { |
alec1 | 1:550759f64702 | 358 | commandMenu() ; |
alec1 | 1:550759f64702 | 359 | } else if (strcmp(cmd, "menu") == 0) { |
alec1 | 1:550759f64702 | 360 | commandMenu() ; |
alec1 | 0:b2771f496313 | 361 | } else { |
alec1 | 0:b2771f496313 | 362 | printf("Command NOT Recognized [ %s ]\n\r", cmd) ; |
alec1 | 1:550759f64702 | 363 | commandMenu() ; |
alec1 | 0:b2771f496313 | 364 | } |
alec1 | 0:b2771f496313 | 365 | } |
alec1 | 0:b2771f496313 | 366 | } |