Skip to content

Commit

Permalink
Merge pull request #11 from Marzogh/v1.3.1-w.i.p
Browse files Browse the repository at this point in the history
v1.3.1 Final
  • Loading branch information
Marzogh committed Sep 2, 2015
2 parents ff0fb17 + b6cfcc9 commit c134429
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 62 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: c++
sudo: false
before_install:
- source <(curl -SLs https://raw.githubusercontent.com/Marzogh/Travis-CI/master/install.sh)
#install:
# - ln -s $PWD /usr/local/share/arduino/libraries/Adafruit_FONA
# - arduino --install-library "Adafruit SleepyDog Library,Adafruit FONA Library,Adafruit CC3000 Library"
script:
- build_main_platforms
notifications:
email:
on_success: change
on_failure: change
11 changes: 2 additions & 9 deletions Changes.log
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
--> Updated ReadMe.md has all information needed to use the library.
--> v1.3.0 is faster and lighter than previous versions.
--> The library is optimised to work with the following Winbond Flash modules W25X05CL, W25X10BV, W25X20BV, W25X40BV, W25Q80BV, W25Q16BV, W25Q32BV, W25Q64BV, W25Q128BV & W25Q256FV.
--> _addressCheck() built into every read/write function.
--> _errorCheck() built into every write function.
--> The library now supports readAnything() & writeAnything().
--> There are now specific functions for reading and writing different types of variables - refer to ReadMe.md for further details.
--> All Read/Write functions now carry out a series of checks to keep data corruption to a minimum
--> Added a diagnostic function to enable error code generation and checking - Follow instruction in the "Diagnostics.ino" example
--> Bug fixes
--> Fixed errors in ReadMe.md
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPIFlash
# SPIFlash [![Build Status](https://travis-ci.org/Marzogh/SPIFlash.svg?branch=v1.3.1-w.i.p)](https://travis-ci.org/Marzogh/SPIFlash)
### Arduino library for Winbond Flash Memory Chips
<sup> Download the latest stable release (v1.3.0) from <a href = "https://github.com/Marzogh/SPIFlash/releases/tag/v1.3.0">here</a>. Please report any bugs in issues.</sup>
<sup> Download the latest stable release (v1.3.1) from <a href = "https://github.com/Marzogh/SPIFlash/releases/latest">here</a>. Please report any bugs in issues.</sup>

This library is for a the Winbond serial flash memory chips. In its current form it enables reading and writing bytes from and to various locations; reading and writing pages of bytes; continous reading/writing of data from/to arrays of bytes; sector, block and chip erase; and powering down for low power operation.

Expand Down Expand Up @@ -31,60 +31,60 @@ Fetches the JEDEC ID as a 32 bit number.
<hr>
##### Read commands
###### readAnything(page_number, offset, value)
Reads _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-4095), the offset of the data within page (0-255) and the variable/struct to write the data back to, as arguments.
Reads _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-maxPage), the offset of the data within page (0-255) and the variable/struct to write the data back to, as arguments.
###### readByte(page_number, offset)
Reads a _byte_ (unsigned 8 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the byte within page (0-255) as arguments.
Reads a _byte_ (unsigned 8 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the byte within page (0-255) as arguments.
###### readChar(page_number, offset)
Reads a _char_ (signed 8 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the char within page (0-255) as arguments.
Reads a _char_ (signed 8 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the char within page (0-255) as arguments.
###### readWord(page_number, offset)
Reads a _word_ (unsigned 16 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the word within page (0-255) as arguments.
Reads a _word_ (unsigned 16 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the word within page (0-255) as arguments.
###### readShort(page_number, offset)
Reads a _short_ (signed 16 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the short within page (0-255) as arguments.
Reads a _short_ (signed 16 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the short within page (0-255) as arguments.
###### readULong(page_number, offset)
Reads an _unsigned long_ (unsigned 32 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the unsigned long within page (0-255) as arguments.
Reads an _unsigned long_ (unsigned 32 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the unsigned long within page (0-255) as arguments.
###### readLong(page_number, offset)
Reads a _long_ (signed 32 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the long within page (0-255) as arguments.
Reads a _long_ (signed 32 bit value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the long within page (0-255) as arguments.
###### readFloat(page_number, offset)
Reads a _float_ (decimal value) from a specific location on a page. Takes the page number (0-4095) and offset of the float within page (0-255) as arguments.
Reads a _float_ (decimal value) from a specific location on a page. Takes the page number (0-maxPage) and offset of the float within page (0-255) as arguments.
###### readPage(page_number, *data_buffer)
Reads a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes.
<hr>
##### Write commands
###### writeByte(page, offset, data)
Writes a byte of data to a specific location on a page. Takes the page number (0-4095), offset of data byte within page (0-255) and one byte of data (0-255) as arguments.
Writes a byte of data to a specific location on a page. Takes the page number (0-maxPage), offset of data byte within page (0-255) and one byte of data (0-255) as arguments.
###### writeChar(page_number, offset, data)
Writes a _char_ (signed 8 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the char and one char of data within page (0-255) as arguments.
Writes a _char_ (signed 8 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the char and one char of data within page (0-255) as arguments.
###### writeWord(page_number, offset, data)
Writes a _word_ (unsigned 16 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the word and one word of data within page (0-255) as arguments.
Writes a _word_ (unsigned 16 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the word and one word of data within page (0-255) as arguments.
###### writeShort(page_number, offset, data)
Writes a _short_ (signed 16 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the short and one short of data within page (0-255) as arguments.
Writes a _short_ (signed 16 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the short and one short of data within page (0-255) as arguments.
###### writeULong(page_number, offset, data)
Writes an _unsigned long_ (unsigned 32 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the unsigned long and one unsigned long of data within page (0-255) as arguments.
Writes an _unsigned long_ (unsigned 32 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the unsigned long and one unsigned long of data within page (0-255) as arguments.
###### writeLong(page_number, offset, data)
Writes a _long_ (signed 32 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the long and one long of data within page (0-255) as arguments.
Writes a _long_ (signed 32 bit value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the long and one long of data within page (0-255) as arguments.
###### writeFloat(page_number, offset, data)
Writes a _float_ (decimal value) to a specific location on a page. Takes the page number (0-4095), the offset of the float and one float of data within page (0-255) as arguments.
Writes a _float_ (decimal value) to a specific location on a page. Takes the page number (0-maxPage), the offset of the float and one float of data within page (0-255) as arguments.
###### writePage(page_number, *data_buffer)
Writes a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes.
###### writeAnything(page_number, offset, value)
Writes _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-4095), the offset of the data within page (0-255) and the variable/struct to write the data from, as arguments.
Writes _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-maxPage), the offset of the data within page (0-255) and the variable/struct to write the data from, as arguments.
<hr>
##### Continuous read/write commands
###### readBytes(page_number, offset, *data_buffer)
Reads an array of bytes starting from a specific location in a page. Takes the page number (0-4095), offset of data byte within page (0-255) and a data_buffer - i.e. an array of bytes to be read from the flash memory - as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of n **bytes**. 'n' is determined by the amount of storage available on the Arduino board.
Reads an array of bytes starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255) and a data_buffer - i.e. an array of bytes to be read from the flash memory - as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of n **bytes**. 'n' is determined by the amount of storage available on the Arduino board.
###### writeBytes(page_number, offset, *data_buffer)
Writes an array of bytes starting from a specific location in a page. Takes the page number (0-4095), offset of data byte within page (0-255) and a data_buffer - i.e. an array of bytes to be written to the flash memory - as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of 'n' **bytes**. The number of bytes - 'n' - is determined by the amount of storage available on the Arduino board.
Writes an array of bytes starting from a specific location in a page. Takes the page number (0-maxPage), offset of data byte within page (0-255) and a data_buffer - i.e. an array of bytes to be written to the flash memory - as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of 'n' **bytes**. The number of bytes - 'n' - is determined by the amount of storage available on the Arduino board.
<hr>
##### Erase commands
###### eraseSector(page_number)
Erases one 4KB sector - 16 pages - containing the page to be erased. The sectors are numbered 0 - 255 containing 16 pages each.
Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255.
Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255, and so on...
###### eraseBlock32K(page_number)
Erases one 32KB block - 128 pages - containing the page to be erased. The blocks are numbered 0 - 31 containing 128 pages each.
Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31.
Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31, and so on...
###### eraseBlock64K(page_number)
Erases one 64KB block - 256 pages - containing the page to be erased. The blocks are numbered 0 - 15 containing 256 pages each.
// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15.
// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15, and so on...
###### eraseChip()
Erases entire chip. Use with care.
<hr>
Expand Down
57 changes: 34 additions & 23 deletions SPIFlash.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* Arduino SPIFlash Library v.1.3.0
/* Arduino SPIFlash Library v.1.3.1
* Copyright (C) 2015 by Prajwal Bhattaram
* Modified by Prajwal Bhattaram - 30/08/2015
* Modified by Prajwal Bhattaram - 02/09/2015
*
* This file is part of the Arduino SPIFlash Library. This library is for
* W25Q80BV serial flash memory. In its current form it enables reading
* and writing bytes from and to various locations, reading and writing pages,
* sector, block and chip erase, powering down for low power operation and
* continuous read functions.
* Winbond NOR flash memory modules. In its current form it enables reading
* and writing individual data variables, structs and arrays from and to various locations;
* reading and writing pages; continuous read functions; sector, block and chip erase;
* suspending and resuming programming/erase and powering down for low power operation.
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -22,6 +22,7 @@
* along with the Arduino SPIFlash Library. If not, see
* <http://www.gnu.org/licenses/>.
*/

#include "SPIFlash.h"
#include <util/delay.h>
#include <SPI.h>
Expand Down Expand Up @@ -169,11 +170,13 @@ bool SPIFlash::_writeEnable(void) {
bool SPIFlash::_writeDisable(void) {
_cmd(WRITEDISABLE);
_chipDeselect();

return true;
}

//Empties the values stored in any array by setting all the values of all the bits in the array to 1
void SPIFlash::_empty(uint8_t *array) {
int i;
uint16_t i;
for (i = 0; i < arrayLen(array); ++i)
array[i] = 0xFF;
}
Expand Down Expand Up @@ -236,6 +239,7 @@ uint32_t SPIFlash::_getAddress(uint16_t page_number, uint8_t offset) {
_errorCodeCheck();
while(1);
#endif
return false;
}
else
return address;
Expand Down Expand Up @@ -281,10 +285,8 @@ bool SPIFlash::_addressCheck(uint32_t address)
}

}
else if (address < capacity) {
address = address;
return true; // Not at end of memory
}

return true; // Not at end of memory if (address < capacity)
}

//Double checks all parameters before calling a Read
Expand Down Expand Up @@ -517,7 +519,7 @@ void SPIFlash::readBytes(uint16_t page_number, uint8_t offset, uint8_t *data_bu
uint32_t address = _prepRead(page_number, offset);
uint16_t length = arrayLen(data_buffer);
_beginRead(address);
for (int a = 0; a < length; a++) {
for (uint16_t a = 0; a < length; a++) {
data_buffer[a] = _readNextByte();
_addressCheck(address++);
}
Expand All @@ -535,7 +537,7 @@ uint16_t SPIFlash::readWord(uint16_t page_number, uint8_t offset) {
uint16_t I;
} data;
_beginRead(address);
for (int i=0; i < (sizeof(int16_t)); i++) {
for (uint16_t i=0; i < (sizeof(int16_t)); i++) {
data.b[i] = _readNextByte();
}
_endProcess();
Expand All @@ -553,7 +555,7 @@ int16_t SPIFlash::readShort(uint16_t page_number, uint8_t offset) {
int16_t s;
} data;
_beginRead(address);
for (int i=0; i < (sizeof(int16_t)); i++) {
for (uint16_t i=0; i < (sizeof(int16_t)); i++) {
data.b[i] = _readNextByte();
}
_endProcess();
Expand All @@ -571,7 +573,7 @@ uint32_t SPIFlash::readULong(uint16_t page_number, uint8_t offset) {
uint32_t l;
} data;
_beginRead(address);
for (int i=0; i < (sizeof(uint32_t)); i++) {
for (uint16_t i=0; i < (sizeof(uint32_t)); i++) {
data.b[i] = _readNextByte();
}
_endProcess();
Expand All @@ -589,7 +591,7 @@ int32_t SPIFlash::readLong(uint16_t page_number, uint8_t offset) {
int32_t l;
} data;
_beginRead(address);
for (int i=0; i < (sizeof(int32_t)); i++) {
for (uint16_t i=0; i < (sizeof(int32_t)); i++) {
data.b[i] = _readNextByte();
}
_endProcess();
Expand All @@ -607,7 +609,7 @@ float SPIFlash::readFloat(uint16_t page_number, uint8_t offset) {
float f;
} data;
_beginRead(address);
for (int i=0; i < (sizeof(float)); i++) {
for (uint16_t i=0; i < (sizeof(float)); i++) {
data.b[i] = _readNextByte();
}
_endProcess();
Expand Down Expand Up @@ -694,7 +696,14 @@ bool SPIFlash::writeBytes(uint16_t page_number, uint8_t offset, uint8_t *data_bu
length -= n;
maxBytes = 256; // Now we can do up to 256 bytes per loop
}
return true;
_endProcess();

if (!errorCheck)
return true;
else{
address = _prepWrite(page_number, offset);
return _writeErrorCheck(address, data_buffer);
}
}

// Writes an unsigned int as two bytes starting from a specific location in a page. Takes four arguments -
Expand All @@ -714,7 +723,7 @@ bool SPIFlash::writeWord(uint16_t page_number, uint8_t offset, uint16_t data, bo
} var;
var.w = data;
_beginWrite(address);
for (int j = 0; j < (sizeof(data)); j++) {
for (uint16_t j = 0; j < (sizeof(data)); j++) {
_writeNextByte(var.b[j]);
}
_endProcess();
Expand Down Expand Up @@ -742,7 +751,7 @@ bool SPIFlash::writeShort(uint16_t page_number, uint8_t offset, int16_t data, bo
} var;
var.s = data;
_beginWrite(address);
for (int j = 0; j < (sizeof(data)); j++) {
for (uint16_t j = 0; j < (sizeof(data)); j++) {
_writeNextByte(var.b[j]);
}
_endProcess();
Expand Down Expand Up @@ -770,7 +779,7 @@ bool SPIFlash::writeULong(uint16_t page_number, uint8_t offset, uint32_t data, b
} var;
var.l = data;
_beginWrite(address);
for (int j = 0; j < (sizeof(data)); j++) {
for (uint16_t j = 0; j < (sizeof(data)); j++) {
_writeNextByte(var.b[j]);
}
_endProcess();
Expand Down Expand Up @@ -798,7 +807,7 @@ bool SPIFlash::writeLong(uint16_t page_number, uint8_t offset, int32_t data, boo
} var;
var.l = data;
_beginWrite(address);
for (int j = 0; j < (sizeof(data)); j++) {
for (uint16_t j = 0; j < (sizeof(data)); j++) {
_writeNextByte(var.b[j]);
}
_endProcess();
Expand Down Expand Up @@ -826,7 +835,7 @@ bool SPIFlash::writeFloat(uint16_t page_number, uint8_t offset, float data, bool
} var;
var.f = data;
_beginWrite(address);
for (int j = 0; j < (sizeof(data)); j++) {
for (uint16_t j = 0; j < (sizeof(data)); j++) {
_writeNextByte(var.b[j]);
}
_endProcess();
Expand Down Expand Up @@ -970,6 +979,8 @@ bool SPIFlash::suspendProg(void) {

if(!_notBusy(20L)) //Max suspend Enable time according to datasheet
return false;

return true;
}

//Resumes previously suspended Block Erase/Sector Erase/Page Program.
Expand Down
13 changes: 7 additions & 6 deletions SPIFlash.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* Arduino SPIFlash Library v.1.3.0
/* Arduino SPIFlash Library v.1.3.1
* Copyright (C) 2015 by Prajwal Bhattaram
* Modified by Prajwal Bhattaram - 30/08/2015
* Modified by Prajwal Bhattaram - 02/09/2015
*
* This file is part of the Arduino SPIFlash Library. This library is for
* W25Q80BV serial flash memory. In its current form it enables reading
* and writing bytes from and to various locations, reading and writing pages,
* sector, block and chip erase, powering down for low power operation and
* continuous read functions.
* Winbond NOR flash memory modules. In its current form it enables reading
* and writing individual data variables, structs and arrays from and to various locations;
* reading and writing pages; continuous read functions; sector, block and chip erase;
* suspending and resuming programming/erase and powering down for low power operation.
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -22,6 +22,7 @@
* along with the Arduino SPIFlash Library. If not, see
* <http://www.gnu.org/licenses/>.
*/

#ifndef SPIFLASH_H
#define SPIFLASH_H

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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=1.3.0
version=1.3.1
author=Marzogh
maintainer=Marzogh <marzogh@icloud.com>
sentence=Winbond SPI flash library for Arduino.
Expand Down

0 comments on commit c134429

Please sign in to comment.