mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Merge remote-tracking branch 'arduino/master' into platforms-b
This commit is contained in:
commit
5ad4422fc7
@ -133,16 +133,19 @@ public class EditorConsole extends JScrollPane {
|
||||
// The files and folders are not deleted on exit because they may be
|
||||
// needed for debugging or bug reporting.
|
||||
tempFolder = Base.createTempFolder("console");
|
||||
tempFolder.deleteOnExit();
|
||||
try {
|
||||
String outFileName = Preferences.get("console.output.file");
|
||||
if (outFileName != null) {
|
||||
outFile = new File(tempFolder, outFileName);
|
||||
outFile.deleteOnExit();
|
||||
stdoutFile = new FileOutputStream(outFile);
|
||||
}
|
||||
|
||||
String errFileName = Preferences.get("console.error.file");
|
||||
if (errFileName != null) {
|
||||
errFile = new File(tempFolder, errFileName);
|
||||
errFile.deleteOnExit();
|
||||
stderrFile = new FileOutputStream(errFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -1,15 +1,34 @@
|
||||
// this sketch turns the Arduino into a AVRISP
|
||||
// using the following pins:
|
||||
// 10: slave reset
|
||||
// 11: MOSI
|
||||
// 12: MISO
|
||||
// 13: SCK
|
||||
|
||||
// ArduinoISP version 04m3
|
||||
// Copyright (c) 2008-2011 Randall Bohn
|
||||
// If you require a license, see
|
||||
// http://www.opensource.org/licenses/bsd-license.php
|
||||
//
|
||||
// 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:
|
||||
// 9: Heartbeat - shows the programmer is running
|
||||
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
|
||||
// 9: Heartbeat - shows the programmer is running
|
||||
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
|
||||
// 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
|
||||
// - Added support for the read signature command
|
||||
//
|
||||
@ -24,35 +43,36 @@
|
||||
// - The SPI functions herein were developed for the AVR910_ARD programmer
|
||||
// - More information at http://code.google.com/p/mega-isp
|
||||
|
||||
#include "pins_arduino.h" // defines SS,MOSI,MISO,SCK
|
||||
#define RESET SS
|
||||
#include "pins_arduino.h"
|
||||
#define RESET SS
|
||||
|
||||
#define LED_HB 9
|
||||
#define LED_ERR 8
|
||||
#define LED_HB 9
|
||||
#define LED_ERR 8
|
||||
#define LED_PMODE 7
|
||||
#define PROG_FLICKER true
|
||||
|
||||
#define HWVER 2
|
||||
#define SWMAJ 1
|
||||
#define SWMIN 18
|
||||
|
||||
// STK Definitions
|
||||
#define STK_OK 0x10
|
||||
#define STK_FAILED 0x11
|
||||
#define STK_OK 0x10
|
||||
#define STK_FAILED 0x11
|
||||
#define STK_UNKNOWN 0x12
|
||||
#define STK_INSYNC 0x14
|
||||
#define STK_NOSYNC 0x15
|
||||
#define CRC_EOP 0x20 //ok it is a space...
|
||||
#define STK_INSYNC 0x14
|
||||
#define STK_NOSYNC 0x15
|
||||
#define CRC_EOP 0x20 //ok it is a space...
|
||||
|
||||
void pulse(int pin, int times);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(19200);
|
||||
pinMode(7, OUTPUT);
|
||||
pulse(7, 2);
|
||||
pinMode(8, OUTPUT);
|
||||
pulse(8, 2);
|
||||
pinMode(9, OUTPUT);
|
||||
pulse(9, 2);
|
||||
Serial.begin(9600);
|
||||
pinMode(LED_PMODE, OUTPUT);
|
||||
pulse(LED_PMODE, 2);
|
||||
pinMode(LED_ERR, OUTPUT);
|
||||
pulse(LED_ERR, 2);
|
||||
pinMode(LED_HB, OUTPUT);
|
||||
pulse(LED_HB, 2);
|
||||
}
|
||||
|
||||
int error=0;
|
||||
@ -91,7 +111,7 @@ void heartbeat() {
|
||||
analogWrite(LED_HB, hbval);
|
||||
delay(40);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop(void) {
|
||||
// is pmode active?
|
||||
@ -100,7 +120,7 @@ void loop(void) {
|
||||
// is there an error?
|
||||
if (error) digitalWrite(LED_ERR, HIGH);
|
||||
else digitalWrite(LED_ERR, LOW);
|
||||
|
||||
|
||||
// light the heartbeat LED
|
||||
heartbeat();
|
||||
if (Serial.available()) {
|
||||
@ -112,9 +132,9 @@ uint8_t getch() {
|
||||
while(!Serial.available());
|
||||
return Serial.read();
|
||||
}
|
||||
void readbytes(int n) {
|
||||
void fill(int n) {
|
||||
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--);
|
||||
}
|
||||
|
||||
void prog_lamp(int state) {
|
||||
if (PROG_FLICKER)
|
||||
digitalWrite(LED_PMODE, state);
|
||||
}
|
||||
|
||||
void spi_init() {
|
||||
uint8_t x;
|
||||
SPCR = 0x53;
|
||||
@ -165,6 +190,7 @@ void empty_reply() {
|
||||
Serial.print((char)STK_OK);
|
||||
}
|
||||
else {
|
||||
error++;
|
||||
Serial.print((char)STK_NOSYNC);
|
||||
}
|
||||
}
|
||||
@ -176,6 +202,7 @@ void breply(uint8_t b) {
|
||||
Serial.print((char)STK_OK);
|
||||
}
|
||||
else {
|
||||
error++;
|
||||
Serial.print((char)STK_NOSYNC);
|
||||
}
|
||||
}
|
||||
@ -202,21 +229,18 @@ void get_version(uint8_t c) {
|
||||
void set_parameters() {
|
||||
// call this after reading paramter packet into buff[]
|
||||
param.devicecode = buff[0];
|
||||
param.revision = buff[1];
|
||||
param.progtype = buff[2];
|
||||
param.parmode = buff[3];
|
||||
param.polling = buff[4];
|
||||
param.selftimed = buff[5];
|
||||
param.lockbytes = buff[6];
|
||||
param.fusebytes = buff[7];
|
||||
param.flashpoll = buff[8];
|
||||
param.revision = buff[1];
|
||||
param.progtype = buff[2];
|
||||
param.parmode = buff[3];
|
||||
param.polling = buff[4];
|
||||
param.selftimed = buff[5];
|
||||
param.lockbytes = buff[6];
|
||||
param.fusebytes = buff[7];
|
||||
param.flashpoll = 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)
|
||||
param.eeprompoll = beget16(&buff[10]);
|
||||
param.pagesize = beget16(&buff[12]);
|
||||
param.pagesize = beget16(&buff[12]);
|
||||
param.eepromsize = beget16(&buff[14]);
|
||||
|
||||
// 32 bits flashsize (big endian)
|
||||
@ -255,9 +279,7 @@ void universal() {
|
||||
int w;
|
||||
uint8_t ch;
|
||||
|
||||
for (w = 0; w < 4; w++) {
|
||||
buff[w] = getch();
|
||||
}
|
||||
fill(4);
|
||||
ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
|
||||
breply(ch);
|
||||
}
|
||||
@ -269,22 +291,39 @@ void flash(uint8_t hilo, int addr, uint8_t data) {
|
||||
data);
|
||||
}
|
||||
void commit(int addr) {
|
||||
if (PROG_FLICKER) prog_lamp(LOW);
|
||||
spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
|
||||
if (PROG_FLICKER) {
|
||||
delay(PTIME);
|
||||
prog_lamp(HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
//#define _current_page(x) (here & 0xFFFFE0)
|
||||
int current_page(int addr) {
|
||||
if (param.pagesize == 32) return here & 0xFFFFFFF0;
|
||||
if (param.pagesize == 64) return here & 0xFFFFFFE0;
|
||||
if (param.pagesize == 32) return here & 0xFFFFFFF0;
|
||||
if (param.pagesize == 64) return here & 0xFFFFFFE0;
|
||||
if (param.pagesize == 128) return here & 0xFFFFFFC0;
|
||||
if (param.pagesize == 256) return here & 0xFFFFFF80;
|
||||
return here;
|
||||
}
|
||||
uint8_t write_flash(int length) {
|
||||
if (param.pagesize < 1) return STK_FAILED;
|
||||
//if (param.pagesize != 64) return STK_FAILED;
|
||||
int page = current_page(here);
|
||||
|
||||
|
||||
void write_flash(int length) {
|
||||
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 page = current_page(here);
|
||||
while (x < length) {
|
||||
if (page != current_page(here)) {
|
||||
commit(page);
|
||||
@ -300,43 +339,69 @@ uint8_t write_flash(int length) {
|
||||
return STK_OK;
|
||||
}
|
||||
|
||||
#define EECHUNK (32)
|
||||
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,
|
||||
// page writing may be faster (4 bytes at a time)
|
||||
fill(length);
|
||||
prog_lamp(LOW);
|
||||
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);
|
||||
}
|
||||
}
|
||||
prog_lamp(HIGH);
|
||||
return STK_OK;
|
||||
}
|
||||
|
||||
void program_page() {
|
||||
char result = (char) STK_FAILED;
|
||||
int length = 256 * getch() + getch();
|
||||
if (length > 256) {
|
||||
Serial.print((char) STK_FAILED);
|
||||
return;
|
||||
}
|
||||
int length = 256 * getch();
|
||||
length += getch();
|
||||
char memtype = getch();
|
||||
for (int x = 0; x < length; x++) {
|
||||
buff[x] = getch();
|
||||
// flash memory @here, (length) bytes
|
||||
if (memtype == 'F') {
|
||||
write_flash(length);
|
||||
return;
|
||||
}
|
||||
if (CRC_EOP == getch()) {
|
||||
Serial.print((char) STK_INSYNC);
|
||||
if (memtype == 'F') result = (char)write_flash(length);
|
||||
if (memtype == 'E') result = (char)write_eeprom(length);
|
||||
Serial.print(result);
|
||||
}
|
||||
else {
|
||||
Serial.print((char) STK_NOSYNC);
|
||||
if (memtype == 'E') {
|
||||
result = (char)write_eeprom(length);
|
||||
if (CRC_EOP == getch()) {
|
||||
Serial.print((char) STK_INSYNC);
|
||||
Serial.print(result);
|
||||
}
|
||||
else {
|
||||
error++;
|
||||
Serial.print((char) STK_NOSYNC);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Serial.print((char)STK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t flash_read(uint8_t hilo, int addr) {
|
||||
return spi_transaction(0x20 + hilo * 8,
|
||||
(addr >> 8) & 0xFF,
|
||||
addr & 0xFF,
|
||||
0);
|
||||
(addr >> 8) & 0xFF,
|
||||
addr & 0xFF,
|
||||
0);
|
||||
}
|
||||
|
||||
char flash_read_page(int length) {
|
||||
@ -352,8 +417,10 @@ char flash_read_page(int length) {
|
||||
|
||||
char eeprom_read_page(int length) {
|
||||
// here again we have a word address
|
||||
int start = here * 2;
|
||||
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);
|
||||
}
|
||||
return STK_OK;
|
||||
@ -361,9 +428,11 @@ char eeprom_read_page(int length) {
|
||||
|
||||
void read_page() {
|
||||
char result = (char)STK_FAILED;
|
||||
int length = 256 * getch() + getch();
|
||||
int length = 256 * getch();
|
||||
length += getch();
|
||||
char memtype = getch();
|
||||
if (CRC_EOP != getch()) {
|
||||
error++;
|
||||
Serial.print((char) STK_NOSYNC);
|
||||
return;
|
||||
}
|
||||
@ -376,6 +445,7 @@ void read_page() {
|
||||
|
||||
void read_signature() {
|
||||
if (CRC_EOP != getch()) {
|
||||
error++;
|
||||
Serial.print((char) STK_NOSYNC);
|
||||
return;
|
||||
}
|
||||
@ -399,6 +469,7 @@ int avrisp() {
|
||||
uint8_t ch = getch();
|
||||
switch (ch) {
|
||||
case '0': // signon
|
||||
error = 0;
|
||||
empty_reply();
|
||||
break;
|
||||
case '1':
|
||||
@ -412,12 +483,12 @@ int avrisp() {
|
||||
get_version(getch());
|
||||
break;
|
||||
case 'B':
|
||||
readbytes(20);
|
||||
fill(20);
|
||||
set_parameters();
|
||||
empty_reply();
|
||||
break;
|
||||
case 'E': // extended parameters - ignore for now
|
||||
readbytes(5);
|
||||
fill(5);
|
||||
empty_reply();
|
||||
break;
|
||||
|
||||
@ -425,8 +496,9 @@ int avrisp() {
|
||||
start_pmode();
|
||||
empty_reply();
|
||||
break;
|
||||
case 'U':
|
||||
here = getch() + 256 * getch();
|
||||
case 'U': // set address (word)
|
||||
here = getch();
|
||||
here += 256 * getch();
|
||||
empty_reply();
|
||||
break;
|
||||
|
||||
@ -443,32 +515,34 @@ int avrisp() {
|
||||
case 0x64: //STK_PROG_PAGE
|
||||
program_page();
|
||||
break;
|
||||
|
||||
case 0x74: //STK_READ_PAGE
|
||||
|
||||
case 0x74: //STK_READ_PAGE 't'
|
||||
read_page();
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
case 'V': //0x56
|
||||
universal();
|
||||
break;
|
||||
case 'Q':
|
||||
case 'Q': //0x51
|
||||
error=0;
|
||||
end_pmode();
|
||||
empty_reply();
|
||||
break;
|
||||
|
||||
case 0x75: //STK_READ_SIGN
|
||||
|
||||
case 0x75: //STK_READ_SIGN 'u'
|
||||
read_signature();
|
||||
break;
|
||||
|
||||
// expecting a command, not CRC_EOP
|
||||
// this is how we can get back in sync
|
||||
// expecting a command, not CRC_EOP
|
||||
// this is how we can get back in sync
|
||||
case CRC_EOP:
|
||||
error++;
|
||||
Serial.print((char) STK_NOSYNC);
|
||||
break;
|
||||
|
||||
// anything else we will return STK_UNKNOWN
|
||||
|
||||
// anything else we will return STK_UNKNOWN
|
||||
default:
|
||||
error++;
|
||||
if (CRC_EOP == getch())
|
||||
Serial.print((char)STK_UNKNOWN);
|
||||
else
|
||||
@ -476,3 +550,5 @@ int avrisp() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -73,8 +73,8 @@ extern "C"{
|
||||
#define noInterrupts() cli()
|
||||
|
||||
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
|
||||
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
|
||||
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||
|
||||
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||
|
@ -21,4 +21,4 @@ parallel.force=true
|
||||
arduinoisp.name=Arduino as ISP
|
||||
arduinoisp.communication=serial
|
||||
arduinoisp.protocol=stk500v1
|
||||
arduinoisp.speed=19200
|
||||
arduinoisp.speed=9600
|
||||
|
Loading…
x
Reference in New Issue
Block a user