Skip to content

Commit be2303f

Browse files
committed
Merge pull request esp8266#648 from kzyapkov/avrisp
ESP8266AVRISP library
2 parents 85c05e9 + 899c575 commit be2303f

File tree

6 files changed

+907
-0
lines changed

6 files changed

+907
-0
lines changed

libraries/ESP8266AVRISP/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# AVR In-System Programming over WiFi for ESP8266
2+
3+
This library allows an ESP8266 module with the HSPI port available to become
4+
an AVR In-System Programmer.
5+
6+
## Hardware
7+
8+
The ESP8266 module connects to the AVR target chip via the standard 6-pin
9+
AVR "Recommended In-System Programming Interface Connector Layout" as seen
10+
in [AVR910](http://www.atmel.com/images/doc0943.pdf) among other places.
11+
12+
If the AVR target is powered by a different Vcc than what powers your ESP8266
13+
chip, you **must provide voltage level shifting** or some other form of buffers.
14+
Exposing the pins of ESP8266 to anything larger than 3.6V will damage it.
15+
16+
Connections are as follows:
17+
18+
ESP8266 | AVR / SPI
19+
--------|------------
20+
GPIO12 | MISO
21+
GPIO13 | MOSI
22+
GPIO14 | SCK
23+
any* | RESET
24+
25+
For RESET use a GPIO other than 0, 2 and 15 (bootselect pins), and apply an
26+
external pullup/down so that the target is normally running.
27+
28+
## Usage
29+
30+
See the included example. In short:
31+
32+
```arduino
33+
34+
// Create the programmer object
35+
ESP8266AVRISP avrprog(PORT, RESET_PIN)
36+
// ... with custom SPI frequency
37+
ESP8266AVRISP avrprog(PORT, RESET_PIN, 4e6)
38+
39+
// Check current connection state, but don't perform any actions
40+
AVRISPState_t state = avrprog.update();
41+
42+
// Serve the pending connection, execute STK500 commands
43+
AVRISPState_t state = avrprog.serve();
44+
```
45+
46+
### License and Authors
47+
48+
This library started off from the source of ArduinoISP "sketch" included with
49+
the Arduino IDE:
50+
51+
ArduinoISP version 04m3
52+
Copyright (c) 2008-2011 Randall Bohn
53+
If you require a license, see
54+
http://www.opensource.org/licenses/bsd-license.php
55+
56+
Support for TCP on ESP8266
57+
Copyright (c) Kiril Zyapkov <[email protected]>.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <SPI.h>
2+
#include <ESP8266WiFi.h>
3+
#include <ESP8266mDNS.h>
4+
#include <ESP8266AVRISP.h>
5+
6+
const char* host = "esp8266-avrisp";
7+
const char* ssid = "**********";
8+
const char* pass = "**********";
9+
const uint16_t port = 328;
10+
const uint8_t reset_pin = 5;
11+
12+
ESP8266AVRISP avrprog(port, reset_pin);
13+
14+
void setup() {
15+
Serial.begin(115200);
16+
Serial.println("");
17+
Serial.println("Arduino AVR-ISP over TCP");
18+
avrprog.setReset(false); // let the AVR run
19+
20+
WiFi.begin(ssid, pass);
21+
while (WiFi.waitForConnectResult() != WL_CONNECTED);
22+
23+
MDNS.begin(host);
24+
MDNS.addService("avrisp", "tcp", port);
25+
26+
IPAddress local_ip = WiFi.localIP();
27+
Serial.print("IP address: ");
28+
Serial.println(local_ip);
29+
Serial.println("Use your avrdude:");
30+
Serial.print("avrdude -c arduino -p <device> -P net:");
31+
Serial.print(local_ip);
32+
Serial.print(":");
33+
Serial.print(port);
34+
Serial.println(" -t # or -U ...");
35+
36+
// listen for avrdudes
37+
avrprog.begin();
38+
}
39+
40+
void loop() {
41+
static AVRISPState_t last_state = AVRISP_STATE_IDLE;
42+
AVRISPState_t new_state = avrprog.update();
43+
if (last_state != new_state) {
44+
switch (new_state) {
45+
case AVRISP_STATE_IDLE: {
46+
Serial.printf("[AVRISP] now idle\r\n");
47+
// Use the SPI bus for other purposes
48+
break;
49+
}
50+
case AVRISP_STATE_PENDING: {
51+
Serial.printf("[AVRISP] connection pending\r\n");
52+
// Clean up your other purposes and prepare for programming mode
53+
break;
54+
}
55+
case AVRISP_STATE_ACTIVE: {
56+
Serial.printf("[AVRISP] programming mode\r\n");
57+
// Stand by for completion
58+
break;
59+
}
60+
}
61+
last_state = new_state;
62+
}
63+
// Serve the client
64+
if (last_state != AVRISP_STATE_IDLE) {
65+
avrprog.serve();
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ESP8266AVRISP
2+
version=1.0
3+
author=Kiril Zyapkov
4+
maintainer=Kiril Zyapkov <[email protected]>
5+
sentence=AVR In-System Programming over WiFi for ESP8266
6+
paragraph=This library allows programming 8-bit AVR ICSP targets via TCP over WiFi with ESP8266.
7+
category=Communication
8+
url=
9+
architectures=esp8266

0 commit comments

Comments
 (0)