|
@@ -37,15 +37,16 @@
|
|
|
/* ATmega328 non-picopower devices */
|
|
|
/* ATmega644P based devices (Sanguino) */
|
|
|
/* ATmega1284P based devices */
|
|
|
+/* ATmega1280 based devices (Arduino Mega) */
|
|
|
/* */
|
|
|
/* Alpha test */
|
|
|
-/* ATmega1280 based devices (Arduino Mega) */
|
|
|
+/* ATmega32 */
|
|
|
/* */
|
|
|
/* Work in progress: */
|
|
|
/* ATtiny84 based devices (Luminet) */
|
|
|
/* */
|
|
|
/* Does not support: */
|
|
|
-/* USB based devices (eg. Teensy) */
|
|
|
+/* USB based devices (eg. Teensy, Leonardo) */
|
|
|
/* */
|
|
|
/* Assumptions: */
|
|
|
/* The code makes several assumptions that reduce the */
|
|
@@ -138,6 +139,10 @@
|
|
|
/* Version 4 starts with the arduino repository commit */
|
|
|
/* that brought the arduino repository up-to-date with */
|
|
|
/* the optiboot source tree changes since v3. */
|
|
|
+/* It would be good if versions implemented outside the */
|
|
|
+/* official repository used an out-of-seqeunce version */
|
|
|
+/* number (like 104.6 if based on based on 4.5) to */
|
|
|
+/* prevent collisions. */
|
|
|
/* */
|
|
|
/**********************************************************/
|
|
|
|
|
@@ -300,7 +305,7 @@ void appStart(uint8_t rstFlags) __attribute__ ((naked));
|
|
|
#if defined(__AVR_ATmega168__)
|
|
|
#define RAMSTART (0x100)
|
|
|
#define NRWWSTART (0x3800)
|
|
|
-#elif defined(__AVR_ATmega328P__)
|
|
|
+#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32__)
|
|
|
#define RAMSTART (0x100)
|
|
|
#define NRWWSTART (0x7000)
|
|
|
#elif defined (__AVR_ATmega644P__)
|
|
@@ -334,7 +339,7 @@ void appStart(uint8_t rstFlags) __attribute__ ((naked));
|
|
|
|
|
|
/*
|
|
|
* Handle devices with up to 4 uarts (eg m1280.) Rather inelegantly.
|
|
|
- * Note that mega8 still needs special handling, because ubrr is handled
|
|
|
+ * Note that mega8/m32 still needs special handling, because ubrr is handled
|
|
|
* differently.
|
|
|
*/
|
|
|
#if UART == 0
|
|
@@ -386,7 +391,7 @@ int main(void) {
|
|
|
// If not, uncomment the following instructions:
|
|
|
// cli();
|
|
|
asm volatile ("clr __zero_reg__");
|
|
|
-#ifdef __AVR_ATmega8__
|
|
|
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
|
|
|
SP=RAMEND; // This is done by hardware reset
|
|
|
#endif
|
|
|
|
|
@@ -400,7 +405,7 @@ int main(void) {
|
|
|
TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
|
|
|
#endif
|
|
|
#ifndef SOFT_UART
|
|
|
-#ifdef __AVR_ATmega8__
|
|
|
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
|
|
|
UCSRA = _BV(U2X); //Double speed mode USART
|
|
|
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
|
|
|
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
|
|
@@ -497,7 +502,9 @@ int main(void) {
|
|
|
while (--length);
|
|
|
|
|
|
// If we are in NRWW section, page erase has to be delayed until now.
|
|
|
- // Todo: Take RAMPZ into account
|
|
|
+ // Todo: Take RAMPZ into account (not doing so just means that we will
|
|
|
+ // treat the top of both "pages" of flash as NRWW, for a slight speed
|
|
|
+ // decrease, so fixing this is not urgent.)
|
|
|
if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
|
|
|
|
|
|
// Read command terminator, start reply
|
|
@@ -635,7 +642,7 @@ uint8_t getch(void) {
|
|
|
uint8_t ch;
|
|
|
|
|
|
#ifdef LED_DATA_FLASH
|
|
|
-#ifdef __AVR_ATmega8__
|
|
|
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
|
|
|
LED_PORT ^= _BV(LED);
|
|
|
#else
|
|
|
LED_PIN |= _BV(LED);
|
|
@@ -685,7 +692,7 @@ uint8_t getch(void) {
|
|
|
#endif
|
|
|
|
|
|
#ifdef LED_DATA_FLASH
|
|
|
-#ifdef __AVR_ATmega8__
|
|
|
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
|
|
|
LED_PORT ^= _BV(LED);
|
|
|
#else
|
|
|
LED_PIN |= _BV(LED);
|
|
@@ -734,7 +741,7 @@ void flash_led(uint8_t count) {
|
|
|
TCNT1 = -(F_CPU/(1024*16));
|
|
|
TIFR1 = _BV(TOV1);
|
|
|
while(!(TIFR1 & _BV(TOV1)));
|
|
|
-#ifdef __AVR_ATmega8__
|
|
|
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
|
|
|
LED_PORT ^= _BV(LED);
|
|
|
#else
|
|
|
LED_PIN |= _BV(LED);
|