Skip to content

Commit 7476498

Browse files
committed
Split example sketch guide into dedicated per-sketch pages
1 parent df265c7 commit 7476498

9 files changed

Lines changed: 400 additions & 312 deletions

File tree

docs/guide/example-sketches.md

Lines changed: 20 additions & 312 deletions
Original file line numberDiff line numberDiff line change
@@ -1,323 +1,31 @@
11
# Example Sketches Guide (Troubleshooting + Learning)
22

3-
The bundled examples are one of the best parts of this library. This page explains what each one does, what success looks like, and what failures mean.
3+
This page is now the hub. Each bundled example has its own dedicated documentation page.
44

5-
## `FlashDiagnostics/FlashDiagnostics.ino`
5+
## Recommended Beginner Order
66

7-
### Exact test inventory (every operation it executes)
7+
1. [FlashDiagnostics.ino](examples/flashdiagnostics.md)
8+
2. [TestFlash.ino](examples/testflash.md)
9+
3. [readWriteString.ino](examples/readwritestring.md)
10+
4. [getAddressEx.ino](examples/getaddressex.md)
11+
5. [Struct_writer.ino](examples/struct-writer.md)
12+
6. [Diagnostics_functions.ino](examples/diagnostics-functions.md)
813

9-
Identity and metadata (from `getID()`):
14+
## Per-Sketch Pages
1015

11-
- `flash.libver(&_ver, &_subver, &_bugfix)` (when `LIBVER` is enabled)
12-
- `flash.getJEDECID()`
13-
- `flash.getCapacity()`
14-
- `flash.getMaxPage()`
15-
- `flash.getUniqueID()`
16+
- [FlashDiagnostics.ino](examples/flashdiagnostics.md)
17+
- [TestFlash.ino](examples/testflash.md)
18+
- [getAddressEx.ino](examples/getaddressex.md)
19+
- [readWriteString.ino](examples/readwritestring.md)
20+
- [Struct_writer.ino](examples/struct-writer.md)
21+
- [Diagnostics_functions.ino](examples/diagnostics-functions.md)
1622

17-
Power tests:
23+
## What You Get On Each Page
1824

