Skip to content

Commit

Permalink
Merge pull request #179 from Marzogh/development
Browse files Browse the repository at this point in the history
Final code for v3.4.0 from Development
  • Loading branch information
Marzogh authored Jun 3, 2019
2 parents 2711ccc + 106ae3f commit 82db983
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 66 deletions.
19 changes: 12 additions & 7 deletions Change log.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##### Change log
[![Build Status](https://travis-ci.org/Marzogh/SPIMemory.svg?branch=master)](https://travis-ci.org/Marzogh/SPIMemory) [![DOI](https://zenodo.org/badge/35823047.svg)](https://zenodo.org/badge/latestdoi/35823047)
[![GitHub release](https://img.shields.io/github/release/Marzogh/SPIMemory.svg)](https://github.com/Marzogh/SPIMemory)
[![GitHub commits](https://img.shields.io/github/commits-since/Marzogh/SPIMemory/v3.3.0.svg)](https://github.com/Marzogh/SPIMemory/compare/v3.3.0...development)
[![GitHub commits](https://img.shields.io/github/commits-since/Marzogh/SPIMemory/v3.4.0.svg)](https://github.com/Marzogh/SPIMemory/compare/v3.3.0...v3.4.0)
[![GitHub issues](https://img.shields.io/github/issues/Marzogh/SPIMemory.svg)](https://github.com/Marzogh/SPIMemory/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/Marzogh/SPIMemory.svg)](https://github.com/Marzogh/SPIMemory/pulls)
[![license](https://img.shields.io/github/license/Marzogh/SPIMemory.svg)](https://github.com/Marzogh/SPIMemory/blob/master/LICENSE)
Expand All @@ -11,11 +11,12 @@
<hr>

## Version 3.4.0 (In progress)
## Version 3.4.0

#### Release date TBA
#### Release date 03.06.2019

###### Bugs squashed:
- FastRead works properly now. All previous versions of the library has a FastRead bug that prevent it from doing what it was supposed to.

###### Enhancements:
- An alternate version of the constructor
Expand All @@ -25,10 +26,14 @@ SPIFlash flash(int8_t *SPIPinsArray);
can be used (only with ESP32 boards as of now) to enable the use of custom SPI pins. ```SPIPinsArray``` has to be a 4 element array containing the custom SPI pin numbers (as signed integers - int8_t) in the following order - sck, miso, mosi, ss. Refer to the wiki for more information. Resolves #113
- Created new error code `NOCHIPSELECTDECLARED` for errors with declaring custom SPI pins.
- Using other SPI ports (HSPI, VSPI, SPI1, SPI2 etc.) is now also supported on ESP32 boards - along with SAMD and STM32 boards (supported since v3.0.0). Resolves #177
- Formatted and merged pull request #153. This changes the way [setClock()](https://github.com/Marzogh/SPIMemory/wiki/Library-instantiation-functions#setclockclockspeed) works and allows for the definition of clock speed before the SPI Bus is instantiated. Refer to [wiki](https://github.com/Marzogh/SPIMemory/wiki/Library-instantiation-functions#setclockclockspeed) for further details. Thanks @rambo.

###### New flash memory chips supported:
###### New Microcontrollers supported:
- nRF52832 ARM Cortex M4F (Adafruit nRF52 Feather)
- STM32L0 ARM Cortex M0+ (Nucleo-L031K6)

###### New FRAM memory chips supported:
###### New flash memory chips supported:
- MX25L4005 & MX25L4005 from Macronix


<hr>
Expand Down Expand Up @@ -80,12 +85,12 @@ can be used (only with ESP32 boards as of now) to enable the use of custom SPI p
|FlashDiagnostics.ino from v3.2.0<br>with #RUNDIAGNOSTIC commented out | Arduino Pro Mini 8MHz 3.3V |


| Library version | Compiled code size<br>(Bytesb | SFDP status | Size compared to v3.1.0 |
| Library version | Compiled code size<br>(Bytes) | SFDP status | Size compared to v3.1.0 |
| :------: | :------: | :------: | :-----: |
| v3.1.0 | 17652 | SFDP discovery not supported | Same size |
| v3.2.0 | 20104 | SFDP discovery supported & on by default | 13.9% larger than v3.1.0 |
| v3.2.1 | 15316 | SFDP discovery turned off | 13.75% smaller than v3.1.0 |
| v3.2.1 | 17854 bytes | SFDP discovery turned on | 1.1% larger than v3.1.0 |
| v3.2.1 | 17854 | SFDP discovery turned on | 1.1% larger than v3.1.0 |

<hr>

Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPIMemory [![Build Status](https://travis-ci.org/Marzogh/SPIMemory.svg?branch=master)](https://travis-ci.org/Marzogh/SPIMemory) [![DOI](https://zenodo.org/badge/35823047.svg)](https://zenodo.org/badge/latestdoi/35823047)
[![GitHub release](https://img.shields.io/github/release/Marzogh/SPIMemory.svg)](https://github.com/Marzogh/SPIMemory)
[![GitHub commits](https://img.shields.io/github/commits-since/Marzogh/SPIMemory/v3.2.1.svg)](https://github.com/Marzogh/SPIMemory/compare/v3.2.1...v3.3.0)
[![GitHub commits](https://img.shields.io/github/commits-since/Marzogh/SPIMemory/v3.3.0.svg)](https://github.com/Marzogh/SPIMemory/compare/v3.3.0...v3.4.0)
[![GitHub issues](https://img.shields.io/github/issues/Marzogh/SPIMemory.svg)](https://github.com/Marzogh/SPIMemory/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/Marzogh/SPIMemory.svg)](https://github.com/Marzogh/SPIMemory/pulls)
[![license](https://img.shields.io/github/license/Marzogh/SPIMemory.svg)](https://github.com/Marzogh/SPIMemory/blob/master/LICENSE)
Expand Down Expand Up @@ -30,8 +30,10 @@ This Arduino library is for use with flash and FRAM memory chips that communicat
| ATmega2560 | Arduino Mega | - |
| ATSAMD21G18 (ARM Cortex M0+) | Adafruit Feather M0, <br> Adafruit Feather M0 Express, <br> Adafruit ItsyBitsy M0 Express | - |
| AT91SAM3X8E (ARM Cortex M3) | Arduino Due | - |
| nRF52832 (ARM Cortex M4F) | Adafruit nRF52 Feather | - |
| ATSAMD51J19 (ARM Cortex M4) | Adafruit Metro M4 | - |
| STM32F091RCT6 | Nucleo-F091RC | |
| STM32L0 | Nucleo-L031K6 | |
| ESP8266 | Adafruit ESP8266 Feather, <br> Sparkfun ESP8266 Thing | - |
| ESP32 | Adafruit ESP32 Feather, <br> Sparkfun ESP32 Thing | Onboard flash memory. Refer to footnote<sup>£</sup> below. |
| Simblee | Sparkfun Simblee | - |
Expand All @@ -47,11 +49,13 @@ This Arduino library is for use with flash and FRAM memory chips that communicat
| Winbond | W25Q16BV <br> W25Q64FV <br> W25Q64JV <br> W25Q80BV <br> W25Q256FV | Should work with the W25QXXXBV, W25QXXXFV & <br> W25QXXXJV families |
| Microchip | SST25VF064C <br> SST26VF016B <br> SST26VF032B <br> SST26VF064B | Should work with the SST25 & SST26 families |
| Cypress/Spansion | S25FL032P <br> S25FL116K <br> S25FL127S | Should work with the S25FL family |
| ON Semiconductor | LE25U40CMC | |
| AMIC| A25L512A0 | |
| Micron| M25P40 | |
| Adesto| AT25SF041 | |
| Giga devices| GD25Q16C | (Used on the Adafruit ItsyBitsy M0 Express) |
| ON Semiconductor | LE25U40CMC | |
| AMIC| A25L512A0 | |
| Micron| M25P40 | |
| Adesto| AT25SF041 | |
| Macronix| MX25L4005 <br> MX25L4005 | |
| Giga devices| GD25Q16C | (Used on the Adafruit ItsyBitsy M0 Express) |


##### Should work with any flash memory that is compatible with the SFDP standard as defined in JESD216B

Expand Down Expand Up @@ -105,13 +109,13 @@ As of v3.2.1, SFDP parameter discovery is an user controlled option. To get the

#### SPIFram <sup>^</sup>

- The library is called by declaring the```SPIFram fram(csPin*)``` constructor where 'flash' can be replaced by a user constructor of choice and 'csPin' is the Chip Select pin for the flash module.
- The library is called by declaring the```SPIFram fram(csPin*)``` constructor where 'fram' can be replaced by a user constructor of choice and 'csPin' is the Chip Select pin for the fram module.

<sub>* Optional. Do not include csPin if using the default slave select pin for your board.</sub>
- Every version of the library >= v3.0.0 supports the ability to use any of multiple SPI interfaces (if your micro-controller supports them). Switching to use another SPI interface is done by calling ```SPIFram fram(csPin, &SPI1);``` (or &SPI2 and so on), instead of ```SPIFram fram(csPin)```.

<sub>* NOTE: This is currently only officially supported on the SAMD and STM32 architectures.</sub>
- Also make sure to include ```fram.begin(CHIPSIZE*)``` in ```void setup()```. This enables the library to detect the type of flash chip installed and load the right parameters.
- Also make sure to include ```fram.begin(CHIPSIZE*)``` in ```void setup()```. This enables the library to detect the type of fram chip installed and load the right parameters.

<sup>^</sup> <sub> Currently in BETA. The methods in SPIFram are not final and subject to change over the next few revisions.</sub>

Expand Down
1 change: 0 additions & 1 deletion examples/FlashDiagnostics/Diagnostics_functions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,3 @@ void eraseChipTest() {
}

}

10 changes: 7 additions & 3 deletions examples/FlashDiagnostics/FlashDiagnostics.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SPIFlash flash;
//SPIFlash flash(SS1, &SPI1); //Use this constructor if using an SPI bus other than the default SPI. Only works with chips with more than one hardware SPI bus

void setup() {

Serial.begin(BAUD_RATE);
#if defined (ARDUINO_ARCH_SAMD) || defined (__AVR_ATmega32U4__) || defined (ARCH_STM32) || defined (NRF5) || defined (ARDUINO_ARCH_ESP32)
while (!Serial) ; // Wait for Serial monitor to open
Expand All @@ -59,10 +59,14 @@ void setup() {
}
Serial.println();
randomSeed(analogRead(RANDPIN));
Serial.println(flash.error(VERBOSE));

if (flash.error()) {
Serial.println(flash.error(VERBOSE));
}

flash.begin();
//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));
//flash.begin(MB(32));

if (getID()) {

Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=SPIMemory
version=3.3.0
version=3.4.0
author=Prajwal Bhattaram
maintainer=Prajwal Bhattaram <marzogh@icloud.com>
sentence=SPI Memory library for Arduino. (Formerly SPIFlash)
paragraph=This library enables read, write, erase and power functions on number of compatible flash and fram 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
architectures=avr,sam,samd,esp8266,esp32,Simblee,stm32,nrf52
includes=SPIMemory.h
2 changes: 1 addition & 1 deletion src/DMASAM.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 30/09/2016
* Original code from @manitou48 <https://github.com/manitou48/DUEZoo/blob/master/dmaspi.ino>
Expand Down
2 changes: 1 addition & 1 deletion src/DMASAM.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/04/2018
* Modified by Prajwal Bhattaram - 19/06/2018
Expand Down
23 changes: 17 additions & 6 deletions src/SPIFlash.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 20/05/2015
* Modified by @boseji <salearj@hotmail.com> - 02/03/2017
* Modified by Prajwal Bhattaram - 20/04/2019
* Modified by Prajwal Bhattaram - 03/06/2019
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Flash and FRAM memory modules. In its current form it enables reading,
Expand Down Expand Up @@ -123,7 +123,13 @@ bool SPIFlash::begin(uint32_t flashChipSize) {

#ifdef SPI_HAS_TRANSACTION
//Define the settings to be used by the SPI bus
_settings = SPISettings(SPI_CLK, MSBFIRST, SPI_MODE0);
if (!_SPISettingsSet) {
_settings = SPISettings(SPI_CLK, MSBFIRST, SPI_MODE0);
}
#else
if (!_clockdiv) {
_clockdiv = SPI_CLOCK_DIV2;
}
#endif
bool retVal = _chipID(flashChipSize);
_endSPI();
Expand All @@ -137,6 +143,11 @@ bool SPIFlash::begin(uint32_t flashChipSize) {
#ifdef SPI_HAS_TRANSACTION
void SPIFlash::setClock(uint32_t clockSpeed) {
_settings = SPISettings(clockSpeed, MSBFIRST, SPI_MODE0);
_SPISettingsSet = true;
}
#else
void SPIFlash::setClock(uint8_t clockdiv) {
_clockdiv = clockdiv;
}
#endif

Expand Down Expand Up @@ -172,9 +183,9 @@ float SPIFlash::functionRunTime(void) {

//Returns the library version as three bytes
bool SPIFlash::libver(uint8_t *b1, uint8_t *b2, uint8_t *b3) {
*b1 = LIBVER;
*b2 = LIBSUBVER;
*b3 = BUGFIXVER;
*b1 = SPIFLASH_LIBVER;
*b2 = SPIFLASH_LIBSUBVER;
*b3 = SPIFLASH_REVVER;
return true;
}

Expand Down
13 changes: 10 additions & 3 deletions src/SPIFlash.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/05/2015
* Modified by @boseji <salearj@hotmail.com> - 02/03/2017
* Modified by Prajwal Bhattaram - 20/04/2019
* Modified by Prajwal Bhattaram - 03/06/2019
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Flash and FRAM memory modules. In its current form it enables reading,
Expand Down Expand Up @@ -43,7 +43,11 @@ class SPIFlash {
#endif
//----------------------------- Initial / Chip Functions ------------------------------//
bool begin(uint32_t flashChipSize = 0);
#ifdef SPI_HAS_TRANSACTION
void setClock(uint32_t clockSpeed);
#else
void setClock(uint8_t clockdiv);
#endif
bool libver(uint8_t *b1, uint8_t *b2, uint8_t *b3);
bool sfdpPresent(void);
uint8_t error(bool verbosity = false);
Expand Down Expand Up @@ -153,6 +157,9 @@ class SPIFlash {
//-------------------------------- Private variables ----------------------------------//
#ifdef SPI_HAS_TRANSACTION
SPISettings _settings;
bool _SPISettingsSet = false;
#else
uint8_t _clockdiv;
#endif

//If multiple SPI ports are available this variable is used to choose between them (SPI, SPI1, SPI2 etc.)
Expand Down Expand Up @@ -215,7 +222,7 @@ class SPIFlash {
{KB(64), KB(128), KB(256), KB(512), MB(1), MB(2), MB(4), MB(8), MB(16), MB(32), MB(2), MB(4), MB(8), MB(8), KB(256), KB(512), MB(4), KB(512)};
// To understand the _memSize definitions check defines.h

const uint8_t _supportedManID[8] = {WINBOND_MANID, MICROCHIP_MANID, CYPRESS_MANID, ADESTO_MANID, MICRON_MANID, ON_MANID, GIGA_MANID, AMIC_MANID};
const uint8_t _supportedManID[9] = {WINBOND_MANID, MICROCHIP_MANID, CYPRESS_MANID, ADESTO_MANID, MICRON_MANID, ON_MANID, GIGA_MANID, AMIC_MANID, MACRONIX_MANID};

const uint8_t _altChipEraseReq[3] = {A25L512, M25P40, SST26};
};
Expand Down
33 changes: 27 additions & 6 deletions src/SPIFlashIO.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/05/2015
* Modified by @boseji <salearj@hotmail.com> - 02/03/2017
* Modified by Prajwal Bhattaram - 20/04/2019
* Modified by Prajwal Bhattaram - 03/06/2019
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Flash and FRAM memory modules. In its current form it enables reading,
Expand Down Expand Up @@ -174,7 +174,7 @@
#ifdef SPI_HAS_TRANSACTION
SPI.beginTransaction(_settings);
#else
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.setClockDivider(_clockdiv);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
#endif
Expand Down Expand Up @@ -202,8 +202,8 @@

case FASTREAD:
_nextByte(WRITE, opcode);
_nextByte(WRITE, DUMMYBYTE);
_transferAddress();
_nextByte(WRITE, DUMMYBYTE);
break;

case SECTORERASE:
Expand Down Expand Up @@ -259,7 +259,10 @@

//Reads/Writes next data buffer. Should be called after _beginSPI()
void SPIFlash::_nextBuf(uint8_t opcode, uint8_t *data_buffer, uint32_t size) {
#if !defined(ARDUINO_ARCH_SAM) && !defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_ARCH_AVR)
uint8_t *_dataAddr = &(*data_buffer);
#endif

switch (opcode) {
case READDATA:
#if defined (ARDUINO_ARCH_SAM)
Expand Down Expand Up @@ -562,6 +565,22 @@
Serial.println(F("No Chip size defined by user. Checking library support."));
#endif
//Identify capacity
if(_chip.manufacturerID == MACRONIX_MANID)
{
switch(_chip.capacityID)
{
case MX25L4005:
_chip.capacity = MB(4);
break;

case MX25L8005:
_chip.capacity = MB(8);
break;

default:
_troubleshoot(UNKNOWNCHIP); //Error code for unidentified capacity
} //TODO - Set up other manufaturerIDs in a similar pattern.
}
for (uint8_t j = 0; j < sizeof(_capID); j++) {
if (_chip.capacityID == _capID[j]) {
_chip.capacity = (_memSize[j]);
Expand All @@ -576,7 +595,7 @@
else {
if (_chip.sfdpAvailable) {
#ifdef RUNDIAGNOSTIC
Serial.println("SFDP ID finished.");
Serial.println(F("SFDP ID finished."));
#endif
return true;
}
Expand All @@ -588,7 +607,9 @@
}

if (!_chip.capacity) {

#ifdef RUNDIAGNOSTIC
Serial.println(F("Chip capacity cannot be identified"));
#endif
if (flashChipSize) {
// If a custom chip size is defined
#ifdef RUNDIAGNOSTIC
Expand Down
2 changes: 1 addition & 1 deletion src/SPIFlashSFDP.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 18/04/2018
* Modified by Prajwal Bhattaram - 19/06/2018
Expand Down
9 changes: 5 additions & 4 deletions src/SPIFram.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/06/2018
* Modified by Prajwal Bhattaram - 03/06/2019
*
* This file is part of the Arduino SPIMemory Library. This library is for
* Flash and FRAM memory modules. In its current form it enables reading,
Expand Down Expand Up @@ -117,9 +118,9 @@ float SPIFram::functionRunTime(void) {

//Returns the library version as three bytes
bool SPIFram::libver(uint8_t *b1, uint8_t *b2, uint8_t *b3) {
*b1 = LIBVER;
*b2 = LIBSUBVER;
*b3 = BUGFIXVER;
*b1 = SPIFRAM_LIBVER;
*b2 = SPIFRAM_LIBSUBVER;
*b3 = SPIFRAM_REVVER;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/SPIFram.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/06/2018
*
Expand Down
2 changes: 1 addition & 1 deletion src/SPIFramIO.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/06/2018
*
Expand Down
2 changes: 1 addition & 1 deletion src/SPIMemory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Arduino SPIMemory Library v.3.3.0
/* Arduino SPIMemory Library v.3.4.0
* Copyright (C) 2019 by Prajwal Bhattaram
* Created by Prajwal Bhattaram - 19/05/2015
* Modified by @boseji <salearj@hotmail.com> - 02/03/2017
Expand Down
Loading

0 comments on commit 82db983

Please sign in to comment.