Skip to content

Commit

Permalink
Final code fix for #135. ReadMe and change log updated. v3.2.1 is rea…
Browse files Browse the repository at this point in the history
…dy to go.

Relative to v3.2.0 this version (v3.2.1) reduces compiled code memory
footprint by 24% and 12%, with SFDP discovery turned off and turned on
respectively.
  • Loading branch information
Marzogh committed May 21, 2018
1 parent fa07241 commit c0acadd
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 61 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ SPIFlash flash(33);

<sub>* Optional</sub>

##### Note on SFDP discovery
As of v3.2.1, SFDP parameter discovery is an user controlled option. To get the library to work with SFDP compatible flash memory chips that are not officially supported by the library, the user must uncomment '//#define USES_SFDP' in 'SPIMemory.h'.

##### Notes on Address overflow and Error checking
- The library has Address overflow enabled by default - i.e. if the last address read/written from/to, in any function, is 0xFFFFF then, the next address read/written from/to is 0x00000. This can be disabled by uncommenting ```#define DISABLEOVERFLOW``` in SPIMemory.h. (Address overflow only works for Read / Write functions. Erase functions erase only a set number of blocks/sectors irrespective of overflow.)
- All write functions have Error checking turned on by default - i.e. every byte written to the flash memory will be checked against the data stored on the Arduino. Users who require greater write speeds can disable this function by setting an optional last 'errorCheck' argument in any write function to NOERRCHK - For eg. call the function ```writeByte(address, *data_buffer, NOERRCHK)``` instead of ```writeByte(address, *data_buffer)```.
Expand Down
10 changes: 5 additions & 5 deletions extras/Changes.log
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Bugs squashed
Enhancements
--> The way the basic functions execute has been modified to keep the function runtime the same (or improved) while reducing their memory footprint.

