Skip to content

Commit 9079afd

Browse files
committed
platform/avr: add reset to bootloader and reset functions
Signed-off-by: Rafael Silva <perigoso@riseup.net>
1 parent 5edd900 commit 9079afd

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/platform/avr/boot.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* SPDX-FileCopyrightText: 2022 Rafael Silva <silvagracarafael@gmail.com>
4+
*/
5+
6+
#include <avr/wdt.h>
7+
8+
// Assuming the Caterina bootloader that comes with the 32u4
9+
uint16_t bootKey = 0x7777;
10+
volatile uint16_t *const bootKeyPtr = (volatile uint16_t *) 0x0800;
11+
12+
void reset()
13+
{
14+
wdt_enable(WDTO_15MS);
15+
for (;;) {
16+
}
17+
}
18+
19+
void bootloader()
20+
{
21+
*bootKeyPtr = bootKey;
22+
23+
reset();
24+
}

src/platform/avr/boot.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* SPDX-FileCopyrightText: 2022 Rafael Silva <perigoso@riseup.net>
4+
*/
5+
6+
void reset() __attribute__((noreturn));
7+
void bootloader() __attribute__((noreturn));
8+
;

0 commit comments

Comments
 (0)