2023-11-14 06:21 AM
Good morning,
I'm trying to program the user option bytes of the STM32C011 using the HAL. The objective of the test is to toggle the BOR bit.
static HAL_StatusTypeDef testOptionBytes()
{
FLASH_OBProgramInitTypeDef obInit = {0};
FLASH_OBProgramInitTypeDef obProgram = {0};
FLASH_OBProgramInitTypeDef obCmp = {0};
HAL_StatusTypeDef status = HAL_OK;
HAL_FLASHEx_OBGetConfig(&obInit);
status = HAL_FLASH_Unlock();
assert(status == HAL_OK);
status = HAL_FLASH_OB_Unlock();
assert(status == HAL_OK);
obProgram.OptionType = OPTIONBYTE_USER;
obProgram.USERType = OB_USER_BOR_EN;
obProgram.USERConfig = (obInit.USERConfig & OB_USER_BOR_EN) ^ OB_USER_BOR_EN;
status = HAL_FLASHEx_OBProgram(&obProgram);
assert(status == HAL_OK);
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
HAL_FLASHEx_OBGetConfig(&obCmp);
assert(obInit.USERConfig != obCmp.USERConfig);
return status;
}
When I step through the HAL code everything looks fine, the FLASH->OPTR register is written with the correct value, but the final assert() always fails.
Have I overseen something here?
Thanks in advance, Andreas
Solved! Go to Solution.
2023-11-14 08:48 AM
You need to call HAL_FLASH_OB_Launch() after HAL_FLASHEx_OBProgram()
2023-11-14 08:48 AM
You need to call HAL_FLASH_OB_Launch() after HAL_FLASHEx_OBProgram()