Skip to content

Commit

Permalink
Fix for possible break of DFU functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
shodan committed Sep 18, 2018
1 parent b5cd376 commit 92b46fb
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions STM32F1/cores/maple/usb_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,6 @@ static void ifaceSetupHook(unsigned hook __attribute__((unused)), void *requestv
#endif
}

#define RESET_DELAY 100000
#ifdef SERIAL_USB
static void wait_reset(void) {
delay_us(RESET_DELAY);
nvic_sys_reset();
}
#endif


#define STACK_TOP 0x20000800
#define EXC_RETURN 0xFFFFFFF9
#define DEFAULT_CPSR 0x61000000
static void rxHook(unsigned hook __attribute__((unused)), void *ignored __attribute__((unused))) {
static const uint8 magic[4] = {'1', 'E', 'A', 'F'};
/* FIXME this is mad buggy; we need a new reset sequence. E.g. NAK
Expand All @@ -309,34 +297,11 @@ static const uint8 magic[4] = {'1', 'E', 'A', 'F'};
#ifdef SERIAL_USB
// The magic reset sequence is "1EAF".
// Got the magic sequence -> reset, presumably into the bootloader.
// Return address is wait_reset, but we must set the thumb bit.
bkp_init();
bkp_enable_writes();
bkp_write(10, 0x424C);
bkp_disable_writes();

uintptr_t target = (uintptr_t)wait_reset | 0x1;
asm volatile("mov r0, %[stack_top] \n\t" // Reset stack
"mov sp, r0 \n\t"
"mov r0, #1 \n\t"
"mov r1, %[target_addr] \n\t"
"mov r2, %[cpsr] \n\t"
"push {r2} \n\t" // Fake xPSR
"push {r1} \n\t" // PC target addr
"push {r0} \n\t" // Fake LR
"push {r0} \n\t" // Fake R12
"push {r0} \n\t" // Fake R3
"push {r0} \n\t" // Fake R2
"push {r0} \n\t" // Fake R1
"push {r0} \n\t" // Fake R0
"mov lr, %[exc_return] \n\t"
"bx lr"
:
: [stack_top] "r" (STACK_TOP),
[target_addr] "r" (target),
[exc_return] "r" (EXC_RETURN),
[cpsr] "r" (DEFAULT_CPSR)
: "r0", "r1", "r2");
nvic_sys_reset();
#endif
/* Can't happen. */
ASSERT_FAULT(0);
Expand Down

0 comments on commit 92b46fb

Please sign in to comment.