In STM32G473RB how to jump into system boot area using software.
Hello, I am trying jump into system boot area using software. and try to update firware.
But this function is not working please help. After calling this function controller get reset and again start from main().
void firmware_update(void)
{
HAL_DeInit();
//usb_deinit();
HAL_RCC_DeInit();
SystemInit();
FLASH_OBProgramInitTypeDef pOBInit;
/* Get the Option byte configuration */
HAL_FLASHEx_OBGetConfig(&pOBInit);
/* BOOT_SEL = 0 */
pOBInit.UserConfig &= ~(OB_USER_nSWBOOT0);
/* nBOOT0=1 */
pOBInit.UserConfig |= OB_USER_nBOOT0;
/** HAL_FLASHEx_OBProgram && HAL_FLASHEx_OBErase
* HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes
*/
if(HAL_FLASH_OB_Unlock() != HAL_OK)
{
return HAL_ERROR;
}
/*We need to erase option bytes before write. */
// if(HAL_FLASHEx_OBErase() != HAL_OK)
// {
// return HAL_ERROR;
// }
/* Write changed option bytes */
if(HAL_FLASHEx_OBProgram(&pOBInit))
{
return HAL_ERROR;
}
//Map the "system" memory to 0x00000000 as required by the ST BSL.
SYSCFG->MEMRMP = SYSCFG_MEMRMP_MEM_MODE_0;
// Restore the reset setting of VTOR (location of vector table), possibly required by the ST BSL.
SCB->VTOR = 0;
// Set the stack pointer and PC as if reset itself did it to induce the ST BSL.
__set_MSP(*(uint32_t*)0x1FFF0000);
__NO_RETURN void (*StBsl)() = (void *)(*(uint32_t*)0x1FFF0004);
StBsl();
HAL_Delay(1000);
}