Test sketch - FlashDiagnostics.ino from v3.2.0 with #RUNDIAGNOSTIC uncommented
Test sketch - FlashDiagnostics.ino from v3.2.0 with #RUNDIAGNOSTIC commented out
Test platform - Arduino Pro Mini 8MHz 3.3V
Library version: v3.1.0 Compiled code size - 20500 bytes (SFDP discovery not supported)
Library version: v3.2.0 Compiled code size - 23010 bytes (SFDP discovery supported & on by default) (12% larger than v3.1.0)
Library version: v3.2.1 Compiled code size - 18660 bytes (SFDP discovery turned off) (9% smaller than v3.1.0)
Library version: v3.2.1 Compiled code size - 21698 bytes (SFDP discovery turned on) (5% larger than v3.1.0)
Library version: v3.1.0 Compiled code size - 17652 bytes (SFDP discovery not supported)
Library version: v3.2.0 Compiled code size - 20104 bytes (SFDP discovery supported & on by default) (13.9% larger than v3.1.0)
Library version: v3.2.1 Compiled code size - 15316 bytes (SFDP discovery turned off) (13.75% smaller than v3.1.0)
Library version: v3.2.1 Compiled code size - 17854 bytes (SFDP discovery turned on) (1.1% larger than v3.1.0)

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Version 3.2.0 //
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version=3.2.1
author=Prajwal Bhattaram
maintainer=Prajwal Bhattaram <marzogh@icloud.com>
sentence=SPI Memory library for Arduino. (Formerly SPIFlash)
paragraph=Starting v3.2.0, this library enables read, write, erase and power functions on all SFDP compatible Flash chips. Older versions are only compatible with specific chips as listed here - < v2.6.0 is compatible with W25X05**, W25X10**, W25X20**, W25X40**, W25Q80**, W25Q16**, W25Q32** & W25Q64**. All other Winbond flash chips can also be used with this library from v2.6.0 onwards. A number of Microchip, Cypress & Spansion chips - W25Q128**, W25Q256**, SST25VF064C, SST26VF064B & S25FL116K - can be used with with the library from v3.0.0 onwards. Refer to change log for further information about this release.
paragraph=This library enables read, write, erase and power functions on number of compatible flash memory chips. Refer to change log for further information about this release. To download any version of this library pre v3.2.0 (pre name-change from SPIFlash please visit https://github.com/Marzogh/SPIMemory/releases?after=v3.2.0 )
category=Data Storage
url=https://github.com/Marzogh/SPIMemory
architectures=avr,sam,samd,esp8266,esp32,Simblee,stm32
Expand Down
4 changes: 2 additions & 2 deletions src/SPIFlash.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Arduino SPIMemory Library v.3.1.0
/* Arduino SPIMemory Library v.3.2.1
* Copyright (C) 2017 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/05/2015
* Modified by @boseji <salearj@hotmail.com> - 02/03/2017
* Modified by Prajwal Bhattaram - 24/02/2018
* Modified by Prajwal Bhattaram - 21/05/2018
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Winbond NOR flash memory modules. In its current form it enables reading
Expand Down
80 changes: 37 additions & 43 deletions src/SPIFlash.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Arduino SPIMemory Library v.3.1.0
/* Arduino SPIMemory Library v.3.2.1
* Copyright (C) 2017 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/05/2015
* Modified by @boseji <salearj@hotmail.com> - 02/03/2017
* Modified by Prajwal Bhattaram - 24/02/2018
* Modified by Prajwal Bhattaram - 21/05/2018
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Winbond NOR flash memory modules. In its current form it enables reading
Expand Down Expand Up @@ -234,7 +234,7 @@ template <class T> bool SPIFlash::_writeErrorCheck(uint32_t _addr, const T& valu
return false;
}
const uint8_t* p = (const uint8_t*)(const void*)&value;
if (_dataType == _STRUCT_) {
/*if (_dataType == _STRUCT_) {
uint8_t _inByte[_sz];
_beginSPI(READDATA);
_nextBuf(READDATA, &(*_inByte), _sz);
Expand All @@ -249,7 +249,7 @@ template <class T> bool SPIFlash::_writeErrorCheck(uint32_t _addr, const T& valu
}
}
}
else {
else {*/
CHIP_SELECT
_nextByte(WRITE, READDATA);
_transferAddress();
Expand All @@ -261,7 +261,7 @@ template <class T> bool SPIFlash::_writeErrorCheck(uint32_t _addr, const T& valu
}
}
_endSPI();
}
//}
return true;
}

