Flash the Nano over WiFi through the ESP32

- ESP32: NanoFlashBridge on TCP port 2323. A connection power cycles the
  Nano into its bootloader and bridges TCP <-> Serial2 at 57600 baud; the
  clock pauses during the session, 10 s idle timeout
- tools/nano_net_upload.py: STK500v1 uploader over TCP (standard library
  only), with sync retries, write and read-back verification. avrdude 6.3
  net: ports are broken on Windows, so avrdude is not used
- New nano_ota environment: pio run -e nano_ota -t upload
- README: usage, requirements, troubleshooting; TODO for hardware test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-10-13 00:35:28 +02:00
1 parent 8415dee347
commit bea5b9daa1
10 files changed
+438 -7

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include <Arduino.h>
#include <WiFi.h>
// WiFi to serial bridge for flashing the Nano from the PC (pio run -e nano_ota -t upload).
//
// When a TCP client connects, onStart() is called to restart the Nano into its bootloader.
// After that, bytes are copied between the TCP connection and the Nano's serial port
// until the client disconnects or is idle too long. onEnd() is then called.
// The uploader on the PC side is tools/nano_net_upload.py.
class NanoFlashBridge
{
public:
NanoFlashBridge(uint16_t port, HardwareSerial &serial, void (*onStart)(), void (*onEnd)());
void begin();
// Call from loop(). Returns true while a flash session is running; the caller must not
// send anything to the Nano then.
bool handle();
private:
// Give up when no data moves in either direction for this long
static const uint32_t IDLE_TIMEOUT = 10000;
WiFiServer _server;
WiFiClient _client;
HardwareSerial &_serial;
void (*_onStart)();
void (*_onEnd)();
bool _active = false;
uint32_t _last_activity = 0;
void _end();
};