cancel
Showing results for 
Search instead for 
Did you mean: 

OpenBootloader release binary is not working but the debug binary does work

newbie_stm32
Associate III

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();
}

 

3 REPLIES 3
KrzysztofK
Associate

In Release set optymalization level to (-O1). Than works without hard fault. 

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?

KrzysztofK
Associate

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.