diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..6065e76 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,47 @@ +Hey there! Thanks for using the SPIFlash library for Arduino. + +**Note: For support questions, please use the [Arduino Forums](http://forum.arduino.cc/index.php?topic=324009.0). This repository's issues are reserved for feature requests and bug reports.** + +**I'm submitting a ...** + - [ ] bug report + - [ ] feature request + - [ ] support request => Please do not submit support request here, see note at the top of this template. + +Do the checklist before filing an issue: + +- [ ] Is this something you can **debug and fix**? Send a pull request! Bug fixes and documentation fixes are welcome. +- [ ] Is this an idea for a feature? Post the feature request as an issue here with a title that clearly says "Feature Request". +- [ ] Is this a bug that you cannot fix? Post the bug report as an issue here with a title that cleary says "Bug Report". + +When opening an issue please include the following details: +------------------------------------------------------------- + +- [ ] Do you want to request a *feature* or report a *bug*? +- [ ] Which library version are you using? +- [ ] Which Arduino IDE version are you compiling the library on? +- [ ] Which OS are you compiling your code on? [Linux / Mac / Windows] +- [ ] Which microcontroller platform are you using? +- [ ] Which Flash memory module are you using? +- [ ] What is the current behavior? +- [ ] What is the expected behavior? + +-------------------------- +###### Bug reports only + +- [ ] If this is a bug report - Provide a **minimal code snippet** example that reproduces the bug. Please make sure you wrap any code in the proper code blocks like below +``` +```CODE HERE``` +``` +- [ ] Provide **screenshots** where appropriate +- [ ] Provide **wiring diagram** where appropriate + +----------------------------- +###### Feature Requests only + +- [ ] If this is a feature request, what is the motivation / use case for changing the behavior? + +---------------------------- + +- [ ] Other information (e.g. detailed explanation, related issues, suggestions how to fix, links for us to have context etc.) + +_Make sure to add **all the information needed to understand the bug/feature** so that someone can help. If the info is missing we'll add the 'Needs more information' label and close the issue until there is enough information._ diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..eb18044 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,23 @@ +* **Please check if the PR fulfills these requirements** +- [ ] The commit message/s explain/s all the changes clearly +- [ ] Tests for the changes have been added (for bug fixes / features) +- [ ] Docs have been added / updated (for bug fixes / features) + + +* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) + + + +* **What is the current behavior?** (You can also link to an open issue here) + + + +* **What is the new behavior (if this is a feature change)?** + + + +* **Does this PR introduce a breaking change?** (What changes might users need to make in their application due to this PR?) + + + +* **Other information**: diff --git a/README.md b/README.md index 9a44e68..f058204 100755 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ SPIFlash flash(33); - SST26VF064B - Cypress/Spansion - S25FL116K + - S25FL127S ###### Should work with (Similar enough to the ones actually tested with) - Winbond (All SPI Flash chips) diff --git a/examples/FlashDiagnostics/FlashDiagnostics.ino b/examples/FlashDiagnostics/FlashDiagnostics.ino index a45f13c..b4a3ad0 100644 --- a/examples/FlashDiagnostics/FlashDiagnostics.ino +++ b/examples/FlashDiagnostics/FlashDiagnostics.ino @@ -23,15 +23,15 @@ #endif #if defined (SIMBLEE) - #define BAUD_RATE 250000 - #define RANDPIN 1 +#define BAUD_RATE 250000 +#define RANDPIN 1 #else - #define BAUD_RATE 115200 - #if defined(ARCH_STM32) - #define RANDPIN PA0 - #else - #define RANDPIN A0 - #endif +#define BAUD_RATE 115200 +#if defined(ARCH_STM32) +#define RANDPIN PA0 +#else +#define RANDPIN A0 +#endif #endif #define TRUE 1 @@ -42,9 +42,9 @@ SPIFlash flash; void setup() { Serial.begin(BAUD_RATE); - #if defined (ARDUINO_ARCH_SAMD) || (__AVR_ATmega32U4__) || defined(ARCH_STM32) - while (!Serial) ; // Wait for Serial monitor to open - #endif +#if defined (ARDUINO_ARCH_SAMD) || (__AVR_ATmega32U4__) || defined(ARCH_STM32) + while (!Serial) ; // Wait for Serial monitor to open +#endif delay(50); //Time to terminal get connected Serial.print(F("Initialising Flash memory")); for (uint8_t i = 0; i < 10; ++i) @@ -53,12 +53,15 @@ void setup() { } Serial.println(); randomSeed(analogRead(RANDPIN)); - flash.begin(); + //while (! + flash.begin();/*) { + delay(1000); + }*/ //To use a custom flash memory size (if using memory from manufacturers not officially supported by the library) - declare a size variable according to the list in defines.h //flash.begin(MB(1)); Serial.println(); Serial.println(); - + getID(); eraseChipTest(); eraseBlock64KTest(); diff --git a/examples/TestFlash/TestFlash.ino b/examples/TestFlash/TestFlash.ino old mode 100755 new mode 100644 index 1cc0977..ff4c51b --- a/examples/TestFlash/TestFlash.ino +++ b/examples/TestFlash/TestFlash.ino @@ -1,10 +1,12 @@ /* ---------------------------------------------------------------------------------------------------------------------------------- | Winbond Flash | - | SPIFlash library test v2.4.0 | + | SPIFlash library test v3.0.1 | |----------------------------------------------------------------------------------------------------------------------------------| | Marzogh | | 16.11.2016 | + | Modified: hanyazou | + | 19.11.2017 | |----------------------------------------------------------------------------------------------------------------------------------| | (Please make sure your Serial monitor is set to 'No Line Ending') | | ***************************************************************** | @@ -93,8 +95,11 @@ String inputString, outputString; SPIFlash flash; void setup() { - delay(10); Serial.begin(BAUD_RATE); + #if defined (ARDUINO_ARCH_SAMD) || (__AVR_ATmega32U4__) || defined(ARCH_STM32) + while (!Serial) ; // Wait for Serial monitor to open + #endif + delay(50); //Time to terminal get connected Serial.print(F("Initialising Flash memory")); for (int i = 0; i < 10; ++i) { @@ -337,22 +342,25 @@ void loop() { } addr = Serial.parseInt(); Serial.println(addr); - flash.eraseSector(addr); - clearprintBuffer(); - sprintf(printBuffer, "A 4KB sector containing address %d has been erased", addr); - Serial.println(printBuffer); - printReadChoice(); - while (!Serial.available()) { - } - uint8_t choice = Serial.parseInt(); - Serial.println(choice); - if (choice == 1) { - printOutputChoice(); + if (flash.eraseSector(addr)) { + clearprintBuffer(); + sprintf(printBuffer, "A 4KB sector containing address %d has been erased", addr); + Serial.println(printBuffer); + printReadChoice(); while (!Serial.available()) { } - uint8_t outputType = Serial.parseInt(); - Serial.println(outputType); - printPage(addr, outputType); + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(addr, outputType); + } + } else { + Serial.println("Erasing sector failed"); } printLine(); printNextCMD(); @@ -368,22 +376,25 @@ void loop() { } addr = Serial.parseInt(); Serial.println(addr); - flash.eraseBlock32K(addr); - clearprintBuffer(); - sprintf(printBuffer, "A 32KB block containing address %d has been erased", addr); - Serial.println(printBuffer); - printReadChoice(); - while (!Serial.available()) { - } - uint8_t choice = Serial.parseInt(); - Serial.println(choice); - if (choice == 1) { - printOutputChoice(); + if (flash.eraseBlock32K(addr)) { + clearprintBuffer(); + sprintf(printBuffer, "A 32KB block containing address %d has been erased", addr); + Serial.println(printBuffer); + printReadChoice(); while (!Serial.available()) { } - uint8_t outputType = Serial.parseInt(); - Serial.println(outputType); - printPage(addr, outputType); + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(addr, outputType); + } + } else { + Serial.println("Erasing block 32K failed"); } printLine(); printNextCMD(); @@ -399,22 +410,25 @@ void loop() { } addr = Serial.parseInt(); Serial.println(addr); - flash.eraseBlock64K(addr); - clearprintBuffer(); - sprintf(printBuffer, "A 64KB block containing address %d has been erased", addr); - Serial.println(printBuffer); - printReadChoice(); - while (!Serial.available()) { - } - uint8_t choice = Serial.parseInt(); - Serial.println(choice); - if (choice == 1) { - printOutputChoice(); + if (flash.eraseBlock64K(addr)) { + clearprintBuffer(); + sprintf(printBuffer, "A 64KB block containing address %d has been erased", addr); + Serial.println(printBuffer); + printReadChoice(); while (!Serial.available()) { } - uint8_t outputType = Serial.parseInt(); - Serial.println(outputType); - printPage(addr, outputType); + uint8_t choice = Serial.parseInt(); + Serial.println(choice); + if (choice == 1) { + printOutputChoice(); + while (!Serial.available()) { + } + uint8_t outputType = Serial.parseInt(); + Serial.println(outputType); + printPage(addr, outputType); + } + } else { + Serial.println("Erasing block 64K failed"); } printLine(); printNextCMD(); diff --git a/examples/TestFlash/command_list.ino b/examples/TestFlash/command_list.ino old mode 100755 new mode 100644 index 7ac5e30..823d5e6 --- a/examples/TestFlash/command_list.ino +++ b/examples/TestFlash/command_list.ino @@ -1,7 +1,7 @@ void commandList() { Serial.println(F("-----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F(" Winbond Flash ")); - Serial.println(F(" SPIFlash library test v2.5.0 ")); + Serial.println(F(" SPIFlash library test v3.0.1 ")); Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F(" Marzogh ")); Serial.println(F(" 24.11.2015 ")); diff --git a/extras/Changes.log b/extras/Changes.log index c7ab58a..9a2cd47 100755 --- a/extras/Changes.log +++ b/extras/Changes.log @@ -2,11 +2,26 @@ // SPIFlash Library // // Changes log // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Version 3.0.1 // +// Author: Prajwal Bhattaram // +// 10.12.2017 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +Bugs squashed: +**************** +Thanks for catching and fixing the following @hanyazou (PR #101) +--> Added missing break statements in SPIFlash::_beginSPI() because that lacks some essential break statement in switch/case. (commit 1: 1de2c10) +--> The library did not wait until the busy bit in SR1 was cleared. Timeout argument of _notBusy() must be in micro-second. 500L means 500 micro seconds which is too short to wait for completion of erase command. Added " * 1000" to the arguments. (commit 2: 9633c2f) +--> Modified TestFlash.ino to check error of erase commands execution. (commit 3: a179306) +**************** +--> Fixes a major bug that was causing input Arrays to be overwritten by zeros during the writeByteArray() / writeCharArray() process. Thanks for catching this @hanyazou. (Issue #102) + +New flash memory chips supported: +--> S25FL127S +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// // Version 3.0.0 // // Author: Prajwal Bhattaram // // 09.08.2017 // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -To check: Bugs Squashed: --> The writeByteArray() & writeCharArray() bug that occurred when writing arrays that spanned page boundaries (squashed in v2.5.0), stayed around to haunt the other functions. Writing any data larger than a single byte that spanned page boundaries would cause the data to wrap around to the beginning of the page. The likelihood of this occurring was slim - no one has reported it to date. However, just in case, this has now been squashed in this release. diff --git a/library.properties b/library.properties index fff047c..9688e9b 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SPIFlash -version=3.0.0 +version=3.0.1 author=Prajwal Bhattaram maintainer=Prajwal Bhattaram sentence=SPI Flash library for Arduino. diff --git a/src/FLASHIO.cpp b/src/FLASHIO.cpp index 5227e84..12644ed 100755 --- a/src/FLASHIO.cpp +++ b/src/FLASHIO.cpp @@ -188,18 +188,22 @@ bool SPIFlash::_beginSPI(uint8_t opcode) { _nextByte(WRITE, opcode); _nextByte(WRITE, DUMMYBYTE); _transferAddress(); + break; case SECTORERASE: _nextByte(WRITE, opcode); _transferAddress(); + break; case BLOCK32ERASE: _nextByte(WRITE, opcode); _transferAddress(); + break; case BLOCK64ERASE: _nextByte(WRITE, opcode); _transferAddress(); + break; default: _nextByte(WRITE, opcode); @@ -267,7 +271,7 @@ void SPIFlash::_nextBuf(uint8_t opcode, uint8_t *data_buffer, uint32_t size) { #ifdef ENABLEZERODMA spi_write(&(*data_buffer), size); #else - _spi->transfer(&(*data_buffer), size); + _spi->transfer(&data_buffer[0], size); #endif #elif defined (ARDUINO_ARCH_AVR) SPI.transfer(&(*data_buffer), size); @@ -397,7 +401,7 @@ bool SPIFlash::_notBusy(uint32_t timeout) { } _time++; } while ((micros() - _time) < timeout); - if ((micros() - _time) == timeout) { + if (timeout <= (micros() - _time)) { return false; } return true; diff --git a/src/SPIFlash.cpp b/src/SPIFlash.cpp index 6d5062b..c388b6e 100755 --- a/src/SPIFlash.cpp +++ b/src/SPIFlash.cpp @@ -471,7 +471,10 @@ bool SPIFlash::writeByteArray(uint32_t _addr, uint8_t *data_buffer, size_t buffe CHIP_SELECT _nextByte(WRITE, PAGEPROG); _transferAddress(); - _nextBuf(PAGEPROG, &data_buffer[0], bufferSize); + //_nextBuf(PAGEPROG, &data_buffer[0], bufferSize); + for (uint16_t i = 0; i < bufferSize; ++i) { + _nextByte(WRITE, data_buffer[i]); + } CHIP_DESELECT } else { @@ -551,7 +554,10 @@ bool SPIFlash::writeCharArray(uint32_t _addr, char *data_buffer, size_t bufferSi CHIP_SELECT _nextByte(WRITE, PAGEPROG); _transferAddress(); - _nextBuf(PAGEPROG, (uint8_t*) &data_buffer[0], bufferSize); + //_nextBuf(PAGEPROG, (uint8_t*) &data_buffer[0], bufferSize); + for (uint16_t i = 0; i < bufferSize; ++i) { + _nextByte(WRITE, data_buffer[i]); + } CHIP_DESELECT } else { @@ -730,7 +736,7 @@ bool SPIFlash::eraseSector(uint32_t _addr) { _beginSPI(SECTORERASE); //The address is transferred as a part of this function _endSPI(); - if(!_notBusy(500L)) { + if(!_notBusy(500 * 1000L)) { return false; //Datasheet says erasing a sector takes 400ms max } //_writeDisable(); @@ -753,7 +759,7 @@ bool SPIFlash::eraseBlock32K(uint32_t _addr) { _beginSPI(BLOCK32ERASE); _endSPI(); - if(!_notBusy(1*S)) { + if(!_notBusy(1000 * 1000L)) { return false; //Datasheet says erasing a sector takes 400ms max } _writeDisable(); @@ -777,7 +783,7 @@ bool SPIFlash::eraseBlock64K(uint32_t _addr) { _beginSPI(BLOCK64ERASE); _endSPI(); - if(!_notBusy(1200L)) { + if(!_notBusy(1200 * 1000L)) { return false; //Datasheet says erasing a sector takes 400ms max } #ifdef RUNDIAGNOSTIC