19-
- `flash.powerDown()`
20-
- `flash.powerUp()`
21-
22-
Erase tests:
23-
24-
- `flash.eraseChip()`
25-
- `flash.eraseSection(_addr, KB(72))`
26-
- `flash.eraseBlock64K(_addr)`
27-
- `flash.eraseBlock32K(_addr)`
28-
- `flash.eraseSector(_addr)` (4 KB)
29-
30-
Primitive data write/read tests:
31-
32-
- `flash.writeByte(addr, 35)` + `flash.readByte(addr)`
33-
- `flash.writeChar(addr, -110)` + `flash.readChar(addr)`
34-
- `flash.writeWord(addr, 4520)` + `flash.readWord(addr)`
35-
- `flash.writeShort(addr, -1250)` + `flash.readShort(addr)`
36-
- `flash.writeULong(addr, 876532)` + `flash.readULong(addr)`
37-
- `flash.writeLong(addr, -10959)` + `flash.readLong(addr)`
38-
- `flash.writeFloat(addr, 3.14)` + `flash.readFloat(addr)`
39-
40-
Higher-level data tests:
41-
42-
- `flash.writeStr(addr, "This is a test String 123!@#")` + `flash.readStr(addr, _data)`
43-
- `flash.writeAnything(addr, testStruct)` + `flash.readAnything(addr, testStructOut)`
44-
- `flash.writeByteArray(addr, _d, 256)` + `flash.readByteArray(addr, _data, 256)`
45-
46-
Timing and diagnostics:
47-
48-
- `flash.functionRunTime()` is sampled after each operation to print runtime columns.
49-
- PASS/FAIL is decided by value comparison in each test function.
50-
51-
### Why run it first
52-
53-
It gives broad signal quickly: if this sketch fails, fix hardware/config before writing app logic.
54-
55-
### Expected success signs
56-
57-
- JEDEC ID prints non-zero.
58-
- Function tests report pass.
59-
- Read values match written values.
60-
61-
### Expected serial output (sample)
62-
63-
```text
64-
Initialising..........
65-
66-
SPIMemory Library version: 3.x.x
67-
68-
JEDEC ID: 0xEF4017
69-
Man ID: 0xEF
70-
Memory ID: 0x40
71-
Capacity: 8388608
72-
Max Pages: 32768
73-
Unique ID: ...
74-
75-
----------------------------------------------------------------
76-
Testing library code
77-
----------------------------------------------------------------
78-
...
79-
Byte PASS
80-
Char PASS
81-
Word PASS
82-
Short PASS
83-
ULong PASS
84-
Long PASS
85-
Float PASS
86-
Struct PASS
87-
Array PASS
88-
String PASS
89-
```
90-
91-
### Warning output to watch for
92-
93-
```text
94-
No comms. Check wiring. Is chip supported?
95-
```
96-
97-
or repeated `FAIL` rows in erase/data sections.
98-
99-
### Common failure patterns
100-
101-
- Fails immediately: wiring/CS/board SPI mismatch.
102-
- Write tests fail: region not erased, `WP/HOLD` pin state, unstable power.
103-
- Mixed intermittent failures: clock too fast, shared SPI bus interference.
104-
105-
---
106-
107-
## `TestFlash/TestFlash.ino`
108-
109-
### What it is
110-
111-
Interactive serial command tester for direct operation-by-operation checks.
112-
113-
### Best use
114-
115-
Use this when you want to isolate a single failing operation (`writeByte`, `eraseSector`, `readStr`, etc.) without full diagnostics noise.
116-
117-
### Full command map (all interactive commands)
118-
119-
1. `getJEDECID` and component ID bytes
120-
2. `writeByte(addr, byte)`
121-
3. `readByte(addr)`
122-
4. `writeWord(addr, word)`
123-
5. `readWord(addr)`
124-
6. `writeStr(addr, inputString)`
125-
7. `readStr(addr, outputString)`
126-
8. `writeByteArray(addr, pageBuffer, SPI_PAGESIZE)` where `pageBuffer` is `0..255`
127-
9. `readByteArray(addr, data_buffer, SPI_PAGESIZE)` via `printPage`
128-
10. Full-chip dump: loops through flash and calls `readByteArray` repeatedly in `printAllPages`
129-
11. `eraseSector(addr)` (4 KB)
130-
12. `eraseBlock32K(addr)`
131-
13. `eraseBlock64K(addr)`
132-
14. `eraseChip()`
133-
134-
### Tips
135-
136-
- Set Serial Monitor to expected line ending mode from sketch notes.
137-
- Test simple operations first (`getID`, `writeByte` + `readByte`).
138-
- Move to erase and string operations after basics pass.
139-
140-
### Expected serial output (sample)
141-
142-
On boot:
143-
144-
```text
145-
Initialising..........
146-
...
147-
Please pick from the following commands...
148-
1. getID
149-
2. writeByte [address] [byte]
150-
3. readByte [address]
151-
...
152-
14. Erase Chip
153-
```
154-
155-
When running command `1`:
156-
157-
```text
158-
Function 1 : Get JEDEC ID
159-
Manufacturer ID: efh
160-
Memory Type: 40h
161-
Capacity: 17h
162-
JEDEC ID: ef4017h
163-
```
164-
165-
When running `2` then `3` on same address:
166-
167-
```text
168-
Function 2 : Write Byte
169-
... has been written to address ...
170-
171-
Function 3 : Read Byte
172-
The byte at address ... is: ...
173-
```
174-
175-
---
176-
177-
## `getAddressEx/getAddressEx.ino`
178-
179-
### What it teaches
180-
181-
How to use `getAddress()` and `sizeofStr()` to allocate addresses safely without hardcoding offsets.
182-
183-
### Exact API calls used
184-
185-
- Allocation:
186-
- `flash.getAddress(sizeof(byte))`
187-
- `flash.getAddress(sizeof(float))`
188-
- `flash.getAddress(flash.sizeofStr(testStr[i]))`
189-
- Byte I/O:
190-
- `flash.writeByte(byteAddr[i], testByte[i])`
191-
- `flash.readByte(byteAddr[i])`
192-
- Float I/O:
193-
- `flash.writeFloat(floatAddr[i], testFloat[i])`
194-
- `flash.readFloat(floatAddr[i])`
195-
- String I/O:
196-
- `flash.writeStr(strAddr[i], testStr[i])`
197-
- `flash.readStr(strAddr[i], _string)`
198-
199-
### Troubleshooting value
200-
201-
If this fails, you may have pre-written data conflicts or boundary behavior confusion.
202-
203-
### Expected serial output (sample)
204-
205-
```text
206-
Initialising Flash memory..........
207-
208-
Byte Address 0 : 0x...
209-
Byte Address 1 : 0x...
210-
Float Address 0 : 0x...
211-
String Address 0 : 0x...
212-
213-
3 written to 0x...
214-
3 read from 0x...
215-
3.1415 written to 0x...
216-
3.1415 read from 0x...
217-
'Test String 0' written to 0x...
218-
'Test String 0' read from 0x...
219-
```
220-
221-
Addresses should be valid hex values and read-back values should match writes.
222-
223-
---
224-
225-
## `readWriteString/readWriteString.ino`
226-
227-
### What it teaches
228-
229-
Simple `writeStr`/`readStr` workflow.
230-
231-
### Exact API calls used
232-
233-
- `flash.getCapacity()` (for random address generation)
234-
- `flash.writeStr(strAddr, inputString)`
235-
- `flash.readStr(strAddr, outputString)`
236-
- `flash.eraseSector(strAddr)` (cleanup after test)
237-
238-
### Troubleshooting value
239-
240-
Great for catching string-specific issues (length metadata, readback integrity, sector erase assumptions).
241-
242-
### Expected serial output (sample)
243-
244-
```text
245-
Written string: This is a test String
246-
To address: 123456
247-
Read string: This is a test String
248-
From address: 123456
249-
```
250-
251-
The written/read strings should be identical and the address should match in both lines.
252-
253-
---
254-
255-
## `Struct_writer/Struct_writer.ino`
256-
257-
### What it teaches
258-
259-
Write/read complete structs repeatedly, including nested members and arrays.
260-
261-
### Exact API calls used
262-
263-
- `flash.getCapacity()` (random target address range)
264-
- `flash.eraseSection(_addr, sizeof(configurationIn))`
265-
- `flash.writeAnything(_addr, configurationIn)`
266-
- `flash.readAnything(_addr, configurationOut)`
267-
268-
Loop behavior detail:
269-
270-
- Runs `NUMBEROFREPEATS` iterations (`100` by default).
271-
- Tracks `eraseCount`, `writeCount`, `errorCount`, `readCount`.
272-
- Final summary prints all counters.
273-
274-
### Troubleshooting value
275-
276-
Use this for data-model persistence validation. If this fails while primitive tests pass, inspect struct layout assumptions and erase coverage.
277-
278-
### Expected serial output (sample)
279-
280-
```text
281-
Initialising Flash memory..........
282-
1
283-
2
284-
3
285-
...
286-
100
287-
288-
----------------------------------------------------------------
289-
Final results
290-
----------------------------------------------------------------
291-
No. of successful erases: 100
292-
No. of successful writes: 100
293-
No. of errors generated: 0 (errorCheck function failures)
294-
No. of successful reads: 100
295-
```
296-
297-
Counts should be close to `NUMBEROFREPEATS` (default `100`), with errors at `0`.
298-
299-
---
300-
301-
## `FlashDiagnostics/Diagnostics_functions.ino`
302-
303-
### What it is
304-
305-
Helper routines used by diagnostics output (formatting, timing presentation, pass/fail display).
306-
307-
### Why it matters
308-
309-
Helps you understand what diagnostics output lines map to which underlying test sections.
310-
311-
### Expected serial behavior
312-
313-
This file does not run as a standalone sketch. It provides helper print functions used by `FlashDiagnostics.ino`, including:
314-
315-
- line separators (`printLine`)
316-
- PASS/FAIL formatting (`pass`)
317-
- runtime formatting (`printTimer`, `printTime`)
318-
- ID printing (`getID`, `printUniqueID`)
319-
320-
If formatting looks wrong in diagnostics output, this helper file is the first place to inspect.
25+
- exact API call inventory used by the sketch
26+
- expected serial output samples
27+
- failure signals and common root causes
28+
- practical debugging interpretation
32129

