Arduino-Storage
External Memory Storage library for Arduino
MC23LCXXX.ino
Go to the documentation of this file.
1 #include "Storage.h"
2 #include "GPIO.h"
3 #include "SPI.h"
4 #include "Driver/MC23LCXXX.h"
5 
6 // Configure: SPI bus manager implementation
7 #define USE_SOFTWARE_SPI
8 
9 #if defined(USE_SOFTWARE_SPI)
10 #include "Software/SPI.h"
11 Software::SPI<BOARD::D11, BOARD::D12, BOARD::D13> spi;
12 #else
13 #include "Hardware/SPI.h"
14 Hardware::SPI spi;
15 #endif
16 
17 // External memory device
19 
20 // Pin assignments are:
21 // SS D10, MOSI D11, MISO D12, SCK D13
22 
23 // Local memory buffer
24 const int BUF_MAX = 1000;
25 static uint8_t buf[BUF_MAX];
26 
27 void setup()
28 {
29  Serial.begin(57600);
30  while (!Serial);
31 }
32 
33 void loop()
34 {
35  static uint8_t n = 0;
36  for (int i = 0; i < BUF_MAX; i++) buf[i] = n + i;
37 
38  Serial.println();
39  Serial.println(F("spi.FREQ(MHz) = 8"));
40  Serial.print(F("sram.SIZE(kbyte) = "));
41  Serial.println(sram.SIZE / 1024);
42  Serial.println();
43 
44  // Benchmark#1: Measure write with increasing buffer size
45  Serial.println(F("write(N, us, us/byte, kbyte/s)"));
46  Serial.flush();
47  for (int i = 1; i < 10000; i *= 10) {
48  uint32_t start = micros();
49  sram.write(0x0000, buf, i);
50  uint32_t us = micros() - start;
51  float uspb = ((float) us) / i;
52  Serial.print(i);
53  Serial.print(F(", "));
54  Serial.print(us);
55  Serial.print(F(", "));
56  Serial.print(uspb);
57  Serial.print(F(", "));
58  Serial.println(1000 / uspb);
59  Serial.flush();
60  }
61  Serial.println();
62 
63  for (int i = 0; i < BUF_MAX; i++) buf[i] = 0;
64 
65  // Benchmark#2: Measure read with increasing buffer size
66  Serial.println(F("read(N, us, us/byte, kbyte/s)"));
67  Serial.flush();
68  for (int i = 1; i < 10000; i *= 10) {
69  uint32_t start = micros();
70  sram.read(buf, 0x0000, i);
71  uint32_t us = micros() - start;
72  float uspb = ((float) us) / i;
73  Serial.print(i);
74  Serial.print(F(", "));
75  Serial.print(us);
76  Serial.print(F(", "));
77  Serial.print(uspb);
78  Serial.print(F(", "));
79  Serial.println(1000 / uspb);
80  Serial.flush();
81  }
82 
83  for (int i = 0; i < BUF_MAX; i++) {
84  if (buf[i] != ((n + i) & 0xff)) {
85  Serial.print(i);
86  Serial.println(F(": verification error"));
87  break;
88  }
89  }
90  n += 1;
91 
92  delay(5000);
93 }
Software::SPI< BOARD::D11, BOARD::D12, BOARD::D13 > spi
Definition: MC23LCXXX.ino:11
static uint8_t buf[BUF_MAX]
Definition: MC23LCXXX.ino:25
void loop()
Definition: MC23LCXXX.ino:33
MC23LC1024< BOARD::D10 > sram(spi)
const int BUF_MAX
Definition: MC23LCXXX.ino:24
void setup()
Definition: MC23LCXXX.ino:27