![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
MX25R6435F Library Example
Fork of MX25Rxx35F_Serial_NOR_Flash_Testbench by
Diff: main.cpp
- Revision:
- 3:5dcc71b5ea22
- Parent:
- 2:32ff86163041
diff -r 32ff86163041 -r 5dcc71b5ea22 main.cpp --- a/main.cpp Thu Jul 23 17:11:38 2015 +0000 +++ b/main.cpp Wed Mar 28 13:17:39 2018 +0000 @@ -1,21 +1,20 @@ #include <ctype.h> #include "mbed.h" #include "SPI_MX25R.h" -DigitalOut myled3(LED3); //Red -DigitalOut myled1(LED1); //Blue -DigitalOut led_green(LED_GREEN); -DigitalOut led_red(LED_RED); +DigitalOut led_green(D5); +DigitalOut led_red(D4); // SPI_MX25R(PinName mosi, PinName miso, PinName sclk, PinName cs) ; -// FRDM-K64F -// D13 SPI0_SCK (PTD1) J2<12> -// D12 SPI0_MISO (PTD3) J2<10> -// D11 SPI0_MOSI (PTD2) J2<8> -// D10 SPI0_PCS0 (PTD0) J2<6> -// Vdd =3.3V = J3<4> -// Gnd =0.0V = J2<14> -SPI_MX25R spi_mem(PTD2, PTD3, PTD1,PTD0) ; - +// STM32L476 +// D13 SPI0_SCK +// D12 SPI0_MISO +// D11 SPI0_MOSI +// D10 SPI0_PCS0 +// Vdd =3.3V +// Gnd =0.0V +SPI_MX25R spi_mem(D11, D12, D13,D10) ; + +uint8_t * mem_nBytes; void rdRange(unsigned long rd_start_address, unsigned long rd_end_address) { @@ -144,11 +143,13 @@ printf(" lp (Enter LP mode = WREN=06h + WRSR= 01h 000000h)\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(" se address (4KB Sector Erase, ex: se 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") ; printf(" ce (Chip Erase = C7h, ex: ce <- note: sets WEL)\n\r") ; printf(" pp address (256B Page Program, ex: pp 0x00 <- note: sets WEL)\n\r") ; + printf(" pread address (256B Page Read, ex: pr 0x000000 \n\r") ; + printf(" nread address (nBytes Read, ex: pn 0x00 \n\r 0x100 \n\r") ; printf(" read address (read 1 byte of data, ex: read 0x0000)\n\r") ; printf(" rd1 startadr endadr (read range of data, ex: rd1 0x00 0x10)\n\r") ; printf(" fread startadr endadr (read range of data, ex: sfdp 0x00 0x10)\n\r") ; @@ -182,8 +183,6 @@ printf("\n\r") ; commandMenu() ; -myled3 = 1; -myled1 = 1; led_green = 0; led_red = 1; @@ -267,6 +266,30 @@ printf("\n\r") ; printf(" PP = 02h done\n\r") ; + }else if (strcmp(cmd, "pread") == 0) { // Page read + scanf("%X", &address) ; + printf("reading page at: 0x%X\n\r",address) ; + uint8_t pageData[256]={0}; + spi_mem.readNBytes(address, pageData, 256) ; + printf("\n\r________Start________\n\r") ; + for ( int jj = 0 ; jj < 256 ; jj++ ) { + printf("%02X ", pageData[jj]) ; + } + printf("\n\r________Done__________\n\r") ; + + }else if (strcmp(cmd, "nread") == 0) { // nBytes read + scanf("%X", &address) ; + int nBytes=0; + scanf("%d", &nBytes) ; + printf("reading %d bytes at: 0x%X \n\r",nBytes, address) ; + mem_nBytes = new uint8_t [nBytes]; + spi_mem.readNBytes(address, mem_nBytes, nBytes) ; + printf("\n\r________Start________\n\r") ; + for ( int jj = 0 ; jj < nBytes ; jj++ ) { + printf("%02X ", mem_nBytes[jj]) ; + } + printf("\n\r________Done__________\n\r") ; + } else if (strcmp(cmd, "ce") == 0) { // Chip Erase spi_mem.writeEnable() ; // send WREN 1st spi_mem.chipErase() ;