32230
### Helper functions defined in this file
32331

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Diagnostics_functions.ino
2+
3+
Sketch path: `examples/FlashDiagnostics/Diagnostics_functions.ino`
4+
5+
## Purpose
6+
7+
Provide helper routines consumed by `FlashDiagnostics.ino`.
8+
9+
## What This File Defines
10+
11+
Formatting helpers:
12+
13+
- `printLine`
14+
- `printTab`
15+
- `printTime`
16+
- `printTimer`
17+
- `pass`
18+
19+
Identity and metadata helpers:
20+
21+
- `printUniqueID`
22+
- `getID`
23+
24+
Test routines called by `FlashDiagnostics.ino`:
25+
26+
- power: `powerDownTest`, `powerUpTest`
27+
- erase: `eraseChipTest`, `eraseSectionTest`, `eraseBlock64KTest`, `eraseBlock32KTest`, `eraseSectorTest`
28+
- data: `byteTest`, `charTest`, `wordTest`, `shortTest`, `uLongTest`, `longTest`, `floatTest`, `structTest`, `arrayTest`, `stringTest`
29+
30+
## Important Note
31+
32+
This is not intended as a standalone sketch to upload directly. It is a companion source file used by `FlashDiagnostics.ino`.
33+
34+
## When To Read This Page
35+
36+
- diagnostics output formatting looks wrong
37+
- you need to map a failing table row back to exact test routine
38+
- you are extending diagnostics with new data-type checks

0 commit comments

Comments
 (0)