Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose MCUSR register to applications using GPIOR0 #558

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions bootloaders/caterina/Caterina.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uint16_t Timeout = 0;
uint16_t bootKey = 0x7777;
volatile uint16_t *const bootKeyPtr = (volatile uint16_t *)0x0800;

void StartSketch(void)
void StartSketch(uint8_t mcusr_state)
{
cli();

Expand All @@ -86,6 +86,8 @@ void StartSketch(void)
TX_LED_OFF();
RX_LED_OFF();

GPIOR0 = mcusr_state;

/* jump to beginning of application space */
__asm__ volatile("jmp 0x0000");
}
Expand Down Expand Up @@ -126,10 +128,10 @@ int main(void)
} else if ((mcusr_state & (1<<PORF)) && (pgm_read_word(0) != 0xFFFF)) {
// After a power-on reset skip the bootloader and jump straight to sketch
// if one exists.
StartSketch();
StartSketch(mcusr_state);
} else if ((mcusr_state & (1<<WDRF)) && (bootKeyPtrVal != bootKey) && (pgm_read_word(0) != 0xFFFF)) {
// If it looks like an "accidental" watchdog reset then start the sketch.
StartSketch();
StartSketch(mcusr_state);
}

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

/* Jump to beginning of application space to run the sketch - do not reset */
StartSketch();
StartSketch(mcusr_state);
}

/** Configures all hardware required for the bootloader. */
Expand Down
2 changes: 1 addition & 1 deletion bootloaders/caterina/Caterina.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;

/* Function Prototypes: */
void StartSketch(void);
void StartSketch(uint8_t mcur_state);
void LEDPulse(void);

void CDC_Task(void);
Expand Down
Loading