diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..544b4f2 --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/Changes.log b/Changes.log index 1e315dd..2a98d3a 100644 --- a/Changes.log +++ b/Changes.log @@ -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 diff --git a/README.md b/README.md index 4c82ed7..ff70873 100644 --- a/README.md +++ b/README.md @@ -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 - Download the latest stable release (v1.3.0) from here. Please report any bugs in issues. + Download the latest stable release (v1.3.1) from here. Please report any bugs in issues. 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. @@ -31,60 +31,60 @@ Fetches the JEDEC ID as a 32 bit number.
##### 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.
##### 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.
##### 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.
##### 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.
diff --git a/SPIFlash.cpp b/SPIFlash.cpp index 393948b..edb3b76 100644 --- a/SPIFlash.cpp +++ b/SPIFlash.cpp @@ -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 @@ -22,6 +22,7 @@ * along with the Arduino SPIFlash Library. If not, see * . */ + #include "SPIFlash.h" #include #include @@ -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; } @@ -236,6 +239,7 @@ uint32_t SPIFlash::_getAddress(uint16_t page_number, uint8_t offset) { _errorCodeCheck(); while(1); #endif + return false; } else return address; @@ -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 @@ -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++); } @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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 - @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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. diff --git a/SPIFlash.h b/SPIFlash.h index d529ffd..c41386b 100644 --- a/SPIFlash.h +++ b/SPIFlash.h @@ -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 @@ -22,6 +22,7 @@ * along with the Arduino SPIFlash Library. If not, see * . */ + #ifndef SPIFLASH_H #define SPIFLASH_H diff --git a/examples/Data_writer/.due.test.skip b/examples/Data_writer/.due.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/Data_writer/.esp8266.test.skip b/examples/Data_writer/.esp8266.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/Data_writer/.leonardo.test.skip b/examples/Data_writer/.leonardo.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/Diagnostics/.due.test.skip b/examples/Diagnostics/.due.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/Diagnostics/.esp8266.test.skip b/examples/Diagnostics/.esp8266.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/Diagnostics/.leonardo.test.skip b/examples/Diagnostics/.leonardo.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/TestFlash/.due.test.skip b/examples/TestFlash/.due.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/TestFlash/.esp8266.test.skip b/examples/TestFlash/.esp8266.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/TestFlash/.leonardo.test.skip b/examples/TestFlash/.leonardo.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/library.properties b/library.properties index f19b416..2a88fd7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SPIFlash -version=1.3.0 +version=1.3.1 author=Marzogh maintainer=Marzogh sentence=Winbond SPI flash library for Arduino.