-
Notifications
You must be signed in to change notification settings - Fork 961
/
bootloader.c
39 lines (36 loc) · 1.21 KB
/
bootloader.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "bootloader.h"
#include "stm32_def.h"
#include "backup.h"
#ifdef BL_LEGACY_LEAF
void dtr_togglingHook(uint8_t *buf, uint32_t *len)
{
/**
* Four byte is the magic pack "1EAF" that puts the MCU into bootloader.
* Check if the incoming contains the string "1EAF".
* If yes, put the MCU into the bootloader mode.
*/
if ((*len >= 4) && (buf[0] == '1') && (buf[1] == 'E') && (buf[2] == 'A') && (buf[3] == 'F')) {
NVIC_SystemReset();
}
}
#endif /* BL_LEGACY_LEAF */
#ifdef BL_HID
void dtr_togglingHook(uint8_t *buf, uint32_t *len)
{
/**
* Four byte is the magic pack "1EAF" that puts the MCU into bootloader.
* Check if the incoming contains the string "1EAF".
* If yes, put the MCU into the bootloader mode.
*/
if ((*len >= 4) && (buf[0] == '1') && (buf[1] == 'E') && (buf[2] == 'A') && (buf[3] == 'F')) {
enableBackupDomain();
/* New HID Bootloader (ver 2.2+) */
setBackupRegister(HID_MAGIC_NUMBER_BKP_INDEX, HID_MAGIC_NUMBER_BKP_VALUE);
#ifdef HID_OLD_MAGIC_NUMBER_BKP_INDEX
/* Compatibility to the old HID Bootloader (ver <= 2.1) */
setBackupRegister(HID_OLD_MAGIC_NUMBER_BKP_INDEX, HID_MAGIC_NUMBER_BKP_VALUE);
#endif
NVIC_SystemReset();
}
}
#endif /* BL_HID */