@@ -36,7 +36,7 @@ class SerialFlashFile; | |||
class SerialFlashChip | |||
{ | |||
public: | |||
static bool begin(); | |||
static bool begin(uint8_t pin = 6); | |||
static uint32_t capacity(const uint8_t *id); | |||
static uint32_t blockSize(); | |||
static void sleep(); |
@@ -28,19 +28,17 @@ | |||
#include "SerialFlash.h" | |||
#include "util/SerialFlash_directwrite.h" | |||
#define CSCONFIG() pinMode(6, OUTPUT) | |||
#define CSASSERT() digitalWriteFast(6, LOW) | |||
#define CSRELEASE() digitalWriteFast(6, HIGH) | |||
#define CSASSERT() DIRECT_WRITE_LOW(cspin_basereg, cspin_bitmask) | |||
#define CSRELEASE() DIRECT_WRITE_HIGH(cspin_basereg, cspin_bitmask) | |||
#define SPICONFIG SPISettings(50000000, MSBFIRST, SPI_MODE0) | |||
#if !defined(__arm__) || !defined(CORE_TEENSY) | |||
#define digitalWriteFast(pin, state) digitalWrite((pin), (state)) | |||
#endif | |||
uint16_t SerialFlashChip::dirindex = 0; | |||
uint8_t SerialFlashChip::flags = 0; | |||
uint8_t SerialFlashChip::busy = 0; | |||
static volatile IO_REG_TYPE *cspin_basereg; | |||
static IO_REG_TYPE cspin_bitmask; | |||
#define FLAG_32BIT_ADDR 0x01 // larger than 16 MByte address | |||
#define FLAG_STATUS_CMD70 0x02 // requires special busy flag check | |||
#define FLAG_DIFF_SUSPEND 0x04 // uses 2 different suspend commands | |||
@@ -332,14 +330,16 @@ bool SerialFlashChip::ready() | |||
//#define FLAG_DIFF_SUSPEND 0x04 // uses 2 different suspend commands | |||
//#define FLAG_256K_BLOCKS 0x10 // has 256K erase blocks | |||
bool SerialFlashChip::begin() | |||
bool SerialFlashChip::begin(uint8_t pin) | |||
{ | |||
uint8_t id[3]; | |||
uint8_t f; | |||
uint32_t size; | |||
cspin_basereg = PIN_TO_BASEREG(pin); | |||
cspin_bitmask = PIN_TO_BITMASK(pin); | |||
SPI.begin(); | |||
CSCONFIG(); | |||
pinMode(pin, OUTPUT); | |||
CSRELEASE(); | |||
readID(id); | |||
f = 0; | |||
@@ -383,6 +383,8 @@ bool SerialFlashChip::begin() | |||
return true; | |||
} | |||
// chips tested: https://github.com/PaulStoffregen/SerialFlash/pull/12#issuecomment-169596992 | |||
// | |||
void SerialFlashChip::sleep() | |||
{ | |||
if (busy) wait(); |
@@ -2,8 +2,8 @@ | |||
#include <SD.h> | |||
#include <SPI.h> | |||
const int SDchipSelect = 4; // Audio Shield has SD card CS on pin 10 | |||
const int FlashChipSelect = 6; | |||
const int SDchipSelect = 4; // Audio Shield has SD card CS on pin 10 | |||
const int FlashChipSelect = 6; // digital pin for flash chip CS pin | |||
void setup() { | |||
//uncomment these if using Teensy audio shield | |||
@@ -24,7 +24,7 @@ void setup() { | |||
if (!SD.begin(SDchipSelect)) { | |||
error("Unable to access SD card"); | |||
} | |||
if (!SerialFlash.begin()) { | |||
if (!SerialFlash.begin(FlashChipSelect)) { | |||
error("Unable to access SPI Flash chip"); | |||
} | |||
@@ -79,9 +79,10 @@ | |||
//SPI Pins (these are the values on the Audio board; change them if you have different ones) | |||
#define MOSI 7 | |||
#define MOSI 7 | |||
#define MISO 12 | |||
#define SCK 14 | |||
#define SCK 14 | |||
#define CSPIN 6 | |||
void setup(){ | |||
Serial.begin(9600); //Teensy serial is always at full USB speed and buffered... the baud rate here is required but ignored | |||
@@ -92,7 +93,7 @@ void setup(){ | |||
SPI.setMOSI(MOSI); | |||
SPI.setMISO(MISO); | |||
SPI.setSCK(SCK); | |||
SerialFlash.begin(); | |||
SerialFlash.begin(CSPIN); | |||
//We start by formatting the flash... | |||
uint8_t id[3]; |
@@ -1,6 +1,8 @@ | |||
#include <SerialFlash.h> | |||
#include <SPI.h> | |||
const int FlashChipSelect = 6; // digital pin for flash chip CS pin | |||
SerialFlashFile file; | |||
const unsigned long testIncrement = 4096; | |||
@@ -20,7 +22,7 @@ void setup() { | |||
while (!Serial && (millis() - startMillis < 10000)) ; | |||
delay(100); | |||
SerialFlash.begin(); | |||
SerialFlash.begin(FlashChipSelect); | |||
unsigned char id[3]; | |||
SerialFlash.readID(id); | |||
unsigned long size = SerialFlash.capacity(id); |
@@ -1,7 +1,7 @@ | |||
#include <SerialFlash.h> | |||
#include <SPI.h> | |||
const int FlashChipSelect = 6; | |||
const int FlashChipSelect = 6; // digital pin for flash chip CS pin | |||
void setup() { | |||
//uncomment these if using Teensy audio shield | |||
@@ -18,7 +18,7 @@ void setup() { | |||
delay(100); | |||
Serial.println("All Files on SPI Flash chip:"); | |||
if (!SerialFlash.begin()) { | |||
if (!SerialFlash.begin(FlashChipSelect)) { | |||
error("Unable to access SPI Flash chip"); | |||
} | |||
@@ -18,10 +18,11 @@ | |||
// the exact part number and manufacturer of the chip. | |||
#include <SerialFlash.h> | |||
#include <SPI.h> | |||
const int FlashChipSelect = 6; // digital pin for flash chip CS pin | |||
SerialFlashFile file; | |||
const unsigned long testIncrement = 4096; | |||
@@ -41,7 +42,7 @@ void setup() { | |||
delay(100); | |||
Serial.println("Raw SerialFlash Hardware Test"); | |||
SerialFlash.begin(); | |||
SerialFlash.begin(FlashChipSelect); | |||
if (test()) { | |||
Serial.println(); |