Skip to content
This repository has been archived by the owner on Sep 2, 2019. It is now read-only.

Commit

Permalink
DM: working GD25Q
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm1278 committed Apr 16, 2018
1 parent 3b3142f commit 745f054
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 24 deletions.
10 changes: 10 additions & 0 deletions Adafruit_QSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ void Adafruit_QSPI::runInstruction(const QSPIInstr *instr, uint32_t addr, uint8_
QSPI->INTFLAG.bit.INSTREND = 1;
}

/**************************************************************************/
/*!
@brief Run a single QSPI instruction. This should only be used for single byte instructions that do not read or write data or require an address.
@param instr pointer to the struct containing instruction settings
*/
/**************************************************************************/
void Adafruit_QSPI::runInstruction(const QSPIInstr *instr){
runInstruction(instr, 0, NULL, NULL, 0);
}

/**************************************************************************/
/*!
@brief transfer data via QSPI
Expand Down
2 changes: 2 additions & 0 deletions Adafruit_QSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ typedef enum {
QSPI_WRITE_MEMORY,
} QSPITransferType_t;

#define QSPI_OPTION_NONE 0 ///< no option
#define QSPI_OPTION_INSTREN QSPI_INSTRFRAME_INSTREN ///< enable sending of instruction
#define QSPI_OPTION_ADDREN QSPI_INSTRFRAME_ADDREN ///< enable sending of address
#define QSPI_OPTION_OPCODEEN QSPI_INSTRFRAME_OPTCODEEN ///< enable sending of opcode
Expand Down Expand Up @@ -159,6 +160,7 @@ class Adafruit_QSPI
void begin();
void end(); ///< de-init the peripheral

void runInstruction(const QSPIInstr *instr);
void runInstruction(const QSPIInstr *instr, uint32_t addr, uint8_t *txData, uint8_t *rxData, uint32_t size);

void setMemoryMode(QSPIMode_t mode);
Expand Down
55 changes: 33 additions & 22 deletions Adafruit_QSPI_GD25Q.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,55 @@
#include "Adafruit_QSPI_GD25Q.h"

enum {
GD25Q_READ_STATUS_2 = 0,
GD25Q_READ_STATUS_3,
GD25Q_WRITE_ENABLE_STATUS,
GD25Q_READ_STATUS = 0,
GD25Q_READ_STATUS1,
GD25Q_WRITE_ENABLE_VOLATILE_STATUS,
};

static const QSPIInstr cmdSetGD25Q[] = {
//read status 2
{ 0x35, false, QSPI_ADDRLEN_24_BITS, QSPI_OPCODE_LEN_NONE, QSPI_IO_FORMAT_SINGLE, (QSPI_OPTION_INSTREN | QSPI_OPTION_DATAEN | QSPI_OPTION_ADDREN), QSPI_READ, 0 },
//read status 3
{ 0x33, false, QSPI_ADDRLEN_24_BITS, QSPI_OPCODE_LEN_NONE, QSPI_IO_FORMAT_SINGLE, (QSPI_OPTION_INSTREN | QSPI_OPTION_DATAEN | QSPI_OPTION_ADDREN), QSPI_READ, 0 },
//write enable status
{ 0x50, false, QSPI_ADDRLEN_NONE, QSPI_OPCODE_LEN_NONE, QSPI_IO_FORMAT_SINGLE, (QSPI_OPTION_INSTREN), QSPI_READ, 0 },
//read status
{ 0x05, false, QSPI_ADDRLEN_NONE, QSPI_OPCODE_LEN_NONE, QSPI_IO_FORMAT_SINGLE, (QSPI_OPTION_INSTREN | QSPI_INSTRFRAME_DATAEN), QSPI_READ, 0 },
//read status1
{ 0x35, false, QSPI_ADDRLEN_NONE, QSPI_OPCODE_LEN_NONE, QSPI_IO_FORMAT_SINGLE, (QSPI_OPTION_INSTREN | QSPI_INSTRFRAME_DATAEN), QSPI_READ, 0 },
//write enable volatile status
{ 0x50, false, QSPI_ADDRLEN_NONE, QSPI_OPCODE_LEN_NONE, QSPI_IO_FORMAT_SINGLE, (QSPI_OPTION_INSTREN), QSPI_WRITE, 0 },
};

/**************************************************************************/
/*!
@brief additional commands specific to the GD25Q flash device
@returns true if the device was identified and could be properly set up. False otherwise.
*/
/**************************************************************************/
bool Adafruit_QSPI_GD25Q::begin()
{
Adafruit_QSPI_Generic::begin();

//enable quad
writeStatus(0x22, 0x00);

if (readDeviceID() != 0x14) return false;
if (readManufacturerID() != 0xC8) return false;

uint8_t s2;
QSPI0.runInstruction(&cmdSetGD25Q[GD25Q_READ_STATUS_2], 0, NULL, &s2, 1);
Serial.println(s2,HEX);
return (s2 == 0x02);
_status.reg = 0;
//_status.bit.HPF = 1; //enable high performance mode
_status.bit.QE = 1; //enable quad io

writeStatus();

QSPI0.runInstruction(&cmdSetGD25Q[GD25Q_READ_STATUS], 0, NULL, ((uint8_t *)&_status.reg), 1);
while(_status.bit.WIP){
delay(1);
QSPI0.runInstruction(&cmdSetGD25Q[GD25Q_READ_STATUS], 0, NULL, ((uint8_t *)&_status.reg), 1);
}

QSPI0.runInstruction(&cmdSetGD25Q[GD25Q_READ_STATUS1], 0, NULL, ((uint8_t *)&_status.reg) + 1, 1);
return (_status.bit.QE);
}

