Skip to content

Commit

Permalink
Merge pull request #105 from Marzogh/development
Browse files Browse the repository at this point in the history
Bugfix PR - resolves #102
  • Loading branch information
Marzogh authored Dec 10, 2017
2 parents 109b919 + 64e133a commit 6d88fb4
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 67 deletions.
47 changes: 47 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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._
23 changes: 23 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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**:
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 16 additions & 13 deletions examples/FlashDiagnostics/FlashDiagnostics.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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();
Expand Down
102 changes: 58 additions & 44 deletions examples/TestFlash/TestFlash.ino
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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') |
| ***************************************************************** |
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/TestFlash/command_list.ino
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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 "));
Expand Down
17 changes: 16 additions & 1 deletion extras/Changes.log
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SPIFlash
version=3.0.0
version=3.0.1
author=Prajwal Bhattaram
maintainer=Prajwal Bhattaram <marzogh@icloud.com>
sentence=SPI Flash library for Arduino.
Expand Down
8 changes: 6 additions & 2 deletions src/FLASHIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 6d88fb4

Please sign in to comment.