Skip to content

Commit 824d295

Browse files
committed
docs: add info about NVS support
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 2744d8e commit 824d295

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,61 @@ func main() {
114114
- **Configurable**: Customize baud rate, compression, reset mode, and more
115115
- **USB-JTAG/Serial**: Native USB support for boards like ESP32-S3 and ESP32-C3 that expose a built-in USB-JTAG/Serial interface (typically `/dev/ttyACM0` on Linux, `cu.usbmodem*` on macOS)
116116
- **Stubs**: Use stubs for higher-speed downloads and other advanced processor features
117+
- **NVS support**: Generate and parse ESP-IDF NVS (Non-Volatile Storage) partition images in pure Go
118+
119+
## NVS Package
120+
121+
The `nvs` package provides a pure-Go implementation for generating and parsing [ESP-IDF NVS (Non-Volatile Storage)](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/storage/nvs_flash.html) partition images in the v2 binary format.
122+
123+
### Installation
124+
125+
```bash
126+
go get tinygo.org/x/espflasher/pkg/nvs
127+
```
128+
129+
### Generating an NVS Partition
130+
131+
```go
132+
import "tinygo.org/x/espflasher/pkg/nvs"
133+
134+
entries := []nvs.Entry{
135+
{Namespace: "wifi", Key: "ssid", Type: "string", Value: "MyNetwork"},
136+
{Namespace: "wifi", Key: "channel", Type: "u8", Value: uint8(6)},
137+
{Namespace: "config", Key: "timeout", Type: "u16", Value: uint16(3000)},
138+
{Namespace: "config", Key: "name", Type: "string", Value: "MyDevice"},
139+
}
140+
141+
partition, err := nvs.GenerateNVS(entries, nvs.DefaultPartSize)
142+
if err != nil {
143+
log.Fatal(err)
144+
}
145+
// partition is a []byte ready to flash at the NVS partition offset
146+
```
147+
148+
### Parsing an NVS Partition
149+
150+
```go
151+
entries, err := nvs.ParseNVS(partitionData)
152+
if err != nil {
153+
log.Fatal(err)
154+
}
155+
for _, e := range entries {
156+
fmt.Printf("[%s] %s = %v\n", e.Namespace, e.Key, e.Value)
157+
}
158+
```
159+
160+
### Supported Value Types
161+
162+
| Type | Go Value Type |
163+
|------|---------------|
164+
| `u8` | `uint8` (or `int`) |
165+
| `u16` | `uint16` (or `int`) |
166+
| `u32` | `uint32` (or `int`) |
167+
| `i8` | `int8` (or `int`) |
168+
| `i16` | `int16` (or `int`) |
169+
| `i32` | `int32` (or `int`) |
170+
| `string` | `string` |
171+
| `blob` | `[]byte` |
117172

118173
## Reset Modes
119174

@@ -188,6 +243,7 @@ The library is organized in layers:
188243
| Chip | `pkg/espflasher/chip.go`, `pkg/espflasher/target_*.go` | Per-target definitions and detection |
189244
| Reset | `pkg/espflasher/reset.go` | Hardware reset strategies |
190245
| Flasher | `pkg/espflasher/flasher.go` | High-level flash/verify/reset API |
246+
| NVS | `pkg/nvs/*.go` | Generate and parse NVS partition images |
191247
| CLI | `main.go` | Command-line interface |
192248

193249
## Development

pkg/espflasher/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141
// The protocol uses SLIP framing over serial UART. Commands are sent as
4242
// request packets with an opcode, and the device responds with status.
4343
// Flash writes can optionally use zlib-compressed data for faster transfers.
44-
package espflasher
44+
package espflasher // import "tinygo.org/x/espflasher/pkg/espflasher"

0 commit comments

Comments
 (0)