mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Merge remote-tracking branch 'arduino/master' into platforms-b
This commit is contained in:
@ -133,16 +133,19 @@ public class EditorConsole extends JScrollPane {
|
|||||||
// The files and folders are not deleted on exit because they may be
|
// The files and folders are not deleted on exit because they may be
|
||||||
// needed for debugging or bug reporting.
|
// needed for debugging or bug reporting.
|
||||||
tempFolder = Base.createTempFolder("console");
|
tempFolder = Base.createTempFolder("console");
|
||||||
|
tempFolder.deleteOnExit();
|
||||||
try {
|
try {
|
||||||
String outFileName = Preferences.get("console.output.file");
|
String outFileName = Preferences.get("console.output.file");
|
||||||
if (outFileName != null) {
|
if (outFileName != null) {
|
||||||
outFile = new File(tempFolder, outFileName);
|
outFile = new File(tempFolder, outFileName);
|
||||||
|
outFile.deleteOnExit();
|
||||||
stdoutFile = new FileOutputStream(outFile);
|
stdoutFile = new FileOutputStream(outFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
String errFileName = Preferences.get("console.error.file");
|
String errFileName = Preferences.get("console.error.file");
|
||||||
if (errFileName != null) {
|
if (errFileName != null) {
|
||||||
errFile = new File(tempFolder, errFileName);
|
errFile = new File(tempFolder, errFileName);
|
||||||
|
errFile.deleteOnExit();
|
||||||
stderrFile = new FileOutputStream(errFile);
|
stderrFile = new FileOutputStream(errFile);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -1,15 +1,34 @@
|
|||||||
// this sketch turns the Arduino into a AVRISP
|
// ArduinoISP version 04m3
|
||||||
// using the following pins:
|
// Copyright (c) 2008-2011 Randall Bohn
|
||||||
// 10: slave reset
|
// If you require a license, see
|
||||||
// 11: MOSI
|
// http://www.opensource.org/licenses/bsd-license.php
|
||||||
// 12: MISO
|
//
|
||||||
// 13: SCK
|
// This sketch turns the Arduino into a AVRISP
|
||||||
|
// using the following arduino pins:
|
||||||
|
//
|
||||||
|
// pin name: not-mega: mega(1280 and 2560)
|
||||||
|
// slave reset: 10: 53
|
||||||
|
// MOSI: 11: 51
|
||||||
|
// MISO: 12: 50
|
||||||
|
// SCK: 13: 52
|
||||||
|
//
|
||||||
// Put an LED (with resistor) on the following pins:
|
// Put an LED (with resistor) on the following pins:
|
||||||
// 9: Heartbeat - shows the programmer is running
|
// 9: Heartbeat - shows the programmer is running
|
||||||
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
|
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
|
||||||
// 7: Programming - In communication with the slave
|
// 7: Programming - In communication with the slave
|
||||||
//
|
//
|
||||||
|
// 23 July 2011 Randall Bohn
|
||||||
|
// -Address Arduino issue 509 :: Portability of ArduinoISP
|
||||||
|
// http://code.google.com/p/arduino/issues/detail?id=509
|
||||||
|
//
|
||||||
|
// October 2010 by Randall Bohn
|
||||||
|
// - Write to EEPROM > 256 bytes
|
||||||
|
// - Better use of LEDs:
|
||||||
|
// -- Flash LED_PMODE on each flash commit
|
||||||
|
// -- Flash LED_PMODE while writing EEPROM (both give visual feedback of writing progress)
|
||||||
|
// - Light LED_ERR whenever we hit a STK_NOSYNC. Turn it off when back in sync.
|
||||||
|
// - Use pins_arduino.h (should also work on Arduino Mega)
|
||||||
|
//
|
||||||
// October 2009 by David A. Mellis
|
// October 2009 by David A. Mellis
|
||||||
// - Added support for the read signature command
|
// - Added support for the read signature command
|
||||||
//
|
//
|
||||||
@ -24,12 +43,13 @@
|
|||||||
// - The SPI functions herein were developed for the AVR910_ARD programmer
|
// - The SPI functions herein were developed for the AVR910_ARD programmer
|
||||||
// - More information at http://code.google.com/p/mega-isp
|
// - More information at http://code.google.com/p/mega-isp
|
||||||
|
|
||||||
#include "pins_arduino.h" // defines SS,MOSI,MISO,SCK
|
#include "pins_arduino.h"
|
||||||
#define RESET SS
|
#define RESET SS
|
||||||
|
|
||||||
#define LED_HB 9
|
#define LED_HB 9
|
||||||
#define LED_ERR 8
|
#define LED_ERR 8
|
||||||
#define LED_PMODE 7
|
#define LED_PMODE 7
|
||||||
|
#define PROG_FLICKER true
|
||||||
|
|
||||||
#define HWVER 2
|
#define HWVER 2
|
||||||
#define SWMAJ 1
|
#define SWMAJ 1
|
||||||
@ -46,13 +66,13 @@
|
|||||||
void pulse(int pin, int times);
|
void pulse(int pin, int times);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(19200);
|
Serial.begin(9600);
|
||||||
pinMode(7, OUTPUT);
|
pinMode(LED_PMODE, OUTPUT);
|
||||||
pulse(7, 2);
|
pulse(LED_PMODE, 2);
|
||||||
pinMode(8, OUTPUT);
|
pinMode(LED_ERR, OUTPUT);
|
||||||
pulse(8, 2);
|
pulse(LED_ERR, 2);
|
||||||
pinMode(9, OUTPUT);
|
pinMode(LED_HB, OUTPUT);
|
||||||
pulse(9, 2);
|
pulse(LED_HB, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int error=0;
|
int error=0;
|
||||||
@ -112,9 +132,9 @@ uint8_t getch() {
|
|||||||
while(!Serial.available());
|
while(!Serial.available());
|
||||||
return Serial.read();
|
return Serial.read();
|
||||||
}
|
}
|
||||||
void readbytes(int n) {
|
void fill(int n) {
|
||||||
for (int x = 0; x < n; x++) {
|
for (int x = 0; x < n; x++) {
|
||||||
buff[x] = Serial.read();
|
buff[x] = getch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +149,11 @@ void pulse(int pin, int times) {
|
|||||||
while (times--);
|
while (times--);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void prog_lamp(int state) {
|
||||||
|
if (PROG_FLICKER)
|
||||||
|
digitalWrite(LED_PMODE, state);
|
||||||
|
}
|
||||||
|
|
||||||
void spi_init() {
|
void spi_init() {
|
||||||
uint8_t x;
|
uint8_t x;
|
||||||
SPCR = 0x53;
|
SPCR = 0x53;
|
||||||
@ -165,6 +190,7 @@ void empty_reply() {
|
|||||||
Serial.print((char)STK_OK);
|
Serial.print((char)STK_OK);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
error++;
|
||||||
Serial.print((char)STK_NOSYNC);
|
Serial.print((char)STK_NOSYNC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,6 +202,7 @@ void breply(uint8_t b) {
|
|||||||
Serial.print((char)STK_OK);
|
Serial.print((char)STK_OK);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
error++;
|
||||||
Serial.print((char)STK_NOSYNC);
|
Serial.print((char)STK_NOSYNC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,9 +238,6 @@ void set_parameters() {
|
|||||||
param.fusebytes = buff[7];
|
param.fusebytes = buff[7];
|
||||||
param.flashpoll = buff[8];
|
param.flashpoll = buff[8];
|
||||||
// ignore buff[9] (= buff[8])
|
// ignore buff[9] (= buff[8])
|
||||||
//getch(); // discard second value
|
|
||||||
|
|
||||||
// WARNING: not sure about the byte order of the following
|
|
||||||
// following are 16 bits (big endian)
|
// following are 16 bits (big endian)
|
||||||
param.eeprompoll = beget16(&buff[10]);
|
param.eeprompoll = beget16(&buff[10]);
|
||||||
param.pagesize = beget16(&buff[12]);
|
param.pagesize = beget16(&buff[12]);
|
||||||
@ -255,9 +279,7 @@ void universal() {
|
|||||||
int w;
|
int w;
|
||||||
uint8_t ch;
|
uint8_t ch;
|
||||||
|
|
||||||
for (w = 0; w < 4; w++) {
|
fill(4);
|
||||||
buff[w] = getch();
|
|
||||||
}
|
|
||||||
ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
|
ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
|
||||||
breply(ch);
|
breply(ch);
|
||||||
}
|
}
|
||||||
@ -269,7 +291,12 @@ void flash(uint8_t hilo, int addr, uint8_t data) {
|
|||||||
data);
|
data);
|
||||||
}
|
}
|
||||||
void commit(int addr) {
|
void commit(int addr) {
|
||||||
|
if (PROG_FLICKER) prog_lamp(LOW);
|
||||||
spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
|
spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
|
||||||
|
if (PROG_FLICKER) {
|
||||||
|
delay(PTIME);
|
||||||
|
prog_lamp(HIGH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define _current_page(x) (here & 0xFFFFE0)
|
//#define _current_page(x) (here & 0xFFFFE0)
|
||||||
@ -280,11 +307,23 @@ int current_page(int addr) {
|
|||||||
if (param.pagesize == 256) return here & 0xFFFFFF80;
|
if (param.pagesize == 256) return here & 0xFFFFFF80;
|
||||||
return here;
|
return here;
|
||||||
}
|
}
|
||||||
uint8_t write_flash(int length) {
|
|
||||||
if (param.pagesize < 1) return STK_FAILED;
|
|
||||||
//if (param.pagesize != 64) return STK_FAILED;
|
void write_flash(int length) {
|
||||||
int page = current_page(here);
|
fill(length);
|
||||||
|
if (CRC_EOP == getch()) {
|
||||||
|
Serial.print((char) STK_INSYNC);
|
||||||
|
Serial.print((char) write_flash_pages(length));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error++;
|
||||||
|
Serial.print((char) STK_NOSYNC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t write_flash_pages(int length) {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
int page = current_page(here);
|
||||||
while (x < length) {
|
while (x < length) {
|
||||||
if (page != current_page(here)) {
|
if (page != current_page(here)) {
|
||||||
commit(page);
|
commit(page);
|
||||||
@ -300,38 +339,64 @@ uint8_t write_flash(int length) {
|
|||||||
return STK_OK;
|
return STK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define EECHUNK (32)
|
||||||
uint8_t write_eeprom(int length) {
|
uint8_t write_eeprom(int length) {
|
||||||
// here is a word address, so we use here*2
|
// here is a word address, get the byte address
|
||||||
|
int start = here * 2;
|
||||||
|
int remaining = length;
|
||||||
|
if (length > param.eepromsize) {
|
||||||
|
error++;
|
||||||
|
return STK_FAILED;
|
||||||
|
}
|
||||||
|
while (remaining > EECHUNK) {
|
||||||
|
write_eeprom_chunk(start, EECHUNK);
|
||||||
|
start += EECHUNK;
|
||||||
|
remaining -= EECHUNK;
|
||||||
|
}
|
||||||
|
write_eeprom_chunk(start, remaining);
|
||||||
|
return STK_OK;
|
||||||
|
}
|
||||||
|
// write (length) bytes, (start) is a byte address
|
||||||
|
uint8_t write_eeprom_chunk(int start, int length) {
|
||||||
// this writes byte-by-byte,
|
// this writes byte-by-byte,
|
||||||
// page writing may be faster (4 bytes at a time)
|
// page writing may be faster (4 bytes at a time)
|
||||||
|
fill(length);
|
||||||
|
prog_lamp(LOW);
|
||||||
for (int x = 0; x < length; x++) {
|
for (int x = 0; x < length; x++) {
|
||||||
spi_transaction(0xC0, 0x00, here*2+x, buff[x]);
|
int addr = start+x;
|
||||||
|
spi_transaction(0xC0, (addr>>8) & 0xFF, addr & 0xFF, buff[x]);
|
||||||
delay(45);
|
delay(45);
|
||||||
}
|
}
|
||||||
|
prog_lamp(HIGH);
|
||||||
return STK_OK;
|
return STK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void program_page() {
|
void program_page() {
|
||||||
char result = (char) STK_FAILED;
|
char result = (char) STK_FAILED;
|
||||||
int length = 256 * getch() + getch();
|
int length = 256 * getch();
|
||||||
if (length > 256) {
|
length += getch();
|
||||||
Serial.print((char) STK_FAILED);
|
char memtype = getch();
|
||||||
|
// flash memory @here, (length) bytes
|
||||||
|
if (memtype == 'F') {
|
||||||
|
write_flash(length);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char memtype = getch();
|
if (memtype == 'E') {
|
||||||
for (int x = 0; x < length; x++) {
|
result = (char)write_eeprom(length);
|
||||||
buff[x] = getch();
|
|
||||||
}
|
|
||||||
if (CRC_EOP == getch()) {
|
if (CRC_EOP == getch()) {
|
||||||
Serial.print((char) STK_INSYNC);
|
Serial.print((char) STK_INSYNC);
|
||||||
if (memtype == 'F') result = (char)write_flash(length);
|
|
||||||
if (memtype == 'E') result = (char)write_eeprom(length);
|
|
||||||
Serial.print(result);
|
Serial.print(result);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
error++;
|
||||||
Serial.print((char) STK_NOSYNC);
|
Serial.print((char) STK_NOSYNC);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Serial.print((char)STK_FAILED);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t flash_read(uint8_t hilo, int addr) {
|
uint8_t flash_read(uint8_t hilo, int addr) {
|
||||||
return spi_transaction(0x20 + hilo * 8,
|
return spi_transaction(0x20 + hilo * 8,
|
||||||
(addr >> 8) & 0xFF,
|
(addr >> 8) & 0xFF,
|
||||||
@ -352,8 +417,10 @@ char flash_read_page(int length) {
|
|||||||
|
|
||||||
char eeprom_read_page(int length) {
|
char eeprom_read_page(int length) {
|
||||||
// here again we have a word address
|
// here again we have a word address
|
||||||
|
int start = here * 2;
|
||||||
for (int x = 0; x < length; x++) {
|
for (int x = 0; x < length; x++) {
|
||||||
uint8_t ee = spi_transaction(0xA0, 0x00, here*2+x, 0xFF);
|
int addr = start + x;
|
||||||
|
uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF);
|
||||||
Serial.print((char) ee);
|
Serial.print((char) ee);
|
||||||
}
|
}
|
||||||
return STK_OK;
|
return STK_OK;
|
||||||
@ -361,9 +428,11 @@ char eeprom_read_page(int length) {
|
|||||||
|
|
||||||
void read_page() {
|
void read_page() {
|
||||||
char result = (char)STK_FAILED;
|
char result = (char)STK_FAILED;
|
||||||
int length = 256 * getch() + getch();
|
int length = 256 * getch();
|
||||||
|
length += getch();
|
||||||
char memtype = getch();
|
char memtype = getch();
|
||||||
if (CRC_EOP != getch()) {
|
if (CRC_EOP != getch()) {
|
||||||
|
error++;
|
||||||
Serial.print((char) STK_NOSYNC);
|
Serial.print((char) STK_NOSYNC);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -376,6 +445,7 @@ void read_page() {
|
|||||||
|
|
||||||
void read_signature() {
|
void read_signature() {
|
||||||
if (CRC_EOP != getch()) {
|
if (CRC_EOP != getch()) {
|
||||||
|
error++;
|
||||||
Serial.print((char) STK_NOSYNC);
|
Serial.print((char) STK_NOSYNC);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -399,6 +469,7 @@ int avrisp() {
|
|||||||
uint8_t ch = getch();
|
uint8_t ch = getch();
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '0': // signon
|
case '0': // signon
|
||||||
|
error = 0;
|
||||||
empty_reply();
|
empty_reply();
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
@ -412,12 +483,12 @@ int avrisp() {
|
|||||||
get_version(getch());
|
get_version(getch());
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
readbytes(20);
|
fill(20);
|
||||||
set_parameters();
|
set_parameters();
|
||||||
empty_reply();
|
empty_reply();
|
||||||
break;
|
break;
|
||||||
case 'E': // extended parameters - ignore for now
|
case 'E': // extended parameters - ignore for now
|
||||||
readbytes(5);
|
fill(5);
|
||||||
empty_reply();
|
empty_reply();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -425,8 +496,9 @@ int avrisp() {
|
|||||||
start_pmode();
|
start_pmode();
|
||||||
empty_reply();
|
empty_reply();
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U': // set address (word)
|
||||||
here = getch() + 256 * getch();
|
here = getch();
|
||||||
|
here += 256 * getch();
|
||||||
empty_reply();
|
empty_reply();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -444,31 +516,33 @@ int avrisp() {
|
|||||||
program_page();
|
program_page();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x74: //STK_READ_PAGE
|
case 0x74: //STK_READ_PAGE 't'
|
||||||
read_page();
|
read_page();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'V':
|
case 'V': //0x56
|
||||||
universal();
|
universal();
|
||||||
break;
|
break;
|
||||||
case 'Q':
|
case 'Q': //0x51
|
||||||
error=0;
|
error=0;
|
||||||
end_pmode();
|
end_pmode();
|
||||||
empty_reply();
|
empty_reply();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x75: //STK_READ_SIGN
|
case 0x75: //STK_READ_SIGN 'u'
|
||||||
read_signature();
|
read_signature();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// expecting a command, not CRC_EOP
|
// expecting a command, not CRC_EOP
|
||||||
// this is how we can get back in sync
|
// this is how we can get back in sync
|
||||||
case CRC_EOP:
|
case CRC_EOP:
|
||||||
|
error++;
|
||||||
Serial.print((char) STK_NOSYNC);
|
Serial.print((char) STK_NOSYNC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// anything else we will return STK_UNKNOWN
|
// anything else we will return STK_UNKNOWN
|
||||||
default:
|
default:
|
||||||
|
error++;
|
||||||
if (CRC_EOP == getch())
|
if (CRC_EOP == getch())
|
||||||
Serial.print((char)STK_UNKNOWN);
|
Serial.print((char)STK_UNKNOWN);
|
||||||
else
|
else
|
||||||
@ -476,3 +550,5 @@ int avrisp() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ extern "C"{
|
|||||||
#define noInterrupts() cli()
|
#define noInterrupts() cli()
|
||||||
|
|
||||||
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||||
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
|
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||||
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
|
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||||
|
|
||||||
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||||
#define highByte(w) ((uint8_t) ((w) >> 8))
|
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||||
|
@ -21,4 +21,4 @@ parallel.force=true
|
|||||||
arduinoisp.name=Arduino as ISP
|
arduinoisp.name=Arduino as ISP
|
||||||
arduinoisp.communication=serial
|
arduinoisp.communication=serial
|
||||||
arduinoisp.protocol=stk500v1
|
arduinoisp.protocol=stk500v1
|
||||||
arduinoisp.speed=19200
|
arduinoisp.speed=9600
|
||||||
|
Reference in New Issue
Block a user