Skip to content

Commit

Permalink
Merge pull request #1 from fprwi6labs/dev
Browse files Browse the repository at this point in the history
Add source files
  • Loading branch information
fpistm authored Sep 21, 2017
2 parents b39ec1b + 73892c8 commit 818b608
Show file tree
Hide file tree
Showing 11 changed files with 2,276 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
# MX25R6435F
Arduino library to support the Quad-SPI NOR Flash memory MX25R6435F

## API

The library provides the following API:

* begin()
* end()
* write()
* read()
* mapped()
* erase()
* eraseChip()
* eraseSector()
* suspendErase()
* resumeErase()
* sleep()
* wakeup()
* status()
* info()
* length()

## Examples

3 sketches provide basic examples to show how to use the library API.
demo.ino uses basic read/write functions.
eraseChip.ino erases all data present in the memory.
memoryMappedMode.ino shows how to use the mapped mode.

## Documentation

You can find the source files at
https://github.com/stm32duino/MX25R6435F

The MX25R6435F datasheet is available at
http://www.mxic.com.tw/Lists/Datasheet/Attachments/6270/MX25R6435F,%20Wide%20Range,%2064Mb,%20v1.4.pdf
128 changes: 128 additions & 0 deletions examples/demo/demo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* demo
*
* This sketch show how to use the mx25r6435f driver.
*
*/

#include <MX25R6435F.h>

#define BUFFER_SIZE ((uint32_t)0x0100)
#define WRITE_READ_ADDR ((uint32_t)0x0050)

uint8_t aTxBuffer[BUFFER_SIZE];
uint8_t aRxBuffer[BUFFER_SIZE];

static void Fill_Buffer (uint8_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset);
static uint8_t Buffercmp (uint8_t* pBuffer1, uint8_t* pBuffer2, uint32_t BufferLength);

void setup() {
Serial.begin(9600);
}

void loop() {
uint8_t status;

Serial.println("*****************************************************************");
Serial.println("*********************** Memory Test *****************************");
Serial.println("*****************************************************************");

MX25R6435F.end();

/*##-1- Configure the device ##########################################*/
/* Device configuration */
MX25R6435F.begin();
status = MX25R6435F.status();

if ((status == MEMORY_ERROR) || (status == MEMORY_SUSPENDED) || (status == MEMORY_BUSY))
{
Serial.println("Init : FAILED, Test Aborted");
}
else
{
Serial.println("Init : OK");

/*##-2- Read & check the info #######################################*/
if( (MX25R6435F.info(MEMORY_SIZE) != 0x800000) ||
(MX25R6435F.info(MEMORY_SECTOR_SIZE) != 0x1000) ||
(MX25R6435F.info(MEMORY_PAGE_SIZE) != 0x100) ||
(MX25R6435F.info(MEMORY_SECTOR_NUMBER) != 2048) ||
(MX25R6435F.info(MEMORY_PAGE_NUMBER) != 32768))
{
Serial.println("GET INFO : FAILED, Test Aborted");
}
else
{
Serial.println("GET INFO : OK");

/*##-3- Erase memory ################################################*/
if(MX25R6435F.erase(WRITE_READ_ADDR) != MEMORY_OK)
{
Serial.println("ERASE : FAILED, Test Aborted");
}
else
{
Serial.println("ERASE : OK");

/*##-4- memory read/write access #################################*/
/* Fill the buffer to write */
Fill_Buffer(aTxBuffer, BUFFER_SIZE, 0xD20F);

/* Write data to the QSPI memory */
if(MX25R6435F.write(aTxBuffer, WRITE_READ_ADDR, BUFFER_SIZE) == 0)
{
Serial.println("WRITE : FAILED, Test Aborted");
}
else
{
Serial.println("WRITE : OK");

/* Read back data from the QSPI memory */
MX25R6435F.read(aRxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);

/*##-5- Checking data integrity ############################################*/
if(Buffercmp(aRxBuffer, aTxBuffer, BUFFER_SIZE) > 0)
{
Serial.println("COMPARE : FAILED, Test Aborted");
}
else
{
Serial.println("Test : OK");
}
}
}
}
}

// Enables the deep power mode
MX25R6435F.sleep();
delay(5000);
MX25R6435F.wakeup();
}

static void Fill_Buffer(uint8_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset)
{
uint32_t tmpIndex = 0;

/* Put in global buffer different values */
for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++ )
{
pBuffer[tmpIndex] = tmpIndex + uwOffset;
}
}

static uint8_t Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint32_t BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return 1;
}

pBuffer1++;
pBuffer2++;
}

return 0;
}
27 changes: 27 additions & 0 deletions examples/eraseChip/eraseChip.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* eraseChip
*
* Sets all of the bytes of the memory to the default value (0xFF).
* Could take until 240 seconds to erase all the memory (worst conditions).
*
*/

#include <MX25R6435F.h>

