Flash handler for M25P* chips with no Device ID.

Dependencies:   RTOS_SPI_Clean

Fork of flash25spi by Klaus Steinhammer

Revision:
5:3fe5c97a223b
Parent:
4:af870c53c0e9
Child:
6:94558d4243f8
--- a/flash25spi.h	Fri Apr 25 12:40:20 2014 +0000
+++ b/flash25spi.h	Fri Apr 25 12:49:48 2014 +0000
@@ -34,28 +34,30 @@
 #include "mbed.h"
 
 /**
-A class to read and write M25P* serial SPI flash devices.
+An interface class to read and write M25P* serial SPI flash devices.
+Supports M25P10-A and M25P40 ICs with no Device ID.
 */
 class FlashM25PSpi
 {
 public:
     /**
-        Create the handler class. it tries to autodetect your device. If your device is not recognized, add the devices parameters
-        to the device data structure at the library sources.
-        @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
+        Create the flash interface class.
+        It will autodetect the Signature of your device. If your device is not recognized, add the devices parameters to the device data structure.
+        @param spi the SPI port where the flash is connected. Must be set to speed matching your device.
+        Will automatically set it to format(8,0).
         @param enable the pin name for the port where /CS is connected
     */
     FlashM25PSpi(SPI *spi, PinName enable);
 
     /**
-        Destroy the handler and powers down the flash chip
+        Destroy the interface and power down the flash chip
     */
     ~FlashM25PSpi();
 
     /**
         Read a part of the flash memory into destination.
-        The buffer must be pre-allocated by the caller
-        @param startAdr Flash address to start reading from. Doesn't need to match a page boundary
+        The buffer must be pre-allocated by the caller.
+        @param startAddr Flash address to start reading from. Doesn't need to match a page boundary
         @param destination Destination buffer
         @param len Number of bytes to read (must not exceed the end of memory)
         @return true if succeeded
@@ -63,36 +65,42 @@
     bool read(uint32_t startAddr, void* destination, size_t len);
 
     /**
-        Write the give buffer into the memory.
+        Write the provided buffer into the flash memory.
         This function handles dividing the write into pages until the physical write has finished.
-        @note The flash must be erased before starting a write cycle.
-        @param startAdr Address to start writing. Doesn't need to match a page boundary
+        Blocks until write completes.
+        @note The flash must be in the erased (0xFF) state before starting a write cycle. This is not checked.
+        @param startAddr Address to start writing. Doesn't need to match a page boundary
         @param data Source data buffer
-        @param len the number of bytes to write (must not exceed the end of memory)
-        @return false if the adresses are out of range
+        @param len the number of bytes to write (must not exceed the end of flash memory)
+        @return false if the addresses are out of range
     */
     bool write(uint32_t startAddr, const void* data, size_t len);
 
     /**
-        Erases the sector containing the given address to 0xFF - this erases several pages.
-        Refer to the IC datasheet or Size() methods for memory organisation.
+        Erases the sector containing the given address to 0xFF.
+        This erases several pages, refer to the IC datasheet or
+        sectorSize() and pageSize() methods for memory organisation.
         @param addr Any address within the sector to be cleared
     */
     void eraseSector(uint32_t addr);
 
     //! Erases the whole flash to 0xFF
     void eraseMem();
-    
-    //! Read detected flash size
+
+    //! Flash size
     size_t flashSize() const {
         return _size;
     }
-    
-    //! Read detected flash sector size
-    size_t sectorSize() const {return _sectorSize;}
-    
-    //! Read detected flash page size
-    size_t pageSize() const {return _pageSize;}
+
+    //! Flash sector size
+    size_t sectorSize() const {
+        return _sectorSize;
+    }
+
+    //! Flash page size
+    size_t pageSize() const {
+        return _pageSize;
+    }
 
 private:
     bool writePage(uint32_t startAddr, const char* data, size_t len);