flipperzero-firmware icon indicating copy to clipboard operation
flipperzero-firmware copied to clipboard

Fix hard crash on some custom firmwares in RELEASE mode

Open derskythe opened this issue 3 years ago • 4 comments

What's new

  • Fix crash on shutdown in RELEASE mode
  • Code of RESTORE_REGISTERS_AND_HALT_MCU was separated to DEBUG and RELEASE mode

Verification

  • Сompile the firmware in release mode and try to turn off the Flipper

Checklist (For Reviewer)

  • [ ] PR has description of feature/bug or link to Confluence/Jira task
  • [ ] Description contains actions to verify feature/bugfix
  • [ ] I've built this code, uploaded it to the device and verified feature/bugfix

derskythe avatar Oct 29 '22 17:10 derskythe

Can we have a little bit more information on what exactly removing bkpt fixes?

skotopes avatar Oct 29 '22 17:10 skotopes

Ok, I've reproduced issue.

skotopes avatar Oct 29 '22 17:10 skotopes

Can we have a little bit more information on what exactly removing bkpt fixes?

In previous version you had code like this, but in latest version enter to DEBUG state in RELEASE version gives error: HardFault

static FURI_NORETURN void __furi_halt_mcu() {
    register const void* r12 asm("r12") = (void*)__furi_check_registers;
    asm volatile("ldm r12, {r0-r11} \n"
#ifdef FURI_DEBUG
                 "bkpt 0x00  \n"
#endif
                 "loop%=:    \n"
                 "wfi        \n"
                 "b loop%=   \n"
                 :
                 : "r"(r12)
                 : "memory");
    __builtin_unreachable();
}

derskythe avatar Oct 29 '22 17:10 derskythe

Yep, I forgot why I was adding it last time and decided to drop it. Now I've recalled why ;-) I'd like to analyze this thing a little bit more before merging this PR.

skotopes avatar Oct 29 '22 18:10 skotopes

Superseded by #1957

skotopes avatar Oct 30 '22 22:10 skotopes