Skip to content

Commit 8467be4

Browse files
committed
Adding minimum example to README file and mention the need for formatting
1 parent fa28443 commit 8467be4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Arduino MKRMEM
22
This library provides a driver for the Arduino MKR MEM shield W25Q16DV SPI flash (with a capacity of 2 MByte) complete with integration for the [SPIFFS](https://github.com/pellepl/spiffs) embedded flash file system (EFFS).
33

4+
**Attention**: Before you can use SPIFFS you need to erase and format the flash memory chip using [SPIFFSFormat.ino](examples/SPIFFSFormat/SPIFFSFormat.ino).
5+
46
## Why use an EFFS?
57
The usage of semiconductor based flash memories differs fundamentally from other devices such as magnetic based hard discs. In flash terminology you don't write to memory but you **program** it. When a flash memory is programmed the default state of the flash memory (all bits equal to 1) is changed to the desired value. Note that you can only change bits from 1 to 0, in order to change a bit to 1 again an **erase operation** has to be performed. Such an erase operation can not be performed for each individual bit, only a bit block of bits and bytes can be "erased" together. The smallest possible erase size for the W25Q16DV is 4 kByte (sector erase). Also you can not just program any address on the flash, programming is usually performed **page-by-page**. The W25Q16DV page size is 256 bytes.
68

@@ -11,3 +13,34 @@ When a maximum number of program / erase cycles (≥ 10^5) are exceeded the flas
1113
The goals of garbage collection (maximizing the free sectors) and wear-leveling (even utilization of all sectors) are in conflict with one another. To get both sufficient performance and endurance, a good trade-off must be found between these two tasks.
1214

1315
So while the usage of an embedded flash file system comes with a bit of overhead, it is the only way to reasonably ensure successful long-term operation of flash memories.
16+
17+
## How to use
18+
19+
```C++
20+
#include <Arduino_MKRMEM.h>
21+
/* ... */
22+
static char const PANGRAM[] = "The quick brown fox jumps over the lazy dog.";
23+
/* ... */
24+
void setup()
25+
{
26+
Serial.begin();
27+
flash.begin();
28+
/* ... */
29+
if(SPIFFS_OK != filesystem.mount()) {
30+
Serial.println("mount() failed with error code "); Serial.println(filesystem.err()); return;
31+
}
32+
/* ... */
33+
File file = filesystem.open("fox.txt", CREATE | READ_WRITE| TRUNCATE);
34+
/* ... */
35+
file.write((void *)PANGRAM, strlen(PANGRAM));
36+
/* ... */
37+
file.lseek(0, START); /* Rewind file pointer to the start */
38+
char buf[64] = {0};
39+
int const bytes_read = file.read(buf, sizeof(buf));
40+
buf[bytes_read] = '\0';
41+
Serial.println(buf);
42+
/* ... */
43+
file.close();
44+
filesystem.unmount();
45+
}
46+
```

0 commit comments

Comments
 (0)