diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index f2fa5e26d30..86d15d4c363 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -44,6 +44,7 @@ public class Compiler implements MessageConsumer { String buildPath; String primaryClassName; boolean verbose; + PrintWriter outputFile = null; RunnerException exception; @@ -179,8 +180,25 @@ public boolean compile(Sketch sketch, baseCommandLinker.add("-L" + buildPath); baseCommandLinker.add("-lm"); + if (Preferences.getBoolean("compiler.map_file")) + baseCommandLinker.add("-Wl,-Map," + sketch.getFolder() + File.separator + sketch.getName() + ".map"); + execAsynchronously(baseCommandLinker); + // 4a. create the size output + if (Preferences.getBoolean("compiler.detailed_size")) { + List baseCommandsize = new ArrayList(Arrays.asList(new String[] { + avrBasePath + "avr-size", + "-C", + "--mcu=" + boardPreferences.get("build.mcu"), + buildPath + File.separator + primaryClassName + ".elf"//, + //" > ", + //sketch.getFolder() + File.separator + sketch.getName() + ".size" + })); + + execAsynchronously(baseCommandsize); + } + List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-objcopy", "-O", @@ -210,6 +228,18 @@ public boolean compile(Sketch sketch, commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex"); execAsynchronously(commandObjcopy); + // 7. produce the .lst file + if (Preferences.getBoolean("compiler.lst_file")) { + List baseCommandObjdump = new ArrayList(Arrays.asList(new String[] { + avrBasePath + "avr-objdump", + "-d", + "-S", + buildPath + File.separator + primaryClassName + ".elf" + })); + + execAsynchronously(baseCommandObjdump, sketch.getFolder() + File.separator + sketch.getName() + ".lst"); + } + return true; } @@ -261,6 +291,14 @@ private List compileFiles(String avrBasePath, * Either succeeds or throws a RunnerException fit for public consumption. */ private void execAsynchronously(List commandList) throws RunnerException { + execAsynchronouslyFile (commandList, null); + } + + private void execAsynchronously(List commandList, String outputFileName) throws RunnerException { + execAsynchronouslyFile (commandList, outputFileName); + } + + private void execAsynchronouslyFile(List commandList, String outputFileName) throws RunnerException { String[] command = new String[commandList.size()]; commandList.toArray(command); int result = 0; @@ -275,6 +313,19 @@ private void execAsynchronously(List commandList) throws RunnerException { firstErrorFound = false; // haven't found any errors yet secondErrorFound = false; + if (outputFileName != null) + { + try { + File filename = new File (outputFileName); + FileWriter fout = new FileWriter (filename); + outputFile = new PrintWriter (fout, true); + } catch (IOException e) { + RunnerException re = new RunnerException(e.getMessage()); + re.hideStackTrace(); + throw re; + } + } + Process process; try { @@ -321,9 +372,15 @@ private void execAsynchronously(List commandList) throws RunnerException { re.hideStackTrace(); throw re; } + + if (outputFile != null) + { + outputFile.flush (); + outputFile.close (); + outputFile = null; + } } - /** * Part of the MessageConsumer interface, this is called * whenever a piece (usually a line) of error message is spewed @@ -333,49 +390,54 @@ private void execAsynchronously(List commandList) throws RunnerException { public void message(String s) { int i; - // remove the build path so people only see the filename - // can't use replaceAll() because the path may have characters in it which - // have meaning in a regular expression. - if (!verbose) { - while ((i = s.indexOf(buildPath + File.separator)) != -1) { - s = s.substring(0, i) + s.substring(i + (buildPath + File.separator).length()); + if (outputFile != null) + outputFile.print (s); + else + { + // remove the build path so people only see the filename + // can't use replaceAll() because the path may have characters in it which + // have meaning in a regular expression. + if (!verbose) { + while ((i = s.indexOf(buildPath + File.separator)) != -1) { + s = s.substring(0, i) + s.substring(i + (buildPath + File.separator).length()); + } } - } - - // look for error line, which contains file name, line number, - // and at least the first line of the error message - String errorFormat = "([\\w\\d_]+.\\w+):(\\d+):\\s*error:\\s*(.*)\\s*"; - String[] pieces = PApplet.match(s, errorFormat); + + // look for error line, which contains file name, line number, + // and at least the first line of the error message + String errorFormat = "([\\w\\d_]+.\\w+):(\\d+):\\s*error:\\s*(.*)\\s*"; + String[] pieces = PApplet.match(s, errorFormat); // if (pieces != null && exception == null) { // exception = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1); // if (exception != null) exception.hideStackTrace(); // } - - if (pieces != null) { - RunnerException e = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1); - - // replace full file path with the name of the sketch tab (unless we're - // in verbose mode, in which case don't modify the compiler output) - if (e != null && !verbose) { - SketchCode code = sketch.getCode(e.getCodeIndex()); - String fileName = code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName(); - s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage(); + + if (pieces != null) { + RunnerException e = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1); + + // replace full file path with the name of the sketch tab (unless we're + // in verbose mode, in which case don't modify the compiler output) + if (e != null && !verbose) { + SketchCode code = sketch.getCode(e.getCodeIndex()); + String fileName = code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName(); + s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage(); + } + + if (pieces[3].trim().equals("SPI.h: No such file or directory")) { + e = new RunnerException("Please import the SPI library from the Sketch > Import Library menu."); + s += "\nAs of Arduino 0019, the Ethernet library depends on the SPI library." + + "\nYou appear to be using it or another library that depends on the SPI library."; + } + + if (exception == null && e != null) { + exception = e; + exception.hideStackTrace(); + } } - - if (pieces[3].trim().equals("SPI.h: No such file or directory")) { - e = new RunnerException("Please import the SPI library from the Sketch > Import Library menu."); - s += "\nAs of Arduino 0019, the Ethernet library depends on the SPI library." + - "\nYou appear to be using it or another library that depends on the SPI library."; - } - - if (exception == null && e != null) { - exception = e; - exception.hideStackTrace(); - } + + System.err.print(s); } - - System.err.print(s); } ///////////////////////////////////////////////////////////////////////////// @@ -411,13 +473,19 @@ static private List getCommandCompilerC(String avrBasePath, List includePaths, "-c", // compile, don't link "-g", // include debugging info (so errors include line numbers) "-Os", // optimize for size - "-w", // surpress all warnings "-ffunction-sections", // place each function in its own section "-fdata-sections", "-mmcu=" + boardPreferences.get("build.mcu"), "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, })); + + if (!Preferences.getBoolean("compiler.show_all_warnings")) + baseCommandCompiler.add("-w"); // suppress all warnings + else { + baseCommandCompiler.add("-W"); // show all warnings + baseCommandCompiler.add("-Wall"); // be aggressive with warnings + } for (int i = 0; i < includePaths.size(); i++) { baseCommandCompiler.add("-I" + (String) includePaths.get(i)); @@ -439,7 +507,6 @@ static private List getCommandCompilerCPP(String avrBasePath, "-c", // compile, don't link "-g", // include debugging info (so errors include line numbers) "-Os", // optimize for size - "-w", // surpress all warnings "-fno-exceptions", "-ffunction-sections", // place each function in its own section "-fdata-sections", @@ -448,6 +515,13 @@ static private List getCommandCompilerCPP(String avrBasePath, "-DARDUINO=" + Base.REVISION, })); + if (!Preferences.getBoolean("compiler.show_all_warnings")) + baseCommandCompilerCPP.add("-w"); // suppress all warnings + else { + baseCommandCompilerCPP.add("-W"); // show all warnings + baseCommandCompilerCPP.add("-Wall"); // be aggressive with warnings + } + for (int i = 0; i < includePaths.size(); i++) { baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i)); } diff --git a/hardware/arduino/cores/arduino/HardwareSerial.cpp b/hardware/arduino/cores/arduino/HardwareSerial.cpp index 4397efb7ee0..089f27ac595 100644 --- a/hardware/arduino/cores/arduino/HardwareSerial.cpp +++ b/hardware/arduino/cores/arduino/HardwareSerial.cpp @@ -257,10 +257,6 @@ int HardwareSerial::read(void) void HardwareSerial::flush() { - // don't reverse this or there may be problems if the RX interrupt - // occurs after reading the value of rx_buffer_head but before writing - // the value to rx_buffer_tail; the previous value of rx_buffer_head - // may be written to rx_buffer_tail, making it appear as if the buffer // don't reverse this or there may be problems if the RX interrupt // occurs after reading the value of rx_buffer_head but before writing // the value to rx_buffer_tail; the previous value of rx_buffer_head diff --git a/hardware/arduino/cores/arduino/Print.cpp b/hardware/arduino/cores/arduino/Print.cpp index 4ee556dd82d..fd689423a4a 100755 --- a/hardware/arduino/cores/arduino/Print.cpp +++ b/hardware/arduino/cores/arduino/Print.cpp @@ -45,7 +45,7 @@ void Print::write(const uint8_t *buffer, size_t size) void Print::print(const String &s) { - for (int i = 0; i < s.length(); i++) { + for (unsigned int i = 0; i < s.length(); i++) { write(s[i]); } } diff --git a/hardware/arduino/cores/arduino/WInterrupts.c b/hardware/arduino/cores/arduino/WInterrupts.c index 3b3e0c9ec43..bc92a0ed128 100755 --- a/hardware/arduino/cores/arduino/WInterrupts.c +++ b/hardware/arduino/cores/arduino/WInterrupts.c @@ -33,7 +33,7 @@ #include "WConstants.h" #include "wiring_private.h" -volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; +static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; // volatile static voidFuncPtr twiIntFunc; void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { diff --git a/hardware/arduino/cores/arduino/WString.cpp b/hardware/arduino/cores/arduino/WString.cpp index db5a441dc27..aab06cd5088 100644 --- a/hardware/arduino/cores/arduino/WString.cpp +++ b/hardware/arduino/cores/arduino/WString.cpp @@ -88,7 +88,7 @@ String::String( const long value, const int base ) String::String( const unsigned long value, const int base ) { char buf[33]; - ultoa(value, buf, 10); + ultoa(value, buf, base); getBuffer( _length = strlen(buf) ); if ( _buffer != NULL ) strcpy( _buffer, buf ); diff --git a/hardware/arduino/cores/arduino/WString.h b/hardware/arduino/cores/arduino/WString.h index cadddb9476f..56faf9a4880 100644 --- a/hardware/arduino/cores/arduino/WString.h +++ b/hardware/arduino/cores/arduino/WString.h @@ -67,7 +67,7 @@ class String int lastIndexOf( char ch, unsigned int fromIndex ) const; int lastIndexOf( const String &str ) const; int lastIndexOf( const String &str, unsigned int fromIndex ) const; - const unsigned int length( ) const { return _length; } + unsigned int length( ) const { return _length; } void setCharAt(unsigned int index, const char ch); unsigned char startsWith( const String &prefix ) const; unsigned char startsWith( const String &prefix, unsigned int toffset ) const; diff --git a/hardware/arduino/cores/arduino/pins_arduino.c b/hardware/arduino/cores/arduino/pins_arduino.c index 0c816e94d9a..9f27b9cdb95 100755 --- a/hardware/arduino/cores/arduino/pins_arduino.c +++ b/hardware/arduino/cores/arduino/pins_arduino.c @@ -81,50 +81,50 @@ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) const uint16_t PROGMEM port_to_mode_PGM[] = { NOT_A_PORT, - &DDRA, - &DDRB, - &DDRC, - &DDRD, - &DDRE, - &DDRF, - &DDRG, - &DDRH, + (uint16_t) &DDRA, + (uint16_t) &DDRB, + (uint16_t) &DDRC, + (uint16_t) &DDRD, + (uint16_t) &DDRE, + (uint16_t) &DDRF, + (uint16_t) &DDRG, + (uint16_t) &DDRH, NOT_A_PORT, - &DDRJ, - &DDRK, - &DDRL, + (uint16_t) &DDRJ, + (uint16_t) &DDRK, + (uint16_t) &DDRL, }; const uint16_t PROGMEM port_to_output_PGM[] = { NOT_A_PORT, - &PORTA, - &PORTB, - &PORTC, - &PORTD, - &PORTE, - &PORTF, - &PORTG, - &PORTH, + (uint16_t) &PORTA, + (uint16_t) &PORTB, + (uint16_t) &PORTC, + (uint16_t) &PORTD, + (uint16_t) &PORTE, + (uint16_t) &PORTF, + (uint16_t) &PORTG, + (uint16_t) &PORTH, NOT_A_PORT, - &PORTJ, - &PORTK, - &PORTL, + (uint16_t) &PORTJ, + (uint16_t) &PORTK, + (uint16_t) &PORTL, }; const uint16_t PROGMEM port_to_input_PGM[] = { NOT_A_PIN, - &PINA, - &PINB, - &PINC, - &PIND, - &PINE, - &PINF, - &PING, - &PINH, + (uint16_t) &PINA, + (uint16_t) &PINB, + (uint16_t) &PINC, + (uint16_t) &PIND, + (uint16_t) &PINE, + (uint16_t) &PINF, + (uint16_t) &PING, + (uint16_t) &PINH, NOT_A_PIN, - &PINJ, - &PINK, - &PINL, + (uint16_t) &PINJ, + (uint16_t) &PINK, + (uint16_t) &PINL, }; const uint8_t PROGMEM digital_pin_to_port_PGM[] = { diff --git a/hardware/arduino/cores/arduino/pins_arduino.h b/hardware/arduino/cores/arduino/pins_arduino.h index bc931c597c4..83eec66ebea 100644 --- a/hardware/arduino/cores/arduino/pins_arduino.h +++ b/hardware/arduino/cores/arduino/pins_arduino.h @@ -50,15 +50,15 @@ #define TIMER5C 16 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -const static uint8_t SS = 53; -const static uint8_t MOSI = 51; -const static uint8_t MISO = 50; -const static uint8_t SCK = 52; +static const uint8_t SS = 53; +static const uint8_t MOSI = 51; +static const uint8_t MISO = 50; +static const uint8_t SCK = 52; #else -const static uint8_t SS = 10; -const static uint8_t MOSI = 11; -const static uint8_t MISO = 12; -const static uint8_t SCK = 13; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 12; +static const uint8_t SCK = 13; #endif // On the ATmega1280, the addresses of some of the port registers are diff --git a/hardware/arduino/cores/arduino/wiring_private.h b/hardware/arduino/cores/arduino/wiring_private.h index 11f6f00f28a..3c87413b9c8 100755 --- a/hardware/arduino/cores/arduino/wiring_private.h +++ b/hardware/arduino/cores/arduino/wiring_private.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include diff --git a/libraries/SD/SD.cpp b/libraries/SD/SD.cpp index aca7468dd24..64837bc087a 100644 --- a/libraries/SD/SD.cpp +++ b/libraries/SD/SD.cpp @@ -424,9 +424,9 @@ boolean SDClass::mkdir(char *filepath) { boolean SDClass::rmdir(char *filepath) { /* - Makes a single directory or a heirarchy of directories. + Remove a single directory or a heirarchy of directories. - A rough equivalent to `mkdir -p`. + A rough equivalent to `rm -rf`. */ return walkPath(filepath, root, callback_rmdir); @@ -436,4 +436,4 @@ boolean SDClass::remove(char *filepath) { return walkPath(filepath, root, callback_remove); } -SDClass SD; \ No newline at end of file +SDClass SD; diff --git a/libraries/SD/utility/Sd2Card.cpp b/libraries/SD/utility/Sd2Card.cpp index 26c4236ac07..f91677226dd 100644 --- a/libraries/SD/utility/Sd2Card.cpp +++ b/libraries/SD/utility/Sd2Card.cpp @@ -25,7 +25,8 @@ /** Send a byte to the card */ static void spiSend(uint8_t b) { SPDR = b; - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; } /** Receive a byte from the card */ static uint8_t spiRec(void) { @@ -112,7 +113,8 @@ uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) { spiSend(crc); // wait for response - for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++); + for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++) + ; return status_; } //------------------------------------------------------------------------------ @@ -360,18 +362,21 @@ uint8_t Sd2Card::readData(uint32_t block, // skip data before offset for (;offset_ < offset; offset_++) { - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; SPDR = 0XFF; } // transfer data n = count - 1; for (uint16_t i = 0; i < n; i++) { - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; dst[i] = SPDR; SPDR = 0XFF; } // wait for last byte - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; dst[n] = SPDR; #else // OPTIMIZE_HARDWARE_SPI @@ -406,11 +411,13 @@ void Sd2Card::readEnd(void) { // optimize skip for hardware SPDR = 0XFF; while (offset_++ < 513) { - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; SPDR = 0XFF; } // wait for last crc byte - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; #else // OPTIMIZE_HARDWARE_SPI while (offset_++ < 514) spiRec(); #endif // OPTIMIZE_HARDWARE_SPI @@ -561,14 +568,17 @@ uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) { // send two byte per iteration for (uint16_t i = 0; i < 512; i += 2) { - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; SPDR = src[i]; - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; SPDR = src[i+1]; } // wait for last data byte - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; #else // OPTIMIZE_HARDWARE_SPI spiSend(token);