2022-04-19 06:00 PM
I'm trying to program the option bytes on an STM32G0B1 but it keeps timing out at the end of the program sequence and never actually succeeds, no matter how many times I try.
I enable the Flash peripheral
I (successfully) unlock the flash
I (successfully) unlock the option bytes
I program the option bytes
... and it times out 10 times
then it calls OB_Launch and hard faults.
.. what am I missing? This was easy on the H7...
{
__HAL_RCC_FLASH_CLK_ENABLE();
FLASH_OBProgramInitTypeDef flashDef;
memset(&flashDef, 0, sizeof(FLASH_OBProgramInitTypeDef));
HAL_FLASHEx_OBGetConfig(&flashDef);
if ((flashDef.USERConfig & OB_BOR_ENABLE) == 0)
{
for (int i = 0; i < 10; i++)
{
if (HAL_FLASH_Unlock() == HAL_OK)
break;
}
for (int i = 0; i < 10; i++)
{
if (HAL_FLASH_OB_Unlock() == HAL_OK)
break;
}
memset(&flashDef, 0, sizeof(FLASH_OBProgramInitTypeDef));
flashDef.OptionType = OPTIONBYTE_USER;
flashDef.USERType = OB_USER_BOR_EN;
flashDef.USERConfig = OB_BOR_ENABLE;
for (int i = 0; i < 10; i++)
{
if (HAL_FLASHEx_OBProgram(&flashDef) == HAL_OK)
break;
}
HAL_FLASH_OB_Launch();
for (int i = 0; i < 10; i++)
{
if (HAL_FLASH_OB_Lock() == HAL_OK)
break;
}
for (int i = 0; i < 10; i++)
{
if (HAL_FLASH_Lock() == HAL_OK)
break;
}
}
}
2022-04-19 07:13 PM
Same thing as here?
2022-04-20 06:26 AM
Yup, looks like it. I didn't find that post while searching the forums to see if anyone had similar difficulties... Kinda surprised this doesn't have an answer yet...