113
113
#define BL_PIN PINF
114
114
#define BL0 PINF7
115
115
#define BL1 PINF6
116
- #elif defined __AVR_ATmega1280__
116
+ #elif defined __AVR_ATmega1280__
117
117
/* we just don't do anything for the MEGA and enter bootloader on reset anyway*/
118
118
#else
119
119
/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */
133
133
#define LED_PIN PINB
134
134
#define LED PINB7
135
135
#else
136
- /* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duomilanuove */
136
+ /* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duomilanuove */
137
137
/* other boards like e.g. Crumb8, Crumb168 are using PB2 */
138
138
#define LED_DDR DDRB
139
139
#define LED_PORT PORTB
142
142
#endif
143
143
144
144
145
+
145
146
/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */
146
147
#if defined(__AVR_ATmega128__ ) || defined(__AVR_ATmega1280__ )
147
148
#define MONITOR 1
@@ -343,7 +344,7 @@ int main(void)
343
344
#endif
344
345
}
345
346
346
- #ifdef __AVR_ATmega128__
347
+ #ifdef __AVR_ATmega128__
347
348
/* no bootuart was selected, default to uart 0 */
348
349
if (!bootuart ) {
349
350
bootuart = 1 ;
@@ -371,7 +372,7 @@ int main(void)
371
372
UBRR = (uint8_t )(F_CPU /(BAUD_RATE * 16L )- 1 );
372
373
UBRRHI = (F_CPU /(BAUD_RATE * 16L )- 1 ) >> 8 ;
373
374
UCSRA = 0x00 ;
374
- UCSRB = _BV (TXEN )|_BV (RXEN );
375
+ UCSRB = _BV (TXEN )|_BV (RXEN );
375
376
#elif defined(__AVR_ATmega168__ ) || defined(__AVR_ATmega328P__ ) || defined (__AVR_ATmega328__ )
376
377
377
378
#ifdef DOUBLE_SPEED
@@ -440,7 +441,7 @@ int main(void)
440
441
441
442
/* A bunch of if...else if... gives smaller code than switch...case ! */
442
443
443
- /* Hello is anyone home ? */
444
+ /* Hello is anyone home ? */
444
445
if (ch == '0' ) {
445
446
nothing_response ();
446
447
}
@@ -537,10 +538,10 @@ int main(void)
537
538
if (ch == 0 ) {
538
539
byte_response (SIG1 );
539
540
} else if (ch == 1 ) {
540
- byte_response (SIG2 );
541
+ byte_response (SIG2 );
541
542
} else {
542
543
byte_response (SIG3 );
543
- }
544
+ }
544
545
} else {
545
546
getNch (3 );
546
547
byte_response (0x00 );
@@ -571,7 +572,7 @@ int main(void)
571
572
eeprom_write_byte ((void * )address .word ,buff [w ]);
572
573
#endif
573
574
address .word ++ ;
574
- }
575
+ }
575
576
}
576
577
else { //Write to FLASH one page at a time
577
578
if (address .byte [1 ]> 127 ) address_high = 0x01 ; //Only possible with m128, m256 will need 3rd address byte. FIXME
@@ -596,17 +597,17 @@ int main(void)
596
597
"ldi r29,hi8(buff) \n\t"
597
598
"lds r24,length \n\t" //Length of data to be written (in bytes)
598
599
"lds r25,length+1 \n\t"
599
- "length_loop: \n\t" //Main loop, repeat for number of words in block
600
+ "length_loop: \n\t" //Main loop, repeat for number of words in block
600
601
"cpi r17,0x00 \n\t" //If page_word_count=0 then erase page
601
- "brne no_page_erase \n\t"
602
+ "brne no_page_erase \n\t"
602
603
"wait_spm1: \n\t"
603
604
"lds r16,%0 \n\t" //Wait for previous spm to complete
604
605
"andi r16,1 \n\t"
605
606
"cpi r16,1 \n\t"
606
607
"breq wait_spm1 \n\t"
607
608
"ldi r16,0x03 \n\t" //Erase page pointed to by Z
608
609
"sts %0,r16 \n\t"
609
- "spm \n\t"
610
+ "spm \n\t"
610
611
#ifdef __AVR_ATmega163__
611
612
".word 0xFFFF \n\t"
612
613
"nop \n\t"
@@ -615,19 +616,19 @@ int main(void)
615
616
"lds r16,%0 \n\t" //Wait for previous spm to complete
616
617
"andi r16,1 \n\t"
617
618
"cpi r16,1 \n\t"
618
- "breq wait_spm2 \n\t"
619
+ "breq wait_spm2 \n\t"
619
620
620
621
"ldi r16,0x11 \n\t" //Re-enable RWW section
621
- "sts %0,r16 \n\t"
622
+ "sts %0,r16 \n\t"
622
623
"spm \n\t"
623
624
#ifdef __AVR_ATmega163__
624
625
".word 0xFFFF \n\t"
625
626
"nop \n\t"
626
627
#endif
627
- "no_page_erase: \n\t"
628
+ "no_page_erase: \n\t"
628
629
"ld r0,Y+ \n\t" //Write 2 bytes into page buffer
629
- "ld r1,Y+ \n\t"
630
-
630
+ "ld r1,Y+ \n\t"
631
+
631
632
"wait_spm3: \n\t"
632
633
"lds r16,%0 \n\t" //Wait for previous spm to complete
633
634
"andi r16,1 \n\t"
@@ -636,7 +637,7 @@ int main(void)
636
637
"ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer
637
638
"sts %0,r16 \n\t"
638
639
"spm \n\t"
639
-
640
+
640
641
"inc r17 \n\t" //page_word_count++
641
642
"cpi r17,%1 \n\t"
642
643
"brlo same_page \n\t" //Still same page in FLASH
@@ -649,7 +650,7 @@ int main(void)
649
650
"breq wait_spm4 \n\t"
650
651
#ifdef __AVR_ATmega163__
651
652
"andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write
652
- #endif
653
+ #endif
653
654
"ldi r16,0x05 \n\t" //Write page pointed to by Z
654
655
"sts %0,r16 \n\t"
655
656
"spm \n\t"
@@ -662,15 +663,15 @@ int main(void)
662
663
"lds r16,%0 \n\t" //Wait for previous spm to complete
663
664
"andi r16,1 \n\t"
664
665
"cpi r16,1 \n\t"
665
- "breq wait_spm5 \n\t"
666
+ "breq wait_spm5 \n\t"
666
667
"ldi r16,0x11 \n\t" //Re-enable RWW section
667
- "sts %0,r16 \n\t"
668
- "spm \n\t"
668
+ "sts %0,r16 \n\t"
669
+ "spm \n\t"
669
670
#ifdef __AVR_ATmega163__
670
671
".word 0xFFFF \n\t"
671
672
"nop \n\t"
672
673
#endif
673
- "same_page: \n\t"
674
+ "same_page: \n\t"
674
675
"adiw r30,2 \n\t" //Next word in FLASH
675
676
"sbiw r24,2 \n\t" //length-2
676
677
"breq final_write \n\t" //Finished
@@ -696,7 +697,7 @@ int main(void)
696
697
} else {
697
698
if (++ error_count == MAX_ERROR_COUNT )
698
699
app_start ();
699
- }
700
+ }
700
701
}
701
702
702
703
@@ -761,7 +762,7 @@ int main(void)
761
762
}
762
763
763
764
764
- #if defined MONITOR
765
+ #if defined MONITOR
765
766
766
767
/* here come the extended monitor commands by Erik Lins */
767
768
@@ -783,7 +784,7 @@ int main(void)
783
784
welcome = "ATmegaBOOT / PROBOmega128 - (C) J.P.Kyle, E.Lins - 050815\n\r" ;
784
785
#elif defined SAVVY128
785
786
welcome = "ATmegaBOOT / Savvy128 - (C) J.P.Kyle, E.Lins - 050815\n\r" ;
786
- #elif defined __AVR_ATmega1280__
787
+ #elif defined __AVR_ATmega1280__
787
788
welcome = "ATmegaBOOT / Arduino Mega - (C) Arduino LLC - 090930\n\r" ;
788
789
#endif
789
790
@@ -815,7 +816,7 @@ int main(void)
815
816
LED_PORT |= _BV (LED );
816
817
putch ('0' );
817
818
}
818
- }
819
+ }
819
820
820
821
/* read byte from address */
821
822
else if (ch == 'r' ) {
@@ -907,14 +908,14 @@ void puthex(char ch) {
907
908
} else {
908
909
ah += '0' ;
909
910
}
910
-
911
+
911
912
ch &= 0x0f ;
912
913
if (ch >= 0x0a ) {
913
914
ch = ch - 0x0a + 'a' ;
914
915
} else {
915
916
ch += '0' ;
916
917
}
917
-
918
+
918
919
putch (ah );
919
920
putch (ch );
920
921
}
@@ -948,7 +949,7 @@ char getch(void)
948
949
uint32_t count = 0 ;
949
950
if (bootuart == 1 ) {
950
951
while (!(UCSR0A & _BV (RXC0 ))) {
951
- /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
952
+ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
952
953
/* HACKME:: here is a good place to count times*/
953
954
count ++ ;
954
955
if (count > MAX_TIME_COUNT )
@@ -959,7 +960,7 @@ char getch(void)
959
960
}
960
961
else if (bootuart == 2 ) {
961
962
while (!(UCSR1A & _BV (RXC1 ))) {
962
- /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
963
+ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
963
964
/* HACKME:: here is a good place to count times*/
964
965
count ++ ;
965
966
if (count > MAX_TIME_COUNT )
@@ -972,7 +973,7 @@ char getch(void)
972
973
#elif defined(__AVR_ATmega168__ ) || defined(__AVR_ATmega328P__ ) || defined (__AVR_ATmega328__ )
973
974
uint32_t count = 0 ;
974
975
while (!(UCSR0A & _BV (RXC0 ))){
975
- /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
976
+ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
976
977
/* HACKME:: here is a good place to count times*/
977
978
count ++ ;
978
979
if (count > MAX_TIME_COUNT )
@@ -983,7 +984,7 @@ char getch(void)
983
984
/* m8,16,32,169,8515,8535,163 */
984
985
uint32_t count = 0 ;
985
986
while (!(UCSRA & _BV (RXC ))){
986
- /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
987
+ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
987
988
/* HACKME:: here is a good place to count times*/
988
989
count ++ ;
989
990
if (count > MAX_TIME_COUNT )
@@ -1001,7 +1002,7 @@ void getNch(uint8_t count)
1001
1002
if (bootuart == 1 ) {
1002
1003
while (!(UCSR0A & _BV (RXC0 )));
1003
1004
UDR0 ;
1004
- }
1005
+ }
1005
1006
else if (bootuart == 2 ) {
1006
1007
while (!(UCSR1A & _BV (RXC1 )));
1007
1008
UDR1 ;
@@ -1010,11 +1011,11 @@ void getNch(uint8_t count)
1010
1011
getch ();
1011
1012
#else
1012
1013
/* m8,16,32,169,8515,8535,163 */
1013
- /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
1014
+ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
1014
1015
//while(!(UCSRA & _BV(RXC)));
1015
1016
//UDR;
1016
1017
getch (); // need to handle time out
1017
- #endif
1018
+ #endif
1018
1019
}
1019
1020
}
1020
1021
0 commit comments