Skip to content

Commit c727cb1

Browse files
committed
Expose MCUSR register to applications using GPIOR0
This allows application to handle reset reasons, e.g. watchdog, reset button, ...
1 parent 6309212 commit c727cb1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: bootloaders/caterina/Caterina.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ uint16_t Timeout = 0;
6868
uint16_t bootKey = 0x7777;
6969
volatile uint16_t *const bootKeyPtr = (volatile uint16_t *)0x0800;
7070

71-
void StartSketch(void)
71+
void StartSketch(uint8_t mcusr_state)
7272
{
7373
cli();
7474

@@ -86,6 +86,8 @@ void StartSketch(void)
8686
TX_LED_OFF();
8787
RX_LED_OFF();
8888

89+
GPIOR0 = mcusr_state;
90+
8991
/* jump to beginning of application space */
9092
__asm__ volatile("jmp 0x0000");
9193
}
@@ -126,10 +128,10 @@ int main(void)
126128
} else if ((mcusr_state & (1<<PORF)) && (pgm_read_word(0) != 0xFFFF)) {
127129
// After a power-on reset skip the bootloader and jump straight to sketch
128130
// if one exists.
129-
StartSketch();
131+
StartSketch(mcusr_state);
130132
} else if ((mcusr_state & (1<<WDRF)) && (bootKeyPtrVal != bootKey) && (pgm_read_word(0) != 0xFFFF)) {
131133
// If it looks like an "accidental" watchdog reset then start the sketch.
132-
StartSketch();
134+
StartSketch(mcusr_state);
133135
}
134136

135137
/* Setup hardware required for the bootloader */
@@ -155,7 +157,7 @@ int main(void)
155157
USB_Detach();
156158

157159
/* Jump to beginning of application space to run the sketch - do not reset */
158-
StartSketch();
160+
StartSketch(mcusr_state);
159161
}
160162

161163
/** Configures all hardware required for the bootloader. */

Diff for: bootloaders/caterina/Caterina.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
8787

8888
/* Function Prototypes: */
89-
void StartSketch(void);
89+
void StartSketch(uint8_t mcur_state);
9090
void LEDPulse(void);
9191

9292
void CDC_Task(void);

0 commit comments

Comments
 (0)