Flash handler for M25P* chips with no Device ID.

Dependencies:   RTOS_SPI_Clean

Fork of flash25spi by Klaus Steinhammer

Files at this revision

API Documentation at this revision

Comitter:
Tomo2k
Date:
Fri Apr 25 12:40:20 2014 +0000
Parent:
3:318fabd6708c
Child:
5:3fe5c97a223b
Commit message:
Removed need for CDI

Changed in this revision

flash25spi.cpp Show annotated file Show diff for this revision Revisions of this file
flash25spi.h Show annotated file Show diff for this revision Revisions of this file
--- a/flash25spi.cpp	Fri Apr 25 12:25:08 2014 +0000
+++ b/flash25spi.cpp	Fri Apr 25 12:40:20 2014 +0000
@@ -34,9 +34,7 @@
 #include "flash25spi.h"
 #include "wait_api.h"
 
-#include "cdi.h"
-
-#define DEBUG
+//#define DEBUG
 
 struct dataBase {
     uint8_t signature;
@@ -70,7 +68,7 @@
 #define MID(x) ((x&0xff00)>>8)
 #define LOW(x) (x&0xff)
 
-FlashM25PSpi::FlashM25PSpi(SPI *spi, PinName enable, CDI *cdi) :
+FlashM25PSpi::FlashM25PSpi(SPI *spi, PinName enable) :
     _spi(spi)
     , _enable(enable)
     , _size(0)
@@ -95,7 +93,7 @@
     while (_size == 0) {
         if (devices[i].memsize == 0) {  // Nobody makes a memory of zero size
 #ifdef DEBUG
-            if (cdi) cdi->printf("\r\nUnknown Flash Memory signature: %xh\r\n", chipSig);
+            printf("\r\nUnknown Flash Memory signature: %xh\r\n", chipSig);
 #endif
             return;
         }
@@ -104,8 +102,8 @@
             _sectorSize=devices[i].sectorsize;
             _pageSize=devices[i].pagesize;
 #ifdef DEBUG
-            if (cdi) cdi->printf("\r\nFlash Memory Sig:%Xh : %u bytes Org: %x, %x\r\n",
-                                     chipSig, _size, _sectorSize, _pageSize);
+            printf("\r\nFlash Memory Sig:%Xh : %u bytes Org: %x, %x\r\n",
+                   chipSig, _size, _sectorSize, _pageSize);
 #endif
         } else
             i++;
@@ -140,7 +138,7 @@
     _spi->write(MID(startAddr));
     _spi->write(LOW(startAddr));
 
-    // Read into destination buffer 
+    // Read into destination buffer
     while (len--) {
         *dest8++ = _spi->write(0);
     }
@@ -156,7 +154,7 @@
 
     // Cast to char
     char *data8 = (char*)data;
-    
+
     size_t ofs = 0;
     while (ofs < len) {
         // calculate amount of data to write into current page
--- a/flash25spi.h	Fri Apr 25 12:25:08 2014 +0000
+++ b/flash25spi.h	Fri Apr 25 12:40:20 2014 +0000
@@ -33,8 +33,6 @@
 #pragma once
 #include "mbed.h"
 
-class CDI;
-
 /**
 A class to read and write M25P* serial SPI flash devices.
 */
@@ -47,7 +45,7 @@
         @param spi the SPI port where the flash is connected. Must be set to format(8,3), and with a speed matching the one of your device
         @param enable the pin name for the port where /CS is connected
     */
-    FlashM25PSpi(SPI *spi, PinName enable, CDI *cdi = 0);
+    FlashM25PSpi(SPI *spi, PinName enable);
 
     /**
         Destroy the handler and powers down the flash chip
@@ -86,7 +84,9 @@
     void eraseMem();
     
     //! Read detected flash size
-    size_t flashSize() const {return _size;}
+    size_t flashSize() const {
+        return _size;
+    }
     
     //! Read detected flash sector size
     size_t sectorSize() const {return _sectorSize;}