Expand All @@ -288,57 +288,51 @@ template <class T> bool SPIFlash::_write(uint32_t _addr, const T& value, uint32_
//Serial.print("_addrIn: ");
//Serial.println(_addrIn, HEX);
const uint8_t* p = ((const uint8_t*)(const void*)&value);
//Serial.print(F("Address being written to: "));
//Serial.println(_addr);
//Serial.print(F("Address being written to: "));
//Serial.println(_addr);
uint32_t length = _sz;
uint16_t maxBytes = SPI_PAGESIZE-(_addrIn % SPI_PAGESIZE); // Force the first set of bytes to stay within the first page

if (!SPIBusState) {
_startSPIBus();
}
CHIP_SELECT
_nextByte(WRITE, PAGEPROG);
_transferAddress();
//If data is only one byte (8 bits) long
if (_sz == 0x01) {
_nextByte(WRITE, *p);

if (maxBytes > length) {
for (uint16_t i = 0; i < length; ++i) {
_nextByte(WRITE, *p++);
}
CHIP_DESELECT
}
else { //If data is longer than one byte (8 bits)
uint32_t length = _sz;
uint16_t maxBytes = SPI_PAGESIZE-(_addrIn % SPI_PAGESIZE); // Force the first set of bytes to stay within the first page
else {
uint32_t writeBufSz;
uint16_t data_offset = 0;

do {
writeBufSz = (length<=maxBytes) ? length : maxBytes;

if (maxBytes > length) {
for (uint16_t i = 0; i < length; ++i) {
for (uint16_t i = 0; i < writeBufSz; ++i) {
_nextByte(WRITE, *p++);
}
CHIP_DESELECT
}
else {
uint32_t writeBufSz;
uint16_t data_offset = 0;

do {
writeBufSz = (length<=maxBytes) ? length : maxBytes;

for (uint16_t i = 0; i < writeBufSz; ++i) {
_nextByte(WRITE, *p++);
}
CHIP_DESELECT
if (!_addressOverflow) {
_currentAddress += writeBufSz;
}
else {
if (data_offset >= _addressOverflow) {
_currentAddress = 0x00;
_addressOverflow = false;
}
}
data_offset += writeBufSz;
length -= writeBufSz;
maxBytes = SPI_PAGESIZE; // Now we can do up to 256 bytes per loop
if(!_notBusy() || !_writeEnable()) {
return false;
if (!_addressOverflow) {
_currentAddress += writeBufSz;
}
else {
if (data_offset >= _addressOverflow) {
_currentAddress = 0x00;
_addressOverflow = false;
}
} while (length > 0);
}
}
data_offset += writeBufSz;
length -= writeBufSz;
maxBytes = SPI_PAGESIZE; // Now we can do up to 256 bytes per loop
if(!_notBusy() || !_writeEnable()) {
return false;
}
} while (length > 0);
}

if (!errorCheck) {
Expand Down
4 changes: 2 additions & 2 deletions src/SPIFlashIO.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Arduino SPIMemory Library v.3.1.0
/* Arduino SPIMemory Library v.3.2.1
* Copyright (C) 2017 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/05/2015
* Modified by @boseji <salearj@hotmail.com> - 02/03/2017
* Modified by Prajwal Bhattaram - 24/02/2018
* Modified by Prajwal Bhattaram - 21/05/2018
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Winbond NOR flash memory modules. In its current form it enables reading
Expand Down
13 changes: 8 additions & 5 deletions src/SPIMemory.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Arduino SPIMemory Library v.3.2.0
/* Arduino SPIMemory Library v.3.2.1
* Copyright (C) 2017 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 18/04/2018
* Modified by Prajwal Bhattaram - 20/04/2018
* Modified by Prajwal Bhattaram - 21/05/2018
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Winbond NOR flash memory modules. In its current form it enables reading
Expand Down Expand Up @@ -31,14 +31,16 @@
// if using an unsupported chip //
// //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
#define USES_SFDP //
//#define USES_SFDP //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Uncomment the code below to run a diagnostic if your flash //
// does not respond //
// //
// Error codes will be generated and returned on functions //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
#define RUNDIAGNOSTIC //
//#define RUNDIAGNOSTIC //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
Expand All @@ -49,6 +51,7 @@
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//#define HIGHSPEED //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Uncomment the code below to disable overflow and force data //
// to only be written to the last address of the flash memory //
Expand All @@ -59,7 +62,7 @@

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Comment out the code below to disable DMA mode on SAMD based //
// platforms //
// platforms (In ALPHA) //
// //
// Change the ZERO_SPISERCOM define below to use other SPI ports //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
Expand Down
6 changes: 3 additions & 3 deletions src/defines.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Arduino SPIMemory Library v.3.1.0
/* Arduino SPIMemory Library v.3.2.1
* Copyright (C) 2017 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/05/2015
* Modified by Prajwal Bhattaram - 24/02/2018
* Modified by Prajwal Bhattaram - 21/05/2018
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Winbond NOR flash memory modules. In its current form it enables reading
Expand Down Expand Up @@ -191,7 +191,7 @@
#define VERBOSE true
#define PRINTOVERRIDE true
#define ERASEFUNC 0xEF
#define BUSY_TIMEOUT 10000000L
#define BUSY_TIMEOUT 1000000000L
#define arrayLen(x) (sizeof(x) / sizeof(*x))
#define lengthOf(x) (sizeof(x))/sizeof(byte)
#define BYTE 1L
Expand Down

0 comments on commit c0acadd

Please sign in to comment.