2023-10-26 11:35 PM - edited 2023-10-26 11:41 PM
Hi Community,
I have a customized OpenBootloader that works well in debug build but is not working when the same is built for release. After some investigation, it was found that execution hitting hard fault at OPENBL_FLASH_JumpToAddress when OpenBootloader_DeInit() is executed which in turn calls HAL_RCC_DeInit().
What may be the reason it is not working in the release build?
Please find the OPENBL_FLASH_JumpToAddress implementation:
void OPENBL_FLASH_JumpToAddress(uint32_t Address)
{
Function_Pointer jump_to_address;
/* Deinitialize all HW resources used by the Bootloader to their reset values */
OpenBootloader_DeInit();
/* Enable IRQ */
Common_EnableIrq();
jump_to_address = (Function_Pointer)(*(__IO uint32_t *)(Address + 4U));
/* Initialize user application's stack pointer */
Common_SetMsp(*(__IO uint32_t *) Address);
jump_to_address();
}
2024-02-16 12:01 AM
In Release set optymalization level to (-O1). Than works without hard fault.
2024-02-16 12:08 AM - edited 2024-02-16 12:10 AM
Yes, I am aware of this. I fixed it a few months back while experimenting with different optimization levels. But the reason for this is still unknown.
@KrzysztofK Do you have any input on why changing the optimization level works?
2024-02-16 12:29 AM
After investigation, it seems to me that in the case of optimizations at the -O1 level, push/pop instructions are used to write and restore processor registers, which allows a safe call and return from the function. In contrast, in the case of -Os-level optimization, the ldmia.w and stmia.w instructions are used, which are more efficient in terms of memory occupied but can lead to errors.