void setup() {
// initialize the LED pin as an output.
pinMode(LED_BUILTIN, OUTPUT);

// initialize the MX25R6435F flash memory
MX25R6435F.begin();

// erase all the memory: set byte to 0xFF
MX25R6435F.eraseChip();

// turn the LED on when we're done
digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {
/** Empty loop. **/
}
131 changes: 131 additions & 0 deletions examples/memoryMappedMode/memoryMappedMode.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* memoryMappedMode
*
* This sketch show how to use the mx25r6435f driver and the memory mapped mode.
*
*/

#include <MX25R6435F.h>

#define BUFFER_SIZE ((uint32_t)0x0100)
#define WRITE_READ_ADDR ((uint32_t)0x0050)

uint8_t aTxBuffer[BUFFER_SIZE];
uint8_t aRxBuffer[BUFFER_SIZE];

static void Fill_Buffer (uint8_t *pBuffer, uint32_t uwBufferLength, uint32_t uwOffset);

void setup() {
Serial.begin(9600);
}

void loop() {
/* QSPI info structure */
uint8_t status, read_status = 0;
uint16_t index = 0;
uint8_t *mem_addr;

Serial.println("*****************************************************************");
Serial.println("********************* Memory mapped Test ************************");
Serial.println("*****************************************************************");

MX25R6435F.end();

/*##-1- Configure the device ##########################################*/
/* Device configuration */
MX25R6435F.begin();
status = MX25R6435F.status();

if ((status == MEMORY_ERROR) || (status == MEMORY_SUSPENDED) || (status == MEMORY_BUSY))
{
Serial.println("Init : FAILED, Test Aborted");
}
else
{
Serial.println("Init : OK");

/*##-2- Read & check the info #######################################*/
if( (MX25R6435F.info(MEMORY_SIZE) != 0x800000) ||
(MX25R6435F.info(MEMORY_SECTOR_SIZE) != 0x1000) ||
(MX25R6435F.info(MEMORY_PAGE_SIZE) != 0x100) ||
(MX25R6435F.info(MEMORY_SECTOR_NUMBER) != 2048) ||
(MX25R6435F.info(MEMORY_PAGE_NUMBER) != 32768))
{
Serial.println("GET INFO : FAILED, Test Aborted");
}
else
{
Serial.println("GET INFO : OK");

/*##-3- Erase memory ################################################*/
if(MX25R6435F.erase(WRITE_READ_ADDR) != MEMORY_OK)
{
Serial.println("ERASE : FAILED, Test Aborted");
}
else
{
Serial.println("ERASE : OK");

/*##-4- memory read/write access #################################*/
/* Fill the buffer to write */
Fill_Buffer(aTxBuffer, BUFFER_SIZE, 0xD20F);

for(uint32_t i = 0; i < 1; i++)
{
if(MX25R6435F.write(aTxBuffer, (i * 0x100), BUFFER_SIZE) != BUFFER_SIZE)
{
Serial.println("WRITE : FAILED, Test Aborted");
}
}

/* Read back data from the QSPI memory */
mem_addr = MX25R6435F.mapped();

if(mem_addr != NULL) {
for(uint32_t i = 0; i < 1; i++)
{
mem_addr += (i * 0x100);
for (index = 0; index < BUFFER_SIZE; index++)
{
if (*mem_addr != aTxBuffer[index])
{
read_status++;
Serial.println(read_status);
}
mem_addr++;
}
}


if(read_status != 0)
{
Serial.println("READ : FAILED");
Serial.println("Test Aborted");
}
else
{
Serial.println("READ : OK");
Serial.println("Test : OK");

}
} else {
Serial.println("MAPPED MODE : FAILED");
Serial.println("Test Aborted");
}
}
}
}

delay(5000);
}

static void Fill_Buffer(uint8_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset)
{
uint32_t tmpIndex = 0;

/* Put in global buffer different values */
for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++ )
{
pBuffer[tmpIndex] = tmpIndex + uwOffset;
}
}
42 changes: 42 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#######################################
# Syntax Coloring Map MX25R6435F
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

MX25R6435F KEYWORD

#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2
write KEYWORD2
read KEYWORD2
mapped KEYWORD2
erase KEYWORD2
eraseSector KEYWORD2
eraseChip KEYWORD2
suspendErase KEYWORD2
resumeErase KEYWORD2
sleep KEYWORD2
wakeup KEYWORD2
status KEYWORD2
info KEYWORD2
length KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
MEMORY_SIZE LITERAL1
MEMORY_SECTOR_SIZE LITERAL1
MEMORY_SECTOR_NUMBER LITERAL1
MEMORY_PAGE_SIZE LITERAL1
MEMORY_PAGE_NUMBER LITERAL1
MEMORY_OK LITERAL1
MEMORY_ERROR LITERAL1
MEMORY_BUSY LITERAL1
MEMORY_NOT_SUPPORTED LITERAL1
MEMORY_SUSPENDED LITERAL1
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=MX25R6435F
version=1.0.0
author=Wi6Labs
maintainer=stm32duino
sentence=Quad-SPI NOR Flash memory library.
paragraph=This library provides Arduino support for the 64-Mbit Quad-SPI NOR Flash memory MX25R6435F connected to the Quad-SPI interface of a STM32 board.
category=Data Storage
url=https://github.com/stm32duino/MX25R6435F
architectures=stm32
Loading

0 comments on commit 818b608

Please sign in to comment.