void Adafruit_QSPI_GD25Q::writeStatus(byte s1, byte s2, byte s3)
void Adafruit_QSPI_GD25Q::writeStatus()
{
uint8_t c[] = {s1, s2, s3};
uint8_t c[] = {(uint8_t)(_status.reg & 0xFF), (uint8_t)((_status.reg >> 8) & 0xFF)};

uint8_t dummy;
QSPI0.runInstruction(&cmdSetGeneric[ADAFRUIT_QSPI_GENERIC_CMD_WRITE_ENABLE], 0, NULL, &dummy, 1);
QSPI0.runInstruction(&cmdSetGD25Q[GD25Q_WRITE_ENABLE_STATUS], 0, NULL, &dummy, 1);
QSPI0.runInstruction(&cmdSetGeneric[ADAFRUIT_QSPI_GENERIC_CMD_WRITE_ENABLE]);

QSPI0.runInstruction(&cmdSetGeneric[ADAFRUIT_QSPI_GENERIC_CMD_WRITE_STATUS], 0, c, NULL, 3);
QSPI0.runInstruction(&cmdSetGeneric[ADAFRUIT_QSPI_GENERIC_CMD_WRITE_STATUS], 0, c, NULL, 2);
}

26 changes: 25 additions & 1 deletion Adafruit_QSPI_GD25Q.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

#include "Adafruit_QSPI_Generic.h"

/**************************************************************************/
/*!
@brief a class for interfacing with a GD25Q QSPI flash device. http://www.elm-tech.com/en/products/spi-flash-memory/gd25q16/gd25q16.pdf
*/
/**************************************************************************/
class Adafruit_QSPI_GD25Q : public Adafruit_QSPI_Generic {

public:
Expand All @@ -18,7 +23,26 @@ class Adafruit_QSPI_GD25Q : public Adafruit_QSPI_Generic {

bool begin();

void writeStatus(byte s1, byte s2, byte s3);
private:
void writeStatus();

typedef union {
struct {
uint8_t WIP:1;
uint8_t WEL:1;
uint8_t BP:5;
uint8_t SRP0:1;
uint8_t SRP1:1;
uint8_t QE:1;
uint8_t LB:1;
uint8_t :2;
uint8_t HPF:1;
uint8_t CMP:1;
uint8_t SUS:1;
} bit;
uint16_t reg;
} statusRegister;
statusRegister _status;
};


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
/* Test QSPI read and write functionality. Erase chip, write sequential bytes, verify.
*/
#include "Adafruit_QSPI_S25FL1.h"

//Uncomment one of the following lines based on the flash device used

//#define FLASH_DEVICE_S25FL1
#define FLASH_DEVICE_GD25Q
//#define FLASH_DEVICE_GENERIC

#ifdef FLASH_DEVICE_GD25Q

#include "Adafruit_QSPI_GD25Q.h"
Adafruit_QSPI_GD25Q flash;
#elif defined(FLASH_DEVICE_S25FL1)
#include "Adafruit_QSPI_S25FL1.h"
Adafruit_QSPI_S25FL1 flash;
#elif defined(FLASH_DEVICE_S25FL1)
#include "Adafruit_QSPI_Generic.h"
Adafruit_QSPI_Generic flash;
#else
#error "Flash Device not supported."
#endif

#define PROGSIZE 512

Expand Down

0 comments on commit 745f054

Please sign in to comment.