SPI Single IO NOR Flash Library for Nucleo F767ZI Interfacing

Dependents:   SPI_FLASH_MEM

Fork of W25X40BV by Johnny Yam

Files at this revision

API Documentation at this revision

Comitter:
shivanandgowdakr
Date:
Tue Oct 23 10:22:44 2018 +0000
Parent:
6:ef894010def4
Commit message:
OK

Changed in this revision

S25FL256S.cpp Show annotated file Show diff for this revision Revisions of this file
S25FL256S.h Show annotated file Show diff for this revision Revisions of this file
--- a/S25FL256S.cpp	Tue May 22 09:44:34 2018 +0000
+++ b/S25FL256S.cpp	Tue Oct 23 10:22:44 2018 +0000
@@ -25,6 +25,7 @@
 
 void S25FL256S::readStream(int addr, char* buf, int count)
 {
+    int i;
     if (count < 1)
         return;
     chipEnable();
@@ -33,10 +34,11 @@
     this->write((addr & ADDR_BMASK2) >> ADDR_BSHIFT2);
     this->write((addr & ADDR_BMASK1) >> ADDR_BSHIFT1);
     this->write((addr & ADDR_BMASK0) >> ADDR_BSHIFT0);
-    for (int i = 0; i < count; i++) {
+    for ( i = 0; i < count; i++) {
         buf[i] =  this->write(DUMMY_ADDR);
-        printf("i= %d   :%c \r\n",i,buf[i]);
+       // printf("i= %d   :%c \r\n",i,buf[i]);
     }
+    buf[i]='\0';
     chipDisable();
 }
 
@@ -71,10 +73,16 @@
     for (int i = 0; i < count; i++) {
         this->write(buf[i]);
     }
-    wait(0.1);
+    
     chipDisable();
     writeDisable();
-    wait(WAIT_TIME);
+    uint8_t busy=checkIfBusy();
+    while(busy)
+    {  
+      busy=checkIfBusy(); 
+     }
+    
+   
 }
 
 void S25FL256S::writeString(int addr, string str)
@@ -104,9 +112,10 @@
     this->write(RDSR1);
     uint8_t val=this->write(DUMMY_ADDR);
     chipDisable();
-   //wait(WAIT_TIME);//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
-    //printf("value of reg is %X  \r\n",val);
-    return(val);
+    if(val&0x01==0x01)
+    return 1;
+    else 
+    return 0;
 
 }
 //ERASING
@@ -132,7 +141,7 @@
     wait(WAIT_TIME);//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
 }
 
-void S25FL256S::sectorErase(int addr)
+int S25FL256S::sectorErase(int addr)
 {
     writeEnable();
     chipEnable();
@@ -143,7 +152,15 @@
     this->write((addr & ADDR_BMASK0) >> ADDR_BSHIFT0);
     chipDisable();
     writeDisable();
-    wait(WAIT_TIME);//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
+     uint8_t busy=checkIfBusy();
+    while(busy)
+    {  
+      busy=checkIfBusy();     
+      
+      printf(" Am Here \r\n\r\n");
+     }//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails
+     
+     return 1; 
 }
 void S25FL256S::reset()
 {
@@ -157,7 +174,7 @@
 uint8_t S25FL256S::checkIfBusy()
 {
     uint8_t value=readRegister();
-    printf("Value of Status Reg=%X\r\n\r\n",value);
+   // printf("Value of Status Reg=%X\r\n\r\n",value);
     if((value&0x01)==0x01)
         return 1;
     else
--- a/S25FL256S.h	Tue May 22 09:44:34 2018 +0000
+++ b/S25FL256S.h	Tue Oct 23 10:22:44 2018 +0000
@@ -6,7 +6,7 @@
 #include "mbed.h"
 #include <string>
 
-#define SPI_FREQ        5000000                 //Change SPI Frequency Here
+#define SPI_FREQ        10000000                 //Change SPI Frequency Here
 #define SPI_MODE        0                       // SPI Mode can be 0 or 3 . see data sheet
 #define SPI_NBIT        8                       // Number of bits 8.
 
@@ -120,7 +120,7 @@
     void writeByte(int addr, int data);                     // takes a 32-bit (4 bytes) address and a byte of data to write at that location
     void writeStream(int addr, char* buf, int count);       // write count bytes of data from buf to memory, starting at addr  
     void writeString(int add, string str);
-    void sectorErase(int addr);
+    int sectorErase(int addr);
     void chipErase();                                       //erase all data on chip
     uint8_t readRegister();  
     uint8_t checkIfBusy();                                  // Check if IC is bury writing or erasing