@@ -80,11 +80,26 @@ Description: add timeout feature like previous Wiring bootloader
80
80
//* Aug 23, 2010 <MLS> Added support for atmega2561
81
81
//* Aug 26, 2010 <MLS> Removed support for BOOT_BY_SWITCH
82
82
//* Sep 8, 2010 <MLS> Added support for atmega16
83
- //* Nov 9, 2010 <MLS> Fixed bug that 3 !!! in code would cause it to jump to monitor
83
+ //* Nov 9, 2010 <MLS> Issue 392: Fixed bug that 3 !!! in code would cause it to jump to monitor
84
84
//* Jun 24, 2011 <MLS> Removed analogRead (was not used)
85
+ //* Dec 29, 2011 <MLS> Issue 181: added watch dog timmer support
86
+ //* Dec 29, 2011 <MLS> Issue 505: bootloader is comparing the seqNum to 1 or the current sequence
87
+ //* Jan 1, 2012 <MLS> Issue 543: CMD_CHIP_ERASE_ISP now returns STATUS_CMD_FAILED instead of STATUS_CMD_OK
88
+ //* Jan 1, 2012 <MLS> Issue 543: Write EEPROM now does something (NOT TESTED)
89
+ //* Jan 1, 2012 <MLS> Issue 544: stk500v2 bootloader doesn't support reading fuses
85
90
//************************************************************************
86
91
87
-
92
+ //************************************************************************
93
+ //* these are used to test issues
94
+ //* http://code.google.com/p/arduino/issues/detail?id=505
95
+ //* Reported by mark.stubbs, Mar 14, 2011
96
+ //* The STK500V2 bootloader is comparing the seqNum to 1 or the current sequence
97
+ //* (IE: Requiring the sequence to be 1 or match seqNum before continuing).
98
+ //* The correct behavior is for the STK500V2 to accept the PC's sequence number, and echo it back for the reply message.
99
+ #define _FIX_ISSUE_505_
100
+ //************************************************************************
101
+ //* Issue 181: added watch dog timmer support
102
+ #define _FIX_ISSUE_181_
88
103
89
104
#include <inttypes.h>
90
105
#include <avr/io.h>
@@ -112,7 +127,7 @@ Description: add timeout feature like previous Wiring bootloader
112
127
#define EEMWE 2
113
128
#endif
114
129
115
- #define _DEBUG_SERIAL_
130
+ // #define _DEBUG_SERIAL_
116
131
//#define _DEBUG_WITH_LEDS_
117
132
118
133
@@ -420,7 +435,7 @@ void __jumpMain(void)
420
435
421
436
asm volatile ( ".set __stack, %0" :: "i" (RAMEND ) );
422
437
423
- //* et stack pointer to top of RAM
438
+ //* set stack pointer to top of RAM
424
439
425
440
asm volatile ( "ldi 16, %0" :: "i" (RAMEND >> 8 ) );
426
441
asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_HI_ADDR ) );
@@ -509,6 +524,8 @@ uint32_t count = 0;
509
524
return UART_DATA_REG ;
510
525
}
511
526
527
+ //* for watch dog timer startup
528
+ void (* app_start )(void ) = 0x0000 ;
512
529
513
530
514
531
//*****************************************************************************
@@ -540,14 +557,35 @@ int main(void)
540
557
asm volatile ( "ldi 16, %0" :: "i" (RAMEND & 0x0ff ) );
541
558
asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_LO_ADDR ) );
542
559
560
+ #ifdef _FIX_ISSUE_181_
561
+ //************************************************************************
562
+ //* Dec 29, 2011 <MLS> Issue #181, added watch dog timmer support
563
+ //* handle the watch dog timer
564
+ uint8_t mcuStatusReg ;
565
+ mcuStatusReg = MCUSR ;
566
+
567
+ __asm__ __volatile__ ("cli" );
568
+ __asm__ __volatile__ ("wdr" );
569
+ MCUSR = 0 ;
570
+ WDTCSR |= _BV (WDCE ) | _BV (WDE );
571
+ WDTCSR = 0 ;
572
+ __asm__ __volatile__ ("sei" );
573
+ // check if WDT generated the reset, if so, go straight to app
574
+ if (mcuStatusReg & _BV (WDRF ))
575
+ {
576
+ app_start ();
577
+ }
578
+ //************************************************************************
579
+ #endif
543
580
544
581
545
582
boot_timer = 0 ;
546
583
boot_state = 0 ;
547
584
548
585
#ifdef BLINK_LED_WHILE_WAITING
549
- boot_timeout = 90000 ; //* should be about 4 seconds
586
+ // boot_timeout = 90000; //* should be about 4 seconds
550
587
// boot_timeout = 170000;
588
+ boot_timeout = 20000 ; //* should be about 1 second
551
589
#else
552
590
boot_timeout = 3500000 ; // 7 seconds , approx 2us per step when optimize "s"
553
591
#endif
@@ -678,6 +716,11 @@ int main(void)
678
716
break ;
679
717
680
718
case ST_GET_SEQ_NUM :
719
+ #ifdef _FIX_ISSUE_505_
720
+ seqNum = c ;
721
+ msgParseState = ST_MSG_SIZE_1 ;
722
+ checksum ^= c ;
723
+ #else
681
724
if ( (c == 1 ) || (c == seqNum ) )
682
725
{
683
726
seqNum = c ;
@@ -688,6 +731,7 @@ int main(void)
688
731
{
689
732
msgParseState = ST_START ;
690
733
}
734
+ #endif
691
735
break ;
692
736
693
737
case ST_MSG_SIZE_1 :
@@ -754,20 +798,41 @@ int main(void)
754
798
unsigned char signatureIndex = msgBuffer [6 ];
755
799
756
800
if ( signatureIndex == 0 )
757
- answerByte = (SIGNATURE_BYTES >>16 ) & 0x000000FF ;
801
+ {
802
+ answerByte = (SIGNATURE_BYTES >> 16 ) & 0x000000FF ;
803
+ }
758
804
else if ( signatureIndex == 1 )
805
+ {
759
806
answerByte = (SIGNATURE_BYTES >> 8 ) & 0x000000FF ;
807
+ }
760
808
else
809
+ {
761
810
answerByte = SIGNATURE_BYTES & 0x000000FF ;
811
+ }
762
812
}
763
813
else if ( msgBuffer [4 ] & 0x50 )
764
814
{
765
- answerByte = 0 ; //read fuse/lock bits not implemented, return dummy value
815
+ //* Issue 544: stk500v2 bootloader doesn't support reading fuses
816
+ //* I cant find the docs that say what these are supposed to be but this was figured out by trial and error
817
+ // answerByte = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS);
818
+ // answerByte = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
819
+ // answerByte = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS);
820
+ if (msgBuffer [4 ] == 0x50 )
821
+ {
822
+ answerByte = boot_lock_fuse_bits_get (GET_LOW_FUSE_BITS );
823
+ }
824
+ else if (msgBuffer [4 ] == 0x58 )
825
+ {
826
+ answerByte = boot_lock_fuse_bits_get (GET_HIGH_FUSE_BITS );
827
+ }
828
+ else
829
+ {
830
+ answerByte = 0 ;
831
+ }
766
832
}
767
833
else
768
834
{
769
835
answerByte = 0 ; // for all others command are not implemented, return dummy value for AVRDUDE happy <Worapoht>
770
- // flag = 1; // Remark this line for AVRDUDE <Worapoht>
771
836
}
772
837
if ( !flag )
773
838
{
@@ -903,7 +968,8 @@ int main(void)
903
968
case CMD_CHIP_ERASE_ISP :
904
969
eraseAddress = 0 ;
905
970
msgLength = 2 ;
906
- msgBuffer [1 ] = STATUS_CMD_OK ;
971
+ // msgBuffer[1] = STATUS_CMD_OK;
972
+ msgBuffer [1 ] = STATUS_CMD_FAILED ; //* isue 543, return FAILED instead of OK
907
973
break ;
908
974
909
975
case CMD_LOAD_ADDRESS :
@@ -954,8 +1020,9 @@ int main(void)
954
1020
}
955
1021
else
956
1022
{
957
- #if (!defined(__AVR_ATmega1280__ ) && !defined(__AVR_ATmega2560__ ) && !defined(__AVR_ATmega2561__ ) && !defined(__AVR_ATmega1284P__ ) && !defined(__AVR_ATmega640__ ))
958
- // #if (defined(EEARL) && defined(EEARH) && defined(EEMWE) && defined(EEWE) && defined(EEDR))
1023
+ //* issue 543, this should work, It has not been tested.
1024
+ // #if (!defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega2560__) && !defined(__AVR_ATmega2561__) && !defined(__AVR_ATmega1284P__) && !defined(__AVR_ATmega640__))
1025
+ #if (defined(EEARL ) && defined(EEARH ) && defined(EEMWE ) && defined(EEWE ) && defined(EEDR ))
959
1026
/* write EEPROM */
960
1027
do {
961
1028
EEARL = address ; // Setup EEPROM address
@@ -1158,25 +1225,7 @@ unsigned long gEepromIndex;
1158
1225
#define false 0
1159
1226
1160
1227
#include "avr_cpunames.h"
1161
- /*
1162
- #if defined(__AVR_ATmega128__)
1163
- #define kCPU_NAME "ATmega128"
1164
- #elif defined(__AVR_ATmega1280__)
1165
- #define kCPU_NAME "ATmega1280"
1166
- #elif defined(__AVR_ATmega1281__)
1167
- #define kCPU_NAME "ATmega1281"
1168
- #elif defined(__AVR_ATmega2560__)
1169
- #define kCPU_NAME "ATmega2560"
1170
- #elif defined(__AVR_ATmega2561__)
1171
- #define kCPU_NAME "ATmega2561"
1172
- #elif defined(__AVR_ATmega1284P__)
1173
- #define kCPU_NAME "ATmega1284P"
1174
- #elif defined(__AVR_ATmega640__)
1175
- #define kCPU_NAME "ATmega640"
1176
- #else
1177
- #error cpu name not defined
1178
- #endif
1179
- */
1228
+
1180
1229
#ifndef _AVR_CPU_NAME_
1181
1230
#error cpu name not defined
1182
1231
#endif
@@ -1577,6 +1626,8 @@ int errorCount;
1577
1626
1578
1627
1579
1628
#if (FLASHEND > 0x08000 )
1629
+ //* this includes the interrupt names for the monitor portion. There is no longer enough
1630
+ //* memory to include this
1580
1631
// #include "avrinterruptnames.h"
1581
1632
// #ifndef _INTERRUPT_NAMES_DEFINED_
1582
1633
// #warning Interrupt vectors not defined
0 commit comments