Skip to content

STK500V2 hangs with active Serial 0 on boot. Patch Provided. #172

Open
@hayden-t

Description

@hayden-t

If you have an active serial device (eg gps) hooked up to Serial 0 during boot, it hangs the boot loader as it thinks it is getting a new sketch but it never comes. Other boot loaders have the fix already, but not this one, making Serial 0 unusable for a permanently connected serial device.

This is a simple fix that checks if the incoming serial stream is a new sketch or not, and if it is not, then it continues the boot process and loads the existing sketch.

regards,
Hayden.

--- stk500boot.c    Sun Mar 30 12:51:46 2014
+++ stk500boot.c    Wed May 28 14:11:19 2014
@@ -272,6 +272,7 @@
    #define BOOTSIZE 2048
 #endif

+#define MAX_ERR_COUNT       10
 #define APP_END  (FLASHEND -(2*BOOTSIZE) + 1)

 /*
@@ -541,6 +542,7 @@
    unsigned char   msgBuffer[285];
    unsigned char   c, *p;
    unsigned char   isLeave = 0;
+    unsigned char   errCnt = 0;

    unsigned long   boot_timeout;
    unsigned long   boot_timer;
@@ -712,6 +714,18 @@
                        {
                            msgParseState   =   ST_GET_SEQ_NUM;
                            checksum        =   MESSAGE_START^0;
+                        }
+                        else
+                        {
+                            errCnt++;
+                            if(errCnt > MAX_ERR_COUNT)
+                            {
+                                msgParseState   =   99; //* we dont want it do anything
+                                isLeave         =   1;
+                                errCnt = 0;
+                                boot_state = 2;         // boot_state=2 bootloader timeout, jump to main 0x00000
+                                goto ENTER_APP_CODE;
+                            }
                        }
                        break;

@@ -1149,7 +1163,7 @@
    delay_ms(100);
 #endif

-
+ENTER_APP_CODE:
 #ifndef REMOVE_BOOTLOADER_LED
    PROGLED_DDR     &=  ~(1<<PROGLED_PIN);  // set to default
    PROGLED_PORT    &=  ~(1<<PROGLED_PIN);  // active low LED OFF

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions